Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions backend/src/api/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,10 @@ pub async fn get_flow_pad_caps(
/// Trigger a scene transition on a compositor block.
///
/// Animates the transition between two inputs on a compositor/mixer block.
///
/// A vision mixer takes between its own authoritative PGM/PVW bus state and
/// ignores `from_input`/`to_input`. A block with no live state requires them.
///
/// Supported transition types:
/// - `cut`: Instant switch (no animation)
/// - `fade`: Cross-fade via alpha blending
Expand Down Expand Up @@ -1850,21 +1854,12 @@ pub async fn trigger_transition(
}));
}

let (Some(from_input), Some(to_input)) = (req.from_input, req.to_input) else {
return Err((
StatusCode::BAD_REQUEST,
Json(ErrorResponse::with_details(
"Failed to trigger transition",
"from_input and to_input are required (only a stinger may leave them out)",
)),
));
};
let actual_transition_type = state
let (actual_transition_type, old_pgm, new_pgm) = state
.trigger_transition(
&flow_id,
&block_id,
from_input,
to_input,
req.from_input,
req.to_input,
&req.transition_type,
req.duration_ms,
)
Expand All @@ -1880,11 +1875,18 @@ pub async fn trigger_transition(
)
})?;

Ok(Json(TransitionResponse {
message: format!(
// Report the sources the take actually ran between, not the request —
// on a vision mixer those differ. Neither is named when a bus is a PiP.
let message = match (old_pgm, new_pgm) {
(Some(from), Some(to)) => format!(
"Transition {} started: input {} -> {}",
req.transition_type, from_input, to_input
req.transition_type, from, to
),
_ => format!("Transition {} started", req.transition_type),
};

Ok(Json(TransitionResponse {
message,
transition_type: req.transition_type,
actual_transition_type,
duration_ms: req.duration_ms,
Expand Down
42 changes: 35 additions & 7 deletions backend/src/gst/pipeline/effects/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl PipelineManager {
/// dist + multiview compositors; otherwise runs a standard single-pad
/// transition on the mv mixer.
///
/// `from_input`/`to_input` are only consulted for a block that registered
/// no overlay state (a plain compositor). They are required in that case
/// and ignored otherwise.
///
/// Returns `(was_ftb_cancelled, old_pgm, new_pgm, actual_kind)`. The two
/// middle elements are `None` when the corresponding bus is a PiP source.
/// `actual_kind` is the transition that actually ran — differs from
Expand All @@ -59,15 +63,15 @@ impl PipelineManager {
pub fn trigger_transition(
&self,
block_instance_id: &str,
from_input: usize,
to_input: usize,
from_input: Option<usize>,
to_input: Option<usize>,
transition_type: &str,
duration_ms: u64,
) -> Result<(bool, Option<usize>, Option<usize>, String), PipelineError> {
use crate::gst::transitions::{TransitionController, TransitionType};

debug!(
"Triggering {} transition on {} from input {} to {} ({}ms)",
"Triggering {} transition on {} from input {:?} to {:?} ({}ms)",
transition_type, block_instance_id, from_input, to_input, duration_ms
);

Expand Down Expand Up @@ -98,18 +102,42 @@ impl PipelineManager {
.as_ref()
.map(|s| s.num_inputs)
.unwrap_or(usize::MAX);

// Without overlay state the request indices are the only thing naming
// the pads to animate, so an omitted one leaves the take
// underspecified rather than merely redundant.
if overlay_state.is_none() && (from_input.is_none() || to_input.is_none()) {
return Err(PipelineError::InvalidProperty {
element: block_instance_id.to_string(),
property: "from_input/to_input".to_string(),
reason: "block has no live PGM/PVW state: both indices are required".to_string(),
});
}

// When overlay state is missing entirely, fall back to the request-
// provided indices. When state exists but reports None (PiP on bus),
// pass None through so the PiP-aware branch below handles it.
let old_pgm: Option<usize> = match overlay_state.as_ref() {
Some(s) => s.pgm_input(),
None => Some(from_input),
None => from_input,
};
let new_pgm: Option<usize> = match overlay_state.as_ref() {
Some(s) => s.pvw_input(),
None => Some(to_input),
None => to_input,
};

// The vision mixer page sends indices on every take, so a disagreement
// is routine rather than a fault — debug, not warn.
if overlay_state.is_some()
&& (from_input.is_some_and(|i| Some(i) != old_pgm)
|| to_input.is_some_and(|i| Some(i) != new_pgm))
{
debug!(
"Discarding client indices {:?} -> {:?} on {}: bus state says {:?} -> {:?}",
from_input, to_input, block_instance_id, old_pgm, new_pgm
);
}

// Auto-cancel FTB if active. Zone-border underlays need no special
// handling here: they are regular pads driven by the take paths
// below exactly like their content pads.
Expand Down Expand Up @@ -451,8 +479,8 @@ impl PipelineManager {

// Single-input transition only. Multi-source compositions are now
// expressed as PiPs which are handled by the PiP-aware branch above.
let from = old_pgm.unwrap_or(from_input);
let to = new_pgm.unwrap_or(to_input);
let from = old_pgm.or(from_input).unwrap_or(0);
let to = new_pgm.or(to_input).unwrap_or(0);
let controller = TransitionController::new(mixer.clone(), canvas_width, canvas_height);

// Shader transitions need the FX engine — downgrade to Fade when it
Expand Down
30 changes: 20 additions & 10 deletions backend/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2416,17 +2416,25 @@ impl AppState {
}

/// Trigger a transition on a compositor/mixer block.
///
/// `from_input`/`to_input` are honoured only for a block with no live
/// PGM/PVW state; see [`TriggerTransitionRequest`].
///
/// Returns `(actual_kind, old_pgm, new_pgm)` — the latter two are the
/// sources the take actually ran between, `None` when that bus is a PiP.
///
/// [`TriggerTransitionRequest`]: strom_types::api::TriggerTransitionRequest
pub async fn trigger_transition(
&self,
flow_id: &FlowId,
block_instance_id: &str,
from_input: usize,
to_input: usize,
from_input: Option<usize>,
to_input: Option<usize>,
transition_type: &str,
duration_ms: u64,
) -> Result<String, PipelineError> {
) -> Result<(String, Option<usize>, Option<usize>), PipelineError> {
debug!(
"Triggering {} transition on block {} in flow {} ({} -> {}, {}ms)",
"Triggering {} transition on block {} in flow {} ({:?} -> {:?}, {}ms)",
transition_type, block_instance_id, flow_id, from_input, to_input, duration_ms
);

Expand Down Expand Up @@ -2469,7 +2477,7 @@ impl AppState {
)
.await;

Ok(actual_kind)
Ok((actual_kind, old_pgm, new_pgm))
}

/// What every take does once the mixer has been told: persist which
Expand All @@ -2479,8 +2487,8 @@ impl AppState {
&self,
flow_id: &FlowId,
block_instance_id: &str,
from_input: usize,
to_input: usize,
from_input: Option<usize>,
to_input: Option<usize>,
transition_type: &str,
duration_ms: u64,
ftb_cancelled: bool,
Expand Down Expand Up @@ -2578,14 +2586,16 @@ impl AppState {
}
}

// Broadcast transition event
// Report the sources the take actually ran between, falling back to
// the request. The variant's fields are `usize`, so a PiP bus still
// has to report something: 0 stands in.
self.inner
.events
.broadcast(StromEvent::TransitionTriggered {
flow_id: *flow_id,
block_instance_id: block_instance_id.to_string(),
from_input,
to_input,
from_input: old_pgm.or(from_input).unwrap_or(0),
to_input: new_pgm.or(to_input).unwrap_or(0),
transition_type: transition_type.to_string(),
duration_ms,
});
Expand Down
6 changes: 3 additions & 3 deletions backend/src/state/stinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl AppState {
// change: the program still cuts, once the claim is gone.
let (reason, program_changed) = if cut_instead {
let cut = self
.trigger_transition(flow_id, block, from, to, "cut", 0)
.trigger_transition(flow_id, block, Some(from), Some(to), "cut", 0)
.await;
(format!("{reason}, cut instead"), cut.is_ok())
} else {
Expand Down Expand Up @@ -1066,8 +1066,8 @@ impl AppState {
self.after_vision_mixer_take(
flow_id,
block,
from,
to,
Some(from),
Some(to),
"stinger",
plan.duration_ms,
ftb_cancelled,
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/it/stinger_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ async fn a_take_is_followed_by_its_id() {
assert_eq!(started, Some(id));
assert_eq!(completed, Some(id));

// Any other transition still needs its inputs.
// A vision mixer takes PGM to PVW, so any other take needs no indices.
let (status, _) = call(
&app,
"POST",
&format!("{blocks}/transition"),
Some(json!({"transition_type": "cut"})),
)
.await;
assert_eq!(status, StatusCode::BAD_REQUEST);
assert_eq!(status, StatusCode::OK);

r.state.stop_flow(&r.flow_id).await.unwrap();
}
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/it/vision_mixer_fx_passthrough_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn idle_fx_slots_pass_buffers_through_and_effects_still_apply() {
// --- TAKE: a shader wipe from red (0) to white (1) must animate. ---
h.reset_counters();
h.manager
.trigger_transition(h.block_id, 0, 1, "wipe_left", 1500)
.trigger_transition(h.block_id, Some(0), Some(1), "wipe_left", 1500)
.expect("wipe take");
h.manager
.update_vision_mixer_after_take(h.block_id, Some(1), Some(0), 2)
Expand Down Expand Up @@ -428,7 +428,7 @@ fn idle_fx_slots_pass_buffers_through_and_effects_still_apply() {

// The next take resets the TAKE slots to neutral: all idle again.
h.manager
.trigger_transition(h.block_id, 1, 0, "cut", 0)
.trigger_transition(h.block_id, Some(1), Some(0), "cut", 0)
.expect("cut back");
h.manager
.update_vision_mixer_after_take(h.block_id, Some(0), Some(1), 2)
Expand All @@ -443,7 +443,7 @@ fn idle_fx_slots_pass_buffers_through_and_effects_still_apply() {
// --- Master-FX take: the envelope renders on fx_pgm_take. ---
h.reset_counters();
h.manager
.trigger_transition(h.block_id, 0, 1, "glitch_cut", 600)
.trigger_transition(h.block_id, Some(0), Some(1), "glitch_cut", 600)
.expect("glitch take");
h.manager
.update_vision_mixer_after_take(h.block_id, Some(1), Some(0), 2)
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/it/vision_mixer_fx_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ async fn vision_mixer_fx_engine_end_to_end() {

// Shader wipe take and master-FX take must run without error.
manager
.trigger_transition(BLOCK_ID, 0, 1, "wipe_left", 200)
.trigger_transition(BLOCK_ID, None, None, "wipe_left", 200)
.expect("wipe take failed");
tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;

manager
.trigger_transition(BLOCK_ID, 1, 0, "glitch_cut", 200)
.trigger_transition(BLOCK_ID, None, None, "glitch_cut", 200)
.expect("glitch take failed");
tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;

Expand Down Expand Up @@ -456,7 +456,7 @@ async fn wipe_between_letterboxed_sources_animates() {

// --- classic orientation: 2.40:1 -> 2.34:1 (outgoing does not cover) ---
manager
.trigger_transition(LETTERBOX_BLOCK_ID, 0, 1, "wipe_left", 2000)
.trigger_transition(LETTERBOX_BLOCK_ID, None, None, "wipe_left", 2000)
.expect("wipe 0->1");
// Mirror the API handler: persist the PGM/PVW swap after the take —
// trigger_transition reads the authoritative bus state from overlay
Expand All @@ -482,7 +482,7 @@ async fn wipe_between_letterboxed_sources_animates() {

// --- inverted orientation: 2.34:1 -> 2.40:1 (outgoing covers) ---
manager
.trigger_transition(LETTERBOX_BLOCK_ID, 1, 0, "wipe_left", 2000)
.trigger_transition(LETTERBOX_BLOCK_ID, None, None, "wipe_left", 2000)
.expect("wipe 1->0");
manager
.update_vision_mixer_after_take(LETTERBOX_BLOCK_ID, Some(0), Some(1), 2)
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/it/vision_mixer_overlay_upload_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Running {
fn cut_frames(&self) -> u32 {
let (_, old_pgm, new_pgm, _) = self
.manager
.trigger_transition(self.block_id, 0, 1, "cut", 0)
.trigger_transition(self.block_id, Some(0), Some(1), "cut", 0)
.expect("cut");
self.manager
.update_vision_mixer_after_take(self.block_id, new_pgm, old_pgm, self.num_inputs)
Expand Down Expand Up @@ -580,7 +580,7 @@ async fn tally_follows_a_cut_on_the_same_frame_with_late_inputs() {
// two frames, for slow CI).
let (_, old_pgm, new_pgm, _) = running
.manager
.trigger_transition(running.block_id, 0, 1, "cut", 0)
.trigger_transition(running.block_id, Some(0), Some(1), "cut", 0)
.expect("cut");
running
.manager
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/it/vision_mixer_underlay_upload_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn run(block_id: &str, backend: &str, mixer_frame_delay: Option<Duration>) {
// frame and the configuration gave it the zone's color.
std::thread::sleep(Duration::from_millis(1000));
manager
.trigger_transition(block_id, 0, 0, "cut", 0)
.trigger_transition(block_id, Some(0), Some(0), "cut", 0)
.expect("take the PiP");
// The first PGM frame showing the PiP (blue background) already shows
// the border. Had the border's frame only been pushed on the cut, it
Expand Down Expand Up @@ -582,11 +582,11 @@ fn run(block_id: &str, backend: &str, mixer_frame_delay: Option<Duration>) {
// Take away from the PiP (the border goes) and fade back to it (the
// border returns in its new colour).
manager
.trigger_transition(block_id, 0, 0, "cut", 0)
.trigger_transition(block_id, Some(0), Some(0), "cut", 0)
.expect("take the input");
wait_for_border(&appsink, "the zone border gone", is_black);
manager
.trigger_transition(block_id, 0, 0, "fade", 300)
.trigger_transition(block_id, Some(0), Some(0), "fade", 300)
.expect("take the PiP back");
let frames_until_back = wait_for_border(&appsink, "the green zone border back", is_green);
eprintln!("{backend}: border back after a 300 ms fade: {frames_until_back} PGM frame(s)");
Expand Down
Loading