Skip to content

Commit

Permalink
chore: mediaConfig_ -> staringMediaInfo_, startingMedia_ -> currentMe…
Browse files Browse the repository at this point in the history
…diaInfo_ (#953)
  • Loading branch information
brandonocasey authored Sep 23, 2020
1 parent 7eb112d commit 8801d1c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
10 changes: 5 additions & 5 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ export class MasterPlaylistController extends videojs.EventTarget {

if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
// if the audio playlist loader exists, then alternate audio is active
if (!this.mainSegmentLoader_.startingMedia_ ||
this.mainSegmentLoader_.startingMedia_.hasVideo) {
if (!this.mainSegmentLoader_.currentMediaInfo_ ||
this.mainSegmentLoader_.currentMediaInfo_.hasVideo) {
// if we do not know if the main segment loader contains video yet or if we
// definitively know the main segment loader contains video, then we need to wait
// for both main and audio segment loaders to call endOfStream
Expand Down Expand Up @@ -1346,7 +1346,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
const usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;

// one or both loaders has not loaded sufficently to get codecs
if (!this.mainSegmentLoader_.startingMedia_ || (usingAudioLoader && !this.audioSegmentLoader_.startingMedia_)) {
if (!this.mainSegmentLoader_.currentMediaInfo_ || (usingAudioLoader && !this.audioSegmentLoader_.currentMediaInfo_)) {
return false;
}

Expand All @@ -1355,8 +1355,8 @@ export class MasterPlaylistController extends videojs.EventTarget {

getCodecsOrExclude_() {
const media = {
main: this.mainSegmentLoader_.startingMedia_ || {},
audio: this.audioSegmentLoader_.startingMedia_ || {}
main: this.mainSegmentLoader_.currentMediaInfo_ || {},
audio: this.audioSegmentLoader_.currentMediaInfo_ || {}
};

// set "main" media equal to video
Expand Down
35 changes: 17 additions & 18 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ export default class SegmentLoader extends videojs.EventTarget {
this.mediaSource_ = settings.mediaSource;
this.vhs_ = settings.vhs;
this.loaderType_ = settings.loaderType;
this.startingMedia_ = void 0;
this.currentMediaInfo_ = void 0;
this.startingMediaInfo_ = void 0;
this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
this.goalBufferLength_ = settings.goalBufferLength;
this.sourceType_ = settings.sourceType;
Expand Down Expand Up @@ -632,12 +633,12 @@ export default class SegmentLoader extends videojs.EventTarget {
* TimeRange object representing the current buffered ranges
*/
buffered_() {
if (!this.sourceUpdater_ || !this.mediaConfig_) {
if (!this.sourceUpdater_ || !this.startingMediaInfo_) {
return videojs.createTimeRanges();
}

if (this.loaderType_ === 'main') {
const { hasAudio, hasVideo, isMuxed } = this.mediaConfig_;
const { hasAudio, hasVideo, isMuxed } = this.startingMediaInfo_;

if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
return this.sourceUpdater_.buffered();
Expand Down Expand Up @@ -839,7 +840,7 @@ export default class SegmentLoader extends videojs.EventTarget {
// out before we start adding more data
this.resyncLoader();
}
this.startingMedia_ = void 0;
this.currentMediaInfo_ = void 0;
this.trigger('playlistupdate');

// the rest of this function depends on `oldPlaylist` being defined
Expand Down Expand Up @@ -978,7 +979,7 @@ export default class SegmentLoader extends videojs.EventTarget {
end = this.duration_();
}

if (!this.sourceUpdater_ || !this.startingMedia_) {
if (!this.sourceUpdater_ || !this.currentMediaInfo_) {
// nothing to remove if we haven't processed any media
return;
}
Expand All @@ -997,7 +998,7 @@ export default class SegmentLoader extends videojs.EventTarget {
this.sourceUpdater_.removeAudio(start, end, removeFinished);
}

if (this.loaderType_ === 'main' && this.startingMedia_ && this.startingMedia_.hasVideo) {
if (this.loaderType_ === 'main' && this.currentMediaInfo_ && this.currentMediaInfo_.hasVideo) {
this.gopBuffer_ = removeGopBuffer(this.gopBuffer_, start, end, this.timeMapping_);
removesRemaining++;
this.sourceUpdater_.removeVideo(start, end, removeFinished);
Expand Down Expand Up @@ -1471,16 +1472,14 @@ export default class SegmentLoader extends videojs.EventTarget {
// When we have track info, determine what media types this loader is dealing with.
// Guard against cases where we're not getting track info at all until we are
// certain that all streams will provide it.
if (!shallowEqual(this.startingMedia_, trackInfo)) {
if (!shallowEqual(this.currentMediaInfo_, trackInfo)) {
this.appendInitSegment_ = {
audio: true,
video: true
};

// TODO: rename these variables to
// startingMediaInfo_ and currentMediaInfo_
this.mediaConfig_ = trackInfo;
this.startingMedia_ = trackInfo;
this.startingMediaInfo_ = trackInfo;
this.currentMediaInfo_ = trackInfo;
this.logger_('trackinfo update', trackInfo);
this.trigger('trackinfo');
}
Expand Down Expand Up @@ -1678,7 +1677,7 @@ export default class SegmentLoader extends videojs.EventTarget {
// created together (before appending). Source buffer creation uses the presence of
// audio and video data to determine whether to create audio/video source buffers, and
// uses processed (transmuxed or parsed) media to determine the types required.
if (!this.startingMedia_) {
if (!this.currentMediaInfo_) {
return true;
}

Expand Down Expand Up @@ -1728,7 +1727,7 @@ export default class SegmentLoader extends videojs.EventTarget {
}

if (!this.handlePartialData_) {
const {hasAudio, hasVideo, isMuxed} = this.startingMedia_;
const {hasAudio, hasVideo, isMuxed} = this.currentMediaInfo_;

if (hasVideo && !segmentInfo.videoTimingInfo) {
return false;
Expand Down Expand Up @@ -1809,7 +1808,7 @@ export default class SegmentLoader extends videojs.EventTarget {
segmentInfo[timingInfoPropertyForMedia(result.type)].start;
} else {
const useVideoTimingInfo =
this.loaderType_ === 'main' && this.startingMedia_.hasVideo;
this.loaderType_ === 'main' && this.currentMediaInfo_.hasVideo;
let firstVideoFrameTimeForData;

if (useVideoTimingInfo) {
Expand Down Expand Up @@ -2372,7 +2371,7 @@ export default class SegmentLoader extends videojs.EventTarget {
}

waitForAppendsToComplete_(segmentInfo) {
if (!this.startingMedia_) {
if (!this.currentMediaInfo_) {
this.error({
message: 'No starting media returned, likely due to an unsupported media format.',
blacklistDuration: Infinity
Expand All @@ -2383,7 +2382,7 @@ export default class SegmentLoader extends videojs.EventTarget {
// Although transmuxing is done, appends may not yet be finished. Throw a marker
// on each queue this loader is responsible for to ensure that the appends are
// complete.
const {hasAudio, hasVideo, isMuxed} = this.startingMedia_;
const {hasAudio, hasVideo, isMuxed} = this.currentMediaInfo_;
const waitForVideo = this.loaderType_ === 'main' && hasVideo;
// TODO: does this break partial support for muxed content?
const waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;
Expand Down Expand Up @@ -2452,7 +2451,7 @@ export default class SegmentLoader extends videojs.EventTarget {

checkForIllegalMediaSwitch(trackInfo) {
const illegalMediaSwitchError =
illegalMediaSwitch(this.loaderType_, this.startingMedia_, trackInfo);
illegalMediaSwitch(this.loaderType_, this.currentMediaInfo_, trackInfo);

if (illegalMediaSwitchError) {
this.error({
Expand Down Expand Up @@ -2508,7 +2507,7 @@ export default class SegmentLoader extends videojs.EventTarget {
updateTimingInfoEnd_(segmentInfo) {
segmentInfo.timingInfo = segmentInfo.timingInfo || {};
const useVideoTimingInfo =
this.loaderType_ === 'main' && this.startingMedia_.hasVideo;
this.loaderType_ === 'main' && this.currentMediaInfo_.hasVideo;
const prioritizedTimingInfo = useVideoTimingInfo && segmentInfo.videoTimingInfo ?
segmentInfo.videoTimingInfo : segmentInfo.audioTimingInfo;

Expand Down
22 changes: 11 additions & 11 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ QUnit.test('resets everything for a fast quality change', function(assert) {
origRemove.call(segmentLoader, start, end);
};

segmentLoader.startingMedia_ = { hasVideo: true };
segmentLoader.currentMediaInfo_ = { hasVideo: true };
segmentLoader.audioDisabled_ = true;

segmentLoader.sourceUpdater_.removeVideo = function(start, end) {
Expand Down Expand Up @@ -1044,8 +1044,8 @@ QUnit.test('waits for both main and audio loaders to finish before calling endOf
MPC.mainSegmentLoader_.on('ended', () => videoEnded++);
MPC.audioSegmentLoader_.on('ended', () => audioEnded++);

MPC.mainSegmentLoader_.startingMedia_ = { hasVideo: true };
MPC.audioSegmentLoader_.startingMedia_ = { hasAudio: true };
MPC.mainSegmentLoader_.currentMediaInfo_ = { hasVideo: true };
MPC.audioSegmentLoader_.currentMediaInfo_ = { hasAudio: true };

// master
this.standardXHRResponse(this.requests.shift(), manifests.demuxed);
Expand Down Expand Up @@ -2835,7 +2835,7 @@ QUnit.test('parses codec from audio only fmp4 init segment', function(assert) {
},
'parsed audio codec'
);
assert.deepEqual(loader.startingMedia_, {
assert.deepEqual(loader.currentMediaInfo_, {
audioCodec: 'mp4a.40.2',
hasAudio: true,
hasVideo: false,
Expand Down Expand Up @@ -2896,7 +2896,7 @@ QUnit.test('parses codec from video only fmp4 init segment', function(assert) {
},
'parsed video codec'
);
assert.deepEqual(loader.startingMedia_, {
assert.deepEqual(loader.currentMediaInfo_, {
hasAudio: false,
hasVideo: true,
isFmp4: true,
Expand Down Expand Up @@ -2957,7 +2957,7 @@ QUnit.test('parses codec from muxed fmp4 init segment', function(assert) {
},
'parsed video codec'
);
assert.deepEqual(loader.startingMedia_, {
assert.deepEqual(loader.currentMediaInfo_, {
hasAudio: true,
hasVideo: true,
videoCodec: 'avc1.42c00d',
Expand Down Expand Up @@ -4577,11 +4577,11 @@ QUnit.module('MasterPlaylistController codecs', {
} = options;

if (mainStartingMedia) {
this.mpc.mainSegmentLoader_.startingMedia_ = mainStartingMedia;
this.mpc.mainSegmentLoader_.currentMediaInfo_ = mainStartingMedia;
}

if (audioStartingMedia) {
this.mpc.audioSegmentLoader_.startingMedia_ = audioStartingMedia;
this.mpc.audioSegmentLoader_.currentMediaInfo_ = audioStartingMedia;
}

this.master = {mediaGroups: {AUDIO: {}}, playlists: []};
Expand Down Expand Up @@ -5165,7 +5165,7 @@ QUnit.test('main & audio loader only trackinfo works as expected', function(asse
assert.equal(createBuffers, 0, 'createSourceBuffers not called');
assert.equal(switchBuffers, 0, 'addOrChangeSourceBuffers not called');

this.mpc.audioSegmentLoader_.startingMedia_ = {
this.mpc.audioSegmentLoader_.currentMediaInfo_ = {
hasVideo: false,
hasAudio: true,
audioCodec: 'mp4a.40.2'
Expand All @@ -5179,7 +5179,7 @@ QUnit.test('main & audio loader only trackinfo works as expected', function(asse
this.mpc.sourceUpdater_.ready = () => true;
this.mpc.sourceUpdater_.canChangeType = () => true;

this.mpc.mainSegmentLoader_.startingMedia_ = {
this.mpc.mainSegmentLoader_.currentMediaInfo_ = {
videoCodec: 'avc1.4c400e',
hasVideo: true,
hasAudio: false
Expand All @@ -5195,7 +5195,7 @@ QUnit.test('main & audio loader only trackinfo works as expected', function(asse
assert.equal(createBuffers, 1, 'createBuffers not called');
assert.equal(switchBuffers, 1, 'addOrChangeSourceBuffers called');

this.mpc.audioSegmentLoader_.startingMedia_ = {
this.mpc.audioSegmentLoader_.currentMediaInfo_ = {
hasVideo: false,
hasAudio: true,
audioCodec: 'mp4a.40.5'
Expand Down
4 changes: 2 additions & 2 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3366,8 +3366,8 @@ QUnit.module('SegmentLoader: FMP4', function(hooks) {
endTime: 2,
text: 'test'
});
// set startingMedia_
loader.startingMedia_ = {hasVideo: true, hasAudio: true};
// set currentMediaInfo_
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.remove(0, 2);
assert.equal(this.inbandTextTracks.CC1.cues.length, 0, 'all cues have been removed');

Expand Down
20 changes: 10 additions & 10 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ QUnit.test('does not blacklist compatible H.264 codec strings', function(assert)
const master = this.player.tech_.vhs.playlists.master;
const loader = this.player.tech_.vhs.masterPlaylistController_.mainSegmentLoader_;

loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');

assert.strictEqual(
Expand Down Expand Up @@ -1697,7 +1697,7 @@ QUnit.test('does not blacklist compatible AAC codec strings', function(assert) {
const loader = this.player.tech_.vhs.masterPlaylistController_.mainSegmentLoader_;
const master = this.player.tech_.vhs.playlists.master;

loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');

assert.strictEqual(
Expand Down Expand Up @@ -1758,7 +1758,7 @@ QUnit.test('blacklists incompatible playlists by codec, without codec switching'

mpc.sourceUpdater_.canChangeType = () => false;

loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');
const playlists = master.playlists;

Expand Down Expand Up @@ -1818,7 +1818,7 @@ QUnit.test('does not blacklist incompatible codecs with codec switching', functi

mpc.sourceUpdater_.canChangeType = () => true;

loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');
const playlists = master.playlists;

Expand Down Expand Up @@ -1882,17 +1882,17 @@ QUnit.test('blacklists fmp4 playlists by browser support', function(assert) {

playlistLoader.media = () => playlists[0];
loader.mainStartingMedia_ = playlists[0];
loader.startingMedia_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.trigger('trackinfo');

playlistLoader.media = () => playlists[1];
loader.mainStartingMedia_ = playlists[1];
loader.startingMedia_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.trigger('trackinfo');

playlistLoader.media = () => playlists[2];
loader.mainStartingMedia_ = playlists[2];
loader.startingMedia_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true, isFmp4: true};
loader.trigger('trackinfo');

assert.strictEqual(playlists.length, 3, 'three playlists total');
Expand Down Expand Up @@ -1950,17 +1950,17 @@ QUnit.test('blacklists ts playlists by muxer support', function(assert) {

playlistLoader.media = () => playlists[0];
loader.mainStartingMedia_ = playlists[0];
loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');

playlistLoader.media = () => playlists[1];
loader.mainStartingMedia_ = playlists[1];
loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');

playlistLoader.media = () => playlists[2];
loader.mainStartingMedia_ = playlists[2];
loader.startingMedia_ = {hasVideo: true, hasAudio: true};
loader.currentMediaInfo_ = {hasVideo: true, hasAudio: true};
loader.trigger('trackinfo');

assert.strictEqual(playlists.length, 3, 'three playlists total');
Expand Down

0 comments on commit 8801d1c

Please sign in to comment.