From 82cf6e784280020113715f312b65bc5e7b5a1265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Jan 2023 09:59:02 +0200 Subject: [PATCH] Update for `glib::Boxed` `ToGlibPtr<*mut _>` trait impl addition Part-of: --- gstreamer-controller/src/control_point.rs | 10 ++-------- gstreamer-play/src/play_visualization.rs | 10 ++-------- gstreamer-player/src/player_visualization.rs | 10 ++-------- .../src/subclass/rtsp_client.rs | 7 +------ gstreamer-sdp/src/sdp_media.rs | 2 +- gstreamer-sdp/src/sdp_message.rs | 7 ++----- .../src/web_rtc_ice_candidate_stats.rs | 18 ++++++++---------- .../src/web_rtc_session_description.rs | 4 ++-- 8 files changed, 20 insertions(+), 48 deletions(-) diff --git a/gstreamer-controller/src/control_point.rs b/gstreamer-controller/src/control_point.rs index 75af56a6e..d0a056612 100644 --- a/gstreamer-controller/src/control_point.rs +++ b/gstreamer-controller/src/control_point.rs @@ -16,17 +16,11 @@ glib::wrapper! { impl ControlPoint { pub fn timestamp(&self) -> gst::ClockTime { - unsafe { - let ptr = self.to_glib_none().0; - try_from_glib((*ptr).timestamp).expect("undefined timestamp") - } + unsafe { try_from_glib((*self.as_ptr()).timestamp).expect("undefined timestamp") } } pub fn value(&self) -> f64 { - unsafe { - let ptr = self.to_glib_none().0; - (*ptr).value - } + unsafe { (*self.as_ptr()).value } } } diff --git a/gstreamer-play/src/play_visualization.rs b/gstreamer-play/src/play_visualization.rs index bfd6109ec..61d4a4efb 100644 --- a/gstreamer-play/src/play_visualization.rs +++ b/gstreamer-play/src/play_visualization.rs @@ -2,22 +2,16 @@ use std::ffi::CStr; -use glib::translate::*; - use crate::PlayVisualization; impl PlayVisualization { pub fn name(&self) -> &str { - unsafe { - CStr::from_ptr((*self.to_glib_none().0).name) - .to_str() - .unwrap() - } + unsafe { CStr::from_ptr((*self.as_ptr()).name).to_str().unwrap() } } pub fn description(&self) -> &str { unsafe { - CStr::from_ptr((*self.to_glib_none().0).description) + CStr::from_ptr((*self.as_ptr()).description) .to_str() .unwrap() } diff --git a/gstreamer-player/src/player_visualization.rs b/gstreamer-player/src/player_visualization.rs index 8ed8ad404..56df04b5d 100644 --- a/gstreamer-player/src/player_visualization.rs +++ b/gstreamer-player/src/player_visualization.rs @@ -2,22 +2,16 @@ use std::ffi::CStr; -use glib::translate::*; - use crate::PlayerVisualization; impl PlayerVisualization { pub fn name(&self) -> &str { - unsafe { - CStr::from_ptr((*self.to_glib_none().0).name) - .to_str() - .unwrap() - } + unsafe { CStr::from_ptr((*self.as_ptr()).name).to_str().unwrap() } } pub fn description(&self) -> &str { unsafe { - CStr::from_ptr((*self.to_glib_none().0).description) + CStr::from_ptr((*self.as_ptr()).description) .to_str() .unwrap() } diff --git a/gstreamer-rtsp-server/src/subclass/rtsp_client.rs b/gstreamer-rtsp-server/src/subclass/rtsp_client.rs index 126bd9582..14ad322a4 100644 --- a/gstreamer-rtsp-server/src/subclass/rtsp_client.rs +++ b/gstreamer-rtsp-server/src/subclass/rtsp_client.rs @@ -1,7 +1,5 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::mem; - use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::RTSPClient; @@ -783,10 +781,7 @@ unsafe extern "C" fn client_create_sdp( let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); - let sdp = mem::ManuallyDrop::new(imp.create_sdp(&from_glib_borrow(media))); - let ptr = sdp.to_glib_none().0; - - ptr as *mut _ + imp.create_sdp(&from_glib_borrow(media)).into_glib_ptr() } unsafe extern "C" fn client_configure_client_media( diff --git a/gstreamer-sdp/src/sdp_media.rs b/gstreamer-sdp/src/sdp_media.rs index 18ce5f65d..fc5ef43f0 100644 --- a/gstreamer-sdp/src/sdp_media.rs +++ b/gstreamer-sdp/src/sdp_media.rs @@ -57,7 +57,7 @@ impl ops::Deref for SDPMedia { type Target = SDPMediaRef; fn deref(&self) -> &SDPMediaRef { - unsafe { &*(self.to_glib_none().0 as *const SDPMediaRef) } + unsafe { &*(self.as_ptr() as *const SDPMediaRef) } } } diff --git a/gstreamer-sdp/src/sdp_message.rs b/gstreamer-sdp/src/sdp_message.rs index 0ece3d421..31e988dec 100644 --- a/gstreamer-sdp/src/sdp_message.rs +++ b/gstreamer-sdp/src/sdp_message.rs @@ -52,7 +52,7 @@ impl ops::Deref for SDPMessage { type Target = SDPMessageRef; fn deref(&self) -> &SDPMessageRef { - unsafe { &*(self.to_glib_none().0 as *const SDPMessageRef) } + unsafe { &*(self.as_ptr() as *const SDPMessageRef) } } } @@ -190,10 +190,7 @@ impl SDPMessageRef { #[doc(alias = "gst_sdp_message_add_media")] pub fn add_media(&mut self, media: SDPMedia) { unsafe { - ffi::gst_sdp_message_add_media( - &mut self.0, - media.to_glib_none().0 as *mut ffi::GstSDPMedia, - ); + ffi::gst_sdp_message_add_media(&mut self.0, media.as_ptr() as *mut ffi::GstSDPMedia); } } diff --git a/gstreamer-webrtc/src/web_rtc_ice_candidate_stats.rs b/gstreamer-webrtc/src/web_rtc_ice_candidate_stats.rs index f1a2dfcfd..8040ee977 100644 --- a/gstreamer-webrtc/src/web_rtc_ice_candidate_stats.rs +++ b/gstreamer-webrtc/src/web_rtc_ice_candidate_stats.rs @@ -2,14 +2,12 @@ use std::ffi::CStr; -use glib::translate::*; - use crate::WebRTCICECandidateStats; impl WebRTCICECandidateStats { pub fn ipaddr(&self) -> Option<&str> { unsafe { - let ptr = (*self.to_glib_none().0).ipaddr; + let ptr = (*self.as_ptr()).ipaddr; if ptr.is_null() { None } else { @@ -19,16 +17,16 @@ impl WebRTCICECandidateStats { } pub fn port(&self) -> u32 { - unsafe { (*self.to_glib_none().0).port } + unsafe { (*self.as_ptr()).port } } pub fn stream_id(&self) -> u32 { - unsafe { (*self.to_glib_none().0).stream_id } + unsafe { (*self.as_ptr()).stream_id } } pub fn type_(&self) -> Option<&str> { unsafe { - let ptr = (*self.to_glib_none().0).type_; + let ptr = (*self.as_ptr()).type_; if ptr.is_null() { None } else { @@ -39,7 +37,7 @@ impl WebRTCICECandidateStats { pub fn proto(&self) -> Option<&str> { unsafe { - let ptr = (*self.to_glib_none().0).proto; + let ptr = (*self.as_ptr()).proto; if ptr.is_null() { None } else { @@ -50,7 +48,7 @@ impl WebRTCICECandidateStats { pub fn relay_proto(&self) -> Option<&str> { unsafe { - let ptr = (*self.to_glib_none().0).relay_proto; + let ptr = (*self.as_ptr()).relay_proto; if ptr.is_null() { None } else { @@ -60,12 +58,12 @@ impl WebRTCICECandidateStats { } pub fn prio(&self) -> u32 { - unsafe { (*self.to_glib_none().0).prio } + unsafe { (*self.as_ptr()).prio } } pub fn url(&self) -> Option<&str> { unsafe { - let ptr = (*self.to_glib_none().0).url; + let ptr = (*self.as_ptr()).url; if ptr.is_null() { None } else { diff --git a/gstreamer-webrtc/src/web_rtc_session_description.rs b/gstreamer-webrtc/src/web_rtc_session_description.rs index 81f597124..b884da5df 100644 --- a/gstreamer-webrtc/src/web_rtc_session_description.rs +++ b/gstreamer-webrtc/src/web_rtc_session_description.rs @@ -21,11 +21,11 @@ impl WebRTCSessionDescription { #[doc(alias = "get_type")] pub fn type_(&self) -> crate::WebRTCSDPType { - unsafe { from_glib((*self.to_glib_none().0).type_) } + unsafe { from_glib((*self.as_ptr()).type_) } } #[doc(alias = "get_sdp")] pub fn sdp(&self) -> gst_sdp::SDPMessage { - unsafe { from_glib_none((*self.to_glib_none().0).sdp) } + unsafe { from_glib_none((*self.as_ptr()).sdp) } } }