Iraj Sodagar, irajs@live.com
Tencent America
2021-05-17
This document provides an extended W3C Media Source Extensions (MSE) model for the processing of DASH inband events.
Note: The current MSE specification does not support the processing of inband events and this document is just one possible illustrative design on how MSE can be extended to support such functionality.
See https://www.w3.org/TR/media-timed-events/#event-triggering
For those events that the application has subscribed to receive, the API should:
- Generate a DOM event when an in-band media timed event cue is parsed from the media container or media stream (DASH-IF on-receive mode).
- Generate DOM events when the current media playback position reaches the start time and the end time of a media timed event cue during playback (DASH-IF on-start mode). This applies equally to cues generated by the user agent when parsed from the media container and cues added by the web application.
In general, it is not possible for the UA to know which dispatch mode to use for any given event type. So we introduce the following API so that the web application can tell the UA:
enum DispatchMode {
"onstart",
"onreceive"
};
interface InbandEventTrack extends TextTrack {
undefined subscribe(DOMString eventType, DispatchMode dispatchMode);
undefined unsubscribe(DOMString eventType);
};
TODO: How to construct
eventType
from emsgscheme_id_uri
andvalue
?
TODO: How to construct an
InbandEventTrack
? Some UAs already process inband events usingTextTrack
and create theTextTrack
automatically.
The process@append rule defines how the inband events of a segment are processed, i.e. parsed, and dispatched or scheduled to dispatch at the time of appending the segment to the MSE SourceBuffer
using appendBuffer()
.
In the case of an inband event whose eventType
has not been subscribed by the web application:
- Discard the event
In the case of an inband event whose eventType
has been subscribed by the web application with the onreceive dispatch mode:
- If the event end time is not smaller than the current playback position, and
- If this event or an equivalent has not been dispatched before,
Then the dispatcher dispatches the event immediately.
In the case of an inband event whose eventType
has been subscribed by the web application with the onstart dispatch mode:
- If the current playback position is not smaller than the event start time, and
- If the current playback position is not equal or larger than the event end time, and
- If this event or an equivalent has not been dispatched before,
Then the event is stored in a dispatch buffer for dispatching at the event start time.
Figure 1 demonstrates an inband event with the onstart dispatch mode relative to the MSE timing model.
Figure 1. Media source and in-band event dispatch buffers
Figure 2 demonstrates an example of the overlapping events with onstart dispatch mode.
Figure 2. Event buffer model example for onstart events
As is shown above, emsgs E0, E1, and E2 are mapped to the dispatch buffer. With the initial appending of the S1 media segment to the media buffer, the ranges between the event's start and the event's end are marked in the dispatch buffer for E0 and E1.
When S2 is appended to the media buffer, in this case since E2 overlaps with E1 in the dispatch buffer, the corresponding range in the dispatched first is divided into 3 subranges, as shown in the figure.
Figure 3 demonstrates an example of an overwrite, in which the segment S2 is overwritten by a new segment S2' (that does not contain any emsgs) and has a duration that only covers a portion of S2 in the media buffer.
Figure 3. Overwrite of a part of a segment with events having onstart dispatch mode
As shown, since the event E2 has the onstart dispatch mode, its range in the dispatch buffer is unchanged.
- Applications inputs to DASH client
- Subscribe SchemeIdURI/value
- Provide dispatch mode
- Event buffer initialization:
- Event dispatch (range of event purge may go beyond media buffer)
- Set Presentation Time Offset (PTO)
Add the following steps to the MSE Segment Parser Loop, which is called from the Buffer Append Algorithm. After step 6.2., which describes handling of coded frames, add:
- If the input buffer contains one or more inband event messages, then run the inband event processing algorithm.
The inband event processing algorithm is a new algorithm which we propose to add to MSE.
When inband event messages have been parsed by the segment parser loop then the following steps are run:
- For each inband event message in the media segment run the following steps:
- Parse the emsg
- Generate the
eventType
from the emsg.scheme_id_uri and emsg.value - Look up the
eventType
in theInbandEventTrack
's list of subscribed event types- If not present, discard the emsg and abort these steps
- Calculate the
startTime
andendTime
values for theDataCue
:- For emsg v0 (esmg.version = 0): startTime = segment_start + emsg.presentation_time_delta / emsg.time_scale
- For emsg v1 (emsg.version = 1): startTime = emsg.presentation_time / emsg.timescale
- If emsg.duration is 0xFFFFFFFF then endTime = +Infinity, else endTime = startTime + emsg.duration / emsg.timescale
- If there is an equivalent event message in the
InbandEventTrack
's list of text track cues, discard the event message and abort these steps. An event message is equivalent if itsid
,scheme_id_uri
, andvalue
values are the same those of any existing - Construct a
DataCue
instance with the following attributes:- startTime (as calculated above)
- endTime (as calculated above)
- id = emsg.id
- pauseOnExit = false
- type = emsg.scheme_id_uri
- value = { data: emsg.message_data, emsgValue: emsg.value }
- If the subscription's dispatch mode is onreceive, queue a task to fire an event named
addcue
at theInbandEventTrack
object with thecue
attribute initialized to the newDataCue
object - If the subscription's dispatch mode is onstart, run the HTML
addCue()
steps with the newDataCue
object
TODO: Firing of cue
enter
andexit
for event messages in onstart dispatch mode is handled by the HTML time marches on steps
- Find the events occurring in the dispatch buffer at the playback position.
- For each event
- If its emsg.id is not in the "already-dispatched" table,
- Dispatch the event
- Add its emsg.id to the "already-dispatched" table
- Remove the event from the dispatch buffer
- Otherwise, remove the event from the dispatch buffer
- If its emsg.id is not in the "already-dispatched" table,
TODO: Purging is controlled by the web application, by calling SourceBuffer.remove(startTime, endTime). The MSE Range Removal algorithm applies. Should this algorithm also remove cues that lie in the removed time range?
In a purge operation, either a range from the start or a range from the end of the media buffer is purged. This range is referred to as the "purged-range" in this subclause.
- If any event in the dispatch buffer overlaps with the purged-range
- Split the event into two events around the purge-range boundary
- Remove the purged-range from the dispatch buffer