Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: exclude text processors from Stream.getProcessors when text is disabled #3342

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/streaming/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ function Stream(config) {
}

function getProcessors() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getProcessors is used in other functions as well. I would prefer to add a flag to this function "includeTextIfDisabled" or something similar. This flag should default to true and should only be false for the use case you describe.

const isTextEnabled = textController.isTextEnabled();

let arr = [];

let type,
Expand All @@ -723,7 +725,9 @@ function Stream(config) {
streamProcessor = streamProcessors[i];
type = streamProcessor.getType();

if (type === Constants.AUDIO || type === Constants.VIDEO || type === Constants.FRAGMENTED_TEXT || type === Constants.TEXT) {
if (type === Constants.AUDIO || type === Constants.VIDEO) {
arr.push(streamProcessor);
} else if ((type === Constants.FRAGMENTED_TEXT || type == Constants.TEXT) && isTextEnabled) {
arr.push(streamProcessor);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/streaming/controllers/PlaybackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ function PlaybackController() {
function startPlaybackCatchUp() {
if (videoModel) {
const cpr = settings.get().streaming.liveCatchUpPlaybackRate;
const liveDelay = mediaPlayerModel.getLiveDelay();
const deltaLatency = getCurrentLiveLatency() - liveDelay;
const playerLiveDelay = mediaPlayerModel.getLiveDelay();
const deltaLatency = getCurrentLiveLatency() - playerLiveDelay;
const d = deltaLatency * 5;
// Playback rate must be between (1 - cpr) - (1 + cpr)
// ex: if cpr is 0.5, it can have values between 0.5 - 1.5
Expand All @@ -641,7 +641,7 @@ function PlaybackController() {
// just cause more and more stall situations
if (playbackStalled) {
const bufferLevel = getBufferLevel();
if (bufferLevel > liveDelay / 2) {
if (bufferLevel > playerLiveDelay / 2) {
playbackStalled = false;
} else if (deltaLatency > 0) {
newRate = 1.0;
Expand Down
10 changes: 9 additions & 1 deletion src/streaming/metrics/metrics/handlers/BufferLevelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

import Constants from '../../../constants/Constants';
import HandlerHelpers from '../../utils/HandlerHelpers';

function BufferLevelHandler(config) {
Expand All @@ -47,6 +48,7 @@ function BufferLevelHandler(config) {
let storedVOs = [];

const metricsConstants = config.metricsConstants;
const textController = config.textController || {};

function getLowestBufferLevelVO() {
try {
Expand Down Expand Up @@ -93,8 +95,14 @@ function BufferLevelHandler(config) {
}

function handleNewMetric(metric, vo, type) {

if (metric === metricsConstants.BUFFER_LEVEL) {
storedVOs[type] = vo;
const isTextVo = type === Constants.FRAGMENTED_TEXT || type === Constants.TEXT;
const storeTextVo = isTextVo && (textController.isTextEnabled() || false);

if (!isTextVo || storeTextVo) {
storedVOs[type] = vo;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/unit/helpers/ObjectsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ObjectsHelper {
calcSegmentAvailabilityRange: () => { return {start: start, end: end};},
isTimeSyncCompleted: () => {return true;},
setExpectedLiveEdge: () => {},
setRange: (range) => {start = range.start; end = range.end;}
setRange: (range) => {start = range.start; end = range.end;},
setTimeSyncCompleted: () => {}
};
}

Expand Down
4 changes: 3 additions & 1 deletion test/unit/mocks/AbrControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ function AbrControllerMock () {

this.getAbandonmentStateFor = function () {};

this.getQualityForBitrate = function () {};
this.getQualityForBitrate = function () {
return this.QUALITY_DEFAULT();
};

this.getBitrateList = function () {
return [];
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mocks/AdapterMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function AdapterMock () {

this.getAllMediaInfoForType = function () {
return [{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 0, isText: false, lang: 'eng',mimeType: 'audio/mp4', roles: ['main']},
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 1, isText: false, lang: 'deu',mimeType: 'audio/mp4', roles: ['main']}];
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 1, isText: false, lang: 'deu',mimeType: 'audio/mp4', roles: ['main']},
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 2, isText: true, lang: 'eng',mimeType: 'audio/mp4', roles: ['main']}];
};

this.getDataForMedia = function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mocks/MediaControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class MediaControllerMock {
return this.tracks;
}

getCurrentTrackFor() {
return this.track;
getCurrentTrackFor(type) {
return this.track === undefined || this.track === null ? { codec: '', type } : this.track;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mocks/TextControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TextControllerMock {
this.textEnabled = state;
}
getTextDefaultEnabled() {
return true;
return false;
}
addEmbeddedTrack() {}
}
Expand Down
57 changes: 57 additions & 0 deletions test/unit/streaming.Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Errors from '../../src/core/errors/Errors';
import Settings from '../../src/core/Settings';

import AdapterMock from './mocks/AdapterMock';
import BaseURLControllerMock from './mocks/BaseURLControllerMock';
import ManifestModelMock from './mocks/ManifestModelMock';
import ErrorHandlerMock from './mocks/ErrorHandlerMock';
import AbrControllerMock from './mocks/AbrControllerMock';
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('Stream', function () {
const dashMetricsMock = new DashMetricsMock();
const textControllerMock = new TextControllerMock();
const videoModelMock = new VideoModelMock();
const baseURLControllerMock = new BaseURLControllerMock();
const timelineConverter = objectsHelper.getDummyTimelineConverter();
const streamInfo = {
id: 'id',
Expand All @@ -70,6 +72,7 @@ describe('Stream', function () {
dashMetrics: dashMetricsMock,
textController: textControllerMock,
videoModel: videoModelMock,
baseURLController: baseURLControllerMock,
settings: settings});
});

Expand All @@ -90,6 +93,60 @@ describe('Stream', function () {
expect(processors).to.be.empty; // jshint ignore:line
});

it('should return an array that does not include the streamProcessors for text and fragmented text when getProcessors is called and text is disabled', () => {
// test-specific setup
adapterMock.setRepresentation({
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
hasInitialization: () => false,
hasSegments: () => true,
id: 'foo'
});

stream.initialize(streamInfo, {});
stream.activate(
null,
null
);

// check textControllerMock is in correct state
expect(textControllerMock.isTextEnabled()).to.be.false; // jshint ignore:line

// check assertions
const processors = stream.getProcessors();
expect(processors.length).to.be.equal(2); // jshint ignore:line
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
});

it('should return an array that includes the streamProcessors for text and fragmented text when getProcessors is called and text is enabled', () => {
// test-specific setup
adapterMock.setRepresentation({
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
hasInitialization: () => false,
hasSegments: () => true,
id: 'foo'
});

textControllerMock.enableText(true);

stream.initialize(streamInfo, {});
stream.activate(
null,
null
);

// check textControllerMock is in correct state
expect(textControllerMock.isTextEnabled()).to.be.true; // jshint ignore:line

// check assertions
const processors = stream.getProcessors();
expect(processors.length).to.be.equal(4); // jshint ignore:line
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
expect(processors[2].getType()).to.be.equal('text'); // jshint ignore:line
expect(processors[3].getType()).to.be.equal('fragmentedText'); // jshint ignore:line
});

it('should trigger MANIFEST_ERROR_ID_NOSTREAMS_CODE error when setMediaSource is called but streamProcessors array is empty', () => {
stream.setMediaSource();
expect(errHandlerMock.errorCode).to.be.equal(Errors.MANIFEST_ERROR_ID_NOSTREAMS_CODE); // jshint ignore:line
Expand Down