diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index f65664479b..538a62e6aa 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -688,11 +688,9 @@ shaka.media.MediaSourceEngine = class { goog.asserts.assert( box.version == 0 || box.version == 1, 'TFDT version can only be 0 or 1'); - - const parsedTFDTBox = shaka.util.Mp4BoxParsers.parseTFDT( + const parsed = shaka.util.Mp4BoxParsers.parseTFDTInaccurate( box.reader, box.version); - const baseTime = parsedTFDTBox.baseMediaDecodeTime; - startTime = baseTime / timescale; + startTime = parsed.baseMediaDecodeTime / timescale; parsedMedia = true; box.parser.stop(); }).parse(data, /* partialOkay= */ true); diff --git a/lib/util/mp4_box_parsers.js b/lib/util/mp4_box_parsers.js index 3deeb5f8ef..4658e1d495 100644 --- a/lib/util/mp4_box_parsers.js +++ b/lib/util/mp4_box_parsers.js @@ -66,6 +66,29 @@ shaka.util.Mp4BoxParsers = class { }; } + /** + * Parses a TFDT Box, with a loss of precision beyond 53 bits. + * Use only when exact integers are not required, e.g. when + * dividing by the timescale. + * + * @param {!shaka.util.DataViewReader} reader + * @param {number} version + * @return {!shaka.util.ParsedTFDTBox} + */ + static parseTFDTInaccurate(reader, version) { + if (version == 1) { + const high = reader.readUint32(); + const low = reader.readUint32(); + return { + baseMediaDecodeTime: (high * Math.pow(2, 32)) + low, + }; + } else { + return { + baseMediaDecodeTime: reader.readUint32(), + }; + } + } + /** * Parses a MDHD Box. * @param {!shaka.util.DataViewReader} reader