Skip to content

avformat/shared: add an offset option - #87

Merged
ronag merged 1 commit into
masterfrom
nxtedition
Oct 23, 2026
Merged

ronag merged 1 commit into
masterfrom
nxtedition

Conversation

@haasn

@haasn haasn commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

This additionally fixes a prior silent corruption when a parent offset option was implicitly passed down to the inner protocol, resulting in a stream that did not start at 0, yet the inner protocol offset tracking did not account for this.

By just always handling this option ourselves, we avoid this class of problem.

Fixes: #80
See-Also: nxtedition/casparcg#103
Sponsored-by: nxtedition AB

This additionally fixes a prior silent corruption when a parent `offset`
option was implicitly passed down to the inner protocol, resulting in a
stream that did not start at 0, yet the inner protocol offset tracking
did not account for this.

By just always handling this option ourselves, we avoid this class of
problem.

Fixes: #80
See-Also: nxtedition/casparcg#103
Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
Copilot AI lite review requested due to automatic review settings October 23, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

end_offset must be consumed safely or otherwise prevented from truncating the shared cache during range requests.

1 open issue
What changed in this PR

Adds an offset option to the shared protocol, initializing the logical read position in the cache layer rather than forwarding it to the underlying protocol.

Changes:

  • Adds and applies SharedContext.offset.
  • Documents the new option and its non-forwarding behavior.
  • Leaves end_offset forwarded to the inner protocol, which can truncate shared caches for HLS/DASH range requests.
File Summary
libavformat/​shared.c Implements the shared protocol offset, but leaves a critical unresolved issue where end_offset may be forwarded and permanently truncate cached resources.
doc/​protocols.texi Documents the new offset option and its interaction with the underlying protocol.

Review effort: Lite

Comment thread libavformat/shared.c
{ "retry_errors", "Re-request blocks even if they previously failed", OFFSET(retry_errors), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, .flags = D },
{ "retry_corrupt", "Re-request blocks that fail the CRC check", OFFSET(retry_corrupt), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, .flags = D },
{ "cache_size_max", "Limit the maximum amount of data cached", OFFSET(cache_size_max), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, .flags = D },
{ "offset", "Initial byte offset", OFFSET(offset), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, .flags = D },
@ronag
ronag merged commit 6110cb4 into master Oct 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

avformat/shared: an offset option poisons the cache — shared assumes the inner protocol starts at byte 0

3 participants