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
75 changes: 75 additions & 0 deletions backend/src/blocks/builtin/html_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,81 @@ fn html_input_definition() -> BlockDefinition {
persist: None,
visible_when: None,
},
ExposedProperty {
name: strom_types::stinger::STINGER_MODE_PROPERTY.to_string(),
label: "Stinger Page".to_string(),
description: "Play this page as a Vision Mixer stinger: wire video_out to the mixer's stinger \
input, and a take triggers the page by setting its URL fragment to \
#strom-take-<n> (listen for hashchange), so its URL cannot \
have a fragment of its own. The page must be transparent and \
stop drawing at rest, and change something visible on the first \
frame of its animation; the cut is timed from that frame. Plays as \
a classic stinger with premultiplied alpha."
.to_string(),
property_type: PropertyType::Bool,
default_value: Some(PropertyValue::Bool(false)),
mapping: PropertyMapping {
element_id: "_block".to_string(),
property_name: strom_types::stinger::STINGER_MODE_PROPERTY.to_string(),
transform: None,
},
live: false,
persist: None,
visible_when: None,
},
ExposedProperty {
name: strom_types::stinger::WEB_STINGER_DURATION_PROPERTY.to_string(),
label: "Stinger Duration (ms)".to_string(),
description: "How long the stinger page covers the program after a take. Required for a \
stinger page."
.to_string(),
property_type: PropertyType::UInt,
default_value: Some(PropertyValue::UInt(0)),
mapping: PropertyMapping {
element_id: "_block".to_string(),
property_name: strom_types::stinger::WEB_STINGER_DURATION_PROPERTY.to_string(),
transform: None,
},
live: false,
persist: None,
visible_when: None,
},
ExposedProperty {
name: strom_types::stinger::WEB_STINGER_CUT_POINT_PROPERTY.to_string(),
label: "Stinger Cut Point (ms)".to_string(),
description: "How far into the page's animation the program changes beneath it, while the \
page covers the frame. 0 takes the middle of the duration. Must be \
at least about 170 ms (the take finds the page's first frame \
first) and before the end."
.to_string(),
property_type: PropertyType::UInt,
default_value: Some(PropertyValue::UInt(0)),
mapping: PropertyMapping {
element_id: "_block".to_string(),
property_name: strom_types::stinger::WEB_STINGER_CUT_POINT_PROPERTY.to_string(),
transform: None,
},
live: false,
persist: None,
visible_when: None,
},
ExposedProperty {
name: strom_types::stinger::WEB_STINGER_MIX_PROPERTY.to_string(),
label: "Stinger Mix (ms)".to_string(),
description: "How long the program mixes from the old source to the new one at the cut \
point. 0 cuts."
.to_string(),
property_type: PropertyType::UInt,
default_value: Some(PropertyValue::UInt(0)),
mapping: PropertyMapping {
element_id: "_block".to_string(),
property_name: strom_types::stinger::WEB_STINGER_MIX_PROPERTY.to_string(),
transform: None,
},
live: false,
persist: None,
visible_when: None,
},
],
external_pads: ExternalPads {
inputs: vec![],
Expand Down
189 changes: 143 additions & 46 deletions backend/src/gst/pipeline/effects/stinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub struct StingerTake {
/// Spacing of the clip's frames, so the take knows which one is due at
/// the cut point.
pub clip_frame_ns: u64,
/// The graphic pad was raised ahead of the take
/// ([`PipelineManager::raise_stinger_fill`]), because the take's start
/// is only known once its source has started. It stays up until `end`.
pub fill_raised: bool,
}

/// Flows whose stinger programming fails once all its pad changes are made.
Expand Down Expand Up @@ -88,6 +92,27 @@ pub struct StingerProgramError {
pub ftb_cancelled: bool,
}

impl StingerProgramError {
/// A failure before the take changed anything.
fn unchanged(error: PipelineError) -> Self {
Self {
error,
ftb_cancelled: false,
}
}
}

/// The mixer, pads and state one take programs.
struct StingerTarget<'a> {
mixer: &'a gst::Element,
pads: StingerPads,
/// The outgoing source's pad.
a: gst::Pad,
/// The incoming source's pad.
b: gst::Pad,
state: Arc<overlay::VisionMixerOverlayState>,
}

