baa54acc by David LaPalomento

Parse out frame payload from ID3 frames

Fix up karma configuration so tests pass from the command line. Attach the bytes of the ID3 frame body in metadata stream events.
1 parent 622d5984
......@@ -49,13 +49,7 @@
// http://id3.org/id3v2.3.0#ID3v2_frame_overview
chunk.frames = [];
do {
chunk.frames.push({
id: String.fromCharCode(chunk.data[frameStart]) +
String.fromCharCode(chunk.data[frameStart + 1]) +
String.fromCharCode(chunk.data[frameStart + 2]) +
String.fromCharCode(chunk.data[frameStart + 3])
});
// determine the number of bytes in this frame
frameSize = (chunk.data[frameStart + 4] << 24) |
(chunk.data[frameStart + 5] << 16) |
(chunk.data[frameStart + 6] << 8) |
......@@ -63,13 +57,22 @@
if (frameSize < 1) {
return videojs.log('Malformed ID3 frame encountered. Skipping metadata parsing.');
}
chunk.frames.push({
id: String.fromCharCode(chunk.data[frameStart]) +
String.fromCharCode(chunk.data[frameStart + 1]) +
String.fromCharCode(chunk.data[frameStart + 2]) +
String.fromCharCode(chunk.data[frameStart + 3]),
data: chunk.data.subarray(frameStart + 10, frameStart + frameSize + 10)
});
frameStart += 10; // advance past the frame header
frameStart += frameSize; // advance past the frame body
} while (frameStart < tagSize)
} while (frameStart < tagSize);
this.trigger('data', chunk);
};
};
MetadataStream.prototype = new videojs.Hls.Stream();
videojs.Hls.MetadataStream = MetadataStream;
})(window, videojs);
})(window, window.videojs);
......
......@@ -80,14 +80,15 @@ module.exports = function(config) {
'../node_modules/pkcs7/dist/pkcs7.unpad.js',
'../test/karma-qunit-shim.js',
'../src/videojs-hls.js',
'../src/xhr.js',
'../src/stream.js',
'../src/flv-tag.js',
'../src/exp-golomb.js',
'../src/h264-stream.js',
'../src/aac-stream.js',
'../src/metadata-stream.js',
'../src/segment-parser.js',
'../src/stream.js',
'../src/m3u8/m3u8-parser.js',
'../src/xhr.js',
'../src/playlist-loader.js',
'../src/decrypter.js',
'../tmp/manifests.js',
......
......@@ -44,14 +44,15 @@ module.exports = function(config) {
'../node_modules/pkcs7/dist/pkcs7.unpad.js',
'../test/karma-qunit-shim.js',
'../src/videojs-hls.js',
'../src/xhr.js',
'../src/stream.js',
'../src/flv-tag.js',
'../src/exp-golomb.js',
'../src/h264-stream.js',
'../src/aac-stream.js',
'../src/metadata-stream.js',
'../src/segment-parser.js',
'../src/stream.js',
'../src/m3u8/m3u8-parser.js',
'../src/xhr.js',
'../src/playlist-loader.js',
'../src/decrypter.js',
'../tmp/manifests.js',
......
......@@ -66,7 +66,15 @@
};
test('parses simple ID3 metadata out of PES packets', function() {
var events = [], id3Bytes, size;
var
events = [],
wxxxPayload = [
0x00 // text encoding. ISO-8859-1
].concat(stringToCString('ad tag URL'), // description
stringToInts('http://example.com/ad?v=1234&q=7')), // value
id3Bytes,
size;
metadataStream.on('data', function(event) {
events.push(event);
});
......@@ -84,9 +92,7 @@
// frame 0
// http://id3.org/id3v2.3.0#User_defined_text_information_frame
], id3Frame('WXXX',
[0x00], // text encoding. ISO-8859-1
stringToCString('ad tag URL'), // description
stringToInts('http://example.com/ad?v=1234&q=7')), // value
wxxxPayload), // value
// frame 1
// custom tag
id3Frame('XINF',
......@@ -115,11 +121,17 @@
equal(events.length, 1, 'parsed one tag');
equal(events[0].frames.length, 2, 'parsed two frames');
equal(events[0].frames[0].id, 'WXXX', 'parsed a WXXX frame');
deepEqual(new Uint8Array(events[0].frames[0].data),
new Uint8Array(wxxxPayload),
'attached the frame payload');
equal(events[0].frames[1].id, 'XINF', 'parsed a user-defined frame');
deepEqual(new Uint8Array(events[0].frames[1].data),
new Uint8Array([0x04, 0x03, 0x02, 0x01]),
'attached the frame payload');
});
test('skips non-ID3 metadata events', function() {
var events = [], id3Bytes, size;
var events = [];
metadataStream.on('data', function(event) {
events.push(event);
});
......@@ -143,5 +155,7 @@
// compressed frames
// encrypted frames
// frame groups
// too large/small tag size values
// too large/small frame size values
})(window, videojs);
})(window, window.videojs);
......