Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DASH): Add video transfer characteristics. #1210

Merged
merged 11 commits into from
Sep 8, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<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.022683143615723S">
<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: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">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<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.022683143615723S">
<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: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">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
Expand All @@ -15,6 +16,7 @@
</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: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">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<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.802799940109253S">
<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: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">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
Expand Down
8 changes: 8 additions & 0 deletions packager/mpd/base/adaptation_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ base::Optional<xml::XmlNode> AdaptationSet::GetXml() {
}
}

// https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf - 4.2.5.1
if (IsVideo() && transfer_characteristics_ > 0 &&
!adaptation_set.AddSupplementalProperty(
"urn:mpeg:mpegB:cicp:TransferCharacteristics",
std::to_string(transfer_characteristics_))) {
return base::nullopt;
}

// Note: must be checked before checking segments_aligned_ (below). So that
// segments_aligned_ is set before checking below.
if (mpd_options_.mpd_type == MpdType::kStatic) {
Expand Down
14 changes: 14 additions & 0 deletions packager/mpd/base/adaptation_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ class AdaptationSet {
/// @param codec is the new codec to be set.
void set_codec(const std::string& codec) { codec_ = codec; };

/// @return transfer_characteristics.
const uint32_t transfer_characteristics() const {
return transfer_characteristics_;
}

/// Set AdaptationSet's video transfer characteristics.
/// @param transfer_characteristics is the video transfer characteristics.
void set_transfer_characteristics(const uint32_t& transfer_characteristics) {
transfer_characteristics_ = transfer_characteristics;
};

protected:
/// @param language is the language of this AdaptationSet. Mainly relevant for
/// audio.
Expand Down Expand Up @@ -314,6 +325,9 @@ class AdaptationSet {
// and HD videos in different AdaptationSets can share the same trick play
// stream.
std::vector<const AdaptationSet*> trick_play_references_;

// Transfer characteristics.
uint32_t transfer_characteristics_ = 0;
};

} // namespace shaka
Expand Down
11 changes: 11 additions & 0 deletions packager/mpd/base/mpd_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ std::string GetAdaptationSetKey(const MediaInfo& media_info,
if (!ignore_codec) {
key.append(":");
key.append(GetBaseCodec(media_info));

if (GetBaseCodec(media_info).find("dvh") == 0) {
joeyparrish marked this conversation as resolved.
Show resolved Hide resolved
// Transfer characteristics for Dolby Vision (dvh1 or dvhe) must be PQ
// irrespective of value present in SPS VUI.
key.append(":");
key.append(std::to_string(kTransferFunctionPQ));
} else if (media_info.video_info().has_transfer_characteristics()) {
key.append(":");
key.append(
std::to_string(media_info.video_info().transfer_characteristics()));
}
}
key.append(":");
key.append(GetLanguage(media_info));
Expand Down
1 change: 1 addition & 0 deletions packager/mpd/base/mpd_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct SegmentInfo;
const char kEncryptedMp4Scheme[] = "urn:mpeg:dash:mp4protection:2011";
const char kPsshElementName[] = "cenc:pssh";
const char kMsproElementName[] = "mspr:pro";
const uint32_t kTransferFunctionPQ = 16;

bool HasVODOnlyFields(const MediaInfo& media_info);

Expand Down
16 changes: 16 additions & 0 deletions packager/mpd/base/period.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ bool Period::SetNewAdaptationSetAttributes(
}
}

// Set transfer characteristics.
// https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf - 4.2.5.1
// ISO/IEC 23001-8 MPEG systems technologies — Part 8: Coding-independent
// code points. https://en.wikipedia.org/wiki/Coding-independent_code_points
// - Common CCIP values.
// Dolby vision:
// https://professionalsupport.dolby.com/s/article/How-to-signal-Dolby-Vision-in-MPEG-DASH
// Transfer characteristics for Dolby Vision (dvh1 or dvhe) must be PQ
// irrespective of value present in SPS VUI.
if (new_adaptation_set->codec().find("dvh") == 0) {
new_adaptation_set->set_transfer_characteristics(kTransferFunctionPQ);
} else if (media_info.video_info().has_transfer_characteristics()) {
new_adaptation_set->set_transfer_characteristics(
media_info.video_info().transfer_characteristics());
}

} else if (media_info.has_text_info()) {
// IOP requires all AdaptationSets to have (sub)segmentAlignment set to
// true, so carelessly set it to true.
Expand Down
Loading