From 8aac047af5f8b0bf3f5b6b4b472d5826a59ccd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 5 Jan 2020 04:38:55 +0200 Subject: [PATCH] Use NonZeroU64/U32 for PadProbeId, NotifyId and DeviceMonitorFilterId This allows for some further optimizations. --- gstreamer/src/device_monitor.rs | 8 +++++--- gstreamer/src/element.rs | 9 +++++---- gstreamer/src/pad.rs | 9 +++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gstreamer/src/device_monitor.rs b/gstreamer/src/device_monitor.rs index 1c86b2eee..960a4a021 100644 --- a/gstreamer/src/device_monitor.rs +++ b/gstreamer/src/device_monitor.rs @@ -15,6 +15,8 @@ use glib::translate::*; use gst_sys; +use std::num::NonZeroU32; + impl DeviceMonitor { pub fn new() -> DeviceMonitor { assert_initialized_main_thread!(); @@ -35,13 +37,13 @@ impl Default for DeviceMonitor { } #[derive(Debug, PartialEq, Eq)] -pub struct DeviceMonitorFilterId(libc::c_uint); +pub struct DeviceMonitorFilterId(NonZeroU32); impl ToGlib for DeviceMonitorFilterId { type GlibType = libc::c_uint; fn to_glib(&self) -> libc::c_uint { - self.0 + self.0.get() } } @@ -49,7 +51,7 @@ impl FromGlib for DeviceMonitorFilterId { fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId { skip_assert_initialized!(); assert_ne!(val, 0); - DeviceMonitorFilterId(val) + DeviceMonitorFilterId(unsafe { NonZeroU32::new_unchecked(val) }) } } diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 575a94213..ad36cd521 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -39,6 +39,7 @@ use StateChangeSuccess; use std::ffi::CStr; use std::mem; +use std::num::NonZeroU64; use libc; @@ -106,13 +107,13 @@ pub enum ElementMessageType { } #[derive(Debug, PartialEq, Eq)] -pub struct NotifyWatchId(libc::c_ulong); +pub struct NotifyWatchId(NonZeroU64); impl ToGlib for NotifyWatchId { type GlibType = libc::c_ulong; fn to_glib(&self) -> libc::c_ulong { - self.0 + self.0.get() as libc::c_ulong } } @@ -120,7 +121,7 @@ impl FromGlib for NotifyWatchId { fn from_glib(val: libc::c_ulong) -> NotifyWatchId { skip_assert_initialized!(); assert_ne!(val, 0); - NotifyWatchId(val) + NotifyWatchId(unsafe { NonZeroU64::new_unchecked(val as u64) }) } } @@ -569,7 +570,7 @@ impl> ElementExtManual for O { unsafe { gst_sys::gst_element_remove_property_notify_watch( self.as_ref().to_glib_none().0, - watch_id.0, + watch_id.to_glib(), ); } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 69da1d6ec..378c7ef48 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -32,6 +32,7 @@ use StaticPadTemplate; use std::cell::RefCell; use std::mem; +use std::num::NonZeroU64; use std::ptr; use glib; @@ -61,13 +62,13 @@ impl Pad { } #[derive(Debug, PartialEq, Eq)] -pub struct PadProbeId(libc::c_ulong); +pub struct PadProbeId(NonZeroU64); impl ToGlib for PadProbeId { type GlibType = libc::c_ulong; fn to_glib(&self) -> libc::c_ulong { - self.0 + self.0.get() as libc::c_ulong } } @@ -75,7 +76,7 @@ impl FromGlib for PadProbeId { fn from_glib(val: libc::c_ulong) -> PadProbeId { skip_assert_initialized!(); assert_ne!(val, 0); - PadProbeId(val) + PadProbeId(unsafe { NonZeroU64::new_unchecked(val as u64) }) } } @@ -1032,7 +1033,7 @@ where let mut probe_info = PadProbeInfo { mask: from_glib((*info).type_), - id: PadProbeId((*info).id), + id: PadProbeId(NonZeroU64::new_unchecked((*info).id)), offset: (*info).offset, size: (*info).size, data: if (*info).data.is_null() {