diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-08-28 09:32:30 -0700 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-08-29 22:50:10 -0500 |
commit | aacbf07ad726a4ef9bd79da33e4675dcf31bbad8 (patch) | |
tree | d2909e83dc5f613e75c2b3944b54cd02cb3ccc67 /youtube | |
parent | 9d3ebca622f7eddd3539e4532957dcf8487feb72 (diff) | |
download | yt-local-aacbf07ad726a4ef9bd79da33e4675dcf31bbad8.tar.lz yt-local-aacbf07ad726a4ef9bd79da33e4675dcf31bbad8.tar.xz yt-local-aacbf07ad726a4ef9bd79da33e4675dcf31bbad8.zip |
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>
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/static/js/av-merge.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js index 84e121c..93664b9 100644 --- a/youtube/static/js/av-merge.js +++ b/youtube/static/js/av-merge.js @@ -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, |