-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fmp4 emsg ID3 support (#1370)
* feat: add fmp4 emsg ID3 support * fix worker function * add id3fn to finishLoading * fix captions tests * add media segment request test
- Loading branch information
Showing
3 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1357,6 +1357,17 @@ QUnit.test('non-TS segment will get parsed for captions', function(assert) { | |
} | ||
}); | ||
} | ||
|
||
if (event.action === 'probeEmsgID3') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'probeEmsgID3', | ||
emsgData: event.data, | ||
id3Frames: [] | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
mediaSegmentRequest({ | ||
|
@@ -1498,6 +1509,17 @@ QUnit.test('non-TS segment will get parsed for captions on next segment request | |
} | ||
}); | ||
} | ||
|
||
if (event.action === 'probeEmsgID3') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'probeEmsgID3', | ||
emsgData: event.data, | ||
id3Frames: [] | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
mediaSegmentRequest({ | ||
|
@@ -1553,3 +1575,133 @@ QUnit.test('non-TS segment will get parsed for captions on next segment request | |
// Simulate receiving the init segment after the media | ||
this.standardXHRResponse(initReq, mp4VideoInit()); | ||
}); | ||
|
||
QUnit.test('can get emsg ID3 frames from fmp4 segment', function(assert) { | ||
const done = assert.async(); | ||
let gotEmsgId3 = 0; | ||
let gotData = 0; | ||
// expected frame data | ||
const id3Frames = [{ | ||
cueTime: 1, | ||
duration: 0, | ||
frames: [{ | ||
id: 'TXXX', | ||
description: 'foo bar', | ||
data: { key: 'value' } | ||
}, | ||
{ | ||
id: 'PRIV', | ||
owner: '[email protected]', | ||
// 'foo' | ||
data: new Uint8Array([0x66, 0x6F, 0x6F]) | ||
}] | ||
}, | ||
{ | ||
cueTime: 3, | ||
duration: 0, | ||
frames: [{ | ||
id: 'PRIV', | ||
owner: '[email protected]', | ||
// 'bar' | ||
data: new Uint8Array([0x62, 0x61, 0x72]) | ||
}, | ||
{ | ||
id: 'TXXX', | ||
description: 'bar foo', | ||
data: { key: 'value' } | ||
}] | ||
}]; | ||
const transmuxer = new videojs.EventTarget(); | ||
|
||
transmuxer.postMessage = (event) => { | ||
if (event.action === 'pushMp4Captions') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'mp4Captions', | ||
data: event.data, | ||
captions: 'foo bar', | ||
logs: [] | ||
} | ||
}); | ||
} | ||
|
||
if (event.action === 'probeMp4StartTime') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'probeMp4StartTime', | ||
data: event.data, | ||
timingInfo: {} | ||
} | ||
}); | ||
} | ||
|
||
if (event.action === 'probeMp4Tracks') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'probeMp4Tracks', | ||
data: event.data, | ||
tracks: [{type: 'video', codec: 'avc1.4d400d'}] | ||
} | ||
}); | ||
} | ||
|
||
if (event.action === 'probeEmsgID3') { | ||
transmuxer.trigger({ | ||
type: 'message', | ||
data: { | ||
action: 'probeEmsgID3', | ||
emsgData: event.data, | ||
id3Frames | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
mediaSegmentRequest({ | ||
xhr: this.xhr, | ||
xhrOptions: this.xhrOptions, | ||
decryptionWorker: this.mockDecrypter, | ||
segment: { | ||
transmuxer, | ||
resolvedUri: 'mp4Video.mp4', | ||
map: { | ||
resolvedUri: 'mp4VideoInit.mp4' | ||
} | ||
}, | ||
progressFn: this.noop, | ||
trackInfoFn: this.noop, | ||
timingInfoFn: this.noop, | ||
id3Fn: (segment, _id3Frames) => { | ||
gotEmsgId3++; | ||
assert.deepEqual(_id3Frames, id3Frames, 'got expected emsg id3 data.'); | ||
}, | ||
captionsFn: this.noop, | ||
dataFn: (segment, segmentData) => { | ||
gotData++; | ||
assert.ok(segmentData, 'init segment bytes in map'); | ||
assert.ok(segment.map.tracks, 'added tracks'); | ||
assert.ok(segment.map.tracks.video, 'added video track'); | ||
}, | ||
doneFn: () => { | ||
assert.equal(gotEmsgId3, 1, 'received emsg ID3 event'); | ||
assert.equal(gotData, 1, 'received data event'); | ||
transmuxer.off(); | ||
done(); | ||
} | ||
}); | ||
assert.equal(this.requests.length, 2, 'there are two requests'); | ||
|
||
const initReq = this.requests.shift(); | ||
const segmentReq = this.requests.shift(); | ||
|
||
assert.equal(initReq.uri, 'mp4VideoInit.mp4', 'the first request is for the init segment'); | ||
assert.equal(segmentReq.uri, 'mp4Video.mp4', 'the second request is for a segment'); | ||
|
||
// Simulate receiving the media first | ||
this.standardXHRResponse(segmentReq, mp4Video()); | ||
// Simulate receiving the init segment after the media | ||
this.standardXHRResponse(initReq, mp4VideoInit()); | ||
}); |