Skip to content

Commit

Permalink
feat: Parse dvvC box for Dolby Vision support (#6866)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Jun 20, 2024
1 parent 9f5b5a5 commit 69fe20f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/media/segment_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,39 @@ shaka.media.SegmentUtils = class {
case 'avc3':
codecBase = 'dvav';
break;
case 'av01':
codecBase = 'dav1';
break;
}
const parsedDVCCBox = shaka.util.Mp4BoxParsers.parseDVCC(
codecBase, box.reader, box.name);
videoCodecs.push(parsedDVCCBox.codec);
hasVideo = true;
})
.box('dvvC', (box) => {
let codecBase = baseBox || '';
switch (baseBox) {
case 'hvc1':
codecBase = 'dvh1';
break;
case 'hev1':
codecBase = 'dvhe';
break;
case 'avc1':
codecBase = 'dva1';
break;
case 'avc3':
codecBase = 'dvav';
break;
case 'av01':
codecBase = 'dav1';
break;
}
const parsedDVCCBox = shaka.util.Mp4BoxParsers.parseDVVC(
codecBase, box.reader, box.name);
videoCodecs.push(parsedDVCCBox.codec);
hasVideo = true;
})
.fullBox('vpcC', (box) => {
const codecBase = baseBox || '';
const parsedVPCCBox = shaka.util.Mp4BoxParsers.parseVPCC(
Expand All @@ -356,7 +383,12 @@ shaka.media.SegmentUtils = class {
hasVideo = true;
})
.box('av1C', (box) => {
const codecBase = baseBox || '';
let codecBase = baseBox || '';
switch (baseBox) {
case 'dav1':
codecBase = 'av01';
break;
}
const parsedAV1CBox = shaka.util.Mp4BoxParsers.parseAV1C(
codecBase, box.reader, box.name);
videoCodecs.push(parsedAV1CBox.codec);
Expand Down
32 changes: 32 additions & 0 deletions lib/util/mp4_box_parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,27 @@ shaka.util.Mp4BoxParsers = class {
return {codec};
}

/**
* Parses a DVVC box.
* @param {string} codecBase
* @param {!shaka.util.DataViewReader} reader
* @param {string} boxName
* @return {!shaka.util.ParsedDVVCBox}
*/
static parseDVVC(codecBase, reader, boxName) {
const Mp4BoxParsers = shaka.util.Mp4BoxParsers;
reader.skip(2); // Skip "dv_version_major" and "dv_version_minor"
const thirdByte = reader.readUint8();
const fourthByte = reader.readUint8();
const profile = (thirdByte >> 1) & 0x7f;
const level = ((thirdByte << 5) & 0x20) | ((fourthByte >> 3) & 0x1f);
const codec = codecBase + '.' +
Mp4BoxParsers.addLeadingZero_(profile) + '.' +
Mp4BoxParsers.addLeadingZero_(level);

return {codec};
}

/**
* Parses a VPCC box.
* @param {string} codecBase
Expand Down Expand Up @@ -866,6 +887,17 @@ shaka.util.ParsedHVCCBox;
*/
shaka.util.ParsedDVCCBox;

/**
* @typedef {{
* codec: string
* }}
*
* @property {string} codec
*
* @exportDoc
*/
shaka.util.ParsedDVVCBox;

/**
* @typedef {{
* codec: string
Expand Down

0 comments on commit 69fe20f

Please sign in to comment.