mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
initial checkin of autoplugcache and a test program to simulate dynamic autoplugging
Original commit message from CVS: initial checkin of autoplugcache and a test program to simulate dynamic autoplugging
This commit is contained in:
parent
12d962e174
commit
4b85dd12e9
3 changed files with 353 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
filterdir = $(libdir)/gst
|
||||
|
||||
filter_LTLIBRARIES = libgststaticautoplug.la libgststaticautoplugrender.la
|
||||
filter_LTLIBRARIES = libgststaticautoplug.la libgststaticautoplugrender.la \
|
||||
libgstautoplugcache.la
|
||||
|
||||
libgststaticautoplug_la_SOURCES = \
|
||||
gststaticautoplug.c
|
||||
|
@ -8,5 +9,14 @@ libgststaticautoplug_la_SOURCES = \
|
|||
libgststaticautoplugrender_la_SOURCES = \
|
||||
gststaticautoplugrender.c
|
||||
|
||||
libgstautoplugcache_la_SOURCES = gstautoplugcache.c
|
||||
|
||||
libgststaticautoplug_la_LDFLAGS = -version-info $(GST_LIBVERSION)
|
||||
libgststaticautoplugrender_la_LDFLAGS = -version-info $(GST_LIBVERSION)
|
||||
libgstautoplugcache_la_LDFLAGS = -version-info $(GST_LIBVERSION)
|
||||
|
||||
noinst_PROGRAMS = autoplugtest
|
||||
|
||||
LIBS += $(GST_LIBS)
|
||||
CFLAGS += $(GST_CFLAGS)
|
||||
|
||||
|
|
55
gst/autoplug/autoplugtest.c
Normal file
55
gst/autoplug/autoplugtest.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
GstElement *pipeline, *src, *autobin, *cache, *typefind, *decoder, *sink;
|
||||
|
||||
void have_type(GstElement *element, GstCaps *caps, GstCaps **private_caps) {
|
||||
fprintf(stderr,"have caps, mime type is %s\n",gst_caps_get_mime(caps));
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
||||
|
||||
gst_element_disconnect(cache,"src",typefind,"sink");
|
||||
// gst_bin_remove(GST_BIN(autobin),typefind);
|
||||
|
||||
/*
|
||||
if (!strstr(gst_caps_get_mime(caps),"mp3")) {
|
||||
decoder = gst_elementfactory_make ("mad","decoder");
|
||||
sink = gst_elementfactory_make ("esdsink","sink");
|
||||
gst_bin_add(GST_BIN(autobin),decoder);
|
||||
gst_bin_add(GST_BIN(autobin),sink);
|
||||
gst_element_connect(decoder,"src",sink,"sink");
|
||||
|
||||
gst_element_connect(cache,"src",decoder,"sink");
|
||||
}
|
||||
*/
|
||||
|
||||
exit(0);
|
||||
fprintf(stderr,"done with have_type signal\n");
|
||||
}
|
||||
|
||||
int main (int argc,char *argv[]) {
|
||||
GstCaps *caps;
|
||||
int i;
|
||||
|
||||
gst_init(&argc,&argv);
|
||||
|
||||
pipeline = gst_pipeline_new("pipeline");
|
||||
src = gst_elementfactory_make ("disksrc","src");
|
||||
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
||||
gst_bin_add (GST_BIN(pipeline),src);
|
||||
|
||||
autobin = gst_bin_new("autobin");
|
||||
cache = gst_elementfactory_make ("autoplugcache","cache");
|
||||
typefind = gst_elementfactory_make ("typefind", "typefind");
|
||||
gtk_signal_connect (GTK_OBJECT(typefind),"have_type",GTK_SIGNAL_FUNC(have_type),&caps);
|
||||
gst_bin_add (GST_BIN(autobin),cache);
|
||||
gst_bin_add (GST_BIN(autobin),typefind);
|
||||
gst_element_connect(cache,"src",typefind,"sink");
|
||||
gst_element_add_ghost_pad(autobin,gst_element_get_pad(cache,"sink"),"sink");
|
||||
|
||||
gst_bin_add (GST_BIN(pipeline), autobin);
|
||||
gst_element_connect (src,"src",autobin,"sink");
|
||||
|
||||
gst_element_set_state(pipeline,GST_STATE_PLAYING);
|
||||
|
||||
gst_bin_iterate(GST_BIN(pipeline));
|
||||
}
|
287
gst/autoplug/gstautoplugcache.c
Normal file
287
gst/autoplug/gstautoplugcache.c
Normal file
|
@ -0,0 +1,287 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2001 RidgeRun, Inc. (www.ridgerun.com)
|
||||
*
|
||||
* gstautoplugcache.c: Data cache for the dynamic autoplugger
|
||||
*
|
||||
* 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 <gst/gst.h>
|
||||
|
||||
GstElementDetails gst_autoplugcache_details = {
|
||||
"AutoplugCache",
|
||||
"Connection",
|
||||
"Data cache for the dynamic autoplugger",
|
||||
VERSION,
|
||||
"Erik Walthinsen <omega@temple-baptist.com>",
|
||||
"(C) 2001 RidgeRun, Inc. (www.ridgerun.com)",
|
||||
};
|
||||
|
||||
#define GST_TYPE_AUTOPLUGCACHE \
|
||||
(gst_autoplugcache_get_type())
|
||||
#define GST_AUTOPLUGCACHE(obj) \
|
||||
(GTK_CHECK_CAST((obj),GST_TYPE_AUTOPLUGCACHE,GstAutoplugCache))
|
||||
#define GST_AUTOPLUGCACHE_CLASS(klass) \
|
||||
(GTK_CHECK_CLASS_CAST((klass),GST_TYPE_AUTOPLUGCACHE,GstAutoplugCacheClass))
|
||||
#define GST_IS_AUTOPLUGCACHE(obj) \
|
||||
(GTK_CHECK_TYPE((obj),GST_TYPE_AUTOPLUGCACHE))
|
||||
#define GST_IS_AUTOPLUGCACHE_CLASS(obj) \
|
||||
(GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_AUTOPLUGCACHE))
|
||||
|
||||
typedef struct _GstAutoplugCache GstAutoplugCache;
|
||||
typedef struct _GstAutoplugCacheClass GstAutoplugCacheClass;
|
||||
|
||||
struct _GstAutoplugCache {
|
||||
GstElement element;
|
||||
|
||||
GstPad *sinkpad, *srcpad;
|
||||
|
||||
GList *cache;
|
||||
GList *cache_start;
|
||||
gint buffer_count;
|
||||
GList *current_playout;
|
||||
};
|
||||
|
||||
struct _GstAutoplugCacheClass {
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
/* Cache signals and args */
|
||||
enum {
|
||||
/* FILL ME */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
ARG_0,
|
||||
ARG_BUFFER_COUNT,
|
||||
ARG_RESET
|
||||
};
|
||||
|
||||
|
||||
static void gst_autoplugcache_class_init (GstAutoplugCacheClass *klass);
|
||||
static void gst_autoplugcache_init (GstAutoplugCache *queue);
|
||||
|
||||
static void gst_autoplugcache_set_arg (GtkObject *object, GtkArg *arg, guint id);
|
||||
static void gst_autoplugcache_get_arg (GtkObject *object, GtkArg *arg, guint id);
|
||||
|
||||
static void gst_autoplugcache_loop (GstElement *element);
|
||||
|
||||
static GstElementStateReturn gst_autoplugcache_change_state (GstElement *element);
|
||||
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
//static guint gst_autoplugcache_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GtkType
|
||||
gst_autoplugcache_get_type(void) {
|
||||
static GtkType autoplugcache_type = 0;
|
||||
|
||||
if (!autoplugcache_type) {
|
||||
static const GtkTypeInfo autoplugcache_info = {
|
||||
"GstAutoplugCache",
|
||||
sizeof(GstAutoplugCache),
|
||||
sizeof(GstAutoplugCacheClass),
|
||||
(GtkClassInitFunc)gst_autoplugcache_class_init,
|
||||
(GtkObjectInitFunc)gst_autoplugcache_init,
|
||||
(GtkArgSetFunc)gst_autoplugcache_set_arg,
|
||||
(GtkArgGetFunc)gst_autoplugcache_get_arg,
|
||||
(GtkClassInitFunc)NULL,
|
||||
};
|
||||
autoplugcache_type = gtk_type_unique (GST_TYPE_ELEMENT, &autoplugcache_info);
|
||||
}
|
||||
return autoplugcache_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_autoplugcache_class_init (GstAutoplugCacheClass *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 ("GstAutoplugCache::buffer_count", GTK_TYPE_INT,
|
||||
GTK_ARG_READABLE, ARG_BUFFER_COUNT);
|
||||
gtk_object_add_arg_type ("GstAutoplugCache::reset", GTK_TYPE_BOOL,
|
||||
GTK_ARG_WRITABLE, ARG_RESET);
|
||||
|
||||
gtkobject_class->set_arg = gst_autoplugcache_set_arg;
|
||||
gtkobject_class->get_arg = gst_autoplugcache_get_arg;
|
||||
|
||||
gstelement_class->change_state = gst_autoplugcache_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_autoplugcache_init (GstAutoplugCache *cache)
|
||||
{
|
||||
gst_element_set_loop_function(GST_ELEMENT(cache), GST_DEBUG_FUNCPTR(gst_autoplugcache_loop));
|
||||
|
||||
cache->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
||||
gst_element_add_pad (GST_ELEMENT(cache), cache->sinkpad);
|
||||
|
||||
cache->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
||||
gst_element_add_pad (GST_ELEMENT(cache), cache->srcpad);
|
||||
|
||||
cache->cache = NULL;
|
||||
cache->buffer_count = 0;
|
||||
cache->current_playout = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_autoplugcache_loop (GstElement *element)
|
||||
{
|
||||
GstAutoplugCache *cache;
|
||||
GstBuffer *buf;
|
||||
|
||||
cache = GST_AUTOPLUGCACHE (element);
|
||||
|
||||
/* Theory:
|
||||
* The cache is a doubly-linked list. The front of the list is the most recent
|
||||
* buffer, the end of the list is the first buffer. The playout pointer always
|
||||
* points to the latest buffer sent out the end. cache points to the front
|
||||
* (most reccent) of the list at all times. cache_start points to the first
|
||||
* buffer, i.e. the end of the list.
|
||||
* If the playout pointer does not have a prev (towards the most recent) buffer
|
||||
* (== NULL), a buffer must be pulled from the sink pad and added to the cache.
|
||||
* When the playout pointer gets reset (as in a set_arg), the cache is walked
|
||||
* without problems, because the playout pointer has a non-NULL next. When
|
||||
* the playout pointer hits the end of cache again it has to start pulling.
|
||||
*/
|
||||
|
||||
do {
|
||||
// the first time through, the current_playout pointer is going to be NULL
|
||||
if (cache->current_playout == NULL) {
|
||||
fprintf(stderr,"current_playout is NULL, first time\n");
|
||||
// get a buffer
|
||||
buf = gst_pad_pull (cache->sinkpad);
|
||||
|
||||
// add it to the cache, though cache == NULL
|
||||
gst_buffer_ref (buf);
|
||||
cache->cache = g_list_prepend (cache->cache, buf);
|
||||
cache->cache_start = cache->cache;
|
||||
cache->buffer_count++;
|
||||
|
||||
// set the current_playout pointer
|
||||
cache->current_playout = cache->cache;
|
||||
|
||||
// send the buffer on its way
|
||||
gst_pad_push (cache->srcpad, buf);
|
||||
}
|
||||
|
||||
// the steady state is where the playout is at the front of the cache
|
||||
else if (g_list_previous(cache->current_playout) == NULL) {
|
||||
fprintf(stderr,"current_playout doesn't have a previous\n");
|
||||
// get a buffer
|
||||
buf = gst_pad_pull (cache->sinkpad);
|
||||
|
||||
// add it to the front of the cache
|
||||
gst_buffer_ref (buf);
|
||||
cache->cache = g_list_prepend (cache->cache, buf);
|
||||
cache->buffer_count++;
|
||||
|
||||
// set the current_playout pointer
|
||||
cache->current_playout = cache->cache;
|
||||
|
||||
// send the buffer on its way
|
||||
gst_pad_push (cache->srcpad, buf);
|
||||
}
|
||||
|
||||
// otherwise we're trundling through existing cached buffers
|
||||
else {
|
||||
fprintf(stderr,"current_playout as a previous\n");
|
||||
// move the current_playout pointer
|
||||
cache->current_playout = g_list_previous (cache->current_playout);
|
||||
|
||||
// push that buffer
|
||||
gst_pad_push (cache->srcpad, GST_BUFFER(cache->current_playout->data));
|
||||
}
|
||||
} while (!GST_FLAG_IS_SET (element, GST_ELEMENT_COTHREAD_STOPPING));
|
||||
}
|
||||
|
||||
static GstElementStateReturn
|
||||
gst_autoplugcache_change_state (GstElement *element)
|
||||
{
|
||||
GstAutoplugCache *cache;
|
||||
|
||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||
|
||||
return GST_STATE_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_autoplugcache_set_arg (GtkObject *object, GtkArg *arg, guint id)
|
||||
{
|
||||
GstAutoplugCache *cache;
|
||||
|
||||
cache = GST_AUTOPLUGCACHE (object);
|
||||
|
||||
switch (id) {
|
||||
case ARG_RESET:
|
||||
// no idea why anyone would set this to FALSE, but just in case ;-)
|
||||
if (GTK_VALUE_BOOL(*arg)) {
|
||||
// reset the playout pointer to the begining again
|
||||
cache->current_playout = cache->cache_start;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_autoplugcache_get_arg (GtkObject *object, GtkArg *arg, guint id)
|
||||
{
|
||||
GstAutoplugCache *cache;
|
||||
|
||||
cache = GST_AUTOPLUGCACHE (object);
|
||||
|
||||
switch (id) {
|
||||
case ARG_BUFFER_COUNT:
|
||||
GTK_VALUE_INT(*arg) = cache->buffer_count;
|
||||
break;
|
||||
default:
|
||||
arg->type = GTK_TYPE_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
plugin_init (GModule *module, GstPlugin *plugin)
|
||||
{
|
||||
GstElementFactory *factory;
|
||||
|
||||
factory = gst_elementfactory_new ("autoplugcache", GST_TYPE_AUTOPLUGCACHE,
|
||||
&gst_autoplugcache_details);
|
||||
g_return_val_if_fail (factory != NULL, FALSE);
|
||||
|
||||
gst_plugin_add_factory (plugin, factory);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GstPluginDesc plugin_desc = {
|
||||
GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"autoplugcache",
|
||||
plugin_init
|
||||
};
|
||||
|
Loading…
Reference in a new issue