From 80ba9a8b8fef8b30378000d85b1ab60821c0ded6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 30 Dec 2016 19:02:31 +0200 Subject: [PATCH] Use caps also for the demuxer sink/src pad templates instead of strings --- gst-plugin-flv/src/lib.rs | 5 +++-- gst-plugin/src/caps.rs | 20 ++++++++++++++++++++ gst-plugin/src/demuxer.c | 30 +++++++++++++----------------- gst-plugin/src/demuxer.rs | 14 ++++++-------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/gst-plugin-flv/src/lib.rs b/gst-plugin-flv/src/lib.rs index f2e85c1e..72cefb9e 100644 --- a/gst-plugin-flv/src/lib.rs +++ b/gst-plugin-flv/src/lib.rs @@ -28,6 +28,7 @@ extern crate flavors; use gst_plugin::plugin::*; use gst_plugin::demuxer::*; +use gst_plugin::caps::*; mod flvdemux; @@ -43,8 +44,8 @@ fn plugin_init(plugin: &Plugin) -> bool { author: "Sebastian Dröge ", rank: 256 + 100, create_instance: FlvDemux::new_boxed, - input_formats: "video/x-flv", - output_formats: "ANY", + input_caps: &Caps::new_simple("video/x-flv", vec![]), + output_caps: &Caps::new_any(), }); true diff --git a/gst-plugin/src/caps.rs b/gst-plugin/src/caps.rs index 75e4715e..10c086f0 100644 --- a/gst-plugin/src/caps.rs +++ b/gst-plugin/src/caps.rs @@ -45,6 +45,26 @@ const TYPE_INT: usize = (6 << 2); const TYPE_STRING: usize = (16 << 2); impl Caps { + pub fn new_empty() -> Self { + extern "C" { + fn gst_caps_new_empty() -> *mut c_void; + } + + let caps = Caps(unsafe { gst_caps_new_empty() }); + + caps + } + + pub fn new_any() -> Self { + extern "C" { + fn gst_caps_new_any() -> *mut c_void; + } + + let caps = Caps(unsafe { gst_caps_new_any() }); + + caps + } + pub fn new_simple(name: &str, values: Vec<(&str, &Value)>) -> Self { extern "C" { fn gst_caps_new_empty() -> *mut c_void; diff --git a/gst-plugin/src/demuxer.c b/gst-plugin/src/demuxer.c index 51aab1d6..2262fbb7 100644 --- a/gst-plugin/src/demuxer.c +++ b/gst-plugin/src/demuxer.c @@ -28,8 +28,8 @@ typedef struct gchar *classification; gchar *author; void *create_instance; - gchar *input_format; - gchar *output_formats; + GstCaps *input_caps; + GstCaps *output_caps; } ElementData; static GHashTable *demuxers; @@ -82,7 +82,6 @@ gst_rs_demuxer_class_init (GstRsDemuxerClass * klass) GstElementClass *gstelement_class; ElementData *data = g_hash_table_lookup (demuxers, GSIZE_TO_POINTER (G_TYPE_FROM_CLASS (klass))); - GstCaps *caps; GstPadTemplate *templ; g_assert (data != NULL); @@ -96,16 +95,14 @@ gst_rs_demuxer_class_init (GstRsDemuxerClass * klass) gst_element_class_set_static_metadata (gstelement_class, data->long_name, data->classification, data->description, data->author); - caps = gst_caps_from_string (data->input_format); - templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps); - gst_caps_unref (caps); - + templ = + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + data->input_caps); gst_element_class_add_pad_template (gstelement_class, templ); - caps = gst_caps_from_string (data->output_formats); - templ = gst_pad_template_new ("src_%u", GST_PAD_SRC, GST_PAD_SOMETIMES, caps); - gst_caps_unref (caps); - + templ = + gst_pad_template_new ("src_%u", GST_PAD_SRC, GST_PAD_SOMETIMES, + data->output_caps); gst_element_class_add_pad_template (gstelement_class, templ); } @@ -523,8 +520,7 @@ gboolean gst_rs_demuxer_register (GstPlugin * plugin, const gchar * name, const gchar * long_name, const gchar * description, const gchar * classification, const gchar * author, GstRank rank, - void *create_instance, const gchar * input_format, - const gchar * output_formats) + void *create_instance, GstCaps * input_caps, GstCaps * output_caps) { GOnce gonce = G_ONCE_INIT; GTypeInfo type_info = { @@ -550,8 +546,8 @@ gst_rs_demuxer_register (GstPlugin * plugin, const gchar * name, GST_DEBUG (" classification: %s", classification); GST_DEBUG (" author: %s", author); GST_DEBUG (" rank: %d", rank); - GST_DEBUG (" input formats: %s", input_format); - GST_DEBUG (" output formats: %s", output_formats); + GST_DEBUG (" input caps: %" GST_PTR_FORMAT, input_caps); + GST_DEBUG (" output caps: %" GST_PTR_FORMAT, output_caps); data = g_new0 (ElementData, 1); data->long_name = g_strdup (long_name); @@ -559,8 +555,8 @@ gst_rs_demuxer_register (GstPlugin * plugin, const gchar * name, data->classification = g_strdup (classification); data->author = g_strdup (author); data->create_instance = create_instance; - data->input_format = g_strdup (input_format); - data->output_formats = g_strdup (output_formats); + data->input_caps = gst_caps_ref (input_caps); + data->output_caps = gst_caps_ref (output_caps); type_name = g_strconcat ("RsDemuxer-", name, NULL); type = g_type_register_static (GST_TYPE_ELEMENT, type_name, &type_info, 0); diff --git a/gst-plugin/src/demuxer.rs b/gst-plugin/src/demuxer.rs index 7c6586bc..5f350a18 100644 --- a/gst-plugin/src/demuxer.rs +++ b/gst-plugin/src/demuxer.rs @@ -496,8 +496,8 @@ pub struct DemuxerInfo<'a> { pub author: &'a str, pub rank: i32, pub create_instance: fn(Element) -> Box, - pub input_formats: &'a str, - pub output_formats: &'a str, + pub input_caps: &'a Caps, + pub output_caps: &'a Caps, } pub fn demuxer_register(plugin: &Plugin, demuxer_info: &DemuxerInfo) { @@ -510,8 +510,8 @@ pub fn demuxer_register(plugin: &Plugin, demuxer_info: &DemuxerInfo) { author: *const c_char, rank: i32, create_instance: *const c_void, - input_format: *const c_char, - output_formats: *const c_char) + input_caps: *const c_void, + output_caps: *const c_void) -> GBoolean; } @@ -520,8 +520,6 @@ pub fn demuxer_register(plugin: &Plugin, demuxer_info: &DemuxerInfo) { let cdescription = CString::new(demuxer_info.description).unwrap(); let cclassification = CString::new(demuxer_info.classification).unwrap(); let cauthor = CString::new(demuxer_info.author).unwrap(); - let cinput_format = CString::new(demuxer_info.input_formats).unwrap(); - let coutput_formats = CString::new(demuxer_info.output_formats).unwrap(); unsafe { gst_rs_demuxer_register(plugin.as_ptr(), @@ -532,7 +530,7 @@ pub fn demuxer_register(plugin: &Plugin, demuxer_info: &DemuxerInfo) { cauthor.as_ptr(), demuxer_info.rank, demuxer_info.create_instance as *const c_void, - cinput_format.as_ptr(), - coutput_formats.as_ptr()); + demuxer_info.input_caps.as_ptr(), + demuxer_info.output_caps.as_ptr()); } }