Skip to content

Commit b4e04b6

Browse files
theodabavelad
andauthored
feat: Store bandwidth info inside references. (#6825)
Issue #6725 --------- Co-authored-by: Álvaro Velad Galván <[email protected]>
1 parent 6425b91 commit b4e04b6

File tree

9 files changed

+56
-4
lines changed

9 files changed

+56
-4
lines changed

lib/dash/segment_base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ shaka.dash.SegmentBase = class {
194194
for (const ref of references) {
195195
ref.codecs = context.representation.codecs;
196196
ref.mimeType = context.representation.mimeType;
197+
ref.bandwidth = context.bandwidth;
197198
}
198199

199200
presentationTimeline.notifySegments(references);

lib/dash/segment_list.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ shaka.dash.SegmentList = class {
6262
context.periodInfo.start, context.periodInfo.duration,
6363
info.startNumber, context.representation.getBaseUris, info,
6464
initSegmentReference, aesKey, context.representation.mimeType,
65-
context.representation.codecs, context.urlParams);
65+
context.representation.codecs, context.bandwidth, context.urlParams);
6666

6767
const isNew = !segmentIndex;
6868
if (segmentIndex) {
@@ -203,13 +203,14 @@ shaka.dash.SegmentList = class {
203203
* @param {shaka.extern.aesKey|undefined} aesKey
204204
* @param {string} mimeType
205205
* @param {string} codecs
206+
* @param {number} bandwidth
206207
* @param {function():string} urlParams
207208
* @return {!Array.<!shaka.media.SegmentReference>}
208209
* @private
209210
*/
210211
static createSegmentReferences_(
211212
periodStart, periodDuration, startNumber, getBaseUris, info,
212-
initSegmentReference, aesKey, mimeType, codecs, urlParams) {
213+
initSegmentReference, aesKey, mimeType, codecs, bandwidth, urlParams) {
213214
const ManifestParserUtils = shaka.util.ManifestParserUtils;
214215

215216
let max = info.mediaSegments.length;
@@ -274,6 +275,7 @@ shaka.dash.SegmentList = class {
274275
aesKey);
275276
ref.codecs = codecs;
276277
ref.mimeType = mimeType;
278+
ref.bandwidth = bandwidth;
277279
references.push(ref);
278280
prevEndTime = endTime;
279281
}

lib/dash/segment_template.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ shaka.dash.SegmentTemplate = class {
275275
indexTemplate: index,
276276
mimeType: context.representation.mimeType,
277277
codecs: context.representation.codecs,
278+
bandwidth: context.bandwidth,
278279
numChunks: numChunks,
279280
};
280281
}
@@ -589,6 +590,7 @@ shaka.dash.SegmentTemplate = class {
589590
aesKey);
590591
ref.codecs = context.representation.codecs;
591592
ref.mimeType = context.representation.mimeType;
593+
ref.bandwidth = context.bandwidth;
592594
// This is necessary information for thumbnail streams:
593595
ref.trueEndTime = trueSegmentEnd;
594596
return ref;
@@ -1003,6 +1005,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
10031005
}
10041006
const codecs = this.templateInfo_.codecs;
10051007
const mimeType = this.templateInfo_.mimeType;
1008+
const bandwidth = this.templateInfo_.bandwidth;
10061009

10071010
const partialSegmentRefs = [];
10081011

@@ -1048,6 +1051,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
10481051
this.aesKey_);
10491052
partial.codecs = codecs;
10501053
partial.mimeType = mimeType;
1054+
partial.bandwidth = bandwidth;
10511055
if (this.segmentSequenceCadence_ == 0) {
10521056
if (i > 0) {
10531057
partial.markAsNonIndependent();
@@ -1095,6 +1099,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
10951099
ref.codecs = codecs;
10961100
ref.mimeType = mimeType;
10971101
ref.trueEndTime = trueSegmentEnd;
1102+
ref.bandwidth = bandwidth;
10981103
this.references[correctedPosition] = ref;
10991104
}
11001105

@@ -1132,6 +1137,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
11321137
* indexTemplate: ?string,
11331138
* mimeType: string,
11341139
* codecs: string,
1140+
* bandwidth: number,
11351141
* numChunks: number
11361142
* }}
11371143
*
@@ -1158,6 +1164,8 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
11581164
* The mimeType.
11591165
* @property {string} codecs
11601166
* The codecs.
1167+
* @property {number} bandwidth
1168+
* The bandwidth.
11611169
* @property {number} numChunks
11621170
* The number of chunks in each segment.
11631171
*/

