1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5#![allow(deprecated)]
6
7use crate::{
8 Bus, Caps, Clock, ClockTime, Context, ElementFactory, Message, Object, Pad, PadTemplate, State,
9 StateChange, StateChangeError, StateChangeReturn, StateChangeSuccess, URIType,
10};
11use glib::{
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::{boxed::Box as Box_, mem, mem::transmute, ptr};
17
18glib::wrapper! {
19 #[doc(alias = "GstElement")]
20 pub struct Element(Object<ffi::GstElement, ffi::GstElementClass>) @extends Object;
21
22 match fn {
23 type_ => || ffi::gst_element_get_type(),
24 }
25}
26
27impl Element {
28 pub const NONE: Option<&'static Element> = None;
29
30 #[doc(alias = "gst_element_make_from_uri")]
31 pub fn make_from_uri(
32 type_: URIType,
33 uri: &str,
34 elementname: Option<&str>,
35 ) -> Result<Element, glib::Error> {
36 assert_initialized_main_thread!();
37 unsafe {
38 let mut error = ptr::null_mut();
39 let ret = ffi::gst_element_make_from_uri(
40 type_.into_glib(),
41 uri.to_glib_none().0,
42 elementname.to_glib_none().0,
43 &mut error,
44 );
45 if error.is_null() {
46 Ok(from_glib_none(ret))
47 } else {
48 Err(from_glib_full(error))
49 }
50 }
51 }
52}
53
54unsafe impl Send for Element {}
55unsafe impl Sync for Element {}
56
57mod sealed {
58 pub trait Sealed {}
59 impl<T: super::IsA<super::Element>> Sealed for T {}
60}
61
62pub trait ElementExt: IsA<Element> + sealed::Sealed + 'static {
63 #[doc(alias = "gst_element_abort_state")]
64 fn abort_state(&self) {
65 unsafe {
66 ffi::gst_element_abort_state(self.as_ref().to_glib_none().0);
67 }
68 }
69
70 #[doc(alias = "gst_element_add_pad")]
71 fn add_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
72 unsafe {
73 glib::result_from_gboolean!(
74 ffi::gst_element_add_pad(
75 self.as_ref().to_glib_none().0,
76 pad.as_ref().to_glib_none().0
77 ),
78 "Failed to add pad"
79 )
80 }
81 }
82
83 #[doc(alias = "gst_element_change_state")]
84 fn change_state(
85 &self,
86 transition: StateChange,
87 ) -> Result<StateChangeSuccess, StateChangeError> {
88 unsafe {
89 try_from_glib(ffi::gst_element_change_state(
90 self.as_ref().to_glib_none().0,
91 transition.into_glib(),
92 ))
93 }
94 }
95
96 #[doc(alias = "gst_element_continue_state")]
97 fn continue_state(
98 &self,
99 ret: impl Into<StateChangeReturn>,
100 ) -> Result<StateChangeSuccess, StateChangeError> {
101 unsafe {
102 try_from_glib(ffi::gst_element_continue_state(
103 self.as_ref().to_glib_none().0,
104 ret.into().into_glib(),
105 ))
106 }
107 }
108
109 #[doc(alias = "gst_element_create_all_pads")]
110 fn create_all_pads(&self) {
111 unsafe {
112 ffi::gst_element_create_all_pads(self.as_ref().to_glib_none().0);
113 }
114 }
115
116 #[cfg(feature = "v1_24")]
117 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
118 #[doc(alias = "gst_element_decorate_stream_id")]
119 fn decorate_stream_id(&self, stream_id: &str) -> glib::GString {
120 unsafe {
121 from_glib_full(ffi::gst_element_decorate_stream_id(
122 self.as_ref().to_glib_none().0,
123 stream_id.to_glib_none().0,
124 ))
125 }
126 }
127
128 #[doc(alias = "gst_element_foreach_pad")]
129 fn foreach_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
130 let func_data: P = func;
131 unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
132 element: *mut ffi::GstElement,
133 pad: *mut ffi::GstPad,
134 user_data: glib::ffi::gpointer,
135 ) -> glib::ffi::gboolean {
136 let element = from_glib_borrow(element);
137 let pad = from_glib_borrow(pad);
138 let callback: *mut P = user_data as *const _ as usize as *mut P;
139 (*callback)(&element, &pad).into_glib()
140 }
141 let func = Some(func_func::<P> as _);
142 let super_callback0: &P = &func_data;
143 unsafe {
144 from_glib(ffi::gst_element_foreach_pad(
145 self.as_ref().to_glib_none().0,
146 func,
147 super_callback0 as *const _ as usize as *mut _,
148 ))
149 }
150 }
151
152 #[doc(alias = "gst_element_foreach_sink_pad")]
153 fn foreach_sink_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
154 let func_data: P = func;
155 unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
156 element: *mut ffi::GstElement,
157 pad: *mut ffi::GstPad,
158 user_data: glib::ffi::gpointer,
159 ) -> glib::ffi::gboolean {
160 let element = from_glib_borrow(element);
161 let pad = from_glib_borrow(pad);
162 let callback: *mut P = user_data as *const _ as usize as *mut P;
163 (*callback)(&element, &pad).into_glib()
164 }
165 let func = Some(func_func::<P> as _);
166 let super_callback0: &P = &func_data;
167 unsafe {
168 from_glib(ffi::gst_element_foreach_sink_pad(
169 self.as_ref().to_glib_none().0,
170 func,
171 super_callback0 as *const _ as usize as *mut _,
172 ))
173 }
174 }
175
176 #[doc(alias = "gst_element_foreach_src_pad")]
177 fn foreach_src_pad<P: FnMut(&Element, &Pad) -> bool>(&self, func: P) -> bool {
178 let func_data: P = func;
179 unsafe extern "C" fn func_func<P: FnMut(&Element, &Pad) -> bool>(
180 element: *mut ffi::GstElement,
181 pad: *mut ffi::GstPad,
182 user_data: glib::ffi::gpointer,
183 ) -> glib::ffi::gboolean {
184 let element = from_glib_borrow(element);
185 let pad = from_glib_borrow(pad);
186 let callback: *mut P = user_data as *const _ as usize as *mut P;
187 (*callback)(&element, &pad).into_glib()
188 }
189 let func = Some(func_func::<P> as _);
190 let super_callback0: &P = &func_data;
191 unsafe {
192 from_glib(ffi::gst_element_foreach_src_pad(
193 self.as_ref().to_glib_none().0,
194 func,
195 super_callback0 as *const _ as usize as *mut _,
196 ))
197 }
198 }
199
200 #[doc(alias = "gst_element_get_base_time")]
201 #[doc(alias = "get_base_time")]
202 fn base_time(&self) -> Option<ClockTime> {
203 unsafe {
204 from_glib(ffi::gst_element_get_base_time(
205 self.as_ref().to_glib_none().0,
206 ))
207 }
208 }
209
210 #[doc(alias = "gst_element_get_bus")]
211 #[doc(alias = "get_bus")]
212 fn bus(&self) -> Option<Bus> {
213 unsafe { from_glib_full(ffi::gst_element_get_bus(self.as_ref().to_glib_none().0)) }
214 }
215
216 #[doc(alias = "gst_element_get_clock")]
217 #[doc(alias = "get_clock")]
218 fn clock(&self) -> Option<Clock> {
219 unsafe { from_glib_full(ffi::gst_element_get_clock(self.as_ref().to_glib_none().0)) }
220 }
221
222 #[doc(alias = "gst_element_get_compatible_pad")]
223 #[doc(alias = "get_compatible_pad")]
224 fn compatible_pad(&self, pad: &impl IsA<Pad>, caps: Option<&Caps>) -> Option<Pad> {
225 unsafe {
226 from_glib_full(ffi::gst_element_get_compatible_pad(
227 self.as_ref().to_glib_none().0,
228 pad.as_ref().to_glib_none().0,
229 caps.to_glib_none().0,
230 ))
231 }
232 }
233
234 #[doc(alias = "gst_element_get_compatible_pad_template")]
235 #[doc(alias = "get_compatible_pad_template")]
236 fn compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate> {
237 unsafe {
238 from_glib_none(ffi::gst_element_get_compatible_pad_template(
239 self.as_ref().to_glib_none().0,
240 compattempl.to_glib_none().0,
241 ))
242 }
243 }
244
245 #[doc(alias = "gst_element_get_context")]
246 #[doc(alias = "get_context")]
247 fn context(&self, context_type: &str) -> Option<Context> {
248 unsafe {
249 from_glib_full(ffi::gst_element_get_context(
250 self.as_ref().to_glib_none().0,
251 context_type.to_glib_none().0,
252 ))
253 }
254 }
255
256 #[doc(alias = "gst_element_get_contexts")]
257 #[doc(alias = "get_contexts")]
258 fn contexts(&self) -> Vec<Context> {
259 unsafe {
260 FromGlibPtrContainer::from_glib_full(ffi::gst_element_get_contexts(
261 self.as_ref().to_glib_none().0,
262 ))
263 }
264 }
265
266 #[doc(alias = "gst_element_get_factory")]
267 #[doc(alias = "get_factory")]
268 fn factory(&self) -> Option<ElementFactory> {
269 unsafe { from_glib_none(ffi::gst_element_get_factory(self.as_ref().to_glib_none().0)) }
270 }
271
272 #[doc(alias = "gst_element_get_start_time")]
273 #[doc(alias = "get_start_time")]
274 fn start_time(&self) -> Option<ClockTime> {
275 unsafe {
276 from_glib(ffi::gst_element_get_start_time(
277 self.as_ref().to_glib_none().0,
278 ))
279 }
280 }
281
282 #[doc(alias = "gst_element_get_state")]
283 #[doc(alias = "get_state")]
284 fn state(
285 &self,
286 timeout: impl Into<Option<ClockTime>>,
287 ) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
288 unsafe {
289 let mut state = mem::MaybeUninit::uninit();
290 let mut pending = mem::MaybeUninit::uninit();
291 let ret = try_from_glib(ffi::gst_element_get_state(
292 self.as_ref().to_glib_none().0,
293 state.as_mut_ptr(),
294 pending.as_mut_ptr(),
295 timeout.into().into_glib(),
296 ));
297 (
298 ret,
299 from_glib(state.assume_init()),
300 from_glib(pending.assume_init()),
301 )
302 }
303 }
304
305 #[doc(alias = "gst_element_get_static_pad")]
306 #[doc(alias = "get_static_pad")]
307 fn static_pad(&self, name: &str) -> Option<Pad> {
308 unsafe {
309 from_glib_full(ffi::gst_element_get_static_pad(
310 self.as_ref().to_glib_none().0,
311 name.to_glib_none().0,
312 ))
313 }
314 }
315
316 #[doc(alias = "gst_element_is_locked_state")]
317 fn is_locked_state(&self) -> bool {
318 unsafe {
319 from_glib(ffi::gst_element_is_locked_state(
320 self.as_ref().to_glib_none().0,
321 ))
322 }
323 }
324
325 #[doc(alias = "gst_element_lost_state")]
326 fn lost_state(&self) {
327 unsafe {
328 ffi::gst_element_lost_state(self.as_ref().to_glib_none().0);
329 }
330 }
331
332 #[doc(alias = "gst_element_no_more_pads")]
333 fn no_more_pads(&self) {
334 unsafe {
335 ffi::gst_element_no_more_pads(self.as_ref().to_glib_none().0);
336 }
337 }
338
339 #[doc(alias = "gst_element_post_message")]
340 fn post_message(&self, message: Message) -> Result<(), glib::error::BoolError> {
341 unsafe {
342 glib::result_from_gboolean!(
343 ffi::gst_element_post_message(
344 self.as_ref().to_glib_none().0,
345 message.into_glib_ptr()
346 ),
347 "Failed to post message"
348 )
349 }
350 }
351
352 #[doc(alias = "gst_element_provide_clock")]
353 fn provide_clock(&self) -> Option<Clock> {
354 unsafe {
355 from_glib_full(ffi::gst_element_provide_clock(
356 self.as_ref().to_glib_none().0,
357 ))
358 }
359 }
360
361 #[doc(alias = "gst_element_release_request_pad")]
362 fn release_request_pad(&self, pad: &impl IsA<Pad>) {
363 unsafe {
364 ffi::gst_element_release_request_pad(
365 self.as_ref().to_glib_none().0,
366 pad.as_ref().to_glib_none().0,
367 );
368 }
369 }
370
371 #[doc(alias = "gst_element_remove_pad")]
372 fn remove_pad(&self, pad: &impl IsA<Pad>) -> Result<(), glib::error::BoolError> {
373 unsafe {
374 glib::result_from_gboolean!(
375 ffi::gst_element_remove_pad(
376 self.as_ref().to_glib_none().0,
377 pad.as_ref().to_glib_none().0
378 ),
379 "Failed to remove pad"
380 )
381 }
382 }
383
384 #[doc(alias = "gst_element_request_pad")]
385 fn request_pad(
386 &self,
387 templ: &PadTemplate,
388 name: Option<&str>,
389 caps: Option<&Caps>,
390 ) -> Option<Pad> {
391 unsafe {
392 from_glib_full(ffi::gst_element_request_pad(
393 self.as_ref().to_glib_none().0,
394 templ.to_glib_none().0,
395 name.to_glib_none().0,
396 caps.to_glib_none().0,
397 ))
398 }
399 }
400
401 #[doc(alias = "gst_element_set_base_time")]
402 fn set_base_time(&self, time: ClockTime) {
403 unsafe {
404 ffi::gst_element_set_base_time(self.as_ref().to_glib_none().0, time.into_glib());
405 }
406 }
407
408 #[doc(alias = "gst_element_set_bus")]
409 fn set_bus(&self, bus: Option<&Bus>) {
410 unsafe {
411 ffi::gst_element_set_bus(self.as_ref().to_glib_none().0, bus.to_glib_none().0);
412 }
413 }
414
415 #[doc(alias = "gst_element_set_clock")]
416 fn set_clock(&self, clock: Option<&impl IsA<Clock>>) -> Result<(), glib::error::BoolError> {
417 unsafe {
418 glib::result_from_gboolean!(
419 ffi::gst_element_set_clock(
420 self.as_ref().to_glib_none().0,
421 clock.map(|p| p.as_ref()).to_glib_none().0
422 ),
423 "Failed to set clock"
424 )
425 }
426 }
427
428 #[doc(alias = "gst_element_set_context")]
429 fn set_context(&self, context: &Context) {
430 unsafe {
431 ffi::gst_element_set_context(self.as_ref().to_glib_none().0, context.to_glib_none().0);
432 }
433 }
434
435 #[doc(alias = "gst_element_set_locked_state")]
436 fn set_locked_state(&self, locked_state: bool) -> bool {
437 unsafe {
438 from_glib(ffi::gst_element_set_locked_state(
439 self.as_ref().to_glib_none().0,
440 locked_state.into_glib(),
441 ))
442 }
443 }
444
445 #[doc(alias = "gst_element_set_start_time")]
446 fn set_start_time(&self, time: impl Into<Option<ClockTime>>) {
447 unsafe {
448 ffi::gst_element_set_start_time(
449 self.as_ref().to_glib_none().0,
450 time.into().into_glib(),
451 );
452 }
453 }
454
455 #[doc(alias = "gst_element_set_state")]
456 fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
457 unsafe {
458 try_from_glib(ffi::gst_element_set_state(
459 self.as_ref().to_glib_none().0,
460 state.into_glib(),
461 ))
462 }
463 }
464
465 #[doc(alias = "gst_element_sync_state_with_parent")]
466 fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> {
467 unsafe {
468 glib::result_from_gboolean!(
469 ffi::gst_element_sync_state_with_parent(self.as_ref().to_glib_none().0),
470 "Failed to sync state with parent"
471 )
472 }
473 }
474
475 #[doc(alias = "gst_element_unlink")]
476 fn unlink(&self, dest: &impl IsA<Element>) {
477 unsafe {
478 ffi::gst_element_unlink(
479 self.as_ref().to_glib_none().0,
480 dest.as_ref().to_glib_none().0,
481 );
482 }
483 }
484
485 #[doc(alias = "gst_element_unlink_pads")]
486 fn unlink_pads(&self, srcpadname: &str, dest: &impl IsA<Element>, destpadname: &str) {
487 unsafe {
488 ffi::gst_element_unlink_pads(
489 self.as_ref().to_glib_none().0,
490 srcpadname.to_glib_none().0,
491 dest.as_ref().to_glib_none().0,
492 destpadname.to_glib_none().0,
493 );
494 }
495 }
496
497 #[doc(alias = "no-more-pads")]
498 fn connect_no_more_pads<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
499 unsafe extern "C" fn no_more_pads_trampoline<
500 P: IsA<Element>,
501 F: Fn(&P) + Send + Sync + 'static,
502 >(
503 this: *mut ffi::GstElement,
504 f: glib::ffi::gpointer,
505 ) {
506 let f: &F = &*(f as *const F);
507 f(Element::from_glib_borrow(this).unsafe_cast_ref())
508 }
509 unsafe {
510 let f: Box_<F> = Box_::new(f);
511 connect_raw(
512 self.as_ptr() as *mut _,
513 b"no-more-pads\0".as_ptr() as *const _,
514 Some(transmute::<_, unsafe extern "C" fn()>(
515 no_more_pads_trampoline::<Self, F> as *const (),
516 )),
517 Box_::into_raw(f),
518 )
519 }
520 }
521
522 #[doc(alias = "pad-added")]
523 fn connect_pad_added<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
524 &self,
525 f: F,
526 ) -> SignalHandlerId {
527 unsafe extern "C" fn pad_added_trampoline<
528 P: IsA<Element>,
529 F: Fn(&P, &Pad) + Send + Sync + 'static,
530 >(
531 this: *mut ffi::GstElement,
532 new_pad: *mut ffi::GstPad,
533 f: glib::ffi::gpointer,
534 ) {
535 let f: &F = &*(f as *const F);
536 f(
537 Element::from_glib_borrow(this).unsafe_cast_ref(),
538 &from_glib_borrow(new_pad),
539 )
540 }
541 unsafe {
542 let f: Box_<F> = Box_::new(f);
543 connect_raw(
544 self.as_ptr() as *mut _,
545 b"pad-added\0".as_ptr() as *const _,
546 Some(transmute::<_, unsafe extern "C" fn()>(
547 pad_added_trampoline::<Self, F> as *const (),
548 )),
549 Box_::into_raw(f),
550 )
551 }
552 }
553
554 #[doc(alias = "pad-removed")]
555 fn connect_pad_removed<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
556 &self,
557 f: F,
558 ) -> SignalHandlerId {
559 unsafe extern "C" fn pad_removed_trampoline<
560 P: IsA<Element>,
561 F: Fn(&P, &Pad) + Send + Sync + 'static,
562 >(
563 this: *mut ffi::GstElement,
564 old_pad: *mut ffi::GstPad,
565 f: glib::ffi::gpointer,
566 ) {
567 let f: &F = &*(f as *const F);
568 f(
569 Element::from_glib_borrow(this).unsafe_cast_ref(),
570 &from_glib_borrow(old_pad),
571 )
572 }
573 unsafe {
574 let f: Box_<F> = Box_::new(f);
575 connect_raw(
576 self.as_ptr() as *mut _,
577 b"pad-removed\0".as_ptr() as *const _,
578 Some(transmute::<_, unsafe extern "C" fn()>(
579 pad_removed_trampoline::<Self, F> as *const (),
580 )),
581 Box_::into_raw(f),
582 )
583 }
584 }
585}
586
587impl<O: IsA<Element>> ElementExt for O {}
588