2020-01-02 21:32:52 +00:00
|
|
|
// Copyright (C) 2019-2020 François Laignel <fengalin@free.fr>
|
2020-03-05 15:59:13 +00:00
|
|
|
// Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com>
|
2019-12-02 09:30:07 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
|
|
|
// Boston, MA 02110-1335, USA.
|
2022-01-15 19:18:47 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2022-08-29 15:41:33 +00:00
|
|
|
#![allow(clippy::non_send_fields_in_send_ty, unused_doc_comments)]
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
use futures::channel::mpsc;
|
|
|
|
use futures::future::BoxFuture;
|
|
|
|
use futures::prelude::*;
|
|
|
|
|
2021-06-03 18:20:54 +00:00
|
|
|
use gst::glib;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
use gst::prelude::*;
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
use gst::EventView;
|
|
|
|
|
2020-11-22 14:24:55 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2022-06-27 16:18:22 +00:00
|
|
|
use std::sync::Mutex;
|
2021-05-26 09:54:34 +00:00
|
|
|
use std::time::Duration;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
use gstthreadshare::runtime::prelude::*;
|
2022-10-12 10:35:20 +00:00
|
|
|
use gstthreadshare::runtime::{
|
|
|
|
Context, PadSink, PadSinkRef, PadSinkWeak, PadSrc, PadSrcRef, Task, TaskState,
|
|
|
|
};
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
const DEFAULT_CONTEXT: &str = "";
|
2021-05-26 09:54:34 +00:00
|
|
|
const THROTTLING_DURATION: Duration = Duration::from_millis(2);
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
fn init() {
|
|
|
|
use std::sync::Once;
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
gst::init().unwrap();
|
|
|
|
gstthreadshare::plugin_register_static().expect("gstthreadshare pad test");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Item {
|
|
|
|
Buffer(gst::Buffer),
|
|
|
|
BufferList(gst::BufferList),
|
|
|
|
Event(gst::Event),
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 09:04:26 +00:00
|
|
|
#[derive(Clone, Debug, glib::Boxed)]
|
|
|
|
#[boxed_type(name = "TsTestItemSender")]
|
2020-11-14 17:09:42 +00:00
|
|
|
struct ItemSender {
|
|
|
|
sender: mpsc::Sender<Item>,
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
// Src
|
|
|
|
mod imp_src {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
struct Settings {
|
|
|
|
context: String,
|
|
|
|
}
|
|
|
|
|
2020-11-22 14:24:55 +00:00
|
|
|
pub static SRC_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
|
|
|
gst::DebugCategory::new(
|
2020-11-14 17:09:42 +00:00
|
|
|
"ts-element-src-test",
|
|
|
|
gst::DebugColorFlags::empty(),
|
|
|
|
Some("Thread-sharing Test Src Element"),
|
2020-11-22 14:24:55 +00:00
|
|
|
)
|
|
|
|
});
|
2020-11-14 17:09:42 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
struct PadSrcTestHandler;
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl PadSrcHandler for PadSrcTestHandler {
|
|
|
|
type ElementImpl = ElementSrcTest;
|
|
|
|
|
2022-10-12 10:35:20 +00:00
|
|
|
fn src_event(&self, pad: &PadSrcRef, imp: &ElementSrcTest, event: gst::Event) -> bool {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", event);
|
2020-11-14 17:09:42 +00:00
|
|
|
|
|
|
|
let ret = match event.view() {
|
2022-10-12 10:35:20 +00:00
|
|
|
EventView::FlushStart(..) => {
|
|
|
|
imp.task.flush_start().await_maybe_on_context().is_ok()
|
|
|
|
}
|
2020-11-14 17:09:42 +00:00
|
|
|
EventView::Qos(..) | EventView::Reconfigure(..) | EventView::Latency(..) => true,
|
2022-10-12 10:35:20 +00:00
|
|
|
EventView::FlushStop(..) => imp.task.flush_stop().await_maybe_on_context().is_ok(),
|
2020-11-14 17:09:42 +00:00
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ret {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handled {:?}", event);
|
2020-11-14 17:09:42 +00:00
|
|
|
} else {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Didn't handle {:?}", event);
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
ret
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct ElementSrcTestTask {
|
|
|
|
element: super::ElementSrcTest,
|
|
|
|
receiver: mpsc::Receiver<Item>,
|
|
|
|
}
|
2020-04-20 19:35:06 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementSrcTestTask {
|
2022-06-27 16:18:22 +00:00
|
|
|
fn new(element: super::ElementSrcTest, receiver: mpsc::Receiver<Item>) -> Self {
|
|
|
|
ElementSrcTestTask { element, receiver }
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementSrcTestTask {
|
|
|
|
fn flush(&mut self) {
|
|
|
|
// Purge the channel
|
|
|
|
while let Ok(Some(_item)) = self.receiver.try_next() {}
|
|
|
|
}
|
2022-06-27 16:18:22 +00:00
|
|
|
async fn push_item(&self, item: Item) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
gst::debug!(SRC_CAT, obj: &self.element, "Handling {:?}", item);
|
|
|
|
|
|
|
|
let elementsrctest = self.element.imp();
|
|
|
|
match item {
|
|
|
|
Item::Event(event) => {
|
|
|
|
elementsrctest.src_pad.push_event(event).await;
|
|
|
|
|
|
|
|
Ok(gst::FlowSuccess::Ok)
|
|
|
|
}
|
|
|
|
Item::Buffer(buffer) => elementsrctest.src_pad.push(buffer).await,
|
|
|
|
Item::BufferList(list) => elementsrctest.src_pad.push_list(list).await,
|
|
|
|
}
|
|
|
|
}
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl TaskImpl for ElementSrcTestTask {
|
2022-08-10 18:10:08 +00:00
|
|
|
type Item = Item;
|
2020-11-14 17:09:42 +00:00
|
|
|
|
2022-08-10 18:10:08 +00:00
|
|
|
fn try_next(&mut self) -> BoxFuture<'_, Result<Item, gst::FlowError>> {
|
|
|
|
async move {
|
|
|
|
self.receiver.next().await.ok_or_else(|| {
|
|
|
|
gst::log!(SRC_CAT, obj: &self.element, "SrcPad channel aborted");
|
|
|
|
gst::FlowError::Eos
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
2020-11-14 17:09:42 +00:00
|
|
|
|
2022-08-10 18:10:08 +00:00
|
|
|
fn handle_item(&mut self, item: Item) -> BoxFuture<'_, Result<(), gst::FlowError>> {
|
|
|
|
async move {
|
|
|
|
let res = self.push_item(item).await.map(drop);
|
2020-11-14 17:09:42 +00:00
|
|
|
match res {
|
2022-02-21 17:43:46 +00:00
|
|
|
Ok(_) => gst::log!(SRC_CAT, obj: &self.element, "Successfully pushed item"),
|
2020-11-14 17:09:42 +00:00
|
|
|
Err(gst::FlowError::Flushing) => {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::debug!(SRC_CAT, obj: &self.element, "Flushing")
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
Err(err) => panic!("Got error {}", err),
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:10:08 +00:00
|
|
|
res
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
2020-11-14 17:09:42 +00:00
|
|
|
.boxed()
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn stop(&mut self) -> BoxFuture<'_, Result<(), gst::ErrorMessage>> {
|
|
|
|
async move {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: &self.element, "Stopping task");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.flush();
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: &self.element, "Task stopped");
|
2020-11-14 17:09:42 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed()
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn flush_start(&mut self) -> BoxFuture<'_, Result<(), gst::ErrorMessage>> {
|
|
|
|
async move {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: &self.element, "Starting task flush");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.flush();
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::log!(SRC_CAT, obj: &self.element, "Task flush started");
|
2020-11-14 17:09:42 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed()
|
2020-04-20 19:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ElementSrcTest {
|
|
|
|
src_pad: PadSrc,
|
|
|
|
task: Task,
|
2022-06-27 16:18:22 +00:00
|
|
|
sender: Mutex<Option<mpsc::Sender<Item>>>,
|
|
|
|
settings: Mutex<Settings>,
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementSrcTest {
|
|
|
|
pub fn try_push(&self, item: Item) -> Result<(), Item> {
|
|
|
|
let state = self.task.lock_state();
|
|
|
|
if *state != TaskState::Started && *state != TaskState::Paused {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::debug!(SRC_CAT, "ElementSrcTest rejecting item due to pad state");
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
return Err(item);
|
|
|
|
}
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-06-30 12:44:07 +00:00
|
|
|
let mut sender = self.sender.lock().unwrap();
|
|
|
|
match sender.as_mut() {
|
2020-11-14 17:09:42 +00:00
|
|
|
Some(sender) => sender
|
|
|
|
.try_send(item)
|
|
|
|
.map_err(mpsc::TrySendError::into_inner),
|
|
|
|
None => Err(item),
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn prepare(&self) -> Result<(), gst::ErrorMessage> {
|
|
|
|
gst::debug!(SRC_CAT, imp: self, "Preparing");
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
let settings = self.settings.lock().unwrap().clone();
|
|
|
|
let context =
|
|
|
|
Context::acquire(&settings.context, THROTTLING_DURATION).map_err(|err| {
|
2020-12-20 18:43:45 +00:00
|
|
|
gst::error_msg!(
|
2020-11-14 17:09:42 +00:00
|
|
|
gst::ResourceError::OpenRead,
|
|
|
|
["Failed to acquire Context: {}", err]
|
|
|
|
)
|
|
|
|
})?;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
let (sender, receiver) = mpsc::channel(1);
|
|
|
|
*self.sender.lock().unwrap() = Some(sender);
|
2020-04-20 19:35:06 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
self.task
|
2022-10-09 13:06:59 +00:00
|
|
|
.prepare(
|
|
|
|
ElementSrcTestTask::new(self.instance().clone(), receiver),
|
|
|
|
context,
|
|
|
|
)
|
2022-08-05 12:44:50 +00:00
|
|
|
.block_on()?;
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SRC_CAT, imp: self, "Prepared");
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn unprepare(&self) {
|
|
|
|
gst::debug!(SRC_CAT, imp: self, "Unpreparing");
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
*self.sender.lock().unwrap() = None;
|
2022-08-05 12:44:50 +00:00
|
|
|
self.task.unprepare().block_on().unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SRC_CAT, imp: self, "Unprepared");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn stop(&self) {
|
|
|
|
gst::debug!(SRC_CAT, imp: self, "Stopping");
|
2022-08-05 12:44:50 +00:00
|
|
|
self.task.stop().await_maybe_on_context().unwrap();
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SRC_CAT, imp: self, "Stopped");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2020-03-26 18:07:25 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn start(&self) {
|
|
|
|
gst::debug!(SRC_CAT, imp: self, "Starting");
|
2022-08-05 12:44:50 +00:00
|
|
|
self.task.start().await_maybe_on_context().unwrap();
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SRC_CAT, imp: self, "Started");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2020-03-26 18:07:25 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn pause(&self) {
|
|
|
|
gst::debug!(SRC_CAT, imp: self, "Pausing");
|
2022-08-10 18:10:08 +00:00
|
|
|
self.task.pause().block_on().unwrap();
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SRC_CAT, imp: self, "Paused");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 16:22:24 +00:00
|
|
|
#[glib::object_subclass]
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ObjectSubclass for ElementSrcTest {
|
|
|
|
const NAME: &'static str = "TsElementSrcTest";
|
|
|
|
type Type = super::ElementSrcTest;
|
|
|
|
type ParentType = gst::Element;
|
|
|
|
|
|
|
|
fn with_class(klass: &Self::Class) -> Self {
|
|
|
|
ElementSrcTest {
|
|
|
|
src_pad: PadSrc::new(
|
2021-04-20 12:58:11 +00:00
|
|
|
gst::Pad::from_template(&klass.pad_template("src").unwrap(), Some("src")),
|
2020-11-14 17:09:42 +00:00
|
|
|
PadSrcTestHandler,
|
|
|
|
),
|
|
|
|
task: Task::default(),
|
2022-06-27 16:18:22 +00:00
|
|
|
sender: Mutex::new(None),
|
|
|
|
settings: Mutex::new(Settings::default()),
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ObjectImpl for ElementSrcTest {
|
2021-01-21 18:21:29 +00:00
|
|
|
fn properties() -> &'static [glib::ParamSpec] {
|
|
|
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
2022-08-18 12:04:15 +00:00
|
|
|
vec![glib::ParamSpecString::builder("context")
|
|
|
|
.nick("Context")
|
|
|
|
.blurb("Context name to share threads with")
|
|
|
|
.default_value(Some(DEFAULT_CONTEXT))
|
|
|
|
.write_only()
|
|
|
|
.build()]
|
2021-01-21 18:21:29 +00:00
|
|
|
});
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2021-01-21 18:21:29 +00:00
|
|
|
PROPERTIES.as_ref()
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
2021-04-12 12:49:54 +00:00
|
|
|
match pspec.name() {
|
2021-01-21 18:21:29 +00:00
|
|
|
"context" => {
|
2020-11-14 17:09:42 +00:00
|
|
|
let context = value
|
2021-04-25 12:41:22 +00:00
|
|
|
.get::<Option<String>>()
|
2020-11-14 17:09:42 +00:00
|
|
|
.expect("type checked upstream")
|
|
|
|
.unwrap_or_else(|| "".into());
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
self.settings.lock().unwrap().context = context;
|
|
|
|
}
|
|
|
|
_ => unimplemented!(),
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn constructed(&self) {
|
|
|
|
self.parent_constructed();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
let obj = self.instance();
|
2020-11-14 17:09:42 +00:00
|
|
|
obj.add_pad(self.src_pad.gst_pad()).unwrap();
|
2022-10-12 10:35:20 +00:00
|
|
|
obj.set_element_flags(gst::ElementFlags::SOURCE);
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 08:57:31 +00:00
|
|
|
impl GstObjectImpl for ElementSrcTest {}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementImpl for ElementSrcTest {
|
2021-01-21 18:21:29 +00:00
|
|
|
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
|
|
|
|
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
|
|
|
|
gst::subclass::ElementMetadata::new(
|
|
|
|
"Thread-sharing Test Src Element",
|
|
|
|
"Generic",
|
|
|
|
"Src Element for Pad Src Test",
|
|
|
|
"François Laignel <fengalin@free.fr>",
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
Some(&*ELEMENT_METADATA)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pad_templates() -> &'static [gst::PadTemplate] {
|
|
|
|
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
|
|
|
|
let caps = gst::Caps::new_any();
|
|
|
|
let src_pad_template = gst::PadTemplate::new(
|
|
|
|
"src",
|
|
|
|
gst::PadDirection::Src,
|
|
|
|
gst::PadPresence::Always,
|
|
|
|
&caps,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
vec![src_pad_template]
|
|
|
|
});
|
|
|
|
|
|
|
|
PAD_TEMPLATES.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn change_state(
|
|
|
|
&self,
|
|
|
|
transition: gst::StateChange,
|
|
|
|
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::log!(SRC_CAT, imp: self, "Changing state {:?}", transition);
|
2020-11-14 17:09:42 +00:00
|
|
|
|
|
|
|
match transition {
|
|
|
|
gst::StateChange::NullToReady => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.prepare().map_err(|err| {
|
|
|
|
self.post_error_message(err);
|
2020-11-14 17:09:42 +00:00
|
|
|
gst::StateChangeError
|
|
|
|
})?;
|
|
|
|
}
|
|
|
|
gst::StateChange::PlayingToPaused => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.pause();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
gst::StateChange::ReadyToNull => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.unprepare();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
_ => (),
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
let mut success = self.parent_change_state(transition)?;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
match transition {
|
|
|
|
gst::StateChange::PausedToReady => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.stop();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
gst::StateChange::PausedToPlaying => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.start();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
gst::StateChange::ReadyToPaused | gst::StateChange::PlayingToPaused => {
|
|
|
|
success = gst::StateChangeSuccess::NoPreroll;
|
|
|
|
}
|
|
|
|
_ => (),
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
Ok(success)
|
|
|
|
}
|
2020-03-05 15:59:13 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn send_event(&self, event: gst::Event) -> bool {
|
2020-11-14 17:09:42 +00:00
|
|
|
match event.view() {
|
|
|
|
EventView::FlushStart(..) => {
|
2022-08-05 12:44:50 +00:00
|
|
|
self.task.flush_start().await_maybe_on_context().unwrap();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
EventView::FlushStop(..) => {
|
2022-08-05 12:44:50 +00:00
|
|
|
self.task.flush_stop().await_maybe_on_context().unwrap();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
_ => (),
|
2020-03-05 15:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
if !event.is_serialized() {
|
|
|
|
self.src_pad.gst_pad().push_event(event)
|
|
|
|
} else {
|
|
|
|
self.try_push(Item::Event(event)).is_ok()
|
|
|
|
}
|
2020-03-05 15:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 22:44:49 +00:00
|
|
|
glib::wrapper! {
|
2020-11-14 17:09:42 +00:00
|
|
|
pub struct ElementSrcTest(ObjectSubclass<imp_src::ElementSrcTest>) @extends gst::Element, gst::Object;
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
// Sink
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
mod imp_sink {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
struct PadSinkTestHandler;
|
|
|
|
|
|
|
|
impl PadSinkHandler for PadSinkTestHandler {
|
|
|
|
type ElementImpl = ElementSinkTest;
|
|
|
|
|
|
|
|
fn sink_chain(
|
2022-10-12 10:35:20 +00:00
|
|
|
self,
|
|
|
|
_pad: PadSinkWeak,
|
|
|
|
elem: super::ElementSinkTest,
|
2020-11-14 17:09:42 +00:00
|
|
|
buffer: gst::Buffer,
|
|
|
|
) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> {
|
|
|
|
async move {
|
2022-10-12 10:35:20 +00:00
|
|
|
let imp = elem.imp();
|
|
|
|
imp.forward_item(Item::Buffer(buffer)).await
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
.boxed()
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn sink_chain_list(
|
2022-10-12 10:35:20 +00:00
|
|
|
self,
|
|
|
|
_pad: PadSinkWeak,
|
|
|
|
elem: super::ElementSinkTest,
|
2020-11-14 17:09:42 +00:00
|
|
|
list: gst::BufferList,
|
|
|
|
) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> {
|
|
|
|
async move {
|
2022-10-12 10:35:20 +00:00
|
|
|
let imp = elem.imp();
|
|
|
|
imp.forward_item(Item::BufferList(list)).await
|
2020-03-05 15:59:13 +00:00
|
|
|
}
|
2020-11-14 17:09:42 +00:00
|
|
|
.boxed()
|
2020-03-15 11:40:45 +00:00
|
|
|
}
|
2020-03-05 15:59:13 +00:00
|
|
|
|
2022-10-12 10:35:20 +00:00
|
|
|
fn sink_event(&self, pad: &PadSinkRef, imp: &ElementSinkTest, event: gst::Event) -> bool {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::debug!(SINK_CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event);
|
2020-11-14 17:09:42 +00:00
|
|
|
|
|
|
|
match event.view() {
|
|
|
|
EventView::FlushStart(..) => {
|
2022-10-12 10:35:20 +00:00
|
|
|
imp.stop();
|
2020-11-14 17:09:42 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
_ => false,
|
2020-03-05 15:59:13 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn sink_event_serialized(
|
2022-10-12 10:35:20 +00:00
|
|
|
self,
|
|
|
|
pad: PadSinkWeak,
|
|
|
|
elem: super::ElementSinkTest,
|
2020-11-14 17:09:42 +00:00
|
|
|
event: gst::Event,
|
|
|
|
) -> BoxFuture<'static, bool> {
|
|
|
|
async move {
|
2022-10-12 10:35:20 +00:00
|
|
|
let pad = pad.upgrade().expect("PadSink no longer exists");
|
|
|
|
gst::log!(SINK_CAT, obj: pad.gst_pad(), "Handling serialized {:?}", event);
|
2020-11-14 17:09:42 +00:00
|
|
|
|
2022-10-12 10:35:20 +00:00
|
|
|
let imp = elem.imp();
|
2020-11-14 17:09:42 +00:00
|
|
|
if let EventView::FlushStop(..) = event.view() {
|
2022-10-12 10:35:20 +00:00
|
|
|
imp.start();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2020-01-06 12:19:11 +00:00
|
|
|
|
2022-10-12 10:35:20 +00:00
|
|
|
imp.forward_item(Item::Event(event)).await.is_ok()
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
.boxed()
|
2020-01-06 12:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ElementSinkTest {
|
|
|
|
sink_pad: PadSink,
|
|
|
|
flushing: AtomicBool,
|
2022-06-27 16:18:22 +00:00
|
|
|
sender: Mutex<Option<mpsc::Sender<Item>>>,
|
2020-01-06 12:19:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementSinkTest {
|
2022-10-09 13:06:59 +00:00
|
|
|
async fn forward_item(&self, item: Item) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2020-11-14 17:09:42 +00:00
|
|
|
if !self.flushing.load(Ordering::SeqCst) {
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SINK_CAT, imp: self, "Fowarding {:?}", item);
|
2022-06-27 16:18:22 +00:00
|
|
|
let mut sender = self
|
|
|
|
.sender
|
2020-11-14 17:09:42 +00:00
|
|
|
.lock()
|
2022-06-27 16:18:22 +00:00
|
|
|
.unwrap()
|
2020-11-14 17:09:42 +00:00
|
|
|
.as_mut()
|
|
|
|
.expect("Item Sender not set")
|
2022-06-27 16:18:22 +00:00
|
|
|
.clone();
|
|
|
|
sender
|
2020-11-14 17:09:42 +00:00
|
|
|
.send(item)
|
|
|
|
.await
|
|
|
|
.map(|_| gst::FlowSuccess::Ok)
|
|
|
|
.map_err(|_| gst::FlowError::Error)
|
|
|
|
} else {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::debug!(
|
2020-11-14 17:09:42 +00:00
|
|
|
SINK_CAT,
|
2022-10-09 13:06:59 +00:00
|
|
|
imp: self,
|
2020-11-14 17:09:42 +00:00
|
|
|
"Not fowarding {:?} due to flushing",
|
|
|
|
item
|
|
|
|
);
|
|
|
|
Err(gst::FlowError::Flushing)
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn start(&self) {
|
|
|
|
gst::debug!(SINK_CAT, imp: self, "Starting");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.flushing.store(false, Ordering::SeqCst);
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SINK_CAT, imp: self, "Started");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn stop(&self) {
|
|
|
|
gst::debug!(SINK_CAT, imp: self, "Stopping");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.flushing.store(true, Ordering::SeqCst);
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SINK_CAT, imp: self, "Stopped");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
pub fn push_flush_start(&self) {
|
|
|
|
gst::debug!(SINK_CAT, imp: self, "Pushing FlushStart");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.sink_pad
|
|
|
|
.gst_pad()
|
|
|
|
.push_event(gst::event::FlushStart::new());
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SINK_CAT, imp: self, "FlushStart pushed");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
pub fn push_flush_stop(&self) {
|
|
|
|
gst::debug!(SINK_CAT, imp: self, "Pushing FlushStop");
|
2020-11-14 17:09:42 +00:00
|
|
|
self.sink_pad
|
|
|
|
.gst_pad()
|
|
|
|
.push_event(gst::event::FlushStop::new(true));
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::debug!(SINK_CAT, imp: self, "FlushStop pushed");
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-22 14:24:55 +00:00
|
|
|
static SINK_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
|
|
|
gst::DebugCategory::new(
|
2020-11-14 17:09:42 +00:00
|
|
|
"ts-element-sink-test",
|
|
|
|
gst::DebugColorFlags::empty(),
|
|
|
|
Some("Thread-sharing Test Sink Element"),
|
2020-11-22 14:24:55 +00:00
|
|
|
)
|
|
|
|
});
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2021-03-07 16:22:24 +00:00
|
|
|
#[glib::object_subclass]
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ObjectSubclass for ElementSinkTest {
|
|
|
|
const NAME: &'static str = "TsElementSinkTest";
|
|
|
|
type Type = super::ElementSinkTest;
|
|
|
|
type ParentType = gst::Element;
|
|
|
|
|
|
|
|
fn with_class(klass: &Self::Class) -> Self {
|
|
|
|
ElementSinkTest {
|
|
|
|
sink_pad: PadSink::new(
|
2021-04-20 12:58:11 +00:00
|
|
|
gst::Pad::from_template(&klass.pad_template("sink").unwrap(), Some("sink")),
|
2020-11-14 17:09:42 +00:00
|
|
|
PadSinkTestHandler,
|
|
|
|
),
|
|
|
|
flushing: AtomicBool::new(true),
|
2022-06-27 16:18:22 +00:00
|
|
|
sender: Mutex::new(None),
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ObjectImpl for ElementSinkTest {
|
2021-01-21 18:21:29 +00:00
|
|
|
fn properties() -> &'static [glib::ParamSpec] {
|
|
|
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
2022-09-05 08:45:47 +00:00
|
|
|
vec![glib::ParamSpecBoxed::builder::<ItemSender>("sender")
|
|
|
|
.nick("Sender")
|
|
|
|
.blurb("Channel sender to forward the incoming items to")
|
|
|
|
.write_only()
|
|
|
|
.construct_only()
|
|
|
|
.build()]
|
2021-01-21 18:21:29 +00:00
|
|
|
});
|
2020-11-14 17:09:42 +00:00
|
|
|
|
2021-01-21 18:21:29 +00:00
|
|
|
PROPERTIES.as_ref()
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
2021-04-12 12:49:54 +00:00
|
|
|
match pspec.name() {
|
2021-01-21 18:21:29 +00:00
|
|
|
"sender" => {
|
2020-11-14 17:09:42 +00:00
|
|
|
let ItemSender { sender } = value
|
|
|
|
.get::<&ItemSender>()
|
|
|
|
.expect("type checked upstream")
|
|
|
|
.clone();
|
2022-06-27 16:18:22 +00:00
|
|
|
*self.sender.lock().unwrap() = Some(sender);
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
|
|
|
_ => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn constructed(&self) {
|
|
|
|
self.parent_constructed();
|
2020-11-14 17:09:42 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
let obj = self.instance();
|
2020-11-14 17:09:42 +00:00
|
|
|
obj.add_pad(self.sink_pad.gst_pad()).unwrap();
|
2022-10-12 10:35:20 +00:00
|
|
|
obj.set_element_flags(gst::ElementFlags::SINK);
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 08:57:31 +00:00
|
|
|
impl GstObjectImpl for ElementSinkTest {}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
impl ElementImpl for ElementSinkTest {
|
2021-01-21 18:21:29 +00:00
|
|
|
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
|
|
|
|
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
|
|
|
|
gst::subclass::ElementMetadata::new(
|
|
|
|
"Thread-sharing Test Sink Element",
|
|
|
|
"Generic",
|
|
|
|
"Sink Element for Pad Test",
|
|
|
|
"François Laignel <fengalin@free.fr>",
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
Some(&*ELEMENT_METADATA)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pad_templates() -> &'static [gst::PadTemplate] {
|
|
|
|
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
|
|
|
|
let caps = gst::Caps::new_any();
|
|
|
|
let sink_pad_template = gst::PadTemplate::new(
|
|
|
|
"sink",
|
|
|
|
gst::PadDirection::Sink,
|
|
|
|
gst::PadPresence::Always,
|
|
|
|
&caps,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
vec![sink_pad_template]
|
|
|
|
});
|
|
|
|
|
|
|
|
PAD_TEMPLATES.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
fn change_state(
|
|
|
|
&self,
|
|
|
|
transition: gst::StateChange,
|
|
|
|
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
|
2022-10-09 13:06:59 +00:00
|
|
|
gst::log!(SINK_CAT, imp: self, "Changing state {:?}", transition);
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
if let gst::StateChange::PausedToReady = transition {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.stop();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
let success = self.parent_change_state(transition)?;
|
2020-01-06 12:19:11 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
if let gst::StateChange::ReadyToPaused = transition {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.start();
|
2020-11-14 17:09:42 +00:00
|
|
|
}
|
2020-01-06 12:19:11 +00:00
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
Ok(success)
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:44:49 +00:00
|
|
|
glib::wrapper! {
|
2020-11-14 17:09:42 +00:00
|
|
|
pub struct ElementSinkTest(ObjectSubclass<imp_sink::ElementSinkTest>) @extends gst::Element, gst::Object;
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:30:07 +00:00
|
|
|
fn setup(
|
|
|
|
context_name: &str,
|
2020-01-06 12:19:11 +00:00
|
|
|
mut middle_element_1: Option<gst::Element>,
|
|
|
|
mut middle_element_2: Option<gst::Element>,
|
2019-12-02 09:30:07 +00:00
|
|
|
) -> (
|
|
|
|
gst::Pipeline,
|
2020-11-14 17:09:42 +00:00
|
|
|
ElementSrcTest,
|
|
|
|
ElementSinkTest,
|
2019-12-02 09:30:07 +00:00
|
|
|
mpsc::Receiver<Item>,
|
|
|
|
) {
|
|
|
|
init();
|
|
|
|
|
2020-01-06 12:19:11 +00:00
|
|
|
let pipeline = gst::Pipeline::new(None);
|
|
|
|
|
2019-12-02 09:30:07 +00:00
|
|
|
// Src
|
2022-10-07 18:07:48 +00:00
|
|
|
let src_element = glib::Object::new::<ElementSrcTest>(&[]);
|
2021-11-08 09:55:40 +00:00
|
|
|
src_element.set_property("context", &context_name);
|
2020-01-06 12:19:11 +00:00
|
|
|
pipeline.add(&src_element).unwrap();
|
|
|
|
|
2020-11-14 17:09:42 +00:00
|
|
|
let mut last_element = src_element.clone().upcast::<gst::Element>();
|
2020-01-06 12:19:11 +00:00
|
|
|
|
|
|
|
if let Some(middle_element) = middle_element_1.take() {
|
|
|
|
pipeline.add(&middle_element).unwrap();
|
|
|
|
last_element.link(&middle_element).unwrap();
|
|
|
|
last_element = middle_element;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(middle_element) = middle_element_2.take() {
|
|
|
|
// Don't link the 2 middle elements: this is used for ts-proxy
|
|
|
|
pipeline.add(&middle_element).unwrap();
|
|
|
|
last_element = middle_element;
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
// Sink
|
2021-01-31 12:44:45 +00:00
|
|
|
let (sender, receiver) = mpsc::channel::<Item>(10);
|
2022-10-07 18:07:48 +00:00
|
|
|
let sink_element = glib::Object::new::<ElementSinkTest>(&[("sender", &ItemSender { sender })]);
|
2020-01-06 12:19:11 +00:00
|
|
|
pipeline.add(&sink_element).unwrap();
|
|
|
|
last_element.link(&sink_element).unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
(pipeline, src_element, sink_element, receiver)
|
|
|
|
}
|
|
|
|
|
2020-01-06 12:19:11 +00:00
|
|
|
fn nominal_scenario(
|
|
|
|
scenario_name: &str,
|
|
|
|
pipeline: gst::Pipeline,
|
2020-11-14 17:09:42 +00:00
|
|
|
src_element: ElementSrcTest,
|
2020-01-06 12:19:11 +00:00
|
|
|
mut receiver: mpsc::Receiver<Item>,
|
|
|
|
) {
|
2022-01-17 17:36:41 +00:00
|
|
|
let elem_src_test = src_element.imp();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
// Initial events
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(scenario_name)
|
2020-01-24 23:20:37 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
2019-11-30 18:51:31 +00:00
|
|
|
.build(),
|
2020-03-05 15:59:13 +00:00
|
|
|
))
|
|
|
|
.unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2019-12-02 09:30:07 +00:00
|
|
|
Item::Event(event) => match event.view() {
|
2020-01-06 12:19:11 +00:00
|
|
|
EventView::StreamStart(_) => (),
|
2019-12-02 09:30:07 +00:00
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-05 15:59:13 +00:00
|
|
|
.unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2019-12-02 09:30:07 +00:00
|
|
|
Item::Event(event) => match event.view() {
|
2020-01-06 12:19:11 +00:00
|
|
|
EventView::Segment(_) => (),
|
2019-12-02 09:30:07 +00:00
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![1, 2, 3, 4])))
|
2020-01-06 12:19:11 +00:00
|
|
|
.unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2019-12-02 09:30:07 +00:00
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// BufferList
|
|
|
|
let mut list = gst::BufferList::new();
|
|
|
|
list.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.add(gst::Buffer::from_slice(vec![1, 2, 3, 4]));
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test.try_push(Item::BufferList(list)).unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2019-12-02 09:30:07 +00:00
|
|
|
Item::BufferList(_) => (),
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pause the Pad task
|
|
|
|
pipeline.set_state(gst::State::Paused).unwrap();
|
|
|
|
|
2020-03-19 18:34:51 +00:00
|
|
|
// Item accepted, but not processed before switching to Playing again
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
2020-03-19 18:34:51 +00:00
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![5, 6, 7])))
|
|
|
|
.unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
// Nothing forwarded
|
|
|
|
receiver.try_next().unwrap_err();
|
|
|
|
|
|
|
|
// Switch back the Pad task to Started
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
2020-03-19 18:34:51 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![5, 6, 7].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
// Flush
|
2020-06-24 22:33:57 +00:00
|
|
|
src_element.send_event(gst::event::FlushStart::new());
|
|
|
|
src_element.send_event(gst::event::FlushStop::new(true));
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2020-01-06 12:19:11 +00:00
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::FlushStop(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
2019-12-02 09:30:07 +00:00
|
|
|
|
2020-03-19 18:34:51 +00:00
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![8, 9])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![8, 9].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:30:07 +00:00
|
|
|
// EOS
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Eos::new()))
|
2020-03-05 15:59:13 +00:00
|
|
|
.unwrap();
|
2020-01-06 12:19:11 +00:00
|
|
|
|
2020-03-05 15:59:13 +00:00
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
2019-12-02 09:30:07 +00:00
|
|
|
Item::Event(event) => match event.view() {
|
2020-01-06 12:19:11 +00:00
|
|
|
EventView::Eos(_) => (),
|
2019-12-02 09:30:07 +00:00
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Ready).unwrap();
|
|
|
|
|
|
|
|
// Receiver was dropped when stopping => can't send anymore
|
2020-03-05 15:59:13 +00:00
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(&format!("{}_past_stop", scenario_name))
|
2020-01-24 23:20:37 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
2019-11-30 18:51:31 +00:00
|
|
|
.build(),
|
2020-03-05 15:59:13 +00:00
|
|
|
))
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
2019-12-02 09:30:07 +00:00
|
|
|
}
|
2020-01-06 12:19:11 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn src_sink_nominal() {
|
|
|
|
let name = "src_sink_nominal";
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
let (pipeline, src_element, _sink_element, receiver) = setup(name, None, None);
|
2020-01-06 12:19:11 +00:00
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
nominal_scenario(name, pipeline, src_element, receiver);
|
2020-01-06 12:19:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 18:34:51 +00:00
|
|
|
#[test]
|
|
|
|
fn src_tsqueue_sink_nominal() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let name = "src_tsqueue_sink";
|
|
|
|
|
|
|
|
let ts_queue = gst::ElementFactory::make("ts-queue", Some("ts-queue")).unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
ts_queue.set_property("context", format!("{}_queue", name));
|
|
|
|
ts_queue.set_property("context-wait", THROTTLING_DURATION.as_millis() as u32);
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
let (pipeline, src_element, _sink_element, receiver) = setup(name, Some(ts_queue), None);
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
nominal_scenario(name, pipeline, src_element, receiver);
|
2020-03-19 18:34:51 +00:00
|
|
|
}
|
2020-01-06 12:19:11 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn src_queue_sink_nominal() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let name = "src_queue_sink";
|
|
|
|
|
|
|
|
let queue = gst::ElementFactory::make("queue", Some("queue")).unwrap();
|
|
|
|
let (pipeline, src_element, _sink_element, receiver) = setup(name, Some(queue), None);
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
nominal_scenario(name, pipeline, src_element, receiver);
|
2020-01-06 12:19:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 18:34:51 +00:00
|
|
|
#[test]
|
|
|
|
fn src_tsproxy_sink_nominal() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let name = "src_tsproxy_sink";
|
|
|
|
|
|
|
|
let ts_proxy_sink = gst::ElementFactory::make("ts-proxysink", Some("ts-proxysink")).unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
ts_proxy_sink.set_property("proxy-context", format!("{}_proxy_context", name));
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
let ts_proxy_src = gst::ElementFactory::make("ts-proxysrc", Some("ts-proxysrc")).unwrap();
|
2021-11-08 09:55:40 +00:00
|
|
|
ts_proxy_src.set_property("proxy-context", format!("{}_proxy_context", name));
|
|
|
|
ts_proxy_src.set_property("context", format!("{}_context", name));
|
|
|
|
ts_proxy_src.set_property("context-wait", THROTTLING_DURATION.as_millis() as u32);
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
let (pipeline, src_element, _sink_element, receiver) =
|
|
|
|
setup(name, Some(ts_proxy_sink), Some(ts_proxy_src));
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
nominal_scenario(name, pipeline, src_element, receiver);
|
2020-03-19 18:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn start_pause_start() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let scenario_name = "start_pause_start";
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
let (pipeline, src_element, _sink_element, mut receiver) = setup(scenario_name, None, None);
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-01-17 17:36:41 +00:00
|
|
|
let elem_src_test = src_element.imp();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
// Initial events
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(scenario_name)
|
2020-03-19 18:34:51 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
|
|
|
.build(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::StreamStart(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![1, 2, 3, 4])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Paused).unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![5, 6, 7])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![5, 6, 7].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing else forwarded
|
|
|
|
receiver.try_next().unwrap_err();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn start_stop_start() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let scenario_name = "start_stop_start";
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
let (pipeline, src_element, _sink_element, mut receiver) = setup(scenario_name, None, None);
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-01-17 17:36:41 +00:00
|
|
|
let elem_src_test = src_element.imp();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
// Initial events
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(&format!("{}-after_stop", scenario_name))
|
2020-03-19 18:34:51 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
|
|
|
.build(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::StreamStart(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![1, 2, 3, 4])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Ready).unwrap();
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
// Initial events again
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(scenario_name)
|
2020-03-19 18:34:51 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
|
|
|
.build(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(_buffer) => {
|
2022-02-21 17:43:46 +00:00
|
|
|
gst::info!(
|
2020-11-14 17:09:42 +00:00
|
|
|
imp_src::SRC_CAT,
|
2020-03-19 18:34:51 +00:00
|
|
|
"{}: initial buffer went through, don't expect any pending item to be dropped",
|
|
|
|
scenario_name
|
|
|
|
);
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::StreamStart(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::StreamStart(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![5, 6, 7])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![5, 6, 7].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn start_flush() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let scenario_name = "start_flush";
|
|
|
|
|
2021-07-30 10:53:35 +00:00
|
|
|
let (pipeline, src_element, sink_element, mut receiver) = setup(scenario_name, None, None);
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-01-17 17:36:41 +00:00
|
|
|
let elem_src_test = src_element.imp();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Playing).unwrap();
|
|
|
|
|
|
|
|
// Initial events
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Event(
|
2020-06-24 22:33:57 +00:00
|
|
|
gst::event::StreamStart::builder(&format!("{}-after_stop", scenario_name))
|
2020-03-19 18:34:51 +00:00
|
|
|
.group_id(gst::GroupId::next())
|
|
|
|
.build(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::StreamStart(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![1, 2, 3, 4])))
|
|
|
|
.unwrap();
|
|
|
|
|
2022-01-17 17:36:41 +00:00
|
|
|
let elem_sink_test = sink_element.imp();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
elem_sink_test.push_flush_start();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![5, 6, 7])))
|
|
|
|
.unwrap_err();
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
elem_sink_test.push_flush_stop();
|
2020-03-19 18:34:51 +00:00
|
|
|
|
|
|
|
elem_src_test
|
2020-06-24 22:33:57 +00:00
|
|
|
.try_push(Item::Event(gst::event::Segment::new(
|
|
|
|
&gst::FormattedSegment::<gst::format::Time>::new(),
|
|
|
|
)))
|
2020-03-19 18:34:51 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
2020-03-26 18:07:25 +00:00
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
// In some cases, the first Buffer might be processed before FlushStart
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Event(event) => match event.view() {
|
|
|
|
EventView::Segment(_) => (),
|
|
|
|
other => panic!("Unexpected event {:?}", other),
|
|
|
|
},
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 18:34:51 +00:00
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post flush buffer
|
|
|
|
elem_src_test
|
|
|
|
.try_push(Item::Buffer(gst::Buffer::from_slice(vec![8, 9])))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match futures::executor::block_on(receiver.next()).unwrap() {
|
|
|
|
Item::Buffer(buffer) => {
|
|
|
|
let data = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(data.as_slice(), vec![8, 9].as_slice());
|
|
|
|
}
|
|
|
|
other => panic!("Unexpected item {:?}", other),
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline.set_state(gst::State::Null).unwrap();
|
|
|
|
}
|