2017-07-07 11:47:28 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Element;
|
2017-07-05 08:09:49 +00:00
|
|
|
|
2020-01-22 17:38:13 +00:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::ClockTime;
|
|
|
|
use crate::ElementFlags;
|
|
|
|
use crate::Event;
|
|
|
|
use crate::Format;
|
|
|
|
use crate::FormattedValue;
|
|
|
|
use crate::GenericFormattedValue;
|
|
|
|
use crate::Pad;
|
|
|
|
use crate::PadTemplate;
|
|
|
|
use crate::Plugin;
|
|
|
|
use crate::QueryRef;
|
|
|
|
use crate::Rank;
|
|
|
|
use crate::SpecificFormattedValue;
|
|
|
|
use crate::State;
|
|
|
|
use crate::StateChange;
|
|
|
|
use crate::StateChangeError;
|
|
|
|
use crate::StateChangeReturn;
|
|
|
|
use crate::StateChangeSuccess;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-01-16 11:32:58 +00:00
|
|
|
use glib::object::Cast;
|
2019-01-16 13:23:53 +00:00
|
|
|
use glib::object::IsA;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib::translate::FromGlibPtrBorrow;
|
2018-07-27 10:36:40 +00:00
|
|
|
use glib::translate::{
|
|
|
|
from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrContainer, ToGlib, ToGlibPtr,
|
|
|
|
};
|
2017-07-05 08:09:49 +00:00
|
|
|
|
2017-08-17 09:48:54 +00:00
|
|
|
use std::ffi::CStr;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-01-20 09:59:13 +00:00
|
|
|
use std::future::Future;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-01-20 09:59:13 +00:00
|
|
|
use std::marker::Unpin;
|
2017-11-11 10:21:55 +00:00
|
|
|
use std::mem;
|
2020-01-05 02:38:55 +00:00
|
|
|
use std::num::NonZeroU64;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-01-20 09:59:13 +00:00
|
|
|
use std::pin::Pin;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2017-07-05 08:09:49 +00:00
|
|
|
impl Element {
|
|
|
|
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2019-04-10 13:30:26 +00:00
|
|
|
for e in elements.windows(2) {
|
2017-07-05 08:09:49 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::glib_result_from_gboolean!(
|
|
|
|
ffi::gst_element_link(
|
2019-04-10 13:30:26 +00:00
|
|
|
e[0].as_ref().to_glib_none().0,
|
|
|
|
e[1].as_ref().to_glib_none().0,
|
2019-01-25 17:15:01 +00:00
|
|
|
),
|
|
|
|
"Failed to link elements"
|
|
|
|
)?;
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
Ok(())
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unlink_many<E: IsA<Element>>(elements: &[&E]) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2019-04-10 13:30:26 +00:00
|
|
|
for e in elements.windows(2) {
|
2017-07-05 08:09:49 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_unlink(
|
2019-04-10 13:30:26 +00:00
|
|
|
e[0].as_ref().to_glib_none().0,
|
|
|
|
e[1].as_ref().to_glib_none().0,
|
|
|
|
);
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-04 05:22:58 +00:00
|
|
|
|
|
|
|
pub fn register(
|
|
|
|
plugin: Option<&Plugin>,
|
|
|
|
name: &str,
|
|
|
|
rank: Rank,
|
|
|
|
type_: glib::types::Type,
|
|
|
|
) -> Result<(), glib::error::BoolError> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::glib_result_from_gboolean!(
|
|
|
|
ffi::gst_element_register(
|
2019-06-04 05:22:58 +00:00
|
|
|
plugin.to_glib_none().0,
|
|
|
|
name.to_glib_none().0,
|
|
|
|
rank.to_glib() as u32,
|
|
|
|
type_.to_glib()
|
|
|
|
),
|
|
|
|
"Failed to register element factory"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
2017-07-29 13:04:34 +00:00
|
|
|
|
2017-11-26 21:50:39 +00:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
|
2017-09-15 16:00:51 +00:00
|
|
|
pub enum ElementMessageType {
|
|
|
|
Error,
|
|
|
|
Warning,
|
|
|
|
Info,
|
|
|
|
}
|
|
|
|
|
2018-01-25 19:06:39 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2020-01-05 02:38:55 +00:00
|
|
|
pub struct NotifyWatchId(NonZeroU64);
|
2017-10-27 15:55:48 +00:00
|
|
|
|
|
|
|
impl ToGlib for NotifyWatchId {
|
|
|
|
type GlibType = libc::c_ulong;
|
|
|
|
|
|
|
|
fn to_glib(&self) -> libc::c_ulong {
|
2020-01-05 02:38:55 +00:00
|
|
|
self.0.get() as libc::c_ulong
|
2017-10-27 15:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromGlib<libc::c_ulong> for NotifyWatchId {
|
|
|
|
fn from_glib(val: libc::c_ulong) -> NotifyWatchId {
|
|
|
|
skip_assert_initialized!();
|
2018-01-25 19:06:39 +00:00
|
|
|
assert_ne!(val, 0);
|
2020-01-05 02:38:55 +00:00
|
|
|
NotifyWatchId(unsafe { NonZeroU64::new_unchecked(val as u64) })
|
2017-10-27 15:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait ElementExtManual: 'static {
|
2020-11-07 10:49:19 +00:00
|
|
|
fn get_element_class(&self) -> &glib::Class<Element>;
|
2018-11-18 12:20:16 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn change_state(&self, transition: StateChange)
|
|
|
|
-> Result<StateChangeSuccess, StateChangeError>;
|
|
|
|
fn continue_state(
|
|
|
|
&self,
|
|
|
|
ret: StateChangeReturn,
|
|
|
|
) -> Result<StateChangeSuccess, StateChangeError>;
|
|
|
|
|
|
|
|
fn get_state(
|
|
|
|
&self,
|
|
|
|
timeout: ClockTime,
|
|
|
|
) -> (Result<StateChangeSuccess, StateChangeError>, State, State);
|
|
|
|
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError>;
|
|
|
|
|
2017-07-29 13:04:34 +00:00
|
|
|
fn query(&self, query: &mut QueryRef) -> bool;
|
2017-08-01 12:58:50 +00:00
|
|
|
|
|
|
|
fn send_event(&self, event: Event) -> bool;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
|
|
|
fn get_pad_template(&self, name: &str) -> Option<PadTemplate>;
|
|
|
|
fn get_pad_template_list(&self) -> Vec<PadTemplate>;
|
2017-09-15 16:00:51 +00:00
|
|
|
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn message_full<T: crate::MessageErrorDomain>(
|
2017-09-15 16:00:51 +00:00
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
2017-11-11 15:12:26 +00:00
|
|
|
line: u32,
|
2017-09-15 16:00:51 +00:00
|
|
|
);
|
2018-07-20 07:21:06 +00:00
|
|
|
|
2019-05-11 10:13:33 +00:00
|
|
|
fn set_element_flags(&self, flags: ElementFlags);
|
|
|
|
|
2019-05-11 12:51:33 +00:00
|
|
|
fn unset_element_flags(&self, flags: ElementFlags);
|
|
|
|
|
2019-05-11 10:13:33 +00:00
|
|
|
fn get_element_flags(&self) -> ElementFlags;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn message_full_with_details<T: crate::MessageErrorDomain>(
|
2017-09-15 16:00:51 +00:00
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
2017-11-11 15:12:26 +00:00
|
|
|
line: u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
structure: crate::Structure,
|
2017-09-15 16:00:51 +00:00
|
|
|
);
|
2017-09-17 15:41:02 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn post_message(&self, message: crate::Message) -> Result<(), glib::error::BoolError>;
|
|
|
|
fn post_error_message(&self, msg: crate::ErrorMessage);
|
2017-12-20 17:52:57 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_pads(&self) -> crate::Iterator<Pad>;
|
|
|
|
fn iterate_sink_pads(&self) -> crate::Iterator<Pad>;
|
|
|
|
fn iterate_src_pads(&self) -> crate::Iterator<Pad>;
|
2017-10-25 10:48:01 +00:00
|
|
|
|
|
|
|
fn get_pads(&self) -> Vec<Pad>;
|
|
|
|
fn get_sink_pads(&self) -> Vec<Pad>;
|
|
|
|
fn get_src_pads(&self) -> Vec<Pad>;
|
2017-10-27 15:55:48 +00:00
|
|
|
|
2019-09-03 14:14:47 +00:00
|
|
|
fn num_pads(&self) -> u16;
|
|
|
|
fn num_sink_pads(&self) -> u16;
|
|
|
|
fn num_src_pads(&self) -> u16;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn add_property_deep_notify_watch(
|
2017-10-27 15:55:48 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
property_name: Option<&str>,
|
2017-10-27 15:55:48 +00:00
|
|
|
include_value: bool,
|
|
|
|
) -> NotifyWatchId;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn add_property_notify_watch(
|
2017-10-27 15:55:48 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
property_name: Option<&str>,
|
2017-10-27 15:55:48 +00:00
|
|
|
include_value: bool,
|
|
|
|
) -> NotifyWatchId;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2017-10-27 15:55:48 +00:00
|
|
|
fn remove_property_notify_watch(&self, watch_id: NotifyWatchId);
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<U>;
|
|
|
|
fn query_convert_generic<V: Into<GenericFormattedValue>>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
|
|
|
) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_position<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn seek<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
rate: f64,
|
2020-11-21 13:46:48 +00:00
|
|
|
flags: crate::SeekFlags,
|
|
|
|
start_type: crate::SeekType,
|
2017-11-11 10:21:55 +00:00
|
|
|
start: V,
|
2020-11-21 13:46:48 +00:00
|
|
|
stop_type: crate::SeekType,
|
2017-11-11 10:21:55 +00:00
|
|
|
stop: V,
|
|
|
|
) -> Result<(), glib::error::BoolError>;
|
2017-12-09 16:20:21 +00:00
|
|
|
fn seek_simple<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
seek_flags: crate::SeekFlags,
|
2017-11-11 10:21:55 +00:00
|
|
|
seek_pos: V,
|
|
|
|
) -> Result<(), glib::error::BoolError>;
|
2018-03-14 13:42:17 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2018-03-14 13:42:17 +00:00
|
|
|
fn call_async<F>(&self, func: F)
|
|
|
|
where
|
|
|
|
F: FnOnce(&Self) + Send + 'static;
|
2020-01-20 09:59:13 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-01-20 09:59:13 +00:00
|
|
|
fn call_async_future<F, T>(
|
|
|
|
&self,
|
|
|
|
func: F,
|
|
|
|
) -> Pin<Box<dyn Future<Output = T> + Unpin + Send + 'static>>
|
|
|
|
where
|
|
|
|
F: FnOnce(&Self) -> T + Send + 'static,
|
|
|
|
T: Send + 'static;
|
2020-04-11 17:02:41 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn get_current_running_time(&self) -> crate::ClockTime;
|
|
|
|
fn get_current_clock_time(&self) -> crate::ClockTime;
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<Element>> ElementExtManual for O {
|
2020-11-07 10:49:19 +00:00
|
|
|
fn get_element_class(&self) -> &glib::Class<Element> {
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let klass = (*(self.as_ptr() as *mut glib::gobject_ffi::GTypeInstance)).g_class
|
2020-11-07 10:49:19 +00:00
|
|
|
as *const glib::Class<Element>;
|
2018-11-18 12:20:16 +00:00
|
|
|
&*klass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn change_state(
|
|
|
|
&self,
|
|
|
|
transition: StateChange,
|
|
|
|
) -> Result<StateChangeSuccess, StateChangeError> {
|
|
|
|
let ret: StateChangeReturn = unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_change_state(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-01-08 16:13:37 +00:00
|
|
|
transition.to_glib(),
|
|
|
|
))
|
|
|
|
};
|
|
|
|
ret.into_result()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn continue_state(
|
|
|
|
&self,
|
|
|
|
ret: StateChangeReturn,
|
|
|
|
) -> Result<StateChangeSuccess, StateChangeError> {
|
|
|
|
let ret: StateChangeReturn = unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_continue_state(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-01-08 16:13:37 +00:00
|
|
|
ret.to_glib(),
|
|
|
|
))
|
|
|
|
};
|
|
|
|
ret.into_result()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_state(
|
|
|
|
&self,
|
|
|
|
timeout: ClockTime,
|
|
|
|
) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut state = mem::MaybeUninit::uninit();
|
|
|
|
let mut pending = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-07-11 12:34:28 +00:00
|
|
|
state.as_mut_ptr(),
|
|
|
|
pending.as_mut_ptr(),
|
2019-01-08 16:13:37 +00:00
|
|
|
timeout.to_glib(),
|
|
|
|
));
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
ret.into_result(),
|
|
|
|
from_glib(state.assume_init()),
|
|
|
|
from_glib(pending.assume_init()),
|
|
|
|
)
|
2019-01-08 16:13:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
|
|
|
|
let ret: StateChangeReturn = unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_set_state(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-01-08 16:13:37 +00:00
|
|
|
state.to_glib(),
|
|
|
|
))
|
|
|
|
};
|
|
|
|
ret.into_result()
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:04:34 +00:00
|
|
|
fn query(&self, query: &mut QueryRef) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_query(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-01 12:58:50 +00:00
|
|
|
|
|
|
|
fn send_event(&self, event: Event) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_send_event(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-08-02 16:41:33 +00:00
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
|
2018-11-18 12:20:16 +00:00
|
|
|
self.get_element_class().get_metadata(key)
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_pad_template(&self, name: &str) -> Option<PadTemplate> {
|
2018-11-18 12:20:16 +00:00
|
|
|
self.get_element_class().get_pad_template(name)
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_pad_template_list(&self) -> Vec<PadTemplate> {
|
2018-11-18 12:20:16 +00:00
|
|
|
self.get_element_class().get_pad_template_list()
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
2017-09-15 16:00:51 +00:00
|
|
|
|
2019-05-11 10:13:33 +00:00
|
|
|
fn set_element_flags(&self, flags: ElementFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2019-05-11 10:13:33 +00:00
|
|
|
(*ptr).flags |= flags.to_glib();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:51:33 +00:00
|
|
|
fn unset_element_flags(&self, flags: ElementFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2019-05-11 12:51:33 +00:00
|
|
|
(*ptr).flags &= !flags.to_glib();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 10:13:33 +00:00
|
|
|
fn get_element_flags(&self) -> ElementFlags {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2019-05-11 10:13:33 +00:00
|
|
|
from_glib((*ptr).flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn message_full<T: crate::MessageErrorDomain>(
|
2017-09-15 16:00:51 +00:00
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
2017-11-11 15:12:26 +00:00
|
|
|
line: u32,
|
2017-09-15 16:00:51 +00:00
|
|
|
) {
|
|
|
|
unsafe {
|
|
|
|
let type_ = match type_ {
|
2020-11-21 13:46:48 +00:00
|
|
|
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
|
|
|
|
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
|
|
|
|
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
|
2017-09-15 16:00:51 +00:00
|
|
|
};
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_message_full(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-09-15 16:00:51 +00:00
|
|
|
type_,
|
2018-07-30 08:46:40 +00:00
|
|
|
T::domain().to_glib(),
|
2017-09-15 16:00:51 +00:00
|
|
|
code.code(),
|
|
|
|
message.to_glib_full(),
|
|
|
|
debug.to_glib_full(),
|
|
|
|
file.to_glib_none().0,
|
|
|
|
function.to_glib_none().0,
|
2017-11-11 15:12:26 +00:00
|
|
|
line as i32,
|
2017-09-15 16:00:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn message_full_with_details<T: crate::MessageErrorDomain>(
|
2017-09-15 16:00:51 +00:00
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
2017-11-11 15:12:26 +00:00
|
|
|
line: u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
structure: crate::Structure,
|
2017-09-15 16:00:51 +00:00
|
|
|
) {
|
|
|
|
unsafe {
|
|
|
|
let type_ = match type_ {
|
2020-11-21 13:46:48 +00:00
|
|
|
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
|
|
|
|
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
|
|
|
|
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
|
2017-09-15 16:00:51 +00:00
|
|
|
};
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_message_full_with_details(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-09-15 16:00:51 +00:00
|
|
|
type_,
|
2018-07-30 08:46:40 +00:00
|
|
|
T::domain().to_glib(),
|
2017-09-15 16:00:51 +00:00
|
|
|
code.code(),
|
|
|
|
message.to_glib_full(),
|
|
|
|
debug.to_glib_full(),
|
|
|
|
file.to_glib_none().0,
|
|
|
|
function.to_glib_none().0,
|
2017-11-11 15:12:26 +00:00
|
|
|
line as i32,
|
2017-09-15 16:00:51 +00:00
|
|
|
structure.into_ptr(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn post_message(&self, message: crate::Message) -> Result<(), glib::error::BoolError> {
|
2020-06-30 20:51:15 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::glib_result_from_gboolean!(
|
|
|
|
ffi::gst_element_post_message(self.as_ref().to_glib_none().0, message.into_ptr()),
|
2020-06-30 20:51:15 +00:00
|
|
|
"Failed to post message"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn post_error_message(&self, msg: crate::ErrorMessage) {
|
|
|
|
let crate::ErrorMessage {
|
2017-12-20 17:52:57 +00:00
|
|
|
error_domain,
|
|
|
|
error_code,
|
|
|
|
ref message,
|
|
|
|
ref debug,
|
|
|
|
filename,
|
|
|
|
function,
|
|
|
|
line,
|
2020-06-30 20:51:15 +00:00
|
|
|
} = msg;
|
2017-12-20 17:52:57 +00:00
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_message_full(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::GST_MESSAGE_ERROR,
|
2018-07-30 08:46:40 +00:00
|
|
|
error_domain.to_glib(),
|
2017-12-20 17:52:57 +00:00
|
|
|
error_code,
|
|
|
|
message.to_glib_full(),
|
|
|
|
debug.to_glib_full(),
|
|
|
|
filename.to_glib_none().0,
|
|
|
|
function.to_glib_none().0,
|
|
|
|
line as i32,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_pads(&self) -> crate::Iterator<Pad> {
|
2019-01-16 11:32:58 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_element_iterate_pads(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_sink_pads(&self) -> crate::Iterator<Pad> {
|
2019-01-16 11:32:58 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_element_iterate_sink_pads(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_src_pads(&self) -> crate::Iterator<Pad> {
|
2019-01-16 11:32:58 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_element_iterate_src_pads(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
2017-10-25 10:48:01 +00:00
|
|
|
|
|
|
|
fn get_pads(&self) -> Vec<Pad> {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2017-10-25 10:48:01 +00:00
|
|
|
FromGlibPtrContainer::from_glib_none(elt.pads)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_sink_pads(&self) -> Vec<Pad> {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2017-10-25 10:48:01 +00:00
|
|
|
FromGlibPtrContainer::from_glib_none(elt.sinkpads)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_src_pads(&self) -> Vec<Pad> {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2017-10-25 10:48:01 +00:00
|
|
|
FromGlibPtrContainer::from_glib_none(elt.srcpads)
|
|
|
|
}
|
|
|
|
}
|
2017-10-27 15:55:48 +00:00
|
|
|
|
2019-09-03 14:14:47 +00:00
|
|
|
fn num_pads(&self) -> u16 {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2019-09-03 14:14:47 +00:00
|
|
|
elt.numpads
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn num_sink_pads(&self) -> u16 {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2019-09-03 14:14:47 +00:00
|
|
|
elt.numsinkpads
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn num_src_pads(&self) -> u16 {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
2019-09-03 14:14:47 +00:00
|
|
|
elt.numsrcpads
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn add_property_deep_notify_watch(
|
2017-10-27 15:55:48 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
property_name: Option<&str>,
|
2017-10-27 15:55:48 +00:00
|
|
|
include_value: bool,
|
|
|
|
) -> NotifyWatchId {
|
|
|
|
let property_name = property_name.to_glib_none();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_add_property_deep_notify_watch(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-10-27 15:55:48 +00:00
|
|
|
property_name.0,
|
|
|
|
include_value.to_glib(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn add_property_notify_watch(
|
2017-10-27 15:55:48 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
property_name: Option<&str>,
|
2017-10-27 15:55:48 +00:00
|
|
|
include_value: bool,
|
|
|
|
) -> NotifyWatchId {
|
|
|
|
let property_name = property_name.to_glib_none();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_element_add_property_notify_watch(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-10-27 15:55:48 +00:00
|
|
|
property_name.0,
|
|
|
|
include_value.to_glib(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2017-10-27 15:55:48 +00:00
|
|
|
fn remove_property_notify_watch(&self, watch_id: NotifyWatchId) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_remove_property_notify_watch(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2020-01-05 02:38:55 +00:00
|
|
|
watch_id.to_glib(),
|
2019-01-16 11:32:58 +00:00
|
|
|
);
|
2017-10-27 15:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<U> {
|
2017-11-11 10:21:55 +00:00
|
|
|
let src_val = src_val.into();
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-12-09 16:20:21 +00:00
|
|
|
src_val.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
src_val.to_raw_value(),
|
2017-12-09 16:20:21 +00:00
|
|
|
U::get_default_format().to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(U::from_raw(U::get_default_format(), dest_val.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_convert_generic<V: Into<GenericFormattedValue>>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
|
|
|
) -> Option<GenericFormattedValue> {
|
|
|
|
let src_val = src_val.into();
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-12-09 16:20:21 +00:00
|
|
|
src_val.get_format().to_glib(),
|
|
|
|
src_val.get_value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
dest_format.to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(
|
|
|
|
dest_format,
|
|
|
|
dest_val.assume_init(),
|
|
|
|
))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-12-09 16:20:21 +00:00
|
|
|
T::get_default_format().to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(T::from_raw(T::get_default_format(), duration.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-11-11 10:21:55 +00:00
|
|
|
format.to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, duration.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_position<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-12-09 16:20:21 +00:00
|
|
|
T::get_default_format().to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(T::from_raw(T::get_default_format(), cur.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_element_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-11-11 10:21:55 +00:00
|
|
|
format.to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, cur.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn seek<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
rate: f64,
|
2020-11-21 13:46:48 +00:00
|
|
|
flags: crate::SeekFlags,
|
|
|
|
start_type: crate::SeekType,
|
2017-11-11 10:21:55 +00:00
|
|
|
start: V,
|
2020-11-21 13:46:48 +00:00
|
|
|
stop_type: crate::SeekType,
|
2017-11-11 10:21:55 +00:00
|
|
|
stop: V,
|
|
|
|
) -> Result<(), glib::error::BoolError> {
|
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(stop.get_format(), start.get_format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::glib_result_from_gboolean!(
|
|
|
|
ffi::gst_element_seek(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-11-11 10:21:55 +00:00
|
|
|
rate,
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_format().to_glib(),
|
2017-11-11 10:21:55 +00:00
|
|
|
flags.to_glib(),
|
|
|
|
start_type.to_glib(),
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
stop_type.to_glib(),
|
2017-12-09 16:20:21 +00:00
|
|
|
stop.get_value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
),
|
|
|
|
"Failed to seek",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn seek_simple<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
seek_flags: crate::SeekFlags,
|
2017-11-11 10:21:55 +00:00
|
|
|
seek_pos: V,
|
|
|
|
) -> Result<(), glib::error::BoolError> {
|
|
|
|
let seek_pos = seek_pos.into();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::glib_result_from_gboolean!(
|
|
|
|
ffi::gst_element_seek_simple(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-12-09 16:20:21 +00:00
|
|
|
seek_pos.get_format().to_glib(),
|
2017-11-11 10:21:55 +00:00
|
|
|
seek_flags.to_glib(),
|
2017-12-09 16:20:21 +00:00
|
|
|
seek_pos.get_value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
),
|
|
|
|
"Failed to seek",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 13:42:17 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2018-03-14 13:42:17 +00:00
|
|
|
fn call_async<F>(&self, func: F)
|
|
|
|
where
|
|
|
|
F: FnOnce(&Self) + Send + 'static,
|
|
|
|
{
|
2019-01-30 13:02:03 +00:00
|
|
|
let user_data: Box<Option<F>> = Box::new(Some(func));
|
2018-03-14 13:42:17 +00:00
|
|
|
|
|
|
|
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
2020-11-21 13:46:48 +00:00
|
|
|
element: *mut ffi::GstElement,
|
|
|
|
user_data: glib::ffi::gpointer,
|
2018-03-14 13:42:17 +00:00
|
|
|
) {
|
2019-01-30 13:02:03 +00:00
|
|
|
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
|
2018-03-14 13:42:17 +00:00
|
|
|
let callback = user_data.take().unwrap();
|
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
callback(&Element::from_glib_borrow(element).unsafe_cast_ref());
|
2018-03-14 13:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
|
2020-11-21 13:46:48 +00:00
|
|
|
user_data: glib::ffi::gpointer,
|
2018-03-14 13:42:17 +00:00
|
|
|
) {
|
2019-01-30 13:02:03 +00:00
|
|
|
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
|
2018-03-14 13:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_element_call_async(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(trampoline::<Self, F>),
|
2018-03-14 13:42:17 +00:00
|
|
|
Box::into_raw(user_data) as *mut _,
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(free_user_data::<Self, F>),
|
2018-03-14 13:42:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 09:59:13 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
|
2020-01-20 09:59:13 +00:00
|
|
|
fn call_async_future<F, T>(
|
|
|
|
&self,
|
|
|
|
func: F,
|
|
|
|
) -> Pin<Box<dyn Future<Output = T> + Unpin + Send + 'static>>
|
|
|
|
where
|
|
|
|
F: FnOnce(&Self) -> T + Send + 'static,
|
|
|
|
T: Send + 'static,
|
|
|
|
{
|
|
|
|
use futures_channel::oneshot;
|
|
|
|
use futures_util::future::FutureExt;
|
|
|
|
|
|
|
|
let (sender, receiver) = oneshot::channel();
|
|
|
|
|
|
|
|
self.call_async(move |element| {
|
|
|
|
let _ = sender.send(func(element));
|
|
|
|
});
|
|
|
|
|
|
|
|
Box::pin(receiver.map(|res| res.expect("sender dropped")))
|
|
|
|
}
|
2020-04-11 17:02:41 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn get_current_running_time(&self) -> crate::ClockTime {
|
|
|
|
use crate::ElementExt;
|
2020-04-11 17:02:41 +00:00
|
|
|
|
|
|
|
let base_time = self.get_base_time();
|
|
|
|
let clock_time = self.get_current_clock_time();
|
|
|
|
|
|
|
|
clock_time - base_time
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn get_current_clock_time(&self) -> crate::ClockTime {
|
|
|
|
use crate::ClockExt;
|
|
|
|
use crate::ElementExt;
|
2020-04-11 17:02:41 +00:00
|
|
|
|
|
|
|
if let Some(clock) = self.get_clock() {
|
|
|
|
clock.get_time()
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::CLOCK_TIME_NONE
|
2020-04-11 17:02:41 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
pub unsafe trait ElementClassExt {
|
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let klass = self as *const _ as *const ffi::GstElementClass;
|
2018-11-18 12:20:16 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_element_class_get_metadata(klass as *mut _, key.to_glib_none().0);
|
2018-11-18 12:20:16 +00:00
|
|
|
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(CStr::from_ptr(ptr).to_str().unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
fn get_pad_template(&self, name: &str) -> Option<PadTemplate> {
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let klass = self as *const _ as *const ffi::GstElementClass;
|
2018-11-18 12:20:16 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_none(ffi::gst_element_class_get_pad_template(
|
2018-11-18 12:20:16 +00:00
|
|
|
klass as *mut _,
|
|
|
|
name.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
fn get_pad_template_list(&self) -> Vec<PadTemplate> {
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let klass = self as *const _ as *const ffi::GstElementClass;
|
2018-11-18 12:20:16 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
FromGlibPtrContainer::from_glib_none(ffi::gst_element_class_get_pad_template_list(
|
2018-11-18 12:20:16 +00:00
|
|
|
klass as *mut _,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
unsafe impl<T: IsA<Element>> ElementClassExt for glib::object::Class<T> {}
|
|
|
|
|
2020-01-22 17:38:13 +00:00
|
|
|
pub static ELEMENT_METADATA_AUTHOR: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_AUTHOR)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
|
|
|
pub static ELEMENT_METADATA_DESCRIPTION: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DESCRIPTION)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
|
|
|
pub static ELEMENT_METADATA_DOC_URI: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DOC_URI)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
|
|
|
pub static ELEMENT_METADATA_ICON_NAME: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_ICON_NAME)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
|
|
|
pub static ELEMENT_METADATA_KLASS: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_KLASS)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
|
|
|
pub static ELEMENT_METADATA_LONGNAME: Lazy<&'static str> = Lazy::new(|| unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_LONGNAME)
|
2020-01-22 17:38:13 +00:00
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
});
|
2017-10-26 11:29:37 +00:00
|
|
|
|
2017-11-11 15:28:23 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gst_element_error(
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
2017-11-15 15:03:19 +00:00
|
|
|
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Error,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
2017-11-11 15:28:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gst_element_warning(
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
2017-11-15 15:03:19 +00:00
|
|
|
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Warning,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
2017-11-11 15:28:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gst_element_info(
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-11 15:28:23 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
);
|
|
|
|
}};
|
2017-11-15 15:03:19 +00:00
|
|
|
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
Some($msg),
|
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
None,
|
|
|
|
Some($debug),
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($msg)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
None,
|
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
|
|
|
|
use $crate::ElementExtManual;
|
|
|
|
$obj.message_full_with_details(
|
|
|
|
$crate::ElementMessageType::Info,
|
|
|
|
$err,
|
|
|
|
None,
|
2017-11-16 11:37:52 +00:00
|
|
|
Some(&format!($($debug)*)),
|
2017-11-15 15:03:19 +00:00
|
|
|
file!(),
|
|
|
|
module_path!(),
|
|
|
|
line!(),
|
|
|
|
$details,
|
|
|
|
);
|
|
|
|
}};
|
2017-11-11 15:28:23 +00:00
|
|
|
);
|
|
|
|
|
2017-10-26 11:29:37 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2018-12-09 16:06:12 +00:00
|
|
|
use glib::GString;
|
2018-03-16 15:04:35 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2018-03-14 13:42:17 +00:00
|
|
|
use std::sync::mpsc::channel;
|
2017-10-26 11:29:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_pads() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-10-26 11:29:37 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let identity = crate::ElementFactory::make("identity", None).unwrap();
|
2017-10-26 11:29:37 +00:00
|
|
|
|
|
|
|
let mut pad_names = identity
|
|
|
|
.get_pads()
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.get_name())
|
2018-12-09 16:06:12 +00:00
|
|
|
.collect::<Vec<GString>>();
|
2017-10-26 11:29:37 +00:00
|
|
|
pad_names.sort();
|
|
|
|
assert_eq!(pad_names, vec![String::from("sink"), String::from("src")]);
|
|
|
|
|
|
|
|
let mut pad_names = identity
|
|
|
|
.get_sink_pads()
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.get_name())
|
2018-12-09 16:06:12 +00:00
|
|
|
.collect::<Vec<GString>>();
|
2017-10-26 11:29:37 +00:00
|
|
|
pad_names.sort();
|
|
|
|
assert_eq!(pad_names, vec![String::from("sink")]);
|
|
|
|
|
|
|
|
let mut pad_names = identity
|
|
|
|
.get_src_pads()
|
|
|
|
.iter()
|
|
|
|
.map(|p| p.get_name())
|
2018-12-09 16:06:12 +00:00
|
|
|
.collect::<Vec<GString>>();
|
2017-10-26 11:29:37 +00:00
|
|
|
pad_names.sort();
|
|
|
|
assert_eq!(pad_names, vec![String::from("src")]);
|
|
|
|
}
|
2018-03-14 13:42:17 +00:00
|
|
|
|
2019-01-29 14:14:06 +00:00
|
|
|
#[test]
|
2019-01-30 12:56:09 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2019-01-29 14:14:06 +00:00
|
|
|
fn test_foreach_pad() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-01-29 14:14:06 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let identity = crate::ElementFactory::make("identity", None).unwrap();
|
2019-01-29 14:14:06 +00:00
|
|
|
|
|
|
|
let mut pad_names = Vec::new();
|
|
|
|
identity.foreach_pad(|_element, pad| {
|
|
|
|
pad_names.push(pad.get_name());
|
|
|
|
|
|
|
|
true
|
|
|
|
});
|
|
|
|
pad_names.sort();
|
|
|
|
assert_eq!(pad_names, vec![String::from("sink"), String::from("src")]);
|
|
|
|
}
|
|
|
|
|
2018-03-16 15:04:35 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2018-03-14 13:42:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_call_async() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2018-03-14 13:42:17 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let identity = crate::ElementFactory::make("identity", None).unwrap();
|
2018-03-14 13:42:17 +00:00
|
|
|
let (sender, receiver) = channel();
|
|
|
|
|
|
|
|
identity.call_async(move |_| {
|
|
|
|
sender.send(()).unwrap();
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(receiver.recv(), Ok(()));
|
|
|
|
}
|
2017-10-26 11:29:37 +00:00
|
|
|
}
|