diff --git a/gstreamer-webrtc/src/lib.rs b/gstreamer-webrtc/src/lib.rs index ce94232d8..69d74360c 100644 --- a/gstreamer-webrtc/src/lib.rs +++ b/gstreamer-webrtc/src/lib.rs @@ -22,10 +22,16 @@ pub use crate::auto::*; #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] mod web_rtc_ice_candidate_stats; mod web_rtc_session_description; +#[cfg(any(feature = "v1_22", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] +mod web_rtcice; // Re-export all the traits in a prelude module, so that applications // can always "use gst_webrtc::prelude::*" without getting conflicts pub mod prelude { + #[cfg(any(feature = "v1_22", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] + pub use crate::web_rtcice::WebRTCICEExtManual; #[doc(hidden)] pub use gst_sdp::prelude::*; } diff --git a/gstreamer-webrtc/src/web_rtcice.rs b/gstreamer-webrtc/src/web_rtcice.rs new file mode 100644 index 000000000..ed60ed82f --- /dev/null +++ b/gstreamer-webrtc/src/web_rtcice.rs @@ -0,0 +1,46 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use glib::{prelude::*, translate::*}; + +use crate::{WebRTCICE, WebRTCICEStream}; + +pub trait WebRTCICEExtManual: 'static { + #[doc(alias = "gst_webrtc_ice_add_candidate")] + fn add_candidate(&self, stream: &impl IsA, candidate: &str); +} + +impl> WebRTCICEExtManual for O { + fn add_candidate(&self, stream: &impl IsA, candidate: &str) { + unsafe { + use std::{mem, ptr}; + + if gst::version() >= (1, 23, 0, 0) { + let func = mem::transmute::< + unsafe extern "C" fn( + *mut ffi::GstWebRTCICE, + *mut ffi::GstWebRTCICEStream, + *const std::os::raw::c_char, + ), + unsafe extern "C" fn( + *mut ffi::GstWebRTCICE, + *mut ffi::GstWebRTCICEStream, + *const std::os::raw::c_char, + *mut gst::ffi::GstPromise, + ), + >(ffi::gst_webrtc_ice_add_candidate); + func( + self.as_ref().to_glib_none().0, + stream.as_ref().to_glib_none().0, + candidate.to_glib_none().0, + ptr::null_mut(), + ); + } else { + ffi::gst_webrtc_ice_add_candidate( + self.as_ref().to_glib_none().0, + stream.as_ref().to_glib_none().0, + candidate.to_glib_none().0, + ); + } + } + } +}