gst-plugins-rs/utils/fallbackswitch/tests/fallbackswitch.rs

587 lines
18 KiB
Rust
Raw Normal View History

2019-08-17 08:47:05 +00:00
// Copyright (C) 2019 Sebastian Dröge <sebastian@centricular.com>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
// Boston, MA 02110-1335, USA.
2020-11-22 16:59:46 +00:00
use gst::gst_debug;
2019-08-17 08:47:05 +00:00
use gst::prelude::*;
use once_cell::sync::Lazy;
2019-08-17 08:47:05 +00:00
static TEST_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
gst::DebugCategory::new(
2019-08-17 08:47:05 +00:00
"fallbackswitch-test",
gst::DebugColorFlags::empty(),
Some("fallbackswitch test"),
)
});
2019-08-17 08:47:05 +00:00
fn init() {
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once(|| {
gst::init().unwrap();
gstfallbackswitch::plugin_register_static().expect("gstfallbackswitch test");
});
}
macro_rules! assert_fallback_buffer {
($buffer:expr, $ts:expr) => {
2021-04-12 12:49:54 +00:00
assert_eq!($buffer.pts(), $ts);
assert_eq!($buffer.size(), 160 * 120 * 4);
2019-08-17 08:47:05 +00:00
};
}
macro_rules! assert_buffer {
($buffer:expr, $ts:expr) => {
2021-04-12 12:49:54 +00:00
assert_eq!($buffer.pts(), $ts);
assert_eq!($buffer.size(), 320 * 240 * 4);
2019-08-17 08:47:05 +00:00
};
}
#[test]
fn test_no_fallback_no_drops() {
let pipeline = setup_pipeline(None);
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
set_time(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::SECOND);
set_time(&pipeline, gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(&pipeline, 2 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(2 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
push_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
#[test]
fn test_no_drops_live() {
test_no_drops(true);
}
#[test]
fn test_no_drops_not_live() {
test_no_drops(false);
}
fn test_no_drops(live: bool) {
let pipeline = setup_pipeline(Some(live));
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
push_fallback_buffer(&pipeline, gst::ClockTime::ZERO);
set_time(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, gst::ClockTime::SECOND);
push_buffer(&pipeline, gst::ClockTime::SECOND);
set_time(&pipeline, gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
push_fallback_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(&pipeline, 2 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(2 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// EOS on the fallback should not be required
push_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
#[test]
fn test_no_drops_but_no_fallback_frames_live() {
test_no_drops_but_no_fallback_frames(true);
}
#[test]
fn test_no_drops_but_no_fallback_frames_not_live() {
test_no_drops_but_no_fallback_frames(false);
}
fn test_no_drops_but_no_fallback_frames(live: bool) {
let pipeline = setup_pipeline(Some(live));
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
// +10ms needed here because the immediate timeout will be always at running time 0, but
// aggregator also adds the latency to it so we end up at 10ms instead.
2021-05-28 16:35:28 +00:00
set_time(&pipeline, 10 * gst::ClockTime::MSECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::SECOND);
set_time(&pipeline, gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(&pipeline, 2 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(2 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// EOS on the fallback should not be required
push_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
#[test]
fn test_short_drop_live() {
test_short_drop(true);
}
#[test]
fn test_short_drop_not_live() {
test_short_drop(false);
}
fn test_short_drop(live: bool) {
let pipeline = setup_pipeline(Some(live));
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
push_fallback_buffer(&pipeline, gst::ClockTime::ZERO);
set_time(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
// A timeout at 1s will get rid of the fallback buffer
// but not output anything
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
// Time out the fallback buffer at +10ms
2021-05-28 16:35:28 +00:00
set_time(
&pipeline,
gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
push_fallback_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
push_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(&pipeline, 2 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(2 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
push_eos(&pipeline);
push_fallback_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
#[test]
fn test_long_drop_and_eos_live() {
test_long_drop_and_eos(true);
}
#[test]
fn test_long_drop_and_eos_not_live() {
test_long_drop_and_eos(false);
}
fn test_long_drop_and_eos(live: bool) {
let pipeline = setup_pipeline(Some(live));
// Produce the first frame
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
push_fallback_buffer(&pipeline, gst::ClockTime::ZERO);
set_time(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
// Produce a second frame but only from the fallback source
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, gst::ClockTime::SECOND);
set_time(
&pipeline,
gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
// Produce a third frame but only from the fallback source
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(
&pipeline,
2 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
// Produce a fourth frame but only from the fallback source
// This should be output now
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 3 * gst::ClockTime::SECOND);
set_time(
&pipeline,
3 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_fallback_buffer!(buffer, Some(3 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Produce a fifth frame but only from the fallback source
// This should be output now
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 4 * gst::ClockTime::SECOND);
set_time(
&pipeline,
4 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_fallback_buffer!(buffer, Some(4 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Wait for EOS to arrive at appsink
push_eos(&pipeline);
push_fallback_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
#[test]
fn test_long_drop_and_recover_live() {
test_long_drop_and_recover(true);
}
#[test]
fn test_long_drop_and_recover_not_live() {
test_long_drop_and_recover(false);
}
fn test_long_drop_and_recover(live: bool) {
let pipeline = setup_pipeline(Some(live));
// Produce the first frame
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, gst::ClockTime::ZERO);
push_fallback_buffer(&pipeline, gst::ClockTime::ZERO);
set_time(&pipeline, gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(gst::ClockTime::ZERO));
2019-08-17 08:47:05 +00:00
// Produce a second frame but only from the fallback source
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, gst::ClockTime::SECOND);
set_time(
&pipeline,
gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
// Produce a third frame but only from the fallback source
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 2 * gst::ClockTime::SECOND);
set_time(
&pipeline,
2 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
// Produce a fourth frame but only from the fallback source
// This should be output now
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 3 * gst::ClockTime::SECOND);
set_time(
&pipeline,
3 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_fallback_buffer!(buffer, Some(3 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Produce a fifth frame but only from the fallback source
// This should be output now
2021-05-28 16:35:28 +00:00
push_fallback_buffer(&pipeline, 4 * gst::ClockTime::SECOND);
set_time(
&pipeline,
4 * gst::ClockTime::SECOND + 10 * gst::ClockTime::MSECOND,
);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_fallback_buffer!(buffer, Some(4 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Produce a sixth frame from the normal source
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 5 * gst::ClockTime::SECOND);
push_fallback_buffer(&pipeline, 5 * gst::ClockTime::SECOND);
set_time(&pipeline, 5 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(5 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Produce a seventh frame from the normal source but no fallback.
// This should still be output immediately
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 6 * gst::ClockTime::SECOND);
set_time(&pipeline, 6 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(6 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Produce a eight frame from the normal source
2021-05-28 16:35:28 +00:00
push_buffer(&pipeline, 7 * gst::ClockTime::SECOND);
push_fallback_buffer(&pipeline, 7 * gst::ClockTime::SECOND);
set_time(&pipeline, 7 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let buffer = pull_buffer(&pipeline);
2021-05-28 16:35:28 +00:00
assert_buffer!(buffer, Some(7 * gst::ClockTime::SECOND));
2019-08-17 08:47:05 +00:00
// Wait for EOS to arrive at appsink
push_eos(&pipeline);
push_fallback_eos(&pipeline);
wait_eos(&pipeline);
stop_pipeline(pipeline);
}
struct Pipeline {
pipeline: gst::Pipeline,
clock_join_handle: Option<std::thread::JoinHandle<()>>,
}
impl std::ops::Deref for Pipeline {
type Target = gst::Pipeline;
fn deref(&self) -> &gst::Pipeline {
&self.pipeline
}
}
fn setup_pipeline(with_live_fallback: Option<bool>) -> Pipeline {
init();
gst_debug!(TEST_CAT, "Setting up pipeline");
let clock = gst_check::TestClock::new();
2021-05-28 16:35:28 +00:00
clock.set_time(gst::ClockTime::ZERO);
2019-08-17 08:47:05 +00:00
let pipeline = gst::Pipeline::new(None);
// Running time 0 in our pipeline is going to be clock time 1s. All
// clock ids before 1s are used for signalling to our clock advancing
// thread.
pipeline.use_clock(Some(&clock));
2021-05-28 16:35:28 +00:00
pipeline.set_base_time(gst::ClockTime::SECOND);
pipeline.set_start_time(gst::ClockTime::NONE);
2019-08-17 08:47:05 +00:00
let src = gst::ElementFactory::make("appsrc", Some("src"))
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
2021-11-08 09:55:40 +00:00
src.set_property("is-live", true);
src.set_property("format", gst::Format::Time);
src.set_property("min-latency", 10i64);
2019-08-17 08:47:05 +00:00
src.set_property(
"caps",
&gst::Caps::builder("video/x-raw")
.field("format", "ARGB")
.field("width", 320)
.field("height", 240)
.field("framerate", gst::Fraction::new(1, 1))
2019-08-17 08:47:05 +00:00
.build(),
2021-11-08 09:55:40 +00:00
);
2019-08-17 08:47:05 +00:00
let switch = gst::ElementFactory::make("fallbackswitch", Some("switch")).unwrap();
2021-11-08 09:55:40 +00:00
switch.set_property("timeout", 3 * gst::ClockTime::SECOND);
2019-08-17 08:47:05 +00:00
let sink = gst::ElementFactory::make("appsink", Some("sink"))
.unwrap()
.downcast::<gst_app::AppSink>()
.unwrap();
2021-11-08 09:55:40 +00:00
sink.set_property("sync", false);
2019-08-17 08:47:05 +00:00
let queue = gst::ElementFactory::make("queue", None).unwrap();
pipeline
.add_many(&[src.upcast_ref(), &switch, &queue, sink.upcast_ref()])
2019-08-17 08:47:05 +00:00
.unwrap();
src.link_pads(Some("src"), &switch, Some("sink")).unwrap();
switch.link_pads(Some("src"), &queue, Some("sink")).unwrap();
queue.link_pads(Some("src"), &sink, Some("sink")).unwrap();
if let Some(live) = with_live_fallback {
let fallback_src = gst::ElementFactory::make("appsrc", Some("fallback-src"))
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
2021-11-08 09:55:40 +00:00
fallback_src.set_property("is-live", live);
fallback_src.set_property("format", gst::Format::Time);
fallback_src.set_property("min-latency", 10i64);
fallback_src.set_property(
"caps",
&gst::Caps::builder("video/x-raw")
.field("format", "ARGB")
.field("width", 160)
.field("height", 120)
.field("framerate", gst::Fraction::new(1, 1))
.build(),
);
2019-08-17 08:47:05 +00:00
pipeline.add(&fallback_src).unwrap();
fallback_src
.link_pads(Some("src"), &switch, Some("fallback_sink"))
.unwrap();
}
pipeline.set_state(gst::State::Playing).unwrap();
let clock_join_handle = std::thread::spawn(move || {
loop {
while let Some(clock_id) = clock.peek_next_pending_id().and_then(|clock_id| {
// Process if the clock ID is in the past or now
2021-05-28 16:35:28 +00:00
if clock.time().map_or(false, |time| time >= clock_id.time()) {
2019-08-17 08:47:05 +00:00
Some(clock_id)
} else {
None
}
}) {
2021-04-12 12:49:54 +00:00
gst_debug!(TEST_CAT, "Processing clock ID at {}", clock_id.time());
2019-08-17 08:47:05 +00:00
if let Some(clock_id) = clock.process_next_clock_id() {
2021-04-12 12:49:54 +00:00
gst_debug!(TEST_CAT, "Processed clock ID at {}", clock_id.time());
2021-05-28 16:35:28 +00:00
if clock_id.time().is_zero() {
2019-08-17 08:47:05 +00:00
gst_debug!(TEST_CAT, "Stopping clock thread");
return;
}
}
}
// Sleep for 5ms as long as we have pending clock IDs that are in the future
// at the top of the queue. We don't want to do a busy loop here.
while clock.peek_next_pending_id().iter().any(|clock_id| {
// Sleep if the clock ID is in the future
2021-05-28 16:35:28 +00:00
// FIXME probably can expect clock.time()
clock
.time()
.map_or(true, |clock_time| clock_time < clock_id.time())
2019-08-17 08:47:05 +00:00
}) {
use std::{thread, time};
thread::sleep(time::Duration::from_millis(10));
}
// Otherwise if there are none (or they are ready now) wait until there are
// clock ids again
let _ = clock.wait_for_next_pending_id();
}
});
Pipeline {
pipeline,
clock_join_handle: Some(clock_join_handle),
}
}
fn push_buffer(pipeline: &Pipeline, time: gst::ClockTime) {
let src = pipeline
2021-04-20 12:58:11 +00:00
.by_name("src")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
let mut buffer = gst::Buffer::with_size(320 * 240 * 4).unwrap();
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(time);
}
src.push_buffer(buffer).unwrap();
}
fn push_fallback_buffer(pipeline: &Pipeline, time: gst::ClockTime) {
let src = pipeline
2021-04-20 12:58:11 +00:00
.by_name("fallback-src")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
let mut buffer = gst::Buffer::with_size(160 * 120 * 4).unwrap();
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(time);
}
src.push_buffer(buffer).unwrap();
}
fn push_eos(pipeline: &Pipeline) {
let src = pipeline
2021-04-20 12:58:11 +00:00
.by_name("src")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
src.end_of_stream().unwrap();
}
fn push_fallback_eos(pipeline: &Pipeline) {
let src = pipeline
2021-04-20 12:58:11 +00:00
.by_name("fallback-src")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
src.end_of_stream().unwrap();
}
fn pull_buffer(pipeline: &Pipeline) -> gst::Buffer {
let sink = pipeline
2021-04-20 12:58:11 +00:00
.by_name("sink")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSink>()
.unwrap();
let sample = sink.pull_sample().unwrap();
2021-04-12 12:49:54 +00:00
sample.buffer_owned().unwrap()
2019-08-17 08:47:05 +00:00
}
fn set_time(pipeline: &Pipeline, time: gst::ClockTime) {
let clock = pipeline
2021-04-12 12:49:54 +00:00
.clock()
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_check::TestClock>()
.unwrap();
gst_debug!(TEST_CAT, "Setting time to {}", time);
2021-05-28 16:35:28 +00:00
clock.set_time(gst::ClockTime::SECOND + time);
2019-08-17 08:47:05 +00:00
}
fn wait_eos(pipeline: &Pipeline) {
let sink = pipeline
2021-04-20 12:58:11 +00:00
.by_name("sink")
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_app::AppSink>()
.unwrap();
// FIXME: Ideally without a sleep
loop {
use std::{thread, time};
if sink.is_eos() {
gst_debug!(TEST_CAT, "Waited for EOS");
break;
}
thread::sleep(time::Duration::from_millis(10));
}
}
fn stop_pipeline(mut pipeline: Pipeline) {
pipeline.set_state(gst::State::Null).unwrap();
let clock = pipeline
2021-04-12 12:49:54 +00:00
.clock()
2019-08-17 08:47:05 +00:00
.unwrap()
.downcast::<gst_check::TestClock>()
.unwrap();
// Signal shutdown to the clock thread
2021-05-28 16:35:28 +00:00
let clock_id = clock.new_single_shot_id(gst::ClockTime::ZERO);
let _ = clock_id.wait();
2019-08-17 08:47:05 +00:00
2021-04-20 12:58:11 +00:00
let switch = pipeline.by_name("switch").unwrap();
2019-08-17 08:47:05 +00:00
let switch_weak = switch.downgrade();
drop(switch);
let pipeline_weak = pipeline.downgrade();
pipeline.clock_join_handle.take().unwrap().join().unwrap();
drop(pipeline);
assert!(switch_weak.upgrade().is_none());
assert!(pipeline_weak.upgrade().is_none());
}