forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into worktree-agent-a5b9617c2130e9ba7

Browse files at this commit

36c8b93803da5e6ddf57fcd0bb2a6f54320d3ec3Ahmet Kaan GümüşParent: cdb0c4b9728053
crates/app/src/main.rsmodified+228 -35
@@ -11,11 +11,12 @@ use std::time::{Duration, Instant};
1111
1212 use engine::audio::StreamInfo;
1313 use engine::color::ColorParams;
14+use engine::decode::Backend;
1415 use engine::eq::{Band, BandKind, EqParams};
1516 use engine::export::{ExportSettings, Format};
1617 use engine::project::{Edge, Lane, LaneKind, Source, Speed};
1718 use engine::scale::FitPolicy;
18-use engine::{Clip, ExportHandle, Frame, PlaybackSession};
19+use engine::{Clip, Codec, ExportHandle, Frame, PlaybackSession};
1920 use gpui::{
2021 AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, FocusHandle,
2122 KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels,
@@ -644,6 +645,19 @@ struct Player {
644645 /// `None` is a file with no picture to report (every source that is not an
645646 /// image, and one whose header would not read).
646647 sizes: HashMap<PathBuf, Option<(u32, u32)>>,
648+ /// Which decoder each source will run on, probed once at import and kept:
649+ /// the codec (`None` for a still) and the seat the engine picked for it.
650+ /// What a library row says *before* anything plays; the running answer is
651+ /// the session's own (`PlaybackSession::decode_backend`), which follows a
652+ /// fallback this cannot. Filled like `sizes`: presence means "asked", and
653+ /// `None` is a source with no decoder to name -- a song, or one the probe
654+ /// refused -- which must stay in the map or every repaint would ask again.
655+ decoders: HashMap<PathBuf, Option<(Option<Codec>, Backend)>>,
656+ /// Which encoder an export of the picked settings would open, and what it
657+ /// was asked about: the probe opens a real VA-API encoder (~100 ms), so it
658+ /// runs off the render thread and only while the export card is up. The
659+ /// inner `None` is "asked, not answered yet".
660+ export_seat: Option<(ExportSettings, (u32, u32), Option<&'static str>)>,
647661 /// The copied clip. Frame ranges only, so it survives the clip it was taken
648662 /// from being deleted -- and it outlives the selection.
649663 clipboard: Option<Clip>,
@@ -2011,6 +2025,28 @@ impl Player {
20112025 })
20122026 .detach();
20132027 }
2028+ // Which decoder each file will run on, for the row that says so before
2029+ // a frame of it plays. Off the render thread like the streams above: a
2030+ // stream the plugin takes costs one VA-API init (~90 ms) to answer.
2031+ for path in unseen_paths(session.sources(), &self.decoders) {
2032+ self.decoders.insert(path.clone(), None);
2033+ let probed = cx.background_executor().spawn({
2034+ let path = path.clone();
2035+ // A song and a source no decoder here takes are both `None`:
2036+ // the row says nothing about them rather than guessing, and
2037+ // import refused the second at the door anyway.
2038+ async move { engine::decode::probe(&path).ok() }
2039+ });
2040+ cx.spawn(async move |this, cx| {
2041+ let probed = probed.await;
2042+ this.update(cx, |this, cx| {
2043+ this.decoders.insert(path, probed);
2044+ cx.notify();
2045+ })
2046+ .ok();
2047+ })
2048+ .detach();
2049+ }
20142050 for key in unseen_sources(session.sources(), &self.waves) {
20152051 self.waves.insert(key.clone(), Wave::Loading);
20162052 let decoded = cx.background_executor().spawn({
@@ -2043,6 +2079,51 @@ impl Player {
20432079 }
20442080 }
20452081
2082+ /// Probes the encoder an export would open, once per (settings,
2083+ /// resolution) and only while the export card is up -- it opens the very
2084+ /// VA-API encoder the export would, which is what makes the card's line a
2085+ /// measurement instead of a promise, and also what makes it too slow for
2086+ /// the render thread. Written before the spawn, like the probes above, so
2087+ /// the repaints during it start no second one.
2088+ fn cache_export_seat(&mut self, cx: &mut Context<Self>) {
2089+ let Some(session) = &self.session else {
2090+ return;
2091+ };
2092+ let settings = export_settings(self.quality, self.custom_mbps, self.format);
2093+ if !self.export_open || !settings.format.has_video() {
2094+ return;
2095+ }
2096+ let meta = *session.meta();
2097+ let key = (settings, (meta.width, meta.height));
2098+ if self
2099+ .export_seat
2100+ .is_some_and(|(asked, size, _)| (asked, size) == key)
2101+ {
2102+ return;
2103+ }
2104+ self.export_seat = Some((key.0, key.1, None));
2105+ let probed = cx
2106+ .background_executor()
2107+ .spawn(async move { engine::export::planned_video(&meta, &settings) });
2108+ cx.spawn(async move |this, cx| {
2109+ let probed = probed.await;
2110+ this.update(cx, |this, cx| {
2111+ // Only if the card is still asking the same question: a format
2112+ // changed while the plugin opened has a probe of its own.
2113+ if let Some(seat) = this
2114+ .export_seat
2115+ .as_mut()
2116+ .filter(|(asked, size, _)| (*asked, *size) == key)
2117+ {
2118+ seat.2 = probed;
2119+ }
2120+ cx.notify();
2121+ })
2122+ .ok();
2123+ })
2124+ .detach();
2125+ }
2126+
20462127 /// The group id of the clicked clip, which is what marks the other half.
20472128 fn selected_link(&self) -> Option<u32> {
20482129 let (lane, idx) = self.selected?;
@@ -3152,6 +3233,7 @@ impl Render for Player {
31523233 // has been through a repaint by the time its clips are drawn, so this
31533234 // is the one place that has to notice a new one.
31543235 self.cache_media(cx);
3236+ self.cache_export_seat(cx);
31553237 // What the compositor calls this window. Pushed only when it changes:
31563238 // it is a protocol round trip and this runs at vsync.
31573239 let title = window_title(&self.name);
@@ -3642,11 +3724,17 @@ impl Player {
36423724 // Its own length, not one derived from what is on the lanes: a row
36433725 // imported and never placed is a row with a length, and it is the
36443726 // length a drag would put down.
3645- let rows: Vec<_> = library_rows(sources, &self.streams, self.timeline_audio(), |path| {
3646- self.session
3647- .as_ref()
3648- .map_or(0, |session| session.file_frames(path))
3649- })
3727+ let rows: Vec<_> = library_rows(
3728+ sources,
3729+ &self.streams,
3730+ &self.decoders,
3731+ self.timeline_audio(),
3732+ |path| {
3733+ self.session
3734+ .as_ref()
3735+ .map_or(0, |session| session.file_frames(path))
3736+ },
3737+ )
36503738 .into_iter()
36513739 .enumerate()
36523740 .map(|(i, row)| {
@@ -3883,6 +3971,30 @@ impl Player {
38833971 ))
38843972 }
38853973
3974+ /// What is decoding the picture right now, for the transport line: the
3975+ /// backend is the running worker's own (it is written where a hardware
3976+ /// session falls back to software, so this follows reality), and the codec
3977+ /// comes from the clip under the playhead. Empty when nothing is playing --
3978+ /// the question is about what is happening, not about what would.
3979+ fn live_decode(&self, position: f64, playing: bool) -> String {
3980+ let Some(session) = self.session.as_ref().filter(|_| playing) else {
3981+ return String::new();
3982+ };
3983+ let backend = session.decode_backend();
3984+ let codec = session
3985+ .video_clip_at(position)
3986+ .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| clip.source))
3987+ .and_then(|source| session.sources().get(source))
3988+ .and_then(|source| self.decoders.get(&source.path).copied().flatten())
3989+ .and_then(|(codec, _)| codec);
3990+ match backend {
3991+ // Neither is a decode, and saying "SW" of them would be a lie.
3992+ Backend::Gap => "gap · nothing to decode".to_string(),
3993+ Backend::Still => "still · one decode, held".to_string(),
3994+ _ => format!("{} decode", decode_label(codec, backend)),
3995+ }
3996+ }
3997+
38863998 /// Transport, edit and file buttons, timecode, playhead, clips lane.
38873999 fn panel(
38884000 &self,
@@ -3924,8 +4036,16 @@ impl Player {
39244036 let progress = export.progress();
39254037 (
39264038 format!(
3927- "EXPORTING {}% — {} cancels",
4039+ "EXPORTING {}% · {} · {} — {} cancels",
39284040 (progress * 100.) as u32,
4041+ // The row that was picked; the engine's line below names the
4042+ // seats alone, since the library is what identifies a codec.
4043+ format_label(self.format),
4044+ // What the worker actually opened, so a fallback to the
4045+ // software encoder shows here rather than being invisible.
4046+ export
4047+ .encoders()
4048+ .unwrap_or_else(|| "opening the encoder".to_string()),
39294049 key(ActionId::CancelExport)
39304050 ),
39314051 progress,
@@ -3935,12 +4055,19 @@ impl Player {
39354055 // tooltips. Keys first: at a 640 px window the tail is what a
39364056 // truncation eats, and the two hints at the end are also on the
39374057 // ruler's and Import's tooltips.
4058+ // While it plays, what is decoding it goes first: it is the
4059+ // answer that changes as the playhead crosses a cut, and the tail
4060+ // of this line is what a narrow window truncates.
39384061 (
3939- format!(
3940- "{} copy · {} paste · {} undo · click the bar to seek · drop a file to import",
3941- key(ActionId::Copy),
3942- key(ActionId::Paste),
3943- key(ActionId::Undo)
4062+ join_detail(
4063+ &self.live_decode(position, playing),
4064+ &format!(
4065+ "{} copy · {} paste · {} undo · click the bar to seek · drop a file to \
4066+ import",
4067+ key(ActionId::Copy),
4068+ key(ActionId::Paste),
4069+ key(ActionId::Undo)
4070+ ),
39444071 ),
39454072 filled,
39464073 )
@@ -4711,7 +4838,11 @@ impl Player {
47114838 .px(px(6.))
47124839 .text_size(px(11.))
47134840 .text_color(rgb(INK_DIM))
4714- .child(export_line(self.format, self.session.as_ref())),
4841+ .child(export_line(
4842+ self.format,
4843+ self.session.as_ref(),
4844+ self.export_seat.and_then(|(.., seat)| seat),
4845+ )),
47154846 )
47164847 .child(
47174848 div()
@@ -6576,6 +6707,7 @@ struct Row {
65766707 fn library_rows(
65776708 sources: &[Source],
65786709 streams: &HashMap<PathBuf, Vec<StreamInfo>>,
6710+ decoders: &HashMap<PathBuf, Option<(Option<Codec>, Backend)>>,
65796711 timeline_audio: Option<(u32, u16)>,
65806712 frames: impl Fn(&Path) -> u32,
65816713 ) -> Vec<Row> {
@@ -6591,12 +6723,22 @@ fn library_rows(
65916723 path: source.path.clone(),
65926724 stream: source.audio_stream,
65936725 name: row_name(&source.path, source.audio_stream, of_file.len() > 1),
6594- // Only where there is a choice to describe: a file with one audio
6595- // track is the row it has always been, name and length, and the
6596- // length is what would be squeezed out at the panel's least width.
6597- detail: info
6598- .filter(|_| of_file.len() > 1)
6599- .map_or_else(String::new, stream_detail),
6726+ // The decoder first: it is the same for every row of a file and
6727+ // it is what a person opening the panel is asking about. The
6728+ // stream half only where there is a choice to describe -- a file
6729+ // with one audio track is the row it has always been, name and
6730+ // length, and the length is what would be squeezed out at the
6731+ // panel's least width.
6732+ detail: join_detail(
6733+ &decoders
6734+ .get(&source.path)
6735+ .copied()
6736+ .flatten()
6737+ .map_or_else(String::new, |(codec, backend)| decode_label(codec, backend)),
6738+ &info
6739+ .filter(|_| of_file.len() > 1)
6740+ .map_or_else(String::new, stream_detail),
6741+ ),
66006742 // A stream already on the timeline is playing: whatever a probe
66016743 // would say about it now, it is usable by demonstration.
66026744 unusable: None,
@@ -6633,9 +6775,20 @@ fn library_rows(
66336775 /// why it cannot be used, with the separator only where both halves exist (a
66346776 /// single-stream file says nothing about its stream).
66356777 fn join_detail(detail: &str, tail: &str) -> String {
6636- match detail.is_empty() {
6637- true => tail.to_string(),
6638- false => format!("{detail} · {tail}"),
6778+ match (detail.is_empty(), tail.is_empty()) {
6779+ (true, _) => tail.to_string(),
6780+ (false, true) => detail.to_string(),
6781+ (false, false) => format!("{detail} · {tail}"),
6782+ }
6783+}
6784+
6785+/// How a source's decoder reads: the codec and which seat has it, or the seat
6786+/// alone for a still, which has no coded stream to name. The one place either
6787+/// answer is spelled, so a row, a transport line and a card cannot disagree.
6788+fn decode_label(codec: Option<Codec>, backend: Backend) -> String {
6789+ match codec {
6790+ Some(codec) => format!("{} · {}", codec.name(), backend.label()),
6791+ None => backend.label().to_string(),
66396792 }
66406793 }
66416794
@@ -6953,14 +7106,32 @@ fn next_resolution(current: (u32, u32), native: (u32, u32)) -> (u32, u32) {
69537106 /// [`format_line`] plus the project's resolution, which is what a video export
69547107 /// is written at however many sizes the media on the timeline are. Only for the
69557108 /// formats that carry a picture -- a WAV has no resolution to state.
6956-fn export_line(format: Format, session: Option<&PlaybackSession>) -> String {
7109+fn export_line(
7110+ format: Format,
7111+ session: Option<&PlaybackSession>,
7112+ seat: Option<&'static str>,
7113+) -> String {
69577114 let line = format_line(format);
7115+ // What it will really be encoded by, on the same line: the picture's seat
7116+ // as the probe found it (`…` until it lands, never a guess) and the sound's,
7117+ // which is decided without opening anything. Both are what a running export
7118+ // then names on its progress line, from the same two functions.
7119+ let encoders = match session {
7120+ Some(session) => join_detail(
7121+ seat.unwrap_or(match format.has_video() {
7122+ true => "encoder …",
7123+ false => "",
7124+ }),
7125+ session.planned_audio(format),
7126+ ),
7127+ None => String::new(),
7128+ };
69587129 match session.filter(|_| format.has_video()) {
69597130 Some(session) => {
69607131 let (w, h) = session.resolution();
6961- format!("{line} · project {w}x{h}")
7132+ format!("{line} · project {w}x{h} · {encoders}")
69627133 }
6963- None => line.to_string(),
7134+ None => join_detail(line, &encoders),
69647135 }
69657136 }
69667137
@@ -8062,9 +8233,13 @@ mod tests {
80628233 );
80638234 // The rows the panel draws: one per source, each its file's own length
80648235 // -- source 1 has no clip anywhere and is still 4 s at 30 fps.
8065- let rows = library_rows(session.sources(), &HashMap::new(), None, |path| {
8066- session.file_frames(path)
8067- });
8236+ let rows = library_rows(
8237+ session.sources(),
8238+ &HashMap::new(),
8239+ &HashMap::new(),
8240+ None,
8241+ |path| session.file_frames(path),
8242+ );
80688243 assert_eq!(rows.len(), 2);
80698244 assert_eq!(rows[0].frames, 150, "5 s at 30 fps");
80708245 assert_eq!(rows[1].frames, 120, "4 s at 30 fps, never placed");
@@ -8103,7 +8278,9 @@ mod tests {
81038278 .find(|s| s.index == session.sources()[0].audio_stream)
81048279 .map(|s| (s.sample_rate, s.channels));
81058280 let frames = session.file_frames(&path);
8106- let rows = library_rows(session.sources(), &streams, rate, |_| frames);
8281+ let rows = library_rows(session.sources(), &streams, &HashMap::new(), rate, |_| {
8282+ frames
8283+ });
81078284 assert_eq!(rows.len(), 1);
81088285 assert_eq!(rows[0].name, "test_tone.mp3");
81098286 assert_eq!(rows[0].unusable, None, "the row is placeable");
@@ -8170,7 +8347,13 @@ mod tests {
81708347 info(3, 0, 0, None, false),
81718348 ],
81728349 );
8173- let rows = library_rows(&sources, &streams, Some((44_100, 2)), |_| 90);
8350+ let rows = library_rows(
8351+ &sources,
8352+ &streams,
8353+ &HashMap::new(),
8354+ Some((44_100, 2)),
8355+ |_| 90,
8356+ );
81748357 assert_eq!(
81758358 rows.iter().map(|r| r.stream).collect::<Vec<_>>(),
81768359 [0, 1, 2, 3],
@@ -8208,7 +8391,7 @@ mod tests {
82088391 PathBuf::from("/m/plain.mp4"),
82098392 vec![info(0, 44_100, 2, None, true)],
82108393 );
8211- let rows = library_rows(&plain, &one, Some((44_100, 2)), |_| 90);
8394+ let rows = library_rows(&plain, &one, &HashMap::new(), Some((44_100, 2)), |_| 90);
82128395 assert_eq!(rows.len(), 1);
82138396 assert_eq!(rows[0].name, "plain.mp4");
82148397 assert_eq!(
@@ -8219,7 +8402,7 @@ mod tests {
82198402 let mut silent = HashMap::new();
82208403 silent.insert(PathBuf::from("/m/plain.mp4"), Vec::new());
82218404 for probe in [silent, HashMap::new()] {
8222- let rows = library_rows(&plain, &probe, None, |_| 90);
8405+ let rows = library_rows(&plain, &probe, &HashMap::new(), None, |_| 90);
82238406 assert_eq!(rows.len(), 1);
82248407 assert_eq!(rows[0].name, "plain.mp4");
82258408 assert_eq!(rows[0].detail, "");
@@ -8237,7 +8420,13 @@ mod tests {
82378420 PathBuf::from("/m/other.mp4"),
82388421 vec![info(0, 44_100, 2, None, true)],
82398422 );
8240- let rows = library_rows(&placed, &streams, Some((44_100, 2)), |_| 90);
8423+ let rows = library_rows(
8424+ &placed,
8425+ &streams,
8426+ &HashMap::new(),
8427+ Some((44_100, 2)),
8428+ |_| 90,
8429+ );
82418430 assert_eq!(
82428431 rows.iter()
82438432 .map(|r| (file_name(&r.path), r.stream))
@@ -8640,7 +8829,7 @@ mod tests {
86408829 );
86418830 let streams = HashMap::new();
86428831 let rows = |session: &PlaybackSession| {
8643- library_rows(session.sources(), &streams, None, |_| 0).len()
8832+ library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len()
86448833 };
86458834 assert_eq!(rows(&session), 2, "a row per source");
86468835
@@ -10033,7 +10222,9 @@ mod tests {
1003310222 // a title and a status line.
1003410223 let title = 17.;
1003510224 let status = 28.;
10036- let fixed = 17.;
10225+ // Two lines of 11 px: the format line carries the encoders an export
10226+ // would open, which is what takes it past one at this width.
10227+ let fixed = 30.;
1003710228 let gaps = 4. * 2.;
1003810229 let padding = 24.;
1003910230 assert!(
@@ -10581,6 +10772,8 @@ fn main() {
1058110772 waves: HashMap::new(),
1058210773 streams: HashMap::new(),
1058310774 sizes: HashMap::new(),
10775+ decoders: HashMap::new(),
10776+ export_seat: None,
1058410777 clipboard: None,
1058510778 scrubbing: false,
1058610779 trim: None,
crates/engine/src/decode.rsmodified+116 -1
@@ -3,7 +3,7 @@
33
44 use std::path::{Path, PathBuf};
55 use std::sync::Arc;
6-use std::sync::atomic::{AtomicBool, Ordering};
6+use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
77 use std::sync::mpsc::{Receiver, SyncSender, sync_channel};
88 use std::thread;
99
@@ -25,6 +25,106 @@ pub struct Frame {
2525 pub bgra: Vec<u8>,
2626 }
2727
28+/// Which decoder a source is really running on. Read-only introspection: it
29+/// decides nothing, it *reports* what [`DecodeSession::open_worker`] chose --
30+/// a hardware session that opened and then failed before its first picture
31+/// falls back to software and this says so, because it is written where the
32+/// fallback happens rather than where it was hoped for.
33+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
34+pub enum Backend {
35+ /// The worker has not reached its decoder yet: the plugin's VA-API init is
36+ /// ~90 ms, and this is what a caller reads in that window.
37+ #[default]
38+ Opening,
39+ /// The VA-API plugin (`libengine_hw.so`).
40+ Hardware,
41+ /// `rusty_h264`, in this process.
42+ Software,
43+ /// A still image: one `image` decode, no stream and no decoder to pick.
44+ Still,
45+ /// A gap: black frames, nothing decoded at all.
46+ Gap,
47+}
48+
49+impl Backend {
50+ /// Short enough for a library row and a transport line.
51+ pub fn label(self) -> &'static str {
52+ match self {
53+ Self::Opening => "opening",
54+ Self::Hardware => "HW",
55+ Self::Software => "SW",
56+ Self::Still => "still",
57+ Self::Gap => "gap",
58+ }
59+ }
60+
61+ fn code(self) -> u8 {
62+ match self {
63+ Self::Opening => 0,
64+ Self::Hardware => 1,
65+ Self::Software => 2,
66+ Self::Still => 3,
67+ Self::Gap => 4,
68+ }
69+ }
70+
71+ fn from_code(code: u8) -> Self {
72+ match code {
73+ 1 => Self::Hardware,
74+ 2 => Self::Software,
75+ 3 => Self::Still,
76+ 4 => Self::Gap,
77+ _ => Self::Opening,
78+ }
79+ }
80+}
81+
82+/// Where a worker publishes the decoder it opened, for whoever holds the other
83+/// end of its channel. One atomic byte, written once at open (and once more if
84+/// hardware hands the range back to software), read whenever a caller repaints
85+/// -- never per frame on either side.
86+#[derive(Clone, Default)]
87+pub struct BackendCell(Arc<AtomicU8>);
88+
89+impl BackendCell {
90+ fn new(backend: Backend) -> Self {
91+ Self(Arc::new(AtomicU8::new(backend.code())))
92+ }
93+
94+ fn set(&self, backend: Backend) {
95+ self.0.store(backend.code(), Ordering::Relaxed);
96+ }
97+
98+ pub fn get(&self) -> Backend {
99+ Backend::from_code(self.0.load(Ordering::Relaxed))
100+ }
101+}
102+
103+/// Which decoder `path` would open, decided exactly as [`DecodeSession::open_worker`]
104+/// decides it: the same `VE_SW` pin and the same plugin probe against this very
105+/// file. What lets a front-end name the decoder *before* anything plays.
106+///
107+/// The codec is `None` for a still image, which has no coded stream. A stream
108+/// no decoder here can take is an `Err` naming the plugin, exactly as opening
109+/// it would be -- the same refusal, one VA-API init earlier.
110+///
111+/// Costs that one init (~90 ms) for a stream the plugin takes: ask it once per
112+/// file, off a render thread, and keep the answer.
113+pub fn probe(path: &Path) -> crate::Result<(Option<Codec>, Backend)> {
114+ if crate::is_image(path) {
115+ return Ok((None, Backend::Still));
116+ }
117+ let path = path.to_path_buf();
118+ let (meta, _demuxer) = Demuxer::open(&path)?;
119+ if open_hw(&path, 0).is_some() {
120+ return Ok((Some(meta.codec), Backend::Hardware));
121+ }
122+ if meta.codec != Codec::H264 {
123+ return Err(meta.codec.needs_plugin().into());
124+ }
125+ Ok((Some(meta.codec), Backend::Software))
126+}
127+
28128 /// A running decode worker: the flag that stops it, and the handle to wait on.
29129 ///
30130 /// Dropping one cancels *and joins*. A worker abandoned mid-`vaInitialize`
@@ -85,6 +185,9 @@ impl Drop for Worker {
85185 pub(crate) struct FrameStream {
86186 pub(crate) frames: Receiver<Frame>,
87187 pub(crate) worker: Worker,
188+ /// What this stream's pictures are being decoded by. Dropped last and read
189+ /// by the caller, so it outlives nothing and blocks nothing.
190+ pub(crate) backend: BackendCell,
88191 }
89192
90193 pub struct DecodeSession;
@@ -152,6 +255,7 @@ impl DecodeSession {
152255 cancel,
153256 handle: None,
154257 },
258+ backend: BackendCell::new(Backend::Gap),
155259 };
156260 }
157261 let worker_cancel = Arc::clone(&cancel);
@@ -180,6 +284,7 @@ impl DecodeSession {
180284 FrameStream {
181285 frames: rx,
182286 worker: Worker { cancel, handle },
287+ backend: BackendCell::new(Backend::Gap),
183288 }
184289 }
185290
@@ -209,6 +314,7 @@ impl DecodeSession {
209314 cancel,
210315 handle: None,
211316 },
317+ backend: BackendCell::new(Backend::Still),
212318 });
213319 }
214320 // The one conversion, on this thread: it is a few milliseconds and the
@@ -245,6 +351,7 @@ impl DecodeSession {
245351 Ok(FrameStream {
246352 frames: rx,
247353 worker: Worker { cancel, handle },
354+ backend: BackendCell::new(Backend::Still),
248355 })
249356 }
250357
@@ -285,6 +392,9 @@ impl DecodeSession {
285392 // decoder run ahead of the display without limit.
286393 let (tx, rx) = sync_channel(2);
287394 let cancel = Arc::new(AtomicBool::new(false));
395+ // Written by the worker below the moment it knows, so a caller reading
396+ // it sees what opened rather than what was hoped for.
397+ let backend = BackendCell::default();
288398 if end_frame <= start_frame {
289399 // Nothing to decode: dropping `tx` here closes the channel cleanly,
290400 // so the caller sees an immediate end of stream rather than an error.
@@ -296,10 +406,12 @@ impl DecodeSession {
296406 cancel,
297407 handle: None,
298408 },
409+ backend,
299410 },
300411 ));
301412 }
302413 let worker_cancel = Arc::clone(&cancel);
414+ let worker_backend = backend.clone();
303415 let handle = thread::Builder::new()
304416 .name("decode".into())
305417 .spawn(move || {
@@ -320,6 +432,7 @@ impl DecodeSession {
320432 return;
321433 }
322434 eprintln!("decode backend: hardware (VA-API plugin)");
435+ worker_backend.set(Backend::Hardware);
323436 if run_hw(hw, &tx, start_frame, end_frame, &mut render, &worker_cancel) {
324437 return;
325438 }
@@ -334,6 +447,7 @@ impl DecodeSession {
334447 return;
335448 }
336449 eprintln!("decode backend: software (rusty_h264)");
450+ worker_backend.set(Backend::Software);
337451 run(
338452 demuxer,
339453 tx,
@@ -351,6 +465,7 @@ impl DecodeSession {
351465 cancel,
352466 handle: Some(handle),
353467 },
468+ backend,
354469 },
355470 ))
356471 }
crates/engine/src/export.rsmodified+142 -20
@@ -146,6 +146,10 @@ struct Shared {
146146 cancel: AtomicBool,
147147 finished: AtomicBool,
148148 outcome: Mutex<Option<crate::Result<()>>>,
149+ /// The encoders this job really opened, published the moment they are
150+ /// chosen and never changed after -- one seat for the whole file, which is
151+ /// what [`Enc`] states. `None` until then.
152+ encoders: Mutex<Option<String>>,
149153 }
150154
151155 /// A running export. Poll [`is_finished`](ExportHandle::is_finished) once per
@@ -174,6 +178,13 @@ impl ExportHandle {
174178 self.shared.finished.load(Ordering::Acquire)
175179 }
176180
181+ /// What this export is encoding with -- the video seat and what the sound
182+ /// is doing -- as the worker chose them, hardware fallback included.
183+ /// `None` for the first instants of a job, before the encoder is open.
184+ pub fn encoders(&self) -> Option<String> {
185+ self.shared.encoders.lock().unwrap().clone()
186+ }
187+
177188 /// The outcome, once — taken out of the handle, so a caller that already
178189 /// reported it sees `None` afterwards. `None` while the export is running.
179190 pub fn result(&self) -> Option<crate::Result<()>> {
@@ -197,6 +208,7 @@ pub fn start(
197208 cancel: AtomicBool::new(false),
198209 finished: AtomicBool::new(false),
199210 outcome: Mutex::new(None),
211+ encoders: Mutex::new(None),
200212 });
201213 let worker = Arc::clone(&shared);
202214 let out = out.to_path_buf();
@@ -261,6 +273,103 @@ fn has_picture(project: &Project) -> bool {
261273 .any(|lane| lane.kind == LaneKind::Video && !project.lane(lane).is_empty())
262274 }
263275
276+/// Whether any audio lane holds anything, [`has_picture`]'s pair: what tells a
277+/// timeline whose export will carry sound from one whose file has none.
278+fn has_sound(project: &Project) -> bool {
279+ project
280+ .lanes()
281+ .into_iter()
282+ .any(|lane| lane.kind == LaneKind::Audio && !project.lane(lane).is_empty())
283+}
284+
285+/// Whether any equalizer on the sound is doing something -- the one edit a
286+/// packet copy cannot carry, so an mp4 whose lane has one is decoded and
287+/// re-encoded ([`encode_audio`]) instead of copied. Asked of every audio lane:
288+/// the copy path has exactly one by the time it asks, and [`planned_audio`] is
289+/// asked before that is settled.
290+fn equalized(project: &Project) -> bool {
291+ project.audio_lanes().into_iter().any(|lane| {
292+ (0..project.lane(lane).len())
293+ .any(|idx| project.eq_of(lane, idx).is_some_and(|eq| !eq.is_identity()))
294+ })
295+}
296+
297+/// The bitrate an export codes at: the caller's number through the same clamp
298+/// as the computed one, for the reason [`Enc::open`] states.
299+fn bitrate_of(meta: &VideoMeta, settings: &ExportSettings) -> u64 {
300+ settings
301+ .bitrate
302+ .map_or_else(|| bitrate_for(meta), |b| b.clamp(MIN_BITRATE, MAX_BITRATE))
303+}
304+
305+/// The hardware seat for these settings, opened exactly as the export opens it
306+/// -- the same pins, the same AV1 opt-in, the same dimensions a driver may
307+/// refuse -- or `None` where the software encoder takes the file. The single
308+/// place that choice is made, which is what lets [`planned_video`] *measure* it
309+/// instead of promising it.
310+fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option<HwEncoder> {
311+ if settings.force_sw || forced("VE_SW_ENC") {
312+ return None;
313+ }
314+ let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?;
315+ let bitrate = bitrate_of(meta, settings);
316+ match settings.format {
317+ // Opt-in only, for the reason [`Enc::open_av1`] states in full.
318+ Format::Av1 if !forced("VE_HW_AV1") => None,
319+ Format::Av1 => HwEncoder::open_av1(meta.width, meta.height, fps_num, fps_den, bitrate),
320+ _ => HwEncoder::open(meta.width, meta.height, fps_num, fps_den, bitrate),
321+ }
322+}
323+
324+/// How a front-end names a video seat: which of the two encoders has the file,
325+/// and which library that is. Not the codec -- a caller shows this beside the
326+/// format it picked, and `rav1e` names AV1 as `rusty_h264` names H.264. One
327+/// place, so what a card says before an export and what its progress line says
328+/// during one cannot drift apart.
329+fn video_label(format: Format, hw: bool) -> &'static str {
330+ match (format, hw) {
331+ (Format::Av1, true) => "HW encode (VA-API)",
332+ (Format::Av1, false) => "SW encode (rav1e)",
333+ (_, true) => "HW encode (VA-API)",
334+ (_, false) => "SW encode (rusty_h264)",
335+ }
336+}
337+
338+/// What the sound is written by. Every audio encoder here is software -- there
339+/// is no hardware AAC, PCM or FLAC seat -- so this names *which* one, and
340+/// whether an mp4 escapes encoding altogether by copying the packets it was
341+/// given. Empty for AV1, which carries no audio at all: a caller joins this to
342+/// a line that already says so, and repeating it would cost a line of card.
343+fn audio_label(project: &Project, format: Format, sound: bool) -> &'static str {
344+ match format {
345+ Format::Av1 => "",
346+ _ if !sound => "no sound to write",
347+ Format::Mp4 if equalized(project) => "AAC · SW encode (rusty_aac)",
348+ Format::Mp4 => "AAC copy",
349+ Format::Wav => "PCM · SW (hound)",
350+ Format::Flac => "FLAC · SW (flacenc)",
351+ }
352+}
353+
354+/// What [`start`] would write this timeline's sound with, before one is
355+/// started. Pure: no probe and no file opened, so a card may ask it per repaint.
356+pub fn planned_audio(project: &Project, format: Format) -> &'static str {
357+ audio_label(project, format, has_sound(project))
358+}
359+
360+/// What [`start`] would encode the picture with, probed the way the export
361+/// probes it -- the very encoder is opened and closed again -- so this is a
362+/// measurement and not a promise. `None` for a format that carries no picture.
363+///
364+/// Costs that open (~100 ms here): ask it off a render thread and keep the
365+/// answer until the format, the resolution or the bitrate changes.
366+pub fn planned_video(meta: &VideoMeta, settings: &ExportSettings) -> Option<&'static str> {
367+ settings
368+ .format
369+ .has_video()
370+ .then(|| video_label(settings.format, hw_seat(meta, settings).is_some()))
371+}
372+
264373 fn settle(shared: &Shared, result: crate::Result<()>) {
265374 *shared.outcome.lock().unwrap() = Some(result);
266375 // Published last: a caller that sees the flag is guaranteed the outcome.
@@ -367,9 +476,7 @@ fn copy_audio(
367476 // only this case is: a timeline nobody has equalized still leaves through
368477 // the copy below, packet for packet, so no passthrough quietly becomes a
369478 // generation of loss.
370- let equalized = (0..project.lane(lane).len())
371- .any(|idx| project.eq_of(lane, idx).is_some_and(|eq| !eq.is_identity()));
372- if equalized {
479+ if equalized(project) {
373480 return encode_audio(project, meta);
374481 }
375482 AudioSession::copy_multi_streams(&project.audio_sources(), segments)
@@ -495,6 +602,18 @@ fn run(
495602 .collect();
496603
497604 let mut encoder = Enc::open(meta, settings)?;
605+ // What this file is really being written by, for a progress line to name.
606+ // Published *after* the seat is open, so a hardware encoder the driver
607+ // refused reads as the software one that took over rather than as the hope
608+ // it replaced -- and the sound says whether it was copied or encoded, which
609+ // `copy_audio` decided a few lines up.
610+ *shared.encoders.lock().unwrap() = Some(
611+ match audio_label(project, settings.format, audio.is_some()) {
612+ // AV1: no sound in the file and none to name.
613+ "" => encoder.label().to_string(),
614+ sound => format!("{} · {sound}", encoder.label()),
615+ },
616+ );
498617 let mut muxer = None;
499618 let mut done = 0u32;
500619 let black = Black::new(meta);
@@ -734,6 +853,9 @@ fn run_audio(
734853 else {
735854 return Err("this timeline has no audio to export".into());
736855 };
856+ // The picture path's line, for a file that is sound alone: there is sound
857+ // by the line above, so this names the encoder writing it.
858+ *shared.encoders.lock().unwrap() = Some(audio_label(project, format, true).to_string());
737859 let channels = usize::from(audio.channels);
738860 let frames = (f64::from(project.timeline_frames()) / meta.frame_rate
739861 * f64::from(audio.sample_rate))
@@ -988,6 +1110,18 @@ enum Enc {
9881110 }
9891111
9901112 impl Enc {
1113+ /// Which seat this *is*, said the way [`video_label`] says it -- so the
1114+ /// name a running export shows is the name the card showed, or the honest
1115+ /// difference where the probe and the open disagreed.
1116+ fn label(&self) -> &'static str {
1117+ match self {
1118+ Self::Hw(_) => video_label(Format::Mp4, true),
1119+ Self::Sw { .. } => video_label(Format::Mp4, false),
1120+ Self::Av1Hw(_) => video_label(Format::Av1, true),
1121+ Self::Av1Sw { .. } => video_label(Format::Av1, false),
1122+ }
1123+ }
1124+
9911125 fn open(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result<Self> {
9921126 if settings.format == Format::Av1 {
9931127 return Self::open_av1(meta, settings);
@@ -995,18 +1129,13 @@ impl Enc {
9951129 // A caller's number goes through the same clamp as the computed one: a
9961130 // zero bitrate switches the software encoder's lookahead on, which would
9971131 // break the one-picture-per-call contract `encode` documents below.
998- let bitrate = settings
999- .bitrate
1000- .map_or_else(|| bitrate_for(meta), |b| b.clamp(MIN_BITRATE, MAX_BITRATE));
1132+ let bitrate = bitrate_of(meta, settings);
10011133 // The plugin wants an exact rational, and the muxer already picks one
10021134 // that is exact at every rate we can read -- `fps * 1000 / 1000` would
10031135 // hand 24000/1001 over as a rounded 23.976, which is the same
10041136 // truncation the container timing had.
1005- let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate)?;
1006- if !settings.force_sw
1007- && !forced("VE_SW_ENC")
1008- && let Some(hw) = HwEncoder::open(meta.width, meta.height, fps_num, fps_den, bitrate)
1009- {
1137+ crate::mux::frame_timing(meta.frame_rate)?;
1138+ if let Some(hw) = hw_seat(meta, settings) {
10101139 eprintln!("export encoder: hardware (VA-API plugin)");
10111140 return Ok(Self::Hw(hw));
10121141 }
@@ -1047,19 +1176,12 @@ impl Enc {
10471176 /// cros-codecs release that fixes it) plus a probe encode of one frame at
10481177 /// open, after which this can prefer hardware the way H.264 does.
10491178 fn open_av1(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result<Self> {
1050- let bitrate = settings
1051- .bitrate
1052- .map_or_else(|| bitrate_for(meta), |b| b.clamp(MIN_BITRATE, MAX_BITRATE));
1179+ let bitrate = bitrate_of(meta, settings);
10531180 let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate)?;
10541181 // Two seconds between keyframes, as the H.264 seat does: a seek may only
10551182 // land on one, and this is what a cluster of the Matroska file is.
10561183 let gop = (meta.frame_rate * 2.0).round().max(1.0) as u64;
1057- if forced("VE_HW_AV1")
1058- && !settings.force_sw
1059- && !forced("VE_SW_ENC")
1060- && let Some(hw) =
1061- HwEncoder::open_av1(meta.width, meta.height, fps_num, fps_den, bitrate)
1062- {
1184+ if let Some(hw) = hw_seat(meta, settings) {
10631185 eprintln!("export encoder: hardware AV1 (VA-API plugin)");
10641186 return Ok(Self::Av1Hw(hw));
10651187 }
crates/engine/src/playback.rsmodified+29 -1
@@ -22,7 +22,7 @@ use crate::ao::AoSession;
2222 use crate::audio::{AudioChunk, AudioSession};
2323 use crate::clock::{ClockSource, PlaybackClock};
2424 use crate::color::ColorParams;
25-use crate::decode::{DecodeSession, Frame, Worker};
25+use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
2626 use crate::demux::{Codec, Demuxer, VideoMeta};
2727 use crate::eq::EqParams;
2828 use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed};
@@ -161,6 +161,11 @@ pub struct PlaybackSession {
161161 frames: Receiver<Frame>,
162162 /// The current decode worker.
163163 worker: Worker,
164+ /// What that worker opened -- hardware, software, a still, a gap -- written
165+ /// by the worker itself and read by [`decode_backend`](Self::decode_backend).
166+ /// Replaced with the stream at every seek, so it always describes the
167+ /// pictures currently arriving and never the clip before them.
168+ backend: BackendCell,
164169 /// Workers cancelled by a seek or a clip change, waiting to be reaped.
165170 /// Joining one inline costs whatever VA-API init it is still inside (98 ms
166171 /// measured worst case), which is a visible hitch on the caller's thread;
@@ -274,6 +279,7 @@ impl PlaybackSession {
274279 native: (meta.width, meta.height),
275280 frames: stream.frames,
276281 worker: stream.worker,
282+ backend: stream.backend,
277283 retired: Vec::new(),
278284 clock: PlaybackClock::new(source),
279285 audio,
@@ -371,6 +377,7 @@ impl PlaybackSession {
371377 native: (width, height),
372378 frames: stream.frames,
373379 worker: stream.worker,
380+ backend: stream.backend,
374381 retired: Vec::new(),
375382 // The song keeps the clock, as a video's own sound does -- and wall
376383 // time keeps it on a machine with no device, where the picture
@@ -446,6 +453,7 @@ impl PlaybackSession {
446453 native: (meta.width, meta.height),
447454 frames: stream.frames,
448455 worker: stream.worker,
456+ backend: stream.backend,
449457 retired: Vec::new(),
450458 clock: PlaybackClock::new(ClockSource::Wall),
451459 audio: None,
@@ -681,6 +689,7 @@ impl PlaybackSession {
681689 native,
682690 frames: stream.frames,
683691 worker: stream.worker,
692+ backend: stream.backend,
684693 retired: Vec::new(),
685694 clock: PlaybackClock::new(match audio {
686695 Some(_) => ClockSource::Audio,
@@ -708,6 +717,24 @@ impl PlaybackSession {
708717 &self.meta
709718 }
710719
720+ /// What the pictures now arriving are being decoded by: the clip under the
721+ /// playhead, since one video worker feeds the composite at a time. An
722+ /// atomic load -- a front-end may ask it every repaint -- and it is what
723+ /// *opened*, so a clip whose hardware session fell back to software reads
724+ /// [`Backend::Software`] from the frame that fallback happened.
725+ pub fn decode_backend(&self) -> Backend {
726+ self.backend.get()
727+ }
728+
729+ /// What an export of this timeline would encode the *sound* with, before
730+ /// one is started: the copy an mp4 normally makes, or the software encoder
731+ /// the format (or an equalized lane) forces. Pure -- no probe, no file
732+ /// opened -- so a card may ask it per repaint; the picture's half costs a
733+ /// plugin open and lives in [`crate::export::planned_video`].
734+ pub fn planned_audio(&self, format: crate::export::Format) -> &'static str {
735+ crate::export::planned_audio(&self.project, format)
736+ }
737+
711738 /// Why this session plays silent although the file has sound -- an audio
712739 /// track in a codec we cannot decode, or one the decoder refused. `None`
713740 /// when there is audio, and for a file that never had any. A front-end
@@ -932,6 +959,7 @@ impl PlaybackSession {
932959 // then can it return and be reaped by a later sweep. Nothing here
933960 // joins, so this ordering costs the seek nothing.
934961 self.frames = stream.frames;
962+ self.backend = stream.backend;
935963 self.retire(stream.worker);
936964 }
937965 self.span = span;
crates/engine/tests/backends.rsadded+187 -0
@@ -0,0 +1,187 @@
1+//! Which decoder and which encoder a job really runs on -- the introspection a
2+//! front-end shows before an operation and while it runs.
3+//!
4+//! The point of every assertion here is *truthfulness*, not a particular seat:
5+//! this box may or may not have a working plugin, and a test that demanded
6+//! hardware would only be measuring the machine. What must hold is that the
7+//! answer given before an operation is the answer the operation then gives, and
8+//! that neither of them ever names a decoder that could not have run (software
9+//! HEVC, for one, does not exist here).
10+
11+use std::path::PathBuf;
12+use std::time::{Duration, Instant};
13+
14+use engine::Codec;
15+use engine::decode::{Backend, probe};
16+use engine::export::{ExportSettings, Format};
17+use engine::{ExportHandle, PlaybackSession};
18+
19+fn asset(name: &str) -> PathBuf {
20+ PathBuf::from(env!("CARGO_MANIFEST_DIR"))
21+ .join("../../assets")
22+ .join(name)
23+}
24+
25+fn out_path(name: &str, ext: &str) -> PathBuf {
26+ let path = std::env::temp_dir().join(format!("ve_backend_{name}_{}.{ext}", std::process::id()));
27+ let _ = std::fs::remove_file(&path);
28+ let _ = std::fs::remove_file(format!("{}.part", path.display()));
29+ path
30+}
31+
32+/// A still has no coded stream and no decoder to pick, and it must say so
33+/// rather than borrowing the picture path's answer.
34+#[test]
35+fn a_still_probes_as_a_still() {
36+ let (codec, backend) = probe(&asset("test_still.png")).expect("probe the still");
37+ assert_eq!(codec, None, "an image has no coded stream to name");
38+ assert_eq!(backend, Backend::Still);
39+}
40+
41+/// H.264 has both seats, so the probe may legitimately answer either -- but it
42+/// must answer one of them, and it must name the codec.
43+#[test]
44+fn an_h264_source_probes_as_one_of_the_two_seats() {
45+ let (codec, backend) = probe(&asset("test_baseline.mp4")).expect("probe the baseline fixture");
46+ assert_eq!(codec, Some(Codec::H264));
47+ assert!(
48+ matches!(backend, Backend::Hardware | Backend::Software),
49+ "a probe that returned must have picked a seat, got {backend:?}"
50+ );
51+}
52+
53+/// HEVC has no software decoder here at all. A box with the plugin answers
54+/// hardware; a box without it is refused by name -- and *never* told that
55+/// `rusty_h264` will take it, which is the one answer that would be a lie.
56+#[test]
57+fn hevc_probes_as_hardware_or_as_a_refusal() {
58+ match probe(&asset("test_hevc.mkv")) {
59+ Ok((codec, backend)) => {
60+ assert_eq!(codec, Some(Codec::Hevc));
61+ assert_eq!(backend, Backend::Hardware, "there is no software HEVC here");
62+ }
63+ Err(e) => assert!(
64+ e.to_string().contains("plugin"),
65+ "a refusal names the plugin, got {e}"
66+ ),
67+ }
68+}
69+
70+/// The running session reports the decoder its *worker* opened, and it agrees
71+/// with what the probe said before anything played. This is the whole point of
72+/// the cell: the worker writes it where the fallback happens, so a hardware
73+/// session that dropped to software could only be seen here.
74+#[test]
75+fn a_playing_session_reports_the_seat_the_probe_named() {
76+ let path = asset("test_baseline.mp4");
77+ let (_codec, probed) = probe(&path).expect("probe the baseline fixture");
78+ let session = PlaybackSession::open(&path).expect("open the fixture");
79+ let started = Instant::now();
80+ loop {
81+ let live = session.decode_backend();
82+ if live != Backend::Opening {
83+ assert_eq!(live, probed, "the running seat is not the probed one");
84+ break;
85+ }
86+ assert!(
87+ started.elapsed() < Duration::from_secs(20),
88+ "the worker never published a decode backend"
89+ );
90+ std::thread::sleep(Duration::from_millis(10));
91+ }
92+}
93+
94+/// What the export card says before the button and what the progress line says
95+/// during the job are the same two answers, from the same two functions: the
96+/// picture's seat is probed by opening the very encoder the export opens, and
97+/// the sound's is decided outright. A drift between them is a front-end lying
98+/// about the machine, which is exactly what this whole surface is for.
99+#[test]
100+fn the_planned_encoders_are_the_ones_the_job_opens() {
101+ let settings = ExportSettings {
102+ format: Format::Mp4,
103+ ..ExportSettings::default()
104+ };
105+ let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
106+ let planned = format!(
107+ "{} · {}",
108+ engine::export::planned_video(session.meta(), &settings).expect("an mp4 carries picture"),
109+ session.planned_audio(Format::Mp4)
110+ );
111+ let out = out_path("planned", "mp4");
112+ let handle = session.export_to_with(&out, &settings);
113+ let started = Instant::now();
114+ let opened = loop {
115+ if let Some(line) = handle.encoders() {
116+ break line;
117+ }
118+ assert!(
119+ !handle.is_finished(),
120+ "the export settled before it opened an encoder: {:?}",
121+ handle.result().map(|r| r.err())
122+ );
123+ assert!(
124+ started.elapsed() < Duration::from_secs(60),
125+ "no encoder was published"
126+ );
127+ std::thread::sleep(Duration::from_millis(10));
128+ };
129+ // Nothing here wants the file, only the seat it was going to be written
130+ // with: cancelling deletes the `.part` the worker had started.
131+ handle.cancel();
132+ wind_down(&handle);
133+ assert_eq!(opened, planned);
134+}
135+
136+/// A WAV job has no picture at all and still names what writes it, so an audio
137+/// export is not a progress line with nothing to say.
138+#[test]
139+fn an_audio_only_job_names_its_encoder() {
140+ let settings = ExportSettings {
141+ format: Format::Wav,
142+ ..ExportSettings::default()
143+ };
144+ assert_eq!(
145+ engine::export::planned_video(
146+ &engine::demux::Demuxer::open(&asset("test_av.mp4"))
147+ .expect("open the fixture")
148+ .0,
149+ &settings
150+ ),
151+ None,
152+ "a WAV has no video seat to name"
153+ );
154+ let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
155+ let planned = session.planned_audio(Format::Wav);
156+ let out = out_path("wav", "wav");
157+ let handle = session.export_to_with(&out, &settings);
158+ let started = Instant::now();
159+ let opened = loop {
160+ if let Some(line) = handle.encoders() {
161+ break line;
162+ }
163+ assert!(
164+ started.elapsed() < Duration::from_secs(60),
165+ "no encoder was published"
166+ );
167+ std::thread::sleep(Duration::from_millis(10));
168+ };
169+ handle.cancel();
170+ wind_down(&handle);
171+ let _ = std::fs::remove_file(&out);
172+ assert_eq!(opened, planned);
173+}
174+
175+/// Waits for a cancelled job to settle, so its `.part` is gone before the test
176+/// ends -- and so no worker outlives the process holding a VA-API session.
177+fn wind_down(handle: &ExportHandle) {
178+ let started = Instant::now();
179+ while !handle.is_finished() {
180+ assert!(
181+ started.elapsed() < Duration::from_secs(60),
182+ "a cancelled export did not settle"
183+ );
184+ std::thread::sleep(Duration::from_millis(10));
185+ }
186+ let _ = handle.result();
187+}