/// The stinger pads of one mixer.
pub struct StingerPads {
pub fill: gst::Pad,
Expand Down Expand Up @@ -287,40 +312,29 @@ impl PipelineManager {
.map(|t| t.nseconds())
}

/// Program a whole stinger take, and start counting the clip's frames.
/// Also returns whether it cancelled a fade-to-black, as any take does.
///
/// A failure once it has started changing pads aborts the take (the old
/// source alone on air, the stinger pads down) before it returns; the
/// error then says whether a fade-to-black was cancelled on the way.
pub fn program_stinger(
/// What a take changes on the mixer, checked before it changes any of it.
fn stinger_target(
&self,
block_instance_id: &str,
take: &StingerTake,
) -> Result<(StingerWatch, bool), StingerProgramError> {
let unchanged = |error| StingerProgramError {
error,
ftb_cancelled: false,
};
let mixer = self.dist_mixer(block_instance_id).map_err(unchanged)?;
let pads = self
.stinger_pads(block_instance_id)
.ok_or_else(|| PipelineError::InvalidProperty {
element: block_instance_id.to_string(),
property: strom_types::stinger::ENABLE_STINGER_PROPERTY.to_string(),
reason: "this vision mixer has no stinger input".to_string(),
})
.map_err(unchanged)?;
) -> Result<StingerTarget<'_>, PipelineError> {
let mixer = self.dist_mixer(block_instance_id)?;
let pads =
self.stinger_pads(block_instance_id)
.ok_or_else(|| PipelineError::InvalidProperty {
element: block_instance_id.to_string(),
property: strom_types::stinger::ENABLE_STINGER_PROPERTY.to_string(),
reason: "this vision mixer has no stinger input".to_string(),
})?;
if take.plan.variant.uses_matte() && pads.matte.is_none() {
return Err(unchanged(PipelineError::TransitionError(
return Err(PipelineError::TransitionError(
"a matte stinger needs the GPU mixer".to_string(),
)));
));
}
let state = overlay::get_overlay_state(&self.flow_id, block_instance_id)
.ok_or_else(|| {
let state =
overlay::get_overlay_state(&self.flow_id, block_instance_id).ok_or_else(|| {
PipelineError::ElementNotFound(format!("overlay state of {}", block_instance_id))
})
.map_err(unchanged)?;
})?;
let pad = |idx: usize| {
mixer
.static_pad(&format!("sink_{}", idx))
Expand All @@ -329,16 +343,80 @@ impl PipelineManager {
pad: format!("sink_{}", idx),
})
};
let a = pad(take.from_input).map_err(unchanged)?;
let b = pad(take.to_input).map_err(unchanged)?;
Ok(StingerTarget {
mixer,
a: pad(take.from_input)?,
b: pad(take.to_input)?,
pads,
state,
})
}

