Skip to content

Commit

Permalink
feat: include a stats plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jforbes committed Dec 13, 2017
1 parent 47e8eec commit ae09d85
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
14 changes: 2 additions & 12 deletions src/playback-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import window from 'global/window';
import Ranges from './ranges';
import videojs from 'video.js';
import logger from './util/logger';

// Set of events that reset the playback-watcher time check logic and clear the timeout
const timerCancelEvents = [
Expand Down Expand Up @@ -38,10 +38,8 @@ export default class PlaybackWatcher {
this.lastRecordedTime = null;
this.timer_ = null;
this.checkCurrentTimeTimeout_ = null;
this.logger_ = logger('PlaybackWatcher');

if (options.debug) {
this.logger_ = videojs.log.bind(videojs, 'playback-watcher ->');
}
this.logger_('initialize');

let canPlayHandler = () => this.monitorCurrentTime_();
Expand Down Expand Up @@ -403,12 +401,4 @@ export default class PlaybackWatcher {

return null;
}

/**
* A debugging logger noop that is set to console.log only if debugging
* is enabled globally
*
* @private
*/
logger_() {}
}
26 changes: 2 additions & 24 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { initSegmentId } from './bin-utils';
import {mediaSegmentRequest, REQUEST_ERRORS} from './media-segment-request';
import { TIME_FUDGE_FACTOR, timeUntilRebuffer as timeUntilRebuffer_ } from './ranges';
import { minRebufferMaxBandwidthSelector } from './playlist-selectors';
import logger from './util/logger';

// in ms
const CHECK_BUFFER_DELAY = 500;
Expand Down Expand Up @@ -177,9 +178,7 @@ export default class SegmentLoader extends videojs.EventTarget {
// ...for determining the fetch location
this.fetchAtBuffer_ = false;

if (options.debug) {
this.logger_ = videojs.log.bind(videojs, 'segment-loader', this.loaderType_, '->');
}
this.logger_ = logger(`SegmentLoader[${this.loaderType_}]`);
}

/**
Expand Down Expand Up @@ -672,27 +671,17 @@ export default class SegmentLoader extends videojs.EventTarget {
return null;
}

this.logger_('checkBuffer_',
'mediaIndex:', mediaIndex,
'hasPlayed:', hasPlayed,
'currentTime:', currentTime,
'syncPoint:', syncPoint,
'fetchAtBuffer:', this.fetchAtBuffer_,
'bufferedTime:', bufferedTime);

// When the syncPoint is null, there is no way of determining a good
// conservative segment index to fetch from
// The best thing to do here is to get the kind of sync-point data by
// making a request
if (syncPoint === null) {
mediaIndex = this.getSyncSegmentCandidate_(playlist);
this.logger_('getSync', 'mediaIndex:', mediaIndex);
return this.generateSegmentInfo_(playlist, mediaIndex, null, true);
}

// Under normal playback conditions fetching is a simple walk forward
if (mediaIndex !== null) {
this.logger_('walkForward', 'mediaIndex:', mediaIndex + 1);
let segment = playlist.segments[mediaIndex];

if (segment && segment.end) {
Expand Down Expand Up @@ -725,9 +714,6 @@ export default class SegmentLoader extends videojs.EventTarget {
mediaIndex = mediaSourceInfo.mediaIndex;
startOfSegment = mediaSourceInfo.startTime;
}
this.logger_('getMediaIndexForTime',
'mediaIndex:', mediaIndex,
'startOfSegment:', startOfSegment);

return this.generateSegmentInfo_(playlist, mediaIndex, startOfSegment, false);
}
Expand Down Expand Up @@ -1274,14 +1260,6 @@ export default class SegmentLoader extends videojs.EventTarget {
(segmentProcessingThroughput - rate) / (++this.throughput.count);
}

/**
* A debugging logger noop that is set to console.log only if debugging
* is enabled globally
*
* @private
*/
logger_() {}

/**
* Adds a cue to the segment-metadata track with some metadata information about the
* segment
Expand Down
14 changes: 2 additions & 12 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import mp4probe from 'mux.js/lib/mp4/probe';
import {inspect as tsprobe} from 'mux.js/lib/tools/ts-inspector.js';
import {sumDurations} from './playlist';
import videojs from 'video.js';
import logger from './util/logger';

export const syncPointStrategies = [
// Stategy "VOD": Handle the VOD-case where the sync-point is *always*
Expand Down Expand Up @@ -147,9 +148,7 @@ export default class SyncController extends videojs.EventTarget {
this.discontinuities = [];
this.datetimeToDisplayTime = null;

if (options.debug) {
this.logger_ = videojs.log.bind(videojs, 'sync-controller ->');
}
this.logger_ = logger('SyncController');
}

/**
Expand Down Expand Up @@ -258,7 +257,6 @@ export default class SyncController extends videojs.EventTarget {
strategy: strategy.name,
syncPoint
});
this.logger_(`syncPoint found via <${strategy.name}>:`, syncPoint);
}
}

Expand Down Expand Up @@ -547,12 +545,4 @@ export default class SyncController extends videojs.EventTarget {
}
}
}

/**
* A debugging logger noop that is set to console.log only if debugging
* is enabled globally
*
* @private
*/
logger_() {}
}
11 changes: 11 additions & 0 deletions src/util/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import videojs from 'video.js';

const logger = (source) => {
if (videojs.log.debug) {
return videojs.log.debug.bind(videojs, 'VHS:', `${source} >`);
}

return function() {};
};

export default logger;
30 changes: 30 additions & 0 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,36 @@ class HlsHandler extends Component {
}
super.dispose();
}

getPlaybackStats() {
const getTimeRanges = (player, type) => {
const timeRangesList = [];
const timeRanges = player[type]();

for (let i = 0; i < timeRanges.length; i++) {
timeRangesList.push({
start: timeRanges.start(i),
end: timeRanges.end(i)
});
}

return timeRangesList;
};

return {
videoPlaybackQuality: this.tech_.getVideoPlaybackQuality(),
playerDimensions: this.tech_.currentDimensions(),
vhsStats: this.stats,
duration: this.tech_.duration(),
buffered: getTimeRanges(this.tech_, 'buffered'),
seekable: getTimeRanges(this.tech_, 'seekable'),
currentTime: this.tech_.currentTime(),
timestamp: Date.now(),
currentSource: this.tech_.currentSource_,
master: this.playlists.master,
currentTech: this.tech_.name_
};
}
}

/**
Expand Down

0 comments on commit ae09d85

Please sign in to comment.