Skip to content

Commit

Permalink
fix: Fix ID3 parsing in TS segments (shaka-project#4609)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Oct 25, 2022
1 parent 5157b44 commit 3b534fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/util/ts_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

goog.provide('shaka.util.TsParser');

goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.util.Id3Utils');
goog.require('shaka.util.Uint8ArrayUtils');


/**
Expand Down Expand Up @@ -342,17 +344,20 @@ shaka.util.TsParser = class {
*/
getMetadata() {
const metadata = [];
let id3Data = new Uint8Array(0);
for (const data of this.id3Data_) {
const pes = this.parsePES(data);
if (pes) {
metadata.push({
cueTime: pes.pts ? pes.pts / 90000 : null,
data: pes.data,
frames: shaka.util.Id3Utils.getID3Frames(pes.data),
dts: pes.dts,
pts: pes.pts,
});
}
goog.asserts.assert(data, 'We should have a data');
id3Data = shaka.util.Uint8ArrayUtils.concat(id3Data, data);
}
const pes = this.parsePES(id3Data);
if (pes) {
metadata.push({
cueTime: pes.pts ? pes.pts / 90000 : null,
data: pes.data,
frames: shaka.util.Id3Utils.getID3Frames(pes.data),
dts: pes.dts,
pts: pes.pts,
});
}
return metadata;
}
Expand Down
4 changes: 3 additions & 1 deletion test/util/ts_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ describe('TsParser', () => {
const metadata = new shaka.util.TsParser().parse(tsSegment)
.getMetadata();
expect(metadata).toBeTruthy();
expect(metadata.length).toBe(2);
expect(metadata.length).toBe(1);
const firstMetadata = metadata[0];
expect(firstMetadata.frames.length).toBe(2);
});

it('get the start time from a TS segment', async () => {
Expand Down

0 comments on commit 3b534fd

Please sign in to comment.