mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
- Error after configurable number of buffers
Original commit message from CVS: - Error after configurable number of buffers
This commit is contained in:
parent
acf7e665f3
commit
8e19b6a4d4
2 changed files with 76 additions and 23 deletions
|
@ -22,13 +22,11 @@
|
||||||
|
|
||||||
|
|
||||||
#include "gst_private.h"
|
#include "gst_private.h"
|
||||||
|
|
||||||
#include "gsttype.h"
|
#include "gsttype.h"
|
||||||
|
|
||||||
#include "gstlog.h"
|
#include "gstlog.h"
|
||||||
#include "gsttypefind.h"
|
#include "gsttypefind.h"
|
||||||
|
|
||||||
/* #define GST_DEBUG_ENABLED */
|
#define DEFAULT_MAX_BUFFERS 1
|
||||||
|
|
||||||
GstElementDetails gst_type_find_details = {
|
GstElementDetails gst_type_find_details = {
|
||||||
"TypeFind",
|
"TypeFind",
|
||||||
|
@ -51,6 +49,7 @@ enum {
|
||||||
enum {
|
enum {
|
||||||
ARG_0,
|
ARG_0,
|
||||||
ARG_CAPS,
|
ARG_CAPS,
|
||||||
|
ARG_MAX_BUFFERS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +64,8 @@ static void gst_type_find_get_property (GObject *object, guint prop_id,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
|
|
||||||
static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
|
static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
|
||||||
|
static GstElementStateReturn
|
||||||
|
gst_type_find_change_state (GstElement *element);
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class = NULL;
|
||||||
static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
|
static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
@ -96,22 +97,31 @@ static void
|
||||||
gst_type_find_class_init (GstTypeFindClass *klass)
|
gst_type_find_class_init (GstTypeFindClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
|
GstElementClass *gstelement_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass*)klass;
|
gobject_class = (GObjectClass*)klass;
|
||||||
|
gstelement_class = (GstElementClass*)klass;
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CAPS,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CAPS,
|
||||||
g_param_spec_pointer("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
|
g_param_spec_pointer ("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
|
||||||
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_BUFFERS,
|
||||||
|
g_param_spec_int ("max_buffers",
|
||||||
|
"Max Buffers",
|
||||||
|
"Maximal amount of buffers before giving en error (0 == unlimited)",
|
||||||
|
0, G_MAXINT, DEFAULT_MAX_BUFFERS, G_PARAM_READWRITE));
|
||||||
|
|
||||||
gst_type_find_signals[HAVE_TYPE] =
|
gst_type_find_signals[HAVE_TYPE] =
|
||||||
g_signal_new ("have_type", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
g_signal_new ("have_type", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
||||||
G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
|
G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
|
||||||
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
||||||
G_TYPE_POINTER);
|
G_TYPE_POINTER);
|
||||||
|
|
||||||
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
|
||||||
|
|
||||||
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_change_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -120,6 +130,10 @@ gst_type_find_init (GstTypeFind *typefind)
|
||||||
typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
||||||
gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
|
||||||
gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
|
gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
|
||||||
|
|
||||||
|
typefind->num_buffer = 0;
|
||||||
|
typefind->max_buffers = DEFAULT_MAX_BUFFERS;
|
||||||
|
typefind->caps = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -133,7 +147,11 @@ gst_type_find_set_property (GObject *object, guint prop_id,
|
||||||
typefind = GST_TYPE_FIND (object);
|
typefind = GST_TYPE_FIND (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
|
case ARG_MAX_BUFFERS:
|
||||||
|
typefind->max_buffers = g_value_get_int (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,9 +168,13 @@ gst_type_find_get_property (GObject *object, guint prop_id,
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_CAPS:
|
case ARG_CAPS:
|
||||||
g_value_set_pointer(value, typefind->caps);
|
g_value_set_pointer (value, typefind->caps);
|
||||||
|
break;
|
||||||
|
case ARG_MAX_BUFFERS:
|
||||||
|
g_value_set_int (value, typefind->max_buffers);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,18 +183,17 @@ static void
|
||||||
gst_type_find_chain (GstPad *pad, GstBuffer *buf)
|
gst_type_find_chain (GstPad *pad, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
GstTypeFind *typefind;
|
GstTypeFind *typefind;
|
||||||
GList *type_list;
|
const GList *type_list;
|
||||||
GstType *type;
|
GstType *type;
|
||||||
|
|
||||||
g_return_if_fail (pad != NULL);
|
|
||||||
g_return_if_fail (GST_IS_PAD (pad));
|
g_return_if_fail (GST_IS_PAD (pad));
|
||||||
g_return_if_fail (buf != NULL);
|
|
||||||
|
|
||||||
typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
|
typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
|
||||||
|
|
||||||
GST_DEBUG (0,"got buffer of %d bytes in '%s'",
|
GST_DEBUG (0,"got buffer of %d bytes in '%s'",
|
||||||
GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
|
GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
|
||||||
|
|
||||||
type_list = (GList *) gst_type_get_list ();
|
type_list = gst_type_get_list ();
|
||||||
|
|
||||||
while (type_list) {
|
while (type_list) {
|
||||||
GSList *factories;
|
GSList *factories;
|
||||||
|
@ -197,24 +218,53 @@ gst_type_find_chain (GstPad *pad, GstBuffer *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* int oldstate = GST_STATE(typefind);*/
|
|
||||||
gst_object_ref (GST_OBJECT (typefind));
|
gst_object_ref (GST_OBJECT (typefind));
|
||||||
g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
|
g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
|
||||||
typefind->caps);
|
typefind->caps);
|
||||||
/* if (GST_STATE(typefind) != oldstate) {
|
|
||||||
GST_DEBUG(0, "state changed during signal, aborting");
|
|
||||||
gst_element_interrupt (GST_ELEMENT (typefind));
|
|
||||||
} */
|
|
||||||
gst_object_unref (GST_OBJECT (typefind));
|
gst_object_unref (GST_OBJECT (typefind));
|
||||||
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
factories = g_slist_next (factories);
|
factories = g_slist_next (factories);
|
||||||
}
|
}
|
||||||
|
|
||||||
type_list = g_list_next (type_list);
|
type_list = g_list_next (type_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typefind->num_buffer++;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
|
|
||||||
|
if (typefind->num_buffer >= typefind->max_buffers) {
|
||||||
|
gst_element_error (GST_ELEMENT (typefind),
|
||||||
|
"typefind could not determine type after %d buffers", typefind->num_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstElementStateReturn
|
||||||
|
gst_type_find_change_state (GstElement *element)
|
||||||
|
{
|
||||||
|
GstTypeFind *typefind;
|
||||||
|
GstElementStateReturn ret;
|
||||||
|
|
||||||
|
typefind = GST_TYPE_FIND (element);
|
||||||
|
|
||||||
|
switch (GST_STATE_TRANSITION (element)) {
|
||||||
|
case GST_STATE_NULL_TO_READY:
|
||||||
|
break;
|
||||||
|
case GST_STATE_READY_TO_PAUSED:
|
||||||
|
typefind->num_buffer = 0;
|
||||||
|
gst_caps_unref (typefind->caps);
|
||||||
|
typefind->caps = NULL;
|
||||||
|
break;
|
||||||
|
case GST_STATE_PAUSED_TO_PLAYING:
|
||||||
|
case GST_STATE_PLAYING_TO_PAUSED:
|
||||||
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
|
case GST_STATE_READY_TO_NULL:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ struct _GstTypeFind {
|
||||||
GstPad *sinkpad;
|
GstPad *sinkpad;
|
||||||
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
|
gint num_buffer;
|
||||||
|
gint max_buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstTypeFindClass {
|
struct _GstTypeFindClass {
|
||||||
|
|
Loading…
Reference in a new issue