Skip to main content

gstreamer/subclass/
tracer.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(not(feature = "v1_26"))]
4use {crate::value::GstValueExt, std::str::FromStr};
5
6use glib::{prelude::*, subclass::prelude::*, translate::*};
7
8use super::prelude::*;
9use crate::{
10    Bin, Buffer, BufferList, Element, Event, FlowError, FlowSuccess, Message, MiniObject, Object,
11    Pad, PadLinkError, PadLinkSuccess, QueryRef, StateChange, StateChangeError, StateChangeSuccess,
12    Tracer, ffi,
13};
14#[cfg(feature = "v1_30")]
15use crate::{TraceFormat, TraceSpanId, TraceValues};
16
17#[allow(unused_variables)]
18pub trait TracerImpl: GstObjectImpl + ObjectSubclass<Type: IsA<Tracer>> {
19    // rustdoc-stripper-ignore-next
20    /// Whether to use `gst::Structure` style "params" and automatically pass
21    /// them to the corresponding properties during instantiation.
22    const USE_STRUCTURE_PARAMS: bool = false;
23
24    fn bin_add_post(&self, ts: u64, bin: &Bin, element: &Element, success: bool) {}
25    fn bin_add_pre(&self, ts: u64, bin: &Bin, element: &Element) {}
26    fn bin_remove_post(&self, ts: u64, bin: &Bin, success: bool) {}
27    fn bin_remove_pre(&self, ts: u64, bin: &Bin, element: &Element) {}
28    fn element_new(&self, ts: u64, element: &Element) {}
29    fn element_add_pad(&self, ts: u64, element: &Element, pad: &Pad) {}
30    fn element_remove_pad(&self, ts: u64, element: &Element, pad: &Pad) {}
31    fn element_change_state_post(
32        &self,
33        ts: u64,
34        element: &Element,
35        change: StateChange,
36        result: Result<StateChangeSuccess, StateChangeError>,
37    ) {
38    }
39    fn element_change_state_pre(&self, ts: u64, element: &Element, change: StateChange) {}
40    fn element_post_message_post(&self, ts: u64, element: &Element, success: bool) {}
41    fn element_post_message_pre(&self, ts: u64, element: &Element, message: &Message) {}
42    fn element_query_post(&self, ts: u64, element: &Element, query: &QueryRef, success: bool) {}
43    fn element_query_pre(&self, ts: u64, element: &Element, query: &QueryRef) {}
44    // rustdoc-stripper-ignore-next
45    /// Hook to be called before the GstMiniObject has been fully initialized.
46    fn mini_object_created(&self, ts: u64, object: std::ptr::NonNull<ffi::GstMiniObject>) {}
47    // rustdoc-stripper-ignore-next
48    /// Hook to be called after the GstMiniObject has been finalized.
49    fn mini_object_destroyed(&self, ts: u64, object: std::ptr::NonNull<ffi::GstMiniObject>) {}
50    fn mini_object_reffed(&self, ts: u64, object: &MiniObject, new_refcount: i32) {}
51    fn mini_object_unreffed(&self, ts: u64, object: &MiniObject, new_refcount: i32) {}
52    fn object_created(&self, ts: u64, object: &Object) {}
53    // rustdoc-stripper-ignore-next
54    /// Hook to be called after the GstObject has been finalized.
55    fn object_destroyed(&self, ts: u64, object: std::ptr::NonNull<ffi::GstObject>) {}
56    fn object_reffed(&self, ts: u64, object: &Object, new_refcount: i32) {}
57    fn object_unreffed(&self, ts: u64, object: &Object, new_refcount: i32) {}
58    fn pad_link_post(
59        &self,
60        ts: u64,
61        src: &Pad,
62        sink: &Pad,
63        result: Result<PadLinkSuccess, PadLinkError>,
64    ) {
65    }
66    fn pad_link_pre(&self, ts: u64, src: &Pad, sink: &Pad) {}
67    fn pad_pull_range_post(&self, ts: u64, pad: &Pad, result: Result<&Buffer, FlowError>) {}
68    fn pad_pull_range_pre(&self, ts: u64, pad: &Pad, offset: u64, size: u32) {}
69    fn pad_push_event_post(&self, ts: u64, pad: &Pad, success: bool) {}
70    fn pad_push_event_pre(&self, ts: u64, pad: &Pad, event: &Event) {}
71    #[cfg(feature = "v1_22")]
72    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
73    fn pad_chain_list_post(&self, ts: u64, pad: &Pad, result: Result<FlowSuccess, FlowError>) {}
74    #[cfg(feature = "v1_22")]
75    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
76    fn pad_chain_list_pre(&self, ts: u64, pad: &Pad, buffer_list: &BufferList) {}
77    #[cfg(feature = "v1_22")]
78    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
79    fn pad_chain_post(&self, ts: u64, pad: &Pad, result: Result<FlowSuccess, FlowError>) {}
80    #[cfg(feature = "v1_22")]
81    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
82    fn pad_chain_pre(&self, ts: u64, pad: &Pad, buffer: &Buffer) {}
83    fn pad_push_list_post(&self, ts: u64, pad: &Pad, result: Result<FlowSuccess, FlowError>) {}
84    fn pad_push_list_pre(&self, ts: u64, pad: &Pad, buffer_list: &BufferList) {}
85    fn pad_push_post(&self, ts: u64, pad: &Pad, result: Result<FlowSuccess, FlowError>) {}
86    fn pad_push_pre(&self, ts: u64, pad: &Pad, buffer: &Buffer) {}
87    fn pad_query_post(&self, ts: u64, pad: &Pad, query: &QueryRef, success: bool) {}
88    fn pad_query_pre(&self, ts: u64, pad: &Pad, query: &QueryRef) {}
89    fn pad_unlink_post(&self, ts: u64, src: &Pad, sink: &Pad, success: bool) {}
90    fn pad_unlink_pre(&self, ts: u64, src: &Pad, sink: &Pad) {}
91    #[cfg(feature = "v1_20")]
92    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
93    fn plugin_feature_loaded(&self, ts: u64, feature: &crate::PluginFeature) {}
94    #[cfg(feature = "v1_26")]
95    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
96    fn memory_init(&self, ts: u64, mem: &crate::MemoryRefTrace) {}
97    #[cfg(feature = "v1_26")]
98    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
99    fn memory_free_pre(&self, ts: u64, mem: &crate::MemoryRef) {}
100    #[cfg(feature = "v1_26")]
101    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
102    fn memory_free_post(&self, ts: u64, mem: std::ptr::NonNull<ffi::GstMemory>) {}
103
104    #[cfg(feature = "v1_28")]
105    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
106    fn pool_buffer_queued(&self, ts: u64, pool: &crate::BufferPool, buffer: &Buffer) {}
107    #[cfg(feature = "v1_28")]
108    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
109    fn pool_buffer_dequeued(&self, ts: u64, pool: &crate::BufferPool, buffer: &Buffer) {}
110    #[cfg(feature = "v1_30")]
111    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
112    fn object_parent_set(&self, ts: u64, object: &crate::Object, parent: Option<&Object>) {}
113    #[cfg(feature = "v1_30")]
114    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
115    fn span_begin(&self, ts: u64, span_id: TraceSpanId, values: TraceValues<'_>) {}
116    #[cfg(feature = "v1_30")]
117    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
118    fn span_end(&self, ts: u64, span_id: TraceSpanId) {}
119}
120
121#[cfg(not(feature = "v1_26"))]
122fn format_available_properties(class: &glib::object::ObjectClass) -> String {
123    class
124        .list_properties()
125        .iter()
126        .filter(|p| {
127            p.flags().contains(glib::ParamFlags::WRITABLE)
128                && p.name() != "parent"
129                && p.name() != "params"
130        })
131        .map(|p| format!("  {}: {}", p.name(), p.blurb().map_or("", |b| b)))
132        .collect::<Vec<_>>()
133        .join("\n")
134}
135
136#[cfg(not(feature = "v1_26"))]
137fn emit_property_warning(obj: &glib::Object, msg: &str) {
138    let props = format_available_properties(obj.class());
139    glib::g_warning!("gsttracer", "{}\nAvailable properties:\n{}", msg, props);
140}
141
142unsafe impl<T: TracerImpl> IsSubclassable<T> for Tracer {
143    fn class_init(class: &mut glib::Class<Self>) {
144        Self::parent_class_init::<T>(class);
145
146        #[cfg(feature = "v1_26")]
147        {
148            let class = class.as_mut();
149            unsafe {
150                ffi::gst_tracer_class_set_use_structure_params(
151                    class,
152                    T::USE_STRUCTURE_PARAMS.into_glib(),
153                );
154            }
155        }
156        #[cfg(not(feature = "v1_26"))]
157        unsafe {
158            if T::USE_STRUCTURE_PARAMS {
159                use std::sync::OnceLock;
160                static TRACER_CONSTRUCTED_FUNC: OnceLock<
161                    unsafe extern "C" fn(*mut glib::gobject_ffi::GObject),
162                > = OnceLock::new();
163
164                let class =
165                    &mut *(class.as_mut() as *mut _ as *mut glib::gobject_ffi::GObjectClass);
166                TRACER_CONSTRUCTED_FUNC.get_or_init(|| class.constructed.unwrap());
167                unsafe extern "C" fn constructed(objptr: *mut glib::gobject_ffi::GObject) {
168                    let obj = unsafe { glib::Object::from_glib_ptr_borrow(&objptr) };
169                    let params = obj.property::<Option<String>>("params");
170
171                    let Some(params) = params else {
172                        unsafe {
173                            TRACER_CONSTRUCTED_FUNC.get().unwrap()(objptr);
174                        }
175
176                        return;
177                    };
178
179                    if params.is_empty() {
180                        unsafe {
181                            TRACER_CONSTRUCTED_FUNC.get().unwrap()(objptr);
182                        }
183
184                        return;
185                    }
186
187                    let s = match crate::Structure::from_str(&format!("tracer-settings,{params}")) {
188                        Ok(s) => s,
189                        Err(err) => {
190                            emit_property_warning(
191                                obj,
192                                &format!(
193                                    "Can't setup tracer {err:?}: invalid parameters '{params}'"
194                                ),
195                            );
196                            return;
197                        }
198                    };
199
200                    let class = obj.class();
201
202                    for (field, field_value) in s.iter() {
203                        let pspec = match class.find_property(field.as_str()) {
204                            Some(p) => p,
205                            None => {
206                                emit_property_warning(
207                                    obj,
208                                    &format!(
209                                        "Can't setup tracer: property '{}' not found",
210                                        field.as_str()
211                                    ),
212                                );
213                                return;
214                            }
215                        };
216
217                        let value = if field_value.type_() == pspec.value_type() {
218                            field_value.to_value()
219                        } else if field_value.type_() == glib::types::Type::STRING {
220                            let str_val = field_value.get::<String>().unwrap();
221                            #[cfg(feature = "v1_20")]
222                            {
223                                match glib::Value::deserialize_with_pspec(&str_val, &pspec) {
224                                    Ok(v) => v,
225                                    Err(_) => {
226                                        emit_property_warning(
227                                            obj,
228                                            &format!(
229                                                "Can't instantiate tracer: invalid property '{}' value: '{}'",
230                                                field.as_str(),
231                                                str_val
232                                            ),
233                                        );
234                                        return;
235                                    }
236                                }
237                            }
238                            #[cfg(not(feature = "v1_20"))]
239                            {
240                                match glib::Value::deserialize(&str_val, pspec.value_type()) {
241                                    Ok(v) => v,
242                                    Err(_) => {
243                                        emit_property_warning(
244                                            obj,
245                                            &format!(
246                                                "Can't instantiate tracer: invalid property '{}' value: '{}'",
247                                                field.as_str(),
248                                                str_val
249                                            ),
250                                        );
251                                        return;
252                                    }
253                                }
254                            }
255                        } else {
256                            emit_property_warning(
257                                obj,
258                                &format!(
259                                    "Can't setup tracer: property '{}' type mismatch, expected {}, got {}",
260                                    field.as_str(),
261                                    pspec.value_type().name(),
262                                    field_value.type_().name()
263                                ),
264                            );
265                            return;
266                        };
267
268                        crate::debug!(crate::CAT_RUST, "Setting property {field:?}");
269                        obj.set_property(field.as_str(), &value);
270                    }
271
272                    unsafe {
273                        TRACER_CONSTRUCTED_FUNC.get().unwrap()(objptr);
274                    }
275                }
276
277                class.constructed = Some(constructed);
278            }
279        }
280    }
281}
282
283pub trait TracerImplExt: TracerImpl {
284    // rustdoc-stripper-ignore-next
285    /// Register a corresponding hook to be called for this tracer when certain events occur.
286    ///
287    /// Upon an event a corresponding method in `TracerImpl` will be called.
288    fn register_hook(&self, hook: TracerHook);
289}
290
291macro_rules! define_tracer_hooks {
292    ($($(#[$attr:meta])* $name: ident($quark: literal) = |$this: ident, $ts: ident, $($cb_arg: ident: $cb_arg_ty: ty),*| $impl: block;)*) => {
293        pub enum TracerHook {
294            $($(#[$attr])* $name),*
295        }
296        impl<T: TracerImpl> TracerImplExt for T {
297            fn register_hook(&self, hook: TracerHook) {
298                use TracerHook::*;
299                let (hook_type, callback) = match hook {
300                    $($(#[$attr])* $name => {
301                        #[allow(non_snake_case)]
302                        unsafe extern "C" fn callback<T: TracerImpl>(
303                            $this: *mut ffi::GstTracer,
304                            $ts: u64,
305                            $($cb_arg: $cb_arg_ty),*
306                        ) { unsafe {
307                            let $this = Tracer::from_glib_borrow($this);
308                            let $this = T::from_obj($this.unsafe_cast_ref());
309                            $impl
310                        }}
311                        (
312                            concat!($quark, "\0"),
313                            callback::<T> as unsafe extern "C" fn(_, _, $($cb_arg_ty),*) as *const ()
314                        )
315                    },)*
316                };
317                unsafe {
318                    let instance = self.obj();
319                    ffi::gst_tracing_register_hook(
320                        instance.to_glib_none().0 as *mut ffi::GstTracer,
321                        hook_type.as_ptr() as *const _,
322                        Some(std::mem::transmute::<*const (), extern "C" fn()>(callback)),
323                    );
324                }
325            }
326        }
327    };
328}
329
330define_tracer_hooks! {
331    BinAddPost("bin-add-post") = |this, ts, b: *mut ffi::GstBin, e: *mut ffi::GstElement, r: glib::ffi::gboolean| {
332        let b = Bin::from_glib_borrow(b);
333        let e = Element::from_glib_borrow(e);
334        this.bin_add_post(ts, &b, &e, bool::from_glib(r))
335    };
336    BinAddPre("bin-add-pre") = |this, ts, b: *mut ffi::GstBin, e: *mut ffi::GstElement| {
337        let b = Bin::from_glib_borrow(b);
338        let e = Element::from_glib_borrow(e);
339        this.bin_add_pre(ts, &b, &e)
340    };
341    BinRemovePost("bin-remove-post") = |this, ts, b: *mut ffi::GstBin, r: glib::ffi::gboolean| {
342        let b = Bin::from_glib_borrow(b);
343        this.bin_remove_post(ts, &b, bool::from_glib(r))
344    };
345    BinRemovePre("bin-remove-pre") = |this, ts, b: *mut ffi::GstBin, e: *mut ffi::GstElement| {
346        let b = Bin::from_glib_borrow(b);
347        let e = Element::from_glib_borrow(e);
348        this.bin_remove_pre(ts, &b, &e)
349    };
350    ElementNew("element-new") = |this, ts, e: *mut ffi::GstElement| {
351        let e = Element::from_glib_borrow(e);
352        this.element_new(ts, &e)
353    };
354    ElementAddPad("element-add-pad") = |this, ts, e: *mut ffi::GstElement, p: *mut ffi::GstPad| {
355        let e = Element::from_glib_borrow(e);
356        let p = Pad::from_glib_borrow(p);
357        this.element_add_pad(ts, &e, &p)
358    };
359    ElementRemovePad("element-remove-pad") = |this, ts, e: *mut ffi::GstElement, p: *mut ffi::GstPad| {
360        let e = Element::from_glib_borrow(e);
361        let p = Pad::from_glib_borrow(p);
362        this.element_remove_pad(ts, &e, &p)
363    };
364    ElementChangeStatePost("element-change-state-post") = |this, ts, e: *mut ffi::GstElement, c: ffi::GstStateChange, r: ffi::GstStateChangeReturn| {
365        let e = Element::from_glib_borrow(e);
366        this.element_change_state_post(ts, &e, StateChange::from_glib(c), try_from_glib(r))
367    };
368    ElementChangeStatePre("element-change-state-pre") = |this, ts, e: *mut ffi::GstElement, c: ffi::GstStateChange| {
369        let e = Element::from_glib_borrow(e);
370        this.element_change_state_pre(ts, &e, StateChange::from_glib(c))
371    };
372    ElementPostMessagePost("element-post-message-post") = |this, ts, e: *mut ffi::GstElement, r: glib::ffi::gboolean| {
373        let e = Element::from_glib_borrow(e);
374        this.element_post_message_post(ts, &e, bool::from_glib(r))
375    };
376    ElementPostMessagePre("element-post-message-pre") = |this, ts, e: *mut ffi::GstElement, m: *mut ffi::GstMessage| {
377        let e = Element::from_glib_borrow(e);
378        let m = Message::from_glib_borrow(m);
379        this.element_post_message_pre(ts, &e, &m)
380    };
381    ElementQueryPost("element-query-post") = |this, ts, e: *mut ffi::GstElement, q: *mut ffi::GstQuery, r: glib::ffi::gboolean| {
382        let e = Element::from_glib_borrow(e);
383        let q = QueryRef::from_ptr(q);
384        this.element_query_post(ts, &e, q, bool::from_glib(r))
385    };
386    ElementQueryPre("element-query-pre") = |this, ts, e: *mut ffi::GstElement, q: *mut ffi::GstQuery| {
387        let e = Element::from_glib_borrow(e);
388        let q = QueryRef::from_ptr(q);
389        this.element_query_pre(ts, &e, q)
390    };
391    // TODO: unclear what to do here as the `GstMiniObject` here is not fully initialized yet…
392    MiniObjectCreated("mini-object-created") = |this, ts, o: *mut ffi::GstMiniObject| {
393        this.mini_object_created(ts, std::ptr::NonNull::new_unchecked(o))
394    };
395    // TODO: unclear what to do here as the `GstMiniObject` here is no longer valid…
396    MiniObjectDestroyed("mini-object-destroyed") = |this, ts, o: *mut ffi::GstMiniObject| {
397        this.mini_object_destroyed(ts, std::ptr::NonNull::new_unchecked(o))
398    };
399    MiniObjectReffed("mini-object-reffed") = |this, ts, o: *mut ffi::GstMiniObject, rc: libc::c_int| {
400        let o = MiniObject::from_glib_borrow(o);
401        this.mini_object_reffed(ts, &o, rc)
402    };
403    MiniObjectUnreffed("mini-object-unreffed") = |this, ts, o: *mut ffi::GstMiniObject, rc: libc::c_int| {
404        let o = MiniObject::from_glib_borrow(o);
405        this.mini_object_unreffed(ts, &o, rc)
406    };
407    ObjectCreated("object-created") = |this, ts, o: *mut ffi::GstObject| {
408        let o = Object::from_glib_borrow(o);
409        this.object_created(ts, &o)
410    };
411    // TODO: unclear what to do here as the `GstObject` here is no longer valid…
412    ObjectDestroyed("object-destroyed") = |this, ts, o: *mut ffi::GstObject| {
413        this.object_destroyed(ts, std::ptr::NonNull::new_unchecked(o))
414    };
415    ObjectReffed("object-reffed") = |this, ts, o: *mut ffi::GstObject, rc: libc::c_int| {
416        let o = Object::from_glib_borrow(o);
417        this.object_reffed(ts, &o, rc)
418    };
419    ObjectUnreffed("object-unreffed") = |this, ts, o: *mut ffi::GstObject, rc: libc::c_int| {
420        let o = Object::from_glib_borrow(o);
421        this.object_unreffed(ts, &o, rc)
422    };
423    #[cfg(feature = "v1_30")]
424    ObjectParentSet("object-parent-set") = |this, ts, o: *mut ffi::GstObject, p: *mut ffi::GstObject| {
425        let o = Object::from_glib_borrow(o);
426        let p = if p.is_null() { None } else { Some(Object::from_glib_borrow(p)) };
427        this.object_parent_set(ts, &o, p.as_deref())
428    };
429    #[cfg(feature = "v1_30")]
430    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
431    SpanBegin("span-begin") = |this, ts, span_id: ffi::GstTraceSpanId, format: *mut ffi::GstTraceFormat, values: *const ffi::GstTraceValue| {
432        let Some(span_id) = TraceSpanId::from_glib(span_id) else {
433            return;
434        };
435        let format = TraceFormat::from_glib_borrow(format);
436        let n_fields = format.n_fields();
437        this.span_begin(ts, span_id, TraceValues::from_glib(format, values, n_fields))
438    };
439    #[cfg(feature = "v1_30")]
440    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
441    SpanEnd("span-end") = |this, ts, span_id: ffi::GstTraceSpanId| {
442        let Some(span_id) = TraceSpanId::from_glib(span_id) else {
443            return;
444        };
445        this.span_end(ts, span_id)
446    };
447    PadLinkPost("pad-link-post") = |this, ts, src: *mut ffi::GstPad, sink: *mut ffi::GstPad, r: ffi::GstPadLinkReturn| {
448        let src = Pad::from_glib_borrow(src);
449        let sink = Pad::from_glib_borrow(sink);
450        this.pad_link_post(ts, &src, &sink, try_from_glib(r))
451    };
452    PadLinkPre("pad-link-pre") = |this, ts, src: *mut ffi::GstPad, sink: *mut ffi::GstPad| {
453        let src = Pad::from_glib_borrow(src);
454        let sink = Pad::from_glib_borrow(sink);
455        this.pad_link_pre(ts, &src, &sink)
456    };
457    PadPullRangePost("pad-pull-range-post") = |this, ts, p: *mut ffi::GstPad, b: *mut ffi::GstBuffer, r: ffi::GstFlowReturn| {
458        let p = Pad::from_glib_borrow(p);
459        let res: Result::<FlowSuccess, FlowError> = try_from_glib(r);
460        match res {
461            Ok(_) => {
462                this.pad_pull_range_post(ts, &p, Ok(&from_glib_borrow(b)))
463            }
464            Err(err) => {
465                this.pad_pull_range_post(ts, &p, Err(err))
466            }
467        }
468    };
469    PadPullRangePre("pad-pull-range-pre") = |this, ts, p: *mut ffi::GstPad, o: u64, s: libc::c_uint| {
470        let p = Pad::from_glib_borrow(p);
471        this.pad_pull_range_pre(ts, &p, o, s)
472    };
473    PadPushEventPost("pad-push-event-post") = |this, ts, p: *mut ffi::GstPad, r: glib::ffi::gboolean| {
474        let p = Pad::from_glib_borrow(p);
475        this.pad_push_event_post(ts, &p, bool::from_glib(r))
476    };
477    PadPushEventPre("pad-push-event-pre") = |this, ts, p: *mut ffi::GstPad, e: *mut ffi::GstEvent| {
478        let p = Pad::from_glib_borrow(p);
479        let e = Event::from_glib_borrow(e);
480        this.pad_push_event_pre(ts, &p, &e)
481    };
482    PadPushListPost("pad-push-list-post") = |this, ts, p: *mut ffi::GstPad, r: ffi::GstFlowReturn| {
483        let p = Pad::from_glib_borrow(p);
484        this.pad_push_list_post(ts, &p, try_from_glib(r))
485    };
486    PadPushListPre("pad-push-list-pre") = |this, ts, p: *mut ffi::GstPad, bl: *mut ffi::GstBufferList| {
487        let p = Pad::from_glib_borrow(p);
488        let bl = BufferList::from_glib_borrow(bl);
489        this.pad_push_list_pre(ts, &p, &bl)
490    };
491    PadPushPost("pad-push-post") = |this, ts, p: *mut ffi::GstPad, r: ffi::GstFlowReturn| {
492        let p = Pad::from_glib_borrow(p);
493        this.pad_push_post(ts, &p, try_from_glib(r))
494    };
495    PadPushPre("pad-push-pre") = |this, ts, p: *mut ffi::GstPad, b: *mut ffi::GstBuffer| {
496        let p = Pad::from_glib_borrow(p);
497        let b = Buffer::from_glib_borrow(b);
498        this.pad_push_pre(ts, &p, &b)
499    };
500    #[cfg(feature = "v1_22")]
501    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
502    PadChainListPost("pad-chain-list-post") = |this, ts, p: *mut ffi::GstPad, r: ffi::GstFlowReturn| {
503        let p = Pad::from_glib_borrow(p);
504        this.pad_chain_list_post(ts, &p, try_from_glib(r))
505    };
506    #[cfg(feature = "v1_22")]
507    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
508    PadChainListPre("pad-chain-list-pre") = |this, ts, p: *mut ffi::GstPad, bl: *mut ffi::GstBufferList| {
509        let p = Pad::from_glib_borrow(p);
510        let bl = BufferList::from_glib_borrow(bl);
511        this.pad_chain_list_pre(ts, &p, &bl)
512    };
513    #[cfg(feature = "v1_22")]
514    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
515    PadChainPost("pad-chain-post") = |this, ts, p: *mut ffi::GstPad, r: ffi::GstFlowReturn| {
516        let p = Pad::from_glib_borrow(p);
517        this.pad_chain_post(ts, &p, try_from_glib(r))
518    };
519    #[cfg(feature = "v1_22")]
520    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
521    PadChainPre("pad-chain-pre") = |this, ts, p: *mut ffi::GstPad, b: *mut ffi::GstBuffer| {
522        let p = Pad::from_glib_borrow(p);
523        let b = Buffer::from_glib_borrow(b);
524        this.pad_chain_pre(ts, &p, &b)
525    };
526    PadQueryPost("pad-query-post") = |this, ts, p: *mut ffi::GstPad, q: *mut ffi::GstQuery, r: glib::ffi::gboolean| {
527        let p = Pad::from_glib_borrow(p);
528        let q = QueryRef::from_ptr(q);
529        this.pad_query_post(ts, &p, q, bool::from_glib(r))
530    };
531    PadQueryPre("pad-query-pre") = |this, ts, p: *mut ffi::GstPad, q: *mut ffi::GstQuery| {
532        let p = Pad::from_glib_borrow(p);
533        let q = QueryRef::from_ptr(q);
534        this.pad_query_pre(ts, &p, q)
535    };
536    PadUnlinkPost("pad-unlink-post") = |this, ts, src: *mut ffi::GstPad, sink: *mut ffi::GstPad, r: glib::ffi::gboolean| {
537        let src = Pad::from_glib_borrow(src);
538        let sink = Pad::from_glib_borrow(sink);
539        this.pad_unlink_post(ts, &src, &sink, bool::from_glib(r))
540    };
541    PadUnlinkPre("pad-unlink-pre") = |this, ts, src: *mut ffi::GstPad, sink: *mut ffi::GstPad| {
542        let src = Pad::from_glib_borrow(src);
543        let sink = Pad::from_glib_borrow(sink);
544        this.pad_unlink_pre(ts, &src, &sink)
545    };
546    #[cfg(feature = "v1_20")]
547    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
548    PluginFeatureLoaded("plugin-feature-loaded") = |this, ts, feature: *mut ffi::GstPluginFeature| {
549        let feature = crate::PluginFeature::from_glib_borrow(feature);
550        this.plugin_feature_loaded(ts, &feature)
551    };
552
553    #[cfg(feature = "v1_26")]
554    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
555    MemoryInit("memory-init") = |this, ts, memory: *mut ffi::GstMemory| {
556        let memory = crate::MemoryRefTrace::from_ptr(memory);
557        this.memory_init(ts, memory)
558    };
559    #[cfg(feature = "v1_26")]
560    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
561    MemoryFreePre("memory-free-pre") = |this, ts, memory: *mut ffi::GstMemory| {
562        let memory = crate::MemoryRef::from_ptr(memory);
563        this.memory_free_pre(ts, memory)
564    };
565    #[cfg(feature = "v1_26")]
566    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
567    MemoryFreePost("memory-free-post") = |this, ts, memory: *mut ffi::GstMemory| {
568        this.memory_free_post(ts, std::ptr::NonNull::new_unchecked(memory))
569    };
570    #[cfg(feature = "v1_28")]
571    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
572    PoolBufferQueued("pool-buffer-queued") = |this, ts, pool: *mut ffi::GstBufferPool, buffer: *mut ffi::GstBuffer| {
573        let pool = crate::BufferPool::from_glib_borrow(pool);
574        let b = Buffer::from_glib_borrow(buffer);
575
576        this.pool_buffer_queued(ts, &pool, &b)
577    };
578    #[cfg(feature = "v1_28")]
579    #[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
580    PoolBufferDequeued("pool-buffer-dequeued") = |this, ts, pool: *mut ffi::GstBufferPool, buffer: *mut ffi::GstBuffer| {
581        let pool = crate::BufferPool::from_glib_borrow(pool);
582        let b = Buffer::from_glib_borrow(buffer);
583
584        this.pool_buffer_dequeued(ts, &pool, &b)
585    };
586}