Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for DASHEventMessageBox Version 1 #3147

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ Toshihiro Suzuki <t.suzuki326@gmail.com>
uStudio Inc. <*@ustudio.com>
Verizon Digital Media Services <*@verizondigitalmedia.com>
Vincent Valot <valot.vince@gmail.com>
Prakash <duggaraju@gmail.com>


1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ Vignesh Venkatasubramanian <vigneshv@google.com>
Vincent Valot <valot.vince@gmail.com>
Yohann Connell <robinconnell@google.com>
Adrián Gómez Llorente <adgllorente@gmail.com>
Prakash Duggaraju <duggaraju@gmail.com>
53 changes: 45 additions & 8 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,19 +1567,56 @@ shaka.media.StreamingEngine = class {
* scheme_id_uri for which emsg boxes should be parsed.
* @param {!shaka.extern.ParsedBox} box
* @private
* https://dashif-documents.azurewebsites.net/Events/master/event.html#emsg-format
* aligned(8) class DASHEventMessageBox
* extends FullBox(‘emsg’, version, flags = 0){
* if (version==0) {
* string scheme_id_uri;
* string value;
* unsigned int(32) timescale;
* unsigned int(32) presentation_time_delta;
* unsigned int(32) event_duration;
* unsigned int(32) id;
* } else if (version==1) {
* unsigned int(32) timescale;
* unsigned int(64) presentation_time;
* unsigned int(32) event_duration;
* unsigned int(32) id;
* string scheme_id_uri;
* string value;
* }
* unsigned int(8) message_data[];
*/
parseEMSG_(reference, emsgSchemeIdUris, box) {
const schemeId = box.reader.readTerminatedString();
// Read the rest of the data.
const value = box.reader.readTerminatedString();
const timescale = box.reader.readUint32();
const presentationTimeDelta = box.reader.readUint32();
const eventDuration = box.reader.readUint32();
const id = box.reader.readUint32();
let timescale;
let id;
let eventDuration;
let schemeId;
let startTime;
let presentationTimeDelta;
let value;

if (box.version === 0) {
schemeId = box.reader.readTerminatedString();
value = box.reader.readTerminatedString();
timescale = box.reader.readUint32();
presentationTimeDelta = box.reader.readUint32();
eventDuration = box.reader.readUint32();
id = box.reader.readUint32();
startTime = reference.startTime + (presentationTimeDelta / timescale);
} else {
timescale = box.reader.readUint32();
const pts = box.reader.readUint64();
startTime = pts / timescale;
presentationTimeDelta = startTime - reference.startTime;
eventDuration = box.reader.readUint32();
id = box.reader.readUint32();
schemeId = box.reader.readTerminatedString();
value = box.reader.readTerminatedString();
}
const messageData = box.reader.readBytes(
box.reader.getLength() - box.reader.getPosition());

const startTime = reference.startTime + (presentationTimeDelta / timescale);

// See DASH sec. 5.10.3.3.1
// If a DASH client detects an event message box with a scheme that is not
Expand Down
21 changes: 21 additions & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,27 @@ describe('StreamingEngine', () => {
expect(event.detail).toEqual(emsgObj);
});

it('raises an event for registered embedded v1 emsg boxes ', async () => {
// same event but verison 1.
const v1EmsgSegment = Uint8ArrayUtils.fromHex(
'0000003f656d7367010000000000000100000000000000080000ffff00000001' +
'666f6f3a6261723a637573746f6d64617461736368656d6500310074657374');
segmentData[ContentType.VIDEO].segments[0] = v1EmsgSegment;
videoStream.emsgSchemeIdUris = [emsgObj.schemeIdUri];

// Here we go!
streamingEngine.switchVariant(variant);
streamingEngine.switchTextStream(textStream);
await streamingEngine.start();
playing = true;
await runTest();

expect(onEvent).toHaveBeenCalledTimes(1);

const event = onEvent.calls.argsFor(0)[0];
expect(event.detail).toEqual(emsgObj);
});

it('raises multiple events', async () => {
const dummyBox =
shaka.util.Uint8ArrayUtils.fromHex('0000000c6672656501020304');
Expand Down