mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-05-20 09:18:15 +00:00
Add new controller objects to Source/Sink
These store a pointer to the native GstElement and will allow calling back into it later.
This commit is contained in:
parent
8b313a752a
commit
4e053cd6bc
10
src/lib.rs
10
src/lib.rs
|
@ -31,10 +31,10 @@ pub mod rshttpsrc;
|
||||||
pub mod rsfilesink;
|
pub mod rsfilesink;
|
||||||
|
|
||||||
use utils::*;
|
use utils::*;
|
||||||
use rssource::Source;
|
use rssource::{Source, SourceController};
|
||||||
use rsfilesrc::FileSrc;
|
use rsfilesrc::FileSrc;
|
||||||
use rshttpsrc::HttpSrc;
|
use rshttpsrc::HttpSrc;
|
||||||
use rssink::Sink;
|
use rssink::{Sink, SinkController};
|
||||||
use rsfilesink::FileSink;
|
use rsfilesink::FileSink;
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
|
@ -49,7 +49,8 @@ extern "C" {
|
||||||
classification: *const c_char,
|
classification: *const c_char,
|
||||||
author: *const c_char,
|
author: *const c_char,
|
||||||
rank: i32,
|
rank: i32,
|
||||||
create_instance: extern "C" fn() -> *mut Box<Source>,
|
create_instance: extern "C" fn(controller: SourceController)
|
||||||
|
-> *mut Box<Source>,
|
||||||
protocols: *const c_char,
|
protocols: *const c_char,
|
||||||
push_only: GBoolean)
|
push_only: GBoolean)
|
||||||
-> GBoolean;
|
-> GBoolean;
|
||||||
|
@ -63,7 +64,8 @@ extern "C" {
|
||||||
classification: *const c_char,
|
classification: *const c_char,
|
||||||
author: *const c_char,
|
author: *const c_char,
|
||||||
rank: i32,
|
rank: i32,
|
||||||
create_instance: extern "C" fn() -> *mut Box<Sink>,
|
create_instance: extern "C" fn(controller: SinkController)
|
||||||
|
-> *mut Box<Sink>,
|
||||||
protocols: *const c_char)
|
protocols: *const c_char)
|
||||||
-> GBoolean;
|
-> GBoolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ use rssink::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FileSink {
|
pub struct FileSink {
|
||||||
|
controller: SinkController,
|
||||||
location: Mutex<Option<PathBuf>>,
|
location: Mutex<Option<PathBuf>>,
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
position: u64,
|
position: u64,
|
||||||
|
@ -37,19 +38,17 @@ unsafe impl Sync for FileSink {}
|
||||||
unsafe impl Send for FileSink {}
|
unsafe impl Send for FileSink {}
|
||||||
|
|
||||||
impl FileSink {
|
impl FileSink {
|
||||||
fn new() -> FileSink {
|
fn new(controller: SinkController) -> FileSink {
|
||||||
FileSink {
|
FileSink {
|
||||||
|
controller: controller,
|
||||||
location: Mutex::new(None),
|
location: Mutex::new(None),
|
||||||
file: None,
|
file: None,
|
||||||
position: 0,
|
position: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_source() -> Box<Sink> {
|
pub extern "C" fn new_ptr(controller: SinkController) -> *mut Box<Sink> {
|
||||||
Box::new(FileSink::new())
|
let instance: Box<Box<Sink>> = Box::new(Box::new(FileSink::new(controller)));
|
||||||
}
|
|
||||||
pub extern "C" fn new_ptr() -> *mut Box<Sink> {
|
|
||||||
let instance = Box::new(FileSink::new_source());
|
|
||||||
return Box::into_raw(instance);
|
return Box::into_raw(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ use rssource::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FileSrc {
|
pub struct FileSrc {
|
||||||
|
controller: SourceController,
|
||||||
location: Mutex<Option<PathBuf>>,
|
location: Mutex<Option<PathBuf>>,
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
position: u64,
|
position: u64,
|
||||||
|
@ -38,19 +39,17 @@ unsafe impl Sync for FileSrc {}
|
||||||
unsafe impl Send for FileSrc {}
|
unsafe impl Send for FileSrc {}
|
||||||
|
|
||||||
impl FileSrc {
|
impl FileSrc {
|
||||||
fn new() -> FileSrc {
|
fn new(controller: SourceController) -> FileSrc {
|
||||||
FileSrc {
|
FileSrc {
|
||||||
|
controller: controller,
|
||||||
location: Mutex::new(None),
|
location: Mutex::new(None),
|
||||||
file: None,
|
file: None,
|
||||||
position: 0,
|
position: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_source() -> Box<Source> {
|
pub extern "C" fn new_ptr(controller: SourceController) -> *mut Box<Source> {
|
||||||
Box::new(FileSrc::new())
|
let instance: Box<Box<Source>> = Box::new(Box::new(FileSrc::new(controller)));
|
||||||
}
|
|
||||||
pub extern "C" fn new_ptr() -> *mut Box<Source> {
|
|
||||||
let instance = Box::new(FileSrc::new_source());
|
|
||||||
return Box::into_raw(instance);
|
return Box::into_raw(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ use rssource::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HttpSrc {
|
pub struct HttpSrc {
|
||||||
|
controller: SourceController,
|
||||||
url: Mutex<Option<Url>>,
|
url: Mutex<Option<Url>>,
|
||||||
client: Client,
|
client: Client,
|
||||||
response: Option<Response>,
|
response: Option<Response>,
|
||||||
|
@ -46,8 +47,9 @@ unsafe impl Sync for HttpSrc {}
|
||||||
unsafe impl Send for HttpSrc {}
|
unsafe impl Send for HttpSrc {}
|
||||||
|
|
||||||
impl HttpSrc {
|
impl HttpSrc {
|
||||||
fn new() -> HttpSrc {
|
fn new(controller: SourceController) -> HttpSrc {
|
||||||
HttpSrc {
|
HttpSrc {
|
||||||
|
controller: controller,
|
||||||
url: Mutex::new(None),
|
url: Mutex::new(None),
|
||||||
client: Client::new(),
|
client: Client::new(),
|
||||||
response: None,
|
response: None,
|
||||||
|
@ -59,11 +61,8 @@ impl HttpSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_source() -> Box<Source> {
|
pub extern "C" fn new_ptr(controller: SourceController) -> *mut Box<Source> {
|
||||||
Box::new(HttpSrc::new())
|
let instance: Box<Box<Source>> = Box::new(Box::new(HttpSrc::new(controller)));
|
||||||
}
|
|
||||||
pub extern "C" fn new_ptr() -> *mut Box<Source> {
|
|
||||||
let instance = Box::new(HttpSrc::new_source());
|
|
||||||
return Box::into_raw(instance);
|
return Box::into_raw(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,14 @@ typedef struct
|
||||||
gchar *description;
|
gchar *description;
|
||||||
gchar *classification;
|
gchar *classification;
|
||||||
gchar *author;
|
gchar *author;
|
||||||
void *(*create_instance) (void);
|
void *create_instance;
|
||||||
gchar **protocols;
|
gchar **protocols;
|
||||||
} ElementData;
|
} ElementData;
|
||||||
static GHashTable *sinks;
|
static GHashTable *sinks;
|
||||||
|
|
||||||
/* Declarations for Rust code */
|
/* Declarations for Rust code */
|
||||||
extern gboolean sinks_register (void *plugin);
|
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 GstFlowReturn sink_render (void *filesink, void *data, size_t data_len);
|
||||||
extern gboolean sink_set_uri (void *filesink, const char *uri);
|
extern gboolean sink_set_uri (void *filesink, const char *uri);
|
||||||
extern char *sink_get_uri (void *filesink);
|
extern char *sink_get_uri (void *filesink);
|
||||||
|
@ -118,7 +119,7 @@ gst_rs_sink_init (GstRsSink * sink, GstRsSinkClass * klass)
|
||||||
|
|
||||||
gst_base_sink_set_sync (GST_BASE_SINK (sink), FALSE);
|
gst_base_sink_set_sync (GST_BASE_SINK (sink), FALSE);
|
||||||
|
|
||||||
sink->instance = data->create_instance ();
|
sink->instance = sink_new (sink, data->create_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -263,7 +264,7 @@ gboolean
|
||||||
gst_rs_sink_register (GstPlugin * plugin, const gchar * name,
|
gst_rs_sink_register (GstPlugin * plugin, const gchar * name,
|
||||||
const gchar * long_name, const gchar * description,
|
const gchar * long_name, const gchar * description,
|
||||||
const gchar * classification, const gchar * author, GstRank rank,
|
const gchar * classification, const gchar * author, GstRank rank,
|
||||||
void *(*create_instance) (void), const gchar * protocols)
|
void *create_instance, const gchar * protocols)
|
||||||
{
|
{
|
||||||
GTypeInfo type_info = {
|
GTypeInfo type_info = {
|
||||||
sizeof (GstRsSinkClass),
|
sizeof (GstRsSinkClass),
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Boston, MA 02110-1301, USA.
|
// Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
|
use std::os::raw::c_void;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -26,6 +27,17 @@ use url::Url;
|
||||||
|
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SinkController {
|
||||||
|
sink: *mut c_void,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SinkController {
|
||||||
|
fn new(sink: *mut c_void) -> SinkController {
|
||||||
|
SinkController { sink: sink }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Sink: Sync + Send {
|
pub trait Sink: Sync + Send {
|
||||||
// Called from any thread at any time
|
// Called from any thread at any time
|
||||||
fn set_uri(&mut self, uri: Option<Url>) -> bool;
|
fn set_uri(&mut self, uri: Option<Url>) -> bool;
|
||||||
|
@ -37,6 +49,14 @@ pub trait Sink: Sync + Send {
|
||||||
fn render(&mut self, data: &[u8]) -> GstFlowReturn;
|
fn render(&mut self, data: &[u8]) -> GstFlowReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn sink_new(sink: *mut c_void,
|
||||||
|
create_instance: extern "C" fn(controller: SinkController)
|
||||||
|
-> *mut Box<Sink>)
|
||||||
|
-> *mut Box<Sink> {
|
||||||
|
create_instance(SinkController::new(sink))
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn sink_drop(ptr: *mut Box<Sink>) {
|
pub extern "C" fn sink_drop(ptr: *mut Box<Sink>) {
|
||||||
unsafe { Box::from_raw(ptr) };
|
unsafe { Box::from_raw(ptr) };
|
||||||
|
|
|
@ -27,13 +27,14 @@ typedef struct
|
||||||
gchar *description;
|
gchar *description;
|
||||||
gchar *classification;
|
gchar *classification;
|
||||||
gchar *author;
|
gchar *author;
|
||||||
void *(*create_instance) (void);
|
void *create_instance;
|
||||||
gchar **protocols;
|
gchar **protocols;
|
||||||
} ElementData;
|
} ElementData;
|
||||||
static GHashTable *sources;
|
static GHashTable *sources;
|
||||||
|
|
||||||
/* Declarations for Rust code */
|
/* Declarations for Rust code */
|
||||||
extern gboolean sources_register (void *plugin);
|
extern gboolean sources_register (void *plugin);
|
||||||
|
extern void *source_new (GstRsSrc * source, void *create_instance);
|
||||||
extern void source_drop (void *source);
|
extern void source_drop (void *source);
|
||||||
extern GstFlowReturn source_fill (void *source, uint64_t offset, void *data,
|
extern GstFlowReturn source_fill (void *source, uint64_t offset, void *data,
|
||||||
size_t * data_len);
|
size_t * data_len);
|
||||||
|
@ -127,7 +128,7 @@ gst_rs_src_init (GstRsSrc * src, GstRsSrcClass * klass)
|
||||||
|
|
||||||
gst_base_src_set_blocksize (GST_BASE_SRC (src), 4096);
|
gst_base_src_set_blocksize (GST_BASE_SRC (src), 4096);
|
||||||
|
|
||||||
src->instance = data->create_instance ();
|
src->instance = source_new (src, data->create_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -308,8 +309,7 @@ gboolean
|
||||||
gst_rs_source_register (GstPlugin * plugin, const gchar * name,
|
gst_rs_source_register (GstPlugin * plugin, const gchar * name,
|
||||||
const gchar * long_name, const gchar * description,
|
const gchar * long_name, const gchar * description,
|
||||||
const gchar * classification, const gchar * author, GstRank rank,
|
const gchar * classification, const gchar * author, GstRank rank,
|
||||||
void *(*create_instance) (void), const gchar * protocols,
|
void *create_instance, const gchar * protocols, gboolean push_only)
|
||||||
gboolean push_only)
|
|
||||||
{
|
{
|
||||||
GTypeInfo type_info = {
|
GTypeInfo type_info = {
|
||||||
sizeof (GstRsSrcClass),
|
sizeof (GstRsSrcClass),
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
// Boston, MA 02110-1301, USA.
|
// Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
|
use std::os::raw::c_void;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -25,6 +26,17 @@ use url::Url;
|
||||||
|
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SourceController {
|
||||||
|
source: *mut c_void,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SourceController {
|
||||||
|
fn new(source: *mut c_void) -> SourceController {
|
||||||
|
SourceController { source: source }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Source: Sync + Send {
|
pub trait Source: Sync + Send {
|
||||||
// Called from any thread at any time
|
// Called from any thread at any time
|
||||||
fn set_uri(&mut self, uri: Option<Url>) -> bool;
|
fn set_uri(&mut self, uri: Option<Url>) -> bool;
|
||||||
|
@ -41,6 +53,14 @@ pub trait Source: Sync + Send {
|
||||||
fn get_size(&self) -> u64;
|
fn get_size(&self) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn source_new(source: *mut c_void,
|
||||||
|
create_instance: extern "C" fn(controller: SourceController)
|
||||||
|
-> *mut Box<Source>)
|
||||||
|
-> *mut Box<Source> {
|
||||||
|
create_instance(SourceController::new(source))
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn source_drop(ptr: *mut Box<Source>) {
|
pub extern "C" fn source_drop(ptr: *mut Box<Source>) {
|
||||||
unsafe { Box::from_raw(ptr) };
|
unsafe { Box::from_raw(ptr) };
|
||||||
|
|
Loading…
Reference in a new issue