1#![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")]
111 pub struct WebRTCDataChannel(Object<ffi::GstWebRTCDataChannel, ffi::GstWebRTCDataChannelClass>);
112
113 match fn {
114 type_ => || ffi::gst_webrtc_data_channel_get_type(),
115 }
116}
117
118impl WebRTCDataChannel {
119 #[doc(alias = "gst_webrtc_data_channel_close")]
121 pub fn close(&self) {
122 unsafe {
123 ffi::gst_webrtc_data_channel_close(self.to_glib_none().0);
124 }
125 }
126
127 #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
135 #[allow(deprecated)]
136 #[doc(alias = "gst_webrtc_data_channel_send_data")]
137 pub fn send_data(&self, data: Option<&glib::Bytes>) {
138 unsafe {
139 ffi::gst_webrtc_data_channel_send_data(self.to_glib_none().0, data.to_glib_none().0);
140 }
141 }
142
143 #[cfg(feature = "v1_22")]
151 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
152 #[doc(alias = "gst_webrtc_data_channel_send_data_full")]
153 pub fn send_data_full(&self, data: Option<&glib::Bytes>) -> Result<(), glib::Error> {
154 unsafe {
155 let mut error = std::ptr::null_mut();
156 let is_ok = ffi::gst_webrtc_data_channel_send_data_full(
157 self.to_glib_none().0,
158 data.to_glib_none().0,
159 &mut error,
160 );
161 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
162 if error.is_null() {
163 Ok(())
164 } else {
165 Err(from_glib_full(error))
166 }
167 }
168 }
169
170 #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
178 #[allow(deprecated)]
179 #[doc(alias = "gst_webrtc_data_channel_send_string")]
180 pub fn send_string(&self, str: Option<&str>) {
181 unsafe {
182 ffi::gst_webrtc_data_channel_send_string(self.to_glib_none().0, str.to_glib_none().0);
183 }
184 }
185
186 #[cfg(feature = "v1_22")]
194 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
195 #[doc(alias = "gst_webrtc_data_channel_send_string_full")]
196 pub fn send_string_full(&self, str: Option<&str>) -> Result<(), glib::Error> {
197 unsafe {
198 let mut error = std::ptr::null_mut();
199 let is_ok = ffi::gst_webrtc_data_channel_send_string_full(
200 self.to_glib_none().0,
201 str.to_glib_none().0,
202 &mut error,
203 );
204 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
205 if error.is_null() {
206 Ok(())
207 } else {
208 Err(from_glib_full(error))
209 }
210 }
211 }
212
213 #[doc(alias = "buffered-amount")]
214 pub fn buffered_amount(&self) -> u64 {
215 ObjectExt::property(self, "buffered-amount")
216 }
217
218 #[doc(alias = "buffered-amount-low-threshold")]
219 pub fn buffered_amount_low_threshold(&self) -> u64 {
220 ObjectExt::property(self, "buffered-amount-low-threshold")
221 }
222
223 #[doc(alias = "buffered-amount-low-threshold")]
224 pub fn set_buffered_amount_low_threshold(&self, buffered_amount_low_threshold: u64) {
225 ObjectExt::set_property(
226 self,
227 "buffered-amount-low-threshold",
228 buffered_amount_low_threshold,
229 )
230 }
231
232 pub fn id(&self) -> i32 {
233 ObjectExt::property(self, "id")
234 }
235
236 pub fn label(&self) -> Option<glib::GString> {
237 ObjectExt::property(self, "label")
238 }
239
240 #[doc(alias = "max-packet-lifetime")]
241 pub fn max_packet_lifetime(&self) -> i32 {
242 ObjectExt::property(self, "max-packet-lifetime")
243 }
244
245 #[doc(alias = "max-retransmits")]
246 pub fn max_retransmits(&self) -> i32 {
247 ObjectExt::property(self, "max-retransmits")
248 }
249
250 pub fn is_negotiated(&self) -> bool {
251 ObjectExt::property(self, "negotiated")
252 }
253
254 pub fn is_ordered(&self) -> bool {
255 ObjectExt::property(self, "ordered")
256 }
257
258 pub fn priority(&self) -> WebRTCPriorityType {
259 ObjectExt::property(self, "priority")
260 }
261
262 pub fn protocol(&self) -> Option<glib::GString> {
263 ObjectExt::property(self, "protocol")
264 }
265
266 #[doc(alias = "ready-state")]
267 pub fn ready_state(&self) -> WebRTCDataChannelState {
268 ObjectExt::property(self, "ready-state")
269 }
270
271 #[doc(alias = "on-buffered-amount-low")]
272 pub fn connect_on_buffered_amount_low<F: Fn(&Self) + Send + Sync + 'static>(
273 &self,
274 f: F,
275 ) -> SignalHandlerId {
276 unsafe extern "C" fn on_buffered_amount_low_trampoline<
277 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
278 >(
279 this: *mut ffi::GstWebRTCDataChannel,
280 f: glib::ffi::gpointer,
281 ) {
282 unsafe {
283 let f: &F = &*(f as *const F);
284 f(&from_glib_borrow(this))
285 }
286 }
287 unsafe {
288 let f: Box_<F> = Box_::new(f);
289 connect_raw(
290 self.as_ptr() as *mut _,
291 c"on-buffered-amount-low".as_ptr(),
292 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293 on_buffered_amount_low_trampoline::<F> as *const (),
294 )),
295 Box_::into_raw(f),
296 )
297 }
298 }
299
300 #[doc(alias = "on-close")]
301 pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
302 unsafe extern "C" fn on_close_trampoline<
303 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
304 >(
305 this: *mut ffi::GstWebRTCDataChannel,
306 f: glib::ffi::gpointer,
307 ) {
308 unsafe {
309 let f: &F = &*(f as *const F);
310 f(&from_glib_borrow(this))
311 }
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"on-close".as_ptr(),
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 on_close_trampoline::<F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "on-error")]
329 pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
330 &self,
331 f: F,
332 ) -> SignalHandlerId {
333 unsafe extern "C" fn on_error_trampoline<
334 F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
335 >(
336 this: *mut ffi::GstWebRTCDataChannel,
337 error: *mut glib::ffi::GError,
338 f: glib::ffi::gpointer,
339 ) {
340 unsafe {
341 let f: &F = &*(f as *const F);
342 f(&from_glib_borrow(this), &from_glib_borrow(error))
343 }
344 }
345 unsafe {
346 let f: Box_<F> = Box_::new(f);
347 connect_raw(
348 self.as_ptr() as *mut _,
349 c"on-error".as_ptr(),
350 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
351 on_error_trampoline::<F> as *const (),
352 )),
353 Box_::into_raw(f),
354 )
355 }
356 }
357
358 #[doc(alias = "on-message-data")]
361 pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
362 &self,
363 f: F,
364 ) -> SignalHandlerId {
365 unsafe extern "C" fn on_message_data_trampoline<
366 F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
367 >(
368 this: *mut ffi::GstWebRTCDataChannel,
369 data: *mut glib::ffi::GBytes,
370 f: glib::ffi::gpointer,
371 ) {
372 unsafe {
373 let f: &F = &*(f as *const F);
374 f(
375 &from_glib_borrow(this),
376 Option::<glib::Bytes>::from_glib_borrow(data)
377 .as_ref()
378 .as_ref(),
379 )
380 }
381 }
382 unsafe {
383 let f: Box_<F> = Box_::new(f);
384 connect_raw(
385 self.as_ptr() as *mut _,
386 c"on-message-data".as_ptr(),
387 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
388 on_message_data_trampoline::<F> as *const (),
389 )),
390 Box_::into_raw(f),
391 )
392 }
393 }
394
395 #[doc(alias = "on-message-string")]
398 pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
399 &self,
400 f: F,
401 ) -> SignalHandlerId {
402 unsafe extern "C" fn on_message_string_trampoline<
403 F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
404 >(
405 this: *mut ffi::GstWebRTCDataChannel,
406 data: *mut std::ffi::c_char,
407 f: glib::ffi::gpointer,
408 ) {
409 unsafe {
410 let f: &F = &*(f as *const F);
411 f(
412 &from_glib_borrow(this),
413 Option::<glib::GString>::from_glib_borrow(data)
414 .as_ref()
415 .as_ref()
416 .map(|s| s.as_str()),
417 )
418 }
419 }
420 unsafe {
421 let f: Box_<F> = Box_::new(f);
422 connect_raw(
423 self.as_ptr() as *mut _,
424 c"on-message-string".as_ptr(),
425 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
426 on_message_string_trampoline::<F> as *const (),
427 )),
428 Box_::into_raw(f),
429 )
430 }
431 }
432
433 #[doc(alias = "on-open")]
434 pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
435 unsafe extern "C" fn on_open_trampoline<
436 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
437 >(
438 this: *mut ffi::GstWebRTCDataChannel,
439 f: glib::ffi::gpointer,
440 ) {
441 unsafe {
442 let f: &F = &*(f as *const F);
443 f(&from_glib_borrow(this))
444 }
445 }
446 unsafe {
447 let f: Box_<F> = Box_::new(f);
448 connect_raw(
449 self.as_ptr() as *mut _,
450 c"on-open".as_ptr(),
451 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
452 on_open_trampoline::<F> as *const (),
453 )),
454 Box_::into_raw(f),
455 )
456 }
457 }
458
459 #[doc(alias = "buffered-amount")]
460 pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
461 &self,
462 f: F,
463 ) -> SignalHandlerId {
464 unsafe extern "C" fn notify_buffered_amount_trampoline<
465 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
466 >(
467 this: *mut ffi::GstWebRTCDataChannel,
468 _param_spec: glib::ffi::gpointer,
469 f: glib::ffi::gpointer,
470 ) {
471 unsafe {
472 let f: &F = &*(f as *const F);
473 f(&from_glib_borrow(this))
474 }
475 }
476 unsafe {
477 let f: Box_<F> = Box_::new(f);
478 connect_raw(
479 self.as_ptr() as *mut _,
480 c"notify::buffered-amount".as_ptr(),
481 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
482 notify_buffered_amount_trampoline::<F> as *const (),
483 )),
484 Box_::into_raw(f),
485 )
486 }
487 }
488
489 #[doc(alias = "buffered-amount-low-threshold")]
490 pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
491 &self,
492 f: F,
493 ) -> SignalHandlerId {
494 unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
495 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
496 >(
497 this: *mut ffi::GstWebRTCDataChannel,
498 _param_spec: glib::ffi::gpointer,
499 f: glib::ffi::gpointer,
500 ) {
501 unsafe {
502 let f: &F = &*(f as *const F);
503 f(&from_glib_borrow(this))
504 }
505 }
506 unsafe {
507 let f: Box_<F> = Box_::new(f);
508 connect_raw(
509 self.as_ptr() as *mut _,
510 c"notify::buffered-amount-low-threshold".as_ptr(),
511 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512 notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
513 )),
514 Box_::into_raw(f),
515 )
516 }
517 }
518
519 #[doc(alias = "ready-state")]
520 pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
521 &self,
522 f: F,
523 ) -> SignalHandlerId {
524 unsafe extern "C" fn notify_ready_state_trampoline<
525 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
526 >(
527 this: *mut ffi::GstWebRTCDataChannel,
528 _param_spec: glib::ffi::gpointer,
529 f: glib::ffi::gpointer,
530 ) {
531 unsafe {
532 let f: &F = &*(f as *const F);
533 f(&from_glib_borrow(this))
534 }
535 }
536 unsafe {
537 let f: Box_<F> = Box_::new(f);
538 connect_raw(
539 self.as_ptr() as *mut _,
540 c"notify::ready-state".as_ptr(),
541 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
542 notify_ready_state_trampoline::<F> as *const (),
543 )),
544 Box_::into_raw(f),
545 )
546 }
547 }
548}
549
550unsafe impl Send for WebRTCDataChannel {}
551unsafe impl Sync for WebRTCDataChannel {}