Skip to content

Multi-period refactor

Vinay Rosenberg requested to merge github/fork/MSOpenTech/development into development

Created by: KozhinM

Description of the changes: The player uses only one video element and only one MediaSource instead of multiple video elements. When manifest is loaded SourceBuffers are created only for the first Period. StreamController is subscribed to 'streamBufferingCompleted' event which occurs after the latest segment of the current Period has been appended to the buffer. Once the event occurs StreamController activates the next Period. Activation means that all the necessary components for scheduling and buffering are initialized. At this point the player makes an attempt to create SourceBuffers for the next Period. If it succeeds, the second Period starts buffering data the same way as the first one. If MediaSource cannot have more buffers then the second Period still starts loading segments, but all of them are queued in a VirtualBuffer. When time to switch comes StreamController detaches MediaSource and then immediately attaches it again. This operation resets MediaSource so that it 'loses' old buffers and new ones could be created. StreamController makes another attempt to create SourceBuffers for the second Period. This time it always succeeds since the old buffers are gone. A new Period starts extracting pre-loaded segments from VirtualBuffer and appends them to the SourceBuffer. Playback of the second Period starts.

Buffer level metrics are calculated as 'actual' buffer size (based on a time range from SourceBuffer) + virtual buffer of both current and next Periods.

Also, instead of a single 'streamswitched' event MediaPlayer now has "streamswitchstarted" and "streamswitchcompleted" events. Thus, if necessary, a page can listen to these events and provide some visual effects during switch time for a better user experience (e.g. loading indicator and/or the last frame of the current Period).

Merge request reports