Skip to content

Commit

Permalink
fix: Handle empty media segments for Mp4VttParser (shaka-project#5131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaelkaim committed Apr 4, 2023
1 parent c2a59d0 commit 6fd44c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/text/mp4_vtt_parser.js
Expand Up @@ -97,6 +97,10 @@ shaka.text.Mp4VttParser = class {
* @export
*/
parseMedia(data, time) {
if (!data.length) {
return [];
}

if (!this.timescale_) {
// Missing timescale for VTT content. We should have seen the init
// segment.
Expand Down
8 changes: 8 additions & 0 deletions test/text/mp4_vtt_parser_unit.js
Expand Up @@ -171,6 +171,14 @@ describe('Mp4VttParser', () => {
verifyHelper(cues, result);
});

it('handles empty media segments', () => {
const parser = new shaka.text.Mp4VttParser();
parser.parseInit(vttInitSegment);
const time = {periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0};
const result = parser.parseMedia(new Uint8Array(0), time);
verifyHelper([], result);
});

it('rejects init segment with no vtt', () => {
const error = shaka.test.Util.jasmineError(new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
Expand Down

0 comments on commit 6fd44c4

Please sign in to comment.