analytics: Manually implement FFI GstTensor because of flexible array member

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1591>
This commit is contained in:
Sebastian Dröge 2024-11-15 11:59:22 +02:00
parent 44006bc4f1
commit 8ba700301d
3 changed files with 41 additions and 28 deletions

View file

@ -50,3 +50,7 @@ boxed_inline = true
name = "GstAnalytics.Mtd"
status = "generate"
boxed_inline = true
[[object]]
name = "GstAnalytics.Tensor"
status = "manual"

View file

@ -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 {

View file

@ -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()
}
}