Skip to content

Commit 1e563bf

Browse files
authored
Merge pull request Dash-Industry-Forum#2844 from Orange-OpenSource/updateMetrics
Update metrics
2 parents 2e407b1 + f114177 commit 1e563bf

File tree

7 files changed

+50
-94
lines changed

7 files changed

+50
-94
lines changed

src/dash/DashMetrics.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ function DashMetrics(config) {
4444
let dashManifestModel = config.dashManifestModel;
4545
let manifestModel = config.manifestModel;
4646

47+
function getPeriod(periodId) {
48+
const manifest = manifestModel.getValue();
49+
if (!manifest) {
50+
return -1;
51+
}
52+
return manifest.Period_asArray[periodId];
53+
}
54+
4755
function getBandwidthForRepresentation(representationId, periodId) {
4856
let representation;
49-
const manifest = manifestModel.getValue();
50-
let period = manifest.Period_asArray[periodId];
57+
let period = getPeriod(periodId);
5158

5259
representation = findRepresentation(period, representationId);
5360

@@ -58,20 +65,16 @@ function DashMetrics(config) {
5865
return representation.bandwidth;
5966
}
6067

61-
6268
/**
6369
*
6470
* @param {string} representationId
6571
* @param {number} periodIdx
6672
* @returns {*}
6773
*/
6874
function getIndexForRepresentation(representationId, periodIdx) {
69-
let representationIndex;
70-
const manifest = manifestModel.getValue();
71-
let period = manifest.Period_asArray[periodIdx];
75+
let period = getPeriod(periodIdx);
7276

73-
representationIndex = findRepresentationIndex(period, representationId);
74-
return representationIndex;
77+
return findRepresentationIndex(period, representationId);
7578
}
7679

7780
/**
@@ -84,15 +87,9 @@ function DashMetrics(config) {
8487
* @instance
8588
*/
8689
function getMaxIndexForBufferType(bufferType, periodIdx) {
87-
let maxIndex;
88-
const manifest = manifestModel.getValue();
89-
if (!manifest) {
90-
return -1;
91-
}
92-
let period = manifest.Period_asArray[periodIdx];
90+
let period = getPeriod(periodIdx);
9391

94-
maxIndex = findMaxBufferIndex(period, bufferType);
95-
return maxIndex;
92+
return findMaxBufferIndex(period, bufferType);
9693
}
9794

9895
/**
@@ -203,17 +200,11 @@ function DashMetrics(config) {
203200

204201
const list = metrics[metricName];
205202

206-
if (!list) {
207-
return null;
208-
}
209-
210-
const length = list.length;
211-
212-
if (length <= 0) {
203+
if (!list || list.length <= 0) {
213204
return null;
214205
}
215206

216-
return list[length - 1];
207+
return list[list.length - 1];
217208
}
218209

219210
/**

src/streaming/MediaPlayer.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ function MediaPlayer() {
241241
adapter.setConfig({
242242
dashManifestModel: dashManifestModel
243243
});
244-
metricsModel.setConfig({
245-
adapter: adapter
246-
});
247244

248245
restoreDefaultUTCTimingSources();
249246
setAutoPlay(AutoPlay !== undefined ? AutoPlay : true);

src/streaming/metrics/MetricsReporting.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ import ReportingFactory from './reporting/ReportingFactory';
3838
function MetricsReporting() {
3939

4040
let context = this.context;
41-
let instance;
42-
43-
let dvbErrorsTranslator;
41+
let instance,
42+
dvbErrorsTranslator;
4443

4544
/**
4645
* Create a MetricsCollectionController, and a DVBErrorsTranslator

src/streaming/metrics/reporting/reporters/DVBReporting.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,26 @@ function DVBReporting(config) {
3737
let instance;
3838

3939
let context = this.context;
40-
let metricSerialiser = MetricSerialiser(context).getInstance();
41-
let randomNumberGenerator = RNG(context).getInstance();
40+
let metricSerialiser,
41+
randomNumberGenerator,
42+
reportingPlayerStatusDecided,
43+
isReportingPlayer,
44+
reportingUrl,
45+
rangeController;
4246

4347
let USE_DRAFT_DVB_SPEC = true;
44-
let isReportingPlayer = false;
45-
let reportingPlayerStatusDecided = false;
46-
let reportingUrl = null;
47-
let rangeController = null;
4848
let allowPendingRequestsToCompleteOnReset = true;
4949
let pendingRequests = [];
5050

5151
const metricsConstants = config.metricsConstants;
5252

53+
function setup() {
54+
metricSerialiser = MetricSerialiser(context).getInstance();
55+
randomNumberGenerator = RNG(context).getInstance();
56+
57+
resetInitialSettings();
58+
}
59+
5360
function doGetRequest(url, successCB, failureCB) {
5461
let req = new XMLHttpRequest();
5562
const oncomplete = function () {
@@ -159,16 +166,20 @@ function DVBReporting(config) {
159166
}
160167
}
161168

169+
function resetInitialSettings() {
170+
reportingPlayerStatusDecided = false;
171+
isReportingPlayer = false;
172+
reportingUrl = null;
173+
rangeController = null;
174+
}
175+
162176
function reset() {
163177
if (!allowPendingRequestsToCompleteOnReset) {
164178
pendingRequests.forEach(req => req.abort());
165179
pendingRequests = [];
166180
}
167181

168-
reportingPlayerStatusDecided = false;
169-
isReportingPlayer = false;
170-
reportingUrl = null;
171-
rangeController = null;
182+
resetInitialSettings();
172183
}
173184

174185
instance = {
@@ -177,6 +188,8 @@ function DVBReporting(config) {
177188
reset: reset
178189
};
179190

191+
setup();
192+
180193
return instance;
181194
}
182195

src/streaming/metrics/utils/DVBErrorsTranslator.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ import MetricsReportingEvents from '../MetricsReportingEvents';
3535
function DVBErrorsTranslator(config) {
3636

3737
config = config || {};
38-
let instance;
39-
let eventBus = config.eventBus;
40-
let metricModel = config.metricsModel;
41-
let mpd;
42-
38+
let instance,
39+
mpd;
40+
const eventBus = config.eventBus;
41+
const metricModel = config.metricsModel;
4342
const metricsConstants = config.metricsConstants;
4443
//MediaPlayerEvents have been added to Events in MediaPlayer class
4544
const Events = config.events;

src/streaming/models/MetricsModel.js

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import Constants from '../constants/Constants';
3232
import MetricsConstants from '../constants/MetricsConstants';
3333
import MetricsList from '../vo/MetricsList';
34-
import TCPConnection from '../vo/metrics/TCPConnection';
3534
import {HTTPRequest, HTTPRequestTrace} from '../vo/metrics/HTTPRequest';
3635
import TrackSwitch from '../vo/metrics/RepresentationSwitch';
3736
import BufferLevel from '../vo/metrics/BufferLevel';
@@ -59,10 +58,6 @@ function MetricsModel() {
5958
streamMetrics = {};
6059
}
6160

62-
function setConfig(config) {
63-
if (!config) return;
64-
}
65-
6661
function metricsChanged() {
6762
eventBus.trigger(Events.METRICS_CHANGED);
6863
}
@@ -121,20 +116,6 @@ function MetricsModel() {
121116
}
122117
}
123118

124-
function addTcpConnection(mediaType, tcpid, dest, topen, tclose, tconnect) {
125-
let vo = new TCPConnection();
126-
127-
vo.tcpid = tcpid;
128-
vo.dest = dest;
129-
vo.topen = topen;
130-
vo.tclose = tclose;
131-
vo.tconnect = tconnect;
132-
133-
pushAndNotify(mediaType, MetricsConstants.TCP_CONNECTION, vo);
134-
135-
return vo;
136-
}
137-
138119
function appendHttpTrace(httpRequest, s, d, b) {
139120
let vo = new HTTPRequestTrace();
140121

@@ -211,8 +192,6 @@ function MetricsModel() {
211192
}
212193

213194
pushAndNotify(mediaType, MetricsConstants.HTTP_REQUEST, vo);
214-
215-
return vo;
216195
}
217196

218197
function addRepresentationSwitch(mediaType, t, mt, to, lto) {
@@ -229,8 +208,6 @@ function MetricsModel() {
229208
}
230209

231210
pushAndNotify(mediaType, MetricsConstants.TRACK_SWITCH, vo);
232-
233-
return vo;
234211
}
235212

236213
function pushAndNotify(mediaType, metricType, metricObject) {
@@ -244,8 +221,6 @@ function MetricsModel() {
244221
vo.level = level;
245222

246223
pushAndNotify(mediaType, MetricsConstants.BUFFER_LEVEL, vo);
247-
248-
return vo;
249224
}
250225

251226
function addBufferState(mediaType, state, target) {
@@ -254,8 +229,6 @@ function MetricsModel() {
254229
vo.state = state;
255230

256231
pushAndNotify(mediaType, MetricsConstants.BUFFER_STATE, vo);
257-
258-
return vo;
259232
}
260233

261234
function addDVRInfo(mediaType, currentTime, mpd, range) {
@@ -265,8 +238,6 @@ function MetricsModel() {
265238
vo.manifestInfo = mpd;
266239

267240
pushAndNotify(mediaType, MetricsConstants.DVR_INFO, vo);
268-
269-
return vo;
270241
}
271242

272243
function addDroppedFrames(mediaType, quality) {
@@ -277,12 +248,10 @@ function MetricsModel() {
277248
vo.droppedFrames = quality.droppedVideoFrames;
278249

279250
if (list.length > 0 && list[list.length - 1] == vo) {
280-
return list[list.length - 1];
251+
return;
281252
}
282253

283254
pushAndNotify(mediaType, MetricsConstants.DROPPED_FRAMES, vo);
284-
285-
return vo;
286255
}
287256

288257
function addSchedulingInfo(mediaType, t, type, startTime, availabilityStartTime, duration, quality, range, state) {
@@ -301,8 +270,6 @@ function MetricsModel() {
301270
vo.state = state;
302271

303272
pushAndNotify(mediaType, MetricsConstants.SCHEDULING_INFO, vo);
304-
305-
return vo;
306273
}
307274

308275
function addRequestsQueue(mediaType, loadingRequests, executedRequests) {
@@ -330,8 +297,6 @@ function MetricsModel() {
330297

331298
pushMetrics(Constants.STREAM, MetricsConstants.MANIFEST_UPDATE, vo);
332299
metricAdded(mediaType, MetricsConstants.MANIFEST_UPDATE, vo);
333-
334-
return vo;
335300
}
336301

337302
function updateManifestUpdateInfo(manifestUpdate, updatedFields) {
@@ -355,10 +320,7 @@ function MetricsModel() {
355320

356321
manifestUpdate.streamInfo.push(vo);
357322
metricUpdated(manifestUpdate.mediaType, MetricsConstants.MANIFEST_UPDATE_STREAM_INFO, manifestUpdate);
358-
359-
return vo;
360323
}
361-
return null;
362324
}
363325

364326
function addManifestUpdateRepresentationInfo(manifestUpdate, id, index, streamIndex, mediaType, presentationTimeOffset, startNumber, fragmentInfoType) {
@@ -375,10 +337,7 @@ function MetricsModel() {
375337

376338
manifestUpdate.representationInfo.push(vo);
377339
metricUpdated(manifestUpdate.mediaType, MetricsConstants.MANIFEST_UPDATE_TRACK_INFO, manifestUpdate);
378-
379-
return vo;
380340
}
381-
return null;
382341
}
383342

384343
function addPlayList(vo) {
@@ -395,24 +354,19 @@ function MetricsModel() {
395354
}
396355

397356
pushAndNotify(type, MetricsConstants.PLAY_LIST, vo);
398-
399-
return vo;
400357
}
401358

402359
function addDVBErrors(vo) {
403360
let type = Constants.STREAM;
404361

405362
pushAndNotify(type, MetricsConstants.DVB_ERRORS, vo);
406-
407-
return vo;
408363
}
409364

410365
instance = {
411366
clearCurrentMetricsForType: clearCurrentMetricsForType,
412367
clearAllCurrentMetrics: clearAllCurrentMetrics,
413368
getReadOnlyMetricsFor: getReadOnlyMetricsFor,
414369
getMetricsFor: getMetricsFor,
415-
addTcpConnection: addTcpConnection,
416370
addHttpRequest: addHttpRequest,
417371
addRepresentationSwitch: addRepresentationSwitch,
418372
addBufferLevel: addBufferLevel,
@@ -426,8 +380,7 @@ function MetricsModel() {
426380
addManifestUpdateStreamInfo: addManifestUpdateStreamInfo,
427381
addManifestUpdateRepresentationInfo: addManifestUpdateRepresentationInfo,
428382
addPlayList: addPlayList,
429-
addDVBErrors: addDVBErrors,
430-
setConfig: setConfig
383+
addDVBErrors: addDVBErrors
431384
};
432385

433386
setup();

src/streaming/net/HTTPLoader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ function HTTPLoader(cfg) {
124124
httpRequest.response ? httpRequest.response.responseHeaders : [],
125125
success ? traces : null
126126
);
127+
128+
if (request.type === HTTPRequest.MPD_TYPE) {
129+
metricsModel.addManifestUpdate('stream', request.type, request.requestStartDate, request.requestEndDate);
130+
}
127131
}
128132
};
129133

0 commit comments

Comments
 (0)