av-merge: Use tickEnd+1 when calculating segment time ranges

tickEnd is inclusive, so two segments might have the following
ticks:

-- Segment 0 --
tickStart: 0
tickEnd: 44099

-- Segment 1 --
tickStart: 44100
tickEnd: 88199

When doing calculations in seconds about segment extent, there
were gaps between segment 0's end and segment 1's beginning. This
sometimes resulted in errors of not finding the corresponding
segment index inside these gaps.

Using (tickEnd+1)/this.sidx.timeScale is the correct method.

Signed-off-by: Jesús <heckyel@hyperbola.info>
This commit is contained in:
James Taylor 2021-08-28 09:32:30 -07:00 committed by Jesús
parent 9d3ebca622
commit aacbf07ad7
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -225,7 +225,7 @@ Stream.prototype.appendSegment = function(segmentIdx, chunk) {
while (numDeleted < 3 && i < currentSegment) {
let entry = this.sidx.entries[i];
let start = entry.tickStart/this.sidx.timeScale;
let end = entry.tickEnd/this.sidx.timeScale;
let end = (entry.tickEnd+1)/this.sidx.timeScale;
if (entry.have) {
this.reportWarning('Deleting segment', i);
this.sourceBuffer.remove(start, end);
@ -248,7 +248,7 @@ Stream.prototype.getSegmentIdx = function(videoTime) {
// go up or down to find correct index
while (index >= 0 && index < this.sidx.entries.length) {
var entry = this.sidx.entries[index];
if (entry.tickStart <= currentTick && entry.tickEnd >= currentTick){
if (entry.tickStart <= currentTick && (entry.tickEnd+1) > currentTick){
return index;
}
index = index + increment;
@ -296,7 +296,7 @@ Stream.prototype.segmentInBuffer = function(segmentIdx) {
var entry = this.sidx.entries[segmentIdx];
// allow for 0.01 second error
var timeStart = entry.tickStart/this.sidx.timeScale + 0.01;
var timeEnd = entry.tickEnd/this.sidx.timeScale - 0.01;
var timeEnd = (entry.tickEnd+1)/this.sidx.timeScale - 0.01;
var timeRanges = this.sourceBuffer.buffered;
for (var i=0; i < timeRanges.length; i++) {
if (timeRanges.start(i) <= timeStart && timeEnd <= timeRanges.end(i)) {
@ -311,7 +311,8 @@ Stream.prototype.fetchSegment = function(segmentIdx) {
this.reportDebug(
'Fetching segment', segmentIdx, ', bytes',
entry.start, entry.end, ', seconds',
entry.tickStart/this.sidx.timeScale, entry.tickEnd/this.sidx.timeScale
entry.tickStart/this.sidx.timeScale,
(entry.tickEnd+1)/this.sidx.timeScale
)
fetchRange(
this.url,