mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-22 08:07:07 +00:00
Implement Sync/Send for more types and don't implement Send for TypeFind
They can actually be shared with multiple threads at the same time safely as all functions requiring an immutable reference are thread-safe. OTOH TypeFind can't be shared safely between different threads as not all implementations of the TypeFind struct are thread-safe.
This commit is contained in:
parent
da8187b016
commit
2ba5105b80
28 changed files with 95 additions and 8 deletions
|
@ -87,6 +87,9 @@ impl Drop for AudioRingBufferSpec {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for AudioRingBufferSpec {}
|
||||
unsafe impl Sync for AudioRingBufferSpec {}
|
||||
|
||||
impl fmt::Debug for AudioRingBufferSpec {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("AudioRingBufferSpec")
|
||||
|
|
|
@ -23,6 +23,9 @@ pub struct BaseParseFrame<'a>(
|
|||
PhantomData<&'a BaseParse>,
|
||||
);
|
||||
|
||||
unsafe impl<'a> Send for BaseParseFrame<'a> {}
|
||||
unsafe impl<'a> Sync for BaseParseFrame<'a> {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Overhead {
|
||||
None,
|
||||
|
|
|
@ -36,6 +36,7 @@ impl Drop for Harness {
|
|||
}
|
||||
|
||||
unsafe impl Send for Harness {}
|
||||
unsafe impl Sync for Harness {}
|
||||
|
||||
impl Harness {
|
||||
pub fn add_element_full<P: IsA<gst::Element>>(
|
||||
|
@ -792,7 +793,7 @@ impl Harness {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ref<'a>(Option<Harness>, PhantomData<&'a gst_check_sys::GstHarness>);
|
||||
pub struct Ref<'a>(Option<Harness>, PhantomData<&'a Harness>);
|
||||
|
||||
impl<'a> ops::Deref for Ref<'a> {
|
||||
type Target = Harness;
|
||||
|
@ -810,10 +811,7 @@ impl<'a> Drop for Ref<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RefMut<'a>(
|
||||
Option<Harness>,
|
||||
PhantomData<&'a mut gst_check_sys::GstHarness>,
|
||||
);
|
||||
pub struct RefMut<'a>(Option<Harness>, PhantomData<&'a mut Harness>);
|
||||
|
||||
impl<'a> ops::Deref for RefMut<'a> {
|
||||
type Target = Harness;
|
||||
|
|
|
@ -11,6 +11,9 @@ use GLContext;
|
|||
#[repr(C)]
|
||||
pub struct GLSyncMeta(gst_gl_sys::GstGLSyncMeta);
|
||||
|
||||
unsafe impl Send for GLSyncMeta {}
|
||||
unsafe impl Sync for GLSyncMeta {}
|
||||
|
||||
impl GLSyncMeta {
|
||||
pub fn add<'a, C: IsA<GLContext>>(
|
||||
buffer: &'a mut gst::BufferRef,
|
||||
|
|
|
@ -10,6 +10,9 @@ use gst_net_sys;
|
|||
#[repr(C)]
|
||||
pub struct NetAddressMeta(gst_net_sys::GstNetAddressMeta);
|
||||
|
||||
unsafe impl Send for NetAddressMeta {}
|
||||
unsafe impl Sync for NetAddressMeta {}
|
||||
|
||||
impl NetAddressMeta {
|
||||
pub fn add<'a, A: IsA<gio::SocketAddress>>(
|
||||
buffer: &'a mut gst::BufferRef,
|
||||
|
|
|
@ -11,6 +11,9 @@ pub enum Writable {}
|
|||
#[repr(C)]
|
||||
pub struct RTPBuffer<'a, T>(gst_rtp_sys::GstRTPBuffer, &'a gst::Buffer, PhantomData<T>);
|
||||
|
||||
unsafe impl<'a, T> Send for RTPBuffer<'a, T> {}
|
||||
unsafe impl<'a, T> Sync for RTPBuffer<'a, T> {}
|
||||
|
||||
impl<'a> RTPBuffer<'a, Readable> {
|
||||
pub fn from_buffer_readable(
|
||||
buffer: &gst::Buffer,
|
||||
|
|
|
@ -16,6 +16,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPAttribute(pub(crate) gst_sdp_sys::GstSDPAttribute);
|
||||
|
||||
unsafe impl Send for SDPAttribute {}
|
||||
unsafe impl Sync for SDPAttribute {}
|
||||
|
||||
impl SDPAttribute {
|
||||
pub fn new(key: &str, value: Option<&str>) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
|
|
@ -16,6 +16,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPBandwidth(pub(crate) gst_sdp_sys::GstSDPBandwidth);
|
||||
|
||||
unsafe impl Send for SDPBandwidth {}
|
||||
unsafe impl Sync for SDPBandwidth {}
|
||||
|
||||
impl SDPBandwidth {
|
||||
pub fn new(bwtype: &str, bandwidth: u32) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
|
|
@ -16,6 +16,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPConnection(pub(crate) gst_sdp_sys::GstSDPConnection);
|
||||
|
||||
unsafe impl Send for SDPConnection {}
|
||||
unsafe impl Sync for SDPConnection {}
|
||||
|
||||
impl SDPConnection {
|
||||
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
|
|
@ -14,6 +14,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPKey(gst_sdp_sys::GstSDPKey);
|
||||
|
||||
unsafe impl Send for SDPKey {}
|
||||
unsafe impl Sync for SDPKey {}
|
||||
|
||||
impl SDPKey {
|
||||
pub fn type_(&self) -> Option<&str> {
|
||||
unsafe {
|
||||
|
|
|
@ -14,6 +14,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPOrigin(pub(crate) gst_sdp_sys::GstSDPOrigin);
|
||||
|
||||
unsafe impl Send for SDPOrigin {}
|
||||
unsafe impl Sync for SDPOrigin {}
|
||||
|
||||
impl SDPOrigin {
|
||||
pub fn username(&self) -> Option<&str> {
|
||||
unsafe {
|
||||
|
|
|
@ -18,6 +18,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPTime(pub(crate) gst_sdp_sys::GstSDPTime);
|
||||
|
||||
unsafe impl Send for SDPTime {}
|
||||
unsafe impl Sync for SDPTime {}
|
||||
|
||||
impl SDPTime {
|
||||
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
|
|
@ -16,6 +16,9 @@ use gst_sdp_sys;
|
|||
#[repr(C)]
|
||||
pub struct SDPZone(pub(crate) gst_sdp_sys::GstSDPZone);
|
||||
|
||||
unsafe impl Send for SDPZone {}
|
||||
unsafe impl Sync for SDPZone {}
|
||||
|
||||
impl SDPZone {
|
||||
pub fn new(time: &str, typed_time: &str) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
|
|
@ -663,6 +663,9 @@ impl<'a> ops::Deref for VideoFrameRef<&'a mut gst::BufferRef> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for VideoFrameRef<T> {}
|
||||
unsafe impl<T> Sync for VideoFrameRef<T> {}
|
||||
|
||||
impl<T> Drop for VideoFrameRef<T> {
|
||||
fn drop(&mut self) {
|
||||
if !self.3 {
|
||||
|
|
|
@ -18,6 +18,9 @@ use gst_video_sys;
|
|||
#[repr(C)]
|
||||
pub struct VideoMeta(gst_video_sys::GstVideoMeta);
|
||||
|
||||
unsafe impl Send for VideoMeta {}
|
||||
unsafe impl Sync for VideoMeta {}
|
||||
|
||||
impl VideoMeta {
|
||||
pub fn add(
|
||||
buffer: &mut gst::BufferRef,
|
||||
|
@ -134,6 +137,9 @@ impl fmt::Debug for VideoMeta {
|
|||
#[repr(C)]
|
||||
pub struct VideoOverlayCompositionMeta(gst_video_sys::GstVideoOverlayCompositionMeta);
|
||||
|
||||
unsafe impl Send for VideoOverlayCompositionMeta {}
|
||||
unsafe impl Sync for VideoOverlayCompositionMeta {}
|
||||
|
||||
impl VideoOverlayCompositionMeta {
|
||||
pub fn add<'a>(
|
||||
buffer: &'a mut gst::BufferRef,
|
||||
|
@ -186,6 +192,11 @@ impl fmt::Debug for VideoOverlayCompositionMeta {
|
|||
#[repr(C)]
|
||||
pub struct VideoCaptionMeta(gst_video_sys::GstVideoCaptionMeta);
|
||||
|
||||
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
||||
unsafe impl Send for VideoCaptionMeta {}
|
||||
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
||||
unsafe impl Sync for VideoCaptionMeta {}
|
||||
|
||||
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
||||
impl VideoCaptionMeta {
|
||||
pub fn add<'a>(
|
||||
|
|
|
@ -525,6 +525,9 @@ impl From<ValidVideoTimeCode> for VideoTimeCode {
|
|||
#[repr(C)]
|
||||
pub struct VideoTimeCodeMeta(gst_video_sys::GstVideoTimeCodeMeta);
|
||||
|
||||
unsafe impl Send for VideoTimeCodeMeta {}
|
||||
unsafe impl Sync for VideoTimeCodeMeta {}
|
||||
|
||||
impl VideoTimeCodeMeta {
|
||||
pub fn add<'a>(
|
||||
buffer: &'a mut gst::BufferRef,
|
||||
|
|
|
@ -15,6 +15,9 @@ use MemoryFlags;
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct AllocationParams(gst_sys::GstAllocationParams);
|
||||
|
||||
unsafe impl Send for AllocationParams {}
|
||||
unsafe impl Sync for AllocationParams {}
|
||||
|
||||
impl AllocationParams {
|
||||
pub fn get_flags(&self) -> MemoryFlags {
|
||||
from_glib(self.0.flags)
|
||||
|
|
|
@ -604,6 +604,9 @@ macro_rules! define_iter(
|
|||
items: PhantomData<$mtyp>,
|
||||
}
|
||||
|
||||
unsafe impl<'a, T: MetaAPI> Send for $name<'a, T> { }
|
||||
unsafe impl<'a, T: MetaAPI> Sync for $name<'a, T> { }
|
||||
|
||||
impl<'a, T: MetaAPI> $name<'a, T> {
|
||||
fn new(buffer: $typ) -> $name<'a, T> {
|
||||
skip_assert_initialized!();
|
||||
|
@ -778,6 +781,9 @@ impl<'a, T> Drop for BufferMap<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a, T> Send for BufferMap<'a, T> {}
|
||||
unsafe impl<'a, T> Sync for BufferMap<'a, T> {}
|
||||
|
||||
impl<T> MappedBuffer<T> {
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) }
|
||||
|
@ -860,6 +866,7 @@ impl<T> PartialEq for MappedBuffer<T> {
|
|||
impl<T> Eq for MappedBuffer<T> {}
|
||||
|
||||
unsafe impl<T> Send for MappedBuffer<T> {}
|
||||
unsafe impl<T> Sync for MappedBuffer<T> {}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref BUFFER_COPY_METADATA: ::BufferCopyFlags =
|
||||
|
|
|
@ -187,6 +187,9 @@ impl BufferPoolConfig {
|
|||
#[derive(Debug)]
|
||||
pub struct BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams);
|
||||
|
||||
unsafe impl Send for BufferPoolAcquireParams {}
|
||||
unsafe impl Sync for BufferPoolAcquireParams {}
|
||||
|
||||
impl BufferPoolAcquireParams {
|
||||
pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self {
|
||||
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams {
|
||||
|
|
|
@ -326,6 +326,7 @@ where
|
|||
}
|
||||
|
||||
unsafe impl<T> Send for Iterator<T> {}
|
||||
unsafe impl<T> Sync for Iterator<T> {}
|
||||
|
||||
unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpointer) -> i32
|
||||
where
|
||||
|
|
|
@ -380,6 +380,9 @@ impl<'a, T> Drop for MemoryMap<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a, T> Send for MemoryMap<'a, T> {}
|
||||
unsafe impl<'a, T> Sync for MemoryMap<'a, T> {}
|
||||
|
||||
impl<T> MappedMemory<T> {
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
unsafe { slice::from_raw_parts(self.map_info.data as *const u8, self.map_info.size) }
|
||||
|
@ -462,3 +465,4 @@ impl<T> PartialEq for MappedMemory<T> {
|
|||
impl<T> Eq for MappedMemory<T> {}
|
||||
|
||||
unsafe impl<T> Send for MappedMemory<T> {}
|
||||
unsafe impl<T> Sync for MappedMemory<T> {}
|
||||
|
|
|
@ -27,7 +27,7 @@ use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr};
|
|||
use glib_sys;
|
||||
use gst_sys;
|
||||
|
||||
pub unsafe trait MetaAPI: Sized {
|
||||
pub unsafe trait MetaAPI: Sync + Send + Sized {
|
||||
type GstType;
|
||||
|
||||
fn get_meta_api() -> glib::Type;
|
||||
|
@ -210,6 +210,9 @@ impl<'a, U> MetaRefMut<'a, Meta, U> {
|
|||
#[repr(C)]
|
||||
pub struct Meta(gst_sys::GstMeta);
|
||||
|
||||
unsafe impl Send for Meta {}
|
||||
unsafe impl Sync for Meta {}
|
||||
|
||||
impl Meta {
|
||||
fn get_api(&self) -> glib::Type {
|
||||
unsafe { glib::Type::from_glib((*self.0.info).api) }
|
||||
|
@ -235,6 +238,9 @@ impl fmt::Debug for Meta {
|
|||
#[repr(C)]
|
||||
pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta);
|
||||
|
||||
unsafe impl Send for ParentBufferMeta {}
|
||||
unsafe impl Sync for ParentBufferMeta {}
|
||||
|
||||
impl ParentBufferMeta {
|
||||
pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> {
|
||||
unsafe {
|
||||
|
@ -276,6 +282,11 @@ impl fmt::Debug for ParentBufferMeta {
|
|||
#[repr(C)]
|
||||
pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta);
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
unsafe impl Send for ReferenceTimestampMeta {}
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
unsafe impl Sync for ReferenceTimestampMeta {}
|
||||
|
||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||
impl ReferenceTimestampMeta {
|
||||
pub fn add<'a>(
|
||||
|
|
|
@ -99,6 +99,9 @@ pub enum PadProbeData<'a> {
|
|||
__Unknown(*mut gst_sys::GstMiniObject),
|
||||
}
|
||||
|
||||
unsafe impl<'a> Send for PadProbeData<'a> {}
|
||||
unsafe impl<'a> Sync for PadProbeData<'a> {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StreamLock(Pad);
|
||||
impl Drop for StreamLock {
|
||||
|
|
|
@ -25,6 +25,9 @@ glib_wrapper! {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for ParseContext {}
|
||||
unsafe impl Sync for ParseContext {}
|
||||
|
||||
impl ParseContext {
|
||||
pub fn new() -> Self {
|
||||
unsafe { from_glib_full(gst_sys::gst_parse_context_new()) }
|
||||
|
|
|
@ -508,6 +508,7 @@ impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
|
|||
impl<T: FormattedValue> Eq for FormattedSegment<T> {}
|
||||
|
||||
unsafe impl<T: FormattedValue> Send for FormattedSegment<T> {}
|
||||
unsafe impl<T: FormattedValue> Sync for FormattedSegment<T> {}
|
||||
|
||||
impl<T: FormattedValue> Clone for FormattedSegment<T> {
|
||||
fn clone(&self) -> Self {
|
||||
|
|
|
@ -25,6 +25,7 @@ macro_rules! gst_plugin_define(
|
|||
|
||||
#[repr(C)]
|
||||
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
|
||||
unsafe impl Send for GstPluginDesc {}
|
||||
unsafe impl Sync for GstPluginDesc {}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -23,6 +23,7 @@ macro_rules! gst_plugin_define(
|
|||
|
||||
#[repr(C)]
|
||||
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
|
||||
unsafe impl Send for GstPluginDesc {}
|
||||
unsafe impl Sync for GstPluginDesc {}
|
||||
|
||||
static GST_PLUGIN_DESC: GstPluginDesc = GstPluginDesc($crate::gst_sys::GstPluginDesc {
|
||||
|
|
|
@ -96,8 +96,6 @@ impl<'a> TypeFind<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a> Send for TypeFind<'a> {}
|
||||
|
||||
impl TypeFindFactory {
|
||||
pub fn call_function(&self, find: &mut dyn TypeFindImpl) {
|
||||
unsafe {
|
||||
|
|
Loading…
Reference in a new issue