forge
Explore
Log in

Don't you dare go Hollow

The seat line finishes the sentence about the sound

Browse files at this commit

aa6d6991f27d2f32d88bc1de405c0ed41eba2a9dAhmet Kaan GümüşParent: 9fdee6f
  • fix
    • the seat line finishes the sentence about the sound
Show full message
🐛 fix(engine): the seat line finishes the sentence about the sound

An mp4 mixes its sound on a thread beside the picture, so the encoders
line is published half-written -- "HW encode (VA-API) · working out the
sound…" -- and completed once the pass is collected. The frame loop does
that where the sound lands under the picture; where the *picture*
finishes first the pass is collected under the muxer instead, and that
path never published again: a card left saying it was still working out
a track it had already written.

The tests read the line the same way now. They took the first one
published, which since hardware encode got fast enough to beat the mix
was the half-line, and `a_mixed_timeline_says_it_re_encodes_and_then_does`
and `the_planned_encoders_are_the_ones_the_job_opens` failed on it every
run; `published_encoders` waits for the line a card settles on instead,
and the mixed timeline runs to the end to read that settled line twice.
crates/engine/src/export.rsmodified+17 -0
@@ -2221,6 +2221,23 @@ fn run(
22212221 "export audio: waited for after {:.1} s of picture",
22222222 picture_started.elapsed().as_secs_f64()
22232223 );
2224+ // ...and the line on screen finished with it. The loop above
2225+ // publishes the measured codec the moment the pass lands
2226+ // under the picture, but a picture that outran the mix never
2227+ // reaches that branch -- and "working out the sound…" would
2228+ // then be the last thing the card ever said about a track it
2229+ // had long since written.
2230+ publish_seats(
2231+ shared,
2232+ seat,
2233+ project,
2234+ settings,
2235+ track.as_ref().map(|track| track.copied),
2236+ track
2237+ .as_ref()
2238+ .is_some_and(|track| track.opus_pre_skip.is_some()),
2239+ false,
2240+ );
22242241 track
22252242 }
22262243 None => late,
crates/engine/tests/backends.rsmodified+50 -44
@@ -123,22 +123,7 @@ fn the_planned_encoders_are_the_ones_the_job_opens() {
123123 );
124124 let out = out_path("planned", ext);
125125 let handle = session.export_to_with(&out, &settings);
126- let started = Instant::now();
127- let opened = loop {
128- if let Some(line) = handle.encoders() {
129- break line;
130- }
131- assert!(
132- !handle.is_finished(),
133- "the export settled before it opened an encoder: {:?}",
134- handle.result().map(|r| r.err())
135- );
136- assert!(
137- started.elapsed() < Duration::from_secs(60),
138- "no encoder was published"
139- );
140- std::thread::sleep(Duration::from_millis(10));
141- };
126+ let opened = published_encoders(&handle, ext);
142127 // Nothing here wants the file, only the seat it was going to be written
143128 // with: cancelling deletes the `.part` the worker had started.
144129 handle.cancel();
@@ -201,22 +186,7 @@ fn the_planned_seat_follows_the_size_and_the_pin() {
201186 }
202187 let out = out_path("seat", ext);
203188 let handle = session.export_to_with(&out, &settings);
204- let started = Instant::now();
205- let opened = loop {
206- if let Some(line) = handle.encoders() {
207- break line;
208- }
209- assert!(
210- !handle.is_finished(),
211- "{ext} {width}x{height}: settled before an encoder opened: {:?}",
212- handle.result().map(|r| r.err())
213- );
214- assert!(
215- started.elapsed() < Duration::from_secs(60),
216- "no encoder was published"
217- );
218- std::thread::sleep(Duration::from_millis(10));
219- };
189+ let opened = published_encoders(&handle, &format!("{ext} {width}x{height}"));
220190 handle.cancel();
221191 wind_down(&handle);
222192 assert!(
@@ -313,28 +283,64 @@ fn a_mixed_timeline_says_it_re_encodes_and_then_does() {
313283 ..ExportSettings::default()
314284 },
315285 );
286+ let opened = published_encoders(&handle, "a mixed timeline");
287+ assert!(
288+ opened.ends_with(&planned),
289+ "{opened} does not end in {planned}"
290+ );
291+ // ...and it is the line the job *settles* on, which is why this one runs to
292+ // the end instead of cancelling: an mp4 mixes its sound beside the picture,
293+ // and a hardware picture is through first, so the measured codec reaches the
294+ // line where the pass is collected under the muxer rather than in the frame
295+ // loop. A card left saying "working out the sound…" over a written file is
296+ // the same lie as one naming a codec that never ran.
316297 let started = Instant::now();
317- let opened = loop {
318- if let Some(line) = handle.encoders() {
319- break line;
298+ while !handle.is_finished() {
299+ assert!(
300+ started.elapsed() < Duration::from_secs(300),
301+ "the export did not finish in 300 s"
302+ );
303+ std::thread::sleep(Duration::from_millis(10));
304+ }
305+ handle.result().expect("an outcome").expect("the export");
306+ let settled = handle.encoders().expect("a finished job still names its seats");
307+ assert!(
308+ settled.ends_with(&planned),
309+ "the export settled on {settled}, which does not end in {planned}"
310+ );
311+}
312+
313+/// The half-line an export shows while its sound is still being mixed on the
314+/// thread beside the picture (`engine::export::publish_seats`). An mp4 job
315+/// overlaps the two passes, so this is what the *first* line out of one says
316+/// about a codec that has not run yet.
317+const MIXING: &str = "working out the sound…";
318+
319+/// The encoders line a running job settles on: published as soon as the picture
320+/// seat is open, and completed once the sound has been measured. Waiting for the
321+/// second half is what makes this the line a card shows rather than a snapshot
322+/// of an export mid-decision -- and, because a job that ends without ever
323+/// completing it fails here, it is also the pin on that completion happening at
324+/// all, whichever of the two passes finishes first.
325+fn published_encoders(handle: &ExportHandle, what: &str) -> String {
326+ let started = Instant::now();
327+ loop {
328+ match handle.encoders() {
329+ Some(line) if !line.ends_with(MIXING) => return line,
330+ _ => {}
320331 }
321332 assert!(
322333 !handle.is_finished(),
323- "the export settled before it opened an encoder: {:?}",
334+ "{what}: the export settled without naming its encoders ({:?}): {:?}",
335+ handle.encoders(),
324336 handle.result().map(|r| r.err())
325337 );
326338 assert!(
327339 started.elapsed() < Duration::from_secs(60),
328- "no encoder was published"
340+ "{what}: no encoder was published"
329341 );
330342 std::thread::sleep(Duration::from_millis(10));
331- };
332- handle.cancel();
333- wind_down(&handle);
334- assert!(
335- opened.ends_with(&planned),
336- "{opened} does not end in {planned}"
337- );
343+ }
338344 }
339345
340346 /// Waits for a cancelled job to settle, so its `.part` is gone before the test