commit 9bb2d32c75ac9ea82812f8d399027d99fcf65474 Author: Sebastian Dröge Date: Fri May 13 16:35:48 2016 +0300 Initial commit diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..d098434a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rsplugin" +version = "0.1.0" +authors = ["Sebastian Dröge "] +build = "build.rs" + +[dependencies] + +[build-dependencies] +gcc = "0.3" +pkg-config = "0.3" + +[lib] +name = "rsplugin" +crate-type = ["dylib"] +path = "src/lib.rs" diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..244c3d7d --- /dev/null +++ b/build.rs @@ -0,0 +1,23 @@ +extern crate gcc; +extern crate pkg_config; + +fn main() { + let gstreamer = pkg_config::probe_library("gstreamer-1.0").unwrap(); + let gstbase = pkg_config::probe_library("gstreamer-base-1.0").unwrap(); + let includes = [gstreamer.include_paths, gstbase.include_paths]; + + let files = ["src/plugin.c", "src/rsfilesrc.c"]; + + let mut config = gcc::Config::new(); + config.include("src"); + + for f in files.iter() { + config.file(f); + } + + for p in includes.iter().flat_map(|i| i) { + config.include(p); + } + + config.compile("librsplugin-c.a"); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..b9cc4298 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +#![crate_type="dylib"] + +pub mod rsfilesrc; diff --git a/src/plugin.c b/src/plugin.c new file mode 100644 index 00000000..f8d4d978 --- /dev/null +++ b/src/plugin.c @@ -0,0 +1,25 @@ +#include + +#include "rsfilesrc.h" + +static gboolean +plugin_init (GstPlugin * plugin) +{ + if (!gst_element_register (plugin, "rsfilesrc", GST_RANK_NONE, + GST_TYPE_RSFILE_SRC)) { + return FALSE; + } + + return TRUE; +} + +#define VERSION "1.0" +#define PACKAGE "rsplugin" +#define GST_PACKAGE_NAME PACKAGE +#define GST_PACKAGE_ORIGIN "http://www.example.org" + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + rsplugin, + "Rust Plugin", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, + GST_PACKAGE_ORIGIN); diff --git a/src/rsfilesrc.c b/src/rsfilesrc.c new file mode 100644 index 00000000..80164364 --- /dev/null +++ b/src/rsfilesrc.c @@ -0,0 +1,174 @@ +#include "rsfilesrc.h" + +GST_DEBUG_CATEGORY_STATIC (gst_rsfile_src_debug); +#define GST_CAT_DEFAULT gst_rsfile_src_debug + +static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +enum +{ + PROP_0, + PROP_LOCATION +}; + +static void gst_rsfile_src_finalize (GObject * object); + +static void gst_rsfile_src_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_rsfile_src_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_rsfile_src_start (GstBaseSrc * basesrc); +static gboolean gst_rsfile_src_stop (GstBaseSrc * basesrc); + +static gboolean gst_rsfile_src_is_seekable (GstBaseSrc * src); +static gboolean gst_rsfile_src_get_size (GstBaseSrc * src, guint64 * size); +static GstFlowReturn gst_rsfile_src_fill (GstBaseSrc * src, guint64 offset, + guint length, GstBuffer * buf); + +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_rsfile_src_debug, "rsfilesrc", 0, "rsfilesrc element"); +#define gst_rsfile_src_parent_class parent_class +G_DEFINE_TYPE_WITH_CODE (GstRsfileSrc, gst_rsfile_src, GST_TYPE_BASE_SRC, _do_init); + +static void +gst_rsfile_src_class_init (GstRsfileSrcClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseSrcClass *gstbasesrc_class; + + gobject_class = G_OBJECT_CLASS (klass); + gstelement_class = GST_ELEMENT_CLASS (klass); + gstbasesrc_class = GST_BASE_SRC_CLASS (klass); + + gobject_class->set_property = gst_rsfile_src_set_property; + gobject_class->get_property = gst_rsfile_src_get_property; + + g_object_class_install_property (gobject_class, PROP_LOCATION, + g_param_spec_string ("location", "File Location", + "Location of the file to read", NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | + GST_PARAM_MUTABLE_READY)); + + gobject_class->finalize = gst_rsfile_src_finalize; + + gst_element_class_set_static_metadata (gstelement_class, + "File Source", + "Source/Rsfile", + "Read from arbitrary point in a file", + "Sebastian Dröge "); + gst_element_class_add_static_pad_template (gstelement_class, &src_template); + + gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_rsfile_src_start); + gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_rsfile_src_stop); + gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_rsfile_src_is_seekable); + gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_rsfile_src_get_size); + gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_rsfile_src_fill); +} + +static void +gst_rsfile_src_init (GstRsfileSrc * src) +{ + gst_base_src_set_blocksize (GST_BASE_SRC (src), 4096); +} + +static void +gst_rsfile_src_finalize (GObject * object) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (object); + + g_free (src->location); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gst_rsfile_src_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (object); + + switch (prop_id) { + case PROP_LOCATION: + if (src->location) + g_free (src->location); + src->location = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_rsfile_src_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (object); + + switch (prop_id) { + case PROP_LOCATION: + g_value_set_string (value, src->location); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +extern void foo(void); + +static GstFlowReturn +gst_rsfile_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length, + GstBuffer * buf) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (basesrc); + + foo(); + + gst_buffer_memset (buf, 0, 0, gst_buffer_get_size (buf)); + + return GST_FLOW_OK; +} + +static gboolean +gst_rsfile_src_is_seekable (GstBaseSrc * basesrc) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (basesrc); + + return TRUE; +} + +static gboolean +gst_rsfile_src_get_size (GstBaseSrc * basesrc, guint64 * size) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (basesrc); + + *size = -1; + + return TRUE; +} + +/* open the rsfile, necessary to go to READY state */ +static gboolean +gst_rsfile_src_start (GstBaseSrc * basesrc) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (basesrc); + + return TRUE; +} + +/* unmap and close the rsfile */ +static gboolean +gst_rsfile_src_stop (GstBaseSrc * basesrc) +{ + GstRsfileSrc *src = GST_RSFILE_SRC (basesrc); + + return TRUE; +} + + diff --git a/src/rsfilesrc.h b/src/rsfilesrc.h new file mode 100644 index 00000000..06318325 --- /dev/null +++ b/src/rsfilesrc.h @@ -0,0 +1,38 @@ +#ifndef __GST_RSFILE_SRC_H__ +#define __GST_RSFILE_SRC_H__ + +#include +#include + +G_BEGIN_DECLS + +#define GST_TYPE_RSFILE_SRC \ + (gst_rsfile_src_get_type()) +#define GST_RSFILE_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RSFILE_SRC,GstRsfileSrc)) +#define GST_RSFILE_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RSFILE_SRC,GstRsfileSrcClass)) +#define GST_IS_RSFILE_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RSFILE_SRC)) +#define GST_IS_RSFILE_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RSFILE_SRC)) +#define GST_RSFILE_SRC_CAST(obj) ((GstRsfileSrc*) obj) + +typedef struct _GstRsfileSrc GstRsfileSrc; +typedef struct _GstRsfileSrcClass GstRsfileSrcClass; + +struct _GstRsfileSrc { + GstBaseSrc element; + + gchar *location; +}; + +struct _GstRsfileSrcClass { + GstBaseSrcClass parent_class; +}; + +G_GNUC_INTERNAL GType gst_rsfile_src_get_type (void); + +G_END_DECLS + +#endif /* __GST_RSFILE_SRC_H__ */ diff --git a/src/rsfilesrc.rs b/src/rsfilesrc.rs new file mode 100644 index 00000000..46915176 --- /dev/null +++ b/src/rsfilesrc.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern fn foo() { + print!("foo\n"); +}