Skip to content

Commit

Permalink
feat: send ID3 tag even when a frame has malformed content (#408)
Browse files Browse the repository at this point in the history
Enables sending ID3 tag with as many frames as could be parsed.

Co-authored-by: Garrett Singer <[email protected]>
  • Loading branch information
pszemus and gesinger authored May 26, 2022
1 parent fab387e commit 1da5d23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/m2ts/metadata-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ MetadataStream = function(options) {
if (frameSize < 1) {
this.trigger('log', {
level: 'warn',
message: 'Malformed ID3 frame encountered. Skipping metadata parsing.'
message: 'Malformed ID3 frame encountered. Skipping remaining metadata parsing.'
});
return;
// If the frame is malformed, don't parse any further frames but allow previous valid parsed frames
// to be sent along.
break;
}
frameHeader = String.fromCharCode(tag.data[frameStart],
tag.data[frameStart + 1],
Expand Down
23 changes: 22 additions & 1 deletion test/metadata-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ QUnit.test('triggers log for non-id3/invalid data', function(assert) {
assert.deepEqual(logs, [
{level: 'warn', message: 'Skipping unrecognized metadata packet'},
{level: 'warn', message: 'Skipping unrecognized metadata packet'},
{level: 'warn', message: 'Malformed ID3 frame encountered. Skipping metadata parsing.'}
{level: 'warn', message: 'Malformed ID3 frame encountered. Skipping remaining metadata parsing.'}
], 'logs as expected.');
});

Expand Down Expand Up @@ -518,6 +518,27 @@ QUnit.test('constructs the dispatch type', function(assert) {
assert.equal(metadataStream.dispatchType, '1503020100', 'built the dispatch type');
});

QUnit.test('should skip tag frame parsing on malformed frame, preserving previous frames', function(assert) {
var events = [],
validFrame = id3Frame('TIT2',
0x03, // utf-8
stringToCString('sample title')),
malformedFrame = id3Frame('WOAF'), // frame with size of 0B
tag = id3Tag(validFrame, malformedFrame);

metadataStream.on('data', function(event) {
events.push(event);
});

metadataStream.push({
type: 'timed-metadata',
data: new Uint8Array(tag)
})

assert.equal(events.length, 1, 'parsed 1 tag')
assert.equal(events[0].frames.length, 1, 'parsed one frame');
assert.equal(events[0].frames[0].key, 'TIT2');
});

QUnit.test('can parse PRIV frames in web worker', function(assert) {
var payload = stringToInts('arbitrary'),
Expand Down

0 comments on commit 1da5d23

Please sign in to comment.