Commit 499659f6 authored by Wim Taymans's avatar Wim Taymans

Added typefind helper.

Original commit message from CVS:
Added typefind helper.
Small preroll fix in the base sink.
Disable typefind code in basesrc.
Crude port of typefindelement.
Fakesrc cleanups.
parent 605ceb3e
2005-04-11 set REAL_NAME environment variable <set EMAIL_ADDRESS environment variable>
2005-04-12 Wim Taymans <wim@fluendo.com>
* gst/base/Makefile.am:
* gst/base/gstbasesink.c: (gst_basesink_base_init),
(gst_basesink_pad_getcaps), (gst_basesink_init),
(gst_basesink_event), (gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_get_type),
(gst_basesrc_init), (gst_basesrc_query),
(gst_basesrc_get_event_mask), (gst_basesrc_do_seek),
(gst_basesrc_event_handler), (gst_basesrc_get_range_unlocked),
(gst_basesrc_check_get_range), (gst_basesrc_loop),
(gst_basesrc_unlock), (gst_basesrc_get_size), (gst_basesrc_start),
(gst_basesrc_stop), (gst_basesrc_activate),
(gst_basesrc_change_state):
* gst/base/gsttypefindhelper.c: (helper_find_peek),
(helper_find_suggest), (gst_type_find_helper):
* gst/base/gsttypefindhelper.h:
* gst/elements/Makefile.am:
* gst/elements/gstelements.c:
* gst/elements/gstfakesink.c: (gst_fakesink_class_init),
(gst_fakesink_get_times), (gst_fakesink_event),
(gst_fakesink_preroll), (gst_fakesink_render):
* gst/elements/gstfakesrc.c: (gst_fakesrc_class_init),
(gst_fakesrc_init), (gst_fakesrc_event_handler),
(gst_fakesrc_get_property), (gst_fakesrc_create),
(gst_fakesrc_start), (gst_fakesrc_stop):
* gst/elements/gstfakesrc.h:
* gst/elements/gstfilesrc.c: (gst_filesrc_class_init),
(gst_filesrc_free_parent_mmap), (gst_filesrc_map_region),
(gst_filesrc_map_small_region), (gst_filesrc_create_mmap),
(gst_filesrc_create_read), (gst_filesrc_create),
(gst_filesrc_is_seekable), (gst_filesrc_get_size),
(gst_filesrc_start):
* gst/elements/gsttypefindelement.c:
(gst_type_find_element_have_type), (gst_type_find_element_init),
(start_typefinding), (stop_typefinding), (push_buffer_store),
(gst_type_find_element_handle_event),
(gst_type_find_element_chain),
(gst_type_find_element_checkgetrange),
(gst_type_find_element_getrange), (do_typefind),
(gst_type_find_element_activate),
(gst_type_find_element_change_state):
* gst/elements/gsttypefindelement.h:
* gst/gstpipeline.c: (pipeline_bus_handler):
Added typefind helper.
Small preroll fix in the base sink.
Disable typefind code in basesrc.
Crude port of typefindelement.
Fakesrc cleanups.
2005-04-11 Wim Taymans <wim@fluendo.com>
* check/gst/gstbus.c: (gstbus_suite):
* check/gst/gstdata.c: (thread_ref), (gst_data_suite):
......
......@@ -7,9 +7,10 @@ noinst_DATA = $(as_libtool_noinst_DATA_files)
libgstbase_@GST_MAJORMINOR@_la_DEPENDENCIES = \
../libgstreamer-@GST_MAJORMINOR@.la
libgstbase_@GST_MAJORMINOR@_la_SOURCES = \
gstbasesink.c \
gstbasesrc.c \
gstbasetransform.c
gstbasesink.c \
gstbasesrc.c \
gstbasetransform.c \
gsttypefindhelper.c
libgstbase_@GST_MAJORMINOR@_la_CFLAGS = $(GST_OBJ_CFLAGS)
libgstbase_@GST_MAJORMINOR@_la_LIBADD = $(GST_OBJ_LIBS) \
......@@ -20,9 +21,10 @@ libgstbase_@GST_MAJORMINOR@includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/base
libgstbase_@GST_MAJORMINOR@include_HEADERS = \
gstbasesink.h \
gstbasesrc.h \
gstbasetransform.h
gstbasesink.h \
gstbasesrc.h \
gstbasetransform.h \
gsttypefindhelper.h
install-data-local: as-libtool-install-data-local
......
......@@ -502,9 +502,7 @@ gst_basesink_event (GstPad * pad, GstEvent * event)
GST_STREAM_LOCK (pad);
GST_PREROLL_LOCK (pad);
gst_basesink_preroll_queue_empty (basesink, pad);
GST_PREROLL_UNLOCK (pad);
gst_basesink_finish_preroll (basesink, pad, NULL);
GST_LOCK (basesink);
need_eos = basesink->eos = TRUE;
......@@ -880,6 +878,8 @@ gst_basesink_change_state (GstElement * element)
/* make sure the element is finished processing */
GST_STREAM_LOCK (basesink->sinkpad);
GST_STREAM_UNLOCK (basesink->sinkpad);
/* clear EOS state */
basesink->eos = FALSE;
break;
case GST_STATE_READY_TO_NULL:
break;
......
......@@ -29,6 +29,7 @@
#endif
#include "gstbasesrc.h"
#include "gsttypefindhelper.h"
#include <gst/gstmarshal.h>
#define DEFAULT_BLOCKSIZE 4096
......@@ -103,8 +104,6 @@ static gboolean gst_basesrc_check_get_range (GstPad * pad);
static GstFlowReturn gst_basesrc_get_range (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buf);
static GstCaps *gst_basesrc_type_find (GstBaseSrc * src);
static void
gst_basesrc_base_init (gpointer g_class)
{
......@@ -351,8 +350,14 @@ static gboolean
gst_basesrc_event_handler (GstPad * pad, GstEvent * event)
{
GstBaseSrc *src;
GstBaseSrcClass *bclass;
gboolean result;
src = GST_BASESRC (GST_PAD_PARENT (pad));
bclass = GST_BASESRC_GET_CLASS (src);
if (bclass->event)
result = bclass->event (src, event);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:
......@@ -594,12 +599,14 @@ gst_basesrc_start (GstBaseSrc * basesrc)
basesrc->segment_start = 0;
/* figure out the size */
if (bclass->get_size)
if (bclass->get_size) {
result = bclass->get_size (basesrc, &basesrc->size);
else
} else {
result = FALSE;
basesrc->size = -1;
}
GST_DEBUG ("size %lld", basesrc->size);
GST_DEBUG ("size %d %lld", result, basesrc->size);
/* we always run to the end */
basesrc->segment_end = -1;
......@@ -611,12 +618,15 @@ gst_basesrc_start (GstBaseSrc * basesrc)
basesrc->seekable = FALSE;
/* run typefind */
#if 0
if (basesrc->seekable) {
GstCaps *caps;
caps = gst_basesrc_type_find (basesrc);
caps = gst_type_find_helper (basesrc->srcpad, basesrc->size);
gst_pad_set_caps (basesrc->srcpad, caps);
}
#endif
return TRUE;
/* ERROR */
......@@ -750,100 +760,3 @@ gst_basesrc_change_state (GstElement * element)
return result;
}
/**
* typefind code here
*/
typedef struct
{
GstBaseSrc *src;
guint best_probability;
GstCaps *caps;
GstBuffer *buffer;
}
BaseSrcTypeFind;
static guint8 *
basesrc_find_peek (gpointer data, gint64 offset, guint size)
{
BaseSrcTypeFind *find;
GstBuffer *buffer;
GstBaseSrc *src;
GstFlowReturn ret;
if (size == 0)
return NULL;
find = (BaseSrcTypeFind *) data;
src = find->src;
if (offset < 0) {
offset += src->size;
}
buffer = NULL;
ret = gst_basesrc_get_range_unlocked (src->srcpad, offset, size, &buffer);
if (find->buffer) {
gst_buffer_unref (find->buffer);
find->buffer = NULL;
}
if (ret != GST_FLOW_OK)
goto error;
find->buffer = buffer;
return GST_BUFFER_DATA (buffer);
error:
{
return NULL;
}
}
static void
basesrc_find_suggest (gpointer data, guint probability, const GstCaps * caps)
{
BaseSrcTypeFind *find = (BaseSrcTypeFind *) data;
if (probability > find->best_probability) {
gst_caps_replace (&find->caps, gst_caps_copy (caps));
find->best_probability = probability;
}
}
static GstCaps *
gst_basesrc_type_find (GstBaseSrc * src)
{
GstTypeFind gst_find;
BaseSrcTypeFind find;
GList *walk, *type_list = NULL;
GstCaps *result = NULL;
walk = type_list = gst_type_find_factory_get_list ();
find.src = src;
find.best_probability = 0;
find.caps = NULL;
find.buffer = NULL;
gst_find.data = &find;
gst_find.peek = basesrc_find_peek;
gst_find.suggest = basesrc_find_suggest;
gst_find.get_length = NULL;
while (walk) {
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
gst_type_find_factory_call_function (factory, &gst_find);
if (find.best_probability >= GST_TYPE_FIND_MAXIMUM)
break;
walk = g_list_next (walk);
}
if (find.best_probability > 0)
result = find.caps;
return result;
}
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000,2005 Wim Taymans <wim@fluendo.com>
*
* gsttypefindhelper.c:
*
* 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 <stdlib.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "gsttypefindhelper.h"
/**
* typefind code here
*/
typedef struct
{
GstPad *src;
guint best_probability;
GstCaps *caps;
guint64 size;
GstBuffer *buffer;
}
GstTypeFindHelper;
static guint8 *
helper_find_peek (gpointer data, gint64 offset, guint size)
{
GstTypeFindHelper *find;
GstBuffer *buffer;
GstPad *src;
GstFlowReturn ret;
if (size == 0)
return NULL;
find = (GstTypeFindHelper *) data;
src = find->src;
if (offset < 0) {
if (find->size == -1)
return NULL;
offset += find->size;
}
buffer = NULL;
ret = GST_RPAD_GETRANGEFUNC (src) (src, offset, size, &buffer);
if (find->buffer) {
gst_buffer_unref (find->buffer);
find->buffer = NULL;
}
if (ret != GST_FLOW_OK)
goto error;
find->buffer = buffer;
return GST_BUFFER_DATA (buffer);
error:
{
return NULL;
}
}
static void
helper_find_suggest (gpointer data, guint probability, const GstCaps * caps)
{
GstTypeFindHelper *find = (GstTypeFindHelper *) data;
if (probability > find->best_probability) {
gst_caps_replace (&find->caps, gst_caps_copy (caps));
find->best_probability = probability;
}
}
GstCaps *
gst_type_find_helper (GstPad * src, guint64 size)
{
GstTypeFind gst_find;
GstTypeFindHelper find;
GList *walk, *type_list = NULL;
GstCaps *result = NULL;
walk = type_list = gst_type_find_factory_get_list ();
find.src = src;
find.best_probability = 0;
find.caps = NULL;
find.size = size;
find.buffer = NULL;
gst_find.data = &find;
gst_find.peek = helper_find_peek;
gst_find.suggest = helper_find_suggest;
gst_find.get_length = NULL;
while (walk) {
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
gst_type_find_factory_call_function (factory, &gst_find);
if (find.best_probability >= GST_TYPE_FIND_MAXIMUM)
break;
walk = g_list_next (walk);
}
if (find.best_probability > 0)
result = find.caps;
return result;
}
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000,2005 Wim Taymans <wim@fluendo.com>
*
* gsttypefindhelper.h:
*
* 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_TYPEFINDHELPER_H__
#define __GST_TYPEFINDHELPER_H__
#include <gst/gst.h>
G_BEGIN_DECLS
GstCaps * gst_type_find_helper (GstPad *src, guint64 size);
G_END_DECLS
#endif /* __GST_TYPEFINDHELPER_H__ */
......@@ -24,19 +24,20 @@ endif
libgstelements_la_DEPENDENCIES = ../libgstreamer-@GST_MAJORMINOR@.la
libgstelements_la_SOURCES = \
gstbufferstore.c \
gstfakesrc.c \
gstfakesink.c \
gstfilesrc.c \
gstidentity.c \
gstelements.c \
gsttee.c
gsttee.c \
gsttypefindelement.c
# FIXME 0.9: mentioned by po/POTFILES.in, so we include them here --
# this is a short-term hack, really we should just decide the fate of
# these files above, then this will be unnecessary
EXTRA_DIST += \
gstaggregator.c \
gstbufferstore.c \
gstfilesink.c \
gstfdsink.c \
gstfdsrc.c \
......@@ -44,8 +45,7 @@ EXTRA_DIST += \
gstmultifilesrc.c \
gstpipefilter.c \
gstshaper.c \
gststatistics.c \
gsttypefindelement.c
gststatistics.c
libgstelements_la_CFLAGS = $(GST_OBJ_CFLAGS)
......
......@@ -71,7 +71,7 @@ static struct _elements_entry _elements[] = {
// {"shaper", GST_RANK_NONE, gst_shaper_get_type},
// {"statistics", GST_RANK_NONE, gst_statistics_get_type},
{"tee", GST_RANK_NONE, gst_tee_get_type},
// {"typefind", GST_RANK_NONE, gst_type_find_element_get_type},
{"typefind", GST_RANK_NONE, gst_type_find_element_get_type},
// {NULL, 0},
};
......
......@@ -278,7 +278,7 @@ gst_fakesink_event (GstBaseSink * bsink, GstEvent * event)
g_free (sink->last_message);
sink->last_message =
g_strdup_printf ("chain ******* E (type: %d) %p",
g_strdup_printf ("event ******* E (type: %d) %p",
GST_EVENT_TYPE (event), event);
g_object_notify (G_OBJECT (sink), "last_message");
......
......@@ -31,12 +31,6 @@
#include "gstfakesrc.h"
#include <gst/gstmarshal.h>
#define DEFAULT_SIZEMIN 0
#define DEFAULT_SIZEMAX 4096
#define DEFAULT_PARENTSIZE 4096*10
#define DEFAULT_DATARATE 0
#define DEFAULT_SYNC FALSE
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
......@@ -60,10 +54,25 @@ enum
LAST_SIGNAL
};
#define DEFAULT_OUTPUT FAKESRC_FIRST_LAST_LOOP
#define DEFAULT_DATA FAKESRC_DATA_ALLOCATE
#define DEFAULT_SIZETYPE FAKESRC_SIZETYPE_NULL
#define DEFAULT_SIZEMIN 0
#define DEFAULT_SIZEMAX 4096
#define DEFAULT_FILLTYPE FAKESRC_FILLTYPE_NULL
#define DEFAULT_DATARATE 0
#define DEFAULT_SYNC FALSE
#define DEFAULT_PATTERN NULL
#define DEFAULT_NUM_BUFFERS -1
#define DEFAULT_EOS FALSE
#define DEFAULT_SIGNAL_HANDOFFS FALSE
#define DEFAULT_SILENT FALSE
#define DEFAULT_DUMP FALSE
#define DEFAULT_PARENTSIZE 4096*10
enum
{
ARG_0,
ARG_NUM_SOURCES,
ARG_OUTPUT,
ARG_DATA,
ARG_SIZETYPE,
......@@ -176,7 +185,8 @@ static void gst_fakesrc_set_property (GObject * object, guint prop_id,
static void gst_fakesrc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstElementStateReturn gst_fakesrc_change_state (GstElement * element);
static gboolean gst_fakesrc_start (GstBaseSrc * basesrc);
static gboolean gst_fakesrc_stop (GstBaseSrc * basesrc);
static gboolean gst_fakesrc_event_handler (GstBaseSrc * src, GstEvent * event);
static GstFlowReturn gst_fakesrc_create (GstBaseSrc * src, guint64 offset,
......@@ -209,19 +219,16 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass)
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property);
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SOURCES,
g_param_spec_int ("num-sources", "num-sources", "Number of sources",
1, G_MAXINT, 1, G_PARAM_READABLE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OUTPUT,
g_param_spec_enum ("output", "output", "Output method (currently unused)",
GST_TYPE_FAKESRC_OUTPUT, FAKESRC_FIRST_LAST_LOOP, G_PARAM_READWRITE));
GST_TYPE_FAKESRC_OUTPUT, DEFAULT_OUTPUT, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATA,
g_param_spec_enum ("data", "data", "Data allocation method",
GST_TYPE_FAKESRC_DATA, FAKESRC_DATA_ALLOCATE, G_PARAM_READWRITE));
GST_TYPE_FAKESRC_DATA, DEFAULT_DATA, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZETYPE,
g_param_spec_enum ("sizetype", "sizetype",
"How to determine buffer sizes", GST_TYPE_FAKESRC_SIZETYPE,
FAKESRC_SIZETYPE_NULL, G_PARAM_READWRITE));
DEFAULT_SIZETYPE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMIN,
g_param_spec_int ("sizemin", "sizemin", "Minimum buffer size", 0,
G_MAXINT, DEFAULT_SIZEMIN, G_PARAM_READWRITE));
......@@ -235,7 +242,7 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass)
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILLTYPE,
g_param_spec_enum ("filltype", "filltype",
"How to fill the buffer, if at all", GST_TYPE_FAKESRC_FILLTYPE,
FAKESRC_FILLTYPE_NULL, G_PARAM_READWRITE));
DEFAULT_FILLTYPE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATARATE,
g_param_spec_int ("datarate", "Datarate",
"Timestamps buffers with number of bytes per second (0 = none)", 0,
......@@ -244,27 +251,29 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass)
g_param_spec_boolean ("sync", "Sync", "Sync to the clock to the datarate",
DEFAULT_SYNC, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PATTERN,
g_param_spec_string ("pattern", "pattern", "pattern", NULL,
g_param_spec_string ("pattern", "pattern", "pattern", DEFAULT_PATTERN,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_BUFFERS,
g_param_spec_int ("num-buffers", "num-buffers",
"Number of buffers to output before sending EOS", -1, G_MAXINT, 0,
G_PARAM_READWRITE));
"Number of buffers to output before sending EOS", -1, G_MAXINT,
DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EOS,
g_param_spec_boolean ("eos", "eos", "Send out the EOS event?", TRUE,
G_PARAM_READWRITE));
g_param_spec_boolean ("eos", "eos", "Send out the EOS event?",
DEFAULT_EOS, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
g_param_spec_string ("last-message", "last-message",
"The last status message", NULL, G_PARAM_READABLE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
g_param_spec_boolean ("silent", "Silent",
"Don't produce last_message events", FALSE, G_PARAM_READWRITE));
"Don't produce last_message events", DEFAULT_SILENT,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNAL_HANDOFFS,
g_param_spec_boolean ("signal-handoffs", "Signal handoffs",
"Send a signal before pushing the buffer", FALSE, G_PARAM_READWRITE));
"Send a signal before pushing the buffer", DEFAULT_SIGNAL_HANDOFFS,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
g_param_spec_boolean ("dump", "Dump", "Dump produced bytes to stdout",
FALSE, G_PARAM_READWRITE));
DEFAULT_DUMP, G_PARAM_READWRITE));
gst_fakesrc_signals[SIGNAL_HANDOFF] =
g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
......@@ -272,8 +281,8 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass)
gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 1,
GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesrc_change_state);
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_fakesrc_start);
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_fakesrc_stop);
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_fakesrc_event_handler);
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_fakesrc_create);
}
......@@ -284,14 +293,13 @@ gst_fakesrc_init (GstFakeSrc * fakesrc)
fakesrc->output = FAKESRC_FIRST_LAST_LOOP;
fakesrc->segment_start = -1;
fakesrc->segment_end = -1;
fakesrc->num_buffers = -1;
fakesrc->num_buffers = DEFAULT_NUM_BUFFERS;
fakesrc->rt_num_buffers = -1;