Skip to content

Commit

Permalink
update mss unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosang committed Oct 2, 2018
1 parent 696469d commit 9d50e89
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/mss/MssFragmentMoovProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

import MssErrors from './errors/MssErrors';

/**
* @module MssFragmentMoovProcessor
* @param {Object} config object
Expand Down Expand Up @@ -304,8 +306,8 @@ function MssFragmentMoovProcessor(config) {
return createMP4AudioSampleEntry(stsd, codec);
default:
throw {
name: 'Unsupported codec',
message: 'Unsupported codec',
code: MssErrors.MSS_UNSUPPORTED_CODEC_CODE,
message: MssErrors.MSS_UNSUPPORTED_CODEC_MESSAGE,
data: {
codec: codec
}
Expand Down
9 changes: 7 additions & 2 deletions src/mss/MssHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import MssFragmentInfoController from './MssFragmentInfoController';
import MssFragmentProcessor from './MssFragmentProcessor';
import MssParser from './parser/MssParser';
import MssErrors from './errors/MssErrors';
import DashJSError from '../streaming/vo/DashJSError';

function MssHandler(config) {

Expand Down Expand Up @@ -85,8 +86,12 @@ function MssHandler(config) {

const chunk = createDataChunk(request, streamProcessor.getStreamInfo().id, e.type !== events.FRAGMENT_LOADING_PROGRESS);

// Generate initialization segment (moov)
chunk.bytes = mssFragmentProcessor.generateMoov(representation);
try {
// Generate initialization segment (moov)
chunk.bytes = mssFragmentProcessor.generateMoov(representation);
} catch (e) {
config.errHandler.error(new DashJSError(e.code, e.message, e.data));
}

eventBus.trigger(events.INIT_FRAGMENT_LOADED, {
chunk: chunk,
Expand Down
2 changes: 2 additions & 0 deletions src/mss/errors/MssErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class MssErrors extends ErrorsBase {
super();

this.MSS_NO_TFRF_CODE = 200;
this.MSS_UNSUPPORTED_CODEC_CODE = 201;
this.MSS_NO_TFRF_MESSAGE = 'Missing tfrf in live media segment';
this.MSS_UNSUPPORTED_CODEC_MESSAGE = 'Unsupported codec';
}
}

Expand Down
30 changes: 28 additions & 2 deletions test/unit/mss.MssFragmentProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MetricsModel from '../../src/streaming/models/MetricsModel';
import PlaybackController from '../../src/streaming/controllers/PlaybackController';
import EventBus from '../../src/core/EventBus';
import MssErrors from '../../src/mss/errors/MssErrors';
import Constants from '../../src/streaming/constants/Constants';

import ErrorHandlerMock from './mocks/ErrorHandlerMock';
import StreamProcessorMock from './mocks/StreamProcessorMock';
Expand All @@ -18,8 +19,12 @@ const playbackController = PlaybackController(context).getInstance();
const eventBus = EventBus(context).getInstance();
const errorHandlerMock = new ErrorHandlerMock();
const mssFragmentProcessor = MssFragmentProcessor(context).create({metricsModel: metricsModel,
playbackController: playbackController, eventBus: eventBus, ISOBoxer: ISOBoxer,
errHandler: errorHandlerMock, debug: new DebugMock()});
playbackController: playbackController,
eventBus: eventBus,
ISOBoxer: ISOBoxer,
errHandler: errorHandlerMock,
debug: new DebugMock(),
constants: Constants});

describe('MssFragmentProcessor', function () {
const testType = 'video';
Expand Down Expand Up @@ -48,4 +53,25 @@ describe('MssFragmentProcessor', function () {
expect(errorHandlerMock.errorValue).to.equal(MssErrors.MSS_NO_TFRF_MESSAGE);
expect(errorHandlerMock.errorCode).to.equal(MssErrors.MSS_NO_TFRF_CODE);
});

it('should throw an error when attempting to call generateMoov for mp4 initialization segment', () => {
const rep = {BaseURL: undefined,
SegmentTemplate: {media: 'QualityLevels($Bandwidth$)/Fragments(audio=$Time$)', timescale: 10000000, SegmentTimeline: {}},
audioChannels: NaN,
audioSamplingRate: NaN,
bandwidth: 64000,
codecPrivateData: '1000',
codecs: 'mp7a.58.2',
height: NaN,
id: 'audio_0',
mimeType: 'audio/mp4',
width: NaN,
adaptation: {period: {mpd: {manifest: {Period_asArray: [{AdaptationSet_asArray: [{SegmentTemplate: {timescale: 0}}]}]}}, index: 0}, index: 0, type: 'audio'}
};
expect(mssFragmentProcessor.generateMoov.bind(mssFragmentProcessor, rep)).to.throw({
name: 'Unsupported codec',
message: 'Unsupported codec',
data: {}
});
});
});
2 changes: 2 additions & 0 deletions test/unit/mss.errors.MssErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ describe('Errors', function () {
it('MssErrors code should exist', () => {
expect(MssErrors).to.exist; // jshint ignore:line
expect(MssErrors.MSS_NO_TFRF_CODE).to.equal(200);
expect(MssErrors.MSS_UNSUPPORTED_CODEC_CODE).to.equal(201);
});

it('MssErrors should return the correct error message', () => {
expect(MssErrors).to.exist; // jshint ignore:line
expect(MssErrors.MSS_NO_TFRF_MESSAGE).to.equal('Missing tfrf in live media segment');
expect(MssErrors.MSS_UNSUPPORTED_CODEC_MESSAGE).to.equal('Unsupported codec');
});
});
1 change: 1 addition & 0 deletions test/unit/mss.parser.MssParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('MssParser', function () {
expect(adaptations).to.have.lengthOf(1);
expect(adaptations[0].contentType).to.equal('audio');
});

it('should throw an error when parse is called with invalid smooth data', function () {
expect(mssParser.parse.bind('<SmoothStreamingMedia')).to.be.throw('parsing the manifest failed');
});
Expand Down

0 comments on commit 9d50e89

Please sign in to comment.