mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-19 00:26:29 +00:00
Pass native GStreamer element pointer to functions
This will later be used to catch panics, convert them to GStreamer errors and invalidate the native instance.
This commit is contained in:
parent
4e053cd6bc
commit
e1d2751fc2
4 changed files with 64 additions and 49 deletions
29
src/rssink.c
29
src/rssink.c
|
@ -37,12 +37,13 @@ static GHashTable *sinks;
|
|||
/* Declarations for Rust code */
|
||||
extern gboolean sinks_register (void *plugin);
|
||||
extern void *sink_new (GstRsSink * sink, void *create_instance);
|
||||
extern GstFlowReturn sink_render (void *filesink, void *data, size_t data_len);
|
||||
extern gboolean sink_set_uri (void *filesink, const char *uri);
|
||||
extern char *sink_get_uri (void *filesink);
|
||||
extern gboolean sink_start (void *filesink);
|
||||
extern gboolean sink_stop (void *filesink);
|
||||
extern void sink_drop (void *filesink);
|
||||
extern GstFlowReturn sink_render (GstRsSink * sink, void *rssink, void *data,
|
||||
size_t data_len);
|
||||
extern gboolean sink_set_uri (GstRsSink * sink, void *rssink, const char *uri);
|
||||
extern char *sink_get_uri (GstRsSink * sink, void *rssink);
|
||||
extern gboolean sink_start (GstRsSink * sink, void *rssink);
|
||||
extern gboolean sink_stop (GstRsSink * sink, void *rssink);
|
||||
extern void sink_drop (GstRsSink * sink, void *rssink);
|
||||
|
||||
extern void cstring_drop (void *str);
|
||||
|
||||
|
@ -127,7 +128,7 @@ gst_rs_sink_finalize (GObject * object)
|
|||
{
|
||||
GstRsSink *sink = GST_RS_SINK (object);
|
||||
|
||||
sink_drop (sink->instance);
|
||||
sink_drop (sink, sink->instance);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ gst_rs_sink_set_property (GObject * object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_URI:
|
||||
sink_set_uri (sink->instance, g_value_get_string (value));
|
||||
sink_set_uri (sink, sink->instance, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
@ -156,7 +157,7 @@ gst_rs_sink_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_URI:{
|
||||
gchar *str = sink_get_uri (sink->instance);
|
||||
gchar *str = sink_get_uri (sink, sink->instance);
|
||||
g_value_set_string (value, str);
|
||||
if (str)
|
||||
cstring_drop (str);
|
||||
|
@ -176,7 +177,7 @@ gst_rs_sink_render (GstBaseSink * basesink, GstBuffer * buffer)
|
|||
GstFlowReturn ret;
|
||||
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||
ret = sink_render (sink->instance, map.data, map.size);
|
||||
ret = sink_render (sink, sink->instance, map.data, map.size);
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
|
||||
return ret;
|
||||
|
@ -188,7 +189,7 @@ gst_rs_sink_start (GstBaseSink * basesink)
|
|||
{
|
||||
GstRsSink *sink = GST_RS_SINK (basesink);
|
||||
|
||||
return sink_start (sink->instance);
|
||||
return sink_start (sink, sink->instance);
|
||||
}
|
||||
|
||||
/* unmap and close the rs */
|
||||
|
@ -197,7 +198,7 @@ gst_rs_sink_stop (GstBaseSink * basesink)
|
|||
{
|
||||
GstRsSink *sink = GST_RS_SINK (basesink);
|
||||
|
||||
return sink_stop (sink->instance);
|
||||
return sink_stop (sink, sink->instance);
|
||||
}
|
||||
|
||||
static GstURIType
|
||||
|
@ -220,7 +221,7 @@ gst_rs_sink_uri_get_uri (GstURIHandler * handler)
|
|||
{
|
||||
GstRsSink *sink = GST_RS_SINK (handler);
|
||||
|
||||
return sink_get_uri (sink->instance);
|
||||
return sink_get_uri (sink, sink->instance);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -229,7 +230,7 @@ gst_rs_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
|||
{
|
||||
GstRsSink *sink = GST_RS_SINK (handler);
|
||||
|
||||
if (!sink_set_uri (sink->instance, uri)) {
|
||||
if (!sink_set_uri (sink, sink->instance, uri)) {
|
||||
g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
|
||||
"Can't handle URI '%s'", uri);
|
||||
return FALSE;
|
||||
|
|
|
@ -58,12 +58,15 @@ pub extern "C" fn sink_new(sink: *mut c_void,
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_drop(ptr: *mut Box<Sink>) {
|
||||
pub extern "C" fn sink_drop(sink: *mut c_void, ptr: *mut Box<Sink>) {
|
||||
unsafe { Box::from_raw(ptr) };
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> GBoolean {
|
||||
pub extern "C" fn sink_set_uri(sink: *mut c_void,
|
||||
ptr: *mut Box<Sink>,
|
||||
uri_ptr: *const c_char)
|
||||
-> GBoolean {
|
||||
let sink: &mut Box<Sink> = unsafe { &mut *ptr };
|
||||
|
||||
if uri_ptr.is_null() {
|
||||
|
@ -82,7 +85,7 @@ pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> G
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_get_uri(ptr: *const Box<Sink>) -> *mut c_char {
|
||||
pub extern "C" fn sink_get_uri(sink: *mut c_void, ptr: *const Box<Sink>) -> *mut c_char {
|
||||
let sink: &Box<Sink> = unsafe { &*ptr };
|
||||
|
||||
match sink.get_uri() {
|
||||
|
@ -92,7 +95,8 @@ pub extern "C" fn sink_get_uri(ptr: *const Box<Sink>) -> *mut c_char {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_render(ptr: *mut Box<Sink>,
|
||||
pub extern "C" fn sink_render(sink: *mut c_void,
|
||||
ptr: *mut Box<Sink>,
|
||||
data_ptr: *const u8,
|
||||
data_len: usize)
|
||||
-> GstFlowReturn {
|
||||
|
@ -103,14 +107,14 @@ pub extern "C" fn sink_render(ptr: *mut Box<Sink>,
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_start(ptr: *mut Box<Sink>) -> GBoolean {
|
||||
pub extern "C" fn sink_start(sink: *mut c_void, ptr: *mut Box<Sink>) -> GBoolean {
|
||||
let sink: &mut Box<Sink> = unsafe { &mut *ptr };
|
||||
|
||||
GBoolean::from_bool(sink.start())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sink_stop(ptr: *mut Box<Sink>) -> GBoolean {
|
||||
pub extern "C" fn sink_stop(sink: *mut c_void, ptr: *mut Box<Sink>) -> GBoolean {
|
||||
let sink: &mut Box<Sink> = unsafe { &mut *ptr };
|
||||
|
||||
GBoolean::from_bool(sink.stop())
|
||||
|
|
|
@ -35,16 +35,18 @@ static GHashTable *sources;
|
|||
/* Declarations for Rust code */
|
||||
extern gboolean sources_register (void *plugin);
|
||||
extern void *source_new (GstRsSrc * source, void *create_instance);
|
||||
extern void source_drop (void *source);
|
||||
extern GstFlowReturn source_fill (void *source, uint64_t offset, void *data,
|
||||
size_t * data_len);
|
||||
extern gboolean source_do_seek (void *source, uint64_t start, uint64_t stop);
|
||||
extern gboolean source_set_uri (void *source, const char *uri);
|
||||
extern char *source_get_uri (void *source);
|
||||
extern uint64_t source_get_size (void *source);
|
||||
extern gboolean source_is_seekable (void *source);
|
||||
extern gboolean source_start (void *source);
|
||||
extern gboolean source_stop (void *source);
|
||||
extern void source_drop (GstRsSrc * source, void *rssource);
|
||||
extern GstFlowReturn source_fill (GstRsSrc * source, void *rssource,
|
||||
uint64_t offset, void *data, size_t * data_len);
|
||||
extern gboolean source_do_seek (GstRsSrc * source, void *rssource,
|
||||
uint64_t start, uint64_t stop);
|
||||
extern gboolean source_set_uri (GstRsSrc * source, void *rssource,
|
||||
const char *uri);
|
||||
extern char *rssource_get_uri (GstRsSrc * source, void *rssource);
|
||||
extern uint64_t source_get_size (GstRsSrc * source, void *rssource);
|
||||
extern gboolean source_is_seekable (GstRsSrc * source, void *rssource);
|
||||
extern gboolean source_start (GstRsSrc * source, void *rssource);
|
||||
extern gboolean source_stop (GstRsSrc * source, void *rssource);
|
||||
|
||||
extern void cstring_drop (void *str);
|
||||
|
||||
|
@ -136,7 +138,7 @@ gst_rs_src_finalize (GObject * object)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (object);
|
||||
|
||||
source_drop (src->instance);
|
||||
source_drop (src, src->instance);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -149,7 +151,7 @@ gst_rs_src_set_property (GObject * object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_URI:
|
||||
source_set_uri (src->instance, g_value_get_string (value));
|
||||
source_set_uri (src, src->instance, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
@ -189,7 +191,7 @@ gst_rs_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|||
gst_buffer_map (buf, &map, GST_MAP_READWRITE);
|
||||
size = length;
|
||||
map_size = map.size;
|
||||
ret = source_fill (src->instance, offset, map.data, &size);
|
||||
ret = source_fill (src, src->instance, offset, map.data, &size);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
if (ret == GST_FLOW_OK && size != map_size)
|
||||
gst_buffer_resize (buf, 0, size);
|
||||
|
@ -202,7 +204,7 @@ gst_rs_src_is_seekable (GstBaseSrc * basesrc)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (basesrc);
|
||||
|
||||
return source_is_seekable (src->instance);
|
||||
return source_is_seekable (src, src->instance);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -210,7 +212,7 @@ gst_rs_src_get_size (GstBaseSrc * basesrc, guint64 * size)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (basesrc);
|
||||
|
||||
*size = source_get_size (src->instance);
|
||||
*size = source_get_size (src, src->instance);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -221,7 +223,7 @@ gst_rs_src_start (GstBaseSrc * basesrc)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (basesrc);
|
||||
|
||||
return source_start (src->instance);
|
||||
return source_start (src, src->instance);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -229,7 +231,7 @@ gst_rs_src_stop (GstBaseSrc * basesrc)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (basesrc);
|
||||
|
||||
return source_stop (src->instance);
|
||||
return source_stop (src, src->instance);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -238,7 +240,7 @@ gst_rs_src_do_seek (GstBaseSrc * basesrc, GstSegment * segment)
|
|||
GstRsSrc *src = GST_RS_SRC (basesrc);
|
||||
gboolean ret;
|
||||
|
||||
ret = source_do_seek (src->instance, segment->start, segment->stop);
|
||||
ret = source_do_seek (src, src->instance, segment->start, segment->stop);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
|
@ -265,7 +267,7 @@ gst_rs_src_uri_get_uri (GstURIHandler * handler)
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (handler);
|
||||
|
||||
return source_get_uri (src->instance);
|
||||
return source_get_uri (src, src->instance);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -274,7 +276,7 @@ gst_rs_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
|||
{
|
||||
GstRsSrc *src = GST_RS_SRC (handler);
|
||||
|
||||
if (!source_set_uri (src->instance, uri)) {
|
||||
if (!source_set_uri (src, src->instance, uri)) {
|
||||
g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
|
||||
"Can't handle URI '%s'", uri);
|
||||
return FALSE;
|
||||
|
|
|
@ -62,12 +62,15 @@ pub extern "C" fn source_new(source: *mut c_void,
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_drop(ptr: *mut Box<Source>) {
|
||||
pub extern "C" fn source_drop(source: *mut c_void, ptr: *mut Box<Source>) {
|
||||
unsafe { Box::from_raw(ptr) };
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_set_uri(ptr: *mut Box<Source>, uri_ptr: *const c_char) -> GBoolean {
|
||||
pub extern "C" fn source_set_uri(source: *mut c_void,
|
||||
ptr: *mut Box<Source>,
|
||||
uri_ptr: *const c_char)
|
||||
-> GBoolean {
|
||||
let source: &mut Box<Source> = unsafe { &mut *ptr };
|
||||
|
||||
if uri_ptr.is_null() {
|
||||
|
@ -86,7 +89,7 @@ pub extern "C" fn source_set_uri(ptr: *mut Box<Source>, uri_ptr: *const c_char)
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_get_uri(ptr: *mut Box<Source>) -> *mut c_char {
|
||||
pub extern "C" fn source_get_uri(source: *mut c_void, ptr: *mut Box<Source>) -> *mut c_char {
|
||||
let source: &mut Box<Source> = unsafe { &mut *ptr };
|
||||
|
||||
match source.get_uri() {
|
||||
|
@ -96,7 +99,8 @@ pub extern "C" fn source_get_uri(ptr: *mut Box<Source>) -> *mut c_char {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_fill(ptr: *mut Box<Source>,
|
||||
pub extern "C" fn source_fill(source: *mut c_void,
|
||||
ptr: *mut Box<Source>,
|
||||
offset: u64,
|
||||
data_ptr: *mut u8,
|
||||
data_len_ptr: *mut usize)
|
||||
|
@ -115,35 +119,39 @@ pub extern "C" fn source_fill(ptr: *mut Box<Source>,
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_get_size(ptr: *const Box<Source>) -> u64 {
|
||||
pub extern "C" fn source_get_size(source: *mut c_void, ptr: *const Box<Source>) -> u64 {
|
||||
let source: &Box<Source> = unsafe { &*ptr };
|
||||
|
||||
return source.get_size();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_start(ptr: *mut Box<Source>) -> GBoolean {
|
||||
pub extern "C" fn source_start(source: *mut c_void, ptr: *mut Box<Source>) -> GBoolean {
|
||||
let source: &mut Box<Source> = unsafe { &mut *ptr };
|
||||
|
||||
GBoolean::from_bool(source.start())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_stop(ptr: *mut Box<Source>) -> GBoolean {
|
||||
pub extern "C" fn source_stop(source: *mut c_void, ptr: *mut Box<Source>) -> GBoolean {
|
||||
let source: &mut Box<Source> = unsafe { &mut *ptr };
|
||||
|
||||
GBoolean::from_bool(source.stop())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_is_seekable(ptr: *const Box<Source>) -> GBoolean {
|
||||
pub extern "C" fn source_is_seekable(source: *mut c_void, ptr: *const Box<Source>) -> GBoolean {
|
||||
let source: &Box<Source> = unsafe { &*ptr };
|
||||
|
||||
GBoolean::from_bool(source.is_seekable())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn source_do_seek(ptr: *mut Box<Source>, start: u64, stop: u64) -> GBoolean {
|
||||
pub extern "C" fn source_do_seek(source: *mut c_void,
|
||||
ptr: *mut Box<Source>,
|
||||
start: u64,
|
||||
stop: u64)
|
||||
-> GBoolean {
|
||||
let source: &mut Box<Source> = unsafe { &mut *ptr };
|
||||
|
||||
GBoolean::from_bool(source.do_seek(start, stop))
|
||||
|
|
Loading…
Reference in a new issue