Skip to main content

gstreamer_webrtc/auto/
web_rtc_data_channel.rs

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::{WebRTCDataChannelState, WebRTCPriorityType, ffi};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{SignalHandlerId, connect_raw},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    #[doc(alias = "GstWebRTCDataChannel")]
18    pub struct WebRTCDataChannel(Object<ffi::GstWebRTCDataChannel, ffi::GstWebRTCDataChannelClass>);
19
20    match fn {
21        type_ => || ffi::gst_webrtc_data_channel_get_type(),
22    }
23}
24
25impl WebRTCDataChannel {
26    #[doc(alias = "gst_webrtc_data_channel_close")]
27    pub fn close(&self) {
28        unsafe {
29            ffi::gst_webrtc_data_channel_close(self.to_glib_none().0);
30        }
31    }
32
33    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
34    #[allow(deprecated)]
35    #[doc(alias = "gst_webrtc_data_channel_send_data")]
36    pub fn send_data(&self, data: Option<&glib::Bytes>) {
37        unsafe {
38            ffi::gst_webrtc_data_channel_send_data(self.to_glib_none().0, data.to_glib_none().0);
39        }
40    }
41
42    #[cfg(feature = "v1_22")]
43    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
44    #[doc(alias = "gst_webrtc_data_channel_send_data_full")]
45    pub fn send_data_full(&self, data: Option<&glib::Bytes>) -> Result<(), glib::Error> {
46        unsafe {
47            let mut error = std::ptr::null_mut();
48            let is_ok = ffi::gst_webrtc_data_channel_send_data_full(
49                self.to_glib_none().0,
50                data.to_glib_none().0,
51                &mut error,
52            );
53            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
54            if error.is_null() {
55                Ok(())
56            } else {
57                Err(from_glib_full(error))
58            }
59        }
60    }
61
62    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
63    #[allow(deprecated)]
64    #[doc(alias = "gst_webrtc_data_channel_send_string")]
65    pub fn send_string(&self, str: Option<&str>) {
66        unsafe {
67            ffi::gst_webrtc_data_channel_send_string(self.to_glib_none().0, str.to_glib_none().0);
68        }
69    }
70
71    #[cfg(feature = "v1_22")]
72    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
73    #[doc(alias = "gst_webrtc_data_channel_send_string_full")]
74    pub fn send_string_full(&self, str: Option<&str>) -> Result<(), glib::Error> {
75        unsafe {
76            let mut error = std::ptr::null_mut();
77            let is_ok = ffi::gst_webrtc_data_channel_send_string_full(
78                self.to_glib_none().0,
79                str.to_glib_none().0,
80                &mut error,
81            );
82            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
83            if error.is_null() {
84                Ok(())
85            } else {
86                Err(from_glib_full(error))
87            }
88        }
89    }
90
91    #[doc(alias = "buffered-amount")]
92    pub fn buffered_amount(&self) -> u64 {
93        ObjectExt::property(self, "buffered-amount")
94    }
95
96    #[doc(alias = "buffered-amount-low-threshold")]
97    pub fn buffered_amount_low_threshold(&self) -> u64 {
98        ObjectExt::property(self, "buffered-amount-low-threshold")
99    }
100
101    #[doc(alias = "buffered-amount-low-threshold")]
102    pub fn set_buffered_amount_low_threshold(&self, buffered_amount_low_threshold: u64) {
103        ObjectExt::set_property(
104            self,
105            "buffered-amount-low-threshold",
106            buffered_amount_low_threshold,
107        )
108    }
109
110    pub fn id(&self) -> i32 {
111        ObjectExt::property(self, "id")
112    }
113
114    pub fn label(&self) -> Option<glib::GString> {
115        ObjectExt::property(self, "label")
116    }
117
118    #[doc(alias = "max-packet-lifetime")]
119    pub fn max_packet_lifetime(&self) -> i32 {
120        ObjectExt::property(self, "max-packet-lifetime")
121    }
122
123    #[doc(alias = "max-retransmits")]
124    pub fn max_retransmits(&self) -> i32 {
125        ObjectExt::property(self, "max-retransmits")
126    }
127
128    pub fn is_negotiated(&self) -> bool {
129        ObjectExt::property(self, "negotiated")
130    }
131
132    pub fn is_ordered(&self) -> bool {
133        ObjectExt::property(self, "ordered")
134    }
135
136    pub fn priority(&self) -> WebRTCPriorityType {
137        ObjectExt::property(self, "priority")
138    }
139
140    pub fn protocol(&self) -> Option<glib::GString> {
141        ObjectExt::property(self, "protocol")
142    }
143
144    #[doc(alias = "ready-state")]
145    pub fn ready_state(&self) -> WebRTCDataChannelState {
146        ObjectExt::property(self, "ready-state")
147    }
148
149    #[doc(alias = "on-buffered-amount-low")]
150    pub fn connect_on_buffered_amount_low<F: Fn(&Self) + Send + Sync + 'static>(
151        &self,
152        f: F,
153    ) -> SignalHandlerId {
154        unsafe extern "C" fn on_buffered_amount_low_trampoline<
155            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
156        >(
157            this: *mut ffi::GstWebRTCDataChannel,
158            f: glib::ffi::gpointer,
159        ) {
160            unsafe {
161                let f: &F = &*(f as *const F);
162                f(&from_glib_borrow(this))
163            }
164        }
165        unsafe {
166            let f: Box_<F> = Box_::new(f);
167            connect_raw(
168                self.as_ptr() as *mut _,
169                c"on-buffered-amount-low".as_ptr(),
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
171                    on_buffered_amount_low_trampoline::<F> as *const (),
172                )),
173                Box_::into_raw(f),
174            )
175        }
176    }
177
178    #[doc(alias = "on-close")]
179    pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
180        unsafe extern "C" fn on_close_trampoline<
181            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
182        >(
183            this: *mut ffi::GstWebRTCDataChannel,
184            f: glib::ffi::gpointer,
185        ) {
186            unsafe {
187                let f: &F = &*(f as *const F);
188                f(&from_glib_borrow(this))
189            }
190        }
191        unsafe {
192            let f: Box_<F> = Box_::new(f);
193            connect_raw(
194                self.as_ptr() as *mut _,
195                c"on-close".as_ptr(),
196                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
197                    on_close_trampoline::<F> as *const (),
198                )),
199                Box_::into_raw(f),
200            )
201        }
202    }
203
204    #[doc(alias = "on-error")]
205    pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
206        &self,
207        f: F,
208    ) -> SignalHandlerId {
209        unsafe extern "C" fn on_error_trampoline<
210            F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
211        >(
212            this: *mut ffi::GstWebRTCDataChannel,
213            error: *mut glib::ffi::GError,
214            f: glib::ffi::gpointer,
215        ) {
216            unsafe {
217                let f: &F = &*(f as *const F);
218                f(&from_glib_borrow(this), &from_glib_borrow(error))
219            }
220        }
221        unsafe {
222            let f: Box_<F> = Box_::new(f);
223            connect_raw(
224                self.as_ptr() as *mut _,
225                c"on-error".as_ptr(),
226                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
227                    on_error_trampoline::<F> as *const (),
228                )),
229                Box_::into_raw(f),
230            )
231        }
232    }
233
234    #[doc(alias = "on-message-data")]
235    pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
236        &self,
237        f: F,
238    ) -> SignalHandlerId {
239        unsafe extern "C" fn on_message_data_trampoline<
240            F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
241        >(
242            this: *mut ffi::GstWebRTCDataChannel,
243            data: *mut glib::ffi::GBytes,
244            f: glib::ffi::gpointer,
245        ) {
246            unsafe {
247                let f: &F = &*(f as *const F);
248                f(
249                    &from_glib_borrow(this),
250                    Option::<glib::Bytes>::from_glib_borrow(data)
251                        .as_ref()
252                        .as_ref(),
253                )
254            }
255        }
256        unsafe {
257            let f: Box_<F> = Box_::new(f);
258            connect_raw(
259                self.as_ptr() as *mut _,
260                c"on-message-data".as_ptr(),
261                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262                    on_message_data_trampoline::<F> as *const (),
263                )),
264                Box_::into_raw(f),
265            )
266        }
267    }
268
269    #[doc(alias = "on-message-string")]
270    pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
271        &self,
272        f: F,
273    ) -> SignalHandlerId {
274        unsafe extern "C" fn on_message_string_trampoline<
275            F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
276        >(
277            this: *mut ffi::GstWebRTCDataChannel,
278            data: *mut std::ffi::c_char,
279            f: glib::ffi::gpointer,
280        ) {
281            unsafe {
282                let f: &F = &*(f as *const F);
283                f(
284                    &from_glib_borrow(this),
285                    Option::<glib::GString>::from_glib_borrow(data)
286                        .as_ref()
287                        .as_ref()
288                        .map(|s| s.as_str()),
289                )
290            }
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                c"on-message-string".as_ptr(),
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    on_message_string_trampoline::<F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304
305    #[doc(alias = "on-open")]
306    pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
307        unsafe extern "C" fn on_open_trampoline<
308            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
309        >(
310            this: *mut ffi::GstWebRTCDataChannel,
311            f: glib::ffi::gpointer,
312        ) {
313            unsafe {
314                let f: &F = &*(f as *const F);
315                f(&from_glib_borrow(this))
316            }
317        }
318        unsafe {
319            let f: Box_<F> = Box_::new(f);
320            connect_raw(
321                self.as_ptr() as *mut _,
322                c"on-open".as_ptr(),
323                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324                    on_open_trampoline::<F> as *const (),
325                )),
326                Box_::into_raw(f),
327            )
328        }
329    }
330
331    #[doc(alias = "buffered-amount")]
332    pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
333        &self,
334        f: F,
335    ) -> SignalHandlerId {
336        unsafe extern "C" fn notify_buffered_amount_trampoline<
337            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
338        >(
339            this: *mut ffi::GstWebRTCDataChannel,
340            _param_spec: glib::ffi::gpointer,
341            f: glib::ffi::gpointer,
342        ) {
343            unsafe {
344                let f: &F = &*(f as *const F);
345                f(&from_glib_borrow(this))
346            }
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                c"notify::buffered-amount".as_ptr(),
353                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354                    notify_buffered_amount_trampoline::<F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    #[doc(alias = "buffered-amount-low-threshold")]
362    pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
363        &self,
364        f: F,
365    ) -> SignalHandlerId {
366        unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
367            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
368        >(
369            this: *mut ffi::GstWebRTCDataChannel,
370            _param_spec: glib::ffi::gpointer,
371            f: glib::ffi::gpointer,
372        ) {
373            unsafe {
374                let f: &F = &*(f as *const F);
375                f(&from_glib_borrow(this))
376            }
377        }
378        unsafe {
379            let f: Box_<F> = Box_::new(f);
380            connect_raw(
381                self.as_ptr() as *mut _,
382                c"notify::buffered-amount-low-threshold".as_ptr(),
383                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
384                    notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
385                )),
386                Box_::into_raw(f),
387            )
388        }
389    }
390
391    #[doc(alias = "ready-state")]
392    pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
393        &self,
394        f: F,
395    ) -> SignalHandlerId {
396        unsafe extern "C" fn notify_ready_state_trampoline<
397            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
398        >(
399            this: *mut ffi::GstWebRTCDataChannel,
400            _param_spec: glib::ffi::gpointer,
401            f: glib::ffi::gpointer,
402        ) {
403            unsafe {
404                let f: &F = &*(f as *const F);
405                f(&from_glib_borrow(this))
406            }
407        }
408        unsafe {
409            let f: Box_<F> = Box_::new(f);
410            connect_raw(
411                self.as_ptr() as *mut _,
412                c"notify::ready-state".as_ptr(),
413                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
414                    notify_ready_state_trampoline::<F> as *const (),
415                )),
416                Box_::into_raw(f),
417            )
418        }
419    }
420}
421
422unsafe impl Send for WebRTCDataChannel {}
423unsafe impl Sync for WebRTCDataChannel {}