Skip to content

Commit

Permalink
getCurrentDroppedFrames doesn't need type attribute
Browse files Browse the repository at this point in the history
update other metrics function with readOnly parameter
  • Loading branch information
nicosang committed Feb 28, 2019
1 parent 203bc3b commit 0076b69
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
9 changes: 3 additions & 6 deletions contrib/akamai/controlbar/ControlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,13 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

getBufferLevel = function () {
var videoMetrics = player.getMetricsFor('video');
var audioMetrics = player.getMetricsFor('audio');
var dashMetrics = player.getDashMetrics();
var bufferLevel = 0;

if (dashMetrics) {
if (videoMetrics) {
bufferLevel = dashMetrics.getCurrentBufferLevel(videoMetrics);
} else if (audioMetrics) {
bufferLevel = dashMetrics.getCurrentBufferLevel(audioMetrics);
bufferLevel = dashMetrics.getCurrentBufferLevel('video', true);
if (!bufferLevel) {
bufferLevel = dashMetrics.getCurrentBufferLevel('audio', true);
}
}
return bufferLevel;
Expand Down
6 changes: 3 additions & 3 deletions samples/chromecast/receiver/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function ReceiverController($scope) {
droppedFramesValue = 0;

if (dashMetrics) {
repSwitch = dashMetrics.getCurrentRepresentationSwitch(type);
bufferLevel = dashMetrics.getCurrentBufferLevel(type);
httpRequest = dashMetrics.getCurrentHttpRequest(type);
repSwitch = dashMetrics.getCurrentRepresentationSwitch(type, true);
bufferLevel = dashMetrics.getCurrentBufferLevel(type, true);
httpRequest = dashMetrics.getCurrentHttpRequest(type, true);
droppedFramesMetrics = dashMetrics.getCurrentDroppedFrames();

if (repSwitch !== null) {
Expand Down
5 changes: 3 additions & 2 deletions samples/dash-if-reference-player/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,10 @@ app.controller('DashController', function ($scope, sources, contributors, dashif

if (dashMetrics && $scope.streamInfo) {
var periodIdx = $scope.streamInfo.index;
var repSwitch = dashMetrics.getCurrentRepresentationSwitch(type);

var maxIndex = dashAdapter.getMaxIndexForBufferType(type, periodIdx);
var bufferLevel = dashMetrics.getCurrentBufferLevel(type);
var repSwitch = dashMetrics.getCurrentRepresentationSwitch(type, true);
var bufferLevel = dashMetrics.getCurrentBufferLevel(type, true);
var index = $scope.player.getQualityFor(type);

var bitrate = repSwitch ? Math.round(dashAdapter.getBandwidthForRepresentation(repSwitch.to, periodIdx) / 1000) : NaN;
Expand Down
17 changes: 9 additions & 8 deletions src/dash/DashMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ function DashMetrics() {

/**
* @param {string} type
* @param {boolean} readOnly
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentRepresentationSwitch(type) {
let metrics = metricsModel.getMetricsFor(type);
function getCurrentRepresentationSwitch(type, readOnly) {
let metrics = metricsModel.getMetricsFor(type, readOnly);
return getCurrent(metrics, MetricsConstants.TRACK_SWITCH);
}

Expand Down Expand Up @@ -84,12 +85,13 @@ function DashMetrics() {

/**
* @param {string} mediaType
* @param {boolean} readOnly
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentHttpRequest(mediaType) {
let metrics = metricsModel.getMetricsFor(mediaType, true);
function getCurrentHttpRequest(mediaType, readOnly) {
let metrics = metricsModel.getMetricsFor(mediaType, readOnly);

if (!metrics) {
return null;
Expand Down Expand Up @@ -153,13 +155,12 @@ function DashMetrics() {
}

/**
* @param {string} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentDroppedFrames(mediaType) {
let metrics = metricsModel.getMetricsFor(mediaType);
function getCurrentDroppedFrames() {
let metrics = metricsModel.getMetricsFor(Constants.VIDEO, true);
return getCurrent(metrics, MetricsConstants.DROPPED_FRAMES);
}

Expand Down Expand Up @@ -228,7 +229,7 @@ function DashMetrics() {
*/
function getLatestFragmentRequestHeaderValueByID(type, id) {
let headers = {};
let httpRequest = getCurrentHttpRequest(type);
let httpRequest = getCurrentHttpRequest(type, true);
if (httpRequest) {
headers = parseResponseHeaders(httpRequest._responseHeaders);
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/dash.DashMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('DashMetrics', function () {
});
});

it('should return null when getCurrentDroppedFrames is called and mediaType is undefined', () => {
it('should return null when getCurrentDroppedFrames is called', () => {
const droppedFrames = dashMetrics.getCurrentDroppedFrames();

expect(droppedFrames).to.be.null; // jshint ignore:line
Expand Down

0 comments on commit 0076b69

Please sign in to comment.