Repository navigation
Conversation
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 09:16
d1293ad to
a3fe3c5
Compare
8 of 10 tasks
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 19:10
a3fe3c5 to
cc9c823
Compare
8 tasks done
decriptor
force-pushed
the
fix/matroska-seekhead-fallback
branch
from
November 21, 2026 19:25
ad69aca to
0311603
Compare
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 19:30
f20a858 to
e103f67
Compare
decriptor
force-pushed
the
fix/matroska-seekhead-fallback
branch
from
November 21, 2026 19:40
0311603 to
22f84e7
Compare
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
2 times, most recently
from
November 21, 2026 20:13
fedf2b8 to
f6b9a29
Compare
decriptor
force-pushed
the
fix/matroska-seekhead-fallback
branch
from
November 21, 2026 20:17
39c4b3f to
04d5de3
Compare
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 20:21
f6b9a29 to
0f385b9
Compare
decriptor
added a commit
that referenced
this pull request
Nov 21, 2026
DocTypeVersion has maxOccurs 1, but a file can store it twice. Every copy below 2 is now raised, and an empty copy is written as 2, as every FlagEnabled copy is written, so a reader that takes the first copy no longer sees 1. The header CRC is recomputed only when a copy changed. The same change as #148 round 2.
Owner
Author
|
Review: 0 findings at ca7f1cd. The last review round (at 583fbd6) found nothing. The only commit since then, ca7f1cd, is a test-only change: it adds the (empty, empty) DocTypeVersion row. All 277 Matroska tests pass at ca7f1cd. What was checked:
|
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 21:39
ca7f1cd to
7903cb6
Compare
FlagEnabled (0xB9) defaults to 1 and a stored 0 marks the track as not usable (RFC 9559 5.1.4.1.4). The main audio and video track is now the first enabled default track of that type, then the first enabled one. When every track of a type is disabled, the same order runs over the disabled tracks, since chapter codecs or control tracks can still make them usable. A missing or empty element is enabled. MatroskaFile.Tracks lists each known-size TrackEntry with its number, UID, type, codec ID, default flag, and enabled flag.
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A stored 1 to 8 octet element is rewritten in place. An empty or missing one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow to hold it, keeping their width when the new size fits. The growth comes out of the Void right after Tracks, so no element moves; without that room the save fails and nothing is written. A stored DocTypeVersion of 1 is raised to 2 when an element is added, since FlagEnabled has minver 2. A track the caller never set keeps its bytes. The track at each ordinal must still carry the number and UID it was read with, or the save fails. This is the same change as #140.
When no Void right after Tracks can take a new FlagEnabled, the grown Tracks goes through MatroskaRewrite.TryGrow: everything after it moves once, and the SeekHead, Cues, Cluster Position, and CRC-32 values follow. In-place edits and the adjacent Void are still preferred, since they move nothing. A second Tracks element without room still fails, as only one is allowed (RFC 9559 5.1.4, maxOccurs 1). The real-file test compares cluster payloads with Position zeroed, since a moved cluster's Position changes and its blocks do not.
…sion 2 A FlagEnabled insert that moves later elements now runs through the widened engine, so a Seek or Cues position that crosses a width boundary is written wider and CueCodecState and CueRefCluster follow their Cluster. The save tests compare every Seek that landed in the input with the output, so a dropped Seek fails them; the real-file toggle test does the same. Adding FlagEnabled (minver 2) makes the EBML header's DocTypeVersion at least 2 (RFC 9559 section 7): a lower stored value is raised in place, and an empty or missing one is written, growing the header and its CRC. The header is outside the Segment, so no Segment Position moves. An unknown-size Tracks with no Void after it names that reason instead of calling itself a second Tracks. The track fixtures use an EBML header with DocTypeVersion 4, as muxers write it.
The same change as #140 round 1 (its F2 and F4), applied to this stack: MatroskaFile.Tracks keeps at most 4096 entries while every entry still ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
The same change as #140 round 2 (its #1 and #3), applied to this stack: MatroskaFile.Tracks is documented as the first 4096 known-size TrackEntry elements, MatroskaFile.TracksTruncated says when a file had more, and tests pin the EBML header size widening (+5, 40 7F) and the wide empty DocTypeVersion shrink (-6).
…e refusals DocTypeVersion has maxOccurs 1, but a file can store it twice. Every copy below 2 is now raised, and an empty copy is written as 2, as every FlagEnabled copy is written, so a reader that takes the first copy no longer sees 1. The header CRC is recomputed only when a copy changed. The IsEnabled remarks list the refusals as examples: an unknown-size Tracks without room, a second Tracks, a SeekHead or TrackEntry that cannot be bounded, a FlagEnabled over 8 octets, a changed track number or UID.
Every other public bool in the library has an Is, Has or Uses prefix. The property is unreleased, so the rename breaks no one. The same change as #140 round 3.
A header with two empty DocTypeVersion copies must end with both at 2. Without this row, replacing only the first empty copy stayed green.
decriptor
force-pushed
the
feat/matroska-track-enabled-shift
branch
from
November 21, 2026 22:30
7903cb6 to
09f9e3a
Compare
decriptor
added a commit
that referenced
this pull request
Nov 22, 2026
DocTypeVersion has maxOccurs 1, but a file can store it twice. Every copy below 2 is now raised, and an empty copy is written as 2, as every FlagEnabled copy is written, so a reader that takes the first copy no longer sees 1. The header CRC is recomputed only when a copy changed. The same change as #148 round 2.
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.
Stacking
Stacked on #149 (
fix/matroska-seekhead-fallback, head52bf607, itself on #1422afe3b2, which is on main85ce8d2), which is itself stacked on #142. Merge order: #142 → #149 → #148. This PR's diff is only the ten commits on top of #149.This PR supersedes the refusal in #140. #140 writes a missing
FlagEnabledonly when the Void right afterTrackshas room, and refuses every other insert. Here, that insert goes through the sharedMatroskaRewrite.TryGrowshift instead. Commits:feat: Skip disabled Matroska tracks when choosing the main track: the same as feat: Honor and save the Matroska track enabled flag in place #140.feat: Save the Matroska track enabled flag: feat: Honor and save the Matroska track enabled flag in place #140's save behavior, conflict-resolved onto this base.feat: Move later elements when the track flag needs room: the new part.If this lands, #140 can be closed. If #140 lands first, commits 1 and 2 drop out on rebase.
Description
Matroska now reads and writes
TrackEntry\FlagEnabled(0xB9).Selection. The main audio and video track is the first enabled default track of that type, then the first enabled one. A track that stores
FlagEnabled0 can no longer win while an enabled track of its type exists. A missing or empty element counts as enabled (default 1).API.
MatroskaFile.Tracks(IReadOnlyList<MatroskaTrack>) lists the first 4096 known-sizeTrackEntryelements (MatroskaFile.IsTrackListTruncatedis true when a file has more):TrackNumber,TrackUid,TrackType(newMatroskaTrackType, RFC 9559 Table 2),CodecId,IsDefault, and a settableIsEnabled. It is shaped likeFlacCueSheet.Tracks.Saving. Only a track whose
IsEnabledthe caller set is touched, and only when the stored value differs. The three cases below are tried in order.B9 81 0v, and the TrackEntry and Tracks sizes grow (keeping their width when the new size fits). If the Void right after Tracks can give the octets (shrinking to nothing or to at least 2), nothing moves.MatroskaRewrite.TryGrow. Everything after Tracks moves once. SeekHead, Cues (CueClusterPosition), ClusterPosition, and their CRC-32s are patched by that shared code.Other rules:
TryGrowreplaces the first Tracks, and RFC 9559 §5.1.4 allows only one.Closes #117
Spec references
Design decisions
IsEnabledis sticky. Re-enabling after a save writes 1 again, and saving the same value twice gives identical bytes.Positionfollows the shift through fix: Keep a moved Matroska element listed in the SeekHead and move later elements for a track flag #149's engine. A value that no longer fits its field is written wider (round 1, F1/F3/F4: these were fixed in fix: Keep a moved Matroska element listed in the SeekHead and move later elements for a track flag #149, as assigned).ChapterFlagEnabledis left to the chapter editor.Type of Change
Checklist
dotnet test)Testing
Gates (this branch)
dotnet build -c Release: 0 warnings, 0 errors on all four TFMs.dotnet test -c Release: net8.0 4639 passed, 17 skipped; net10.0 4639 passed, 17 skipped. The skips are env-gated integration tests.dotnet format --verify-no-changes: clean.Unit tests
Positiongets its new valueIntegration:
MatroskaTrackIntegrationTests, env varTAGLIBSHARP2_TEST_MATROSKA, 3/3 on all 13 files below.Positionvalues are excluded from the comparison.Real files (track #2 disabled; #3 for multi.mkv, #1 for audio.mka)
Columns:
pos.ptsand order are identical in every row.ffprobe -read_intervals 1.5%+#5match the original.Positionvalues that point at their cluster.enzyme0.5.2 (MIT, PyPI), used only as an independent reader. ffprobe and mediainfo do not report FlagEnabled at all.8769001build)-live 1)The matrix above was re-run after rebasing onto
8769001.Round 1 (rebased onto #149
ad69aca)New tests (
MatroskaTrackEnabledShiftTests.cs), each failing at round-0 head a3fe3c5:AssertSeeksLandnow takes the original file, and fails when any Seek that landed in the input is missing or no longer lands (F2). The real-file toggle test compares the set of Seeks that land before and after. The reviewer's F2 mutation (drop the Cues Seek whenever it moves) now turns 12 tests red; before, all 233 passed.The reviewer's grid (45 file × track cells) was run at a3fe3c5 and this head. All 45 cells are identical: same save result, Seek/Cue/Position/CRC summary, packet positions and seek frames. The intended changes show on the reviewer's trigger files:
edge-65534.mkacl-65533.mkacodecstate.mkvcueref.mkvnodtv.mkvunknowntracks.mkvThe env-gated toggle test passes 3/3 on all 25 inputs (samples, Turning Lime and the reviewer's gen files), and fails at a3fe3c5 on edge-65534 and cl-65533. Patch coverage on this PR's source lines vs
ad69acais 93%.Cluster bytes. In test2/3/7/8, every cluster is byte-identical to the original apart from the patched
Positionvalue. In the other files every cluster payload is identical.Main audio after disabling: test5 and multi.mkv switch to the other, enabled audio track (44100 Hz). audio.mka switches to the 22050 Hz FLAC track.
Additional Notes
Implemented from RFC 9559 and RFC 8794 only. No media files are committed; tests build their inputs in code.
Round 2
The stack is rebased onto #142
2afe3b2, which is on main85ce8d2; this PR is on #14952bf607. Restacked from04d5de3after #149's round 3, and again from84fdb03after round 4. This PR's code is unchanged from the approvedca7f1cd; the only difference is one CHANGELOG context line that comes from #149. At the current head: net8.0 and net10.0 4643 passed / 17 skipped, 0 warnings, format clean, and env-gated tests 7/7 on test1, test3 and test7.fedf2b8, andMatroskaFile.IsTrackListTruncatedis public (as in feat: Honor and save the Matroska track enabled flag in place #140 round 2).[Unreleased]section with Added, Changed and Fixed, and main's Ogg lines are kept.IsEnabledremarks and "Remaining refusals" above now list the refusals as examples. The commit count is corrected to eight.Save_InsertedFlag_RaisesEveryDocTypeVersionCopy, which fails at f6b9a29 (expected 2, actual 1). On the reviewer'ssyn/dtvtwice.mkv(1, 4) the result is now (2, 4); ondtvtwice2.mkv(1, empty) it is (2, 2). The other DocTypeVersion files (crc-dtv1,crc-nodtv,dtv0,dtv8,hdr8-nodtv,plain) are byte-identical to the round-1 outputs.Round 3 (from #140's round 3)
Commit
583fbd6:MatroskaFile.TracksTruncatedis renamed toIsTrackListTruncated, matching the library's other public bools. The code, tests, PublicApi snapshot, CHANGELOG and this body are updated.