From 931c4851500377e97b9ecdcf21ba1e517ebc6e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 16 Jan 2019 13:32:58 +0200 Subject: [PATCH] Update manual code for glib API changes --- examples/src/bin/gtkvideooverlay.rs | 6 +- examples/src/bin/pango-cairo.rs | 6 +- gstreamer-app/src/app_sink.rs | 5 +- gstreamer-base/src/aggregator.rs | 2 +- gstreamer-base/src/aggregator_pad.rs | 5 +- gstreamer-base/src/base_sink.rs | 14 +- gstreamer-base/src/base_src.rs | 16 +- gstreamer-base/src/base_transform.rs | 5 +- gstreamer-base/src/flow_combiner.rs | 6 +- gstreamer-base/src/functions.rs | 3 +- gstreamer-check/src/harness.rs | 13 +- .../src/timeline_element.rs | 8 +- gstreamer-gl/src/context.rs | 2 +- gstreamer-gl/src/gl_context.rs | 54 +++---- gstreamer-net/src/net_client_clock.rs | 6 +- gstreamer-net/src/net_time_provider.rs | 4 +- gstreamer-net/src/ntp_clock.rs | 6 +- gstreamer-net/src/ptp_clock.rs | 8 +- gstreamer-pbutils/src/discoverer.rs | 16 +- gstreamer-pbutils/src/encoding_profile.rs | 45 +++--- gstreamer-player/src/player.rs | 21 +-- .../player_video_overlay_video_renderer.rs | 4 +- .../src/rtsp_address_pool.rs | 2 +- gstreamer-rtsp-server/src/rtsp_auth.rs | 5 +- gstreamer-rtsp-server/src/rtsp_client.rs | 5 +- .../src/rtsp_media_factory.rs | 4 +- gstreamer-rtsp-server/src/rtsp_server.rs | 5 +- .../src/rtsp_session_pool.rs | 2 +- gstreamer-rtsp-server/src/rtsp_stream.rs | 4 +- .../src/rtsp_stream_transport.rs | 2 +- gstreamer-video/src/video_overlay.rs | 4 +- gstreamer/src/bin.rs | 32 ++-- gstreamer/src/buffer_pool.rs | 13 +- gstreamer/src/child_proxy.rs | 8 +- gstreamer/src/clock.rs | 8 +- gstreamer/src/device_provider.rs | 4 +- gstreamer/src/element.rs | 86 +++++----- gstreamer/src/ghost_pad.rs | 19 +-- gstreamer/src/gobject.rs | 2 +- gstreamer/src/object.rs | 6 +- gstreamer/src/pad.rs | 147 ++++++++++-------- gstreamer/src/proxy_pad.rs | 21 ++- gstreamer/src/subclass/element.rs | 2 +- gstreamer/src/subclass/mod.rs | 2 +- gstreamer/src/tag_setter.rs | 2 +- tutorials/src/bin/basic-tutorial-5.rs | 6 +- 46 files changed, 343 insertions(+), 303 deletions(-) diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index b5e8fe683..467e3b742 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -24,7 +24,7 @@ extern crate gstreamer_video as gst_video; use gst_video::prelude::*; extern crate glib; -use glib::translate::ToGlibPtr; +use glib::object::ObjectType; extern crate gio; use gio::prelude::*; @@ -133,7 +133,7 @@ fn create_ui(app: >k::Application) { // our video region from the window system, and then we will // pass this unique identifier to the overlay provided by our // sink - so the sink can then arrange the overlay. - let xid = gdk_x11_window_get_xid(gdk_window.to_glib_none().0); + let xid = gdk_x11_window_get_xid(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(xid as usize); } } else { @@ -156,7 +156,7 @@ fn create_ui(app: >k::Application) { // our video region from the windowing system, and then we will // pass this unique identifier to the overlay provided by our // sink - so the sink can then arrange the overlay. - let window = gdk_quartz_window_get_nsview(gdk_window.to_glib_none().0); + let window = gdk_quartz_window_get_nsview(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(window as usize); } } else { diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index c344d0446..2f714ed83 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -29,8 +29,6 @@ use std::sync::{Arc, Mutex}; extern crate failure; use failure::Error; -use glib::GString; - #[macro_use] extern crate failure_derive; @@ -191,7 +189,7 @@ fn create_pipeline() -> Result { // Update the text layout. This function is only updating pango's internal state. // So e.g. that after a 90 degree rotation it knows that what was previously going // to end up as a 200x100 rectangle would now be 100x200. - pangocairo::functions::update_layout(&cr, &layout); + pangocairo::functions::update_layout(&cr, &**layout); let (width, _height) = layout.get_size(); // Using width and height of the text, we can properly possition it within // our canvas. @@ -201,7 +199,7 @@ fn create_pipeline() -> Result { ); // After telling the layout object where to draw itself, we actually tell // it to draw itself into our cairo context. - pangocairo::functions::show_layout(&cr, &layout); + pangocairo::functions::show_layout(&cr, &**layout); // Here we go one step up in our stack of transformations, removing any // changes we did to them since the last call to cr.save(); diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index b1c382b68..d62779617 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -7,6 +7,7 @@ // except according to those terms. use ffi; +use glib::object::ObjectType; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; @@ -190,7 +191,7 @@ impl AppSink { >, > = Box_::new(Box_::new(f)); connect_raw( - self.to_glib_none().0, + self.as_ptr() as *mut _, b"new-sample\0".as_ptr() as *const _, transmute(new_sample_trampoline as usize), Box_::into_raw(f) as *mut _, @@ -214,7 +215,7 @@ impl AppSink { >, > = Box_::new(Box_::new(f)); connect_raw( - self.to_glib_none().0, + self.as_ptr() as *mut _, b"new-preroll\0".as_ptr() as *const _, transmute(new_preroll_trampoline as usize), Box_::into_raw(f) as *mut _, diff --git a/gstreamer-base/src/aggregator.rs b/gstreamer-base/src/aggregator.rs index 9d652818e..118248fbd 100644 --- a/gstreamer-base/src/aggregator.rs +++ b/gstreamer-base/src/aggregator.rs @@ -22,7 +22,7 @@ impl> AggregatorExtManual for O { fn finish_buffer(&self, buffer: gst::Buffer) -> Result { let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_aggregator_finish_buffer( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, buffer.into_ptr(), )) }; diff --git a/gstreamer-base/src/aggregator_pad.rs b/gstreamer-base/src/aggregator_pad.rs index 1054368f4..5efaeb75c 100644 --- a/gstreamer-base/src/aggregator_pad.rs +++ b/gstreamer-base/src/aggregator_pad.rs @@ -7,8 +7,8 @@ // except according to those terms. use ffi; +use glib::object::{IsA, IsClassFor}; use glib::translate::*; -use glib::{IsA, IsClassFor}; use gst; use gst_ffi; use AggregatorPad; @@ -22,8 +22,7 @@ pub trait AggregatorPadExtManual: 'static { impl> AggregatorPadExtManual for O { fn get_segment(&self) -> gst::Segment { unsafe { - let stash = self.to_glib_none(); - let ptr: &ffi::GstAggregatorPad = &*stash.0; + let ptr: &ffi::GstAggregatorPad = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&ptr.parent.object.lock); from_glib_none(&ptr.segment as *const gst_ffi::GstSegment) } diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs index 4143f8e49..ad108d586 100644 --- a/gstreamer-base/src/base_sink.rs +++ b/gstreamer-base/src/base_sink.rs @@ -7,8 +7,8 @@ // except according to those terms. use ffi; +use glib::object::{IsA, IsClassFor}; use glib::translate::*; -use glib::{IsA, IsClassFor}; use gst; use std::mem; use std::ops; @@ -28,8 +28,7 @@ pub trait BaseSinkExtManual: 'static { impl> BaseSinkExtManual for O { fn get_segment(&self) -> gst::Segment { unsafe { - let stash = self.to_glib_none(); - let sink: &ffi::GstBaseSink = &*stash.0; + let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&sink.element.object.lock); from_glib_none(&sink.segment as *const _) } @@ -42,7 +41,7 @@ impl> BaseSinkExtManual for O { unsafe { let mut jitter = mem::uninitialized(); let ret: gst::FlowReturn = from_glib(ffi::gst_base_sink_wait( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, time.to_glib(), &mut jitter, )); @@ -51,8 +50,11 @@ impl> BaseSinkExtManual for O { } fn wait_preroll(&self) -> Result { - let ret: gst::FlowReturn = - unsafe { from_glib(ffi::gst_base_sink_wait_preroll(self.to_glib_none().0)) }; + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_base_sink_wait_preroll( + self.as_ref().to_glib_none().0, + )) + }; ret.into_result() } } diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs index e91550033..b29675451 100644 --- a/gstreamer-base/src/base_src.rs +++ b/gstreamer-base/src/base_src.rs @@ -7,8 +7,8 @@ // except according to those terms. use ffi; +use glib::object::{IsA, IsClassFor}; use glib::translate::*; -use glib::{IsA, IsClassFor}; use gst; use std::ops; use BaseSrc; @@ -26,8 +26,7 @@ pub trait BaseSrcExtManual: 'static { impl> BaseSrcExtManual for O { fn get_segment(&self) -> gst::Segment { unsafe { - let stash = self.to_glib_none(); - let src: &ffi::GstBaseSrc = &*stash.0; + let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&src.element.object.lock); from_glib_none(&src.segment as *const _) } @@ -36,19 +35,22 @@ impl> BaseSrcExtManual for O { fn start_complete(&self, ret: Result) { let ret: gst::FlowReturn = ret.into(); unsafe { - ffi::gst_base_src_start_complete(self.to_glib_none().0, ret.to_glib()); + ffi::gst_base_src_start_complete(self.as_ref().to_glib_none().0, ret.to_glib()); } } fn start_wait(&self) -> Result { let ret: gst::FlowReturn = - unsafe { from_glib(ffi::gst_base_src_start_wait(self.to_glib_none().0)) }; + unsafe { from_glib(ffi::gst_base_src_start_wait(self.as_ref().to_glib_none().0)) }; ret.into_result() } fn wait_playing(&self) -> Result { - let ret: gst::FlowReturn = - unsafe { from_glib(ffi::gst_base_src_wait_playing(self.to_glib_none().0)) }; + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_base_src_wait_playing( + self.as_ref().to_glib_none().0, + )) + }; ret.into_result() } } diff --git a/gstreamer-base/src/base_transform.rs b/gstreamer-base/src/base_transform.rs index b740d65bd..497b78ec8 100644 --- a/gstreamer-base/src/base_transform.rs +++ b/gstreamer-base/src/base_transform.rs @@ -7,8 +7,8 @@ // except according to those terms. use ffi; +use glib::object::{IsA, IsClassFor}; use glib::translate::*; -use glib::{IsA, IsClassFor}; use gst; use std::ops; use BaseTransform; @@ -20,8 +20,7 @@ pub trait BaseTransformExtManual: 'static { impl> BaseTransformExtManual for O { fn get_segment(&self) -> gst::Segment { unsafe { - let stash = self.to_glib_none(); - let trans: &ffi::GstBaseTransform = &*stash.0; + let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&trans.element.object.lock); from_glib_none(&trans.segment as *const _) } diff --git a/gstreamer-base/src/flow_combiner.rs b/gstreamer-base/src/flow_combiner.rs index 56aebff07..96c1da6f7 100644 --- a/gstreamer-base/src/flow_combiner.rs +++ b/gstreamer-base/src/flow_combiner.rs @@ -35,7 +35,7 @@ impl FlowCombiner { pub fn add_pad>(&self, pad: &P) { unsafe { - ffi::gst_flow_combiner_add_pad(self.to_glib_none().0, pad.to_glib_none().0); + ffi::gst_flow_combiner_add_pad(self.to_glib_none().0, pad.as_ref().to_glib_none().0); } } @@ -47,7 +47,7 @@ impl FlowCombiner { pub fn remove_pad>(&self, pad: &P) { unsafe { - ffi::gst_flow_combiner_remove_pad(self.to_glib_none().0, pad.to_glib_none().0); + ffi::gst_flow_combiner_remove_pad(self.to_glib_none().0, pad.as_ref().to_glib_none().0); } } @@ -80,7 +80,7 @@ impl FlowCombiner { let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_flow_combiner_update_pad_flow( self.to_glib_none().0, - pad.to_glib_none().0, + pad.as_ref().to_glib_none().0, fret.to_glib(), )) }; diff --git a/gstreamer-base/src/functions.rs b/gstreamer-base/src/functions.rs index 130acb33f..974aeb41c 100644 --- a/gstreamer-base/src/functions.rs +++ b/gstreamer-base/src/functions.rs @@ -23,13 +23,12 @@ pub fn type_find_helper_for_data< ) -> (Option, gst::TypeFindProbability) { assert_initialized_main_thread!(); let obj = obj.into(); - let obj = obj.to_glib_none(); unsafe { let mut prob = mem::uninitialized(); let data = data.as_ref(); let (ptr, len) = (data.as_ptr(), data.len()); let ret = from_glib_full(ffi::gst_type_find_helper_for_data( - obj.0, + obj.map(|p| p.as_ref()).to_glib_none().0, mut_override(ptr), len, &mut prob, diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index 88f1f71e9..6a6076717 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -62,7 +62,7 @@ impl Harness { unsafe { ffi::gst_harness_add_element_full( self.0.as_ptr(), - element.to_glib_none().0, + element.as_ref().to_glib_none().0, hsrc.to_glib_none().0 as *mut _, element_sinkpad_name.0, hsink.to_glib_none().0 as *mut _, @@ -73,13 +73,16 @@ impl Harness { pub fn add_element_sink_pad>(&mut self, sinkpad: &P) { unsafe { - ffi::gst_harness_add_element_sink_pad(self.0.as_ptr(), sinkpad.to_glib_none().0); + ffi::gst_harness_add_element_sink_pad( + self.0.as_ptr(), + sinkpad.as_ref().to_glib_none().0, + ); } } pub fn add_element_src_pad>(&mut self, srcpad: &P) { unsafe { - ffi::gst_harness_add_element_src_pad(self.0.as_ptr(), srcpad.to_glib_none().0); + ffi::gst_harness_add_element_src_pad(self.0.as_ptr(), srcpad.as_ref().to_glib_none().0); } } @@ -563,7 +566,7 @@ impl Harness { let element_srcpad_name = element_srcpad_name.to_glib_none(); unsafe { Self::from_glib_full(ffi::gst_harness_new_full( - element.to_glib_none().0, + element.as_ref().to_glib_none().0, hsrc.to_glib_none().0 as *mut _, element_sinkpad_name.0, hsink.to_glib_none().0 as *mut _, @@ -595,7 +598,7 @@ impl Harness { let element_srcpad_name = element_srcpad_name.to_glib_none(); unsafe { Self::from_glib_full(ffi::gst_harness_new_with_element( - element.to_glib_none().0, + element.as_ref().to_glib_none().0, element_sinkpad_name.0, element_srcpad_name.0, )) diff --git a/gstreamer-editing-services/src/timeline_element.rs b/gstreamer-editing-services/src/timeline_element.rs index 05ff1b44d..bbce67c58 100644 --- a/gstreamer-editing-services/src/timeline_element.rs +++ b/gstreamer-editing-services/src/timeline_element.rs @@ -22,7 +22,7 @@ impl> TimelineElementExtManual for O { fn get_child_property(&self, name: &str) -> Option { unsafe { let found: bool = from_glib(ffi::ges_timeline_element_lookup_child( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut(), @@ -33,7 +33,7 @@ impl> TimelineElementExtManual for O { let mut value = glib::Value::uninitialized(); ffi::ges_timeline_element_get_child_property( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, value.to_glib_none_mut().0, ); @@ -44,7 +44,7 @@ impl> TimelineElementExtManual for O { fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError> { unsafe { let found: bool = from_glib(ffi::ges_timeline_element_lookup_child( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut(), @@ -55,7 +55,7 @@ impl> TimelineElementExtManual for O { let value = value.to_value(); ffi::ges_timeline_element_set_child_property( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0, ); diff --git a/gstreamer-gl/src/context.rs b/gstreamer-gl/src/context.rs index fbde54493..620503901 100644 --- a/gstreamer-gl/src/context.rs +++ b/gstreamer-gl/src/context.rs @@ -35,7 +35,7 @@ impl ContextGLExt for ContextRef { fn set_gl_display>(&self, display: &T) { unsafe { - ffi::gst_context_set_gl_display(self.as_mut_ptr(), display.to_glib_none().0); + ffi::gst_context_set_gl_display(self.as_mut_ptr(), display.as_ref().to_glib_none().0); } } } diff --git a/gstreamer-gl/src/gl_context.rs b/gstreamer-gl/src/gl_context.rs index 7324ea9df..8287a00bf 100644 --- a/gstreamer-gl/src/gl_context.rs +++ b/gstreamer-gl/src/gl_context.rs @@ -23,45 +23,18 @@ impl GLContext { available_apis: GLAPI, ) -> Option { from_glib_full(ffi::gst_gl_context_new_wrapped( - display.to_glib_none().0, + display.as_ref().to_glib_none().0, handle, context_type.to_glib(), available_apis.to_glib(), )) } -} -pub trait GLContextExtManual: 'static { - fn get_gl_context(&self) -> uintptr_t; - - fn get_proc_address(&self, name: &str) -> uintptr_t; - - fn get_current_gl_context(context_type: GLPlatform) -> uintptr_t; - - fn get_proc_address_with_platform( - context_type: GLPlatform, - gl_api: GLAPI, - name: &str, - ) -> uintptr_t; -} - -impl> GLContextExtManual for O { - fn get_gl_context(&self) -> uintptr_t { - unsafe { ffi::gst_gl_context_get_gl_context(self.to_glib_none().0) as uintptr_t } - } - - fn get_proc_address(&self, name: &str) -> uintptr_t { - unsafe { - ffi::gst_gl_context_get_proc_address(self.to_glib_none().0, name.to_glib_none().0) - as uintptr_t - } - } - - fn get_current_gl_context(context_type: GLPlatform) -> uintptr_t { + pub fn get_current_gl_context(context_type: GLPlatform) -> uintptr_t { unsafe { ffi::gst_gl_context_get_current_gl_context(context_type.to_glib()) as uintptr_t } } - fn get_proc_address_with_platform( + pub fn get_proc_address_with_platform( context_type: GLPlatform, gl_api: GLAPI, name: &str, @@ -75,3 +48,24 @@ impl> GLContextExtManual for O { } } } + +pub trait GLContextExtManual: 'static { + fn get_gl_context(&self) -> uintptr_t; + + fn get_proc_address(&self, name: &str) -> uintptr_t; +} + +impl> GLContextExtManual for O { + fn get_gl_context(&self) -> uintptr_t { + unsafe { ffi::gst_gl_context_get_gl_context(self.as_ref().to_glib_none().0) as uintptr_t } + } + + fn get_proc_address(&self, name: &str) -> uintptr_t { + unsafe { + ffi::gst_gl_context_get_proc_address( + self.as_ref().to_glib_none().0, + name.to_glib_none().0, + ) as uintptr_t + } + } +} diff --git a/gstreamer-net/src/net_client_clock.rs b/gstreamer-net/src/net_client_clock.rs index a3a3366f0..82b585faa 100644 --- a/gstreamer-net/src/net_client_clock.rs +++ b/gstreamer-net/src/net_client_clock.rs @@ -9,7 +9,7 @@ use ffi; use NetClientClock; -use glib::object::Downcast; +use glib::object::Cast; use glib::translate::*; use gst; @@ -32,7 +32,7 @@ impl NetClientClock { remote_port, base_time.to_glib(), )) - .downcast_unchecked() + .unsafe_cast() } } else { // Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 @@ -43,7 +43,7 @@ impl NetClientClock { remote_port, base_time.to_glib(), )) - .downcast_unchecked() + .unsafe_cast() } } } diff --git a/gstreamer-net/src/net_time_provider.rs b/gstreamer-net/src/net_time_provider.rs index 477212098..28d8e90ad 100644 --- a/gstreamer-net/src/net_time_provider.rs +++ b/gstreamer-net/src/net_time_provider.rs @@ -27,7 +27,7 @@ impl NetTimeProvider { if (major, minor) > (1, 12) { unsafe { from_glib_full(ffi::gst_net_time_provider_new( - clock.to_glib_none().0, + clock.as_ref().to_glib_none().0, address.0, port, )) @@ -36,7 +36,7 @@ impl NetTimeProvider { // Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 unsafe { from_glib_none(ffi::gst_net_time_provider_new( - clock.to_glib_none().0, + clock.as_ref().to_glib_none().0, address.0, port, )) diff --git a/gstreamer-net/src/ntp_clock.rs b/gstreamer-net/src/ntp_clock.rs index 3b3727a20..f99828db4 100644 --- a/gstreamer-net/src/ntp_clock.rs +++ b/gstreamer-net/src/ntp_clock.rs @@ -9,7 +9,7 @@ use ffi; use NtpClock; -use glib::object::Downcast; +use glib::object::Cast; use glib::translate::*; use gst; @@ -32,7 +32,7 @@ impl NtpClock { remote_port, base_time.to_glib(), )) - .downcast_unchecked() + .unsafe_cast() } } else { // Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 @@ -43,7 +43,7 @@ impl NtpClock { remote_port, base_time.to_glib(), )) - .downcast_unchecked() + .unsafe_cast() } } } diff --git a/gstreamer-net/src/ptp_clock.rs b/gstreamer-net/src/ptp_clock.rs index 37f2a6767..3064ae906 100644 --- a/gstreamer-net/src/ptp_clock.rs +++ b/gstreamer-net/src/ptp_clock.rs @@ -9,7 +9,7 @@ use ffi; use PtpClock; -use glib::object::Downcast; +use glib::object::Cast; use glib::translate::*; use gst; @@ -21,14 +21,12 @@ impl PtpClock { let (major, minor, _, _) = gst::version(); if (major, minor) > (1, 12) { unsafe { - gst::Clock::from_glib_full(ffi::gst_ptp_clock_new(name.0, domain)) - .downcast_unchecked() + gst::Clock::from_glib_full(ffi::gst_ptp_clock_new(name.0, domain)).unsafe_cast() } } else { // Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 unsafe { - gst::Clock::from_glib_none(ffi::gst_ptp_clock_new(name.0, domain)) - .downcast_unchecked() + gst::Clock::from_glib_none(ffi::gst_ptp_clock_new(name.0, domain)).unsafe_cast() } } } diff --git a/gstreamer-pbutils/src/discoverer.rs b/gstreamer-pbutils/src/discoverer.rs index f2a8395ab..7d074f286 100644 --- a/gstreamer-pbutils/src/discoverer.rs +++ b/gstreamer-pbutils/src/discoverer.rs @@ -11,8 +11,8 @@ use gst; use auto::Discoverer; -use glib::object::Downcast; -use glib::signal::connect; +use glib::object::{Cast, ObjectType}; +use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use glib::IsA; @@ -29,7 +29,7 @@ impl Discoverer { pub fn set_property_timeout(&self, timeout: gst::ClockTime) { unsafe { gobject_ffi::g_object_set_property( - self.to_glib_none().0, + self.as_ptr() as *mut _, "timeout".to_glib_none().0, Value::from(&timeout).to_glib_none().0, ); @@ -40,7 +40,7 @@ impl Discoverer { let mut value = Value::from(&0u64); unsafe { gobject_ffi::g_object_get_property( - self.to_glib_none().0, + self.as_ptr() as *mut _, "timeout".to_glib_none().0, value.to_glib_none_mut().0, ); @@ -54,9 +54,9 @@ impl Discoverer { ) -> SignalHandlerId { unsafe { let f: Box_> = Box_::new(Box_::new(f)); - connect( - self.to_glib_none().0, - "notify::timeout", + connect_raw( + self.as_ptr() as *mut _, + b"notify::timeout\0".as_ptr() as *const _, transmute(notify_timeout_trampoline:: as usize), Box_::into_raw(f) as *mut _, ) @@ -73,5 +73,5 @@ unsafe extern "C" fn notify_timeout_trampoline

( { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f); - f(&Discoverer::from_glib_borrow(this).downcast_unchecked()) + f(&Discoverer::from_glib_borrow(this).unsafe_cast()) } diff --git a/gstreamer-pbutils/src/encoding_profile.rs b/gstreamer-pbutils/src/encoding_profile.rs index c6ce4720a..fe648ec28 100644 --- a/gstreamer-pbutils/src/encoding_profile.rs +++ b/gstreamer-pbutils/src/encoding_profile.rs @@ -43,11 +43,11 @@ trait EncodingProfileBuilderCommon { fn set_restriction<'a, P: Into>>(&self, restriction: P); } -impl + IsA> EncodingProfileBuilderCommon for O { +impl> EncodingProfileBuilderCommon for O { fn set_allow_dynamic_output(&self, allow_dynamic_output: bool) { unsafe { ffi::gst_encoding_profile_set_allow_dynamic_output( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, allow_dynamic_output.to_glib(), ); } @@ -57,19 +57,28 @@ impl + IsA> EncodingProfileBuilder let description = description.into(); let description = description.to_glib_none(); unsafe { - ffi::gst_encoding_profile_set_description(self.to_glib_none().0, description.0); + ffi::gst_encoding_profile_set_description( + self.as_ref().to_glib_none().0, + description.0, + ); } } fn set_enabled(&self, enabled: bool) { unsafe { - ffi::gst_encoding_profile_set_enabled(self.to_glib_none().0, enabled.to_glib()); + ffi::gst_encoding_profile_set_enabled( + self.as_ref().to_glib_none().0, + enabled.to_glib(), + ); } } fn set_format(&self, format: &gst::Caps) { unsafe { - ffi::gst_encoding_profile_set_format(self.to_glib_none().0, format.to_glib_none().0); + ffi::gst_encoding_profile_set_format( + self.as_ref().to_glib_none().0, + format.to_glib_none().0, + ); } } @@ -77,13 +86,13 @@ impl + IsA> EncodingProfileBuilder let name = name.into(); let name = name.to_glib_none(); unsafe { - ffi::gst_encoding_profile_set_name(self.to_glib_none().0, name.0); + ffi::gst_encoding_profile_set_name(self.as_ref().to_glib_none().0, name.0); } } fn set_presence(&self, presence: u32) { unsafe { - ffi::gst_encoding_profile_set_presence(self.to_glib_none().0, presence); + ffi::gst_encoding_profile_set_presence(self.as_ref().to_glib_none().0, presence); } } @@ -91,7 +100,7 @@ impl + IsA> EncodingProfileBuilder let preset = preset.into(); let preset = preset.to_glib_none(); unsafe { - ffi::gst_encoding_profile_set_preset(self.to_glib_none().0, preset.0); + ffi::gst_encoding_profile_set_preset(self.as_ref().to_glib_none().0, preset.0); } } @@ -99,7 +108,10 @@ impl + IsA> EncodingProfileBuilder let preset_name = preset_name.into(); let preset_name = preset_name.to_glib_none(); unsafe { - ffi::gst_encoding_profile_set_preset_name(self.to_glib_none().0, preset_name.0); + ffi::gst_encoding_profile_set_preset_name( + self.as_ref().to_glib_none().0, + preset_name.0, + ); } } @@ -111,7 +123,7 @@ impl + IsA> EncodingProfileBuilder None => gst_ffi::gst_caps_new_any(), }; - ffi::gst_encoding_profile_set_restriction(self.to_glib_none().0, restriction); + ffi::gst_encoding_profile_set_restriction(self.as_ref().to_glib_none().0, restriction); } } } @@ -216,7 +228,7 @@ impl EncodingContainerProfile { glib_result_from_gboolean!( ffi::gst_encoding_container_profile_add_profile( self.to_glib_none().0, - profile.to_glib_full(), + profile.as_ref().to_glib_full(), ), "Failed to add profile", ) @@ -463,9 +475,7 @@ impl<'a> EncodingContainerProfileBuilder<'a> { } pub fn add_profile>(mut self, profile: &P) -> Self { - unsafe { - self.profiles.push(from_glib_none(profile.to_glib_none().0)); - } + self.profiles.push(profile.as_ref().clone()); self } } @@ -574,9 +584,8 @@ mod tests { ); assert_eq!(video_profile.is_enabled(), ENABLED); - let video_profile: EncodingVideoProfile = glib::object::Downcast::downcast(video_profile) - .ok() - .unwrap(); + let video_profile: EncodingVideoProfile = + glib::object::Cast::downcast(video_profile).ok().unwrap(); assert_eq!(video_profile.get_variableframerate(), VARIABLE_FRAMERATE); assert_eq!(video_profile.get_pass(), PASS); } @@ -632,7 +641,7 @@ mod tests { assert_eq!(profile.is_enabled(), ENABLED); let container_profile: EncodingContainerProfile = - glib::object::Downcast::downcast(profile).ok().unwrap(); + glib::object::Cast::downcast(profile).ok().unwrap(); assert!(container_profile.contains_profile(&video_profile)); assert!(container_profile.contains_profile(&audio_profile)); diff --git a/gstreamer-player/src/player.rs b/gstreamer-player/src/player.rs index 09e24ba7c..704a6c73c 100644 --- a/gstreamer-player/src/player.rs +++ b/gstreamer-player/src/player.rs @@ -8,7 +8,8 @@ use ffi; use glib; -use glib::signal::connect; +use glib::object::ObjectType; +use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use glib_ffi; @@ -58,9 +59,9 @@ impl Player { unsafe { let f: Box_> = Box_::new(Box_::new(f)); - connect( - self.to_glib_none().0, - "duration-changed", + connect_raw( + self.as_ptr() as *mut _, + b"duration-changed\0".as_ptr() as *const _, transmute(duration_changed_trampoline as usize), Box_::into_raw(f) as *mut _, ) @@ -74,9 +75,9 @@ impl Player { unsafe { let f: Box_> = Box_::new(Box_::new(f)); - connect( - self.to_glib_none().0, - "position-updated", + connect_raw( + self.as_ptr() as *mut _, + b"position-updated\0".as_ptr() as *const _, transmute(position_updated_trampoline as usize), Box_::into_raw(f) as *mut _, ) @@ -90,9 +91,9 @@ impl Player { unsafe { let f: Box_> = Box_::new(Box_::new(f)); - connect( - self.to_glib_none().0, - "seek-done", + connect_raw( + self.as_ptr() as *mut _, + b"seek-done\0".as_ptr() as *const _, transmute(seek_done_trampoline as usize), Box_::into_raw(f) as *mut _, ) diff --git a/gstreamer-player/src/player_video_overlay_video_renderer.rs b/gstreamer-player/src/player_video_overlay_video_renderer.rs index 59c195df9..521c9f45f 100644 --- a/gstreamer-player/src/player_video_overlay_video_renderer.rs +++ b/gstreamer-player/src/player_video_overlay_video_renderer.rs @@ -33,7 +33,7 @@ impl PlayerVideoOverlayVideoRenderer { from_glib_full(ffi::gst_player_video_overlay_video_renderer_new_with_sink( window_handle as *mut _, - video_sink.to_glib_none().0, + video_sink.as_ref().to_glib_none().0, ) as *mut _) } @@ -43,7 +43,7 @@ impl PlayerVideoOverlayVideoRenderer { unsafe { from_glib_full(ffi::gst_player_video_overlay_video_renderer_new_with_sink( ptr::null_mut(), - video_sink.to_glib_none().0, + video_sink.as_ref().to_glib_none().0, ) as *mut _) } } diff --git a/gstreamer-rtsp-server/src/rtsp_address_pool.rs b/gstreamer-rtsp-server/src/rtsp_address_pool.rs index 242a7b776..2b1876fac 100644 --- a/gstreamer-rtsp-server/src/rtsp_address_pool.rs +++ b/gstreamer-rtsp-server/src/rtsp_address_pool.rs @@ -27,7 +27,7 @@ impl> RTSPAddressPoolExtManual for O { unsafe { let mut address = ptr::null_mut(); let ret = from_glib(ffi::gst_rtsp_address_pool_reserve_address( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, ip_address.to_glib_none().0, port, n_ports, diff --git a/gstreamer-rtsp-server/src/rtsp_auth.rs b/gstreamer-rtsp-server/src/rtsp_auth.rs index 2d62befd1..214e1822e 100644 --- a/gstreamer-rtsp-server/src/rtsp_auth.rs +++ b/gstreamer-rtsp-server/src/rtsp_auth.rs @@ -12,7 +12,10 @@ impl> RTSPAuthExtManual for O { fn set_default_token<'a, P: Into>>(&self, token: P) { let mut token = token.into(); unsafe { - ffi::gst_rtsp_auth_set_default_token(self.to_glib_none().0, token.to_glib_none_mut().0); + ffi::gst_rtsp_auth_set_default_token( + self.as_ref().to_glib_none().0, + token.to_glib_none_mut().0, + ); } } } diff --git a/gstreamer-rtsp-server/src/rtsp_client.rs b/gstreamer-rtsp-server/src/rtsp_client.rs index 2b05cb71f..5fcdc1ea3 100644 --- a/gstreamer-rtsp-server/src/rtsp_client.rs +++ b/gstreamer-rtsp-server/src/rtsp_client.rs @@ -12,11 +12,10 @@ pub trait RTSPClientExtManual: 'static { impl> RTSPClientExtManual for O { fn attach<'a, P: Into>>(&self, context: P) -> SourceId { let context = context.into(); - let context = context.to_glib_none(); unsafe { from_glib(ffi::gst_rtsp_client_attach( - self.to_glib_none().0, - context.0, + self.as_ref().to_glib_none().0, + context.to_glib_none().0, )) } } diff --git a/gstreamer-rtsp-server/src/rtsp_media_factory.rs b/gstreamer-rtsp-server/src/rtsp_media_factory.rs index 14cd50885..0bc79bded 100644 --- a/gstreamer-rtsp-server/src/rtsp_media_factory.rs +++ b/gstreamer-rtsp-server/src/rtsp_media_factory.rs @@ -10,6 +10,8 @@ use RTSPMediaFactory; #[cfg(any(feature = "v1_14", feature = "dox"))] use ffi; +#[cfg(any(feature = "v1_14", feature = "dox"))] +use glib::translate::*; use glib::IsA; #[cfg(any(feature = "v1_14", feature = "dox"))] use gst; @@ -24,7 +26,7 @@ impl> RTSPMediaFactoryExtManual for O { fn add_role_from_structure(&self, structure: &gst::StructureRef) { unsafe { ffi::gst_rtsp_media_factory_add_role_from_structure( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, structure.as_mut_ptr(), ); } diff --git a/gstreamer-rtsp-server/src/rtsp_server.rs b/gstreamer-rtsp-server/src/rtsp_server.rs index a7cf7cc59..1a12fd1e3 100644 --- a/gstreamer-rtsp-server/src/rtsp_server.rs +++ b/gstreamer-rtsp-server/src/rtsp_server.rs @@ -12,11 +12,10 @@ pub trait RTSPServerExtManual: 'static { impl> RTSPServerExtManual for O { fn attach<'a, P: Into>>(&self, context: P) -> SourceId { let context = context.into(); - let context = context.to_glib_none(); unsafe { from_glib(ffi::gst_rtsp_server_attach( - self.to_glib_none().0, - context.0, + self.as_ref().to_glib_none().0, + context.to_glib_none().0, )) } } diff --git a/gstreamer-rtsp-server/src/rtsp_session_pool.rs b/gstreamer-rtsp-server/src/rtsp_session_pool.rs index 06ac74069..edf5d937b 100644 --- a/gstreamer-rtsp-server/src/rtsp_session_pool.rs +++ b/gstreamer-rtsp-server/src/rtsp_session_pool.rs @@ -54,7 +54,7 @@ impl> RTSPSessionPoolExtManual for O { { skip_assert_initialized!(); unsafe { - let source = ffi::gst_rtsp_session_pool_create_watch(self.to_glib_none().0); + let source = ffi::gst_rtsp_session_pool_create_watch(self.as_ref().to_glib_none().0); let trampoline = trampoline_watch as gpointer; glib_ffi::g_source_set_callback( source, diff --git a/gstreamer-rtsp-server/src/rtsp_stream.rs b/gstreamer-rtsp-server/src/rtsp_stream.rs index d0ccfda6b..8b52b4059 100644 --- a/gstreamer-rtsp-server/src/rtsp_stream.rs +++ b/gstreamer-rtsp-server/src/rtsp_stream.rs @@ -14,7 +14,7 @@ impl> RTSPStreamExtManual for O { fn recv_rtcp(&self, buffer: &gst::Buffer) -> Result { let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_rtsp_stream_recv_rtcp( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, buffer.to_glib_full(), )) }; @@ -24,7 +24,7 @@ impl> RTSPStreamExtManual for O { fn recv_rtp(&self, buffer: &gst::Buffer) -> Result { let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_rtsp_stream_recv_rtp( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, buffer.to_glib_full(), )) }; diff --git a/gstreamer-rtsp-server/src/rtsp_stream_transport.rs b/gstreamer-rtsp-server/src/rtsp_stream_transport.rs index 450106d4b..af662dda9 100644 --- a/gstreamer-rtsp-server/src/rtsp_stream_transport.rs +++ b/gstreamer-rtsp-server/src/rtsp_stream_transport.rs @@ -20,7 +20,7 @@ impl> RTSPStreamTransportExtManual for O { ) -> Result { let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_rtsp_stream_transport_recv_data( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, channel, buffer.to_glib_full(), )) diff --git a/gstreamer-video/src/video_overlay.rs b/gstreamer-video/src/video_overlay.rs index 5b69dc8ba..54cf0eac1 100644 --- a/gstreamer-video/src/video_overlay.rs +++ b/gstreamer-video/src/video_overlay.rs @@ -22,11 +22,11 @@ pub trait VideoOverlayExtManual: 'static { impl> VideoOverlayExtManual for O { unsafe fn set_window_handle(&self, handle: uintptr_t) { - ffi::gst_video_overlay_set_window_handle(self.to_glib_none().0, handle) + ffi::gst_video_overlay_set_window_handle(self.as_ref().to_glib_none().0, handle) } unsafe fn got_window_handle(&self, handle: uintptr_t) { - ffi::gst_video_overlay_got_window_handle(self.to_glib_none().0, handle) + ffi::gst_video_overlay_got_window_handle(self.as_ref().to_glib_none().0, handle) } } diff --git a/gstreamer/src/bin.rs b/gstreamer/src/bin.rs index 29199aa94..fdbc3bec0 100644 --- a/gstreamer/src/bin.rs +++ b/gstreamer/src/bin.rs @@ -10,8 +10,9 @@ use Bin; use Element; use glib; +use glib::object::{IsA, IsClassFor}; use glib::translate::{from_glib, from_glib_full, FromGlibPtrContainer, ToGlib, ToGlibPtr}; -use glib::{GString, IsA, IsClassFor}; +use glib::GString; use ffi; @@ -43,8 +44,10 @@ impl> GstBinExtManual for O { fn add_many>(&self, elements: &[&E]) -> Result<(), glib::BoolError> { for e in elements { unsafe { - let ret: bool = - from_glib(ffi::gst_bin_add(self.to_glib_none().0, e.to_glib_none().0)); + let ret: bool = from_glib(ffi::gst_bin_add( + self.as_ref().to_glib_none().0, + e.as_ref().to_glib_none().0, + )); if !ret { return Err(glib_bool_error!("Failed to add elements")); } @@ -58,8 +61,8 @@ impl> GstBinExtManual for O { for e in elements { unsafe { let ret: bool = from_glib(ffi::gst_bin_remove( - self.to_glib_none().0, - e.to_glib_none().0, + self.as_ref().to_glib_none().0, + e.as_ref().to_glib_none().0, )); if !ret { return Err(glib_bool_error!("Failed to add elements")); @@ -73,36 +76,39 @@ impl> GstBinExtManual for O { fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator { unsafe { from_glib_full(ffi::gst_bin_iterate_all_by_interface( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, iface.to_glib(), )) } } fn iterate_elements(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_bin_iterate_elements(self.to_glib_none().0)) } + unsafe { + from_glib_full(ffi::gst_bin_iterate_elements( + self.as_ref().to_glib_none().0, + )) + } } fn iterate_recurse(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.to_glib_none().0)) } + unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.as_ref().to_glib_none().0)) } } fn iterate_sinks(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.to_glib_none().0)) } + unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.as_ref().to_glib_none().0)) } } fn iterate_sorted(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.to_glib_none().0)) } + unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.as_ref().to_glib_none().0)) } } fn iterate_sources(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.to_glib_none().0)) } + unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.as_ref().to_glib_none().0)) } } fn get_children(&self) -> Vec { unsafe { - let stash = self.to_glib_none(); - let bin: &ffi::GstBin = &*stash.0; + let bin: &ffi::GstBin = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&bin.element.object.lock); FromGlibPtrContainer::from_glib_none(bin.children) } diff --git a/gstreamer/src/buffer_pool.rs b/gstreamer/src/buffer_pool.rs index 5daaff7a0..e105aa778 100644 --- a/gstreamer/src/buffer_pool.rs +++ b/gstreamer/src/buffer_pool.rs @@ -241,7 +241,7 @@ pub trait BufferPoolExtManual: 'static { impl> BufferPoolExtManual for O { fn get_config(&self) -> BufferPoolConfig { unsafe { - let ptr = ffi::gst_buffer_pool_get_config(self.to_glib_none().0); + let ptr = ffi::gst_buffer_pool_get_config(self.as_ref().to_glib_none().0); BufferPoolConfig(from_glib_full(ptr)) } } @@ -249,7 +249,10 @@ impl> BufferPoolExtManual for O { fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!( - ffi::gst_buffer_pool_set_config(self.to_glib_none().0, config.0.into_ptr()), + ffi::gst_buffer_pool_set_config( + self.as_ref().to_glib_none().0, + config.0.into_ptr() + ), "Failed to set config", ) } @@ -257,7 +260,7 @@ impl> BufferPoolExtManual for O { fn is_flushing(&self) -> bool { unsafe { - let stash = self.to_glib_none(); + let stash = self.as_ref().to_glib_none(); let ptr: *mut ffi::GstBufferPool = stash.0; from_glib((*ptr).flushing) @@ -277,7 +280,7 @@ impl> BufferPoolExtManual for O { unsafe { let mut buffer = ptr::null_mut(); let ret: ::FlowReturn = from_glib(ffi::gst_buffer_pool_acquire_buffer( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, &mut buffer, params_ptr, )); @@ -288,7 +291,7 @@ impl> BufferPoolExtManual for O { fn release_buffer(&self, buffer: ::Buffer) { unsafe { - ffi::gst_buffer_pool_release_buffer(self.to_glib_none().0, buffer.into_ptr()); + ffi::gst_buffer_pool_release_buffer(self.as_ref().to_glib_none().0, buffer.into_ptr()); } } } diff --git a/gstreamer/src/child_proxy.rs b/gstreamer/src/child_proxy.rs index b46ef0754..193bbd542 100644 --- a/gstreamer/src/child_proxy.rs +++ b/gstreamer/src/child_proxy.rs @@ -22,7 +22,7 @@ impl> ChildProxyExtManual for O { fn get_child_property(&self, name: &str) -> Option { unsafe { let found: bool = from_glib(ffi::gst_child_proxy_lookup( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut(), @@ -33,7 +33,7 @@ impl> ChildProxyExtManual for O { let mut value = glib::Value::uninitialized(); ffi::gst_child_proxy_get_property( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, value.to_glib_none_mut().0, ); @@ -44,7 +44,7 @@ impl> ChildProxyExtManual for O { fn set_child_property(&self, name: &str, value: &glib::ToValue) -> Result<(), glib::BoolError> { unsafe { let found: bool = from_glib(ffi::gst_child_proxy_lookup( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut(), @@ -55,7 +55,7 @@ impl> ChildProxyExtManual for O { let value = value.to_value(); ffi::gst_child_proxy_set_property( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0, ); diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index ad367c90b..b084c4f2c 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -186,7 +186,7 @@ impl> ClockExtManual for O { fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option { unsafe { from_glib_full(ffi::gst_clock_new_periodic_id( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, start_time.to_glib(), interval.to_glib(), )) @@ -202,7 +202,7 @@ impl> ClockExtManual for O { skip_assert_initialized!(); unsafe { let res: bool = from_glib(ffi::gst_clock_periodic_id_reinit( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, id.to_glib_none().0, start_time.to_glib(), interval.to_glib(), @@ -218,7 +218,7 @@ impl> ClockExtManual for O { fn new_single_shot_id(&self, time: ClockTime) -> Option { unsafe { from_glib_full(ffi::gst_clock_new_single_shot_id( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, time.to_glib(), )) } @@ -227,7 +227,7 @@ impl> ClockExtManual for O { fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError> { unsafe { let res: bool = from_glib(ffi::gst_clock_single_shot_id_reinit( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, id.to_glib_none().0, time.to_glib(), )); diff --git a/gstreamer/src/device_provider.rs b/gstreamer/src/device_provider.rs index 444216f36..dfdf61f43 100644 --- a/gstreamer/src/device_provider.rs +++ b/gstreamer/src/device_provider.rs @@ -8,8 +8,8 @@ use DeviceProvider; +use glib::object::IsA; use glib::translate::ToGlibPtr; -use glib::IsA; use std::ffi::CStr; @@ -23,7 +23,7 @@ pub trait DeviceProviderExtManual: 'static { impl> DeviceProviderExtManual for O { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> { unsafe { - let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class + let klass = (*(self.as_ptr() as *mut gobject_ffi::GTypeInstance)).g_class as *mut ffi::GstDeviceProviderClass; let ptr = ffi::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0); diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 2610c6b74..bf12f92f7 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -10,13 +10,13 @@ use Element; use glib; #[cfg(any(feature = "v1_10", feature = "dox"))] -use glib::object::Downcast; +use glib::object::Cast; +use glib::object::{IsA, IsClassFor}; #[cfg(any(feature = "v1_10", feature = "dox"))] use glib::translate::FromGlibPtrBorrow; use glib::translate::{ from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrContainer, ToGlib, ToGlibPtr, }; -use glib::{IsA, IsClassFor}; use miniobject::MiniObject; use ClockTime; use Event; @@ -50,8 +50,8 @@ impl Element { for (e1, e2) in elements.iter().zip(elements.iter().skip(1)) { unsafe { let ret: bool = from_glib(ffi::gst_element_link( - e1.to_glib_none().0, - e2.to_glib_none().0, + e1.as_ref().to_glib_none().0, + e2.as_ref().to_glib_none().0, )); if !ret { return Err(glib_bool_error!("Failed to link elements")); @@ -66,7 +66,7 @@ impl Element { skip_assert_initialized!(); for (e1, e2) in elements.iter().zip(elements.iter().skip(1)) { unsafe { - ffi::gst_element_unlink(e1.to_glib_none().0, e2.to_glib_none().0); + ffi::gst_element_unlink(e1.as_ref().to_glib_none().0, e2.as_ref().to_glib_none().0); } } } @@ -216,7 +216,7 @@ pub trait ElementExtManual: 'static { impl> ElementExtManual for O { fn get_element_class(&self) -> &ElementClass { unsafe { - let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class + let klass = (*(self.as_ptr() as *mut gobject_ffi::GTypeInstance)).g_class as *const ElementClass; &*klass } @@ -228,7 +228,7 @@ impl> ElementExtManual for O { ) -> Result { let ret: StateChangeReturn = unsafe { from_glib(ffi::gst_element_change_state( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, transition.to_glib(), )) }; @@ -241,7 +241,7 @@ impl> ElementExtManual for O { ) -> Result { let ret: StateChangeReturn = unsafe { from_glib(ffi::gst_element_continue_state( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, ret.to_glib(), )) }; @@ -256,7 +256,7 @@ impl> ElementExtManual for O { let mut state = mem::uninitialized(); let mut pending = mem::uninitialized(); let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, &mut state, &mut pending, timeout.to_glib(), @@ -268,7 +268,7 @@ impl> ElementExtManual for O { fn set_state(&self, state: State) -> Result { let ret: StateChangeReturn = unsafe { from_glib(ffi::gst_element_set_state( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, state.to_glib(), )) }; @@ -278,7 +278,7 @@ impl> ElementExtManual for O { fn query(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_element_query( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, query.as_mut_ptr(), )) } @@ -287,7 +287,7 @@ impl> ElementExtManual for O { fn send_event(&self, event: Event) -> bool { unsafe { from_glib(ffi::gst_element_send_event( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, event.into_ptr(), )) } @@ -323,7 +323,7 @@ impl> ElementExtManual for O { }; ffi::gst_element_message_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, type_, T::domain().to_glib(), code.code(), @@ -356,7 +356,7 @@ impl> ElementExtManual for O { }; ffi::gst_element_message_full_with_details( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, type_, T::domain().to_glib(), code.code(), @@ -383,7 +383,7 @@ impl> ElementExtManual for O { unsafe { ffi::gst_element_message_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, ffi::GST_MESSAGE_ERROR, error_domain.to_glib(), error_code, @@ -397,21 +397,32 @@ impl> ElementExtManual for O { } fn iterate_pads(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_element_iterate_pads(self.to_glib_none().0)) } + unsafe { + from_glib_full(ffi::gst_element_iterate_pads( + self.as_ref().to_glib_none().0, + )) + } } fn iterate_sink_pads(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_element_iterate_sink_pads(self.to_glib_none().0)) } + unsafe { + from_glib_full(ffi::gst_element_iterate_sink_pads( + self.as_ref().to_glib_none().0, + )) + } } fn iterate_src_pads(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_element_iterate_src_pads(self.to_glib_none().0)) } + unsafe { + from_glib_full(ffi::gst_element_iterate_src_pads( + self.as_ref().to_glib_none().0, + )) + } } fn get_pads(&self) -> Vec { unsafe { - let stash = self.to_glib_none(); - let elt: &ffi::GstElement = &*stash.0; + let elt: &ffi::GstElement = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&elt.object.lock); FromGlibPtrContainer::from_glib_none(elt.pads) } @@ -419,8 +430,7 @@ impl> ElementExtManual for O { fn get_sink_pads(&self) -> Vec { unsafe { - let stash = self.to_glib_none(); - let elt: &ffi::GstElement = &*stash.0; + let elt: &ffi::GstElement = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&elt.object.lock); FromGlibPtrContainer::from_glib_none(elt.sinkpads) } @@ -428,8 +438,7 @@ impl> ElementExtManual for O { fn get_src_pads(&self) -> Vec { unsafe { - let stash = self.to_glib_none(); - let elt: &ffi::GstElement = &*stash.0; + let elt: &ffi::GstElement = &*(self.as_ptr() as *const _); ::utils::MutexGuard::lock(&elt.object.lock); FromGlibPtrContainer::from_glib_none(elt.srcpads) } @@ -445,7 +454,7 @@ impl> ElementExtManual for O { let property_name = property_name.to_glib_none(); unsafe { from_glib(ffi::gst_element_add_property_deep_notify_watch( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, property_name.0, include_value.to_glib(), )) @@ -462,7 +471,7 @@ impl> ElementExtManual for O { let property_name = property_name.to_glib_none(); unsafe { from_glib(ffi::gst_element_add_property_notify_watch( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, property_name.0, include_value.to_glib(), )) @@ -472,7 +481,10 @@ impl> ElementExtManual for O { #[cfg(any(feature = "v1_10", feature = "dox"))] fn remove_property_notify_watch(&self, watch_id: NotifyWatchId) { unsafe { - ffi::gst_element_remove_property_notify_watch(self.to_glib_none().0, watch_id.0); + ffi::gst_element_remove_property_notify_watch( + self.as_ref().to_glib_none().0, + watch_id.0, + ); } } @@ -484,7 +496,7 @@ impl> ElementExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.to_raw_value(), U::get_default_format().to_glib(), @@ -507,7 +519,7 @@ impl> ElementExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.get_value(), dest_format.to_glib(), @@ -525,7 +537,7 @@ impl> ElementExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut duration, )); @@ -541,7 +553,7 @@ impl> ElementExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut duration, )); @@ -557,7 +569,7 @@ impl> ElementExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut cur, )); @@ -573,7 +585,7 @@ impl> ElementExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_element_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut cur, )); @@ -602,7 +614,7 @@ impl> ElementExtManual for O { unsafe { glib_result_from_gboolean!( ffi::gst_element_seek( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, rate, start.get_format().to_glib(), flags.to_glib(), @@ -625,7 +637,7 @@ impl> ElementExtManual for O { unsafe { glib_result_from_gboolean!( ffi::gst_element_seek_simple( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, seek_pos.get_format().to_glib(), seek_flags.to_glib(), seek_pos.get_value(), @@ -649,7 +661,7 @@ impl> ElementExtManual for O { let user_data: &mut Option> = &mut *(user_data as *mut _); let callback = user_data.take().unwrap(); - callback(&Element::from_glib_borrow(element).downcast_unchecked()); + callback(&Element::from_glib_borrow(element).unsafe_cast()); } unsafe extern "C" fn free_user_data, F: FnOnce(&O) + Send + 'static>( @@ -662,7 +674,7 @@ impl> ElementExtManual for O { let free_user_data = free_user_data::; unsafe { ffi::gst_element_call_async( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline), Box::into_raw(user_data) as *mut _, Some(free_user_data), diff --git a/gstreamer/src/ghost_pad.rs b/gstreamer/src/ghost_pad.rs index 34f2e5667..54b6b1845 100644 --- a/gstreamer/src/ghost_pad.rs +++ b/gstreamer/src/ghost_pad.rs @@ -7,7 +7,7 @@ // except according to those terms. use ffi; -use glib::object::Downcast; +use glib::object::Cast; use glib::object::{IsA, IsClassFor}; use glib::translate::*; use GhostPad; @@ -24,8 +24,11 @@ impl GhostPad { let name = name.into(); let name = name.to_glib_none(); unsafe { - Option::::from_glib_none(ffi::gst_ghost_pad_new(name.0, target.to_glib_none().0)) - .map(|o| Downcast::downcast_unchecked(o)) + Option::::from_glib_none(ffi::gst_ghost_pad_new( + name.0, + target.as_ref().to_glib_none().0, + )) + .map(|o| Cast::unsafe_cast(o)) } } @@ -40,10 +43,10 @@ impl GhostPad { unsafe { Option::::from_glib_none(ffi::gst_ghost_pad_new_from_template( name.0, - target.to_glib_none().0, + target.as_ref().to_glib_none().0, templ.to_glib_none().0, )) - .map(|o| Downcast::downcast_unchecked(o)) + .map(|o| Cast::unsafe_cast(o)) } } @@ -60,11 +63,10 @@ impl GhostPad { ) -> bool { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib(ffi::gst_ghost_pad_activate_mode_default( pad.to_glib_none().0 as *mut ffi::GstPad, - parent.0, + parent.map(|p| p.as_ref()).to_glib_none().0, mode.to_glib(), active.to_glib(), )) @@ -84,11 +86,10 @@ impl GhostPad { ) -> bool { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib(ffi::gst_ghost_pad_internal_activate_mode_default( pad.to_glib_none().0 as *mut ffi::GstPad, - parent.0, + parent.map(|p| p.as_ref()).to_glib_none().0, mode.to_glib(), active.to_glib(), )) diff --git a/gstreamer/src/gobject.rs b/gstreamer/src/gobject.rs index fb2bd321d..6979c6760 100644 --- a/gstreamer/src/gobject.rs +++ b/gstreamer/src/gobject.rs @@ -12,7 +12,7 @@ impl> GObjectExtManualGst for O { fn set_property_from_str(&self, name: &str, value: &str) { unsafe { ffi::gst_util_set_object_arg( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0, ); diff --git a/gstreamer/src/object.rs b/gstreamer/src/object.rs index cb9a3dd89..65ba83c6e 100644 --- a/gstreamer/src/object.rs +++ b/gstreamer/src/object.rs @@ -7,7 +7,7 @@ // except according to those terms. use glib; -use glib::object::{Downcast, ObjectExt}; +use glib::object::{Cast, ObjectExt}; use glib::signal::SignalHandlerId; use glib::translate::{from_glib_borrow, from_glib_none, ToGlibPtr}; use glib::IsA; @@ -44,10 +44,10 @@ impl> GstObjectExtManual for O { }; let obj: glib::Object = - unsafe { from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject) }; + unsafe { from_glib_borrow(self.as_ptr() as *mut gobject_ffi::GObject) }; obj.connect(signal_name.as_str(), false, move |values| { - let obj: O = unsafe { values[0].get::<::Object>().unwrap().downcast_unchecked() }; + let obj: O = unsafe { values[0].get::<::Object>().unwrap().unsafe_cast() }; let prop_obj: ::Object = values[1].get().unwrap(); let pspec = unsafe { diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 63450321e..4f51fbd89 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -35,12 +35,12 @@ use std::ops; use std::ptr; use glib; +use glib::object::{IsA, IsClassFor}; use glib::translate::{ from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, FromGlib, ToGlib, ToGlibPtr, }; -use glib::Object; -use glib::{IsA, IsClassFor, StaticType}; +use glib::StaticType; use glib_ffi; use glib_ffi::gpointer; @@ -127,7 +127,7 @@ pub trait PadExtManual: 'static { fn peer_query(&self, query: &mut QueryRef) -> bool; fn query(&self, query: &mut QueryRef) -> bool; - fn query_default<'a, P: IsA + 'a, Q: Into>>( + fn query_default<'a, P: IsA<::Object> + 'a, Q: Into>>( &self, parent: Q, query: &mut QueryRef, @@ -273,7 +273,7 @@ impl> PadExtManual for O { Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static, > = Box::new(func); let id = ffi::gst_pad_add_probe( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, mask.to_glib(), Some(trampoline_pad_probe), Box::into_raw(Box::new(func_box)) as gpointer, @@ -290,28 +290,34 @@ impl> PadExtManual for O { fn remove_probe(&self, id: PadProbeId) { unsafe { - ffi::gst_pad_remove_probe(self.to_glib_none().0, id.to_glib()); + ffi::gst_pad_remove_probe(self.as_ref().to_glib_none().0, id.to_glib()); } } fn chain(&self, buffer: Buffer) -> Result { unsafe { - FlowReturn::from_glib(ffi::gst_pad_chain(self.to_glib_none().0, buffer.into_ptr())) - .into_result() + FlowReturn::from_glib(ffi::gst_pad_chain( + self.as_ref().to_glib_none().0, + buffer.into_ptr(), + )) + .into_result() } } fn push(&self, buffer: Buffer) -> Result { unsafe { - FlowReturn::from_glib(ffi::gst_pad_push(self.to_glib_none().0, buffer.into_ptr())) - .into_result() + FlowReturn::from_glib(ffi::gst_pad_push( + self.as_ref().to_glib_none().0, + buffer.into_ptr(), + )) + .into_result() } } fn chain_list(&self, list: BufferList) -> Result { unsafe { FlowReturn::from_glib(ffi::gst_pad_chain_list( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, list.into_ptr(), )) .into_result() @@ -321,7 +327,7 @@ impl> PadExtManual for O { fn push_list(&self, list: BufferList) -> Result { unsafe { FlowReturn::from_glib(ffi::gst_pad_push_list( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, list.into_ptr(), )) .into_result() @@ -332,7 +338,7 @@ impl> PadExtManual for O { unsafe { let mut buffer = ptr::null_mut(); let ret: FlowReturn = from_glib(ffi::gst_pad_get_range( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, offset, size, &mut buffer, @@ -345,7 +351,7 @@ impl> PadExtManual for O { unsafe { let mut buffer = ptr::null_mut(); let ret: FlowReturn = from_glib(ffi::gst_pad_pull_range( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, offset, size, &mut buffer, @@ -357,7 +363,7 @@ impl> PadExtManual for O { fn query(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_pad_query( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, query.as_mut_ptr(), )) } @@ -366,24 +372,23 @@ impl> PadExtManual for O { fn peer_query(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_pad_peer_query( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, query.as_mut_ptr(), )) } } - fn query_default<'a, P: IsA + 'a, Q: Into>>( + fn query_default<'a, P: IsA<::Object> + 'a, Q: Into>>( &self, parent: Q, query: &mut QueryRef, ) -> bool { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib(ffi::gst_pad_query_default( - self.to_glib_none().0, - parent.0 as *mut _, + self.as_ref().to_glib_none().0, + parent.map(|p| p.as_ref()).to_glib_none().0, query.as_mut_ptr(), )) } @@ -392,7 +397,7 @@ impl> PadExtManual for O { fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_pad_proxy_query_accept_caps( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, query.as_mut_ptr(), )) } @@ -401,7 +406,7 @@ impl> PadExtManual for O { fn proxy_query_caps(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_pad_proxy_query_accept_caps( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, query.as_mut_ptr(), )) } @@ -414,11 +419,10 @@ impl> PadExtManual for O { ) -> bool { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib(ffi::gst_pad_event_default( - self.to_glib_none().0, - parent.0, + self.as_ref().to_glib_none().0, + parent.map(|p| p.as_ref()).to_glib_none().0, event.into_ptr(), )) } @@ -427,7 +431,7 @@ impl> PadExtManual for O { fn push_event(&self, event: Event) -> bool { unsafe { from_glib(ffi::gst_pad_push_event( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, event.into_ptr(), )) } @@ -436,20 +440,27 @@ impl> PadExtManual for O { fn send_event(&self, event: Event) -> bool { unsafe { from_glib(ffi::gst_pad_send_event( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, event.into_ptr(), )) } } fn get_last_flow_return(&self) -> Result { - let ret: FlowReturn = - unsafe { from_glib(ffi::gst_pad_get_last_flow_return(self.to_glib_none().0)) }; + let ret: FlowReturn = unsafe { + from_glib(ffi::gst_pad_get_last_flow_return( + self.as_ref().to_glib_none().0, + )) + }; ret.into_result() } fn iterate_internal_links(&self) -> ::Iterator { - unsafe { from_glib_full(ffi::gst_pad_iterate_internal_links(self.to_glib_none().0)) } + unsafe { + from_glib_full(ffi::gst_pad_iterate_internal_links( + self.as_ref().to_glib_none().0, + )) + } } fn iterate_internal_links_default<'a, P: IsA<::Object> + 'a, Q: Into>>( @@ -457,11 +468,10 @@ impl> PadExtManual for O { parent: Q, ) -> ::Iterator { let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib_full(ffi::gst_pad_iterate_internal_links_default( - self.to_glib_none().0, - parent.0, + self.as_ref().to_glib_none().0, + parent.map(|p| p.as_ref()).to_glib_none().0, )) } } @@ -469,8 +479,8 @@ impl> PadExtManual for O { fn link>(&self, sinkpad: &P) -> Result { let ret: PadLinkReturn = unsafe { from_glib(ffi::gst_pad_link( - self.to_glib_none().0, - sinkpad.to_glib_none().0, + self.as_ref().to_glib_none().0, + sinkpad.as_ref().to_glib_none().0, )) }; ret.into_result() @@ -483,8 +493,8 @@ impl> PadExtManual for O { ) -> Result { let ret: PadLinkReturn = unsafe { from_glib(ffi::gst_pad_link_full( - self.to_glib_none().0, - sinkpad.to_glib_none().0, + self.as_ref().to_glib_none().0, + sinkpad.as_ref().to_glib_none().0, flags.to_glib(), )) }; @@ -493,9 +503,9 @@ impl> PadExtManual for O { fn stream_lock(&self) -> StreamLock { unsafe { - let pad = self.to_glib_none().0; - glib_ffi::g_rec_mutex_lock(&mut (*pad).stream_rec_lock); - StreamLock(from_glib_none(pad)) + let ptr: &mut ffi::GstPad = &mut *(self.as_ptr() as *mut _); + glib_ffi::g_rec_mutex_lock(&mut ptr.stream_rec_lock); + StreamLock(from_glib_none(ptr as *mut ffi::GstPad)) } } @@ -508,7 +518,7 @@ impl> PadExtManual for O { let func_box: Box) -> bool + Send + Sync + 'static> = Box::new(func); ffi::gst_pad_set_activate_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_activate_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -526,7 +536,7 @@ impl> PadExtManual for O { Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool + Send + Sync + 'static, > = Box::new(func); ffi::gst_pad_set_activatemode_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_activatemode_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -549,7 +559,7 @@ impl> PadExtManual for O { + 'static, > = Box::new(func); ffi::gst_pad_set_chain_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_chain_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -572,7 +582,7 @@ impl> PadExtManual for O { + 'static, > = Box::new(func); ffi::gst_pad_set_chain_list_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_chain_list_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -589,7 +599,7 @@ impl> PadExtManual for O { Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static, > = Box::new(func); ffi::gst_pad_set_event_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_event_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -612,7 +622,7 @@ impl> PadExtManual for O { + 'static, > = Box::new(func); ffi::gst_pad_set_event_full_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_event_full_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -636,7 +646,7 @@ impl> PadExtManual for O { + 'static, > = Box::new(func); ffi::gst_pad_set_getrange_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_getrange_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -653,7 +663,7 @@ impl> PadExtManual for O { Fn(&Pad, &Option<::Object>) -> ::Iterator + Send + Sync + 'static, > = Box::new(func); ffi::gst_pad_set_iterate_internal_links_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_iterate_internal_links_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -676,7 +686,7 @@ impl> PadExtManual for O { + 'static, > = Box::new(func); ffi::gst_pad_set_link_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_link_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -693,7 +703,7 @@ impl> PadExtManual for O { Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static, > = Box::new(func); ffi::gst_pad_set_query_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_query_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -708,7 +718,7 @@ impl> PadExtManual for O { unsafe { let func_box: Box) + Send + Sync + 'static> = Box::new(func); ffi::gst_pad_set_unlink_function_full( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_unlink_function), Box::into_raw(Box::new(func_box)) as gpointer, Some(destroy_closure), @@ -720,7 +730,7 @@ impl> PadExtManual for O { unsafe { glib_result_from_gboolean!( ffi::gst_pad_start_task( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, Some(trampoline_pad_task), into_raw_pad_task(func), Some(destroy_closure_pad_task), @@ -738,7 +748,7 @@ impl> PadExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.to_raw_value(), U::get_default_format().to_glib(), @@ -761,7 +771,7 @@ impl> PadExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.to_raw_value(), dest_format.to_glib(), @@ -779,7 +789,7 @@ impl> PadExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut duration, )); @@ -795,7 +805,7 @@ impl> PadExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut duration, )); @@ -811,7 +821,7 @@ impl> PadExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut cur, )); @@ -827,7 +837,7 @@ impl> PadExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_peer_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut cur, )); @@ -848,7 +858,7 @@ impl> PadExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.to_raw_value(), U::get_default_format().to_glib(), @@ -872,7 +882,7 @@ impl> PadExtManual for O { unsafe { let mut dest_val = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_convert( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, src_val.get_format().to_glib(), src_val.get_value(), dest_format.to_glib(), @@ -890,7 +900,7 @@ impl> PadExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut duration, )); @@ -906,7 +916,7 @@ impl> PadExtManual for O { unsafe { let mut duration = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_duration( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut duration, )); @@ -922,7 +932,7 @@ impl> PadExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, T::get_default_format().to_glib(), &mut cur, )); @@ -938,7 +948,7 @@ impl> PadExtManual for O { unsafe { let mut cur = mem::uninitialized(); let ret = from_glib(ffi::gst_pad_query_position( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, format.to_glib(), &mut cur, )); @@ -952,8 +962,7 @@ impl> PadExtManual for O { fn get_mode(&self) -> ::PadMode { unsafe { - let stash = self.to_glib_none(); - let ptr: &ffi::GstPad = &*stash.0; + let ptr: &ffi::GstPad = &*(self.as_ptr() as *const _); from_glib(ptr.mode) } } @@ -998,14 +1007,18 @@ impl> PadExtManual for O { as *const &mut (FnMut(Event) -> Result, Option>) as glib_ffi::gpointer; - ffi::gst_pad_sticky_events_foreach(self.to_glib_none().0, Some(trampoline), func_ptr); + ffi::gst_pad_sticky_events_foreach( + self.as_ref().to_glib_none().0, + Some(trampoline), + func_ptr, + ); } } fn store_sticky_event(&self, event: &Event) -> Result { let ret: FlowReturn = unsafe { from_glib(ffi::gst_pad_store_sticky_event( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, event.to_glib_none().0, )) }; diff --git a/gstreamer/src/proxy_pad.rs b/gstreamer/src/proxy_pad.rs index 02b76aaa7..d7bb5d4c4 100644 --- a/gstreamer/src/proxy_pad.rs +++ b/gstreamer/src/proxy_pad.rs @@ -16,8 +16,8 @@ use Object; use Pad; use ProxyPad; +use glib::object::IsA; use glib::translate::{from_glib, from_glib_full, ToGlibPtr}; -use glib::IsA; use ffi; @@ -29,11 +29,10 @@ impl ProxyPad { ) -> Result { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); let ret: FlowReturn = unsafe { from_glib(ffi::gst_proxy_pad_chain_default( - pad.to_glib_none().0 as *mut ffi::GstPad, - parent.0, + pad.as_ptr() as *mut ffi::GstPad, + parent.map(|p| p.as_ref()).to_glib_none().0, buffer.into_ptr(), )) }; @@ -47,11 +46,10 @@ impl ProxyPad { ) -> Result { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); let ret: FlowReturn = unsafe { from_glib(ffi::gst_proxy_pad_chain_list_default( - pad.to_glib_none().0 as *mut ffi::GstPad, - parent.0, + pad.as_ptr() as *mut ffi::GstPad, + parent.map(|p| p.as_ref()).to_glib_none().0, list.into_ptr(), )) }; @@ -68,8 +66,8 @@ impl ProxyPad { unsafe { let mut buffer = ptr::null_mut(); let ret: FlowReturn = from_glib(ffi::gst_proxy_pad_getrange_default( - pad.to_glib_none().0 as *mut ffi::GstPad, - parent.to_glib_none().0, + pad.as_ptr() as *mut ffi::GstPad, + parent.as_ref().to_glib_none().0, offset, size, &mut buffer, @@ -89,11 +87,10 @@ impl ProxyPad { ) -> Option<::Iterator> { skip_assert_initialized!(); let parent = parent.into(); - let parent = parent.to_glib_none(); unsafe { from_glib_full(ffi::gst_proxy_pad_iterate_internal_links_default( - pad.to_glib_none().0 as *mut ffi::GstPad, - parent.0, + pad.as_ptr() as *mut ffi::GstPad, + parent.map(|p| p.as_ref()).to_glib_none().0, )) } } diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 3a5c98a00..54c8b9381 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -152,7 +152,7 @@ where ) -> R { unsafe { assert!(element.get_type().is_a(&T::get_type())); - let ptr: *mut ffi::GstElement = element.to_glib_none().0; + let ptr: *mut ffi::GstElement = element.as_ptr() as *mut _; let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); diff --git a/gstreamer/src/subclass/mod.rs b/gstreamer/src/subclass/mod.rs index eabd761d4..19277fdf5 100644 --- a/gstreamer/src/subclass/mod.rs +++ b/gstreamer/src/subclass/mod.rs @@ -39,7 +39,7 @@ use std::sync::atomic::AtomicBool; #[repr(C)] pub struct ElementInstanceStruct { - parent: ::GlibType, + parent: ::GlibType, panicked: AtomicBool, } diff --git a/gstreamer/src/tag_setter.rs b/gstreamer/src/tag_setter.rs index 9c76f32bb..5a00845ba 100644 --- a/gstreamer/src/tag_setter.rs +++ b/gstreamer/src/tag_setter.rs @@ -29,7 +29,7 @@ impl> TagSetterExtManual for O { let v = value.to_send_value(); ffi::gst_tag_setter_add_tag_value( - self.to_glib_none().0, + self.as_ref().to_glib_none().0, mode.to_glib(), T::tag_name().to_glib_none().0, v.to_glib_none().0, diff --git a/tutorials/src/bin/basic-tutorial-5.rs b/tutorials/src/bin/basic-tutorial-5.rs index 4b1f4e703..018322b43 100644 --- a/tutorials/src/bin/basic-tutorial-5.rs +++ b/tutorials/src/bin/basic-tutorial-5.rs @@ -4,7 +4,7 @@ mod tutorial5 { use std::process; extern crate glib; - use self::glib::translate::*; + use self::glib::object::ObjectType; use self::glib::*; extern crate gdk; @@ -223,7 +223,7 @@ mod tutorial5 { } unsafe { - let xid = gdk_x11_window_get_xid(gdk_window.to_glib_none().0); + let xid = gdk_x11_window_get_xid(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(xid as usize); } } else { @@ -239,7 +239,7 @@ mod tutorial5 { } unsafe { - let window = gdk_quartz_window_get_nsview(gdk_window.to_glib_none().0); + let window = gdk_quartz_window_get_nsview(gdk_window.as_ptr() as *mut _); video_overlay.set_window_handle(window as usize); } } else {