forked from Dash-Industry-Forum/dash.js
/
streaming.models.MediaPlayerModel.js
161 lines (127 loc) · 7.86 KB
/
streaming.models.MediaPlayerModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import MediaPlayerModel from '../../src/streaming/models/MediaPlayerModel';
import Constants from '../../src/streaming/constants/Constants';
import {
HTTPRequest
} from '../../src/streaming/vo/metrics/HTTPRequest';
import ABRRulesCollection from '../../src/streaming/rules/abr/ABRRulesCollection';
import Settings from '../../src/core/Settings';
const chai = require('chai');
const expect = chai.expect;
describe('MediaPlayerModel', function () {
const context = {};
const mediaPlayerModel = MediaPlayerModel(context).getInstance();
let settings = Settings(context).getInstance();
beforeEach(() => {
settings.reset();
});
it('Method removeUTCTimingSource should throw an exception', function () {
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, true, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, 1, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, 'string', true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, 'string', 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, true, true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.removeUTCTimingSource.bind(mediaPlayerModel, 1, 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method addUTCTimingSource should throw an exception', function () {
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, true, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, 1, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, 'string', true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, 'string', 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, true, true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addUTCTimingSource.bind(mediaPlayerModel, 1, 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('Method addABRCustomRule should throw an exception', function () {
expect(mediaPlayerModel.addABRCustomRule.bind(mediaPlayerModel, 'unknownRuleType', 'newRuleName')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addABRCustomRule.bind(mediaPlayerModel, true, 'newRuleName')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addABRCustomRule.bind(mediaPlayerModel, 1, 'string')).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addABRCustomRule.bind(mediaPlayerModel, ABRRulesCollection.ABANDON_FRAGMENT_RULES, 1)).to.throw(Constants.BAD_ARGUMENT_ERROR);
expect(mediaPlayerModel.addABRCustomRule.bind(mediaPlayerModel, ABRRulesCollection.ABANDON_FRAGMENT_RULES, true)).to.throw(Constants.BAD_ARGUMENT_ERROR);
});
it('should configure FragmentLoaderRetryAttempts', function () {
let FragmentLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MEDIA_SEGMENT_TYPE);
expect(FragmentLoaderRetryAttempts).to.equal(3);
const s = {streaming: {retryAttempts: {}}};
s.streaming.retryAttempts[HTTPRequest.MEDIA_SEGMENT_TYPE] = 50;
settings.update(s);
FragmentLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MEDIA_SEGMENT_TYPE);
expect(FragmentLoaderRetryAttempts).to.equal(50);
});
it('should configure FragmentLoaderRetryInterval', function () {
let FragmentLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MEDIA_SEGMENT_TYPE);
expect(FragmentLoaderRetryInterval).to.equal(1000);
const s = {streaming: {retryIntervals: {}}};
s.streaming.retryIntervals[HTTPRequest.MEDIA_SEGMENT_TYPE] = 50;
settings.update(s);
FragmentLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MEDIA_SEGMENT_TYPE);
expect(FragmentLoaderRetryInterval).to.equal(50);
});
it('should configure ManifestLoaderRetryAttempts', function () {
let manifestLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryAttempts).to.equal(3);
const s = {streaming: {retryAttempts: {}}};
s.streaming.retryAttempts[HTTPRequest.MPD_TYPE] = 50;
settings.update(s);
manifestLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryAttempts).to.equal(50);
});
it('should configure low latency retry attempt multiplication factor', function () {
let manifestLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryAttempts).to.equal(3);
const s = {
streaming:
{
lowLatencyEnabled: true,
retryAttempts: {
lowLatencyMultiplyFactor: 10
}
}
};
settings.update(s);
manifestLoaderRetryAttempts = mediaPlayerModel.getRetryAttemptsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryAttempts).to.equal(30);
});
it('should configure ManifestLoaderRetryInterval', function () {
let manifestLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryInterval).to.equal(500);
const s = {streaming: {retryIntervals: {}}};
s.streaming.retryIntervals[HTTPRequest.MPD_TYPE] = 50;
settings.update(s);
manifestLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryInterval).to.equal(50);
});
it('should configure low latency retry interval reduction factor', function () {
let manifestLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryInterval).to.equal(500);
const s = {
streaming:
{
lowLatencyEnabled: true,
retryIntervals: {
lowLatencyReductionFactor: 5
}
}
};
settings.update(s);
manifestLoaderRetryInterval = mediaPlayerModel.getRetryIntervalsForType(HTTPRequest.MPD_TYPE);
expect(manifestLoaderRetryInterval).to.equal(100);
});
it('should configure StableBufferTime', function () {
const s = {streaming: {stableBufferTime: 50}};
settings.update(s);
let StableBufferTime = mediaPlayerModel.getStableBufferTime();
expect(StableBufferTime).to.equal(50);
});
it('should configure liveCatchupLatencyThreshold', function () {
let liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();
expect(liveCatchupLatencyThreshold).to.be.NaN; // jshint ignore:line
settings.update({streaming: {lowLatencyEnabled: true, liveDelay: 3, liveCatchUpMinDrift: 3}});
liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();
expect(liveCatchupLatencyThreshold).to.equal(12);
settings.update({streaming: {liveCatchUpMinDrift: NaN}});
liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();
expect(liveCatchupLatencyThreshold).to.equal(6);
settings.update({streaming: {liveCatchupLatencyThreshold: 50}});
liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();
expect(liveCatchupLatencyThreshold).to.equal(50);
});
});