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};
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
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,
|
|
|
|
) -> (
|
|
|
|
mpsc::Sender<SendData>,
|
|
|
|
mpsc::Receiver<()>,
|
|
|
|
mpsc::Receiver<Either<gst::Buffer, gst::Event>>,
|
|
|
|
thread::JoinHandle<()>,
|
|
|
|
) {
|
|
|
|
let fakesink = gst::ElementFactory::make("fakesink", None).unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
fakesink.set_property("async", false);
|
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)
|
|
|
|
};
|
|
|
|
|
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 {
|
|
|
|
gst::Caps::builder("video/x-raw")
|
2021-11-06 07:34:10 +00:00
|
|
|
.field("format", "ARGB")
|
|
|
|
.field("width", 320i32)
|
|
|
|
.field("height", 240i32)
|
|
|
|
.field("framerate", gst::Fraction::new(50, 1))
|
2019-07-10 21:45:02 +00:00
|
|
|
.build()
|
|
|
|
} else {
|
|
|
|
gst::Caps::builder("audio/x-raw")
|
2021-11-06 07:34:10 +00:00
|
|
|
.field("format", "U8")
|
|
|
|
.field("layout", "interleaved")
|
|
|
|
.field("rate", 8000i32)
|
|
|
|
.field("channels", 1i32)
|
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();
|
2021-05-28 16:35:28 +00:00
|
|
|
buffer.set_pts(offset + i * 20 * gst::ClockTime::MSECOND);
|
|
|
|
buffer.set_duration(20 * gst::ClockTime::MSECOND);
|
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()
|
2021-05-28 16:35:28 +00:00
|
|
|
.set_pts(offset + i * 20 * gst::ClockTime::MSECOND);
|
|
|
|
buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.set_duration(20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
let event = gst::event::Gap::new(
|
|
|
|
offset + i * 20 * gst::ClockTime::MSECOND,
|
|
|
|
20 * gst::ClockTime::MSECOND,
|
|
|
|
);
|
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();
|
2019-12-18 05:50:10 +00:00
|
|
|
assert!(gst::ElementFactory::make("togglerecord", None).is_ok());
|
2017-12-05 07:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_pads() {
|
|
|
|
init();
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one_stream_open() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, _, receiver_output, thread) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input, receiver_input_done, receiver_output, thread) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(
|
|
|
|
&pipeline,
|
|
|
|
&togglerecord,
|
|
|
|
"src_%u",
|
|
|
|
5 * gst::ClockTime::MSECOND,
|
|
|
|
);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(
|
|
|
|
running_time.unwrap(),
|
|
|
|
5 * gst::ClockTime::MSECOND + index * 20 * gst::ClockTime::MSECOND
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
pts.unwrap(),
|
|
|
|
5 * gst::ClockTime::MSECOND + index * 20 * gst::ClockTime::MSECOND
|
|
|
|
);
|
2019-07-10 21:45:02 +00:00
|
|
|
if index == 9 {
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(duration.unwrap(), 15 * gst::ClockTime::MSECOND);
|
2019-07-10 21:45:02 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", 5 * gst::ClockTime::MSECOND);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(
|
|
|
|
pts.unwrap(),
|
|
|
|
5 * gst::ClockTime::MSECOND + index * 20 * gst::ClockTime::MSECOND
|
|
|
|
);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(
|
|
|
|
pts.unwrap(),
|
|
|
|
5 * gst::ClockTime::MSECOND + index * 20 * gst::ClockTime::MSECOND
|
|
|
|
);
|
|
|
|
assert_eq!(duration.unwrap(), 15 * gst::ClockTime::MSECOND);
|
2019-07-10 21:45:02 +00:00
|
|
|
} else if index == 10 {
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(
|
|
|
|
running_time.unwrap(),
|
|
|
|
index * 20 * gst::ClockTime::MSECOND - 5 * gst::ClockTime::MSECOND
|
|
|
|
);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 5 * gst::ClockTime::MSECOND);
|
2019-07-10 21:45:02 +00:00
|
|
|
} else {
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(
|
|
|
|
running_time.unwrap(),
|
|
|
|
index * 20 * gst::ClockTime::MSECOND - 5 * gst::ClockTime::MSECOND
|
|
|
|
);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), (10 + index) * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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_close_open() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), (11 + index) * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), (11 + index) * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
2017-12-05 07:52:31 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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 {
|
2021-05-28 16:35:28 +00:00
|
|
|
10 * 20 * gst::ClockTime::MSECOND
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), pts_off + index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
|
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
let togglerecord = gst::ElementFactory::make("togglerecord", None).unwrap();
|
|
|
|
pipeline.add(&togglerecord).unwrap();
|
|
|
|
|
|
|
|
let (sender_input_1, receiver_input_done_1, receiver_output_1, thread_1) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
2021-01-06 18:59:44 +00:00
|
|
|
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
|
2021-05-28 16:35:28 +00:00
|
|
|
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", gst::ClockTime::ZERO);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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;
|
2021-05-28 16:35:28 +00:00
|
|
|
assert_eq!(running_time.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(pts.unwrap(), index * 20 * gst::ClockTime::MSECOND);
|
|
|
|
assert_eq!(duration.unwrap(), 20 * gst::ClockTime::MSECOND);
|
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();
|
|
|
|
}
|