Skip to content

Follow linked SeekHead elements to find Matroska Cues - #3593

Open
FongMi wants to merge 1 commit into
androidx:mainfrom
FongMi:media3-mkv-linked-seekhead
Open

FongMi wants to merge 1 commit into
androidx:mainfrom
FongMi:media3-mkv-linked-seekhead

Conversation

@FongMi

@FongMi FongMi commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Follow linked SeekHead entries to find Matroska Cues in the case reported in #1143. At the first Cluster, follow the linked SeekHeads, read Cues if found, and return to the saved Cluster position. SeekHead and Cues targets share a 32-candidate limit and visited-offset checks.

When the input length is unknown, verify forward linked SeekHead targets and Cues discovered through them using up to 256 KiB of read-ahead before requesting a seek. Skip unusable candidates and continue sequential playback with an unseekable map if no usable index is found.

The traversal stays in MatroskaExtractor. The optional index reader recognizes only SeekHead and Cues elements and can skip malformed index targets. Sequential read errors still propagate to the loader. The package-private unknown-size query on DefaultEbmlReader is used for traversal bounds, while direct Cues retain their existing thumbnail and chunk-index output. The EbmlReader and EbmlProcessor interfaces match upstream.

Testing

  • Parameterized MatroskaExtractorTest runs the three-SeekHead sample against the existing sample.mkv dumps. The sample is byte-identical to the one in Follow chained SeekHead elements to find Cues in Matroska #3588.
  • Targeted tests cover cycles, traversal limits, malformed index targets, premature EOF during sequential reads, and direct Cues in unknown-size Segments. The HTTP regression reaches STATE_ENDED with one request for both known-length and chunked responses.
  • Passed 1,861 Matroska extractor tests and 16 ExoPlayer HTTP/MKV playback tests. All 18 parameterizations of the new sample passed.

Coordination

This revision follows icbaker's guidance and is a candidate for the single linked-SeekHead PR discussed in #3588. Related proposals are #3526, #3579, #3588, and #3597.

@icbaker

icbaker commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

See #3588 (comment)

@FongMi
FongMi force-pushed the media3-mkv-linked-seekhead branch from 84ce8c8 to 7b66422 Compare December 1, 2026 14:31
Some Matroska files reference Cues through a chain of SeekHeads. Follow
the chain at the first Cluster and return to the saved media position
after reading the index.

Bound traversal and verify forward linked targets on unknown-length
inputs before seeking. Discard malformed optional index targets while
propagating errors from sequential reads. Retain the encoded Segment
size for existing direct Cues consumers.

Test the chained sample against the sample.mkv dumps and cover invalid
indexes, premature sequential EOF and truncated HTTP responses.

Issue: androidx#1143
@FongMi
FongMi force-pushed the media3-mkv-linked-seekhead branch from 7b66422 to b13eebf Compare December 1, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants