From 8ba700301d3389df030db3ec417f225270131fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 15 Nov 2024 11:59:22 +0200 Subject: [PATCH] analytics: Manually implement FFI GstTensor because of flexible array member Part-of: --- gstreamer-analytics/sys/Gir.toml | 4 ++++ gstreamer-analytics/sys/src/lib.rs | 32 ++++---------------------- gstreamer-analytics/sys/src/manual.rs | 33 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 gstreamer-analytics/sys/src/manual.rs diff --git a/gstreamer-analytics/sys/Gir.toml b/gstreamer-analytics/sys/Gir.toml index c7a17f828..9da416b43 100644 --- a/gstreamer-analytics/sys/Gir.toml +++ b/gstreamer-analytics/sys/Gir.toml @@ -50,3 +50,7 @@ boxed_inline = true name = "GstAnalytics.Mtd" status = "generate" boxed_inline = true + +[[object]] +name = "GstAnalytics.Tensor" +status = "manual" diff --git a/gstreamer-analytics/sys/src/lib.rs b/gstreamer-analytics/sys/src/lib.rs index fed96b543..086fcc93b 100644 --- a/gstreamer-analytics/sys/src/lib.rs +++ b/gstreamer-analytics/sys/src/lib.rs @@ -15,6 +15,10 @@ use glib_sys as glib; use gstreamer_sys as gst; +mod manual; + +pub use manual::*; + #[cfg(unix)] #[allow(unused_imports)] use libc::{dev_t, gid_t, pid_t, socklen_t, uid_t}; @@ -206,34 +210,6 @@ impl ::std::fmt::Debug for GstAnalyticsTrackingMtd { } } -#[repr(C)] -#[allow(dead_code)] -pub struct GstTensor { - pub id: glib::GQuark, - pub layout: GstTensorLayout, - pub data_type: GstTensorDataType, - pub batch_size: size_t, - pub data: *mut gst::GstBuffer, - pub dims_order: GstTensorDimOrder, - pub num_dims: size_t, - _truncated_record_marker: c_void, - // /*Ignored*/field dims has empty c:type -} - -impl ::std::fmt::Debug for GstTensor { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - f.debug_struct(&format!("GstTensor @ {self:p}")) - .field("id", &self.id) - .field("layout", &self.layout) - .field("data_type", &self.data_type) - .field("batch_size", &self.batch_size) - .field("data", &self.data) - .field("dims_order", &self.dims_order) - .field("num_dims", &self.num_dims) - .finish() - } -} - #[derive(Copy, Clone)] #[repr(C)] pub struct GstTensorDim { diff --git a/gstreamer-analytics/sys/src/manual.rs b/gstreamer-analytics/sys/src/manual.rs new file mode 100644 index 000000000..be3f2eb17 --- /dev/null +++ b/gstreamer-analytics/sys/src/manual.rs @@ -0,0 +1,33 @@ +use gstreamer_sys as gst_sys; +use libc::size_t; + +use crate::{GstTensorDataType, GstTensorDim, GstTensorDimOrder, GstTensorLayout}; + +#[repr(C)] +pub struct GstTensor { + pub id: glib_sys::GQuark, + pub layout: GstTensorLayout, + pub data_type: GstTensorDataType, + pub batch_size: size_t, + pub data: *mut gst_sys::GstBuffer, + pub dims_order: GstTensorDimOrder, + pub num_dims: size_t, + pub dims: [GstTensorDim; 0], +} + +impl ::std::fmt::Debug for GstTensor { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + f.debug_struct(&format!("GstTensor @ {self:p}")) + .field("id", &self.id) + .field("layout", &self.layout) + .field("data_type", &self.data_type) + .field("batch_size", &self.batch_size) + .field("data", &self.data) + .field("dims_order", &self.dims_order) + .field("num_dims", &self.num_dims) + .field("dims", &unsafe { + ::std::slice::from_raw_parts(self.dims.as_ptr(), self.num_dims) + }) + .finish() + } +}