MP4 range/preload fixes + download priority controls#52
Open
hkm5558 wants to merge 8 commits into
Open
Conversation
# Conflicts: # lib/parser/url_parser_mp4.dart
The merge of upstream's last-segment clamp (4d2a93f) with the Mp4RangeResponse refactor left parseIOS clamping endRange against the raw requestRangeEnd, which the refactor no longer rewrites to contentLength-1. For open-ended iOS requests (bytes=0-, requestRangeEnd == -1) the first segment's endRange was clamped to -1, breaking the download. Clamp against rangeResponse.end, consistent with the sublist bounds in the same loop. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
concurrent() only terminated via the contentLength>0 boundary guard. If head() failed (contentLength<=0) and the remaining segments were already cached/in-flight (isExit stays true), activeSize never grew and nextStartRange had no upper bound, spinning the loop forever. Bail when contentLength<=0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves MP4 HTTP range handling and gives callers control over precache download scheduling. Four focused changes plus two correctness fixes found while reconciling with the latest
main.1. Fix MP4 range / preload behavior (
url_parser_mp4.dart)partial = requestRangeStart > 0 || requestRangeEnd > 0returned200forRange: bytes=0-. iOS AVPlayer issuesbytes=0-on normal startup; a200makes the proxy look non-range-capable and breaks seeking. Nowpartial = rangeMatch != null, so any request with a Range header gets206+Content-Range.Mp4RangeResponsehelper that derivescontent-lengthandcontent-rangefrom the real total length (open-endedbytes=N-resolvesendtototal-1), removing the duplicated header construction in the iOS path.concurrent(...)now runs before serving the current segment, so a cached current segment still warms the next one (previously "preload" didn't help the next swipe).2. Promote duplicate download task priority (
download_pool.dart)When
addTask/executeTasksee a task whose cache key is already queued, they promote the existing task's priority (keeping the same task object so in-flight listeners stay attached) instead of dropping the request or removing-and-re-adding.3. Fall back when the native dio adapter is unavailable (
download_pool.dart)Some simulator/runtime combinations can't load
native_dio_adapter's native library._createHttpClientAdapter()now catches the failure and falls back to the default Dio adapter (which still supports the Range requests used here) instead of crashing pool construction.4. Expose precache download priority (
VideoCaching.precache,UrlParser)Adds an optional
priority(default1, matchingDownloadTask's default — fully backward compatible) and threads it through to the createdDownloadTasks in all parsers (default / m3u8 / mp4). Higher-priority tasks are scheduled before lower-priority queued preloads, so the visible video can outrank background warming.Correctness fixes during review
Mp4RangeResponserefactor with the recent last-segment clamp leftparseIOSclampingendRangeagainst the rawrequestRangeEnd, which is no longer rewritten tocontentLength-1. Forbytes=0-(requestRangeEnd == -1) the first segment'sendRangebecame-1. Now clamps againstrangeResponse.end, consistent with the sublist bounds in the same loop. (parseAndroidis unaffected — it still setsrequestRangeEnd = contentLength-1.)concurrent()only terminated via thecontentLength > 0boundary check. A failedhead()(contentLength <= 0) plus an already-cached tail left no upper bound and could spin the loop. Now bails whencontentLength <= 0.Tests
test/parser/url_parser_mp4_test.dart:Mp4RangeResponsemetadata (open-ended / two-byte probe / non-range) and precache content-length + priority threading.test/download/download_pool_test.dart: duplicate-task priority promotion.dart analyze: no issues. All added tests pass.🤖 Generated with Claude Code