Skip to content

Commit

Permalink
feat(Dash): Extract HDR metadata from DASH manifests (shaka-project#3226
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Álvaro Velad Galván authored Mar 17, 2021
1 parent 78357ed commit f23ee0a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ shaka.dash.DashParser = class {
this.config_.dash.autoCorrectDrift);
}

const profiles = mpd.getAttribute('profiles') || '';

/** @type {shaka.dash.DashParser.Context} */
const context = {
// Don't base on updatePeriod_ since emsg boxes can cause manifest
Expand All @@ -374,6 +376,7 @@ shaka.dash.DashParser = class {
bandwidth: 0,
indexRangeWarningGiven: false,
availabilityTimeOffset: availabilityTimeOffset,
profiles: profiles.split(','),
};

const periodsAndDuration = this.parsePeriods_(context, baseUris, mpd);
Expand Down Expand Up @@ -1111,6 +1114,16 @@ shaka.dash.DashParser = class {
}
}

let hdr;
const profiles = context.profiles;
const codecs = context.representation.codecs;

const hevcHDR = 'http://dashif.org/guidelines/dash-if-uhd#hevc-hdr-pq10';
if (profiles.includes(hevcHDR) && (codecs.includes('hvc1.2.4.L153.B0') ||
codecs.includes('hev1.2.4.L153.B0'))) {
hdr = 'PQ';
}

/** @type {shaka.extern.Stream} */
const stream = {
id: this.globalId_++,
Expand Down Expand Up @@ -1145,6 +1158,7 @@ shaka.dash.DashParser = class {
audioSamplingRate: context.representation.audioSamplingRate,
spatialAudio: spatialAudio,
closedCaptions,
hdr,
tilesLayout,
};
return stream;
Expand Down Expand Up @@ -1768,7 +1782,8 @@ shaka.dash.DashParser.InheritanceFrame;
* representation: ?shaka.dash.DashParser.InheritanceFrame,
* bandwidth: number,
* indexRangeWarningGiven: boolean,
* availabilityTimeOffset: number
* availabilityTimeOffset: number,
* profiles: !Array.<string>
* }}
*
* @description
Expand All @@ -1794,6 +1809,9 @@ shaka.dash.DashParser.InheritanceFrame;
* True if the warning about SegmentURL@indexRange has been printed.
* @property {number} availabilityTimeOffset
* The sum of the availabilityTimeOffset values that apply to the element.
* @property {!Array.<string>} profiles
* Profiles of DASH are defined to enable interoperability and the signaling
* of the use of features.
*/
shaka.dash.DashParser.Context;

Expand Down
31 changes: 31 additions & 0 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,37 @@ describe('DashParser Manifest', () => {
expect(textStream.forced).toBe(true);
});

it('supports HDR signaling', async () => {
const hdrProfile =
'http://dashif.org/guidelines/dash-if-uhd#hevc-hdr-pq10';
const manifestText = [
`<MPD minBufferTime="PT75S" profiles="${hdrProfile}">`,
' <Period id="1" duration="PT30S">',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <Representation codecs="hvc1.2.4.L153.B0">',
' <BaseURL>v-sd.mp4</BaseURL>',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet id="3" mimeType="audio/mp4">',
' <Representation id="audio-en">',
' <BaseURL>a-en.mp4</BaseURL>',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');

fakeNetEngine.setResponseText('dummy://foo', manifestText);

/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.variants.length).toBe(1);
const stream = manifest.variants[0].video;
expect(stream.hdr).toBe('PQ');
});

it('Does not error when image adaptation sets are present', async () => {
const manifestText = [
'<MPD minBufferTime="PT75S">',
Expand Down

0 comments on commit f23ee0a

Please sign in to comment.