Skip to content

Commit

Permalink
parse primaries and matrix coefficients and include them in the MPD f…
Browse files Browse the repository at this point in the history
…or DASH
  • Loading branch information
cosmin committed May 9, 2024
1 parent 7a1c990 commit 3e7dda4
Show file tree
Hide file tree
Showing 31 changed files with 181 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns:scte214="urn:scte:dash:scte214-extensions" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT6.022683S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="60000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<Representation id="0" bandwidth="550702" codecs="av01.0.04M.10.0.111.09.16.09.0" mimeType="video/mp4" scte214:supplementalCodecs="dav1.10.01" scte214:supplementalProfiles="db1p" sar="1:1">
<BaseURL>sparks_dovi_10-video.mp4</BaseURL>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns:cenc="urn:mpeg:cenc:2013" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT6.022683S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="60000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="2"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="2"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<ContentProtection value="cenc" schemeIdUri="urn:mpeg:dash:mp4protection:2011" cenc:default_KID="31323334-3536-3738-3930-313233343536"/>
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns:scte214="urn:scte:dash:scte214-extensions" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT6.022683S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="60000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<Representation id="0" bandwidth="807837" codecs="hvc1.2.4.L90.90" mimeType="video/mp4" scte214:supplementalCodecs="dvh1.08.01" scte214:supplementalProfiles="db2g" sar="1:1">
<BaseURL>sparks_dovi_8-video.mp4</BaseURL>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns:cenc="urn:mpeg:cenc:2013" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT6.022683S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="60000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<ContentProtection value="cenc" schemeIdUri="urn:mpeg:dash:mp4protection:2011" cenc:default_KID="31323334-3536-3738-3930-313233343536"/>
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
Expand All @@ -16,6 +18,8 @@
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="video" width="640" height="360" frameRate="60000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<ContentProtection value="cenc" schemeIdUri="urn:mpeg:dash:mp4protection:2011" cenc:default_KID="31323334-3536-3738-3930-313233343536"/>
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
Expand Down
2 changes: 2 additions & 0 deletions packager/app/test/testdata/hdr10-with-encryption/output.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" xmlns:cenc="urn:mpeg:cenc:2013" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT2.8028S">
<Period id="0">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="30000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
<SupplementalProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
<ContentProtection value="cenc" schemeIdUri="urn:mpeg:dash:mp4protection:2011" cenc:default_KID="31323334-3536-3738-3930-313233343536"/>
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
Expand Down
8 changes: 6 additions & 2 deletions packager/media/base/media_handler_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const uint32_t kWidth = 10u;
const uint32_t kHeight = 20u;
const uint32_t kPixelWidth = 2u;
const uint32_t kPixelHeight = 3u;
const uint8_t kColorPrimaries = 0;
const uint8_t kMatrixCoefficients = 0;
const uint8_t kTransferCharacteristics = 0;

const int16_t kTrickPlayFactor = 0;
const uint8_t kNaluLengthSize = 1u;
const bool kEncrypted = true;
Expand Down Expand Up @@ -207,8 +210,9 @@ std::unique_ptr<StreamInfo> MediaHandlerTestBase::GetVideoStreamInfo(
return std::unique_ptr<VideoStreamInfo>(new VideoStreamInfo(
kTrackId, time_scale, kDuration, codec, H26xStreamFormat::kUnSpecified,
kCodecString, kCodecConfig, sizeof(kCodecConfig), width, height,
kPixelWidth, kPixelHeight, kTransferCharacteristics, kTrickPlayFactor,
kNaluLengthSize, kLanguage, !kEncrypted));
kPixelWidth, kPixelHeight, kColorPrimaries, kMatrixCoefficients,
kTransferCharacteristics, kTrickPlayFactor, kNaluLengthSize, kLanguage,
!kEncrypted));
}

