mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-27 01:28:34 +00:00
capsdebug: Add new element
This commit is contained in:
parent
819fb47b78
commit
eb81574469
4 changed files with 375 additions and 1 deletions
|
@ -8,6 +8,7 @@ plugin_LTLIBRARIES = $(EFENCE_PLUGIN) libgstdebug.la libgstnavigationtest.la
|
|||
|
||||
noinst_HEADERS = \
|
||||
efence.h \
|
||||
gstcapsdebug.h \
|
||||
gstcapssetter.h \
|
||||
gstnavigationtest.h \
|
||||
gstnavseek.h \
|
||||
|
@ -33,6 +34,7 @@ libgstnavigationtest_la_LIBTOOLFLAGS = --tag=disable-static
|
|||
libgstdebug_la_SOURCES = \
|
||||
gstdebug.c \
|
||||
breakmydata.c \
|
||||
gstcapsdebug.c \
|
||||
gstcapssetter.c \
|
||||
gstnavseek.c \
|
||||
gstpushfilesrc.c \
|
||||
|
|
314
gst/debugutils/gstcapsdebug.c
Normal file
314
gst/debugutils/gstcapsdebug.c
Normal file
|
@ -0,0 +1,314 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2010 David Schleef <ds@schleef.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/gst.h>
|
||||
#include "gstcapsdebug.h"
|
||||
|
||||
/* prototypes */
|
||||
|
||||
|
||||
static void gst_caps_debug_set_property (GObject * object,
|
||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
||||
static void gst_caps_debug_get_property (GObject * object,
|
||||
guint property_id, GValue * value, GParamSpec * pspec);
|
||||
static void gst_caps_debug_dispose (GObject * object);
|
||||
static void gst_caps_debug_finalize (GObject * object);
|
||||
|
||||
static GstFlowReturn gst_caps_debug_sink_chain (GstPad * pad,
|
||||
GstBuffer * buffer);
|
||||
static GstCaps *gst_caps_debug_getcaps (GstPad * pad);
|
||||
static gboolean gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps);
|
||||
static GstFlowReturn gst_caps_debug_bufferalloc (GstPad * pad,
|
||||
guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_caps_debug_change_state (GstElement * element, GstStateChange transition);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0
|
||||
};
|
||||
|
||||
/* pad templates */
|
||||
|
||||
static GstStaticPadTemplate gst_caps_debug_sink_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
|
||||
static GstStaticPadTemplate gst_caps_debug_src_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS_ANY);
|
||||
|
||||
/* class initialization */
|
||||
|
||||
GST_BOILERPLATE (GstCapsDebug, gst_caps_debug, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static void
|
||||
gst_caps_debug_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&gst_caps_debug_src_template));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&gst_caps_debug_sink_template));
|
||||
|
||||
gst_element_class_set_details_simple (element_class, "Caps debug",
|
||||
"Generic", "Debug caps negotiation", "David Schleef <ds@schleef.org>");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_caps_debug_class_init (GstCapsDebugClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gobject_class->set_property = gst_caps_debug_set_property;
|
||||
gobject_class->get_property = gst_caps_debug_get_property;
|
||||
gobject_class->dispose = gst_caps_debug_dispose;
|
||||
gobject_class->finalize = gst_caps_debug_finalize;
|
||||
element_class->change_state = GST_DEBUG_FUNCPTR (gst_caps_debug_change_state);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gst_caps_debug_init (GstCapsDebug * capsdebug,
|
||||
GstCapsDebugClass * capsdebug_class)
|
||||
{
|
||||
|
||||
capsdebug->srcpad =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get
|
||||
(&gst_caps_debug_src_template), "src");
|
||||
gst_pad_set_getcaps_function (capsdebug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
|
||||
gst_pad_set_acceptcaps_function (capsdebug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
|
||||
gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->srcpad);
|
||||
|
||||
capsdebug->sinkpad =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get
|
||||
(&gst_caps_debug_sink_template), "sink");
|
||||
gst_pad_set_chain_function (capsdebug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_sink_chain));
|
||||
gst_pad_set_bufferalloc_function (capsdebug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_bufferalloc));
|
||||
gst_pad_set_getcaps_function (capsdebug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
|
||||
gst_pad_set_acceptcaps_function (capsdebug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
|
||||
gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->sinkpad);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
gst_caps_debug_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS_DEBUG (object));
|
||||
capsdebug = GST_CAPS_DEBUG (object);
|
||||
|
||||
switch (property_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_caps_debug_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS_DEBUG (object));
|
||||
capsdebug = GST_CAPS_DEBUG (object);
|
||||
|
||||
switch (property_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_caps_debug_dispose (GObject * object)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS_DEBUG (object));
|
||||
capsdebug = GST_CAPS_DEBUG (object);
|
||||
|
||||
/* clean up as possible. may be called multiple times */
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
void
|
||||
gst_caps_debug_finalize (GObject * object)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS_DEBUG (object));
|
||||
capsdebug = GST_CAPS_DEBUG (object);
|
||||
|
||||
/* clean up object here */
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_caps_debug_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
|
||||
return GST_STATE_CHANGE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static GstFlowReturn
|
||||
gst_caps_debug_sink_chain (GstPad * pad, GstBuffer * buffer)
|
||||
{
|
||||
GstFlowReturn ret;
|
||||
GstCapsDebug *capsdebug;
|
||||
|
||||
capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
|
||||
|
||||
ret = gst_pad_push (capsdebug->srcpad, buffer);
|
||||
|
||||
gst_object_unref (capsdebug);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define THISPAD ((pad == capsdebug->srcpad) ? "downstream" : "upstream")
|
||||
#define OTHERPAD ((pad == capsdebug->srcpad) ? "upstream" : "downstream")
|
||||
|
||||
static GstCaps *
|
||||
gst_caps_debug_getcaps (GstPad * pad)
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstCapsDebug *capsdebug;
|
||||
gchar *s;
|
||||
GstPad *otherpad;
|
||||
|
||||
capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
|
||||
otherpad =
|
||||
(pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
|
||||
|
||||
GST_INFO ("%s called getcaps", THISPAD);
|
||||
|
||||
caps = gst_pad_peer_get_caps (otherpad);
|
||||
|
||||
s = gst_caps_to_string (caps);
|
||||
GST_INFO ("%s returned %s", OTHERPAD, s);
|
||||
g_free (s);
|
||||
|
||||
if (caps == NULL)
|
||||
caps = gst_caps_new_any ();
|
||||
|
||||
gst_object_unref (capsdebug);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
gchar *s;
|
||||
gboolean ret;
|
||||
GstPad *otherpad;
|
||||
|
||||
capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
|
||||
otherpad =
|
||||
(pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
|
||||
|
||||
s = gst_caps_to_string (caps);
|
||||
GST_INFO ("%s called acceptcaps with %s", THISPAD, s);
|
||||
g_free (s);
|
||||
|
||||
ret = gst_pad_peer_accept_caps (otherpad, caps);
|
||||
|
||||
GST_INFO ("%s returned %s", OTHERPAD, ret ? "TRUE" : "FALSE");
|
||||
|
||||
gst_object_unref (capsdebug);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_caps_debug_bufferalloc (GstPad * pad, guint64 offset, guint size,
|
||||
GstCaps * caps, GstBuffer ** buf)
|
||||
{
|
||||
GstCapsDebug *capsdebug;
|
||||
gchar *s;
|
||||
gchar *t;
|
||||
GstFlowReturn ret;
|
||||
GstPad *otherpad;
|
||||
gboolean newcaps;
|
||||
|
||||
capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
|
||||
otherpad =
|
||||
(pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
|
||||
|
||||
newcaps = (caps != GST_PAD_CAPS (pad));
|
||||
|
||||
if (newcaps) {
|
||||
s = gst_caps_to_string (caps);
|
||||
GST_INFO ("%s called bufferalloc with new caps, offset=%" G_GUINT64_FORMAT
|
||||
" size=%d caps=%s", THISPAD, offset, size, s);
|
||||
g_free (s);
|
||||
}
|
||||
|
||||
ret = gst_pad_alloc_buffer_and_set_caps (otherpad, offset, size, caps, buf);
|
||||
|
||||
if (newcaps) {
|
||||
GST_INFO ("%s returned %s", OTHERPAD, gst_flow_get_name (ret));
|
||||
}
|
||||
if (caps != GST_BUFFER_CAPS (*buf)) {
|
||||
s = gst_caps_to_string (caps);
|
||||
t = gst_caps_to_string (GST_BUFFER_CAPS (*buf));
|
||||
GST_INFO
|
||||
("%s returned from bufferalloc with different caps, requested=%s returned=%s",
|
||||
OTHERPAD, s, t);
|
||||
g_free (s);
|
||||
g_free (t);
|
||||
}
|
||||
|
||||
gst_object_unref (capsdebug);
|
||||
|
||||
return ret;
|
||||
}
|
55
gst/debugutils/gstcapsdebug.h
Normal file
55
gst/debugutils/gstcapsdebug.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2010 FIXME <fixme@example.com>
|
||||
*
|
||||
* 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_CAPS_DEBUG_H_
|
||||
#define _GST_CAPS_DEBUG_H_
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_CAPS_DEBUG (gst_caps_debug_get_type())
|
||||
#define GST_CAPS_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAPS_DEBUG,GstCapsDebug))
|
||||
#define GST_CAPS_DEBUG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAPS_DEBUG,GstCapsDebugClass))
|
||||
#define GST_IS_CAPS_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAPS_DEBUG))
|
||||
#define GST_IS_CAPS_DEBUG_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAPS_DEBUG))
|
||||
|
||||
typedef struct _GstCapsDebug GstCapsDebug;
|
||||
typedef struct _GstCapsDebugClass GstCapsDebugClass;
|
||||
|
||||
struct _GstCapsDebug
|
||||
{
|
||||
GstElement base_capsdebug;
|
||||
|
||||
GstPad *srcpad;
|
||||
GstPad *sinkpad;
|
||||
|
||||
};
|
||||
|
||||
struct _GstCapsDebugClass
|
||||
{
|
||||
GstElementClass base_capsdebug_class;
|
||||
};
|
||||
|
||||
GType gst_caps_debug_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
|
@ -24,6 +24,7 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
GType gst_break_my_data_get_type (void);
|
||||
GType gst_caps_debug_get_type (void);
|
||||
GType gst_caps_setter_get_type (void);
|
||||
GType gst_rnd_buffer_size_get_type (void);
|
||||
GType gst_navseek_get_type (void);
|
||||
|
@ -54,7 +55,9 @@ plugin_init (GstPlugin * plugin)
|
|||
|| !gst_element_register (plugin, "taginject", GST_RANK_NONE,
|
||||
gst_tag_inject_get_type ())
|
||||
|| !gst_element_register (plugin, "testsink", GST_RANK_NONE,
|
||||
gst_test_get_type ()))
|
||||
gst_test_get_type ())
|
||||
|| !gst_element_register (plugin, "capsdebug", GST_RANK_NONE,
|
||||
gst_caps_debug_get_type ()))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in a new issue