mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-30 05:50:31 +00:00
Add a Rust struct and store/use it in the C code
This commit is contained in:
parent
9bb2d32c75
commit
6a3a42717f
3 changed files with 49 additions and 5 deletions
|
@ -1,5 +1,10 @@
|
||||||
#include "rsfilesrc.h"
|
#include "rsfilesrc.h"
|
||||||
|
|
||||||
|
/* Declarations for Rust code */
|
||||||
|
extern void * filesrc_new (void);
|
||||||
|
extern void filesrc_drop (void * filesrc);
|
||||||
|
extern int filesrc_fill (void * filesrc);
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_rsfile_src_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_rsfile_src_debug);
|
||||||
#define GST_CAT_DEFAULT gst_rsfile_src_debug
|
#define GST_CAT_DEFAULT gst_rsfile_src_debug
|
||||||
|
|
||||||
|
@ -74,6 +79,8 @@ static void
|
||||||
gst_rsfile_src_init (GstRsfileSrc * src)
|
gst_rsfile_src_init (GstRsfileSrc * src)
|
||||||
{
|
{
|
||||||
gst_base_src_set_blocksize (GST_BASE_SRC (src), 4096);
|
gst_base_src_set_blocksize (GST_BASE_SRC (src), 4096);
|
||||||
|
|
||||||
|
src->instance = filesrc_new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -81,6 +88,7 @@ gst_rsfile_src_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstRsfileSrc *src = GST_RSFILE_SRC (object);
|
GstRsfileSrc *src = GST_RSFILE_SRC (object);
|
||||||
|
|
||||||
|
filesrc_drop (src->instance);
|
||||||
g_free (src->location);
|
g_free (src->location);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
|
@ -120,15 +128,14 @@ gst_rsfile_src_get_property (GObject * object, guint prop_id, GValue * value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void foo(void);
|
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_rsfile_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
gst_rsfile_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
||||||
GstBuffer * buf)
|
GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstRsfileSrc *src = GST_RSFILE_SRC (basesrc);
|
GstRsfileSrc *src = GST_RSFILE_SRC (basesrc);
|
||||||
|
|
||||||
foo();
|
g_print ("foo %p\n", src->instance);
|
||||||
|
filesrc_fill (src->instance);
|
||||||
|
|
||||||
gst_buffer_memset (buf, 0, 0, gst_buffer_get_size (buf));
|
gst_buffer_memset (buf, 0, 0, gst_buffer_get_size (buf));
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ struct _GstRsfileSrc {
|
||||||
GstBaseSrc element;
|
GstBaseSrc element;
|
||||||
|
|
||||||
gchar *location;
|
gchar *location;
|
||||||
|
gpointer instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstRsfileSrcClass {
|
struct _GstRsfileSrcClass {
|
||||||
|
|
|
@ -1,4 +1,40 @@
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn foo() {
|
pub extern "C" fn filesrc_new() -> *mut FileSrc {
|
||||||
print!("foo\n");
|
let mut instance = Box::new(FileSrc::new());
|
||||||
|
return &mut *instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn filesrc_drop(ptr: *mut FileSrc) {
|
||||||
|
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
|
||||||
|
|
||||||
|
println!("drop");
|
||||||
|
drop(filesrc);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn filesrc_fill(ptr: *mut FileSrc) {
|
||||||
|
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
|
||||||
|
|
||||||
|
println!("fill");
|
||||||
|
filesrc.location = Some(String::from("bla"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FileSrc {
|
||||||
|
location: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileSrc {
|
||||||
|
fn new() -> FileSrc {
|
||||||
|
FileSrc { location: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for FileSrc {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
println!("drop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue