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