Commit bb1be5f5 authored by Wim Taymans's avatar Wim Taymans

gst/: Simplify pad activation.

Original commit message from CVS:
* gst/base/Makefile.am:
* gst/base/README:
* gst/base/gstbasesink.c: (gst_basesink_get_type),
(gst_basesink_base_init), (gst_basesink_class_init),
(gst_basesink_pad_getcaps), (gst_basesink_init),
(gst_basesink_activate), (gst_basesink_change_state):
* gst/base/gstbasesink.h:
* gst/base/gstbasetransform.c: (gst_base_transform_get_type),
(gst_base_transform_base_init), (gst_base_transform_finalize),
(gst_base_transform_class_init), (gst_base_transform_init),
(gst_base_transform_proxy_getcaps), (gst_base_transform_setcaps),
(gst_base_transform_event), (gst_base_transform_getrange),
(gst_base_transform_chain), (gst_base_transform_handle_buffer),
(gst_base_transform_set_property),
(gst_base_transform_get_property),
(gst_base_transform_sink_activate),
(gst_base_transform_src_activate),
(gst_base_transform_change_state):
* gst/base/gstbasetransform.h:
* gst/elements/gstidentity.c: (gst_identity_finalize),
(gst_identity_class_init), (gst_identity_init),
(gst_identity_event), (gst_identity_check_perfect),
(gst_identity_transform), (gst_identity_set_property),
(gst_identity_get_property), (gst_identity_change_state):
* gst/elements/gstidentity.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_check_pull_range), (gst_pad_pull_range):
* gst/gstpad.h:
Simplify pad activation.
Added function to check if pull_range can be performed.
Error out when pulling inactive or flushing pads.
Removed const from refcounted types as it does not make sense.
Simplify pad templates in basesink
Added base class for simple 1-to-1 transforms.
Make identity subclass the base transform.
parent 64047b28
2005-03-29 Wim Taymans <wim@fluendo.com>
* gst/base/Makefile.am:
* gst/base/README:
* gst/base/gstbasesink.c: (gst_basesink_get_type),
(gst_basesink_base_init), (gst_basesink_class_init),
(gst_basesink_pad_getcaps), (gst_basesink_init),
(gst_basesink_activate), (gst_basesink_change_state):
* gst/base/gstbasesink.h:
* gst/base/gstbasetransform.c: (gst_base_transform_get_type),
(gst_base_transform_base_init), (gst_base_transform_finalize),
(gst_base_transform_class_init), (gst_base_transform_init),
(gst_base_transform_proxy_getcaps), (gst_base_transform_setcaps),
(gst_base_transform_event), (gst_base_transform_getrange),
(gst_base_transform_chain), (gst_base_transform_handle_buffer),
(gst_base_transform_set_property),
(gst_base_transform_get_property),
(gst_base_transform_sink_activate),
(gst_base_transform_src_activate),
(gst_base_transform_change_state):
* gst/base/gstbasetransform.h:
* gst/elements/gstidentity.c: (gst_identity_finalize),
(gst_identity_class_init), (gst_identity_init),
(gst_identity_event), (gst_identity_check_perfect),
(gst_identity_transform), (gst_identity_set_property),
(gst_identity_get_property), (gst_identity_change_state):
* gst/elements/gstidentity.h:
* gst/gstelement.c: (gst_element_get_state_func),
(gst_element_lost_state), (gst_element_pads_activate):
* gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active),
(gst_pad_check_pull_range), (gst_pad_pull_range):
* gst/gstpad.h:
Simplify pad activation.
Added function to check if pull_range can be performed.
Error out when pulling inactive or flushing pads.
Removed const from refcounted types as it does not make sense.
Simplify pad templates in basesink
Added base class for simple 1-to-1 transforms.
Make identity subclass the base transform.
2005-03-29 Andy Wingo <wingo@pobox.com>
* docs/libs/gstreamer-libs-overrides.txt:
......
......@@ -6,7 +6,8 @@ noinst_DATA = $(as_libtool_noinst_DATA_files)
libgstbase_@GST_MAJORMINOR@_la_DEPENDENCIES = ../libgstreamer-@GST_MAJORMINOR@.la
libgstbase_@GST_MAJORMINOR@_la_SOURCES = \
gstbasesink.c
gstbasesink.c \
gstbasetransform.c
libgstbase_@GST_MAJORMINOR@_la_CFLAGS = $(GST_OBJ_CFLAGS)
libgstbase_@GST_MAJORMINOR@_la_LIBADD = $(GST_OBJ_LIBS)
......@@ -16,7 +17,8 @@ libgstbase_@GST_MAJORMINOR@includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/base
libgstbase_@GST_MAJORMINOR@include_HEADERS = \
gstbasesink.h
gstbasesink.h \
gstbasetransform.h
install-data-local: as-libtool-install-data-local
......
......@@ -14,3 +14,14 @@ GstBaseSink
FIXME: not much point making it operate in pull mode as a generic
base class I guess...
GstBaseTransform
Base class for simple tranform filters
- one sinkpad and one srcpad
- formats the same on sink and source pad.
- handles state changes
- does flushing
- push mode
- pull mode if transform can operate on arbitrary data
......@@ -26,11 +26,6 @@
#include "gstbasesink.h"
#include <gst/gstmarshal.h>
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
GST_DEBUG_CATEGORY_STATIC (gst_basesink_debug);
#define GST_CAT_DEFAULT gst_basesink_debug
......@@ -61,11 +56,35 @@ enum
PROP_PREROLL_QUEUE_LEN
};
#define _do_init(bla) \
GST_DEBUG_CATEGORY_INIT (gst_basesink_debug, "basesink", 0, "basesink element");
static GstElementClass *parent_class = NULL;
static void gst_basesink_base_init (gpointer g_class);
static void gst_basesink_class_init (GstBaseSinkClass * klass);
static void gst_basesink_init (GstBaseSink * trans, gpointer g_class);
GType
gst_basesink_get_type (void)
{
static GType basesink_type = 0;
if (!basesink_type) {
static const GTypeInfo basesink_info = {
sizeof (GstBaseSinkClass),
(GBaseInitFunc) gst_basesink_base_init,
NULL,
(GClassInitFunc) gst_basesink_class_init,
NULL,
NULL,
sizeof (GstBaseSink),
0,
(GInstanceInitFunc) gst_basesink_init,
};
GST_BOILERPLATE_FULL (GstBaseSink, gst_basesink, GstElement, GST_TYPE_ELEMENT,
_do_init);
basesink_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstBaseSink", &basesink_info, G_TYPE_FLAG_ABSTRACT);
}
return basesink_type;
}
static void gst_basesink_set_clock (GstElement * element, GstClock * clock);
......@@ -74,7 +93,6 @@ static void gst_basesink_set_property (GObject * object, guint prop_id,
static void gst_basesink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstStaticPadTemplate *gst_base_sink_get_template (GstBaseSink * sink);
static GstCaps *gst_base_sink_get_caps (GstBaseSink * sink);
static gboolean gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps);
static GstBuffer *gst_base_sink_buffer_alloc (GstBaseSink * sink,
......@@ -93,32 +111,11 @@ static gboolean gst_basesink_event (GstPad * pad, GstEvent * event);
static inline void gst_basesink_handle_buffer (GstBaseSink * basesink,
GstBuffer * buf);
static GstStaticPadTemplate *
gst_basesink_get_template (GstBaseSink * bsink)
{
GstStaticPadTemplate *template = NULL;
GstBaseSinkClass *bclass;
bclass = GST_BASESINK_GET_CLASS (bsink);
if (bclass->get_template)
template = bclass->get_template (bsink);
if (template == NULL) {
template = &sinktemplate;
}
return template;
}
static void
gst_basesink_base_init (gpointer g_class)
{
//GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
/*
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sinktemplate));
*/
GST_DEBUG_CATEGORY_INIT (gst_basesink_debug, "basesink", 0,
"basesink element");
}
static void
......@@ -130,6 +127,8 @@ gst_basesink_class_init (GstBaseSinkClass * klass)
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_basesink_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_basesink_get_property);
......@@ -153,7 +152,6 @@ gst_basesink_class_init (GstBaseSinkClass * klass)
klass->get_caps = GST_DEBUG_FUNCPTR (gst_base_sink_get_caps);
klass->set_caps = GST_DEBUG_FUNCPTR (gst_base_sink_set_caps);
klass->get_template = GST_DEBUG_FUNCPTR (gst_base_sink_get_template);
klass->buffer_alloc = GST_DEBUG_FUNCPTR (gst_base_sink_buffer_alloc);
klass->get_times = GST_DEBUG_FUNCPTR (gst_basesink_get_times);
}
......@@ -171,13 +169,15 @@ gst_basesink_pad_getcaps (GstPad * pad)
caps = bclass->get_caps (bsink);
if (caps == NULL) {
GstStaticPadTemplate *stemplate;
GstPadTemplate *template;
GstPadTemplate *pad_template;
stemplate = gst_basesink_get_template (bsink);
template = gst_static_pad_template_get (stemplate);
caps = gst_caps_copy (gst_pad_template_get_caps (template));
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
if (pad_template != NULL) {
caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
}
}
return caps;
}
......@@ -213,15 +213,16 @@ gst_basesink_pad_buffer_alloc (GstPad * pad, guint64 offset, guint size,
}
static void
gst_basesink_init (GstBaseSink * basesink)
gst_basesink_init (GstBaseSink * basesink, gpointer g_class)
{
GstStaticPadTemplate *template;
GstPadTemplate *pad_template;
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink");
g_return_if_fail (pad_template != NULL);
template = gst_basesink_get_template (basesink);
basesink->sinkpad = gst_pad_new_from_template (pad_template, "sink");
basesink->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get (template),
"sink");
gst_pad_set_getcaps_function (basesink->sinkpad,
GST_DEBUG_FUNCPTR (gst_basesink_pad_getcaps));
gst_pad_set_setcaps_function (basesink->sinkpad,
......@@ -328,12 +329,6 @@ gst_basesink_get_property (GObject * object, guint prop_id, GValue * value,
GST_UNLOCK (sink);
}
static GstStaticPadTemplate *
gst_base_sink_get_template (GstBaseSink * sink)
{
return &sinktemplate;
}
static GstCaps *
gst_base_sink_get_caps (GstBaseSink * sink)
{
......@@ -735,6 +730,7 @@ gst_basesink_activate (GstPad * pad, GstActivateMode mode)
case GST_ACTIVATE_PULL:
/* if we have a scheduler we can start the task */
g_return_val_if_fail (basesink->has_loop, FALSE);
gst_pad_peer_set_active (pad, mode);
if (GST_ELEMENT_SCHEDULER (basesink)) {
GST_STREAM_LOCK (pad);
GST_RPAD_TASK (pad) =
......@@ -791,7 +787,7 @@ gst_basesink_change_state (GstElement * element)
break;
case GST_STATE_READY_TO_PAUSED:
/* need to complete preroll before this state change completes, there
* is no data flow in READY so we cqn safely assume we need to preroll. */
* is no data flow in READY so we can safely assume we need to preroll. */
basesink->offset = 0;
GST_PREROLL_LOCK (basesink->sinkpad);
basesink->preroll_queue = g_queue_new ();
......
......@@ -66,8 +66,6 @@ struct _GstBaseSink {
struct _GstBaseSinkClass {
GstElementClass parent_class;
GstStaticPadTemplate* (*get_template) (GstBaseSink *sink);
GstCaps* (*get_caps) (GstBaseSink *sink);
gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps);
......
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
* 2005 Wim Taymans <wim@fluendo.com>
*
* gstbasetransform.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>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include "gstbasetransform.h"
#include <gst/gstmarshal.h>
GST_DEBUG_CATEGORY_STATIC (gst_base_transform_debug);
#define GST_CAT_DEFAULT gst_base_transform_debug
/* BaseTransform signals and args */
enum
{
SIGNAL_HANDOFF,
/* FILL ME */
LAST_SIGNAL
};
enum
{
PROP_0,
};
static GstElementClass *parent_class = NULL;
static void gst_base_transform_base_init (gpointer g_class);
static void gst_base_transform_class_init (GstBaseTransformClass * klass);
static void gst_base_transform_init (GstBaseTransform * trans,
gpointer g_class);
GType
gst_base_transform_get_type (void)
{
static GType base_transform_type = 0;
if (!base_transform_type) {
static const GTypeInfo base_transform_info = {
sizeof (GstBaseTransformClass),
(GBaseInitFunc) gst_base_transform_base_init,
NULL,
(GClassInitFunc) gst_base_transform_class_init,
NULL,
NULL,
sizeof (GstBaseTransform),
0,
(GInstanceInitFunc) gst_base_transform_init,
};
base_transform_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstBaseTransform", &base_transform_info, G_TYPE_FLAG_ABSTRACT);
}
return base_transform_type;
}
static void gst_base_transform_finalize (GObject * object);
static void gst_base_transform_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_base_transform_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_base_transform_src_activate (GstPad * pad,
GstActivateMode mode);
static gboolean gst_base_transform_sink_activate (GstPad * pad,
GstActivateMode mode);
static GstElementStateReturn gst_base_transform_change_state (GstElement *
element);
static gboolean gst_base_transform_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_base_transform_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer);
static GstFlowReturn gst_base_transform_chain (GstPad * pad,
GstBuffer * buffer);
static GstFlowReturn gst_base_transform_handle_buffer (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer ** outbuf);
static GstCaps *gst_base_transform_proxy_getcaps (GstPad * pad);
static gboolean gst_base_transform_setcaps (GstPad * pad, GstCaps * caps);
/* static guint gst_base_transform_signals[LAST_SIGNAL] = { 0 }; */
static void
gst_base_transform_base_init (gpointer g_class)
{
GST_DEBUG_CATEGORY_INIT (gst_base_transform_debug, "basetransform", 0,
"basetransform element");
}
static void
gst_base_transform_finalize (GObject * object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_base_transform_class_init (GstBaseTransformClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = G_OBJECT_CLASS (klass);
gstelement_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property =
GST_DEBUG_FUNCPTR (gst_base_transform_set_property);
gobject_class->get_property =
GST_DEBUG_FUNCPTR (gst_base_transform_get_property);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_transform_finalize);
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_base_transform_change_state);
}
static void
gst_base_transform_init (GstBaseTransform * trans, gpointer g_class)
{
GstPadTemplate *pad_template;
GST_DEBUG ("gst_base_transform_init");
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink");
g_return_if_fail (pad_template != NULL);
trans->sinkpad = gst_pad_new_from_template (pad_template, "sink");
gst_pad_set_getcaps_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_proxy_getcaps));
gst_pad_set_setcaps_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_setcaps));
gst_pad_set_event_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_event));
gst_pad_set_chain_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_chain));
gst_pad_set_activate_function (trans->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_transform_sink_activate));
gst_element_add_pad (GST_ELEMENT (trans), trans->sinkpad);
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
g_return_if_fail (pad_template != NULL);
trans->srcpad = gst_pad_new_from_template (pad_template, "src");
gst_pad_set_getcaps_function (trans->srcpad,
GST_DEBUG_FUNCPTR (gst_base_transform_proxy_getcaps));
gst_pad_set_getrange_function (trans->srcpad,
GST_DEBUG_FUNCPTR (gst_base_transform_getrange));
gst_pad_set_activate_function (trans->srcpad,
GST_DEBUG_FUNCPTR (gst_base_transform_src_activate));
gst_element_add_pad (GST_ELEMENT (trans), trans->srcpad);
}
static GstCaps *
gst_base_transform_proxy_getcaps (GstPad * pad)
{
GstPad *otherpad;
GstBaseTransform *trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
otherpad = pad == trans->srcpad ? trans->sinkpad : trans->srcpad;
return gst_pad_peer_get_caps (otherpad);
}
static gboolean
gst_base_transform_setcaps (GstPad * pad, GstCaps * caps)
{
GstBaseTransform *trans;
GstBaseTransformClass *bclass;
gboolean result = TRUE;
trans = GST_BASE_TRANSFORM (GST_PAD_PARENT (pad));
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->set_caps)
result = bclass->set_caps (trans, caps);
return result;
}
static gboolean
gst_base_transform_event (GstPad * pad, GstEvent * event)
{
GstBaseTransform *trans;
GstBaseTransformClass *bclass;
gboolean ret = FALSE;
trans = GST_BASE_TRANSFORM (GST_PAD_PARENT (pad));
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->event)
bclass->event (trans, event);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH:
if (GST_EVENT_FLUSH_DONE (event)) {
}
GST_STREAM_LOCK (pad);
break;
case GST_EVENT_EOS:
GST_STREAM_LOCK (pad);
break;
default:
break;
}
ret = gst_pad_event_default (pad, event);
GST_STREAM_UNLOCK (pad);
return ret;
}
static GstFlowReturn
gst_base_transform_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer)
{
GstBaseTransform *trans;
GstFlowReturn ret;
GstBuffer *inbuf;
trans = GST_BASE_TRANSFORM (GST_PAD_PARENT (pad));
GST_STREAM_LOCK (pad);
ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf);
if (ret == GST_FLOW_OK) {
ret = gst_base_transform_handle_buffer (trans, inbuf, buffer);
}
GST_STREAM_UNLOCK (pad);
return ret;
}
static GstFlowReturn
gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
{
GstBaseTransform *trans;
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *outbuf;
trans = GST_BASE_TRANSFORM (GST_PAD_PARENT (pad));
GST_STREAM_LOCK (pad);
ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf);
if (ret == GST_FLOW_OK) {
ret = gst_pad_push (trans->srcpad, outbuf);
}
GST_STREAM_UNLOCK (pad);
return ret;
}
static GstFlowReturn
gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer ** outbuf)
{
GstFlowReturn ret = GST_FLOW_OK;
GstBaseTransformClass *bclass;
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
if (bclass->transform)
ret = bclass->transform (trans, inbuf, outbuf);
gst_buffer_unref (inbuf);
return ret;
}
static void
gst_base_transform_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstBaseTransform *trans;
trans = GST_BASE_TRANSFORM (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_base_transform_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstBaseTransform *trans;
trans = GST_BASE_TRANSFORM (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_base_transform_sink_activate (GstPad * pad, GstActivateMode mode)
{
gboolean result = FALSE;
GstBaseTransform *trans;
trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
switch (mode) {
case GST_ACTIVATE_PUSH:
result = TRUE;
break;
case GST_ACTIVATE_PULL:
result = TRUE;
break;
case GST_ACTIVATE_NONE:
result = TRUE;
break;
}
return result;
}
static gboolean
gst_base_transform_src_activate (GstPad * pad, GstActivateMode mode)
{
gboolean result = FALSE;
GstBaseTransform *trans;
trans = GST_BASE_TRANSFORM (GST_OBJECT_PARENT (pad));
switch (mode) {