2017-12-05 07:52:31 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
|
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
|
|
// <https://mozilla.org/MPL/2.0/>.
|
2017-12-05 07:52:31 +00:00
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
use gst::prelude::*;
|
|
|
|
|
|
|
|
use either::*;
|
|
|
|
|
|
|
|
use std::sync::{mpsc, Mutex};
|
2023-04-27 16:59:19 +00:00
|
|
|
use std::{thread, time::Duration};
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
fn init() {
|
2019-07-11 13:41:42 +00:00
|
|
|
use std::sync::Once;
|
|
|
|
static INIT: Once = Once::new();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
gst::init().unwrap();
|
2019-01-17 18:30:46 +00:00
|
|
|
gsttogglerecord::plugin_register_static().expect("gsttogglerecord tests");
|
2017-12-05 07:52:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
enum SendData {
|
|
|
|
Buffers(usize),
|
|
|
|
BuffersDelta(usize),
|
|
|
|
Gaps(usize),
|
|
|
|
Eos,
|
2021-01-06 18:59:44 +00:00
|
|
|
Terminate,
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 09:18:30 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2017-12-05 07:52:31 +00:00
|
|
|
fn setup_sender_receiver(
|
|
|
|
pipeline: &gst::Pipeline,
|
|
|
|
togglerecord: &gst::Element,
|
|
|
|
pad: &str,
|
|
|
|
offset: gst::ClockTime,
|
2023-04-27 16:59:19 +00:00
|
|
|
live: bool,
|
2017-12-05 07:52:31 +00:00
|
|
|
) -> (
|
|
|
|
mpsc::Sender<SendData>,
|
|
|
|
mpsc::Receiver<()>,
|
|
|
|
mpsc::Receiver<Either<gst::Buffer, gst::Event>>,
|
|
|
|
thread::JoinHandle<()>,
|
|
|
|
) {
|
2022-10-19 16:18:43 +00:00
|
|
|
let fakesink = gst::ElementFactory::make("fakesink")
|
|
|
|
.property("async", false)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&fakesink).unwrap();
|
|
|
|
|
2019-07-10 21:45:02 +00:00
|
|
|
let main_stream = pad == "src";
|
|
|
|
|
|
|
|
let (srcpad, sinkpad) = if main_stream {
|
2017-12-05 07:52:31 +00:00
|
|
|
(
|
2021-04-20 12:58:11 +00:00
|
|
|
togglerecord.static_pad("src").unwrap(),
|
|
|
|
togglerecord.static_pad("sink").unwrap(),
|
2017-12-05 07:52:31 +00:00
|
|
|
)
|
|
|
|
} else {
|
2021-04-20 15:28:38 +00:00
|
|
|
let sinkpad = togglerecord.request_pad_simple("sink_%u").unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
let srcpad = sinkpad.iterate_internal_links().next().unwrap().unwrap();
|
|
|
|
(srcpad, sinkpad)
|
|
|
|
};
|
|
|
|
|
2023-04-27 16:59:19 +00:00
|
|
|
sinkpad.add_probe(
|
|
|
|
gst::PadProbeType::QUERY_UPSTREAM,
|
|
|
|
move |_pad, probe_info| {
|
2023-10-16 16:16:52 +00:00
|
|
|
let Some(query) = probe_info.query_mut() else {
|
|
|
|
unreachable!();
|
2023-04-27 16:59:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
match query.view_mut() {
|
2023-10-16 16:16:52 +00:00
|
|
|
gst::QueryViewMut::Latency(q) => {
|
2023-04-27 16:59:19 +00:00
|
|
|
q.set(live, gst::ClockTime::ZERO, None);
|
|
|
|
gst::PadProbeReturn::Handled
|
|
|
|
}
|
|
|
|
_ => gst::PadProbeReturn::Ok,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-04-20 12:58:11 +00:00
|
|
|
let fakesink_sinkpad = fakesink.static_pad("sink").unwrap();
|
2019-01-11 23:45:05 +00:00
|
|
|
srcpad.link(&fakesink_sinkpad).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
let (sender_output, receiver_output) = mpsc::channel::<Either<gst::Buffer, gst::Event>>();
|
|
|
|
let sender_output = Mutex::new(sender_output);
|
|
|
|
srcpad.add_probe(
|
|
|
|
gst::PadProbeType::BUFFER | gst::PadProbeType::EVENT_DOWNSTREAM,
|
|
|
|
move |_, ref probe_info| {
|
|
|
|
match probe_info.data {
|
|
|
|
Some(gst::PadProbeData::Buffer(ref buffer)) => {
|
|
|
|
sender_output
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
|
|
|
.send(Left(buffer.clone()))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
Some(gst::PadProbeData::Event(ref event)) => {
|
|
|
|
sender_output
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
|
|
|
.send(Right(event.clone()))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst::PadProbeReturn::Ok
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
let (sender_input, receiver_input) = mpsc::channel::<SendData>();
|
|
|
|
let (sender_input_done, receiver_input_done) = mpsc::channel::<()>();
|
|
|
|
let thread = thread::spawn(move || {
|
|
|
|
let mut i = 0;
|
|
|
|
let mut first = true;
|
|
|
|
while let Ok(send_data) = receiver_input.recv() {
|
|
|
|
if first {
|
2020-06-24 22:33:57 +00:00
|
|
|
assert!(sinkpad.send_event(gst::event::StreamStart::new("test")));
|
2019-07-10 21:45:02 +00:00
|
|
|
let caps = if main_stream {
|
2022-10-13 18:02:04 +00:00
|
|
|
gst_video::VideoCapsBuilder::new()
|
|
|
|
.format(gst_video::VideoFormat::Argb)
|
|
|
|
.width(320)
|
|
|
|
.height(240)
|
2022-10-14 14:32:43 +00:00
|
|
|
.framerate(50.into())
|
2019-07-10 21:45:02 +00:00
|
|
|
.build()
|
|
|
|
} else {
|
2022-10-13 18:02:04 +00:00
|
|
|
gst_audio::AudioCapsBuilder::new_interleaved()
|
|
|
|
.format(gst_audio::AUDIO_FORMAT_U8)
|
|
|
|
.rate(800)
|
|
|
|
.channels(1)
|
2019-07-10 21:45:02 +00:00
|
|
|
.build()
|
|
|
|
};
|
2020-06-24 22:33:57 +00:00
|
|
|
assert!(sinkpad.send_event(gst::event::Caps::new(&caps)));
|
2019-07-10 21:45:02 +00:00
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2020-06-24 22:33:57 +00:00
|
|
|
assert!(sinkpad.send_event(gst::event::Segment::new(&segment)));
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
let mut tags = gst::TagList::new();
|
|
|
|
tags.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.add::<gst::tags::Title>(&"some title", gst::TagMergeMode::Append);
|
2020-06-24 22:33:57 +00:00
|
|
|
assert!(sinkpad.send_event(gst::event::Tag::new(tags)));
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
2019-07-10 21:45:02 +00:00
|
|
|
let buffer = if main_stream {
|
|
|
|
gst::Buffer::with_size(320 * 240 * 4).unwrap()
|
|
|
|
} else {
|
|
|
|
gst::Buffer::with_size(160).unwrap()
|
|
|
|
};
|
|
|
|
|
2017-12-05 07:52:31 +00:00
|
|
|
match send_data {
|
|
|
|
SendData::Eos => {
|
|
|
|
break;
|
|
|
|
}
|
2018-10-11 10:49:48 +00:00
|
|
|
SendData::Buffers(n) => {
|
|
|
|
for _ in 0..n {
|
2019-07-10 21:45:02 +00:00
|
|
|
let mut buffer = buffer.clone();
|
|
|
|
{
|
|
|
|
let buffer = buffer.make_mut();
|
2022-10-17 17:48:43 +00:00
|
|
|
buffer.set_pts(offset + i * 20.mseconds());
|
|
|
|
buffer.set_duration(20.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
}
|
2018-10-11 10:49:48 +00:00
|
|
|
let _ = sinkpad.chain(buffer);
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SendData::BuffersDelta(n) => {
|
|
|
|
for _ in 0..n {
|
|
|
|
let mut buffer = gst::Buffer::new();
|
|
|
|
buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
2022-10-17 17:48:43 +00:00
|
|
|
.set_pts(offset + i * 20.mseconds());
|
|
|
|
buffer.get_mut().unwrap().set_duration(20.mseconds());
|
2018-10-11 10:49:48 +00:00
|
|
|
buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.set_flags(gst::BufferFlags::DELTA_UNIT);
|
|
|
|
let _ = sinkpad.chain(buffer);
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SendData::Gaps(n) => {
|
|
|
|
for _ in 0..n {
|
2022-10-17 17:48:43 +00:00
|
|
|
let event = gst::event::Gap::new(offset + i * 20.mseconds(), 20.mseconds());
|
2018-10-11 10:49:48 +00:00
|
|
|
let _ = sinkpad.send_event(event);
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 18:59:44 +00:00
|
|
|
SendData::Terminate => {
|
|
|
|
let _ = sender_input_done.send(());
|
|
|
|
return;
|
|
|
|
}
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let _ = sender_input_done.send(());
|
|
|
|
}
|
|
|
|
|
2020-06-24 22:33:57 +00:00
|
|
|
let _ = sinkpad.send_event(gst::event::Eos::new());
|
2017-12-05 07:52:31 +00:00
|
|
|
let _ = sender_input_done.send(());
|
|
|
|
});
|
|
|
|
|
|
|
|
(sender_input, receiver_input_done, receiver_output, thread)
|
|
|
|
}
|
|
|
|
|
2021-06-04 22:16:05 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2017-12-05 07:52:31 +00:00
|
|
|
fn recv_buffers(
|
|
|
|
receiver_output: &mpsc::Receiver<Either<gst::Buffer, gst::Event>>,
|
2017-12-09 17:41:54 +00:00
|
|
|
segment: &mut gst::FormattedSegment<gst::ClockTime>,
|
2017-12-05 07:52:31 +00:00
|
|
|
wait_buffers: usize,
|
2021-05-28 16:35:28 +00:00
|
|
|
) -> (
|
|
|
|
Vec<(
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
)>,
|
|
|
|
bool,
|
|
|
|
) {
|
2017-12-05 07:52:31 +00:00
|
|
|
let mut res = Vec::new();
|
|
|
|
let mut n_buffers = 0;
|
2021-01-06 18:59:44 +00:00
|
|
|
let mut saw_eos = false;
|
2017-12-05 07:52:31 +00:00
|
|
|
while let Ok(val) = receiver_output.recv() {
|
|
|
|
match val {
|
|
|
|
Left(buffer) => {
|
2019-07-10 21:45:02 +00:00
|
|
|
res.push((
|
2021-04-12 12:49:54 +00:00
|
|
|
segment.to_running_time(buffer.pts()),
|
|
|
|
buffer.pts(),
|
|
|
|
buffer.duration(),
|
2019-07-10 21:45:02 +00:00
|
|
|
));
|
2017-12-05 07:52:31 +00:00
|
|
|
n_buffers += 1;
|
|
|
|
if wait_buffers > 0 && n_buffers == wait_buffers {
|
2021-01-06 18:59:44 +00:00
|
|
|
return (res, saw_eos);
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Right(event) => {
|
|
|
|
use gst::EventView;
|
|
|
|
|
|
|
|
match event.view() {
|
2022-01-19 13:07:45 +00:00
|
|
|
EventView::Gap(e) => {
|
2019-07-10 21:45:02 +00:00
|
|
|
let (ts, duration) = e.get();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-05-28 16:35:28 +00:00
|
|
|
res.push((segment.to_running_time(ts), Some(ts), duration));
|
2017-12-05 07:52:31 +00:00
|
|
|
n_buffers += 1;
|
|
|
|
if wait_buffers > 0 && n_buffers == wait_buffers {
|
2021-01-06 18:59:44 +00:00
|
|
|
return (res, saw_eos);
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EventView::Eos(..) => {
|
2021-01-06 18:59:44 +00:00
|
|
|
saw_eos = true;
|
|
|
|
return (res, saw_eos);
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
2022-01-19 13:07:45 +00:00
|
|
|
EventView::Segment(e) => {
|
2021-04-12 12:49:54 +00:00
|
|
|
*segment = e.segment().clone().downcast().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 18:59:44 +00:00
|
|
|
(res, saw_eos)
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create() {
|
|
|
|
init();
|
2022-10-19 16:18:43 +00:00
|
|
|
assert!(gst::ElementFactory::make("togglerecord").build().is_ok());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_pads() {
|
|
|
|
init();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-04-20 15:28:38 +00:00
|
|
|
let sinkpad = togglerecord.request_pad_simple("sink_%u").unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
let srcpad = sinkpad.iterate_internal_links().next().unwrap().unwrap();
|
|
|
|
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(sinkpad.name(), "sink_0");
|
|
|
|
assert_eq!(srcpad.name(), "src_0");
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
togglerecord.release_request_pad(&sinkpad);
|
2021-04-12 12:49:54 +00:00
|
|
|
assert!(sinkpad.parent().is_none());
|
|
|
|
assert!(srcpad.parent().is_none());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 16:59:19 +00:00
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open_nonlivein_nonliveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", false)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
|
|
|
assert_eq!(buffers.len(), 10);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open_nonlivein_liveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", true)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
|
|
|
assert_eq!(buffers.len(), 10);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
2017-12-05 07:52:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
2017-12-05 07:52:31 +00:00
|
|
|
assert_eq!(buffers.len(), 10);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_gaps_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(5)).unwrap();
|
|
|
|
sender_input.send(SendData::Gaps(5)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
2017-12-05 07:52:31 +00:00
|
|
|
assert_eq!(buffers.len(), 10);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_close_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done.recv().unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
2017-12-05 07:52:31 +00:00
|
|
|
assert_eq!(buffers.len(), 10);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open_close() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done.recv().unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
2017-12-05 07:52:31 +00:00
|
|
|
assert_eq!(buffers.len(), 10);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open_close_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done.recv().unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done.recv().unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input.send(SendData::Buffers(10)).unwrap();
|
|
|
|
drop(sender_input);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers, _) = recv_buffers(&receiver_output, &mut segment, 0);
|
2017-12-05 07:52:31 +00:00
|
|
|
assert_eq!(buffers.len(), 20);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_shift() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 5.mseconds(), true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
2019-07-10 21:45:02 +00:00
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
2019-07-10 21:45:02 +00:00
|
|
|
// Second to last buffer should be clipped from second stream, last should be dropped
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), 5.mseconds() + index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), 5.mseconds() + index * 20.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
if index == 9 {
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(duration.unwrap(), 15.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
} else {
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
}
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
2019-07-10 21:45:02 +00:00
|
|
|
assert_eq!(buffers_2.len(), 10);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_shift_main() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", 5.mseconds(), true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
2019-07-10 21:45:02 +00:00
|
|
|
sender_input_2.send(SendData::Buffers(12)).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// PTS 5 maps to running time 0 now
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), 5.mseconds() + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
2019-07-10 21:45:02 +00:00
|
|
|
// First and second last buffer should be clipped from second stream,
|
|
|
|
// last buffer should be dropped
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2019-07-10 21:45:02 +00:00
|
|
|
if index == 0 {
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), 5.mseconds() + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 15.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
} else if index == 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds() - 5.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 5.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
} else {
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds() - 5.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2019-07-10 21:45:02 +00:00
|
|
|
}
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
2019-07-10 21:45:02 +00:00
|
|
|
assert_eq!(buffers_2.len(), 11);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_close() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_close_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Start recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 12:05:29 +00:00
|
|
|
#[test]
|
|
|
|
fn test_two_stream_close_open_nonlivein_nonliveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", false)
|
|
|
|
.property("record", false)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let main_buffers_in_gap = 10u64;
|
|
|
|
let secondary_buffers_in_gap = main_buffers_in_gap + 1;
|
|
|
|
let main_buffers_after_gap = 10u64;
|
|
|
|
let secondary_buffers_after_gap = 9u64;
|
|
|
|
let recv_timeout = Duration::from_secs(10);
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(main_buffers_in_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
receiver_input_done_1.recv_timeout(Duration::from_millis(20)),
|
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers((secondary_buffers_in_gap) as usize))
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
receiver_input_done_2.recv_timeout(Duration::from_millis(20)),
|
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Start recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(main_buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers(secondary_buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_1.len() as u64,
|
|
|
|
main_buffers_in_gap + main_buffers_in_gap
|
|
|
|
);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_2.len() as u64,
|
|
|
|
secondary_buffers_in_gap + secondary_buffers_after_gap
|
|
|
|
);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-03-12 15:19:45 +00:00
|
|
|
// FIXME: racy: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/513
|
|
|
|
#[ignore]
|
2023-06-20 12:05:29 +00:00
|
|
|
fn test_two_stream_close_open_nonlivein_liveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let testclock = gst_check::TestClock::new();
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
pipeline.use_clock(Some(&testclock));
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", true)
|
|
|
|
.property("record", false)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
togglerecord.set_clock(Some(&testclock)).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
let testclock = testclock.downcast::<gst_check::TestClock>().unwrap();
|
|
|
|
testclock.set_time(gst::ClockTime::ZERO);
|
|
|
|
|
|
|
|
let main_buffers_in_gap = 10u64;
|
|
|
|
let secondary_buffers_in_gap = main_buffers_in_gap + 1;
|
|
|
|
let main_buffers_after_gap = 10u64;
|
|
|
|
let secondary_buffers_after_gap = 9u64;
|
|
|
|
let recv_timeout = Duration::from_secs(10);
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(main_buffers_in_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
2023-06-23 13:05:26 +00:00
|
|
|
receiver_input_done_1.recv_timeout(Duration::from_millis(60)),
|
2023-06-20 12:05:29 +00:00
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers((secondary_buffers_in_gap) as usize))
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
2023-06-23 13:05:26 +00:00
|
|
|
receiver_input_done_2.recv_timeout(Duration::from_millis(60)),
|
2023-06-20 12:05:29 +00:00
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Advance the clock
|
|
|
|
let block_time = gst::ClockTime::from_mseconds(42);
|
|
|
|
testclock.advance_time(block_time.nseconds() as i64);
|
|
|
|
|
|
|
|
// Start recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(main_buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers(secondary_buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), block_time + index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_1.len() as u64,
|
|
|
|
main_buffers_in_gap + main_buffers_in_gap
|
|
|
|
);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), block_time + index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_2.len() as u64,
|
|
|
|
secondary_buffers_in_gap + secondary_buffers_after_gap
|
|
|
|
);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
2023-04-27 16:59:19 +00:00
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_close_open_nonlivein_liveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let testclock = gst_check::TestClock::new();
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
pipeline.use_clock(Some(&testclock));
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", true)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
togglerecord.set_clock(Some(&testclock)).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
let testclock = testclock.downcast::<gst_check::TestClock>().unwrap();
|
|
|
|
testclock.set_time(gst::ClockTime::ZERO);
|
|
|
|
|
|
|
|
let main_buffers_before_gap = 10u64;
|
|
|
|
let secondary_buffers_before_gap = main_buffers_before_gap + 1;
|
|
|
|
let buffers_in_gap = 10u64;
|
|
|
|
let buffers_after_gap = 10u64;
|
|
|
|
let recv_timeout = Duration::from_secs(10);
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(main_buffers_before_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers(
|
|
|
|
(secondary_buffers_before_gap - 1) as usize,
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
receiver_input_done_2.recv_timeout(Duration::from_millis(20)),
|
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, this will block
|
|
|
|
togglerecord.set_property("record", false);
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(buffers_in_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Send another 10 buffers to sender 2, both are the same position at 9 buffers, the next one
|
|
|
|
// will block until record=true
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers(buffers_in_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
// Advance the clock
|
|
|
|
let block_time = gst::ClockTime::from_mseconds(42);
|
|
|
|
testclock.advance_time(block_time.nseconds() as i64);
|
|
|
|
|
|
|
|
// Start recording again and send another set of buffers to both senders
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input_1
|
|
|
|
.send(SendData::Buffers(buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
sender_input_2
|
|
|
|
.send(SendData::Buffers(buffers_after_gap as usize))
|
|
|
|
.unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, _) = recv_buffers(
|
|
|
|
&receiver_output_1,
|
|
|
|
&mut segment_1,
|
|
|
|
main_buffers_before_gap as usize,
|
|
|
|
);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(
|
|
|
|
running_time.unwrap(),
|
|
|
|
block_time + (index + main_buffers_before_gap) * 20.mseconds()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
pts.unwrap(),
|
|
|
|
(index + main_buffers_before_gap) * 20.mseconds()
|
|
|
|
);
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_1.len(),
|
|
|
|
(buffers_in_gap + buffers_after_gap) as usize
|
|
|
|
);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, _) = recv_buffers(
|
|
|
|
&receiver_output_2,
|
|
|
|
&mut segment_2,
|
|
|
|
secondary_buffers_before_gap as usize,
|
|
|
|
);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(
|
|
|
|
running_time.unwrap(),
|
|
|
|
block_time + (index + secondary_buffers_before_gap) * 20.mseconds()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
pts.unwrap(),
|
|
|
|
(index + secondary_buffers_before_gap) * 20.mseconds()
|
|
|
|
);
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
buffers_2.len(),
|
|
|
|
(buffers_in_gap + buffers_after_gap - 1) as usize
|
|
|
|
);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_close_open_nonlivein_nonliveout() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::default();
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord")
|
|
|
|
.property("is-live", false)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, false);
|
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
let recv_timeout = Duration::from_secs(10);
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
receiver_input_done_2.recv_timeout(Duration::from_millis(20)),
|
|
|
|
Err(mpsc::RecvTimeoutError::Timeout)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, this will block
|
|
|
|
togglerecord.set_property("record", false);
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
|
|
|
|
// Send another buffer to sender 2, this will block until record=true
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
|
|
|
|
// Start recording again and send another set of buffers to both senders
|
|
|
|
togglerecord.set_property("record", true);
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
receiver_input_done_2.recv_timeout(recv_timeout).unwrap();
|
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 30);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 30);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
2017-12-05 07:52:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_close_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another buffer to sender 2, this will block until sender 1 advances
|
|
|
|
// but must not be dropped, although we're not recording (yet)
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
|
|
|
|
// Start recording again and send another set of buffers to both senders
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 20);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 20);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_open_close_open_gaps() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(3)).unwrap();
|
|
|
|
sender_input_1.send(SendData::Gaps(3)).unwrap();
|
|
|
|
sender_input_1.send(SendData::Buffers(4)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, which will advance
|
|
|
|
// it and release the 11th buffer of sender 2 above
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another 4 gaps and 5 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Gaps(4)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(5)).unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another gap to sender 2, this will block until sender 1 advances
|
|
|
|
// but must not be dropped, although we're not recording (yet)
|
|
|
|
sender_input_2.send(SendData::Gaps(1)).unwrap();
|
|
|
|
|
|
|
|
// Start recording again and send another set of buffers to both senders
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 20);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 20);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_close_open_close_delta() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
|
|
|
|
|
|
|
// Sender 2 is waiting for sender 1 to continue, sender 1 is finished
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Start recording and push new buffers to sender 1. The first one is a delta frame,
|
|
|
|
// so will be dropped, and as such the next frame of sender 2 will also be dropped
|
|
|
|
// Sender 2 is empty now
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::BuffersDelta(1)).unwrap();
|
|
|
|
sender_input_1.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another 9 buffers to sender 2, both are the same position now
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
|
|
|
|
// Wait until all 20 buffers of both senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another buffer to sender 2, this will block until sender 1 advances
|
|
|
|
// but must not be dropped, and we're still recording
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
|
|
|
|
// Stop recording again and send another set of buffers to both senders
|
|
|
|
// The first one is a delta frame, so we only actually stop recording
|
|
|
|
// after recording another frame
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::BuffersDelta(1)).unwrap();
|
|
|
|
sender_input_1.send(SendData::Buffers(9)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), (11 + index) * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), (11 + index) * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_three_stream_open_close_open() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(11)).unwrap();
|
2020-08-05 15:24:10 +00:00
|
|
|
sender_input_3.send(SendData::Buffers(11)).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2020-08-05 15:24:10 +00:00
|
|
|
// Sender 2/3 is waiting for sender 1 to continue
|
2017-12-05 07:52:31 +00:00
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
|
|
|
// Stop recording and push new buffers to sender 1, which will advance
|
2020-08-05 15:24:10 +00:00
|
|
|
// it and release the 11th buffer of sender 2/3 above
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", false);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
2020-08-05 15:24:10 +00:00
|
|
|
|
2017-12-05 07:52:31 +00:00
|
|
|
receiver_input_done_2.recv().unwrap();
|
2020-08-05 15:24:10 +00:00
|
|
|
receiver_input_done_3.recv().unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
2020-08-05 15:24:10 +00:00
|
|
|
// Send another 9 buffers to sender 2/3, all streams are at the same position now
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
2020-08-05 15:24:10 +00:00
|
|
|
sender_input_3.send(SendData::Buffers(9)).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
|
|
|
|
// Wait until all 20 buffers of all senders are done
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// Send another buffer to sender 2, this will block until sender 1 advances
|
|
|
|
// but must not be dropped, although we're not recording (yet)
|
|
|
|
sender_input_2.send(SendData::Buffers(1)).unwrap();
|
|
|
|
|
|
|
|
// Start recording again and send another set of buffers to both senders
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2017-12-05 07:52:31 +00:00
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_3.send(SendData::Buffers(5)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
// The single buffer above for sender 1 should be handled now
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
sender_input_3.send(SendData::Buffers(5)).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS and wait for it to be handled
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
sender_input_3.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_1, _) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 20);
|
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_2, _) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 20);
|
|
|
|
|
2017-12-09 17:41:54 +00:00
|
|
|
let mut segment_3 = gst::FormattedSegment::<gst::ClockTime>::new();
|
2021-01-06 18:59:44 +00:00
|
|
|
let (buffers_3, _) = recv_buffers(&receiver_output_3, &mut segment_3, 0);
|
2019-07-10 21:45:02 +00:00
|
|
|
for (index, &(running_time, pts, duration)) in buffers_3.iter().enumerate() {
|
2017-12-05 07:52:31 +00:00
|
|
|
let pts_off = if index >= 10 {
|
2022-10-17 17:48:43 +00:00
|
|
|
10 * 20.mseconds()
|
2017-12-05 07:52:31 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
gst::ClockTime::ZERO
|
2017-12-05 07:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_3.len(), 20);
|
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
thread_3.join().unwrap();
|
|
|
|
|
2019-01-11 23:45:05 +00:00
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_main_eos() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2021-01-06 18:59:44 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Send 10 buffers to main stream first
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// And send EOS, at this moment, recording state should be still recording
|
|
|
|
// since running time of main stream is advanced than secondary stream
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Send 2 buffers to secondary stream. At this moment, main stream got eos
|
|
|
|
// already (after 10 buffers) and secondary stream got 2 buffers.
|
|
|
|
// it will make running time of secondary stream to be advanced than main
|
|
|
|
// stream and results in all-eos state even if we don't send EOS event
|
|
|
|
// explicitly
|
|
|
|
sender_input_2.send(SendData::Buffers(2)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
sender_input_2.send(SendData::Terminate).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// At this moment, all streams should be in eos state. So togglerecord
|
|
|
|
// must be in stopped state
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(!recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, saw_eos) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Last buffer should be dropped from second stream
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, saw_eos) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_two_stream_secondary_eos_first() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2021-01-06 18:59:44 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Send 10 buffers to main stream first
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS to the second stream
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// Since main stream is not yet EOS state, we should be in recording state
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// And send EOS to the main stream then it will update state to Stopped
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(!recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, saw_eos) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// We sent 9 buffers to the second stream, and there should be no dropped
|
|
|
|
// buffer
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, saw_eos) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 9);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_three_stream_main_eos() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2021-01-06 18:59:44 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
sender_input_3.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// And send EOS, at this moment, recording state should be still recording
|
|
|
|
// since running time of the second stream is not in eos state
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Send 2 buffers to non-main streams. At this moment, main stream got EOS
|
|
|
|
// already (after 10 buffers) and the other streams got 9 buffers.
|
|
|
|
// So those 2 additional buffers to the non-main streams will make running
|
|
|
|
// times of those streams to be advanced than main stream.
|
|
|
|
// It will result in all-eos state even if we don't send EOS event
|
|
|
|
// to the non-main streams explicitly
|
|
|
|
sender_input_2.send(SendData::Buffers(2)).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
sender_input_2.send(SendData::Terminate).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
// The third stream is not in EOS state yet, so still recording == true
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// And terminate the third thread without EOS
|
|
|
|
sender_input_3.send(SendData::Buffers(2)).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
sender_input_3.send(SendData::Terminate).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// At this moment, all streams should be in eos state. So togglerecord
|
|
|
|
// must be in stopped state
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(!recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, saw_eos) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Last buffer should be dropped from non-main streams
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, saw_eos) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_3 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_3, saw_eos) = recv_buffers(&receiver_output_3, &mut segment_3, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_3.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_3.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
thread_3.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_three_stream_main_and_second_eos() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2021-01-06 18:59:44 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
sender_input_3.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// And send EOS, at this moment, recording state should be still recording
|
|
|
|
// since running time of the third stream is not in eos state
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// And send EOS to the second stream, but state shouldn't be affected by
|
|
|
|
// this EOS. The third stream is still not in EOS state
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Send 2 buffers to the third stream. At this moment, main stream and
|
|
|
|
// the second stream got EOS already (after 10 buffers) and the third stream
|
|
|
|
// got 9 buffers.
|
|
|
|
// So those 2 additional buffers to the third streams will make running
|
|
|
|
// time of the stream to be advanced than main stream.
|
|
|
|
// It will result in all-eos state even if we don't send EOS event
|
|
|
|
// to the third stream explicitly
|
|
|
|
sender_input_3.send(SendData::Buffers(2)).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
sender_input_3.send(SendData::Terminate).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// At this moment, all streams should be in eos state. So togglerecord
|
|
|
|
// must be in stopped state
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(!recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, saw_eos) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// We sent 9 buffers to the second stream, and there must be no dropped one
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, saw_eos) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 9);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Last buffer should be dropped from the third stream
|
|
|
|
let mut segment_3 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_3, saw_eos) = recv_buffers(&receiver_output_3, &mut segment_3, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_3.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_3.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
thread_3.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_three_stream_secondary_eos_first() {
|
|
|
|
init();
|
|
|
|
|
2022-10-22 16:06:29 +00:00
|
|
|
let pipeline = gst::Pipeline::default();
|
2022-10-19 16:18:43 +00:00
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord").build().unwrap();
|
2021-01-06 18:59:44 +00:00
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO, true);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2023-04-27 16:59:19 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
gst::ClockTime::ZERO,
|
|
|
|
true,
|
|
|
|
);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
togglerecord.set_property("record", true);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
sender_input_1.send(SendData::Buffers(10)).unwrap();
|
|
|
|
sender_input_2.send(SendData::Buffers(9)).unwrap();
|
|
|
|
sender_input_3.send(SendData::Buffers(9)).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// Send EOS to non-main streams
|
|
|
|
sender_input_2.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_2.recv().unwrap();
|
|
|
|
|
|
|
|
sender_input_3.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_3.recv().unwrap();
|
|
|
|
|
|
|
|
// Since main stream is not yet EOS state, we should be in recording state
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// And send EOS, Send EOS to the main stream then it will update state to
|
|
|
|
// Stopped
|
|
|
|
sender_input_1.send(SendData::Eos).unwrap();
|
|
|
|
receiver_input_done_1.recv().unwrap();
|
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let recording = togglerecord.property::<bool>("recording");
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(!recording);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_1, saw_eos) = recv_buffers(&receiver_output_1, &mut segment_1, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_1.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_1.len(), 10);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
// Last buffer should be dropped from non-main streams
|
|
|
|
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_2, saw_eos) = recv_buffers(&receiver_output_2, &mut segment_2, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_2.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_2.len(), 9);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
let mut segment_3 = gst::FormattedSegment::<gst::ClockTime>::new();
|
|
|
|
let (buffers_3, saw_eos) = recv_buffers(&receiver_output_3, &mut segment_3, 0);
|
|
|
|
for (index, &(running_time, pts, duration)) in buffers_3.iter().enumerate() {
|
|
|
|
let index = index as u64;
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(pts.unwrap(), index * 20.mseconds());
|
|
|
|
assert_eq!(duration.unwrap(), 20.mseconds());
|
2021-01-06 18:59:44 +00:00
|
|
|
}
|
|
|
|
assert_eq!(buffers_3.len(), 9);
|
2021-06-04 22:16:05 +00:00
|
|
|
assert!(saw_eos);
|
2021-01-06 18:59:44 +00:00
|
|
|
|
|
|
|
thread_1.join().unwrap();
|
|
|
|
thread_2.join().unwrap();
|
|
|
|
thread_3.join().unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|