2022-08-16 12:26:24 +00:00
|
|
|
// Copyright (C) 2022 François Laignel <fengalin@free.fr>
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
use futures::future::BoxFuture;
|
|
|
|
use futures::prelude::*;
|
|
|
|
|
2022-08-19 17:40:05 +00:00
|
|
|
use gst::error_msg;
|
2022-08-16 12:26:24 +00:00
|
|
|
use gst::glib;
|
|
|
|
use gst::prelude::*;
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
use gst::EventView;
|
|
|
|
|
2024-01-31 15:07:56 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
use gstthreadshare::runtime::prelude::*;
|
2022-10-24 11:15:13 +00:00
|
|
|
use gstthreadshare::runtime::{Context, PadSink, Task};
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
use std::sync::Mutex;
|
2022-10-15 18:13:32 +00:00
|
|
|
use std::time::Duration;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
use super::super::{Settings, Stats, CAT};
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-08-19 17:40:05 +00:00
|
|
|
enum StreamItem {
|
2022-08-16 12:26:24 +00:00
|
|
|
Buffer(gst::Buffer),
|
|
|
|
Event(gst::Event),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
2022-10-15 18:13:32 +00:00
|
|
|
struct TaskPadSinkHandler;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl PadSinkHandler for TaskPadSinkHandler {
|
|
|
|
type ElementImpl = TaskSink;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
fn sink_chain(
|
2022-10-12 10:35:20 +00:00
|
|
|
self,
|
2022-10-24 11:15:13 +00:00
|
|
|
_pad: gst::Pad,
|
2022-10-15 18:13:32 +00:00
|
|
|
elem: super::TaskSink,
|
2022-08-16 12:26:24 +00:00
|
|
|
buffer: gst::Buffer,
|
|
|
|
) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> {
|
2022-10-12 10:35:20 +00:00
|
|
|
let sender = elem.imp().clone_item_sender();
|
2022-08-16 12:26:24 +00:00
|
|
|
async move {
|
2022-08-19 17:40:05 +00:00
|
|
|
if sender.send_async(StreamItem::Buffer(buffer)).await.is_err() {
|
2022-08-16 12:26:24 +00:00
|
|
|
return Err(gst::FlowError::Flushing);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(gst::FlowSuccess::Ok)
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn sink_event_serialized(
|
2022-10-12 10:35:20 +00:00
|
|
|
self,
|
2022-10-24 11:15:13 +00:00
|
|
|
_pad: gst::Pad,
|
2022-10-15 18:13:32 +00:00
|
|
|
elem: super::TaskSink,
|
2022-08-16 12:26:24 +00:00
|
|
|
event: gst::Event,
|
|
|
|
) -> BoxFuture<'static, bool> {
|
2022-10-12 10:35:20 +00:00
|
|
|
let sender = elem.imp().clone_item_sender();
|
2022-08-16 12:26:24 +00:00
|
|
|
async move {
|
2022-10-15 18:13:32 +00:00
|
|
|
match event.view() {
|
|
|
|
EventView::Segment(_) => {
|
|
|
|
let _ = sender.send_async(StreamItem::Event(event)).await;
|
|
|
|
}
|
|
|
|
EventView::Eos(_) => {
|
|
|
|
let is_main_elem = elem.imp().settings.lock().unwrap().is_main_elem;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, obj = elem, "EOS");
|
2022-10-15 18:13:32 +00:00
|
|
|
|
|
|
|
// When each element sends its own EOS message,
|
|
|
|
// it takes ages for the pipeline to process all of them.
|
|
|
|
// Let's just post an error message and let main shuts down
|
|
|
|
// after all streams have posted this message.
|
|
|
|
let _ = elem
|
|
|
|
.post_message(gst::message::Error::new(gst::LibraryError::Shutdown, "EOS"));
|
|
|
|
}
|
|
|
|
EventView::FlushStop(_) => {
|
|
|
|
let imp = elem.imp();
|
|
|
|
return imp.task.flush_stop().await_maybe_on_context().is_ok();
|
|
|
|
}
|
|
|
|
EventView::SinkMessage(evt) => {
|
|
|
|
let _ = elem.post_message(evt.message());
|
|
|
|
}
|
|
|
|
_ => (),
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
fn sink_event(self, _pad: &gst::Pad, imp: &TaskSink, event: gst::Event) -> bool {
|
2022-08-16 12:26:24 +00:00
|
|
|
if let EventView::FlushStart(..) = event.view() {
|
2022-10-12 10:35:20 +00:00
|
|
|
return imp.task.flush_start().await_maybe_on_context().is_ok();
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
struct TaskSinkTask {
|
|
|
|
elem: super::TaskSink,
|
|
|
|
item_receiver: flume::Receiver<StreamItem>,
|
|
|
|
is_main_elem: bool,
|
2022-08-19 17:40:05 +00:00
|
|
|
last_dts: Option<gst::ClockTime>,
|
2022-10-15 18:13:32 +00:00
|
|
|
segment_start: Option<gst::ClockTime>,
|
|
|
|
stats: Option<Box<Stats>>,
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl TaskSinkTask {
|
|
|
|
fn new(
|
|
|
|
elem: &super::TaskSink,
|
|
|
|
item_receiver: flume::Receiver<StreamItem>,
|
|
|
|
is_main_elem: bool,
|
|
|
|
stats: Option<Box<Stats>>,
|
|
|
|
) -> Self {
|
|
|
|
TaskSinkTask {
|
|
|
|
elem: elem.clone(),
|
|
|
|
item_receiver,
|
|
|
|
is_main_elem,
|
2022-08-19 17:40:05 +00:00
|
|
|
last_dts: None,
|
2022-10-15 18:13:32 +00:00
|
|
|
stats,
|
|
|
|
segment_start: None,
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
fn flush(&mut self) {
|
2022-08-16 12:26:24 +00:00
|
|
|
// Purge the channel
|
2022-10-15 18:13:32 +00:00
|
|
|
while !self.item_receiver.is_empty() {}
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl TaskImpl for TaskSinkTask {
|
2022-08-19 17:40:05 +00:00
|
|
|
type Item = StreamItem;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
fn prepare(&mut self) -> BoxFuture<'_, Result<(), gst::ErrorMessage>> {
|
2024-07-08 08:03:11 +00:00
|
|
|
log_or_trace!(CAT, self.is_main_elem, obj = self.elem, "Preparing Task");
|
2022-10-15 18:13:32 +00:00
|
|
|
future::ok(()).boxed()
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn start(&mut self) -> BoxFuture<'_, Result<(), gst::ErrorMessage>> {
|
|
|
|
async {
|
2024-07-08 08:03:11 +00:00
|
|
|
log_or_trace!(CAT, self.is_main_elem, obj = self.elem, "Starting Task");
|
2022-10-15 18:13:32 +00:00
|
|
|
self.last_dts = None;
|
|
|
|
if let Some(stats) = self.stats.as_mut() {
|
|
|
|
stats.start();
|
2022-08-19 17:40:05 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 12:26:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn stop(&mut self) -> BoxFuture<'_, Result<(), gst::ErrorMessage>> {
|
|
|
|
async {
|
2024-07-08 08:03:11 +00:00
|
|
|
log_or_trace!(CAT, self.is_main_elem, obj = self.elem, "Stopping Task");
|
2022-10-15 18:13:32 +00:00
|
|
|
self.flush();
|
2022-08-16 12:26:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
|
2022-08-19 17:40:05 +00:00
|
|
|
fn try_next(&mut self) -> BoxFuture<'_, Result<StreamItem, gst::FlowError>> {
|
2022-10-15 18:13:32 +00:00
|
|
|
self.item_receiver
|
|
|
|
.recv_async()
|
|
|
|
.map(|opt_item| Ok(opt_item.unwrap()))
|
|
|
|
.boxed()
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-08-19 17:40:05 +00:00
|
|
|
fn handle_item(&mut self, item: StreamItem) -> BoxFuture<'_, Result<(), gst::FlowError>> {
|
2022-08-16 12:26:24 +00:00
|
|
|
async move {
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, self.is_main_elem, obj = self.elem, "Received {item:?}");
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
match item {
|
2022-08-19 17:40:05 +00:00
|
|
|
StreamItem::Buffer(buffer) => {
|
2022-10-15 18:13:32 +00:00
|
|
|
let dts = buffer
|
|
|
|
.dts()
|
|
|
|
.expect("Buffer without dts")
|
|
|
|
.checked_sub(self.segment_start.expect("Buffer without Time Segment"))
|
|
|
|
.expect("dts before Segment start");
|
2022-08-19 17:40:05 +00:00
|
|
|
|
|
|
|
if let Some(last_dts) = self.last_dts {
|
2022-10-15 18:13:32 +00:00
|
|
|
let cur_ts = self.elem.current_running_time().unwrap();
|
2022-08-19 17:40:05 +00:00
|
|
|
let latency: Duration = (cur_ts - dts).into();
|
|
|
|
let interval: Duration = (dts - last_dts).into();
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
if let Some(stats) = self.stats.as_mut() {
|
|
|
|
stats.add_buffer(latency, interval);
|
2022-08-19 17:40:05 +00:00
|
|
|
}
|
2022-10-15 18:13:32 +00:00
|
|
|
|
|
|
|
debug_or_trace!(
|
|
|
|
CAT,
|
|
|
|
self.is_main_elem,
|
2024-07-08 08:03:11 +00:00
|
|
|
obj = self.elem,
|
2022-10-15 18:13:32 +00:00
|
|
|
"o latency {latency:.2?}",
|
|
|
|
);
|
|
|
|
debug_or_trace!(
|
|
|
|
CAT,
|
|
|
|
self.is_main_elem,
|
2024-07-08 08:03:11 +00:00
|
|
|
obj = self.elem,
|
2022-10-15 18:13:32 +00:00
|
|
|
"o interval {interval:.2?}",
|
|
|
|
);
|
2022-08-19 17:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.last_dts = Some(dts);
|
|
|
|
|
2024-07-08 08:03:11 +00:00
|
|
|
log_or_trace!(CAT, self.is_main_elem, obj = self.elem, "Buffer processed");
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
2022-10-15 18:13:32 +00:00
|
|
|
StreamItem::Event(evt) => {
|
|
|
|
if let EventView::Segment(evt) = evt.view() {
|
|
|
|
if let Some(time_seg) = evt.segment().downcast_ref::<gst::ClockTime>() {
|
|
|
|
self.segment_start = time_seg.start();
|
2022-08-19 17:40:05 +00:00
|
|
|
}
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
2022-10-15 18:13:32 +00:00
|
|
|
}
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-10-15 18:13:32 +00:00
|
|
|
pub struct TaskSink {
|
2022-08-16 12:26:24 +00:00
|
|
|
sink_pad: PadSink,
|
|
|
|
task: Task,
|
2022-08-19 17:40:05 +00:00
|
|
|
item_sender: Mutex<Option<flume::Sender<StreamItem>>>,
|
2022-08-16 12:26:24 +00:00
|
|
|
settings: Mutex<Settings>,
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl TaskSink {
|
2022-08-16 12:26:24 +00:00
|
|
|
#[track_caller]
|
2022-08-19 17:40:05 +00:00
|
|
|
fn clone_item_sender(&self) -> flume::Sender<StreamItem> {
|
2022-08-16 12:26:24 +00:00
|
|
|
self.item_sender.lock().unwrap().as_ref().unwrap().clone()
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn prepare(&self) -> Result<(), gst::ErrorMessage> {
|
2022-10-15 18:13:32 +00:00
|
|
|
let settings = self.settings.lock().unwrap();
|
|
|
|
let stats = if settings.logs_stats {
|
|
|
|
Some(Box::new(Stats::new(
|
|
|
|
settings.max_buffers,
|
|
|
|
settings.push_period + settings.context_wait / 2,
|
|
|
|
)))
|
2022-08-19 17:40:05 +00:00
|
|
|
} else {
|
2022-10-15 18:13:32 +00:00
|
|
|
None
|
|
|
|
};
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, settings.is_main_elem, imp = self, "Preparing");
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
let ts_ctx = Context::acquire(&settings.context, settings.context_wait).map_err(|err| {
|
|
|
|
error_msg!(
|
|
|
|
gst::ResourceError::OpenWrite,
|
|
|
|
["Failed to acquire Context: {}", err]
|
|
|
|
)
|
|
|
|
})?;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
// Enable backpressure for items
|
|
|
|
let (item_sender, item_receiver) = flume::bounded(0);
|
2022-10-15 18:13:32 +00:00
|
|
|
let task_impl = TaskSinkTask::new(&self.obj(), item_receiver, settings.is_main_elem, stats);
|
|
|
|
self.task.prepare(task_impl, ts_ctx).block_on()?;
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
*self.item_sender.lock().unwrap() = Some(item_sender);
|
|
|
|
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, settings.is_main_elem, imp = self, "Prepared");
|
2022-08-16 12:26:24 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn unprepare(&self) {
|
2022-10-15 18:13:32 +00:00
|
|
|
let is_main_elem = self.settings.lock().unwrap().is_main_elem;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Unpreparing");
|
2022-08-16 12:26:24 +00:00
|
|
|
self.task.unprepare().block_on().unwrap();
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Unprepared");
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn stop(&self) -> Result<(), gst::ErrorMessage> {
|
2022-10-15 18:13:32 +00:00
|
|
|
let is_main_elem = self.settings.lock().unwrap().is_main_elem;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Stopping");
|
2022-08-16 12:26:24 +00:00
|
|
|
self.task.stop().block_on()?;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Stopped");
|
2022-08-19 17:40:05 +00:00
|
|
|
|
2022-08-16 12:26:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn start(&self) -> Result<(), gst::ErrorMessage> {
|
2022-10-15 18:13:32 +00:00
|
|
|
let is_main_elem = self.settings.lock().unwrap().is_main_elem;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Starting");
|
2022-08-16 12:26:24 +00:00
|
|
|
self.task.start().block_on()?;
|
2024-07-08 08:03:11 +00:00
|
|
|
debug_or_trace!(CAT, is_main_elem, imp = self, "Started");
|
2022-08-19 17:40:05 +00:00
|
|
|
|
2022-08-16 12:26:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
2022-10-15 18:13:32 +00:00
|
|
|
impl ObjectSubclass for TaskSink {
|
|
|
|
const NAME: &'static str = "TsStandaloneTaskSink";
|
|
|
|
type Type = super::TaskSink;
|
2022-08-16 12:26:24 +00:00
|
|
|
type ParentType = gst::Element;
|
|
|
|
|
|
|
|
fn with_class(klass: &Self::Class) -> Self {
|
|
|
|
Self {
|
|
|
|
sink_pad: PadSink::new(
|
2023-05-10 15:02:08 +00:00
|
|
|
gst::Pad::from_template(&klass.pad_template("sink").unwrap()),
|
2022-10-15 18:13:32 +00:00
|
|
|
TaskPadSinkHandler,
|
2022-08-16 12:26:24 +00:00
|
|
|
),
|
|
|
|
task: Task::default(),
|
|
|
|
item_sender: Default::default(),
|
|
|
|
settings: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl ObjectImpl for TaskSink {
|
2022-08-16 12:26:24 +00:00
|
|
|
fn properties() -> &'static [glib::ParamSpec] {
|
2022-10-15 18:13:32 +00:00
|
|
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(Settings::properties);
|
2022-08-16 12:26:24 +00:00
|
|
|
PROPERTIES.as_ref()
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
|
|
|
self.settings.lock().unwrap().set_property(id, value, pspec);
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
|
|
|
self.settings.lock().unwrap().property(id, pspec)
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
fn constructed(&self) {
|
|
|
|
self.parent_constructed();
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2022-10-23 20:03:22 +00:00
|
|
|
let obj = self.obj();
|
2022-08-16 12:26:24 +00:00
|
|
|
obj.add_pad(self.sink_pad.gst_pad()).unwrap();
|
2022-10-09 13:06:59 +00:00
|
|
|
obj.set_element_flags(gst::ElementFlags::SINK);
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl GstObjectImpl for TaskSink {}
|
2022-08-16 12:26:24 +00:00
|
|
|
|
2022-10-15 18:13:32 +00:00
|
|
|
impl ElementImpl for TaskSink {
|
2022-08-16 12:26:24 +00:00
|
|
|
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
|
|
|
|
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
|
|
|
|
gst::subclass::ElementMetadata::new(
|
2022-10-15 18:13:32 +00:00
|
|
|
"Thread-sharing standalone test task sink",
|
2022-08-16 12:26:24 +00:00
|
|
|
"Sink/Test",
|
2022-10-15 18:13:32 +00:00
|
|
|
"Thread-sharing standalone test task sink",
|
2022-08-16 12:26:24 +00:00
|
|
|
"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()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn change_state(
|
|
|
|
&self,
|
|
|
|
transition: gst::StateChange,
|
|
|
|
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
|
2024-07-08 08:03:11 +00:00
|
|
|
gst::trace!(CAT, imp = self, "Changing state {transition:?}");
|
2022-08-16 12:26:24 +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);
|
2022-08-16 12:26:24 +00:00
|
|
|
gst::StateChangeError
|
|
|
|
})?;
|
|
|
|
}
|
|
|
|
gst::StateChange::ReadyToPaused => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.start().map_err(|_| gst::StateChangeError)?;
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
gst::StateChange::PausedToReady => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.stop().map_err(|_| gst::StateChangeError)?;
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
gst::StateChange::ReadyToNull => {
|
2022-10-09 13:06:59 +00:00
|
|
|
self.unprepare();
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
2022-10-09 13:06:59 +00:00
|
|
|
self.parent_change_state(transition)
|
2022-08-16 12:26:24 +00:00
|
|
|
}
|
|
|
|
}
|