// Start from the resting state of a classic take: A alone on air,
// the stinger pads down, no shader take left running. That also
// ends a fade-to-black.
let ftb_cancelled = state
/// Stage a take and raise its graphic pad before its start is known. For
/// a source that starts on a trigger and only then says when it started;
/// `program_stinger` with `fill_raised` programs the rest from that. The
/// source must be transparent until it starts. Returns whether this
/// cancelled a fade-to-black.
///
/// A failure part way through aborts the take, as `program_stinger` does.
pub fn raise_stinger_fill(
&self,
block_instance_id: &str,
take: &StingerTake,
) -> Result<bool, StingerProgramError> {
let t = self
.stinger_target(block_instance_id, take)
.map_err(StingerProgramError::unchanged)?;
let ftb_cancelled = t
.state
.ftb_active
.swap(false, std::sync::atomic::Ordering::Relaxed);
match self.program_stinger_pads(block_instance_id, take, mixer, &pads, &a, &b, &state) {
match self.stage_stinger_pads(block_instance_id, take, &t) {
Ok(()) => {
crate::gst::control_bindings::wipe_control_bindings(
t.pads.fill.upcast_ref(),
&["alpha"],
);
t.pads.fill.set_property("alpha", 1.0f64);
Ok(ftb_cancelled)
}
Err(error) => {
self.abort_stinger(block_instance_id, take);
Err(StingerProgramError {
error,
ftb_cancelled,
})
}
}
}

/// Program a whole stinger take, and start counting the clip's frames.
/// Also returns whether it cancelled a fade-to-black, as any take does.
///
/// A failure once it has started changing pads aborts the take (the old
/// source alone on air, the stinger pads down) before it returns; the
/// error then says whether a fade-to-black was cancelled on the way.
pub fn program_stinger(
&self,
block_instance_id: &str,
take: &StingerTake,
) -> Result<(StingerWatch, bool), StingerProgramError> {
let t = self
.stinger_target(block_instance_id, take)
.map_err(StingerProgramError::unchanged)?;
// A raised graphic pad was staged by `raise_stinger_fill`, which also
// ended any fade-to-black, and the source may already be on it:
// staging again would drop it.
let ftb_cancelled = !take.fill_raised
&& t.state
.ftb_active
.swap(false, std::sync::atomic::Ordering::Relaxed);
let staged = if take.fill_raised {
Ok(())
} else {
self.stage_stinger_pads(block_instance_id, take, &t)
};
match staged.and_then(|()| self.program_stinger_pads(block_instance_id, take, &t)) {
Ok(watch) => Ok((watch, ftb_cancelled)),
Err(error) => {
self.abort_stinger(block_instance_id, take);
Expand All @@ -350,27 +428,29 @@ impl PipelineManager {
}
}

/// The pad changes of [`Self::program_stinger`], from the resting state
/// on. Any of them may have run when this fails.
#[allow(clippy::too_many_arguments)]
fn program_stinger_pads(
/// Put the mixer in a take's resting state, A alone on air and the
/// stinger pads down, and set the graphic pad up for the take's clip.
/// Any of it may have run when this fails.
fn stage_stinger_pads(
&self,
block_instance_id: &str,
take: &StingerTake,
mixer: &gst::Element,
pads: &StingerPads,
a: &gst::Pad,
b: &gst::Pad,
state: &overlay::VisionMixerOverlayState,
) -> Result<StingerWatch, PipelineError> {
let variant = take.plan.variant;
t: &StingerTarget<'_>,
) -> Result<(), PipelineError> {
let StingerTarget {
mixer,
pads,
b,
state,
..
} = t;
let gpu = pads.matte.is_some();
self.reset_take_fx(block_instance_id);
let (cw, ch) = self.dist_canvas_size(block_instance_id);
self.reset_classic_take_pads(
block_instance_id,
mixer,
Some(state),
Some(state.as_ref()),
Some(take.from_input),
state.num_inputs,
cw,
Expand Down Expand Up @@ -427,6 +507,21 @@ impl PipelineManager {
}
}
pads.fill.set_property("zorder", DIST_STINGER_FILL_ZORDER);
Ok(())
}

/// The keyframes of [`Self::program_stinger`], from a staged take on.
/// Any of them may have run when this fails.
fn program_stinger_pads(
&self,
block_instance_id: &str,
take: &StingerTake,
t: &StingerTarget<'_>,
) -> Result<StingerWatch, PipelineError> {
let StingerTarget {
mixer, pads, a, b, ..
} = t;
let variant = take.plan.variant;
// A step key sits half a frame before the output frame it acts on.
// The mixer stamps its frames from a rounded origin, so a frame's
// timestamp can be a nanosecond either side of the grid's: a key
Expand All @@ -437,6 +532,8 @@ impl PipelineManager {
let has_graphic = take.plan.layout != StingerLayout::MaskOnly;
let fill_keys: &[(u64, f64)] = if !has_graphic {
&[(0, 0.0)]
} else if take.fill_raised {
&[(0, 1.0), (step(take.end), 0.0)]
} else {
&[(0, 0.0), (step(take.start), 1.0), (step(take.end), 0.0)]
};
Expand Down
1 change: 1 addition & 0 deletions backend/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ use utoipa::OpenApi;
strom_types::stinger::StingerVariant,
strom_types::stinger::StingerBeneath,
strom_types::stinger::StingerClipSettings,
strom_types::stinger::StingerSourceKind,
strom_types::stinger::StingerClipInfo,
strom_types::stinger::StingerClip,
strom_types::stinger::StingerTakeReport,
Expand Down
Loading