Skip to content

Fix Atmos frames being written to the wrong reel when a reel has no Atmos - #10

Merged
JaumeAP merged 1 commit into
mainfrom
fix/atmos-writer-reel-cursor
Oct 23, 2026
Merged

JaumeAP merged 1 commit into
mainfrom
fix/atmos-writer-reel-cursor

Conversation

@JaumeAP

@JaumeAP JaumeAP commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

If a DCP has several reels and some of them have no Atmos, the Atmos frames of a later reel are
written into an earlier one. The reel that should have the Atmos ends up without it, and the earlier
reel gets too much. dcp::verify then reports

All assets in a reel do not have the same duration.

and the DCP is wrong.

Why it matters

SMPTE ST 429-19:2019 (DCP Operational Constraints for Immersive Audio), section 6.2, says "Each
reel of an Immersive Audio Composition should contain an Immersive Audio element". It is a "should"
(recommended) rather than a "shall". In practice, a DCP in which some reels have Atmos and others do
not is a problem for some processors. I saw this at the Phenomena Experience cinema in Barcelona
(https://phenomena-experience.com) with the Spanish version of John Wick: Chapter 4 (2023): a reel 0
with added title cards had been put in front of the feature without Atmos, and the Dolby CP850
stayed in the "reverted" (to PCM) state instead of playing the Atmos.

The bug fixed here hits exactly the DCPs that follow that recommendation only partly, and turns them
into DCPs where the wrong reel has Atmos. This patch does not add Atmos to reels that have none; it
only stops the Atmos frames that do exist from being written to the wrong reel.

Cause

Writer::write() for Atmos frames keeps a cursor (_atmos_reel) on the reel that is receiving
frames. It moved the cursor to the next reel only when the frame's time was exactly the end of the
current reel (src/lib/writer.cc):

if (_atmos_reel->period().to == time) {
        ++_atmos_reel;

With Atmos in reel 1 (0-10 s) and reel 3 (20-30 s) and none in reel 2, the first frame of reel 3
arrives at 20 s. The cursor is still on reel 1, whose end is 10 s, so 10 s == 20 s is false, the
cursor does not move, and the frames of reel 3 are written to reel 1.

Fix

Move the cursor past every reel that ends at or before the frame:

while (_atmos_reel->period().to <= time) {
        ++_atmos_reel;
        DCPOMATIC_ASSERT(_atmos_reel != _reels.end());
}

For consecutive reels this is the same as before: the loop runs once, then stops because the next
reel ends after the frame.

Test

atmos_multi_reel_gap_test (in test/atmos_test.cc) makes three 10 s reels from
test/data/flat_red.png (at 0, 10 and 20 s) with test/data/atmos_0.mxf at 0 s and at 20 s, so the
middle reel has no Atmos. It checks that reels 1 and 3 have Atmos, reel 2 does not, and that each
Atmos asset is 240 frames. It uses only files from the public test data, the same Atmos file as
atmos_multi_reel_test.

Before the fix (writer.cc unchanged, test added):

$ build/test/unit-tests --run_test=atmos_multi_reel_gap_test,atmos_multi_reel_test
Running 2 test cases...
    All assets in a reel do not have the same duration.
../test/test.cc:1020: error: in "atmos_multi_reel_gap_test": check ok has failed
../test/atmos_test.cc:214: fatal error: in "atmos_multi_reel_gap_test": critical check reels[2]->atmos() has failed
*** 2 failures are detected in the test module "dcpomatic_test"

After the fix:

$ build/test/unit-tests --run_test=atmos_multi_reel_gap_test,atmos_multi_reel_test
Running 2 test cases...
*** No errors detected

atmos_multi_reel_test (three consecutive reels, each with Atmos) passes both before and after.

Also run on this branch, all without errors (45 test cases; two disabled ones are skipped):
atmos_*, reels_*, reel_*, vf_*, multi_reel*, encrypt_only_* and
encrypted_dcp_with_no_kdm_gives_no_butler_error, including atmos_encrypted_passthrough_test,
atmos_passthrough_test and atmos_trim_test. The branch also builds on Ubuntu 24.04 (the fork's
CI, which builds but does not run the tests).

Scope and risk

  • One line of logic in Writer::write(shared_ptr<const dcp::AtmosFrame>, ...); nothing else changes.
  • Behaviour changes only when a frame arrives later than the end of the cursor's reel, which is the
    case that used to produce a wrong DCP.
  • If a frame is later than every reel, DCPOMATIC_ASSERT fails (a ProgrammingError), as it already
    did for a frame exactly at the end of the last reel. Before, such a frame was written silently to
    the wrong reel.

What was not checked

  • The tests were run on macOS (Apple clang 21, Xcode 26) only. The checks that make_and_verify_dcp
    runs on Linux (dcp_inspect, clairmeta, the asdcplib tools) were not run.
  • The private test data used for the Atmos tests above is a regenerated copy, not Carl's own.

🤖 Generated with Claude Code

https://claude.ai/code/session_011HCUWvPpbN7e6hcwuWBJjs

…tmos.

Writer::write() for Atmos frames keeps a cursor on the reel that is
receiving frames, and moved it to the next reel only when the frame's
time was exactly the end of the current reel.  When a reel in between
had no Atmos at all, the next frame arrived later than that, the cursor
stayed where it was and the frames of a later reel were written to the
earlier one.  The earlier reel ended up with too much Atmos, the later
one with none, and verification failed with "All assets in a reel do
not have the same duration".

Advance the cursor past every reel that ends at or before the frame.
For consecutive reels this is the same as before.

Add a test with three reels and Atmos in the first and last only.

Claude-Session: https://claude.ai/code/session_011HCUWvPpbN7e6hcwuWBJjs
@JaumeAP
JaumeAP merged commit a25d38e into main Oct 23, 2026
1 check passed
@JaumeAP
JaumeAP deleted the fix/atmos-writer-reel-cursor branch October 23, 2026 17:08
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.

1 participant