Fetch YouTube streams in 10 MB ranges to stop stalls #24

Merged
nezumi merged 1 commit from fix/playback-stall into dev 2026-11-22 04:02:05 +00:00
Owner

Problem

On first play, video froze after ~7 s and only resumed much later. YouTube throttles a single open-ended download of a googlevideo stream (~1 MB/s after an initial burst), while bounded range requests (<=10 MB) are served at full speed (~90 MB/s measured on the same URL). ExoPlayer's progressive source opened one unbounded request per stream, so the 1080p video starved once the burst ran out.

Fix

  • New ChunkedDataSource wraps the OkHttp data source and reads each stream as consecutive 10 MB range requests (uses clen from the URL to report the total length).
  • PlaybackController.buildSource uses it for both video and audio.
  • Unit tests for chunk boundaries, mid-file opens, explicit lengths, servers that ignore range, and clen.

Verified

Emulator (Android TV API 36), 1080p avc1 + opus: before, playback stalled at 7.3 s for 21 s; after, 90 s of continuous playback with no rebuffering, and restart (seek to 0) works. Not yet tested on the FPT box.

Vi: Sửa lỗi video bị khựng sau vài giây đầu khi phát bài

## Problem On first play, video froze after ~7 s and only resumed much later. YouTube throttles a single open-ended download of a googlevideo stream (~1 MB/s after an initial burst), while bounded range requests (<=10 MB) are served at full speed (~90 MB/s measured on the same URL). ExoPlayer's progressive source opened one unbounded request per stream, so the 1080p video starved once the burst ran out. ## Fix - New `ChunkedDataSource` wraps the OkHttp data source and reads each stream as consecutive 10 MB range requests (uses `clen` from the URL to report the total length). - `PlaybackController.buildSource` uses it for both video and audio. - Unit tests for chunk boundaries, mid-file opens, explicit lengths, servers that ignore range, and `clen`. ## Verified Emulator (Android TV API 36), 1080p avc1 + opus: before, playback stalled at 7.3 s for 21 s; after, 90 s of continuous playback with no rebuffering, and restart (seek to 0) works. Not yet tested on the FPT box. Vi: Sửa lỗi video bị khựng sau vài giây đầu khi phát bài
Fetch YouTube streams in 10 MB ranges to stop stalls
All checks were successful
CI / build (pull_request) Successful in 1m51s
71f9921c22
YouTube throttles a single open-ended download, so 1080p playback froze after
the first few seconds until the buffer slowly refilled. Video and audio are now
fetched as consecutive bounded range requests, which are served at full speed.

Vi: Sửa lỗi video bị khựng sau vài giây đầu khi phát bài
nezumi deleted branch fix/playback-stall 2026-11-22 04:02:05 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nezumi/kara-tv-app!24
No description provided.