1use 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")]
110 pub struct WebRTCDataChannel(Object<ffi::GstWebRTCDataChannel, ffi::GstWebRTCDataChannelClass>);
111
112 match fn {
113 type_ => || ffi::gst_webrtc_data_channel_get_type(),
114 }
115}
116
117impl WebRTCDataChannel {
118 #[doc(alias = "gst_webrtc_data_channel_close")]
120 pub fn close(&self) {
121 unsafe {
122 ffi::gst_webrtc_data_channel_close(self.to_glib_none().0);
123 }
124 }
125
126 #[doc(alias = "gst_webrtc_data_channel_send_data")]
130 pub fn send_data(&self, data: Option<&glib::Bytes>) {
131 unsafe {
132 ffi::gst_webrtc_data_channel_send_data(self.to_glib_none().0, data.to_glib_none().0);
133 }
134 }
135
136 #[cfg(feature = "v1_22")]
144 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
145 #[doc(alias = "gst_webrtc_data_channel_send_data_full")]
146 pub fn send_data_full(&self, data: Option<&glib::Bytes>) -> Result<(), glib::Error> {
147 unsafe {
148 let mut error = std::ptr::null_mut();
149 let is_ok = ffi::gst_webrtc_data_channel_send_data_full(
150 self.to_glib_none().0,
151 data.to_glib_none().0,
152 &mut error,
153 );
154 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
155 if error.is_null() {
156 Ok(())
157 } else {
158 Err(from_glib_full(error))
159 }
160 }
161 }
162
163 #[doc(alias = "gst_webrtc_data_channel_send_string")]
167 pub fn send_string(&self, str: Option<&str>) {
168 unsafe {
169 ffi::gst_webrtc_data_channel_send_string(self.to_glib_none().0, str.to_glib_none().0);
170 }
171 }
172
173 #[cfg(feature = "v1_22")]
181 #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
182 #[doc(alias = "gst_webrtc_data_channel_send_string_full")]
183 pub fn send_string_full(&self, str: Option<&str>) -> Result<(), glib::Error> {
184 unsafe {
185 let mut error = std::ptr::null_mut();
186 let is_ok = ffi::gst_webrtc_data_channel_send_string_full(
187 self.to_glib_none().0,
188 str.to_glib_none().0,
189 &mut error,
190 );
191 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
192 if error.is_null() {
193 Ok(())
194 } else {
195 Err(from_glib_full(error))
196 }
197 }
198 }
199
200 #[doc(alias = "buffered-amount")]
201 pub fn buffered_amount(&self) -> u64 {
202 ObjectExt::property(self, "buffered-amount")
203 }
204
205 #[doc(alias = "buffered-amount-low-threshold")]
206 pub fn buffered_amount_low_threshold(&self) -> u64 {
207 ObjectExt::property(self, "buffered-amount-low-threshold")
208 }
209
210 #[doc(alias = "buffered-amount-low-threshold")]
211 pub fn set_buffered_amount_low_threshold(&self, buffered_amount_low_threshold: u64) {
212 ObjectExt::set_property(
213 self,
214 "buffered-amount-low-threshold",
215 buffered_amount_low_threshold,
216 )
217 }
218
219 pub fn id(&self) -> i32 {
220 ObjectExt::property(self, "id")
221 }
222
223 pub fn label(&self) -> Option<glib::GString> {
224 ObjectExt::property(self, "label")
225 }
226
227 #[doc(alias = "max-packet-lifetime")]
228 pub fn max_packet_lifetime(&self) -> i32 {
229 ObjectExt::property(self, "max-packet-lifetime")
230 }
231
232 #[doc(alias = "max-retransmits")]
233 pub fn max_retransmits(&self) -> i32 {
234 ObjectExt::property(self, "max-retransmits")
235 }
236
237 pub fn is_negotiated(&self) -> bool {
238 ObjectExt::property(self, "negotiated")
239 }
240
241 pub fn is_ordered(&self) -> bool {
242 ObjectExt::property(self, "ordered")
243 }
244
245 pub fn priority(&self) -> WebRTCPriorityType {
246 ObjectExt::property(self, "priority")
247 }
248
249 pub fn protocol(&self) -> Option<glib::GString> {
250 ObjectExt::property(self, "protocol")
251 }
252
253 #[doc(alias = "ready-state")]
254 pub fn ready_state(&self) -> WebRTCDataChannelState {
255 ObjectExt::property(self, "ready-state")
256 }
257
258 #[doc(alias = "close")]
260 pub fn connect_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
261 unsafe extern "C" fn close_trampoline<F: Fn(&WebRTCDataChannel) + Send + Sync + 'static>(
262 this: *mut ffi::GstWebRTCDataChannel,
263 f: glib::ffi::gpointer,
264 ) {
265 let f: &F = &*(f as *const F);
266 f(&from_glib_borrow(this))
267 }
268 unsafe {
269 let f: Box_<F> = Box_::new(f);
270 connect_raw(
271 self.as_ptr() as *mut _,
272 c"close".as_ptr() as *const _,
273 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
274 close_trampoline::<F> as *const (),
275 )),
276 Box_::into_raw(f),
277 )
278 }
279 }
280
281 pub fn emit_close(&self) {
282 self.emit_by_name::<()>("close", &[]);
283 }
284
285 #[doc(alias = "on-buffered-amount-low")]
286 pub fn connect_on_buffered_amount_low<F: Fn(&Self) + Send + Sync + 'static>(
287 &self,
288 f: F,
289 ) -> SignalHandlerId {
290 unsafe extern "C" fn on_buffered_amount_low_trampoline<
291 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
292 >(
293 this: *mut ffi::GstWebRTCDataChannel,
294 f: glib::ffi::gpointer,
295 ) {
296 let f: &F = &*(f as *const F);
297 f(&from_glib_borrow(this))
298 }
299 unsafe {
300 let f: Box_<F> = Box_::new(f);
301 connect_raw(
302 self.as_ptr() as *mut _,
303 c"on-buffered-amount-low".as_ptr() as *const _,
304 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
305 on_buffered_amount_low_trampoline::<F> as *const (),
306 )),
307 Box_::into_raw(f),
308 )
309 }
310 }
311
312 #[doc(alias = "on-close")]
313 pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
314 unsafe extern "C" fn on_close_trampoline<
315 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
316 >(
317 this: *mut ffi::GstWebRTCDataChannel,
318 f: glib::ffi::gpointer,
319 ) {
320 let f: &F = &*(f as *const F);
321 f(&from_glib_borrow(this))
322 }
323 unsafe {
324 let f: Box_<F> = Box_::new(f);
325 connect_raw(
326 self.as_ptr() as *mut _,
327 c"on-close".as_ptr() as *const _,
328 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329 on_close_trampoline::<F> as *const (),
330 )),
331 Box_::into_raw(f),
332 )
333 }
334 }
335
336 #[doc(alias = "on-error")]
339 pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
340 &self,
341 f: F,
342 ) -> SignalHandlerId {
343 unsafe extern "C" fn on_error_trampoline<
344 F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
345 >(
346 this: *mut ffi::GstWebRTCDataChannel,
347 error: *mut glib::ffi::GError,
348 f: glib::ffi::gpointer,
349 ) {
350 let f: &F = &*(f as *const F);
351 f(&from_glib_borrow(this), &from_glib_borrow(error))
352 }
353 unsafe {
354 let f: Box_<F> = Box_::new(f);
355 connect_raw(
356 self.as_ptr() as *mut _,
357 c"on-error".as_ptr() as *const _,
358 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
359 on_error_trampoline::<F> as *const (),
360 )),
361 Box_::into_raw(f),
362 )
363 }
364 }
365
366 #[doc(alias = "on-message-data")]
369 pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
370 &self,
371 f: F,
372 ) -> SignalHandlerId {
373 unsafe extern "C" fn on_message_data_trampoline<
374 F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
375 >(
376 this: *mut ffi::GstWebRTCDataChannel,
377 data: *mut glib::ffi::GBytes,
378 f: glib::ffi::gpointer,
379 ) {
380 let f: &F = &*(f as *const F);
381 f(
382 &from_glib_borrow(this),
383 Option::<glib::Bytes>::from_glib_borrow(data)
384 .as_ref()
385 .as_ref(),
386 )
387 }
388 unsafe {
389 let f: Box_<F> = Box_::new(f);
390 connect_raw(
391 self.as_ptr() as *mut _,
392 c"on-message-data".as_ptr() as *const _,
393 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394 on_message_data_trampoline::<F> as *const (),
395 )),
396 Box_::into_raw(f),
397 )
398 }
399 }
400
401 #[doc(alias = "on-message-string")]
404 pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
405 &self,
406 f: F,
407 ) -> SignalHandlerId {
408 unsafe extern "C" fn on_message_string_trampoline<
409 F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
410 >(
411 this: *mut ffi::GstWebRTCDataChannel,
412 data: *mut std::ffi::c_char,
413 f: glib::ffi::gpointer,
414 ) {
415 let f: &F = &*(f as *const F);
416 f(
417 &from_glib_borrow(this),
418 Option::<glib::GString>::from_glib_borrow(data)
419 .as_ref()
420 .as_ref()
421 .map(|s| s.as_str()),
422 )
423 }
424 unsafe {
425 let f: Box_<F> = Box_::new(f);
426 connect_raw(
427 self.as_ptr() as *mut _,
428 c"on-message-string".as_ptr() as *const _,
429 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
430 on_message_string_trampoline::<F> as *const (),
431 )),
432 Box_::into_raw(f),
433 )
434 }
435 }
436
437 #[doc(alias = "on-open")]
438 pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
439 unsafe extern "C" fn on_open_trampoline<
440 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
441 >(
442 this: *mut ffi::GstWebRTCDataChannel,
443 f: glib::ffi::gpointer,
444 ) {
445 let f: &F = &*(f as *const F);
446 f(&from_glib_borrow(this))
447 }
448 unsafe {
449 let f: Box_<F> = Box_::new(f);
450 connect_raw(
451 self.as_ptr() as *mut _,
452 c"on-open".as_ptr() as *const _,
453 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
454 on_open_trampoline::<F> as *const (),
455 )),
456 Box_::into_raw(f),
457 )
458 }
459 }
460
461 #[doc(alias = "send-data")]
464 pub fn connect_send_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
465 &self,
466 f: F,
467 ) -> SignalHandlerId {
468 unsafe extern "C" fn send_data_trampoline<
469 F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
470 >(
471 this: *mut ffi::GstWebRTCDataChannel,
472 data: *mut glib::ffi::GBytes,
473 f: glib::ffi::gpointer,
474 ) {
475 let f: &F = &*(f as *const F);
476 f(
477 &from_glib_borrow(this),
478 Option::<glib::Bytes>::from_glib_borrow(data)
479 .as_ref()
480 .as_ref(),
481 )
482 }
483 unsafe {
484 let f: Box_<F> = Box_::new(f);
485 connect_raw(
486 self.as_ptr() as *mut _,
487 c"send-data".as_ptr() as *const _,
488 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
489 send_data_trampoline::<F> as *const (),
490 )),
491 Box_::into_raw(f),
492 )
493 }
494 }
495
496 pub fn emit_send_data(&self, data: Option<&glib::Bytes>) {
497 self.emit_by_name::<()>("send-data", &[&data]);
498 }
499
500 #[doc(alias = "send-string")]
503 pub fn connect_send_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
504 &self,
505 f: F,
506 ) -> SignalHandlerId {
507 unsafe extern "C" fn send_string_trampoline<
508 F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
509 >(
510 this: *mut ffi::GstWebRTCDataChannel,
511 data: *mut std::ffi::c_char,
512 f: glib::ffi::gpointer,
513 ) {
514 let f: &F = &*(f as *const F);
515 f(
516 &from_glib_borrow(this),
517 Option::<glib::GString>::from_glib_borrow(data)
518 .as_ref()
519 .as_ref()
520 .map(|s| s.as_str()),
521 )
522 }
523 unsafe {
524 let f: Box_<F> = Box_::new(f);
525 connect_raw(
526 self.as_ptr() as *mut _,
527 c"send-string".as_ptr() as *const _,
528 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
529 send_string_trampoline::<F> as *const (),
530 )),
531 Box_::into_raw(f),
532 )
533 }
534 }
535
536 pub fn emit_send_string(&self, data: Option<&str>) {
537 self.emit_by_name::<()>("send-string", &[&data]);
538 }
539
540 #[doc(alias = "buffered-amount")]
541 pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
542 &self,
543 f: F,
544 ) -> SignalHandlerId {
545 unsafe extern "C" fn notify_buffered_amount_trampoline<
546 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
547 >(
548 this: *mut ffi::GstWebRTCDataChannel,
549 _param_spec: glib::ffi::gpointer,
550 f: glib::ffi::gpointer,
551 ) {
552 let f: &F = &*(f as *const F);
553 f(&from_glib_borrow(this))
554 }
555 unsafe {
556 let f: Box_<F> = Box_::new(f);
557 connect_raw(
558 self.as_ptr() as *mut _,
559 c"notify::buffered-amount".as_ptr() as *const _,
560 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
561 notify_buffered_amount_trampoline::<F> as *const (),
562 )),
563 Box_::into_raw(f),
564 )
565 }
566 }
567
568 #[doc(alias = "buffered-amount-low-threshold")]
569 pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
570 &self,
571 f: F,
572 ) -> SignalHandlerId {
573 unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
574 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
575 >(
576 this: *mut ffi::GstWebRTCDataChannel,
577 _param_spec: glib::ffi::gpointer,
578 f: glib::ffi::gpointer,
579 ) {
580 let f: &F = &*(f as *const F);
581 f(&from_glib_borrow(this))
582 }
583 unsafe {
584 let f: Box_<F> = Box_::new(f);
585 connect_raw(
586 self.as_ptr() as *mut _,
587 c"notify::buffered-amount-low-threshold".as_ptr() as *const _,
588 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
589 notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
590 )),
591 Box_::into_raw(f),
592 )
593 }
594 }
595
596 #[doc(alias = "ready-state")]
597 pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
598 &self,
599 f: F,
600 ) -> SignalHandlerId {
601 unsafe extern "C" fn notify_ready_state_trampoline<
602 F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
603 >(
604 this: *mut ffi::GstWebRTCDataChannel,
605 _param_spec: glib::ffi::gpointer,
606 f: glib::ffi::gpointer,
607 ) {
608 let f: &F = &*(f as *const F);
609 f(&from_glib_borrow(this))
610 }
611 unsafe {
612 let f: Box_<F> = Box_::new(f);
613 connect_raw(
614 self.as_ptr() as *mut _,
615 c"notify::ready-state".as_ptr() as *const _,
616 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
617 notify_ready_state_trampoline::<F> as *const (),
618 )),
619 Box_::into_raw(f),
620 )
621 }
622 }
623}
624
625unsafe impl Send for WebRTCDataChannel {}
626unsafe impl Sync for WebRTCDataChannel {}