Update for glib::Boxed ToGlibPtr<*mut _> trait impl addition

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1192>
This commit is contained in:
Sebastian Dröge 2023-01-17 09:59:02 +02:00
parent c2e7abd128
commit 82cf6e7842
8 changed files with 20 additions and 48 deletions

View file

@ -16,17 +16,11 @@ glib::wrapper! {
impl ControlPoint { impl ControlPoint {
pub fn timestamp(&self) -> gst::ClockTime { pub fn timestamp(&self) -> gst::ClockTime {
unsafe { unsafe { try_from_glib((*self.as_ptr()).timestamp).expect("undefined timestamp") }
let ptr = self.to_glib_none().0;
try_from_glib((*ptr).timestamp).expect("undefined timestamp")
}
} }
pub fn value(&self) -> f64 { pub fn value(&self) -> f64 {
unsafe { unsafe { (*self.as_ptr()).value }
let ptr = self.to_glib_none().0;
(*ptr).value
}
} }
} }

View file

@ -2,22 +2,16 @@
use std::ffi::CStr; use std::ffi::CStr;
use glib::translate::*;
use crate::PlayVisualization; use crate::PlayVisualization;
impl PlayVisualization { impl PlayVisualization {
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
unsafe { unsafe { CStr::from_ptr((*self.as_ptr()).name).to_str().unwrap() }
CStr::from_ptr((*self.to_glib_none().0).name)
.to_str()
.unwrap()
}
} }
pub fn description(&self) -> &str { pub fn description(&self) -> &str {
unsafe { unsafe {
CStr::from_ptr((*self.to_glib_none().0).description) CStr::from_ptr((*self.as_ptr()).description)
.to_str() .to_str()
.unwrap() .unwrap()
} }

View file

@ -2,22 +2,16 @@
use std::ffi::CStr; use std::ffi::CStr;
use glib::translate::*;
use crate::PlayerVisualization; use crate::PlayerVisualization;
impl PlayerVisualization { impl PlayerVisualization {
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
unsafe { unsafe { CStr::from_ptr((*self.as_ptr()).name).to_str().unwrap() }
CStr::from_ptr((*self.to_glib_none().0).name)
.to_str()
.unwrap()
}
} }
pub fn description(&self) -> &str { pub fn description(&self) -> &str {
unsafe { unsafe {
CStr::from_ptr((*self.to_glib_none().0).description) CStr::from_ptr((*self.as_ptr()).description)
.to_str() .to_str()
.unwrap() .unwrap()
} }

View file

@ -1,7 +1,5 @@
// Take a look at the license at the top of the repository in the LICENSE file. // 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 glib::{prelude::*, subclass::prelude::*, translate::*};
use crate::RTSPClient; use crate::RTSPClient;
@ -783,10 +781,7 @@ unsafe extern "C" fn client_create_sdp<T: RTSPClientImpl>(
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let sdp = mem::ManuallyDrop::new(imp.create_sdp(&from_glib_borrow(media))); imp.create_sdp(&from_glib_borrow(media)).into_glib_ptr()
let ptr = sdp.to_glib_none().0;
ptr as *mut _
} }
unsafe extern "C" fn client_configure_client_media<T: RTSPClientImpl>( unsafe extern "C" fn client_configure_client_media<T: RTSPClientImpl>(

View file

@ -57,7 +57,7 @@ impl ops::Deref for SDPMedia {
type Target = SDPMediaRef; type Target = SDPMediaRef;
fn deref(&self) -> &SDPMediaRef { fn deref(&self) -> &SDPMediaRef {
unsafe { &*(self.to_glib_none().0 as *const SDPMediaRef) } unsafe { &*(self.as_ptr() as *const SDPMediaRef) }
} }
} }

View file

@ -52,7 +52,7 @@ impl ops::Deref for SDPMessage {
type Target = SDPMessageRef; type Target = SDPMessageRef;
fn deref(&self) -> &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")] #[doc(alias = "gst_sdp_message_add_media")]
pub fn add_media(&mut self, media: SDPMedia) { pub fn add_media(&mut self, media: SDPMedia) {
unsafe { unsafe {
ffi::gst_sdp_message_add_media( ffi::gst_sdp_message_add_media(&mut self.0, media.as_ptr() as *mut ffi::GstSDPMedia);
&mut self.0,
media.to_glib_none().0 as *mut ffi::GstSDPMedia,
);
} }
} }

View file

@ -2,14 +2,12 @@
use std::ffi::CStr; use std::ffi::CStr;
use glib::translate::*;
use crate::WebRTCICECandidateStats; use crate::WebRTCICECandidateStats;
impl WebRTCICECandidateStats { impl WebRTCICECandidateStats {
pub fn ipaddr(&self) -> Option<&str> { pub fn ipaddr(&self) -> Option<&str> {
unsafe { unsafe {
let ptr = (*self.to_glib_none().0).ipaddr; let ptr = (*self.as_ptr()).ipaddr;
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -19,16 +17,16 @@ impl WebRTCICECandidateStats {
} }
pub fn port(&self) -> u32 { pub fn port(&self) -> u32 {
unsafe { (*self.to_glib_none().0).port } unsafe { (*self.as_ptr()).port }
} }
pub fn stream_id(&self) -> u32 { 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> { pub fn type_(&self) -> Option<&str> {
unsafe { unsafe {
let ptr = (*self.to_glib_none().0).type_; let ptr = (*self.as_ptr()).type_;
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -39,7 +37,7 @@ impl WebRTCICECandidateStats {
pub fn proto(&self) -> Option<&str> { pub fn proto(&self) -> Option<&str> {
unsafe { unsafe {
let ptr = (*self.to_glib_none().0).proto; let ptr = (*self.as_ptr()).proto;
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -50,7 +48,7 @@ impl WebRTCICECandidateStats {
pub fn relay_proto(&self) -> Option<&str> { pub fn relay_proto(&self) -> Option<&str> {
unsafe { unsafe {
let ptr = (*self.to_glib_none().0).relay_proto; let ptr = (*self.as_ptr()).relay_proto;
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -60,12 +58,12 @@ impl WebRTCICECandidateStats {
} }
pub fn prio(&self) -> u32 { pub fn prio(&self) -> u32 {
unsafe { (*self.to_glib_none().0).prio } unsafe { (*self.as_ptr()).prio }
} }
pub fn url(&self) -> Option<&str> { pub fn url(&self) -> Option<&str> {
unsafe { unsafe {
let ptr = (*self.to_glib_none().0).url; let ptr = (*self.as_ptr()).url;
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {

View file

@ -21,11 +21,11 @@ impl WebRTCSessionDescription {
#[doc(alias = "get_type")] #[doc(alias = "get_type")]
pub fn type_(&self) -> crate::WebRTCSDPType { 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")] #[doc(alias = "get_sdp")]
pub fn sdp(&self) -> gst_sdp::SDPMessage { 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) }
} }
} }