Pool input captures across waiting layer previews
Beffroi/beffroi-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-14 18:54:47 +01:00
parent 841ade21e6
commit f4f1e44742
4 changed files with 131 additions and 34 deletions

View File

@ -327,42 +327,50 @@ impl Editor {
self.capture.pending = None;
let automatic = self.capture.refresh.pending_input.take();
let direct = self.capture.pending_layer.take();
let input = direct
.as_ref()
.map(|target| target.2)
.or(automatic)
.unwrap_or(self.capture.input);
// Pool by device/input, including targets selected while this request ran.
// Consume their one-shot requests on failure too: one failed fetch must
// not turn into one retry per waiting layer.
for (id, preview) in &mut self.capture.layers {
if preview.enabled
&& preview.input == input
&& preview.host == self.device.host
&& (0..self.layout.layers().len()).any(|i| {
self.layout.layer_info(i).id == *id
&& self.layout.formats().source_for[i] == preview.source
})
{
let requested = preview.capture_on_selection
|| preview.automatic
|| direct.as_ref().is_some_and(|(target, source, _, host)| {
*target == *id && *source == preview.source && *host == preview.host
});
preview.capture_on_selection = false;
if requested
&& !self.capture.discard_result
&& let Ok(reference) = &result
{
preview.texture = Some(reference.texture.clone());
preview.name = reference.name.clone();
}
}
}
let dialog_requested = self.capture.open
&& self.capture.input == input
&& self.capture.capture_on_selection;
if dialog_requested {
self.capture.capture_on_selection = false;
}
if self.capture.discard_result {
self.capture.discard_result = false;
} else {
match result {
Ok(reference) => {
if let Some((id, source, input, host)) = direct {
if let Some(preview) = self.capture.layers.get_mut(&id)
&& preview.enabled
&& preview.source == source
&& preview.input == input
&& preview.host == host
&& (0..self.layout.layers().len()).any(|i| {
self.layout.layer_info(i).id == id
&& self.layout.formats().source_for[i] == source
})
{
preview.texture = Some(reference.texture);
preview.name = reference.name;
}
} else if let Some(input) = automatic {
for (id, preview) in &mut self.capture.layers {
if preview.enabled
&& preview.automatic
&& preview.input == input
&& preview.host == self.device.host
&& (0..self.layout.layers().len()).any(|i| {
self.layout.layer_info(i).id == *id
&& self.layout.formats().source_for[i]
== preview.source
})
{
preview.texture = Some(reference.texture.clone());
preview.name = reference.name.clone();
}
}
} else {
if dialog_requested || (direct.is_none() && automatic.is_none()) {
self.capture.preview = Some(reference);
}
}
@ -689,6 +697,84 @@ mod tests {
assert!(!app.capture.capture_on_selection);
}
#[test]
fn captures_pool_waiters_by_input_for_direct_automatic_and_dialog_requests() {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.device.snapshot = Some(midra_layout::device::Snapshot {
identity: "Test".into(),
screens: vec![],
raw: serde_json::json!({"device":{"inputList":{"items":{
"INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}}
}}}}),
});
app.capture.host = app.device.host.clone();
let id = app.layout.layer_info(0).id;
let source = app.layout.formats().source_for[0];
for i in 0..2 {
app.capture.layers.insert(
app.layout.layer_info(i).id,
LayerPreview {
input: 3,
host: app.device.host.clone(),
source: app.layout.formats().source_for[i],
texture: None,
automatic: false,
capture_on_selection: true,
name: String::new(),
enabled: true,
guides: 0.35,
},
);
}
for mode in 0..4 {
for preview in app.capture.layers.values_mut() {
preview.capture_on_selection = true;
preview.texture = None;
}
app.capture.last_request = Some(std::time::Instant::now());
let (tx, rx) = std::sync::mpsc::channel();
app.capture.pending = Some(rx);
app.capture.pending_layer =
(mode == 0 || mode == 3).then(|| (id, source, 3, app.device.host.clone()));
app.capture.refresh.pending_input = (mode == 1).then_some(3);
app.capture.input = 3;
if mode == 3 {
tx.send(Err("Test failure".into())).unwrap();
} else {
tx.send(Ok(tiny_reference(&ctx, "shared capture"))).unwrap();
}
app.capture_window(&ctx);
assert!(app.capture.pending.is_none());
assert!(app.capture.layers.values().all(|p| !p.capture_on_selection));
if mode == 3 {
assert!(app.layer_preview(0).is_none());
assert!(app.layer_preview(1).is_none());
assert_eq!(app.capture.error, "Test failure");
} else {
assert_eq!(
app.layer_preview(0).unwrap().0,
app.layer_preview(1).unwrap().0
);
}
app.capture.last_request = None;
assert_eq!(app.next_selection_capture(), None); // no duplicate queued GET
}
// A waiter choosing another input during the fetch must keep its own request.
let second = app.layout.layer_info(1).id;
let p = app.capture.layers.get_mut(&second).unwrap();
p.input = 7;
p.capture_on_selection = true;
app.device.snapshot.as_mut().unwrap().raw["device"]["inputList"]["items"]["INPUT_7"] = serde_json::json!({"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}});
app.capture.last_request = Some(std::time::Instant::now());
let (tx, rx) = std::sync::mpsc::channel();
app.capture.pending = Some(rx);
app.capture.pending_layer = Some((id, source, 3, app.device.host.clone()));
tx.send(Ok(tiny_reference(&ctx, "input three"))).unwrap();
app.capture_window(&ctx);
assert!(app.layer_preview(1).is_none());
assert!(app.capture.layers[&second].capture_on_selection);
}
#[test]
fn automatic_capture_updates_only_opted_in_layers_even_when_inputs_match() {
let ctx = egui::Context::default();
let mut app = Editor::default();

View File

@ -105,8 +105,15 @@ of 5–300 seconds (default 10). Assignments also retain the device address and
physical input number in memory. Visible layers with enabled automatic previews, unchanged
local inputs and the current device address are eligible; unavailable or
snapshot-disabled inputs are skipped. Unique inputs refresh round-robin, one
request per interval, sharing the returned texture only across matching automatic
assignments. Manual stills are never replaced by another layer's automatic refresh.
request per interval. Every completed capture (manual, selection or timer) shares
one decoded texture across matching automatic previews and layers queued for a
first still on the same device/input, including targets queued while the request
was running. Matching one-shot requests are consumed together on success or failure,
so a failed fetch does not retry once per layer. A queued snapshot-import preview
can share the result too, but still requires explicit import. Changed, removed or
disabled targets reject the result; other inputs keep their own requests.
Existing manual stills without a queued capture are never replaced by another
layer's capture.
Selecting an input queues a one-shot capture in either picker, including the first
signal-bearing input selected when opening snapshot import. Selection captures
use the shared five-second minimum rather than waiting the configured refresh

View File

@ -1023,7 +1023,9 @@ For a layer, open **Layer properties → Preview** (or right-click → **Input p
Auto-refresh is per layer. **Request interval** is shared across automatic
previews, defaults to 10 seconds and accepts 5–300 seconds. Visible automatic
previews refresh one input at a time; automatic previews sharing an input share
one fetched image. Layers with auto-refresh off keep their manual stills.
one fetched image. First captures queued for that same input also share the
result, even when selected while a request is running. One fetch serves all
waiting layers; existing stills with auto-refresh off remain unchanged.
Requests are serialized with a minimum five-second gap, including manual captures.
A failed refresh retains the last image; changing the input clears the previous
input's image. Disabling the preview hides it and pauses its refreshes.

View File

@ -4,6 +4,8 @@
## Unreleased
- Pool input captures across matching queued layers and automatic previews, including requests queued during a fetch. Share one decoded texture and consume matching requests on failure to avoid per-layer retries; preserve existing manual stills. Regression tests cover direct, automatic and import captures, failure handling and different-input isolation.
- Capture a first still automatically when selecting a preview input, in both pickers. Queue the latest choice behind the shared five-second throttle and active request, without waiting the auto-refresh cycle; retain explicit recapture/import. Regression tests cover throttling, coalescing and cancelling stale targets.
- Hide no-signal inputs by default in both preview pickers; add a shared session-only Show inputs without signal toggle and explicit No signal labels. Preserve existing choices when filtering or signal loss occurs, and leave initial selection empty when no input has signal. UI tests cover both pickers and the empty state.