lib/media/segment_reference.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ shaka.media.SegmentReference = class {
321321
/** @type {?string} */
322322
this.mimeType = null;
323323

324+
/** @type {?number} */
325+
this.bandwidth = null;
326+
324327
/** @type {BufferSource|null} */
325328
this.segmentData = null;
326329
}

lib/player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6256,7 +6256,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
62566256
const info = /** @type {!shaka.extern.PlaybackStreamInfo} */ ({
62576257
'codecs': reference.codecs || stream.codecs,
62586258
'mimeType': reference.mimeType || stream.mimeType,
6259-
'bandwidth': stream.bandwidth,
6259+
'bandwidth': reference.bandwidth || stream.bandwidth,
62606260
});
62616261
if (stream.type == ContentType.VIDEO) {
62626262
output['video'] = info;

test/dash/dash_parser_live_unit.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('DashParser Live', () => {
114114
*/
115115
function cloneRefs(references) {
116116
return references.map((ref) => {
117-
return new shaka.media.SegmentReference(
117+
const clone = new shaka.media.SegmentReference(
118118
ref.startTime,
119119
ref.endTime,
120120
ref.getUrisInner,
@@ -124,6 +124,10 @@ describe('DashParser Live', () => {
124124
ref.timestampOffset,
125125
ref.appendWindowStart,
126126
ref.appendWindowEnd);
127+
clone.codecs = ref.codecs;
128+
clone.mimeType = ref.mimeType;
129+
clone.bandwidth = ref.bandwidth;
130+
return clone;
127131
});
128132
}
129133

test/dash/dash_parser_segment_template_unit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ function makeTemplateInfo(timeline) {
926926
'indexTemplate': null,
927927
'mimeType': 'video/mp4',
928928
'codecs': 'avc1.42E01E',
929+
'bandwidth': 0,
929930
'numChunks': 0,
930931
};
931932
}

test/test/util/manifest_parser_util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ shaka.test.ManifestParser = class {
9696
/* tileDuration= */ undefined,
9797
syncTime);
9898
ref.discontinuitySequence = /** @type {?} */(jasmine.any(Number));
99+
ref.bandwidth = /** @type {?} */(new shaka.test.AnyOrNull(Number));
100+
ref.codecs = /** @type {?} */(jasmine.any(String));
101+
ref.mimeType = /** @type {?} */(jasmine.any(String));
99102
return ref;
100103
}
101104
};

test/test/util/util.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ shaka.test.StatusPromise = class {
2828
}
2929
};
3030

31+
shaka.test.AnyOrNull = class {
32+
/** @param {Function} factory */
33+
constructor(factory) {
34+
/** @type {!Object} */
35+
this.any = jasmine.any(factory);
36+
}
37+
38+
/**
39+
* @param {?Object} other
40+
* @return {boolean}
41+
* @suppress {checkTypes}
42+
*/
43+
asymmetricMatch(other) {
44+
if (other == null) {
45+
return true;
46+
} else {
47+
return this.any.asymmetricMatch(other);
48+
}
49+
}
50+
51+
/**
52+
* @return {boolean}
53+
* @suppress {checkTypes}
54+
*/
55+
jasmineToString() {
56+
return this.any.jasmineToString()
57+
.replace('jasmine.any', 'shaka.test.AnyOrNull');
58+
}
59+
};
60+
3161
shaka.test.Util = class {
3262
/**
3363
* Fakes an event loop. Each tick processes some number of instantaneous

0 commit comments

Comments
 (0)