Skip to content

Commit 06d92a5

Browse files
authored
fix(HLS): Allow get better segment size estimations (#9043)
Related to #9041
1 parent 3205235 commit 06d92a5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/hls/hls_parser.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,12 +4349,20 @@ shaka.hls.HlsParser = class {
43494349
bitrate,
43504350
duration: reference.endTime - reference.startTime,
43514351
});
4352+
reference.bandwidth = bitrate;
43524353
} else if (bitrates.length) {
43534354
// It applies to every segment between it and the next EXT-X-BITRATE,
43544355
// so we use the latest bitrate value
43554356
const prevBitrate = bitrates.pop();
43564357
prevBitrate.duration += reference.endTime - reference.startTime;
43574358
bitrates.push(prevBitrate);
4359+
reference.bandwidth = prevBitrate.bitrate;
4360+
}
4361+
4362+
if (reference.bandwidth) {
4363+
for (const partial of reference.partialReferences) {
4364+
partial.bandwidth = reference.bandwidth;
4365+
}
43584366
}
43594367

43604368
previousReference = reference;

lib/media/segment_reference.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,14 @@ shaka.media.SegmentReference = class {
407407
getSize() {
408408
if (this.endByte) {
409409
return this.endByte - this.startByte;
410-
} else {
411-
return null;
412410
}
411+
if (this.bandwidth) {
412+
const size = this.bandwidth * (this.endTime - this.startTime);
413+
if (!isNaN(size) && size > 0) {
414+
return size;
415+
}
416+
}
417+
return null;
413418
}
414419

415420
/**

0 commit comments

Comments
 (0)