// This file was generated by gir (https://github.com/gtk-rs/gir) // from gir-files (https://github.com/gtk-rs/gir-files) // from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git) // DO NOT EDIT #![allow(deprecated)] use crate::{ Bus, Caps, Clock, ClockTime, Context, ElementFactory, Message, Object, Pad, PadTemplate, State, StateChange, StateChangeError, StateChangeReturn, StateChangeSuccess, URIType, }; use glib::{ prelude::*, signal::{connect_raw, SignalHandlerId}, translate::*, }; use std::{boxed::Box as Box_, mem, mem::transmute, ptr}; glib::wrapper! { #[doc(alias = "GstElement")] pub struct Element(Object) @extends Object; match fn { type_ => || ffi::gst_element_get_type(), } } impl Element { pub const NONE: Option<&'static Element> = None; #[doc(alias = "gst_element_make_from_uri")] pub fn make_from_uri( type_: URIType, uri: &str, elementname: Option<&str>, ) -> Result { assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_element_make_from_uri( type_.into_glib(), uri.to_glib_none().0, elementname.to_glib_none().0, &mut error, ); if error.is_null() { Ok(from_glib_none(ret)) } else { Err(from_glib_full(error)) } } } } unsafe impl Send for Element {} unsafe impl Sync for Element {} pub trait ElementExt: 'static { #[doc(alias = "gst_element_abort_state")] fn abort_state(&self); #[doc(alias = "gst_element_add_pad")] fn add_pad(&self, pad: &impl IsA) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_change_state")] fn change_state(&self, transition: StateChange) -> Result; #[doc(alias = "gst_element_continue_state")] fn continue_state( &self, ret: impl Into, ) -> Result; #[doc(alias = "gst_element_create_all_pads")] fn create_all_pads(&self); #[cfg(any(feature = "v1_24", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_24")))] #[doc(alias = "gst_element_decorate_stream_id")] fn decorate_stream_id(&self, stream_id: &str) -> glib::GString; #[doc(alias = "gst_element_foreach_pad")] fn foreach_pad bool>(&self, func: P) -> bool; #[doc(alias = "gst_element_foreach_sink_pad")] fn foreach_sink_pad bool>(&self, func: P) -> bool; #[doc(alias = "gst_element_foreach_src_pad")] fn foreach_src_pad bool>(&self, func: P) -> bool; #[doc(alias = "gst_element_get_base_time")] #[doc(alias = "get_base_time")] fn base_time(&self) -> Option; #[doc(alias = "gst_element_get_bus")] #[doc(alias = "get_bus")] fn bus(&self) -> Option; #[doc(alias = "gst_element_get_clock")] #[doc(alias = "get_clock")] fn clock(&self) -> Option; #[doc(alias = "gst_element_get_compatible_pad")] #[doc(alias = "get_compatible_pad")] fn compatible_pad(&self, pad: &impl IsA, caps: Option<&Caps>) -> Option; #[doc(alias = "gst_element_get_compatible_pad_template")] #[doc(alias = "get_compatible_pad_template")] fn compatible_pad_template(&self, compattempl: &PadTemplate) -> Option; #[doc(alias = "gst_element_get_context")] #[doc(alias = "get_context")] fn context(&self, context_type: &str) -> Option; #[doc(alias = "gst_element_get_contexts")] #[doc(alias = "get_contexts")] fn contexts(&self) -> Vec; #[doc(alias = "gst_element_get_factory")] #[doc(alias = "get_factory")] fn factory(&self) -> Option; #[doc(alias = "gst_element_get_start_time")] #[doc(alias = "get_start_time")] fn start_time(&self) -> Option; #[doc(alias = "gst_element_get_state")] #[doc(alias = "get_state")] fn state( &self, timeout: impl Into>, ) -> (Result, State, State); #[doc(alias = "gst_element_get_static_pad")] #[doc(alias = "get_static_pad")] fn static_pad(&self, name: &str) -> Option; #[doc(alias = "gst_element_is_locked_state")] fn is_locked_state(&self) -> bool; #[doc(alias = "gst_element_lost_state")] fn lost_state(&self); #[doc(alias = "gst_element_no_more_pads")] fn no_more_pads(&self); #[doc(alias = "gst_element_post_message")] fn post_message(&self, message: Message) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_provide_clock")] fn provide_clock(&self) -> Option; #[doc(alias = "gst_element_release_request_pad")] fn release_request_pad(&self, pad: &impl IsA); #[doc(alias = "gst_element_remove_pad")] fn remove_pad(&self, pad: &impl IsA) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_request_pad")] fn request_pad( &self, templ: &PadTemplate, name: Option<&str>, caps: Option<&Caps>, ) -> Option; #[doc(alias = "gst_element_set_base_time")] fn set_base_time(&self, time: ClockTime); #[doc(alias = "gst_element_set_bus")] fn set_bus(&self, bus: Option<&Bus>); #[doc(alias = "gst_element_set_clock")] fn set_clock(&self, clock: Option<&impl IsA>) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_set_context")] fn set_context(&self, context: &Context); #[doc(alias = "gst_element_set_locked_state")] fn set_locked_state(&self, locked_state: bool) -> bool; #[doc(alias = "gst_element_set_start_time")] fn set_start_time(&self, time: impl Into>); #[doc(alias = "gst_element_set_state")] fn set_state(&self, state: State) -> Result; #[doc(alias = "gst_element_sync_state_with_parent")] fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError>; #[doc(alias = "gst_element_unlink")] fn unlink(&self, dest: &impl IsA); #[doc(alias = "gst_element_unlink_pads")] fn unlink_pads(&self, srcpadname: &str, dest: &impl IsA, destpadname: &str); #[doc(alias = "no-more-pads")] fn connect_no_more_pads(&self, f: F) -> SignalHandlerId; #[doc(alias = "pad-added")] fn connect_pad_added( &self, f: F, ) -> SignalHandlerId; #[doc(alias = "pad-removed")] fn connect_pad_removed( &self, f: F, ) -> SignalHandlerId; } impl> ElementExt for O { fn abort_state(&self) { unsafe { ffi::gst_element_abort_state(self.as_ref().to_glib_none().0); } } fn add_pad(&self, pad: &impl IsA) -> Result<(), glib::error::BoolError> { unsafe { glib::result_from_gboolean!( ffi::gst_element_add_pad( self.as_ref().to_glib_none().0, pad.as_ref().to_glib_none().0 ), "Failed to add pad" ) } } fn change_state( &self, transition: StateChange, ) -> Result { unsafe { try_from_glib(ffi::gst_element_change_state( self.as_ref().to_glib_none().0, transition.into_glib(), )) } } fn continue_state( &self, ret: impl Into, ) -> Result { unsafe { try_from_glib(ffi::gst_element_continue_state( self.as_ref().to_glib_none().0, ret.into().into_glib(), )) } } fn create_all_pads(&self) { unsafe { ffi::gst_element_create_all_pads(self.as_ref().to_glib_none().0); } } #[cfg(any(feature = "v1_24", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_24")))] fn decorate_stream_id(&self, stream_id: &str) -> glib::GString { unsafe { from_glib_full(ffi::gst_element_decorate_stream_id( self.as_ref().to_glib_none().0, stream_id.to_glib_none().0, )) } } fn foreach_pad bool>(&self, func: P) -> bool { let func_data: P = func; unsafe extern "C" fn func_func bool>( element: *mut ffi::GstElement, pad: *mut ffi::GstPad, user_data: glib::ffi::gpointer, ) -> glib::ffi::gboolean { let element = from_glib_borrow(element); let pad = from_glib_borrow(pad); let callback: *mut P = user_data as *const _ as usize as *mut P; (*callback)(&element, &pad).into_glib() } let func = Some(func_func::

