Skip to content

Commit

Permalink
obs-outputs: Remove requirement for libavutil
Browse files Browse the repository at this point in the history
obs-outputs doesn't link against FFmpeg and shouldn't depend on it.

Also includes some cleanup to make the code more readable.
  • Loading branch information
derrod committed Mar 25, 2023
1 parent 029ac6c commit f64b3fa
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 27 deletions.
62 changes: 35 additions & 27 deletions plugins/obs-outputs/rtmp-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <obs-avc.h>
#include <obs-hevc.h>
#include <libavutil/pixfmt.h>

#ifdef _WIN32
#include <util/windows/win-version.h>
Expand Down Expand Up @@ -904,48 +903,57 @@ static bool send_video_metadata(struct rtmp_stream *stream)
video_output_get_info(video);
enum video_format format = info->format;
enum video_colorspace colorspace = info->colorspace;
enum video_range_type range = info->range;

int bits_per_raw_sample = format == VIDEO_FORMAT_I010 ? 10
: format == VIDEO_FORMAT_P010 ? 10
: format == VIDEO_FORMAT_I210 ? 10
: format == VIDEO_FORMAT_I412 ? 12
: format == VIDEO_FORMAT_YA2L ? 12
: 8;
int bits_per_raw_sample;
switch (format) {
case VIDEO_FORMAT_I010:
case VIDEO_FORMAT_P010:
case VIDEO_FORMAT_I210:
bits_per_raw_sample = 10;
break;
case VIDEO_FORMAT_I412:
case VIDEO_FORMAT_YA2L:
bits_per_raw_sample = 12;
break;
default:
bits_per_raw_sample = 8;
}

int pri = 0, trc = 0, spc = 0;
switch (colorspace) {
case VIDEO_CS_601:
pri = AVCOL_PRI_SMPTE170M;
trc = AVCOL_TRC_SMPTE170M;
spc = AVCOL_SPC_SMPTE170M;
pri = OBSCOL_PRI_SMPTE170M;
trc = OBSCOL_PRI_SMPTE170M;
spc = OBSCOL_PRI_SMPTE170M;
break;
case VIDEO_CS_DEFAULT:
case VIDEO_CS_709:
pri = AVCOL_PRI_BT709;
trc = AVCOL_TRC_BT709;
spc = AVCOL_SPC_BT709;
pri = OBSCOL_PRI_BT709;
trc = OBSCOL_PRI_BT709;
spc = OBSCOL_PRI_BT709;
break;
case VIDEO_CS_SRGB:
pri = AVCOL_PRI_BT709;
trc = AVCOL_TRC_IEC61966_2_1;
spc = AVCOL_SPC_BT709;
pri = OBSCOL_PRI_BT709;
trc = OBSCOL_TRC_IEC61966_2_1;
spc = OBSCOL_PRI_BT709;
break;
case VIDEO_CS_2100_PQ:
pri = AVCOL_PRI_BT2020;
trc = AVCOL_TRC_SMPTE2084;
spc = AVCOL_SPC_BT2020_NCL;
pri = OBSCOL_PRI_BT2020;
trc = OBSCOL_TRC_SMPTE2084;
spc = OBSCOL_SPC_BT2020_NCL;
break;
case VIDEO_CS_2100_HLG:
pri = AVCOL_PRI_BT2020;
trc = AVCOL_TRC_ARIB_STD_B67;
spc = AVCOL_SPC_BT2020_NCL;
pri = OBSCOL_PRI_BT2020;
trc = OBSCOL_TRC_ARIB_STD_B67;
spc = OBSCOL_SPC_BT2020_NCL;
}

const int max_luminance =
(trc == AVCOL_TRC_SMPTE2084)
? (int)obs_get_video_hdr_nominal_peak_level()
: ((trc == AVCOL_TRC_ARIB_STD_B67) ? 1000 : 0);
int max_luminance = 0;
if (trc == OBSCOL_TRC_ARIB_STD_B67)
max_luminance = 1000;
else if (trc == OBSCOL_TRC_SMPTE2084)
max_luminance =
(int)obs_get_video_hdr_nominal_peak_level();