std::unique_ptr<StreamInfo> MediaHandlerTestBase::GetAudioStreamInfo(
Expand Down
4 changes: 4 additions & 0 deletions packager/media/base/video_stream_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ VideoStreamInfo::VideoStreamInfo(int track_id,
uint32_t height,
uint32_t pixel_width,
uint32_t pixel_height,
uint8_t color_primaries,
uint8_t matrix_coefficients,
uint8_t transfer_characteristics,
uint32_t trick_play_factor,
uint8_t nalu_length_size,
Expand All @@ -71,6 +73,8 @@ VideoStreamInfo::VideoStreamInfo(int track_id,
pixel_width_(pixel_width),
pixel_height_(pixel_height),
transfer_characteristics_(transfer_characteristics),
color_primaries_(color_primaries),
matrix_coefficients_(matrix_coefficients),
trick_play_factor_(trick_play_factor),
nalu_length_size_(nalu_length_size) {}

Expand Down
12 changes: 12 additions & 0 deletions packager/media/base/video_stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class VideoStreamInfo : public StreamInfo {
uint32_t height,
uint32_t pixel_width,
uint32_t pixel_height,
uint8_t color_primaries,
uint8_t matrix_coefficients,
uint8_t transfer_characteristics,
uint32_t trick_play_factor,
uint8_t nalu_length_size,
Expand Down Expand Up @@ -67,6 +69,8 @@ class VideoStreamInfo : public StreamInfo {
/// @return 0 if unknown.
uint32_t pixel_height() const { return pixel_height_; }
uint8_t transfer_characteristics() const { return transfer_characteristics_; }
uint8_t color_primaries() const { return color_primaries_; }
uint8_t matrix_coefficients() const { return matrix_coefficients_; }
uint8_t nalu_length_size() const { return nalu_length_size_; }
uint32_t trick_play_factor() const { return trick_play_factor_; }
uint32_t playback_rate() const { return playback_rate_; }
Expand All @@ -91,6 +95,12 @@ class VideoStreamInfo : public StreamInfo {
void set_transfer_characteristics(uint8_t transfer_characteristics) {
transfer_characteristics_ = transfer_characteristics;
}
void set_color_primaries(uint8_t color_primaries) {
color_primaries_ = color_primaries;
}
void set_matrix_coefficients(uint8_t matrix_coefficients) {
matrix_coefficients_ = matrix_coefficients;
}
void set_trick_play_factor(uint32_t trick_play_factor) {
trick_play_factor_ = trick_play_factor;
}
Expand Down Expand Up @@ -120,6 +130,8 @@ class VideoStreamInfo : public StreamInfo {
uint32_t pixel_width_;
uint32_t pixel_height_;
uint8_t transfer_characteristics_ = 0;
uint8_t color_primaries_ = 0;
uint8_t matrix_coefficients_ = 0;
uint32_t trick_play_factor_ = 0; // Non-zero for trick-play streams.

// Playback rate is the attribute for trick play stream, which signals the
Expand Down
18 changes: 18 additions & 0 deletions packager/media/codecs/decoder_configuration_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class DecoderConfigurationRecord {
/// @return Transfer characteristics of the config.
uint8_t transfer_characteristics() const { return transfer_characteristics_; }

/// @return Colour Primaries of the config.
uint8_t color_primaries() const { return color_primaries_; }

/// @return Matrix Coeffs of the config.
uint8_t matrix_coefficients() const { return matrix_coefficients_; }

protected:
DecoderConfigurationRecord();

Expand All @@ -71,6 +77,15 @@ class DecoderConfigurationRecord {
transfer_characteristics_ = transfer_characteristics;
}

/// Sets the colour primaries.
void set_color_primaries(uint8_t color_primaries) {
color_primaries_ = color_primaries;
}
/// Sets the matrix coeffs.
void set_matrix_coefficients(uint8_t matrix_coefficients) {
matrix_coefficients_ = matrix_coefficients;
}

private:
// Performs the actual parsing of the data.
virtual bool ParseInternal() = 0;
Expand All @@ -86,6 +101,9 @@ class DecoderConfigurationRecord {
// The parameter is extracted from SPS.
uint8_t transfer_characteristics_ = 0;

uint8_t color_primaries_ = 0;
uint8_t matrix_coefficients_ = 0;

DISALLOW_COPY_AND_ASSIGN(DecoderConfigurationRecord);
};

Expand Down
4 changes: 2 additions & 2 deletions packager/media/codecs/h264_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ H264Parser::Result H264Parser::ParseVUIParameters(H26xBitReader* br,
READ_BOOL_OR_RETURN(&data); // video_full_range_flag
READ_BOOL_OR_RETURN(&data); // colour_description_present_flag
if (data) {
READ_BITS_OR_RETURN(8, &data); // colour primaries
READ_BITS_OR_RETURN(8, &sps->color_primaries); // colour primaries
READ_BITS_OR_RETURN(8, &sps->transfer_characteristics);
READ_BITS_OR_RETURN(8, &data); // matrix coeffs
READ_BITS_OR_RETURN(8, &sps->matrix_coefficients); // matrix coeffs
}
}

Expand Down
2 changes: 2 additions & 0 deletions packager/media/codecs/h264_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct H264Sps {
int sar_width; // Set to 0 when not specified.
int sar_height; // Set to 0 when not specified.
int transfer_characteristics;
int color_primaries;
int matrix_coefficients;

bool timing_info_present_flag;
long num_units_in_tick;
Expand Down
6 changes: 4 additions & 2 deletions packager/media/codecs/h265_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,11 @@ H265Parser::Result H265Parser::ParseVuiParameters(int max_num_sub_layers_minus1,
bool colour_description_present_flag;
TRUE_OR_RETURN(br->ReadBool(&colour_description_present_flag));
if (colour_description_present_flag) {
TRUE_OR_RETURN(br->SkipBits(8)); // colour_primaries
TRUE_OR_RETURN(
br->ReadBits(8, &vui->color_primaries)); // color_primaries
TRUE_OR_RETURN(br->ReadBits(8, &vui->transfer_characteristics));
TRUE_OR_RETURN(br->SkipBits(8)); // matrix_coeffs
TRUE_OR_RETURN(
br->ReadBits(8, &vui->matrix_coefficients)); // matrix_coeffs
}
}

Expand Down
2 changes: 2 additions & 0 deletions packager/media/codecs/h265_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct H265VuiParameters {
int sar_width = 0;
int sar_height = 0;
int transfer_characteristics = 0;
int color_primaries = 0;
int matrix_coefficients = 0;

bool vui_timing_info_present_flag = false;
long vui_num_units_in_tick = 0;
Expand Down
4 changes: 4 additions & 0 deletions packager/media/codecs/hevc_decoder_configuration_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ bool HEVCDecoderConfigurationRecord::ParseInternal() {
RCHECK(parser.ParseSps(nalu, &sps_id) == H265Parser::kOk);
set_transfer_characteristics(
parser.GetSps(sps_id)->vui_parameters.transfer_characteristics);
set_color_primaries(
parser.GetSps(sps_id)->vui_parameters.color_primaries);
set_matrix_coefficients(
parser.GetSps(sps_id)->vui_parameters.matrix_coefficients);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions packager/media/crypto/subsample_generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ VideoStreamInfo GetVideoStreamInfo(Codec codec) {
const uint16_t kHeight = 20u;
const uint32_t kPixelWidth = 2u;
const uint32_t kPixelHeight = 3u;
const uint8_t kColorPrimaries = 0;
const uint8_t kMatrixCoefficients = 0;
const uint8_t kTransferCharacteristics = 0;
const int16_t kTrickPlayFactor = 0;
const uint8_t kNaluLengthSize = 1u;
Expand All @@ -85,8 +87,9 @@ VideoStreamInfo GetVideoStreamInfo(Codec codec) {
return VideoStreamInfo(
kTrackId, kTimeScale, kDuration, codec, H26xStreamFormat::kUnSpecified,
kCodecString, codec_config, codec_config_size, kWidth, kHeight,
kPixelWidth, kPixelHeight, kTransferCharacteristics, kTrickPlayFactor,
kNaluLengthSize, kLanguage, !kEncrypted);
kPixelWidth, kPixelHeight, kColorPrimaries, kMatrixCoefficients,
kTransferCharacteristics, kTrickPlayFactor, kNaluLengthSize, kLanguage,
!kEncrypted);
}

AudioStreamInfo GetAudioStreamInfo(Codec codec) {
Expand Down
7 changes: 7 additions & 0 deletions packager/media/event/muxer_listener_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ void AddVideoInfo(const VideoStreamInfo* video_stream_info,
video_info->set_transfer_characteristics(
video_stream_info->transfer_characteristics());
}
if (video_stream_info->color_primaries() > 0) {
video_info->set_color_primaries(video_stream_info->color_primaries());
}
if (video_stream_info->matrix_coefficients() > 0) {
video_info->set_matrix_coefficients(
video_stream_info->matrix_coefficients());
}
}

void AddAudioInfo(const AudioStreamInfo* audio_stream_info,
Expand Down
2 changes: 2 additions & 0 deletions packager/media/event/muxer_listener_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ std::shared_ptr<VideoStreamInfo> CreateVideoStreamInfo(
H26xStreamFormat::kUnSpecified, param.codec_string,
param.codec_config.data(), param.codec_config.size(), param.width,
param.height, param.pixel_width, param.pixel_height,
0, // color_primaries
0, // matrix_coefficients
0, // transfer_characteristics
0, // trick_play_factor
param.nalu_length_size, param.language, param.is_encrypted);
Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/mp2t/es_parser_h264.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ bool EsParserH264::UpdateVideoDecoderConfig(int pps_id) {
codec_fourcc, decoder_config_record[1], decoder_config_record[2],
decoder_config_record[3]),
decoder_config_record.data(), decoder_config_record.size(), coded_width,
coded_height, pixel_width, pixel_height, sps->transfer_characteristics, 0,
coded_height, pixel_width, pixel_height, sps->color_primaries,
sps->matrix_coefficients, sps->transfer_characteristics, 0,
nalu_length_size, std::string(), false);
DVLOG(1) << "Profile IDC: " << sps->profile_idc;
DVLOG(1) << "Level IDC: " << sps->level_idc;
Expand Down
6 changes: 4 additions & 2 deletions packager/media/formats/mp2t/es_parser_h265.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ bool EsParserH265::UpdateVideoDecoderConfig(int pps_id) {
pid(), kMpeg2Timescale, kInfiniteDuration, kCodecH265, stream_format,
decoder_config.GetCodecString(codec_fourcc), decoder_config_record.data(),
decoder_config_record.size(), coded_width, coded_height, pixel_width,
pixel_height, sps->vui_parameters.transfer_characteristics, 0,
nalu_length_size, std::string(), false);
pixel_height, sps->vui_parameters.color_primaries,
sps->vui_parameters.matrix_coefficients,
sps->vui_parameters.transfer_characteristics, 0, nalu_length_size,
std::string(), false);

// Video config notification.
new_stream_info_cb_(last_video_decoder_config_);
Expand Down
10 changes: 6 additions & 4 deletions packager/media/formats/mp2t/pes_packet_generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const uint32_t kWidth = 1280;
const uint32_t kHeight = 720;
const uint32_t kPixelWidth = 1;
const uint32_t kPixelHeight = 1;
const uint8_t kColorPrimaries = 0;
const uint8_t kMatrixCoefficients = 0;
const uint8_t kTransferCharacteristics = 0;
const uint16_t kTrickPlayFactor = 1;
const uint8_t kNaluLengthSize = 1;
Expand Down Expand Up @@ -125,8 +127,8 @@ std::shared_ptr<VideoStreamInfo> CreateVideoStreamInfo(Codec codec) {
kTrackId, kTimeScale, kDuration, codec,
H26xStreamFormat::kAnnexbByteStream, kCodecString, kVideoExtraData,
std::size(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTransferCharacteristics, kTrickPlayFactor, kNaluLengthSize, kLanguage,
kIsEncrypted));
kColorPrimaries, kMatrixCoefficients, kTransferCharacteristics,
kTrickPlayFactor, kNaluLengthSize, kLanguage, kIsEncrypted));
return stream_info;
}

Expand Down Expand Up @@ -358,8 +360,8 @@ TEST_F(PesPacketGeneratorTest, TimeStampScaling) {
kTrackId, kTestTimescale, kDuration, kH264Codec,
H26xStreamFormat::kAnnexbByteStream, kCodecString, kVideoExtraData,
std::size(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTransferCharacteristics, kTrickPlayFactor, kNaluLengthSize, kLanguage,
kIsEncrypted));
kColorPrimaries, kMatrixCoefficients, kTransferCharacteristics,
kTrickPlayFactor, kNaluLengthSize, kLanguage, kIsEncrypted));
EXPECT_TRUE(generator_.Initialize(*stream_info));

EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
Expand Down
Loading

0 comments on commit 3e7dda4

Please sign in to comment.