Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

MediaGroups: various bug fixes and refactor #1243

Merged
merged 12 commits into from
Sep 18, 2017
597 changes: 38 additions & 559 deletions src/master-playlist-controller.js

Large diffs are not rendered by default.

751 changes: 751 additions & 0 deletions src/media-groups.js

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ const PlaylistLoader = function(srcUrl, hls, withCredentials) {
if (this.media_) {
this.trigger('mediachanging');
}

request = this.hls_.xhr({
uri: resolveUrl(loader.master.uri, playlist.uri),
withCredentials
Expand Down Expand Up @@ -385,6 +386,7 @@ const PlaylistLoader = function(srcUrl, hls, withCredentials) {
}

loader.state = 'HAVE_CURRENT_METADATA';

request = this.hls_.xhr({
uri: resolveUrl(loader.master.uri, loader.media().uri),
withCredentials
Expand All @@ -397,22 +399,11 @@ const PlaylistLoader = function(srcUrl, hls, withCredentials) {
if (error) {
return playlistRequestError(request, loader.media().uri, 'HAVE_METADATA');
}

haveMetadata(request, loader.media().uri);
});
});

// setup initial sync info
loader.on('firstplay', function() {
let playlist = loader.media();

if (playlist) {
playlist.syncInfo = {
mediaSequence: playlist.mediaSequence,
time: 0
};
}
});

/**
* pause loading of the playlist
*/
Expand All @@ -424,6 +415,19 @@ const PlaylistLoader = function(srcUrl, hls, withCredentials) {
// started, so reset to an unstarted state.
loader.started = false;
}
// Need to restore state now that no activity is happening
if (loader.state === 'SWITCHING_MEDIA') {
// if the loader was in the process of switching media, it should either return to
// HAVE_MASTER or HAVE_METADATA depending on if the loader has loaded a media
// playlist yet. This is determined by the existence of loader.media_
if (loader.media_) {
loader.state = 'HAVE_METADATA';
} else {
loader.state = 'HAVE_MASTER';
}
} else if (loader.state === 'HAVE_CURRENT_METADATA') {
loader.state = 'HAVE_METADATA';
}
};

/**
Expand Down
12 changes: 11 additions & 1 deletion src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export default class SyncController extends videojs.EventTarget {
* @param {SegmentInfo} segmentInfo - The current active request information
*/
probeSegmentInfo(segmentInfo) {
let segment = segmentInfo.segment;
const segment = segmentInfo.segment;
const playlist = segmentInfo.playlist;
let timingInfo;

if (segment.map) {
Expand All @@ -370,6 +371,15 @@ export default class SyncController extends videojs.EventTarget {
if (timingInfo) {
if (this.calculateSegmentTimeMapping_(segmentInfo, timingInfo)) {
this.saveDiscontinuitySyncInfo_(segmentInfo);

// If the playlist does not have sync information yet, record that information
// now with segment timing information
if (!playlist.syncInfo) {
playlist.syncInfo = {
mediaSequence: playlist.mediaSequence + segmentInfo.mediaIndex,
time: segment.start
};
}
}
}
}
Expand Down
53 changes: 0 additions & 53 deletions src/videojs-contrib-hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,6 @@ Hls.isSupported = function() {
'your player\'s techOrder.');
};

const USER_AGENT = window.navigator && window.navigator.userAgent || '';

/**
* Determines whether the browser supports a change in the audio configuration
* during playback. Currently only Firefox 48 and below do not support this.
* window.isSecureContext is a propterty that was added to window in firefox 49,
* so we can use it to detect Firefox 49+.
*
* @return {Boolean} Whether the browser supports audio config change during playback
*/
Hls.supportsAudioInfoChange_ = function() {
if (videojs.browser.IS_FIREFOX) {
let firefoxVersionMap = (/Firefox\/([\d.]+)/i).exec(USER_AGENT);
let version = parseInt(firefoxVersionMap[1], 10);

return version >= 49;
}
return true;
};

const Component = videojs.getComponent('Component');

/**
Expand Down Expand Up @@ -256,15 +236,6 @@ class HlsHandler extends Component {
}
});

this.audioTrackChange_ = () => {
this.masterPlaylistController_.setupAudio();
this.tech_.trigger({type: 'usage', name: 'hls-audio-change'});
};

this.textTrackChange_ = () => {
this.masterPlaylistController_.setupSubtitles();
};

this.on(this.tech_, 'play', this.play);
}

Expand Down Expand Up @@ -444,24 +415,11 @@ class HlsHandler extends Component {
this.tech_.one('canplay',
this.masterPlaylistController_.setupFirstPlay.bind(this.masterPlaylistController_));

this.masterPlaylistController_.on('sourceopen', () => {
this.tech_.audioTracks().addEventListener('change', this.audioTrackChange_);
this.tech_.remoteTextTracks().addEventListener('change', this.textTrackChange_);
});

this.masterPlaylistController_.on('selectedinitialmedia', () => {
// Add the manual rendition mix-in to HlsHandler
renditionSelectionMixin(this);
});

this.masterPlaylistController_.on('audioupdate', () => {
// clear current audioTracks
this.tech_.clearTracks('audio');
this.masterPlaylistController_.activeAudioGroup().forEach((audioTrack) => {
this.tech_.audioTracks().addTrack(audioTrack);
});
});

// the bandwidth of the primary segment loader is our best
// estimate of overall bandwidth
this.on(this.masterPlaylistController_, 'progress', function() {
Expand Down Expand Up @@ -508,15 +466,6 @@ class HlsHandler extends Component {
}
}

/**
* a helper for grabbing the active audio group from MasterPlaylistController
*
* @private
*/
activeAudioGroup_() {
return this.masterPlaylistController_.activeAudioGroup();
}

/**
* Begin playing the video.
*/
Expand Down Expand Up @@ -558,8 +507,6 @@ class HlsHandler extends Component {
if (this.qualityLevels_) {
this.qualityLevels_.dispose();
}
this.tech_.audioTracks().removeEventListener('change', this.audioTrackChange_);
this.tech_.remoteTextTracks().removeEventListener('change', this.textTrackChange_);
super.dispose();
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/vtt-segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,25 @@ export default class VTTSegmentLoader extends SegmentLoader {
/**
* Set a subtitle track on the segment loader to add subtitles to
*
* @param {TextTrack} track
* @param {TextTrack=} track
* The text track to add loaded subtitles to
* @return {TextTrack}
* Returns the subtitles track
*/
track(track) {
if (typeof track === 'undefined') {
return this.subtitlesTrack_;
}

this.subtitlesTrack_ = track;

// if we were unpaused but waiting for a sourceUpdater, start
// buffering now
if (this.state === 'INIT' && this.couldBeginLoading_()) {
this.init_();
}

return this.subtitlesTrack_;
}

/**
Expand Down Expand Up @@ -217,7 +225,7 @@ export default class VTTSegmentLoader extends SegmentLoader {
* @private
*/
handleSegment_() {
if (!this.pendingSegment_) {
if (!this.pendingSegment_ || !this.subtitlesTrack_) {
this.state = 'READY';
return;
}
Expand Down
Loading