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
21 changes: 20 additions & 1 deletion backend/src/blocks/builtin/live_recorder/keepalive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Track {
mux.release_request_pad(&pad);
}

/// The input's drop probe and the queue's position probes.
/// The input's drop and caps-query probes, and the queue's position probes.
pub fn install_probes(self: &Arc<Self>) {
if let Some(input_sink) = self.input.upgrade().and_then(|i| i.static_pad("sink")) {
// Without it, a retired track's branch would answer upstream with
Expand All @@ -224,6 +224,25 @@ impl Track {
}
},
);

// Answer caps queries here, as the input did before its parser was
// linked: any caps, and what cannot be recorded is refused with a
// message when its caps arrive. Passed on, a query reaches the
// muxer, which once it has caps answers with exactly those, including
// fields the encoder added itself (vtenc's chroma-site). The encoder
// then refuses its own input caps, and a converter in front of it that
// cannot renegotiate fails with not-negotiated, which stops the source.
input_sink.add_probe(gst::PadProbeType::QUERY_DOWNSTREAM, |_pad, info| match info
.query_mut()
.map(|q| q.view_mut())
{
Some(gst::QueryViewMut::Caps(q)) => {
let caps = q.filter_owned().unwrap_or_else(gst::Caps::new_any);
q.set_result(&caps);
gst::PadProbeReturn::Handled
}
_ => gst::PadProbeReturn::Ok,
});
}

let Some(queue_sink) = self.queue.upgrade().and_then(|q| q.static_pad("sink")) else {
Expand Down
57 changes: 57 additions & 0 deletions backend/tests/it/live_recorder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1403,3 +1403,60 @@ fn a_video_that_restarts_its_timestamps_after_a_stall_is_recorded() {
video.len()
);
}

/// Wait until the muxer has caps on every sink pad, so it has started pinning
/// them in its caps answers.
fn wait_for_mux_caps(mux: &gst::Element) {
let deadline = Instant::now() + Duration::from_secs(10);
while mux.sink_pads().iter().any(|p| p.current_caps().is_none()) {
assert!(Instant::now() < deadline, "the muxer never got caps");
std::thread::sleep(Duration::from_millis(50));
}
}

/// Once the muxer has caps it answers a caps query with exactly those. Passed
/// through, that answer reaches the encoder, and `vtenc` then refuses input caps
/// that lack a field it pinned. The input must answer as it did before its
/// parser was linked.
#[test]
fn the_input_answers_caps_queries_without_the_muxers_current_caps() {
init();
let dir = tempfile::tempdir().unwrap();
let pipeline = gst::Pipeline::new();
let rec = add_live_recorder(
&pipeline,
"rec",
dir.path(),
&[
("num_video_tracks", PropertyValue::UInt(1)),
("num_audio_tracks", PropertyValue::UInt(0)),
],
);
let enc = recorder::video_source(&pipeline, -1, true);
enc.link(&rec.input("video_input_0")).unwrap();
rec.run_setups();

pipeline.set_state(gst::State::Playing).unwrap();
wait_for_mux_caps(&rec.mux());
no_errors(&pipeline);

// The encoder's caps without `level`: one fixed structure, as an encoder
// asks with, missing a field the muxer's current caps carry.
let enc_src = enc.static_pad("src").unwrap();
let mut filter = enc_src.current_caps().unwrap();
filter
.make_mut()
.structure_mut(0)
.unwrap()
.remove_field("level");
let answer = enc_src.peer_query_caps(Some(&filter));
pipeline.set_state(gst::State::Null).unwrap();

assert!(
filter.is_subset(&answer),
"the recorder input narrowed a caps query to the muxer's current caps\n\
asked: {}\nanswered: {}",
filter,
answer
);
}