String parameter in an element
iron_guitarist1987
jtrinidadperez at gmail.com
Sat Apr 14 22:36:51 PDT 2012
Hello,
I am having problems with a simple chain element I have created. I'm trying
to add a new argument to my code. It is a string type. The code compiles and
runs, but I give it a value to the argument, and when I try to use the
value, it appears as blank. Any suggestions? Thanks.
I run it as:
gst-launch -v -m videotestsrc pattern=snow ! template line_color="blue" !
autovideosink
Heres is my header file:
#ifndef __GST_TEMPLATE__
#define __GST_TEMPLATE__
#include "gstreamer-0.10/gst/gst.h"
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */
#define GST_TYPE_TEMPLATE \
(gst_template_get_type())
#define GST_TEMPLATE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TEMPLATE,GstTemplate))
#define GST_TEMPLATE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TEMPLATE,GstTemplateClass))
#define GST_IS_TEMPLATE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEMPLATE))
#define GST_IS_TEMPLATE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEMPLATE))
typedef struct _GstTemplate GstTemplate;
typedef struct _GstTemplateClass GstTemplateClass;
struct _GstTemplate
{
GstElement element;
GstPad *sinkpad, *srcpad;
gboolean silent;
char *line_color;
};
struct _GstTemplateClass
{
GstElementClass parent_class;
};
GType gst_template_get_type (void);
G_END_DECLS
#endif /* __GST_TEMPLATE__ */
------------------------------------Here is my source
file----------------------------------
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gst/gst.h>
#include "gst_template.h"
GST_DEBUG_CATEGORY_STATIC (gst_template_debug);
#define GST_CAT_DEFAULT gst_template_debug
enum
{
PROP_0,
PROP_SILENT,
LINE_COLOR
};
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("ANY")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("ANY")
);
GST_BOILERPLATE (GstTemplate, gst_template, GstElement,
GST_TYPE_ELEMENT);
static void gst_template_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_template_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_template_set_caps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_template_chain (GstPad * pad, GstBuffer * buf);
static GType
gst_tempalte_color_get_type (void)
{
static GType template_color_type = 0;
static const GEnumValue template_color[] = {
{GST_COLOR_RED, "The color red", "red"},
{GST_COLOR_BLUE, "The color blue", "blue"},
{0, NULL, NULL}
};
if (!template_color_type) {
template_color_type =
g_enum_register_static ("Temlate", template_color);
}
return template_color_type;
}
static void
gst_template_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
gst_element_class_set_details_simple(element_class,
"Plugin Template",
"Template",
"Generic Chain Element",
"name email");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
}
static void
gst_template_class_init (GstTemplateClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gobject_class->set_property = gst_template_set_property;
gobject_class->get_property = gst_template_get_property;
g_object_class_install_property (gobject_class, PROP_SILENT,
g_param_spec_boolean ("silent", "Silent", "Produce verbose output
?",FALSE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, LINE_COLOR,
g_param_spec_string ("line_color", "Line_color", "Chenge the color of the
line", "red", G_PARAM_READWRITE));
}
static void
gst_template_init (GstTemplate * filter,
GstTemplateClass * gclass)
{
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory,
"sink");
gst_pad_set_setcaps_function (filter->sinkpad,
GST_DEBUG_FUNCPTR(gst_template_set_caps));
gst_pad_set_getcaps_function (filter->sinkpad,
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
gst_pad_set_chain_function (filter->sinkpad,
GST_DEBUG_FUNCPTR(gst_template_chain));
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
gst_pad_set_getcaps_function (filter->srcpad,
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
filter->silent = FALSE;
}
static void
gst_template_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstTemplate *filter = GST_TEMPLATE (object);
switch (prop_id) {
case PROP_SILENT:
filter->silent = g_value_get_boolean (value);
break;
case LINE_COLOR:
filter->line_color = g_value_get_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_template_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstTemplate *filter = GST_TEMPLATE (object);
switch (prop_id) {
case PROP_SILENT:
g_value_set_boolean (value, filter->silent);
break;
case LINE_COLOR:
g_value_set_string (value, filter->line_color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_template_set_caps (GstPad * pad, GstCaps * caps)
{
GstStructure *structure = gst_caps_get_structure(caps,0);
GstTemplate *filter;
GstPad *otherpad;
filter = GST_TEMPLATE (gst_pad_get_parent (pad));
gst_structure_get_int (structure, "rate", &filter->srcpad);
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
gst_object_unref (filter);
return gst_pad_set_caps (otherpad, caps);
}
static GstBuffer *
gst_template_convert (GstPad * pad, GstBuffer *in)
{
GstBuffer *tempbuf;
char *color;
GstTemplate *filter;
filter = GST_TEMPLATE (GST_OBJECT_PARENT (pad));
color = filter->line_color;
g_print(" \n\nTHE COLOR IS %s\n\n",color);
tempbuf = in;
return tempbuf;
}
static GstFlowReturn
gst_template_chain (GstPad * pad, GstBuffer * buf)
{
GstTemplate *filter;
GstBuffer *outbuf;
filter = GST_TEMPLATE (GST_OBJECT_PARENT (pad));
outbuf = gst_template_convert (pad, buf);
return gst_pad_push (filter->srcpad, outbuf);
}
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_template_debug, "template",
0, "Template plugin");
return gst_element_register (plugin, "template", GST_RANK_NONE,
GST_TYPE_TEMPLATE);
}
#ifndef PACKAGE
#define PACKAGE "plugintemplate"
#endif
/* gstreamer looks for this structure to register plugins
*
* exchange the string 'Template plugin' with your plugin description
*/
GST_PLUGIN_DEFINE (
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"template",
"Template Example",
plugin_init,
"0.10.28",
"GPL",
"GStreamer",
"http://gstreamer.net/"
)
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/String-parameter-in-an-element-tp4558627p4558627.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list