2002-03-20 21:45:09 +00:00
|
|
|
/* GStreamer
|
2001-01-08 23:55:27 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* First, include the header file for the plugin, to bring in the
|
|
|
|
* object definition and other useful things.
|
|
|
|
*/
|
2001-12-13 19:00:58 +00:00
|
|
|
#include <string.h>
|
2001-01-08 23:55:27 +00:00
|
|
|
#include "example.h"
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
/* The ElementDetails structure gives a human-readable description of the
|
|
|
|
* plugin, as well as author and version data. Use the GST_ELEMENT_DETAILS
|
|
|
|
* macro when defining it.
|
2001-02-22 01:34:25 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElementDetails example_details =
|
|
|
|
GST_ELEMENT_DETAILS ("An example plugin",
|
|
|
|
"Example/FirstExample",
|
|
|
|
"Shows the basic structure of a plugin",
|
|
|
|
"your name <your.name@your.isp>");
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* These are the signals that this element can fire. They are zero-
|
|
|
|
* based because the numbers themselves are private to the object.
|
|
|
|
* LAST_SIGNAL is used for initialization of the signal array.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-02-22 01:34:25 +00:00
|
|
|
ASDF,
|
2001-01-08 23:55:27 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Arguments are identified the same way, but cannot be zero, so you
|
|
|
|
* must leave the ARG_0 entry in as a placeholder.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-01-08 23:55:27 +00:00
|
|
|
ARG_0,
|
2004-01-30 20:48:13 +00:00
|
|
|
ARG_ACTIVE
|
2004-03-13 15:27:01 +00:00
|
|
|
/* FILL ME */
|
2001-01-08 23:55:27 +00:00
|
|
|
};
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The PadFactory structures describe what pads the element has or
|
|
|
|
* can have. They can be quite complex, but for this example plugin
|
|
|
|
* they are rather simple.
|
|
|
|
*/
|
2004-03-15 19:27:17 +00:00
|
|
|
GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", /* The name of the pad */
|
|
|
|
GST_PAD_SINK, /* Direction of the pad */
|
|
|
|
GST_PAD_ALWAYS, /* The pad exists for every instance */
|
|
|
|
GST_STATIC_CAPS ("unknown/unknown, " /* The MIME media type */
|
|
|
|
"foo:int=1, " /* an integer property */
|
|
|
|
"bar:boolean=true, " /* a boolean property */
|
|
|
|
"baz:int={ 1, 3 }" /* a list of values */
|
2004-03-13 15:27:01 +00:00
|
|
|
)
|
|
|
|
);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* This factory is much simpler, and defines the source pad. */
|
2004-03-13 15:27:01 +00:00
|
|
|
GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("unknown/unknown")
|
|
|
|
);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
|
|
|
|
2005-05-17 17:22:31 +00:00
|
|
|
/* A number of function prototypes are given so we can refer to them later. */
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_example_class_init (GstExampleClass * klass);
|
|
|
|
static void gst_example_init (GstExample * example);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_example_chain (GstPad * pad, GstData * _data);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_example_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_example_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static GstElementStateReturn gst_example_change_state (GstElement * element);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The parent class pointer needs to be kept around for some object
|
|
|
|
* operations.
|
|
|
|
*/
|
2001-01-08 23:55:27 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* This array holds the ids of the signals registered for this object.
|
|
|
|
* The array indexes are based on the enum up above.
|
|
|
|
*/
|
|
|
|
static guint gst_example_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
/* This function is used to register and subsequently return the type
|
|
|
|
* identifier for this object class. On first invocation, it will
|
|
|
|
* register the type, providing the name of the class, struct sizes,
|
|
|
|
* and pointers to the various functions that define the class.
|
|
|
|
*/
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_get_type (void)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType example_type = 0;
|
2001-01-08 23:55:27 +00:00
|
|
|
|
|
|
|
if (!example_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo example_info = {
|
2004-03-13 15:27:01 +00:00
|
|
|
sizeof (GstExampleClass),
|
2002-05-26 21:21:37 +00:00
|
|
|
NULL,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
2004-03-13 15:27:01 +00:00
|
|
|
(GClassInitFunc) gst_example_class_init,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-13 15:27:01 +00:00
|
|
|
sizeof (GstExample),
|
2001-06-25 01:20:11 +00:00
|
|
|
0,
|
2004-03-13 15:27:01 +00:00
|
|
|
(GInstanceInitFunc) gst_example_init,
|
2001-01-08 23:55:27 +00:00
|
|
|
};
|
2004-03-13 15:27:01 +00:00
|
|
|
example_type =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstExample", &example_info,
|
|
|
|
0);
|
2001-01-08 23:55:27 +00:00
|
|
|
}
|
|
|
|
return example_type;
|
|
|
|
}
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* In order to create an instance of an object, the class must be
|
2001-06-25 01:20:11 +00:00
|
|
|
* initialized by this function. GObject will take care of running
|
2001-02-22 01:34:25 +00:00
|
|
|
* it, based on the pointer to the function provided above.
|
|
|
|
*/
|
2001-01-29 23:50:29 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_class_init (GstExampleClass * klass)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Class pointers are needed to supply pointers to the private
|
|
|
|
* implementations of parent class methods.
|
|
|
|
*/
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-01-08 23:55:27 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Since the example class contains the parent classes, you can simply
|
|
|
|
* cast the pointer to get access to the parent classes.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The parent class is needed for class method overrides. */
|
2004-03-13 15:27:01 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Here we add an argument to the object. This argument is an integer,
|
|
|
|
* and can be both read and written.
|
|
|
|
*/
|
2004-03-15 19:27:17 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ACTIVE, g_param_spec_int ("active", "active", "active", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2005-05-17 17:22:31 +00:00
|
|
|
/* Here we add a signal to the object. This is a very useless signal
|
2001-02-22 23:18:51 +00:00
|
|
|
* called asdf. The signal will also pass a pointer to the listeners
|
|
|
|
* which happens to be the example element itself */
|
|
|
|
gst_example_signals[ASDF] =
|
2004-03-13 15:27:01 +00:00
|
|
|
g_signal_new ("asdf", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstExampleClass, asdf), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, GST_TYPE_EXAMPLE);
|
2001-02-22 23:18:51 +00:00
|
|
|
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The last thing is to provide the functions that implement get and set
|
|
|
|
* of arguments.
|
|
|
|
*/
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class->set_property = gst_example_set_property;
|
|
|
|
gobject_class->get_property = gst_example_get_property;
|
2002-07-25 20:38:04 +00:00
|
|
|
|
|
|
|
/* we also override the default state change handler with our own
|
|
|
|
* implementation */
|
|
|
|
gstelement_class->change_state = gst_example_change_state;
|
2003-10-31 19:32:47 +00:00
|
|
|
/* We can now provide the details for this element, that we defined earlier. */
|
|
|
|
gst_element_class_set_details (gstelement_class, &example_details);
|
|
|
|
/* The pad templates can be easily generated from the factories above,
|
|
|
|
* and then added to the list of padtemplates for the class.
|
|
|
|
*/
|
2003-12-22 01:39:35 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
2001-01-08 23:55:27 +00:00
|
|
|
}
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* This function is responsible for initializing a specific instance of
|
|
|
|
* the plugin.
|
|
|
|
*/
|
2001-01-29 23:50:29 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_init (GstExample * example)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
2001-02-22 01:34:25 +00:00
|
|
|
/* First we create the sink pad, which is the input to the element.
|
2001-08-21 20:16:48 +00:00
|
|
|
* We will use the template constructed by the factory.
|
2001-02-22 01:34:25 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
example->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
|
|
|
"sink");
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Setting the chain function allows us to supply the function that will
|
|
|
|
* actually be performing the work. Without this, the element would do
|
|
|
|
* nothing, with undefined results (assertion failures and such).
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_pad_set_chain_function (example->sinkpad, gst_example_chain);
|
2001-02-22 01:34:25 +00:00
|
|
|
/* We then must add this pad to the element's list of pads. The base
|
|
|
|
* element class manages the list of pads, and provides accessors to it.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (example), example->sinkpad);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The src pad, the output of the element, is created and registered
|
|
|
|
* in the same way, with the exception of the chain function. Source
|
|
|
|
* pads don't have chain functions, because they can't accept buffers,
|
|
|
|
* they only produce them.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
example->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
|
|
|
"src");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (example), example->srcpad);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Initialization of element's private variables. */
|
2001-01-08 23:55:27 +00:00
|
|
|
example->active = FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The chain function is the heart of the element. It's where all the
|
|
|
|
* work is done. It is passed a pointer to the pad in question, as well
|
|
|
|
* as the buffer provided by the peer element.
|
|
|
|
*/
|
2001-01-29 23:50:29 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_chain (GstPad * pad, GstData * _data)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
2003-10-08 16:06:02 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-01-08 23:55:27 +00:00
|
|
|
GstExample *example;
|
2001-02-22 01:34:25 +00:00
|
|
|
GstBuffer *outbuf;
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Some of these checks are of dubious value, since if there were not
|
|
|
|
* already true, the chain function would never be called.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2005-05-17 17:22:31 +00:00
|
|
|
/* We need to get a pointer to the element this pad belongs to. */
|
2004-03-13 15:27:01 +00:00
|
|
|
example = GST_EXAMPLE (gst_pad_get_parent (pad));
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* A few more sanity checks to make sure that the element that owns
|
|
|
|
* this pad is the right kind of element, in case something got confused.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (example != NULL);
|
|
|
|
g_return_if_fail (GST_IS_EXAMPLE (example));
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* If we are supposed to be doing something, here's where it happens. */
|
2001-01-08 23:55:27 +00:00
|
|
|
if (example->active) {
|
2005-05-17 17:22:31 +00:00
|
|
|
/* In this example we're going to copy the buffer to another one,
|
2001-02-22 17:13:30 +00:00
|
|
|
* so we need to allocate a new buffer first. */
|
2004-03-13 15:27:01 +00:00
|
|
|
outbuf = gst_buffer_new ();
|
2001-02-22 01:34:25 +00:00
|
|
|
|
|
|
|
/* We need to copy the size and offset of the buffer at a minimum. */
|
|
|
|
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf);
|
|
|
|
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buf);
|
|
|
|
|
|
|
|
/* Then allocate the memory for the new buffer */
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_BUFFER_DATA (outbuf) = (guchar *) g_malloc (GST_BUFFER_SIZE (outbuf));
|
2001-02-22 01:34:25 +00:00
|
|
|
|
|
|
|
/* Then copy the data in the incoming buffer into the new buffer. */
|
2004-03-13 15:27:01 +00:00
|
|
|
memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (buf),
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf));
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-05-02 23:12:37 +00:00
|
|
|
/* we don't need the incomming buffer anymore so we unref it. When we are
|
|
|
|
* the last plugin with a handle to the buffer, its memory will be freed */
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* When we're done with the buffer, we push it on to the next element
|
|
|
|
* in the pipeline, through the element's source pad, which is stored
|
|
|
|
* in the element's structure.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_pad_push (example->srcpad, GST_DATA (outbuf));
|
2001-02-22 01:34:25 +00:00
|
|
|
|
2001-02-22 23:18:51 +00:00
|
|
|
/* For fun we'll emit our useless signal here */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_signal_emit (G_OBJECT (example), gst_example_signals[ASDF], 0, example);
|
2001-02-22 23:18:51 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
/* If we're not doing something, just send the original incoming buffer. */
|
2001-02-22 01:34:25 +00:00
|
|
|
} else {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_pad_push (example->srcpad, GST_DATA (buf));
|
2001-02-22 01:34:25 +00:00
|
|
|
}
|
2001-01-08 23:55:27 +00:00
|
|
|
}
|
|
|
|
|
2005-05-17 17:22:31 +00:00
|
|
|
/* Properties are part of the GLib+ object system, and these functions
|
|
|
|
* enable the element to respond to various properties.
|
2001-02-22 01:34:25 +00:00
|
|
|
*/
|
2001-01-29 23:50:29 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
|
|
|
GstExample *example;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (GST_IS_EXAMPLE (object));
|
2001-02-22 01:34:25 +00:00
|
|
|
|
|
|
|
/* Get a pointer of the right type. */
|
2004-03-13 15:27:01 +00:00
|
|
|
example = GST_EXAMPLE (object);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Check the argument id to see which argument we're setting. */
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-01-08 23:55:27 +00:00
|
|
|
case ARG_ACTIVE:
|
2001-02-22 01:34:25 +00:00
|
|
|
/* Here we simply copy the value of the argument to our private
|
|
|
|
* storage. More complex operations can be done, but beware that
|
|
|
|
* they may occur at any time, possibly even while your chain function
|
|
|
|
* is running, if you are using threads.
|
|
|
|
*/
|
2001-06-25 01:20:11 +00:00
|
|
|
example->active = g_value_get_int (value);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("example: set active to %d\n", example->active);
|
2001-01-08 23:55:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* The set function is simply the inverse of the get fuction. */
|
2001-01-29 23:50:29 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
|
|
|
GstExample *example;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (GST_IS_EXAMPLE (object));
|
2005-05-17 17:22:31 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
example = GST_EXAMPLE (object);
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-01-08 23:55:27 +00:00
|
|
|
case ARG_ACTIVE:
|
2001-06-25 01:20:11 +00:00
|
|
|
g_value_set_int (value, example->active);
|
2001-01-08 23:55:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-01-08 23:55:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-25 20:38:04 +00:00
|
|
|
/* This is the state change function that will be called when
|
|
|
|
* the element goes through the different state changes.
|
|
|
|
* The plugin can prepare itself and its internal data structures
|
|
|
|
* in the various state transitions.
|
|
|
|
*/
|
|
|
|
static GstElementStateReturn
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_example_change_state (GstElement * element)
|
2002-07-25 20:38:04 +00:00
|
|
|
{
|
|
|
|
GstExample *example;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-07-25 20:38:04 +00:00
|
|
|
/* cast to our plugin */
|
2004-03-13 15:27:01 +00:00
|
|
|
example = GST_EXAMPLE (element);
|
|
|
|
|
2002-07-25 20:38:04 +00:00
|
|
|
/* we perform our actions based on the state transition
|
|
|
|
* of the element */
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2004-03-13 15:27:01 +00:00
|
|
|
/* The NULL to READY transition is used to
|
2005-05-17 17:22:31 +00:00
|
|
|
* create threads (if any), and/or open devices */
|
2002-07-25 20:38:04 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
break;
|
2004-03-13 15:27:01 +00:00
|
|
|
/* In the PAUSED to PLAYING state, the element should
|
|
|
|
* prepare itself for operation or continue after a PAUSE */
|
2002-07-25 20:38:04 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
2004-03-13 15:27:01 +00:00
|
|
|
/* In the PLAYING to PAUSED state, the element should
|
|
|
|
* PAUSE itself and make sure it can resume operation */
|
2002-07-25 20:38:04 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
2004-03-13 15:27:01 +00:00
|
|
|
/* In the PAUSED to READY state, the element should reset
|
|
|
|
* its internal state and close any devices. */
|
2002-07-25 20:38:04 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
break;
|
2004-03-13 15:27:01 +00:00
|
|
|
/* The element should free all resources, terminate threads
|
|
|
|
* and put itself into its initial state again */
|
2002-07-25 20:38:04 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then we call the parent state change handler */
|
|
|
|
return parent_class->change_state (element);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-22 01:34:25 +00:00
|
|
|
/* This is the entry into the plugin itself. When the plugin loads,
|
|
|
|
* this function is called to register everything that the plugin provides.
|
|
|
|
*/
|
2001-04-22 12:30:14 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-01-08 23:55:27 +00:00
|
|
|
{
|
2005-05-17 17:22:31 +00:00
|
|
|
/* We need to register each element we provide with the plugin. This consists
|
|
|
|
* of the name of the element, a rank that gives the importance of the element
|
2003-10-31 19:32:47 +00:00
|
|
|
* when compared to similar plugins and the GType identifier.
|
2001-02-22 01:34:25 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!gst_element_register (plugin, "example", GST_RANK_MARGINAL,
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_TYPE_EXAMPLE))
|
2003-10-31 19:32:47 +00:00
|
|
|
return FALSE;
|
2001-01-08 23:55:27 +00:00
|
|
|
|
2001-04-22 12:30:14 +00:00
|
|
|
/* Now we can return successfully. */
|
|
|
|
return TRUE;
|
2001-02-22 01:34:25 +00:00
|
|
|
|
|
|
|
/* At this point, the GStreamer core registers the plugin, its
|
2003-10-31 19:32:47 +00:00
|
|
|
* elementfactories, padtemplates, etc., for use in your application.
|
2001-02-22 01:34:25 +00:00
|
|
|
*/
|
2001-01-08 23:55:27 +00:00
|
|
|
}
|
2001-04-22 12:30:14 +00:00
|
|
|
|
|
|
|
/* This structure describes the plugin to the system for dynamically loading
|
|
|
|
* plugins, so that the version number and name can be checked in a uniform
|
|
|
|
* way.
|
|
|
|
*
|
|
|
|
* The symbol pointing to this structure is the only symbol looked up when
|
|
|
|
* loading the plugin.
|
|
|
|
*/
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, /* The major version of the core that this was built with */
|
|
|
|
GST_VERSION_MINOR, /* The minor version of the core that this was built with */
|
|
|
|
"example", /* The name of the plugin. This must be unique: plugins with
|
|
|
|
* the same name will be assumed to be identical, and only
|
|
|
|
* one will be loaded. */
|
|
|
|
"an example plugin", /* a short description of the plugin in English */
|
|
|
|
plugin_init, /* Pointer to the initialisation function for the plugin. */
|
|
|
|
"0.1", /* The version number of the plugin */
|
2005-05-17 17:22:31 +00:00
|
|
|
"LGPL", /* effective license the plugin can be shipped with. Must be
|
2004-03-15 19:27:17 +00:00
|
|
|
* valid for all libraries it links to, too. */
|
2004-03-13 15:27:01 +00:00
|
|
|
"my nifty plugin package",
|
|
|
|
/* package this plugin belongs to. */
|
|
|
|
"http://www.mydomain.com"
|
|
|
|
/* originating URL for this plugin. This is the place to look
|
|
|
|
* for updates, information and so on. */
|
|
|
|
);
|