as _); let super_callback0: &P = &func_data; unsafe { from_glib(ffi::gst_element_foreach_pad( self.as_ref().to_glib_none().0, func, super_callback0 as *const _ as usize as *mut _, )) } } fn foreach_sink_pad bool>(&self, func: P) -> bool { let func_data: P = func; unsafe extern "C" fn func_func bool>( element: *mut ffi::GstElement, pad: *mut ffi::GstPad, user_data: glib::ffi::gpointer, ) -> glib::ffi::gboolean { let element = from_glib_borrow(element); let pad = from_glib_borrow(pad); let callback: *mut P = user_data as *const _ as usize as *mut P; (*callback)(&element, &pad).into_glib() } let func = Some(func_func::

as _); let super_callback0: &P = &func_data; unsafe { from_glib(ffi::gst_element_foreach_sink_pad( self.as_ref().to_glib_none().0, func, super_callback0 as *const _ as usize as *mut _, )) } } fn foreach_src_pad bool>(&self, func: P) -> bool { let func_data: P = func; unsafe extern "C" fn func_func bool>( element: *mut ffi::GstElement, pad: *mut ffi::GstPad, user_data: glib::ffi::gpointer, ) -> glib::ffi::gboolean { let element = from_glib_borrow(element); let pad = from_glib_borrow(pad); let callback: *mut P = user_data as *const _ as usize as *mut P; (*callback)(&element, &pad).into_glib() } let func = Some(func_func::

as _); let super_callback0: &P = &func_data; unsafe { from_glib(ffi::gst_element_foreach_src_pad( self.as_ref().to_glib_none().0, func, super_callback0 as *const _ as usize as *mut _, )) } } fn base_time(&self) -> Option { unsafe { from_glib(ffi::gst_element_get_base_time( self.as_ref().to_glib_none().0, )) } } fn bus(&self) -> Option { unsafe { from_glib_full(ffi::gst_element_get_bus(self.as_ref().to_glib_none().0)) } } fn clock(&self) -> Option { unsafe { from_glib_full(ffi::gst_element_get_clock(self.as_ref().to_glib_none().0)) } } fn compatible_pad(&self, pad: &impl IsA, caps: Option<&Caps>) -> Option { unsafe { from_glib_full(ffi::gst_element_get_compatible_pad( self.as_ref().to_glib_none().0, pad.as_ref().to_glib_none().0, caps.to_glib_none().0, )) } } fn compatible_pad_template(&self, compattempl: &PadTemplate) -> Option { unsafe { from_glib_none(ffi::gst_element_get_compatible_pad_template( self.as_ref().to_glib_none().0, compattempl.to_glib_none().0, )) } } fn context(&self, context_type: &str) -> Option { unsafe { from_glib_full(ffi::gst_element_get_context( self.as_ref().to_glib_none().0, context_type.to_glib_none().0, )) } } fn contexts(&self) -> Vec { unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_element_get_contexts( self.as_ref().to_glib_none().0, )) } } fn factory(&self) -> Option { unsafe { from_glib_none(ffi::gst_element_get_factory(self.as_ref().to_glib_none().0)) } } fn start_time(&self) -> Option { unsafe { from_glib(ffi::gst_element_get_start_time( self.as_ref().to_glib_none().0, )) } } fn state( &self, timeout: impl Into>, ) -> (Result, State, State) { unsafe { let mut state = mem::MaybeUninit::uninit(); let mut pending = mem::MaybeUninit::uninit(); let ret = try_from_glib(ffi::gst_element_get_state( self.as_ref().to_glib_none().0, state.as_mut_ptr(), pending.as_mut_ptr(), timeout.into().into_glib(), )); ( ret, from_glib(state.assume_init()), from_glib(pending.assume_init()), ) } } fn static_pad(&self, name: &str) -> Option { unsafe { from_glib_full(ffi::gst_element_get_static_pad( self.as_ref().to_glib_none().0, name.to_glib_none().0, )) } } fn is_locked_state(&self) -> bool { unsafe { from_glib(ffi::gst_element_is_locked_state( self.as_ref().to_glib_none().0, )) } } fn lost_state(&self) { unsafe { ffi::gst_element_lost_state(self.as_ref().to_glib_none().0); } } fn no_more_pads(&self) { unsafe { ffi::gst_element_no_more_pads(self.as_ref().to_glib_none().0); } } fn post_message(&self, message: Message) -> Result<(), glib::error::BoolError> { unsafe { glib::result_from_gboolean!( ffi::gst_element_post_message( self.as_ref().to_glib_none().0, message.into_glib_ptr() ), "Failed to post message" ) } } fn provide_clock(&self) -> Option { unsafe { from_glib_full(ffi::gst_element_provide_clock( self.as_ref().to_glib_none().0, )) } } fn release_request_pad(&self, pad: &impl IsA) { unsafe { ffi::gst_element_release_request_pad( self.as_ref().to_glib_none().0, pad.as_ref().to_glib_none().0, ); } } fn remove_pad(&self, pad: &impl IsA) -> Result<(), glib::error::BoolError> { unsafe { glib::result_from_gboolean!( ffi::gst_element_remove_pad( self.as_ref().to_glib_none().0, pad.as_ref().to_glib_none().0 ), "Failed to remove pad" ) } } fn request_pad( &self, templ: &PadTemplate, name: Option<&str>, caps: Option<&Caps>, ) -> Option { unsafe { from_glib_full(ffi::gst_element_request_pad( self.as_ref().to_glib_none().0, templ.to_glib_none().0, name.to_glib_none().0, caps.to_glib_none().0, )) } } fn set_base_time(&self, time: ClockTime) { unsafe { ffi::gst_element_set_base_time(self.as_ref().to_glib_none().0, time.into_glib()); } } fn set_bus(&self, bus: Option<&Bus>) { unsafe { ffi::gst_element_set_bus(self.as_ref().to_glib_none().0, bus.to_glib_none().0); } } fn set_clock(&self, clock: Option<&impl IsA>) -> Result<(), glib::error::BoolError> { unsafe { glib::result_from_gboolean!( ffi::gst_element_set_clock( self.as_ref().to_glib_none().0, clock.map(|p| p.as_ref()).to_glib_none().0 ), "Failed to set clock" ) } } fn set_context(&self, context: &Context) { unsafe { ffi::gst_element_set_context(self.as_ref().to_glib_none().0, context.to_glib_none().0); } } fn set_locked_state(&self, locked_state: bool) -> bool { unsafe { from_glib(ffi::gst_element_set_locked_state( self.as_ref().to_glib_none().0, locked_state.into_glib(), )) } } fn set_start_time(&self, time: impl Into>) { unsafe { ffi::gst_element_set_start_time( self.as_ref().to_glib_none().0, time.into().into_glib(), ); } } fn set_state(&self, state: State) -> Result { unsafe { try_from_glib(ffi::gst_element_set_state( self.as_ref().to_glib_none().0, state.into_glib(), )) } } fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> { unsafe { glib::result_from_gboolean!( ffi::gst_element_sync_state_with_parent(self.as_ref().to_glib_none().0), "Failed to sync state with parent" ) } } fn unlink(&self, dest: &impl IsA) { unsafe { ffi::gst_element_unlink( self.as_ref().to_glib_none().0, dest.as_ref().to_glib_none().0, ); } } fn unlink_pads(&self, srcpadname: &str, dest: &impl IsA, destpadname: &str) { unsafe { ffi::gst_element_unlink_pads( self.as_ref().to_glib_none().0, srcpadname.to_glib_none().0, dest.as_ref().to_glib_none().0, destpadname.to_glib_none().0, ); } } fn connect_no_more_pads(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn no_more_pads_trampoline< P: IsA, F: Fn(&P) + Send + Sync + 'static, >( this: *mut ffi::GstElement, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Element::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"no-more-pads\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( no_more_pads_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn connect_pad_added( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn pad_added_trampoline< P: IsA, F: Fn(&P, &Pad) + Send + Sync + 'static, >( this: *mut ffi::GstElement, new_pad: *mut ffi::GstPad, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f( Element::from_glib_borrow(this).unsafe_cast_ref(), &from_glib_borrow(new_pad), ) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"pad-added\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( pad_added_trampoline:: as *const (), )), Box_::into_raw(f), ) } } fn connect_pad_removed( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn pad_removed_trampoline< P: IsA, F: Fn(&P, &Pad) + Send + Sync + 'static, >( this: *mut ffi::GstElement, old_pad: *mut ffi::GstPad, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f( Element::from_glib_borrow(this).unsafe_cast_ref(), &from_glib_borrow(old_pad), ) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"pad-removed\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( pad_removed_trampoline:: as *const (), )), Box_::into_raw(f), ) } } }