mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-05 14:02:26 +00:00
Move plugin example code to new location, and put it into build system.
Original commit message from CVS: Move plugin example code to new location, and put it into build system. Add work on firstplugin chapter of pwg. Fix typo in quotes. Add @'s before commands in manuals.mak
This commit is contained in:
parent
2a4a536fee
commit
c12e795dec
17 changed files with 744 additions and 22 deletions
|
@ -664,6 +664,7 @@ examples/queue4/Makefile
|
|||
examples/thread/Makefile
|
||||
examples/launch/Makefile
|
||||
examples/xml/Makefile
|
||||
examples/plugins/Makefile
|
||||
editor/Makefile
|
||||
editor/pixmaps/Makefile
|
||||
tools/Makefile
|
||||
|
|
|
@ -4,7 +4,8 @@ htmlname = index.html
|
|||
sgml_files = gst-plugin-writers-guide.sgml \
|
||||
titlepage.sgml \
|
||||
intro.sgml \
|
||||
concepts.sgml
|
||||
concepts.sgml \
|
||||
firstplugin.sgml
|
||||
|
||||
fig_files =
|
||||
eps_files =
|
||||
|
|
128
docs/fwg/firstplugin.sgml
Normal file
128
docs/fwg/firstplugin.sgml
Normal file
|
@ -0,0 +1,128 @@
|
|||
<chapter id="cha-boilerplate">
|
||||
<title>Constructing the boilerplate</title>
|
||||
<para>
|
||||
The first thing to do when making a new element is to specify some basic
|
||||
details about it: what its name is, who wrote it, what version number it
|
||||
is, etc. We also need to define an object to represent the element and to
|
||||
store the data the element needs. I shall refer to these details
|
||||
collectively as the <emphasis>boilerplate</emphasis>.
|
||||
</para>
|
||||
|
||||
<sect1 id="sect-boilerplate-gobject">
|
||||
<title>Doing it the hard way with GstObject</title>
|
||||
<para>
|
||||
The standard way of defining the boilerplate is simply to write some
|
||||
code, and fill in some structures. The easiest way to do this is to
|
||||
copy an example and modify according to your needs.
|
||||
</para>
|
||||
<para>
|
||||
First we will examine the code you would be likely to place in a header
|
||||
file (although since the interface to the code is entirely defined
|
||||
by the pluging system, and doesn't depend on reading a header file,
|
||||
this is not crucial.)
|
||||
|
||||
The code here can be found in
|
||||
<filename>examples/plugins/example.h</filename>
|
||||
</para>
|
||||
|
||||
<programlisting>
|
||||
/* Definition of structure storing data for this element. */
|
||||
typedef struct _GstExample GstExample;
|
||||
struct _GstExample {
|
||||
GstElement element;
|
||||
|
||||
GstPad *sinkpad,*srcpad;
|
||||
|
||||
gint8 active;
|
||||
};
|
||||
|
||||
/* Standard definition defining a class for this element. */
|
||||
typedef struct _GstExampleClass GstExampleClass;
|
||||
struct _GstExampleClass {
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
/* Standard macros for defining types for this element. */
|
||||
#define GST_TYPE_EXAMPLE \
|
||||
(gst_example_get_type())
|
||||
#define GST_EXAMPLE(obj) \
|
||||
(GTK_CHECK_CAST((obj),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_EXAMPLE_CLASS(klass) \
|
||||
(GTK_CHECK_CLASS_CAST((klass),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_IS_EXAMPLE(obj) \
|
||||
(GTK_CHECK_TYPE((obj),GST_TYPE_EXAMPLE))
|
||||
#define GST_IS_EXAMPLE_CLASS(obj) \
|
||||
(GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_EXAMPLE))
|
||||
|
||||
/* Standard function returning type information. */
|
||||
GtkType gst_example_get_type(void);
|
||||
</programlisting>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="sect-boilerplate-filterfactory">
|
||||
<title>Doing it the easy way with FilterFactory</title>
|
||||
<para>
|
||||
A plan for the future is to create a FilterFactory, to make the
|
||||
process of making a new filter a simple process of specifying a few
|
||||
details, and writing a small amount of code to perform the actual
|
||||
data processing.
|
||||
</para>
|
||||
<para>
|
||||
Unfortunately, this hasn't yet been implemented. It is also likely
|
||||
that when it is, it will not be possible to cover all the possibilities
|
||||
available by writing the boilerplate yourself, so some plugins will
|
||||
always need to be manually registered.
|
||||
</para>
|
||||
</sect1>
|
||||
</chapter>
|
||||
|
||||
<chapter id="cha-idfilter">
|
||||
<title>An identity filter</title>
|
||||
<para>
|
||||
</para>
|
||||
|
||||
<sect1 id="sect-idfilter-pads">
|
||||
<title>Building an object with pads</title>
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="sect-idfilter-fns">
|
||||
<title>Attaching functions</title>
|
||||
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="sect-idfilter-fns">
|
||||
<title>The chain function</title>
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
</chapter>
|
||||
|
||||
<chapter id="cha-plugininit">
|
||||
<title>The plugin_init function</title>
|
||||
<para>
|
||||
</para>
|
||||
|
||||
<sect1 id="sect-plugininit-types">
|
||||
<title>Registering the types</title>
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="sect-plugininit-filter">
|
||||
<title>Registering the filter</title>
|
||||
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="sect-plugininit-multiple">
|
||||
<title>Having multiple filters in a single plugin</title>
|
||||
<para>
|
||||
</para>
|
||||
</sect1>
|
||||
</chapter>
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<!ENTITY CONCEPTS SYSTEM "concepts.sgml">
|
||||
|
||||
<!ENTITY FIRSTPLUGIN SYSTEM ".sgml">
|
||||
<!ENTITY FIRSTPLUGIN SYSTEM "firstplugin.sgml">
|
||||
|
||||
<!ENTITY TESTAPP SYSTEM ".sgml">
|
||||
|
||||
|
@ -76,24 +76,18 @@
|
|||
We are now have the neccessary concepts to build our first plugin.
|
||||
We are going to build an element which has a single input pad and
|
||||
a single output pad, and simply passes anything it reads on
|
||||
the input pad through and out on the output pad. In a later
|
||||
section we will convert this plugin into something less useless.
|
||||
the input pad through and out on the output pad. We will also
|
||||
see where we could add code to convert this plugin into something
|
||||
more useful.
|
||||
</para>
|
||||
<para>
|
||||
The example code used in this section can be found in
|
||||
<filename>examples/plugins/</filename>
|
||||
</para>
|
||||
</partintro>
|
||||
|
||||
&FIRSTPLUGIN;
|
||||
|
||||
Constructing the boilerplate
|
||||
Doing it the easy way with FilterFactory
|
||||
(NOTE: FilterFactory doesn't exist yet)
|
||||
Doing it the hard way with G[tk]Object
|
||||
An identity filter
|
||||
Building an object with pads
|
||||
Attaching functions
|
||||
The chain function
|
||||
The plugin_init function
|
||||
Registering the types
|
||||
Registering the filter
|
||||
</part>
|
||||
|
||||
<!-- ############ part ############# -->
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Richard</firstname>
|
||||
<othername>John</othername>
|
||||
<surname>Boulton</surname>
|
||||
<authorblurb>
|
||||
<para>
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
We often hang out on the #gstreamer IRC channel on
|
||||
irc.openprojects.net: the following are a selection of amusing<footnote>
|
||||
<para>No guarantee of sense of humour compatibility is given.</para>
|
||||
</footnote>quotes
|
||||
from our conversations.
|
||||
</footnote> quotes from our conversations.
|
||||
</para>
|
||||
|
||||
<variablelist>
|
||||
|
|
|
@ -19,14 +19,14 @@ endif
|
|||
if HAVE_DB2HTML
|
||||
db2html $(manualname).sgml
|
||||
else
|
||||
echo "Can't build $@: don't have db2html tool"
|
||||
@echo "Can't build $@: don't have db2html tool"
|
||||
endif
|
||||
|
||||
$(manualname).pdf: $(manualname).ps
|
||||
if HAVE_PS2PDF
|
||||
@if [ -r $< ] ; then ps2pdf $< $@ ; fi
|
||||
else
|
||||
echo "Can't build $@: don't have ps2pdf tool"
|
||||
@echo "Can't build $@: don't have ps2pdf tool"
|
||||
endif
|
||||
|
||||
if HAVE_FIG2DEV_EPS
|
||||
|
@ -37,7 +37,7 @@ endif
|
|||
if HAVE_DB2PS
|
||||
@if [ -r $< ] ; then db2ps $(manualname).sgml ; fi
|
||||
else
|
||||
echo "Can't build $@: don't have db2ps tool"
|
||||
@echo "Can't build $@: don't have db2ps tool"
|
||||
endif
|
||||
|
||||
images :
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = autoplug \
|
||||
helloworld helloworld2 \
|
||||
queue queue2 queue3 queue4 \
|
||||
launch thread xml
|
||||
launch thread xml plugins
|
||||
|
|
7
examples/plugins/.gitignore
vendored
Normal file
7
examples/plugins/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
8
examples/plugins/Makefile.am
Normal file
8
examples/plugins/Makefile.am
Normal file
|
@ -0,0 +1,8 @@
|
|||
noinst_LTLIBRARIES = libexample.la
|
||||
|
||||
libexample_la_SOURCES = example.c
|
||||
noinst_HEADERS = example.h
|
||||
|
||||
INCLUDES = $(GLIB_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir)
|
||||
|
||||
libexample_la_LIBADD = $(GLIB_LIBS) $(GTK_LIBS)
|
216
examples/plugins/example.c
Normal file
216
examples/plugins/example.c
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* Gnome-Streamer
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
|
||||
/* elementfactory information */
|
||||
static GstElementDetails example_details = {
|
||||
"An example plugin",
|
||||
"Example",
|
||||
"Shows the basic structure of a plugin",
|
||||
VERSION,
|
||||
"your name <your.name@your.isp>",
|
||||
"(C) 2000",
|
||||
};
|
||||
|
||||
/* Example signals and args */
|
||||
enum {
|
||||
/* FILL ME */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
ARG_0,
|
||||
ARG_ACTIVE
|
||||
};
|
||||
|
||||
static GstPadFactory sink_factory = {
|
||||
"sink", /* the name of the pads */
|
||||
GST_PAD_FACTORY_SINK, /* type of the pad */
|
||||
GST_PAD_FACTORY_ALWAYS, /* ALWAYS/SOMETIMES */
|
||||
GST_PAD_FACTORY_CAPS(
|
||||
"example_sink", /* the name of the caps */
|
||||
"unknown/unknown", /* the mime type of the caps */
|
||||
"something", GST_PROPS_INT (1), /* a property */
|
||||
"foo", GST_PROPS_BOOLEAN (TRUE) /* another property */
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
static GstPadFactory src_factory = {
|
||||
"src",
|
||||
GST_PAD_FACTORY_SRC,
|
||||
GST_PAD_FACTORY_ALWAYS,
|
||||
GST_PAD_FACTORY_CAPS(
|
||||
"example_src",
|
||||
"unknown/unknown"
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static void gst_example_class_init (GstExampleClass *klass);
|
||||
static void gst_example_init (GstExample *example);
|
||||
|
||||
static void gst_example_chain (GstPad *pad, GstBuffer *buf);
|
||||
|
||||
static void gst_example_set_arg (GtkObject *object,GtkArg *arg,guint id);
|
||||
static void gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id);
|
||||
|
||||
GstPadTemplate *src_template, *sink_template;
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
static guint gst_example_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GtkType
|
||||
gst_example_get_type(void)
|
||||
{
|
||||
static GtkType example_type = 0;
|
||||
|
||||
if (!example_type) {
|
||||
static const GtkTypeInfo example_info = {
|
||||
"GstExample",
|
||||
sizeof(GstExample),
|
||||
sizeof(GstExampleClass),
|
||||
(GtkClassInitFunc)gst_example_class_init,
|
||||
(GtkObjectInitFunc)gst_example_init,
|
||||
(GtkArgSetFunc)gst_example_set_arg,
|
||||
(GtkArgGetFunc)gst_example_get_arg,
|
||||
(GtkClassInitFunc)NULL,
|
||||
};
|
||||
example_type = gtk_type_unique(GST_TYPE_ELEMENT,&example_info);
|
||||
}
|
||||
return example_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_class_init (GstExampleClass *klass)
|
||||
{
|
||||
GtkObjectClass *gtkobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gtkobject_class = (GtkObjectClass*)klass;
|
||||
gstelement_class = (GstElementClass*)klass;
|
||||
|
||||
parent_class = gtk_type_class(GST_TYPE_ELEMENT);
|
||||
|
||||
gtk_object_add_arg_type("GstExample::active", GTK_TYPE_INT,
|
||||
GTK_ARG_READWRITE, ARG_ACTIVE);
|
||||
|
||||
gtkobject_class->set_arg = gst_example_set_arg;
|
||||
gtkobject_class->get_arg = gst_example_get_arg;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_init(GstExample *example)
|
||||
{
|
||||
example->sinkpad = gst_pad_new_from_template (sink_template, "sink");
|
||||
gst_element_add_pad(GST_ELEMENT(example),example->sinkpad);
|
||||
gst_pad_set_chain_function(example->sinkpad,gst_example_chain);
|
||||
|
||||
example->srcpad = gst_pad_new_from_template (src_template, "src");
|
||||
gst_element_add_pad(GST_ELEMENT(example),example->srcpad);
|
||||
|
||||
example->active = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_chain (GstPad *pad, GstBuffer *buf)
|
||||
{
|
||||
GstExample *example;
|
||||
guchar *data;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail(pad != NULL);
|
||||
g_return_if_fail(GST_IS_PAD(pad));
|
||||
g_return_if_fail(buf != NULL);
|
||||
//g_return_if_fail(GST_IS_BUFFER(buf));
|
||||
|
||||
example = GST_EXAMPLE(pad->parent);
|
||||
|
||||
g_return_if_fail(example != NULL);
|
||||
g_return_if_fail(GST_IS_EXAMPLE(example));
|
||||
|
||||
if (example->active) {
|
||||
/* DO STUFF */
|
||||
}
|
||||
|
||||
gst_pad_push(example->srcpad,buf);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_set_arg (GtkObject *object,GtkArg *arg,guint id)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail(GST_IS_EXAMPLE(object));
|
||||
example = GST_EXAMPLE(object);
|
||||
|
||||
switch(id) {
|
||||
case ARG_ACTIVE:
|
||||
example->active = GTK_VALUE_INT(*arg);
|
||||
g_print("example: set active to %d\n",example->active);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail(GST_IS_EXAMPLE(object));
|
||||
example = GST_EXAMPLE(object);
|
||||
|
||||
switch (id) {
|
||||
case ARG_ACTIVE:
|
||||
GTK_VALUE_INT(*arg) = example->active;
|
||||
break;
|
||||
default:
|
||||
arg->type = GTK_TYPE_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GstPlugin*
|
||||
plugin_init (GModule *module)
|
||||
{
|
||||
GstPlugin *plugin;
|
||||
GstElementFactory *factory;
|
||||
|
||||
plugin = gst_plugin_new("example");
|
||||
g_return_if_fail(plugin != NULL);
|
||||
|
||||
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details);
|
||||
g_return_if_fail(factory != NULL);
|
||||
|
||||
sink_template = gst_padtemplate_new (&sink_factory);
|
||||
gst_elementfactory_add_padtemplate (factory, sink_template);
|
||||
|
||||
src_template = gst_padtemplate_new (&src_factory);
|
||||
gst_elementfactory_add_padtemplate (factory, src_template);
|
||||
|
||||
gst_plugin_add_factory (plugin, factory);
|
||||
|
||||
return plugin;
|
||||
}
|
68
examples/plugins/example.h
Normal file
68
examples/plugins/example.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* Gnome-Streamer
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_EXAMPLE_H__
|
||||
#define __GST_EXAMPLE_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* Definition of structure storing data for this element. */
|
||||
typedef struct _GstExample GstExample;
|
||||
struct _GstExample {
|
||||
GstElement element;
|
||||
|
||||
GstPad *sinkpad,*srcpad;
|
||||
|
||||
gint8 active;
|
||||
};
|
||||
|
||||
/* Standard definition defining a class for this element. */
|
||||
typedef struct _GstExampleClass GstExampleClass;
|
||||
struct _GstExampleClass {
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
/* Standard macros for defining types for this element. */
|
||||
#define GST_TYPE_EXAMPLE \
|
||||
(gst_example_get_type())
|
||||
#define GST_EXAMPLE(obj) \
|
||||
(GTK_CHECK_CAST((obj),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_EXAMPLE_CLASS(klass) \
|
||||
(GTK_CHECK_CLASS_CAST((klass),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_IS_EXAMPLE(obj) \
|
||||
(GTK_CHECK_TYPE((obj),GST_TYPE_EXAMPLE))
|
||||
#define GST_IS_EXAMPLE_CLASS(obj) \
|
||||
(GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_EXAMPLE))
|
||||
|
||||
/* Standard function returning type information. */
|
||||
GtkType gst_example_get_type(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_EXAMPLE_H__ */
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = autoplug \
|
||||
helloworld helloworld2 \
|
||||
queue queue2 queue3 queue4 \
|
||||
launch thread xml
|
||||
launch thread xml plugins
|
||||
|
|
7
tests/old/examples/plugins/.gitignore
vendored
Normal file
7
tests/old/examples/plugins/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.deps
|
||||
.libs
|
8
tests/old/examples/plugins/Makefile.am
Normal file
8
tests/old/examples/plugins/Makefile.am
Normal file
|
@ -0,0 +1,8 @@
|
|||
noinst_LTLIBRARIES = libexample.la
|
||||
|
||||
libexample_la_SOURCES = example.c
|
||||
noinst_HEADERS = example.h
|
||||
|
||||
INCLUDES = $(GLIB_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir)
|
||||
|
||||
libexample_la_LIBADD = $(GLIB_LIBS) $(GTK_LIBS)
|
216
tests/old/examples/plugins/example.c
Normal file
216
tests/old/examples/plugins/example.c
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* Gnome-Streamer
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "example.h"
|
||||
|
||||
/* elementfactory information */
|
||||
static GstElementDetails example_details = {
|
||||
"An example plugin",
|
||||
"Example",
|
||||
"Shows the basic structure of a plugin",
|
||||
VERSION,
|
||||
"your name <your.name@your.isp>",
|
||||
"(C) 2000",
|
||||
};
|
||||
|
||||
/* Example signals and args */
|
||||
enum {
|
||||
/* FILL ME */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
ARG_0,
|
||||
ARG_ACTIVE
|
||||
};
|
||||
|
||||
static GstPadFactory sink_factory = {
|
||||
"sink", /* the name of the pads */
|
||||
GST_PAD_FACTORY_SINK, /* type of the pad */
|
||||
GST_PAD_FACTORY_ALWAYS, /* ALWAYS/SOMETIMES */
|
||||
GST_PAD_FACTORY_CAPS(
|
||||
"example_sink", /* the name of the caps */
|
||||
"unknown/unknown", /* the mime type of the caps */
|
||||
"something", GST_PROPS_INT (1), /* a property */
|
||||
"foo", GST_PROPS_BOOLEAN (TRUE) /* another property */
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
static GstPadFactory src_factory = {
|
||||
"src",
|
||||
GST_PAD_FACTORY_SRC,
|
||||
GST_PAD_FACTORY_ALWAYS,
|
||||
GST_PAD_FACTORY_CAPS(
|
||||
"example_src",
|
||||
"unknown/unknown"
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static void gst_example_class_init (GstExampleClass *klass);
|
||||
static void gst_example_init (GstExample *example);
|
||||
|
||||
static void gst_example_chain (GstPad *pad, GstBuffer *buf);
|
||||
|
||||
static void gst_example_set_arg (GtkObject *object,GtkArg *arg,guint id);
|
||||
static void gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id);
|
||||
|
||||
GstPadTemplate *src_template, *sink_template;
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
static guint gst_example_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GtkType
|
||||
gst_example_get_type(void)
|
||||
{
|
||||
static GtkType example_type = 0;
|
||||
|
||||
if (!example_type) {
|
||||
static const GtkTypeInfo example_info = {
|
||||
"GstExample",
|
||||
sizeof(GstExample),
|
||||
sizeof(GstExampleClass),
|
||||
(GtkClassInitFunc)gst_example_class_init,
|
||||
(GtkObjectInitFunc)gst_example_init,
|
||||
(GtkArgSetFunc)gst_example_set_arg,
|
||||
(GtkArgGetFunc)gst_example_get_arg,
|
||||
(GtkClassInitFunc)NULL,
|
||||
};
|
||||
example_type = gtk_type_unique(GST_TYPE_ELEMENT,&example_info);
|
||||
}
|
||||
return example_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_class_init (GstExampleClass *klass)
|
||||
{
|
||||
GtkObjectClass *gtkobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gtkobject_class = (GtkObjectClass*)klass;
|
||||
gstelement_class = (GstElementClass*)klass;
|
||||
|
||||
parent_class = gtk_type_class(GST_TYPE_ELEMENT);
|
||||
|
||||
gtk_object_add_arg_type("GstExample::active", GTK_TYPE_INT,
|
||||
GTK_ARG_READWRITE, ARG_ACTIVE);
|
||||
|
||||
gtkobject_class->set_arg = gst_example_set_arg;
|
||||
gtkobject_class->get_arg = gst_example_get_arg;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_init(GstExample *example)
|
||||
{
|
||||
example->sinkpad = gst_pad_new_from_template (sink_template, "sink");
|
||||
gst_element_add_pad(GST_ELEMENT(example),example->sinkpad);
|
||||
gst_pad_set_chain_function(example->sinkpad,gst_example_chain);
|
||||
|
||||
example->srcpad = gst_pad_new_from_template (src_template, "src");
|
||||
gst_element_add_pad(GST_ELEMENT(example),example->srcpad);
|
||||
|
||||
example->active = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_chain (GstPad *pad, GstBuffer *buf)
|
||||
{
|
||||
GstExample *example;
|
||||
guchar *data;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail(pad != NULL);
|
||||
g_return_if_fail(GST_IS_PAD(pad));
|
||||
g_return_if_fail(buf != NULL);
|
||||
//g_return_if_fail(GST_IS_BUFFER(buf));
|
||||
|
||||
example = GST_EXAMPLE(pad->parent);
|
||||
|
||||
g_return_if_fail(example != NULL);
|
||||
g_return_if_fail(GST_IS_EXAMPLE(example));
|
||||
|
||||
if (example->active) {
|
||||
/* DO STUFF */
|
||||
}
|
||||
|
||||
gst_pad_push(example->srcpad,buf);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_set_arg (GtkObject *object,GtkArg *arg,guint id)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail(GST_IS_EXAMPLE(object));
|
||||
example = GST_EXAMPLE(object);
|
||||
|
||||
switch(id) {
|
||||
case ARG_ACTIVE:
|
||||
example->active = GTK_VALUE_INT(*arg);
|
||||
g_print("example: set active to %d\n",example->active);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id)
|
||||
{
|
||||
GstExample *example;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail(GST_IS_EXAMPLE(object));
|
||||
example = GST_EXAMPLE(object);
|
||||
|
||||
switch (id) {
|
||||
case ARG_ACTIVE:
|
||||
GTK_VALUE_INT(*arg) = example->active;
|
||||
break;
|
||||
default:
|
||||
arg->type = GTK_TYPE_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GstPlugin*
|
||||
plugin_init (GModule *module)
|
||||
{
|
||||
GstPlugin *plugin;
|
||||
GstElementFactory *factory;
|
||||
|
||||
plugin = gst_plugin_new("example");
|
||||
g_return_if_fail(plugin != NULL);
|
||||
|
||||
factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details);
|
||||
g_return_if_fail(factory != NULL);
|
||||
|
||||
sink_template = gst_padtemplate_new (&sink_factory);
|
||||
gst_elementfactory_add_padtemplate (factory, sink_template);
|
||||
|
||||
src_template = gst_padtemplate_new (&src_factory);
|
||||
gst_elementfactory_add_padtemplate (factory, src_template);
|
||||
|
||||
gst_plugin_add_factory (plugin, factory);
|
||||
|
||||
return plugin;
|
||||
}
|
68
tests/old/examples/plugins/example.h
Normal file
68
tests/old/examples/plugins/example.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* Gnome-Streamer
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_EXAMPLE_H__
|
||||
#define __GST_EXAMPLE_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* Definition of structure storing data for this element. */
|
||||
typedef struct _GstExample GstExample;
|
||||
struct _GstExample {
|
||||
GstElement element;
|
||||
|
||||
GstPad *sinkpad,*srcpad;
|
||||
|
||||
gint8 active;
|
||||
};
|
||||
|
||||
/* Standard definition defining a class for this element. */
|
||||
typedef struct _GstExampleClass GstExampleClass;
|
||||
struct _GstExampleClass {
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
/* Standard macros for defining types for this element. */
|
||||
#define GST_TYPE_EXAMPLE \
|
||||
(gst_example_get_type())
|
||||
#define GST_EXAMPLE(obj) \
|
||||
(GTK_CHECK_CAST((obj),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_EXAMPLE_CLASS(klass) \
|
||||
(GTK_CHECK_CLASS_CAST((klass),GST_TYPE_EXAMPLE,GstExample))
|
||||
#define GST_IS_EXAMPLE(obj) \
|
||||
(GTK_CHECK_TYPE((obj),GST_TYPE_EXAMPLE))
|
||||
#define GST_IS_EXAMPLE_CLASS(obj) \
|
||||
(GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_EXAMPLE))
|
||||
|
||||
/* Standard function returning type information. */
|
||||
GtkType gst_example_get_type(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_EXAMPLE_H__ */
|
Loading…
Reference in a new issue