Repository navigation
Handle secondary and recursive SeekHead elements in MatroskaExtractor - #3479
rashidekbal wants to merge 5 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
I reviewed
For regression coverage, the existing
These were focused extractor probes, not a run of the full PR test suite. |
|
Thanks for the detailed review and test findings! I have updated the implementation to address both issues and added regression coverage in MatroskaExtractorNonParameterizedTest: Index-Resolution & Format Emission Ordering: |
|
Thanks for the update! I rechecked I found two remaining cases involving malformed Cues references:
For reproduction, I used Could these paths finish index resolution by publishing an unseekable map, emitting the required formats, and restoring the saved media position? Regression tests should also assert that samples are emitted after fallback and that index seek requests terminate. These are focused extractor checks: I used the PR extractor source with only its class name changed to coexist with the local extractor, and local dependency modules. I have not run the full upstream suite or device playback tests. |
|
Thanks for testing those edge cases! Both issues—along with additional hardening against cyclic and malformed Cues references—have been addressed in
|
|
Hey what is the status on this PR? It would solve a lot of problems for clients like jellyfin etc. |
|
@TharathielCB i am also waiting for response |
|
@rohitjoins hasn't had a chance to review this PR yet - but before that can happen, please can you re-target it to the |
When resolving secondary SeekHead elements, format emission was delayed until Cues were parsed. If the secondary SeekHead pointed directly to Cues or contained only Cluster entries, the extractor returned directly to the saved Cluster position without scheduling Cues or completing the no-Cues fallback first, causing samples to be emitted before track formats. This commit updates the index-resolution flow to: - Properly schedule Cues parsing or complete the no-Cues fallback (emitting track formats and unseekable SeekMap) before returning to sample reading. - Support multi-hop SeekHead traversal up to a bounded depth (16 hops). - Detect and prevent cycles using visited and pending position tracking. - Reset index traversal state when an explicit seek to position 0 occurs before the seek map is finalized. - Add regression test coverage in MatroskaExtractorNonParameterizedTest for single-hop, multi-hop, Cluster-only secondary SeekHead, cycles, and seek resets. Fixes androidx#1143
When resolving the index (via secondary SeekHead or Cues): - If a Cues reference points to a Cluster, encountering ID_CLUSTER during index resolution could cause maybePrepareSeekMap() to repeatedly schedule seeks to the same position. Now, encountering ID_CLUSTER while seekPositionAfterBuildingCues is set completes index resolution fallback (emitting unseekable SeekMap, track formats, and clearing index flags), and avoids redundant seeks if already at the saved Cluster position. - If EOF is reached while resolving the index (such as a Cues pointer referencing an element at or past the end of input), the extractor now executes terminal fallback by emitting an unseekable SeekMap and track formats, and restores position to the saved Cluster to resume media playback. - Add regression tests in MatroskaExtractorNonParameterizedTest covering both cases. Fixes androidx#1143
- Consume cuesContentPosition upon scheduling seek and record target position in visitedSeekHeadPositions to prevent repeated seeks and cyclic Cues references. - Reject Cues entries pointing to already-visited SeekHead positions. - Guard visitedSeekHeadPositions array bounds against MAX_SEEK_HEAD_HOPS. - Ensure seekMap and track formats are emitted if EOF is reached before seek map is sent. - Validate seekEntryPosition in integerElement against negative values. - Add regression tests in MatroskaExtractorNonParameterizedTest for Cues pointing to non-Cues SeekHead and mutual cyclic Cues references. Fixes androidx#1143
582e6fa to
1d70c25
Compare
|
Thanks for pointing that out! I've rebased the branch onto main and updated the PR target to main. It should be clean and ready for review now. |
Issue: #1143
Problem
Certain Matroska (
.mkv) files, especially large WEB-DL and high-definition encodes created bymkvmerge, place theirCueselement reference inside a secondary (chained/recursive)SeekHeadrather than the primarySeekHeadat the beginning of the file.When reading these files,
MatroskaExtractoronly recordedID_CUESandID_TRACKSseek entries from the primarySeekHead. It ignoredID_SEEK_HEADentries. Consequently,cuesContentPositionremained unset (C.INDEX_UNSET). WhenbuildSeekMap()was invoked,MatroskaExtractorconcluded that the file lacked cues and initialized an unseekableSeekMap.Unseekable(durationUs), rendering the media non-seekable despite valid cues existing in the container.Solution
MatroskaExtractor.endMasterElement(), check forseekEntryId == ID_SEEK_HEAD. WhencuesContentPosition == C.INDEX_UNSET, recordsecondarySeekHeadPosition = seekEntryPosition.cuesContentPositionhas not been located butsecondarySeekHeadPositionis known, initiate a seek viamaybeSeekForSecondarySeekHead()to parse the secondarySeekHeadand discover the truecuesContentPosition.buildSeekMap()and early format emission guards so that seeking is not prematurely disabled as unseekable before attempting to parse the secondary SeekHead.SeekHead, restore the input position back to the previous track reading offset.Testing
SeekHeadpointing toCues.cuesContentPositionis successfully resolved,Cuesare parsed, seek map entries are built, and seeking functions accurately without regression.