flv_packet_metadata(vencoder, &data, &size, bits_per_raw_sample,
pri, trc, spc, 0, max_luminance);
Expand Down
107 changes: 107 additions & 0 deletions plugins/obs-outputs/rtmp-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,110 @@ struct rtmp_stream {
#ifdef _WIN32
void *socket_thread_windows(void *data);
#endif

/* Adapted from FFmpeg's libavutil/pixfmt.h
*
* Renamed to make it apparent that these are not imported as this module does
* not use or link against FFmpeg.
*/

/**
* Chromaticity coordinates of the source primaries.
* These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.1 and ITU-T H.273.
*/
enum OBSColorPrimaries {
OBSCOL_PRI_RESERVED0 = 0,
OBSCOL_PRI_BT709 =
1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
OBSCOL_PRI_UNSPECIFIED = 2,
OBSCOL_PRI_RESERVED = 3,
OBSCOL_PRI_BT470M =
4, ///< also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
OBSCOL_PRI_BT470BG =
5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
OBSCOL_PRI_SMPTE170M =
6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
OBSCOL_PRI_SMPTE240M =
7, ///< identical to above, also called "SMPTE C" even though it uses D65
OBSCOL_PRI_FILM = 8, ///< colour filters using Illuminant C
OBSCOL_PRI_BT2020 = 9, ///< ITU-R BT2020
OBSCOL_PRI_SMPTE428 = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ)
OBSCOL_PRI_SMPTEST428_1 = OBSCOL_PRI_SMPTE428,
OBSCOL_PRI_SMPTE431 = 11, ///< SMPTE ST 431-2 (2011) / DCI P3
OBSCOL_PRI_SMPTE432 =
12, ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
OBSCOL_PRI_EBU3213 =
22, ///< EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors
OBSCOL_PRI_JEDEC_P22 = OBSCOL_PRI_EBU3213,
OBSCOL_PRI_NB ///< Not part of ABI
};

/**
* Color Transfer Characteristic.
* These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.2.
*/
enum OBSColorTransferCharacteristic {
OBSCOL_TRC_RESERVED0 = 0,
OBSCOL_TRC_BT709 = 1, ///< also ITU-R BT1361
OBSCOL_TRC_UNSPECIFIED = 2,
OBSCOL_TRC_RESERVED = 3,
OBSCOL_TRC_GAMMA22 =
4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
OBSCOL_TRC_GAMMA28 = 5, ///< also ITU-R BT470BG
OBSCOL_TRC_SMPTE170M =
6, ///< also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
OBSCOL_TRC_SMPTE240M = 7,
OBSCOL_TRC_LINEAR = 8, ///< "Linear transfer characteristics"
OBSCOL_TRC_LOG =
9, ///< "Logarithmic transfer characteristic (100:1 range)"
OBSCOL_TRC_LOG_SQRT =
10, ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
OBSCOL_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4
OBSCOL_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut
OBSCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC)
OBSCOL_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10-bit system
OBSCOL_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12-bit system
OBSCOL_TRC_SMPTE2084 =
16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems
OBSCOL_TRC_SMPTEST2084 = OBSCOL_TRC_SMPTE2084,
OBSCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1
OBSCOL_TRC_SMPTEST428_1 = OBSCOL_TRC_SMPTE428,
OBSCOL_TRC_ARIB_STD_B67 =
18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
OBSCOL_TRC_NB ///< Not part of ABI
};

/**
* YUV colorspace type.
* These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.3.
*/
enum OBSColorSpace {
OBSCOL_SPC_RGB =
0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
OBSCOL_SPC_BT709 =
1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
OBSCOL_SPC_UNSPECIFIED = 2,
OBSCOL_SPC_RESERVED =
3, ///< reserved for future use by ITU-T and ISO/IEC just like 15-255 are
OBSCOL_SPC_FCC =
4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
OBSCOL_SPC_BT470BG =
5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
OBSCOL_SPC_SMPTE170M =
6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
OBSCOL_SPC_SMPTE240M =
7, ///< derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
OBSCOL_SPC_YCGCO =
8, ///< used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
OBSCOL_SPC_YCOCG = OBSCOL_SPC_YCGCO,
OBSCOL_SPC_BT2020_NCL =
9, ///< ITU-R BT2020 non-constant luminance system
OBSCOL_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system
OBSCOL_SPC_SMPTE2085 = 11, ///< SMPTE 2085, Y'D'zD'x
OBSCOL_SPC_CHROMA_DERIVED_NCL =
12, ///< Chromaticity-derived non-constant luminance system
OBSCOL_SPC_CHROMA_DERIVED_CL =
13, ///< Chromaticity-derived constant luminance system
OBSCOL_SPC_ICTCP = 14, ///< ITU-R BT.2100-0, ICtCp
OBSCOL_SPC_NB ///< Not part of ABI
};

0 comments on commit f64b3fa

Please sign in to comment.