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::{ffi, WebRTCDataChannelState, WebRTCPriorityType};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
161            f(&from_glib_borrow(this))
162        }
163        unsafe {
164            let f: Box_<F> = Box_::new(f);
165            connect_raw(
166                self.as_ptr() as *mut _,
167                c"on-buffered-amount-low".as_ptr() as *const _,
168                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
169                    on_buffered_amount_low_trampoline::<F> as *const (),
170                )),
171                Box_::into_raw(f),
172            )
173        }
174    }
175
176    #[doc(alias = "on-close")]
177    pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
178        unsafe extern "C" fn on_close_trampoline<
179            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
180        >(
181            this: *mut ffi::GstWebRTCDataChannel,
182            f: glib::ffi::gpointer,
183        ) {
184            let f: &F = &*(f as *const F);
185            f(&from_glib_borrow(this))
186        }
187        unsafe {
188            let f: Box_<F> = Box_::new(f);
189            connect_raw(
190                self.as_ptr() as *mut _,
191                c"on-close".as_ptr() as *const _,
192                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193                    on_close_trampoline::<F> as *const (),
194                )),
195                Box_::into_raw(f),
196            )
197        }
198    }
199
200    #[doc(alias = "on-error")]
201    pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
202        &self,
203        f: F,
204    ) -> SignalHandlerId {
205        unsafe extern "C" fn on_error_trampoline<
206            F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
207        >(
208            this: *mut ffi::GstWebRTCDataChannel,
209            error: *mut glib::ffi::GError,
210            f: glib::ffi::gpointer,
211        ) {
212            let f: &F = &*(f as *const F);
213            f(&from_glib_borrow(this), &from_glib_borrow(error))
214        }
215        unsafe {
216            let f: Box_<F> = Box_::new(f);
217            connect_raw(
218                self.as_ptr() as *mut _,
219                c"on-error".as_ptr() as *const _,
220                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221                    on_error_trampoline::<F> as *const (),
222                )),
223                Box_::into_raw(f),
224            )
225        }
226    }
227
228    #[doc(alias = "on-message-data")]
229    pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
230        &self,
231        f: F,
232    ) -> SignalHandlerId {
233        unsafe extern "C" fn on_message_data_trampoline<
234            F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
235        >(
236            this: *mut ffi::GstWebRTCDataChannel,
237            data: *mut glib::ffi::GBytes,
238            f: glib::ffi::gpointer,
239        ) {
240            let f: &F = &*(f as *const F);
241            f(
242                &from_glib_borrow(this),
243                Option::<glib::Bytes>::from_glib_borrow(data)
244                    .as_ref()
245                    .as_ref(),
246            )
247        }
248        unsafe {
249            let f: Box_<F> = Box_::new(f);
250            connect_raw(
251                self.as_ptr() as *mut _,
252                c"on-message-data".as_ptr() as *const _,
253                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
254                    on_message_data_trampoline::<F> as *const (),
255                )),
256                Box_::into_raw(f),
257            )
258        }
259    }
260
261    #[doc(alias = "on-message-string")]
262    pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
263        &self,
264        f: F,
265    ) -> SignalHandlerId {
266        unsafe extern "C" fn on_message_string_trampoline<
267            F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
268        >(
269            this: *mut ffi::GstWebRTCDataChannel,
270            data: *mut std::ffi::c_char,
271            f: glib::ffi::gpointer,
272        ) {
273            let f: &F = &*(f as *const F);
274            f(
275                &from_glib_borrow(this),
276                Option::<glib::GString>::from_glib_borrow(data)
277                    .as_ref()
278                    .as_ref()
279                    .map(|s| s.as_str()),
280            )
281        }
282        unsafe {
283            let f: Box_<F> = Box_::new(f);
284            connect_raw(
285                self.as_ptr() as *mut _,
286                c"on-message-string".as_ptr() as *const _,
287                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288                    on_message_string_trampoline::<F> as *const (),
289                )),
290                Box_::into_raw(f),
291            )
292        }
293    }
294
295    #[doc(alias = "on-open")]
296    pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
297        unsafe extern "C" fn on_open_trampoline<
298            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
299        >(
300            this: *mut ffi::GstWebRTCDataChannel,
301            f: glib::ffi::gpointer,
302        ) {
303            let f: &F = &*(f as *const F);
304            f(&from_glib_borrow(this))
305        }
306        unsafe {
307            let f: Box_<F> = Box_::new(f);
308            connect_raw(
309                self.as_ptr() as *mut _,
310                c"on-open".as_ptr() as *const _,
311                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
312                    on_open_trampoline::<F> as *const (),
313                )),
314                Box_::into_raw(f),
315            )
316        }
317    }
318
319    #[doc(alias = "buffered-amount")]
320    pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
321        &self,
322        f: F,
323    ) -> SignalHandlerId {
324        unsafe extern "C" fn notify_buffered_amount_trampoline<
325            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
326        >(
327            this: *mut ffi::GstWebRTCDataChannel,
328            _param_spec: glib::ffi::gpointer,
329            f: glib::ffi::gpointer,
330        ) {
331            let f: &F = &*(f as *const F);
332            f(&from_glib_borrow(this))
333        }
334        unsafe {
335            let f: Box_<F> = Box_::new(f);
336            connect_raw(
337                self.as_ptr() as *mut _,
338                c"notify::buffered-amount".as_ptr() as *const _,
339                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
340                    notify_buffered_amount_trampoline::<F> as *const (),
341                )),
342                Box_::into_raw(f),
343            )
344        }
345    }
346
347    #[doc(alias = "buffered-amount-low-threshold")]
348    pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
349        &self,
350        f: F,
351    ) -> SignalHandlerId {
352        unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
353            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
354        >(
355            this: *mut ffi::GstWebRTCDataChannel,
356            _param_spec: glib::ffi::gpointer,
357            f: glib::ffi::gpointer,
358        ) {
359            let f: &F = &*(f as *const F);
360            f(&from_glib_borrow(this))
361        }
362        unsafe {
363            let f: Box_<F> = Box_::new(f);
364            connect_raw(
365                self.as_ptr() as *mut _,
366                c"notify::buffered-amount-low-threshold".as_ptr() as *const _,
367                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
368                    notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
369                )),
370                Box_::into_raw(f),
371            )
372        }
373    }
374
375    #[doc(alias = "ready-state")]
376    pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
377        &self,
378        f: F,
379    ) -> SignalHandlerId {
380        unsafe extern "C" fn notify_ready_state_trampoline<
381            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
382        >(
383            this: *mut ffi::GstWebRTCDataChannel,
384            _param_spec: glib::ffi::gpointer,
385            f: glib::ffi::gpointer,
386        ) {
387            let f: &F = &*(f as *const F);
388            f(&from_glib_borrow(this))
389        }
390        unsafe {
391            let f: Box_<F> = Box_::new(f);
392            connect_raw(
393                self.as_ptr() as *mut _,
394                c"notify::ready-state".as_ptr() as *const _,
395                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
396                    notify_ready_state_trampoline::<F> as *const (),
397                )),
398                Box_::into_raw(f),
399            )
400        }
401    }
402}
403
404unsafe impl Send for WebRTCDataChannel {}
405unsafe impl Sync for WebRTCDataChannel {}