2001-12-22 22:43:48 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2001 Thomas <thomas@apestaart.org>
|
2006-05-10 11:54:36 +00:00
|
|
|
* 2005,2006 Wim Taymans <wim@fluendo.com>
|
2001-12-22 22:43:48 +00:00
|
|
|
*
|
|
|
|
* adder.c: Adder element, N in, one out, samples are added
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-03-24 10:42:11 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-adder
|
|
|
|
*
|
2008-07-10 21:06:06 +00:00
|
|
|
* The adder allows to mix several streams into one by adding the data.
|
2006-03-24 10:42:11 +00:00
|
|
|
* Mixed data is clamped to the min/max values of the data format.
|
2008-07-10 21:06:06 +00:00
|
|
|
*
|
|
|
|
* The adder currently mixes all data received on the sinkpads as soon as
|
|
|
|
* possible without trying to synchronize the streams.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
2006-03-24 10:42:11 +00:00
|
|
|
* <title>Example launch line</title>
|
2008-07-10 21:06:06 +00:00
|
|
|
* |[
|
2006-03-24 10:42:11 +00:00
|
|
|
* gst-launch audiotestsrc freq=100 ! adder name=mix ! audioconvert ! alsasink audiotestsrc freq=500 ! mix.
|
2008-07-10 21:06:06 +00:00
|
|
|
* ]| This pipeline produces two sine waves mixed together.
|
2006-03-24 10:42:11 +00:00
|
|
|
* </refsect2>
|
2006-05-10 11:54:36 +00:00
|
|
|
*
|
|
|
|
* Last reviewed on 2006-05-09 (0.10.7)
|
2006-03-24 10:42:11 +00:00
|
|
|
*/
|
2004-01-27 09:00:01 +00:00
|
|
|
/* Element-Checklist-Version: 5 */
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 22:43:48 +00:00
|
|
|
#include "gstadder.h"
|
2002-09-09 09:26:23 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2004-03-15 19:32:28 +00:00
|
|
|
#include <string.h> /* strcmp */
|
2008-12-17 08:51:34 +00:00
|
|
|
/*#include <liboil/liboil.h>*/
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2004-03-31 17:11:14 +00:00
|
|
|
/* highest positive/lowest negative x-bit value we can use for clamping */
|
2005-05-05 09:46:03 +00:00
|
|
|
#define MAX_INT_32 ((gint32) (0x7fffffff))
|
|
|
|
#define MAX_INT_16 ((gint16) (0x7fff))
|
|
|
|
#define MAX_INT_8 ((gint8) (0x7f))
|
|
|
|
#define MAX_UINT_32 ((guint32)(0xffffffff))
|
|
|
|
#define MAX_UINT_16 ((guint16)(0xffff))
|
|
|
|
#define MAX_UINT_8 ((guint8) (0xff))
|
|
|
|
|
|
|
|
#define MIN_INT_32 ((gint32) (0x80000000))
|
|
|
|
#define MIN_INT_16 ((gint16) (0x8000))
|
|
|
|
#define MIN_INT_8 ((gint8) (0x80))
|
|
|
|
#define MIN_UINT_32 ((guint32)(0x00000000))
|
|
|
|
#define MIN_UINT_16 ((guint16)(0x0000))
|
|
|
|
#define MIN_UINT_8 ((guint8) (0x00))
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_FILTER_CAPS
|
|
|
|
};
|
|
|
|
|
2004-03-31 17:11:14 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_adder_debug
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
2004-03-31 17:11:14 +00:00
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2008-05-14 10:58:52 +00:00
|
|
|
|
|
|
|
#define CAPS \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
2008-05-21 05:48:05 +00:00
|
|
|
"width = (int) 32, " \
|
|
|
|
"depth = (int) 32, " \
|
|
|
|
"signed = (boolean) { true, false } ;" \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
|
|
|
"signed = (boolean) { true, false } ;" \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 8, " \
|
|
|
|
"depth = (int) 8, " \
|
2008-05-14 10:58:52 +00:00
|
|
|
"signed = (boolean) { true, false } ;" \
|
|
|
|
"audio/x-raw-float, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) { 32, 64 }"
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_adder_src_template =
|
2008-05-14 10:58:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2008-05-14 10:58:52 +00:00
|
|
|
GST_STATIC_CAPS (CAPS)
|
2004-03-14 22:34:34 +00:00
|
|
|
);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_adder_sink_template =
|
2008-05-14 10:58:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink%d",
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_REQUEST,
|
2008-05-14 10:58:52 +00:00
|
|
|
GST_STATIC_CAPS (CAPS)
|
2004-03-14 22:34:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_adder_class_init (GstAdderClass * klass);
|
|
|
|
static void gst_adder_init (GstAdder * adder);
|
2009-07-10 19:06:28 +00:00
|
|
|
static void gst_adder_dispose (GObject * object);
|
|
|
|
static void gst_adder_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_adder_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2006-04-28 19:17:06 +00:00
|
|
|
static gboolean gst_adder_setcaps (GstPad * pad, GstCaps * caps);
|
|
|
|
static gboolean gst_adder_query (GstPad * pad, GstQuery * query);
|
|
|
|
static gboolean gst_adder_src_event (GstPad * pad, GstEvent * event);
|
2006-05-10 11:54:36 +00:00
|
|
|
static gboolean gst_adder_sink_event (GstPad * pad, GstEvent * event);
|
2006-04-28 19:17:06 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstPad *gst_adder_request_new_pad (GstElement * element,
|
|
|
|
GstPadTemplate * temp, const gchar * unused);
|
2006-05-30 16:07:50 +00:00
|
|
|
static void gst_adder_release_pad (GstElement * element, GstPad * pad);
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn gst_adder_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
static GstFlowReturn gst_adder_collected (GstCollectPads * pads,
|
|
|
|
gpointer user_data);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
GType
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_adder_get_type (void)
|
|
|
|
{
|
2001-12-22 22:43:48 +00:00
|
|
|
static GType adder_type = 0;
|
|
|
|
|
2006-03-24 10:42:11 +00:00
|
|
|
if (G_UNLIKELY (adder_type == 0)) {
|
2001-12-22 22:43:48 +00:00
|
|
|
static const GTypeInfo adder_info = {
|
2002-09-09 09:26:23 +00:00
|
|
|
sizeof (GstAdderClass), NULL, NULL,
|
|
|
|
(GClassInitFunc) gst_adder_class_init, NULL, NULL,
|
2002-09-23 09:39:33 +00:00
|
|
|
sizeof (GstAdder), 0,
|
2002-09-09 09:26:23 +00:00
|
|
|
(GInstanceInitFunc) gst_adder_init,
|
2001-12-22 22:43:48 +00:00
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
adder_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAdder",
|
2004-03-15 19:32:28 +00:00
|
|
|
&adder_info, 0);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "adder", 0,
|
2004-03-31 17:11:14 +00:00
|
|
|
"audio channel mixing element");
|
2001-12-22 22:43:48 +00:00
|
|
|
}
|
|
|
|
return adder_type;
|
|
|
|
}
|
|
|
|
|
2009-03-05 10:27:16 +00:00
|
|
|
/* clipping versions (for int)
|
2008-12-17 08:51:34 +00:00
|
|
|
* FIXME: what about: oil_add_s16 (out, out, in, bytes / sizeof (type))
|
|
|
|
*/
|
2005-12-06 19:42:02 +00:00
|
|
|
#define MAKE_FUNC(name,type,ttype,min,max) \
|
|
|
|
static void name (type *out, type *in, gint bytes) { \
|
|
|
|
gint i; \
|
2009-03-05 10:27:16 +00:00
|
|
|
ttype add; \
|
|
|
|
for (i = 0; i < bytes / sizeof (type); i++) { \
|
|
|
|
add = (ttype)out[i] + (ttype)in[i]; \
|
|
|
|
out[i] = CLAMP (add, min, max); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unsigned versions (for int) */
|
|
|
|
#define MAKE_FUNC_US(name,type,ttype,max) \
|
|
|
|
static void name (type *out, type *in, gint bytes) { \
|
|
|
|
gint i; \
|
|
|
|
ttype add; \
|
|
|
|
for (i = 0; i < bytes / sizeof (type); i++) { \
|
|
|
|
add = (ttype)out[i] + (ttype)in[i]; \
|
|
|
|
out[i] = ((add <= max) ? add : max); \
|
|
|
|
} \
|
2005-05-05 09:46:03 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 15:53:43 +00:00
|
|
|
/* non-clipping versions (for float) */
|
2008-12-17 08:51:34 +00:00
|
|
|
#define MAKE_FUNC_NC(name,type) \
|
2006-08-11 15:53:43 +00:00
|
|
|
static void name (type *out, type *in, gint bytes) { \
|
|
|
|
gint i; \
|
|
|
|
for (i = 0; i < bytes / sizeof (type); i++) \
|
2008-12-17 08:51:34 +00:00
|
|
|
out[i] += in[i]; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2009-03-05 10:27:16 +00:00
|
|
|
/* right now, the liboil function don't seems to be faster on x86
|
2008-12-17 08:51:34 +00:00
|
|
|
* time gst-launch audiotestsrc num-buffers=50000 ! audio/x-raw-float ! adder name=m ! fakesink audiotestsrc num-buffers=50000 ! audio/x-raw-float ! m.
|
|
|
|
* time gst-launch audiotestsrc num-buffers=50000 ! audio/x-raw-float,width=32 ! adder name=m ! fakesink audiotestsrc num-buffers=50000 ! audio/x-raw-float,width=32 ! m.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_float32 (gfloat * out, gfloat * in, gint bytes)
|
|
|
|
{
|
|
|
|
oil_add_f32 (out, out, in, bytes / sizeof (gfloat));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_float64 (gdouble * out, gdouble * in, gint bytes)
|
|
|
|
{
|
|
|
|
oil_add_f64 (out, out, in, bytes / sizeof (gdouble));
|
2006-08-11 15:53:43 +00:00
|
|
|
}
|
2008-12-17 08:51:34 +00:00
|
|
|
#endif
|
2006-08-11 15:53:43 +00:00
|
|
|
|
2006-04-28 19:17:06 +00:00
|
|
|
/* *INDENT-OFF* */
|
2005-05-05 09:46:03 +00:00
|
|
|
MAKE_FUNC (add_int32, gint32, gint64, MIN_INT_32, MAX_INT_32)
|
2006-04-28 19:17:06 +00:00
|
|
|
MAKE_FUNC (add_int16, gint16, gint32, MIN_INT_16, MAX_INT_16)
|
|
|
|
MAKE_FUNC (add_int8, gint8, gint16, MIN_INT_8, MAX_INT_8)
|
2009-03-05 10:27:16 +00:00
|
|
|
MAKE_FUNC_US (add_uint32, guint32, guint64, MAX_UINT_32)
|
|
|
|
MAKE_FUNC_US (add_uint16, guint16, guint32, MAX_UINT_16)
|
|
|
|
MAKE_FUNC_US (add_uint8, guint8, guint16, MAX_UINT_8)
|
2008-12-17 08:51:34 +00:00
|
|
|
MAKE_FUNC_NC (add_float64, gdouble)
|
|
|
|
MAKE_FUNC_NC (add_float32, gfloat)
|
2006-04-28 19:17:06 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
/* we can only accept caps that we and downstream can handle.
|
|
|
|
* if we have filtercaps set, use those to constrain the target caps.
|
|
|
|
*/
|
2007-07-03 11:52:47 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_adder_sink_getcaps (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstAdder *adder;
|
|
|
|
GstCaps *result, *peercaps, *sinkcaps;
|
|
|
|
|
|
|
|
adder = GST_ADDER (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
/* get the downstream possible caps */
|
|
|
|
peercaps = gst_pad_peer_get_caps (adder->srcpad);
|
2009-07-10 19:06:28 +00:00
|
|
|
|
2007-07-03 11:52:47 +00:00
|
|
|
/* get the allowed caps on this sinkpad, we use the fixed caps function so
|
|
|
|
* that it does not call recursively in this function. */
|
|
|
|
sinkcaps = gst_pad_get_fixed_caps_func (pad);
|
|
|
|
if (peercaps) {
|
2009-07-10 19:06:28 +00:00
|
|
|
/* restrict with filter-caps if any */
|
|
|
|
if (adder->filter_caps) {
|
|
|
|
result = gst_caps_intersect (peercaps, adder->filter_caps);
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
peercaps = result;
|
|
|
|
}
|
2007-07-03 11:52:47 +00:00
|
|
|
/* if the peer has caps, intersect */
|
|
|
|
GST_DEBUG_OBJECT (adder, "intersecting peer and template caps");
|
|
|
|
result = gst_caps_intersect (peercaps, sinkcaps);
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
gst_caps_unref (sinkcaps);
|
|
|
|
} else {
|
|
|
|
/* the peer has no caps (or there is no peer), just use the allowed caps
|
|
|
|
* of this sinkpad. */
|
|
|
|
GST_DEBUG_OBJECT (adder, "no peer caps, using sinkcaps");
|
|
|
|
result = sinkcaps;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
|
2009-03-10 19:00:26 +00:00
|
|
|
GST_LOG_OBJECT (adder, "getting caps on pad %p,%s to %" GST_PTR_FORMAT, pad,
|
|
|
|
GST_PAD_NAME (pad), result);
|
|
|
|
|
2007-07-03 11:52:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the first caps we receive on any of the sinkpads will define the caps for all
|
|
|
|
* the other sinkpads because we can only mix streams with the same caps.
|
2009-07-10 19:06:28 +00:00
|
|
|
*/
|
2006-04-28 19:17:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_adder_setcaps (GstPad * pad, GstCaps * caps)
|
2002-02-19 05:59:06 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder;
|
2005-05-05 09:46:03 +00:00
|
|
|
GList *pads;
|
2004-01-27 09:00:01 +00:00
|
|
|
GstStructure *structure;
|
2005-05-05 09:46:03 +00:00
|
|
|
const char *media_type;
|
2004-01-22 03:25:16 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
adder = GST_ADDER (GST_PAD_PARENT (pad));
|
2004-01-22 03:25:16 +00:00
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
GST_LOG_OBJECT (adder, "setting caps on pad %p,%s to %" GST_PTR_FORMAT, pad,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, see if the other pads can accept the format. Also lock the
|
|
|
|
* format on the other pads to this new format. */
|
2005-11-21 16:35:24 +00:00
|
|
|
GST_OBJECT_LOCK (adder);
|
2005-05-05 09:46:03 +00:00
|
|
|
pads = GST_ELEMENT (adder)->pads;
|
2004-01-27 09:00:01 +00:00
|
|
|
while (pads) {
|
|
|
|
GstPad *otherpad = GST_PAD (pads->data);
|
|
|
|
|
|
|
|
if (otherpad != pad) {
|
2005-05-05 09:46:03 +00:00
|
|
|
gst_caps_replace (&GST_PAD_CAPS (otherpad), caps);
|
2002-02-19 05:59:06 +00:00
|
|
|
}
|
2004-01-27 09:00:01 +00:00
|
|
|
pads = g_list_next (pads);
|
|
|
|
}
|
2005-11-21 16:35:24 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
2004-01-27 09:00:01 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
/* parse caps now */
|
2004-01-27 09:00:01 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
media_type = gst_structure_get_name (structure);
|
|
|
|
if (strcmp (media_type, "audio/x-raw-int") == 0) {
|
2004-03-14 22:34:34 +00:00
|
|
|
adder->format = GST_ADDER_FORMAT_INT;
|
|
|
|
gst_structure_get_int (structure, "width", &adder->width);
|
|
|
|
gst_structure_get_int (structure, "depth", &adder->depth);
|
|
|
|
gst_structure_get_int (structure, "endianness", &adder->endianness);
|
|
|
|
gst_structure_get_boolean (structure, "signed", &adder->is_signed);
|
2005-05-05 09:46:03 +00:00
|
|
|
|
2009-05-18 22:03:44 +00:00
|
|
|
GST_INFO_OBJECT (pad, "parse_caps sets adder to format int, %d bit",
|
2008-12-17 08:51:34 +00:00
|
|
|
adder->width);
|
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
if (adder->endianness != G_BYTE_ORDER)
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
switch (adder->width) {
|
|
|
|
case 8:
|
|
|
|
adder->func = (adder->is_signed ?
|
|
|
|
(GstAdderFunction) add_int8 : (GstAdderFunction) add_uint8);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
adder->func = (adder->is_signed ?
|
|
|
|
(GstAdderFunction) add_int16 : (GstAdderFunction) add_uint16);
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
adder->func = (adder->is_signed ?
|
|
|
|
(GstAdderFunction) add_int32 : (GstAdderFunction) add_uint32);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto not_supported;
|
|
|
|
}
|
2004-01-27 09:00:01 +00:00
|
|
|
} else if (strcmp (media_type, "audio/x-raw-float") == 0) {
|
2004-03-14 22:34:34 +00:00
|
|
|
adder->format = GST_ADDER_FORMAT_FLOAT;
|
|
|
|
gst_structure_get_int (structure, "width", &adder->width);
|
2008-05-14 10:58:52 +00:00
|
|
|
gst_structure_get_int (structure, "endianness", &adder->endianness);
|
|
|
|
|
2009-05-18 22:03:44 +00:00
|
|
|
GST_INFO_OBJECT (pad, "parse_caps sets adder to format float, %d bit",
|
2008-12-17 08:51:34 +00:00
|
|
|
adder->width);
|
|
|
|
|
2008-05-14 10:58:52 +00:00
|
|
|
if (adder->endianness != G_BYTE_ORDER)
|
|
|
|
goto not_supported;
|
2005-05-05 09:46:03 +00:00
|
|
|
|
|
|
|
switch (adder->width) {
|
|
|
|
case 32:
|
|
|
|
adder->func = (GstAdderFunction) add_float32;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
adder->func = (GstAdderFunction) add_float64;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto not_supported;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto not_supported;
|
2002-02-19 05:59:06 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &adder->channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &adder->rate);
|
2006-05-10 11:54:36 +00:00
|
|
|
/* precalc bps */
|
|
|
|
adder->bps = (adder->width / 8) * adder->channels;
|
2005-05-05 09:46:03 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
2006-07-28 14:14:58 +00:00
|
|
|
/* ERRORS */
|
2005-05-05 09:46:03 +00:00
|
|
|
not_supported:
|
|
|
|
{
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "unsupported format set as caps");
|
2005-05-05 09:46:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-01-22 04:45:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, the duration query should reflect how long you will produce
|
2007-04-23 20:04:28 +00:00
|
|
|
* data, that is the amount of stream time until you will emit EOS.
|
2006-07-28 14:14:58 +00:00
|
|
|
*
|
|
|
|
* For synchronized mixing this is always the max of all the durations
|
|
|
|
* of upstream since we emit EOS when all of them finished.
|
|
|
|
*
|
2006-05-10 11:54:36 +00:00
|
|
|
* We don't do synchronized mixing so this really depends on where the
|
|
|
|
* streams where punched in and what their relative offsets are against
|
|
|
|
* eachother which we can get from the first timestamps we see.
|
2006-07-28 14:14:58 +00:00
|
|
|
*
|
2006-05-10 11:54:36 +00:00
|
|
|
* When we add a new stream (or remove a stream) the duration might
|
|
|
|
* also become invalid again and we need to post a new DURATION
|
2006-05-29 15:49:53 +00:00
|
|
|
* message to notify this fact to the parent.
|
2006-05-10 11:54:36 +00:00
|
|
|
* For now we take the max of all the upstream elements so the simple
|
2007-04-23 20:04:28 +00:00
|
|
|
* cases work at least somewhat.
|
2006-07-28 14:14:58 +00:00
|
|
|
*/
|
2006-05-10 11:54:36 +00:00
|
|
|
static gboolean
|
|
|
|
gst_adder_query_duration (GstAdder * adder, GstQuery * query)
|
|
|
|
{
|
|
|
|
gint64 max;
|
|
|
|
gboolean res;
|
|
|
|
GstFormat format;
|
2006-05-29 15:49:53 +00:00
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
/* parse format */
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
2006-05-10 11:54:36 +00:00
|
|
|
|
|
|
|
max = -1;
|
|
|
|
res = TRUE;
|
2006-05-29 15:49:53 +00:00
|
|
|
done = FALSE;
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
|
|
|
while (!done) {
|
|
|
|
GstIteratorResult ires;
|
2008-06-02 12:20:35 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
gpointer item;
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
ires = gst_iterator_next (it, &item);
|
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
|
|
|
GstPad *pad = GST_PAD_CAST (item);
|
2008-06-02 12:20:35 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
gint64 duration;
|
|
|
|
|
|
|
|
/* ask sink peer for duration */
|
|
|
|
res &= gst_pad_query_peer_duration (pad, &format, &duration);
|
|
|
|
/* take max from all valid return values */
|
|
|
|
if (res) {
|
|
|
|
/* valid unknown length, stop searching */
|
|
|
|
if (duration == -1) {
|
|
|
|
max = duration;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
/* else see if bigger than current max */
|
|
|
|
else if (duration > max)
|
|
|
|
max = duration;
|
|
|
|
}
|
2008-06-02 12:20:35 +00:00
|
|
|
gst_object_unref (pad);
|
2006-05-10 11:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-29 15:49:53 +00:00
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
max = -1;
|
|
|
|
res = TRUE;
|
2008-05-27 18:10:00 +00:00
|
|
|
gst_iterator_resync (it);
|
2006-05-29 15:49:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
2006-05-10 11:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-28 14:14:58 +00:00
|
|
|
gst_iterator_free (it);
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
if (res) {
|
|
|
|
/* and store the max */
|
2008-05-28 08:14:47 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "Total duration in format %s: %"
|
|
|
|
GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (max));
|
2006-05-29 15:49:53 +00:00
|
|
|
gst_query_set_duration (query, format, max);
|
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-05-28 08:14:47 +00:00
|
|
|
static gboolean
|
|
|
|
gst_adder_query_latency (GstAdder * adder, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstClockTime min, max;
|
|
|
|
gboolean live;
|
|
|
|
gboolean res;
|
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
done = FALSE;
|
|
|
|
|
|
|
|
live = FALSE;
|
|
|
|
min = 0;
|
|
|
|
max = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
/* Take maximum of all latency values */
|
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
|
|
|
while (!done) {
|
|
|
|
GstIteratorResult ires;
|
2008-06-02 12:20:35 +00:00
|
|
|
|
2008-05-28 08:14:47 +00:00
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
ires = gst_iterator_next (it, &item);
|
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
|
|
|
GstPad *pad = GST_PAD_CAST (item);
|
|
|
|
GstQuery *peerquery;
|
|
|
|
GstClockTime min_cur, max_cur;
|
|
|
|
gboolean live_cur;
|
|
|
|
|
|
|
|
peerquery = gst_query_new_latency ();
|
|
|
|
|
|
|
|
/* Ask peer for latency */
|
|
|
|
res &= gst_pad_peer_query (pad, peerquery);
|
|
|
|
|
|
|
|
/* take max from all valid return values */
|
|
|
|
if (res) {
|
|
|
|
gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
|
|
|
|
|
|
|
|
if (min_cur > min)
|
|
|
|
min = min_cur;
|
|
|
|
|
|
|
|
if (max_cur != GST_CLOCK_TIME_NONE &&
|
|
|
|
((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
|
|
|
|
(max == GST_CLOCK_TIME_NONE)))
|
|
|
|
max = max_cur;
|
|
|
|
|
|
|
|
live = live || live_cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_unref (peerquery);
|
2008-06-02 12:20:35 +00:00
|
|
|
gst_object_unref (pad);
|
2008-05-28 08:14:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
live = FALSE;
|
|
|
|
min = 0;
|
|
|
|
max = GST_CLOCK_TIME_NONE;
|
|
|
|
res = TRUE;
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_iterator_free (it);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
/* store the results */
|
|
|
|
GST_DEBUG_OBJECT (adder, "Calculated total latency: live %s, min %"
|
|
|
|
GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
|
|
|
|
(live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
|
|
|
|
gst_query_set_latency (query, live, min, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-10-09 08:56:54 +00:00
|
|
|
static gboolean
|
|
|
|
gst_adder_query (GstPad * pad, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (gst_pad_get_parent (pad));
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
Query API update.
Original commit message from CVS:
* examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline),
(query_positions_elems), (query_positions_pads), (update_scale),
(do_seek), (set_update_scale), (message_received), (main):
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_src_query),
(gst_ogg_demux_perform_seek), (gst_ogg_demux_find_chains),
(gst_ogg_demux_loop):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_sink_query):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_dec_sink_event):
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_query),
(vorbis_dec_sink_event), (vorbis_handle_data_packet):
* gst/adder/gstadder.c: (gst_adder_query):
* gst/audiotestsrc/gstaudiotestsrc.c: (gst_audiotestsrc_src_query):
* gst/playback/test3.c: (update_scale):
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
(dump_element_stats), (main):
* gst/playback/test6.c: (main):
* gst/sine/gstsinesrc.c: (gst_sinesrc_src_query):
Query API update.
2005-10-19 15:55:33 +00:00
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, bring to stream time, might be tricky */
|
|
|
|
gst_query_set_position (query, format, adder->timestamp);
|
Query API update.
Original commit message from CVS:
* examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline),
(query_positions_elems), (query_positions_pads), (update_scale),
(do_seek), (set_update_scale), (message_received), (main):
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_src_query),
(gst_ogg_demux_perform_seek), (gst_ogg_demux_find_chains),
(gst_ogg_demux_loop):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_sink_query):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_dec_sink_event):
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_query),
(vorbis_dec_sink_event), (vorbis_handle_data_packet):
* gst/adder/gstadder.c: (gst_adder_query):
* gst/audiotestsrc/gstaudiotestsrc.c: (gst_audiotestsrc_src_query):
* gst/playback/test3.c: (update_scale):
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
(dump_element_stats), (main):
* gst/playback/test6.c: (main):
* gst/sine/gstsinesrc.c: (gst_sinesrc_src_query):
Query API update.
2005-10-19 15:55:33 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
2006-05-10 11:54:36 +00:00
|
|
|
gst_query_set_position (query, format, adder->offset);
|
Query API update.
Original commit message from CVS:
* examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline),
(query_positions_elems), (query_positions_pads), (update_scale),
(do_seek), (set_update_scale), (message_received), (main):
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_src_query),
(gst_ogg_demux_perform_seek), (gst_ogg_demux_find_chains),
(gst_ogg_demux_loop):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_sink_query):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_dec_sink_event):
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_query),
(vorbis_dec_sink_event), (vorbis_handle_data_packet):
* gst/adder/gstadder.c: (gst_adder_query):
* gst/audiotestsrc/gstaudiotestsrc.c: (gst_audiotestsrc_src_query):
* gst/playback/test3.c: (update_scale):
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
(dump_element_stats), (main):
* gst/playback/test6.c: (main):
* gst/sine/gstsinesrc.c: (gst_sinesrc_src_query):
Query API update.
2005-10-19 15:55:33 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-10-09 08:56:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
Query API update.
Original commit message from CVS:
* examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline),
(query_positions_elems), (query_positions_pads), (update_scale),
(do_seek), (set_update_scale), (message_received), (main):
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_src_query),
(gst_ogg_demux_perform_seek), (gst_ogg_demux_find_chains),
(gst_ogg_demux_loop):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_sink_query):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_dec_sink_event):
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_query),
(vorbis_dec_sink_event), (vorbis_handle_data_packet):
* gst/adder/gstadder.c: (gst_adder_query):
* gst/audiotestsrc/gstaudiotestsrc.c: (gst_audiotestsrc_src_query):
* gst/playback/test3.c: (update_scale):
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
(dump_element_stats), (main):
* gst/playback/test6.c: (main):
* gst/sine/gstsinesrc.c: (gst_sinesrc_src_query):
Query API update.
2005-10-19 15:55:33 +00:00
|
|
|
case GST_QUERY_DURATION:
|
2006-05-10 11:54:36 +00:00
|
|
|
res = gst_adder_query_duration (adder, query);
|
Query API update.
Original commit message from CVS:
* examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline),
(query_positions_elems), (query_positions_pads), (update_scale),
(do_seek), (set_update_scale), (message_received), (main):
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_src_query),
(gst_ogg_demux_perform_seek), (gst_ogg_demux_find_chains),
(gst_ogg_demux_loop):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_sink_query):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_dec_sink_event):
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_query),
(vorbis_dec_sink_event), (vorbis_handle_data_packet):
* gst/adder/gstadder.c: (gst_adder_query):
* gst/audiotestsrc/gstaudiotestsrc.c: (gst_audiotestsrc_src_query):
* gst/playback/test3.c: (update_scale):
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
(dump_element_stats), (main):
* gst/playback/test6.c: (main):
* gst/sine/gstsinesrc.c: (gst_sinesrc_src_query):
Query API update.
2005-10-19 15:55:33 +00:00
|
|
|
break;
|
2008-05-28 08:14:47 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
res = gst_adder_query_latency (adder, query);
|
|
|
|
break;
|
2005-10-09 08:56:54 +00:00
|
|
|
default:
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, needs a custom query handler because we have multiple
|
|
|
|
* sinkpads */
|
2006-02-01 11:56:11 +00:00
|
|
|
res = gst_pad_query_default (pad, query);
|
2005-10-09 08:56:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (adder);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-06-23 16:07:31 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
gboolean flush;
|
|
|
|
} EventData;
|
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
static gboolean
|
2009-06-23 16:07:31 +00:00
|
|
|
forward_event_func (GstPad * pad, GValue * ret, EventData * data)
|
2006-05-29 15:49:53 +00:00
|
|
|
{
|
2009-06-23 16:07:31 +00:00
|
|
|
GstEvent *event = data->event;
|
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
gst_event_ref (event);
|
2006-08-31 12:39:17 +00:00
|
|
|
GST_LOG_OBJECT (pad, "About to send event %s", GST_EVENT_TYPE_NAME (event));
|
2006-05-29 15:49:53 +00:00
|
|
|
if (!gst_pad_push_event (pad, event)) {
|
|
|
|
g_value_set_boolean (ret, FALSE);
|
|
|
|
GST_WARNING_OBJECT (pad, "Sending event %p (%s) failed.",
|
|
|
|
event, GST_EVENT_TYPE_NAME (event));
|
2009-06-23 16:07:31 +00:00
|
|
|
/* quick hack to unflush the pads, ideally we need a way to just unflush
|
|
|
|
* this single collect pad */
|
|
|
|
if (data->flush)
|
|
|
|
gst_pad_send_event (pad, gst_event_new_flush_stop ());
|
2006-05-29 15:49:53 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (pad, "Sent event %p (%s).",
|
|
|
|
event, GST_EVENT_TYPE_NAME (event));
|
|
|
|
}
|
|
|
|
gst_object_unref (pad);
|
2009-06-23 16:07:31 +00:00
|
|
|
|
2009-05-18 22:11:45 +00:00
|
|
|
/* continue on other pads, even if one failed */
|
2006-05-29 15:49:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
/* forwards the event to all sinkpads, takes ownership of the
|
2006-05-10 11:54:36 +00:00
|
|
|
* event
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the event could be forwarded on all
|
|
|
|
* sinkpads.
|
|
|
|
*/
|
2006-04-28 19:17:06 +00:00
|
|
|
static gboolean
|
2009-06-23 16:07:31 +00:00
|
|
|
forward_event (GstAdder * adder, GstEvent * event, gboolean flush)
|
2006-04-28 19:17:06 +00:00
|
|
|
{
|
2006-05-10 11:54:36 +00:00
|
|
|
gboolean ret;
|
2006-05-29 15:49:53 +00:00
|
|
|
GstIterator *it;
|
2009-05-18 22:11:45 +00:00
|
|
|
GstIteratorResult ires;
|
2006-05-29 15:49:53 +00:00
|
|
|
GValue vret = { 0 };
|
2009-06-23 16:07:31 +00:00
|
|
|
EventData data;
|
2006-04-28 19:17:06 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_LOG_OBJECT (adder, "Forwarding event %p (%s)", event,
|
2006-04-28 19:17:06 +00:00
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
2009-06-23 16:07:31 +00:00
|
|
|
data.event = event;
|
|
|
|
data.flush = flush;
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2006-05-29 15:49:53 +00:00
|
|
|
g_value_init (&vret, G_TYPE_BOOLEAN);
|
|
|
|
g_value_set_boolean (&vret, TRUE);
|
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
2009-05-18 22:11:45 +00:00
|
|
|
while (TRUE) {
|
|
|
|
ires = gst_iterator_fold (it, (GstIteratorFoldFunction) forward_event_func,
|
2009-06-23 16:07:31 +00:00
|
|
|
&vret, &data);
|
2009-05-18 22:11:45 +00:00
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
GST_WARNING ("resync");
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
g_value_set_boolean (&vret, TRUE);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
ret = g_value_get_boolean (&vret);
|
|
|
|
goto done;
|
|
|
|
default:
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
2006-05-29 15:49:53 +00:00
|
|
|
gst_iterator_free (it);
|
2009-05-18 22:11:45 +00:00
|
|
|
GST_LOG_OBJECT (adder, "Forwarded event %p (%s), ret=%d", event,
|
|
|
|
GST_EVENT_TYPE_NAME (event), ret);
|
2006-05-10 11:54:36 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_adder_src_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstAdder *adder;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
adder = GST_ADDER (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2006-05-29 15:49:53 +00:00
|
|
|
{
|
|
|
|
GstSeekFlags flags;
|
2006-08-31 12:39:17 +00:00
|
|
|
GstSeekType curtype;
|
2006-08-31 14:37:33 +00:00
|
|
|
gint64 cur;
|
2009-06-17 09:22:51 +00:00
|
|
|
gboolean flush;
|
2006-05-29 15:49:53 +00:00
|
|
|
|
gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected, gst_adder_change_state): gst/adder/gstadder.h (bps, o...
Original commit message from CVS:
* gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected,
gst_adder_change_state):
* gst/adder/gstadder.h (bps, offset, collect_event, segment,
segment_pending, segment_position, segment_rate):
Handle playback-rate on adder.
2007-05-08 19:24:01 +00:00
|
|
|
/* parse the seek parameters */
|
|
|
|
gst_event_parse_seek (event, &adder->segment_rate, NULL, &flags, &curtype,
|
|
|
|
&cur, NULL, NULL);
|
2006-05-29 15:49:53 +00:00
|
|
|
|
2009-06-17 09:22:51 +00:00
|
|
|
flush = (flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
/* check if we are flushing */
|
2009-06-17 09:22:51 +00:00
|
|
|
if (flush) {
|
2007-04-23 20:04:28 +00:00
|
|
|
/* make sure we accept nothing anymore and return WRONG_STATE */
|
|
|
|
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
2006-05-29 15:49:53 +00:00
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
/* flushing seek, start flush downstream, the flush will be done
|
|
|
|
* when all pads received a FLUSH_STOP. */
|
|
|
|
gst_pad_push_event (adder->srcpad, gst_event_new_flush_start ());
|
|
|
|
}
|
2009-05-18 22:13:34 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "handling seek event: %" GST_PTR_FORMAT, event);
|
2009-06-17 09:22:51 +00:00
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
/* now wait for the collected to be finished and mark a new
|
2009-06-17 09:22:51 +00:00
|
|
|
* segment. After we have the lock, no collect function is running and no
|
|
|
|
* new collect function will be called for as long as we're flushing. */
|
2006-05-29 15:49:53 +00:00
|
|
|
GST_OBJECT_LOCK (adder->collect);
|
2006-08-31 12:39:17 +00:00
|
|
|
if (curtype == GST_SEEK_TYPE_SET)
|
|
|
|
adder->segment_position = cur;
|
|
|
|
else
|
|
|
|
adder->segment_position = 0;
|
2009-07-06 21:31:12 +00:00
|
|
|
/* make sure we push a new segment, to inform about new basetime
|
|
|
|
* see FIXME in gst_adder_collected() */
|
|
|
|
adder->segment_pending = TRUE;
|
2009-07-05 19:29:40 +00:00
|
|
|
if (flush) {
|
|
|
|
/* Yes, we need to call _set_flushing again *WHEN* the streaming threads
|
|
|
|
* have stopped so that the cookie gets properly updated. */
|
|
|
|
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
|
|
|
}
|
2009-06-17 09:22:51 +00:00
|
|
|
/* we might have a pending flush_stop event now. This event will either be
|
|
|
|
* sent by an upstream element when it completes the seek or we will push
|
|
|
|
* one in the collected callback ourself */
|
|
|
|
adder->flush_stop_pending = flush;
|
2006-05-29 15:49:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder->collect);
|
2009-05-18 22:13:34 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "forwarding seek event: %" GST_PTR_FORMAT,
|
|
|
|
event);
|
2006-05-29 15:49:53 +00:00
|
|
|
|
2009-06-23 16:07:31 +00:00
|
|
|
result = forward_event (adder, event, flush);
|
2009-06-15 08:40:00 +00:00
|
|
|
if (!result) {
|
2009-06-17 09:22:51 +00:00
|
|
|
/* seek failed. maybe source is a live source. */
|
|
|
|
GST_DEBUG_OBJECT (adder, "seeking failed");
|
2009-05-19 15:41:02 +00:00
|
|
|
}
|
2009-06-17 09:22:51 +00:00
|
|
|
/* FIXME: ideally we would like to send a flush-stop event from here but
|
|
|
|
* collectpads does not have a method that allows us to do that. Instead
|
|
|
|
* we forward all flush-stop events we receive on the sinkpads. We might
|
|
|
|
* be sending too many flush-stop events. */
|
2006-05-10 11:54:36 +00:00
|
|
|
break;
|
2006-05-29 15:49:53 +00:00
|
|
|
}
|
2009-05-18 22:13:34 +00:00
|
|
|
case GST_EVENT_QOS:
|
|
|
|
/* QoS might be tricky */
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
2006-05-10 11:54:36 +00:00
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
/* navigation is rather pointless. */
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* just forward the rest for now */
|
2009-05-18 22:13:34 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "forward unhandled event: %s",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
2009-06-23 16:07:31 +00:00
|
|
|
result = forward_event (adder, event, FALSE);
|
2006-05-10 11:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-28 19:17:06 +00:00
|
|
|
gst_object_unref (adder);
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2006-04-28 19:17:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
static gboolean
|
|
|
|
gst_adder_sink_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstAdder *adder;
|
2009-07-13 07:28:54 +00:00
|
|
|
gboolean ret = TRUE;
|
2006-05-10 11:54:36 +00:00
|
|
|
|
|
|
|
adder = GST_ADDER (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
GST_DEBUG ("Got %s event on pad %s:%s", GST_EVENT_TYPE_NAME (event),
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2009-06-17 09:22:51 +00:00
|
|
|
/* we received a flush-stop. The collect_event function will push the
|
|
|
|
* event past our element. We simply forward all flush-stop events, even
|
|
|
|
* when no flush-stop was pendingk, this is required because collectpads
|
|
|
|
* does not provide an API to handle-but-not-forward the flush-stop.
|
|
|
|
* We unset the pending flush-stop flag so that we don't send anymore
|
|
|
|
* flush-stop from the collect function later.
|
2006-05-10 11:54:36 +00:00
|
|
|
*/
|
2009-06-17 09:22:51 +00:00
|
|
|
GST_OBJECT_LOCK (adder->collect);
|
2006-05-10 11:54:36 +00:00
|
|
|
adder->segment_pending = TRUE;
|
2009-05-19 13:45:56 +00:00
|
|
|
adder->flush_stop_pending = FALSE;
|
2009-07-20 08:53:11 +00:00
|
|
|
/* Clear pending tags */
|
|
|
|
if (adder->pending_events) {
|
|
|
|
g_list_foreach (adder->pending_events, (GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (adder->pending_events);
|
|
|
|
adder->pending_events = NULL;
|
|
|
|
}
|
2009-06-17 09:22:51 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder->collect);
|
2006-05-10 11:54:36 +00:00
|
|
|
break;
|
2009-07-13 07:28:54 +00:00
|
|
|
case GST_EVENT_TAG:
|
|
|
|
GST_OBJECT_LOCK (adder->collect);
|
|
|
|
/* collectpads is a pile of horse manure. */
|
|
|
|
adder->pending_events = g_list_append (adder->pending_events, event);
|
|
|
|
GST_OBJECT_UNLOCK (adder->collect);
|
|
|
|
goto beach;
|
2006-05-10 11:54:36 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now GstCollectPads can take care of the rest, e.g. EOS */
|
|
|
|
ret = adder->collect_event (pad, event);
|
|
|
|
|
2009-07-13 07:28:54 +00:00
|
|
|
beach:
|
2006-05-10 11:54:36 +00:00
|
|
|
gst_object_unref (adder);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_adder_class_init (GstAdderClass * klass)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
2008-08-01 13:06:59 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2005-11-16 18:21:46 +00:00
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_adder_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_adder_get_property);
|
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_adder_dispose);
|
2005-11-16 18:21:46 +00:00
|
|
|
|
2003-11-01 01:10:23 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&gst_adder_src_template));
|
2003-11-01 01:10:23 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&gst_adder_sink_template));
|
2008-05-14 10:58:52 +00:00
|
|
|
gst_element_class_set_details_simple (gstelement_class, "Adder",
|
|
|
|
"Generic/Audio",
|
2008-11-10 13:55:08 +00:00
|
|
|
"Add N audio channels together",
|
|
|
|
"Thomas Vander Stichele <thomas at apestaart dot org>");
|
2003-11-01 01:10:23 +00:00
|
|
|
|
2005-10-09 08:56:54 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2002-09-09 09:26:23 +00:00
|
|
|
|
2009-07-10 22:24:36 +00:00
|
|
|
/**
|
|
|
|
* GstAdder:caps:
|
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
2009-07-10 19:06:28 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FILTER_CAPS,
|
2009-07-10 22:24:36 +00:00
|
|
|
g_param_spec_boxed ("caps", "Target caps",
|
|
|
|
"Set target format for mixing (NULL means ANY). "
|
2009-07-10 19:06:28 +00:00
|
|
|
"Setting this property takes a reference to the supplied GstCaps "
|
|
|
|
"object.", GST_TYPE_CAPS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2008-06-29 13:45:27 +00:00
|
|
|
gstelement_class->request_new_pad =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_request_new_pad);
|
|
|
|
gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_adder_release_pad);
|
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_adder_change_state);
|
2001-12-22 22:43:48 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void
|
|
|
|
gst_adder_init (GstAdder * adder)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
2006-03-09 15:05:03 +00:00
|
|
|
GstPadTemplate *template;
|
|
|
|
|
|
|
|
template = gst_static_pad_template_get (&gst_adder_src_template);
|
|
|
|
adder->srcpad = gst_pad_new_from_template (template, "src");
|
|
|
|
gst_object_unref (template);
|
2008-06-29 13:45:27 +00:00
|
|
|
|
2005-10-09 08:56:54 +00:00
|
|
|
gst_pad_set_getcaps_function (adder->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
|
|
|
gst_pad_set_setcaps_function (adder->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_setcaps));
|
|
|
|
gst_pad_set_query_function (adder->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_query));
|
2006-04-28 19:17:06 +00:00
|
|
|
gst_pad_set_event_function (adder->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_src_event));
|
2005-05-05 09:46:03 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (adder), adder->srcpad);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2002-01-22 04:45:10 +00:00
|
|
|
adder->format = GST_ADDER_FORMAT_UNSET;
|
2006-05-30 16:07:50 +00:00
|
|
|
adder->padcount = 0;
|
2005-05-05 09:46:03 +00:00
|
|
|
adder->func = NULL;
|
2002-01-22 04:45:10 +00:00
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
adder->filter_caps = gst_caps_new_any ();
|
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
/* keep track of the sinkpads requested */
|
2005-11-21 11:54:16 +00:00
|
|
|
adder->collect = gst_collect_pads_new ();
|
2006-03-24 17:11:53 +00:00
|
|
|
gst_collect_pads_set_function (adder->collect,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_collected), adder);
|
2001-12-22 22:43:48 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 18:21:46 +00:00
|
|
|
static void
|
2009-07-10 19:06:28 +00:00
|
|
|
gst_adder_dispose (GObject * object)
|
2005-11-16 18:21:46 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (object);
|
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
if (adder->collect) {
|
|
|
|
gst_object_unref (adder->collect);
|
|
|
|
adder->collect = NULL;
|
|
|
|
}
|
|
|
|
gst_caps_replace (&adder->filter_caps, NULL);
|
2009-07-20 08:53:11 +00:00
|
|
|
if (adder->pending_events) {
|
|
|
|
g_list_foreach (adder->pending_events, (GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (adder->pending_events);
|
|
|
|
adder->pending_events = NULL;
|
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2005-11-16 18:21:46 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
static void
|
|
|
|
gst_adder_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_FILTER_CAPS:{
|
|
|
|
GstCaps *new_caps;
|
|
|
|
GstCaps *old_caps;
|
|
|
|
const GstCaps *new_caps_val = gst_value_get_caps (value);
|
|
|
|
|
|
|
|
if (new_caps_val == NULL) {
|
|
|
|
new_caps = gst_caps_new_any ();
|
|
|
|
} else {
|
|
|
|
new_caps = (GstCaps *) new_caps_val;
|
|
|
|
gst_caps_ref (new_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
old_caps = adder->filter_caps;
|
|
|
|
adder->filter_caps = new_caps;
|
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
|
|
|
|
gst_caps_unref (old_caps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (adder, "set new caps %" GST_PTR_FORMAT, new_caps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_FILTER_CAPS:
|
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
gst_value_set_caps (value, adder->filter_caps);
|
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstPad *
|
|
|
|
gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ,
|
|
|
|
const gchar * unused)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
gchar *name;
|
|
|
|
GstAdder *adder;
|
2005-05-05 09:46:03 +00:00
|
|
|
GstPad *newpad;
|
2006-05-30 16:07:50 +00:00
|
|
|
gint padcount;
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
if (templ->direction != GST_PAD_SINK)
|
|
|
|
goto not_sink;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-01-22 04:45:10 +00:00
|
|
|
adder = GST_ADDER (element);
|
|
|
|
|
2006-05-30 16:07:50 +00:00
|
|
|
/* increment pad counter */
|
|
|
|
padcount = g_atomic_int_exchange_and_add (&adder->padcount, 1);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("sink%d", padcount);
|
2005-05-05 09:46:03 +00:00
|
|
|
newpad = gst_pad_new_from_template (templ, name);
|
2006-05-30 16:07:50 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "request new pad %s", name);
|
2006-05-29 17:19:48 +00:00
|
|
|
g_free (name);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2005-10-09 08:56:54 +00:00
|
|
|
gst_pad_set_getcaps_function (newpad,
|
2007-07-03 11:52:47 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_sink_getcaps));
|
2005-10-09 08:56:54 +00:00
|
|
|
gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_setcaps));
|
2005-11-21 11:54:16 +00:00
|
|
|
gst_collect_pads_add_pad (adder->collect, newpad, sizeof (GstCollectData));
|
2006-05-07 16:39:36 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME: hacked way to override/extend the event function of
|
|
|
|
* GstCollectPads; because it sets its own event function giving the
|
|
|
|
* element no access to events */
|
|
|
|
adder->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (newpad);
|
|
|
|
gst_pad_set_event_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_sink_event));
|
|
|
|
|
2006-05-30 16:07:50 +00:00
|
|
|
/* takes ownership of the pad */
|
2005-05-05 09:46:03 +00:00
|
|
|
if (!gst_element_add_pad (GST_ELEMENT (adder), newpad))
|
|
|
|
goto could_not_add;
|
2002-01-22 04:45:10 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
return newpad;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
/* errors */
|
|
|
|
not_sink:
|
|
|
|
{
|
|
|
|
g_warning ("gstadder: request new pad that is not a SINK pad\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
could_not_add:
|
|
|
|
{
|
2006-05-30 16:07:50 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "could not add pad");
|
2005-11-21 11:54:16 +00:00
|
|
|
gst_collect_pads_remove_pad (adder->collect, newpad);
|
2005-06-28 10:16:13 +00:00
|
|
|
gst_object_unref (newpad);
|
2005-05-05 09:46:03 +00:00
|
|
|
return NULL;
|
2001-12-22 22:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-30 16:07:50 +00:00
|
|
|
static void
|
|
|
|
gst_adder_release_pad (GstElement * element, GstPad * pad)
|
|
|
|
{
|
|
|
|
GstAdder *adder;
|
|
|
|
|
|
|
|
adder = GST_ADDER (element);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (adder, "release pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
gst_collect_pads_remove_pad (adder->collect, pad);
|
|
|
|
gst_element_remove_pad (element, pad);
|
|
|
|
}
|
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_adder_collected (GstCollectPads * pads, gpointer user_data)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
|
|
|
/*
|
2008-12-17 08:51:34 +00:00
|
|
|
* combine streams by adding data values
|
2001-12-22 22:43:48 +00:00
|
|
|
* basic algorithm :
|
2005-05-05 09:46:03 +00:00
|
|
|
* - this function is called when all pads have a buffer
|
|
|
|
* - get available bytes on all pads.
|
|
|
|
* - repeat for each input pad :
|
|
|
|
* - read available bytes, copy or add to target buffer
|
2002-01-22 04:45:10 +00:00
|
|
|
* - if there's an EOS event, remove the input channel
|
2001-12-22 22:43:48 +00:00
|
|
|
* - push out the output buffer
|
2008-12-17 08:51:34 +00:00
|
|
|
*
|
|
|
|
* todo:
|
|
|
|
* - would be nice to have a mixing mode, where instead of adding we mix
|
|
|
|
* - for float we could downscale after collect loop
|
|
|
|
* - for int we need to downscale each input to avoid clipping or
|
|
|
|
* mix into a temp (float) buffer and scale afterwards as well
|
2001-12-22 22:43:48 +00:00
|
|
|
*/
|
2004-03-14 22:34:34 +00:00
|
|
|
GstAdder *adder;
|
2005-05-05 09:46:03 +00:00
|
|
|
GSList *collected;
|
|
|
|
GstFlowReturn ret;
|
2008-12-17 08:51:34 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
gpointer outdata = NULL;
|
|
|
|
guint outsize;
|
2008-02-18 13:51:34 +00:00
|
|
|
gboolean empty = TRUE;
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
adder = GST_ADDER (user_data);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* this is fatal */
|
|
|
|
if (G_UNLIKELY (adder->func == NULL))
|
|
|
|
goto not_negotiated;
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2009-06-12 14:31:00 +00:00
|
|
|
if (adder->flush_stop_pending) {
|
|
|
|
gst_pad_push_event (adder->srcpad, gst_event_new_flush_stop ());
|
|
|
|
adder->flush_stop_pending = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-17 08:51:34 +00:00
|
|
|
/* get available bytes for reading, this can be 0 which could mean empty
|
|
|
|
* buffers or EOS, which we will catch when we loop over the pads. */
|
|
|
|
outsize = gst_collect_pads_available (pads);
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2005-08-24 18:40:27 +00:00
|
|
|
GST_LOG_OBJECT (adder,
|
2008-12-17 08:51:34 +00:00
|
|
|
"starting to cycle through channels, %d bytes available (bps = %d)",
|
|
|
|
outsize, adder->bps);
|
2003-07-19 23:16:25 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
for (collected = pads->data; collected; collected = g_slist_next (collected)) {
|
2008-12-17 08:51:34 +00:00
|
|
|
GstCollectData *collect_data;
|
2008-02-18 13:51:34 +00:00
|
|
|
GstBuffer *inbuf;
|
2008-12-17 08:51:34 +00:00
|
|
|
guint8 *indata;
|
|
|
|
guint insize;
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data = (GstCollectData *) collected->data;
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2008-02-18 13:51:34 +00:00
|
|
|
/* get a subbuffer of size bytes */
|
2008-12-17 08:51:34 +00:00
|
|
|
inbuf = gst_collect_pads_take_buffer (pads, collect_data, outsize);
|
2008-02-18 13:51:34 +00:00
|
|
|
/* NULL means EOS or an empty buffer so we still need to flush in
|
2006-05-10 11:54:36 +00:00
|
|
|
* case of an empty buffer. */
|
2008-02-18 13:51:34 +00:00
|
|
|
if (inbuf == NULL) {
|
2008-12-17 08:51:34 +00:00
|
|
|
GST_LOG_OBJECT (adder, "channel %p: no bytes available", collect_data);
|
|
|
|
continue;
|
2006-05-10 11:54:36 +00:00
|
|
|
}
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2008-12-17 08:51:34 +00:00
|
|
|
indata = GST_BUFFER_DATA (inbuf);
|
|
|
|
insize = GST_BUFFER_SIZE (inbuf);
|
2008-02-18 13:51:34 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
if (outbuf == NULL) {
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_LOG_OBJECT (adder, "channel %p: making output buffer of %d bytes",
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data, outsize);
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2008-12-17 08:51:34 +00:00
|
|
|
/* first buffer, alloc outsize.
|
|
|
|
* FIXME: we can easily subbuffer and _make_writable.
|
|
|
|
* FIXME: only create empty buffer for first non-gap buffer, so that we
|
|
|
|
* only use adder function when really adding
|
|
|
|
*/
|
|
|
|
outbuf = gst_buffer_new_and_alloc (outsize);
|
|
|
|
outdata = GST_BUFFER_DATA (outbuf);
|
2006-05-10 11:54:36 +00:00
|
|
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (adder->srcpad));
|
|
|
|
|
2008-02-18 13:51:34 +00:00
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP)) {
|
|
|
|
GST_LOG_OBJECT (adder, "channel %p: copying %d bytes from data %p",
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data, insize, indata);
|
|
|
|
/* clear if we are only going to fill a partial buffer */
|
|
|
|
if (G_UNLIKELY (outsize > insize))
|
2009-01-30 17:16:39 +00:00
|
|
|
memset ((guint8 *) outdata + insize, 0, outsize - insize);
|
2008-02-18 13:51:34 +00:00
|
|
|
/* and copy the data into it */
|
2008-12-17 08:51:34 +00:00
|
|
|
memcpy (outdata, indata, insize);
|
2008-02-18 13:51:34 +00:00
|
|
|
empty = FALSE;
|
|
|
|
} else {
|
2008-12-17 08:51:34 +00:00
|
|
|
/* clear whole buffer */
|
2008-02-18 13:51:34 +00:00
|
|
|
GST_LOG_OBJECT (adder, "channel %p: zeroing %d bytes from data %p",
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data, insize, indata);
|
|
|
|
memset (outdata, 0, outsize);
|
2008-02-18 13:51:34 +00:00
|
|
|
}
|
2003-01-11 16:28:29 +00:00
|
|
|
} else {
|
2008-02-18 13:51:34 +00:00
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP)) {
|
|
|
|
GST_LOG_OBJECT (adder, "channel %p: mixing %d bytes from data %p",
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data, insize, indata);
|
|
|
|
/* further buffers, need to add them */
|
|
|
|
adder->func ((gpointer) outdata, (gpointer) indata, insize);
|
2008-02-18 13:51:34 +00:00
|
|
|
empty = FALSE;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (adder, "channel %p: skipping %d bytes from data %p",
|
2008-12-17 08:51:34 +00:00
|
|
|
collect_data, insize, indata);
|
2008-02-18 13:51:34 +00:00
|
|
|
}
|
2001-12-23 23:01:28 +00:00
|
|
|
}
|
2008-12-17 08:51:34 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
2004-06-06 23:43:15 +00:00
|
|
|
}
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* can only happen when no pads to collect or all EOS */
|
|
|
|
if (outbuf == NULL)
|
|
|
|
goto eos;
|
|
|
|
|
2007-04-23 20:04:28 +00:00
|
|
|
/* our timestamping is very simple, just an ever incrementing
|
2006-05-10 11:54:36 +00:00
|
|
|
* counter, the new segment time will take care of their respective
|
|
|
|
* stream time. */
|
2006-05-09 16:14:49 +00:00
|
|
|
if (adder->segment_pending) {
|
|
|
|
GstEvent *event;
|
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, use rate/applied_rate as set on all sinkpads.
|
gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected, gst_adder_change_state): gst/adder/gstadder.h (bps, o...
Original commit message from CVS:
* gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected,
gst_adder_change_state):
* gst/adder/gstadder.h (bps, offset, collect_event, segment,
segment_pending, segment_position, segment_rate):
Handle playback-rate on adder.
2007-05-08 19:24:01 +00:00
|
|
|
* - currently we just set rate as received from last seek-event
|
2006-05-10 11:54:36 +00:00
|
|
|
* We could potentially figure out the duration as well using
|
|
|
|
* the current segment positions and the stated stop positions.
|
|
|
|
* Also we just start from stream time 0 which is rather
|
|
|
|
* weird. For non-synchronized mixing, the time should be
|
|
|
|
* the min of the stream times of all received segments,
|
|
|
|
* rationale being that the duration is at least going to
|
|
|
|
* be as long as the earliest stream we start mixing. This
|
|
|
|
* would also be correct for synchronized mixing but then
|
|
|
|
* the later streams would be delayed until the stream times
|
|
|
|
* match.
|
|
|
|
*/
|
gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected, gst_adder_change_state): gst/adder/gstadder.h (bps, o...
Original commit message from CVS:
* gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected,
gst_adder_change_state):
* gst/adder/gstadder.h (bps, offset, collect_event, segment,
segment_pending, segment_position, segment_rate):
Handle playback-rate on adder.
2007-05-08 19:24:01 +00:00
|
|
|
event = gst_event_new_new_segment_full (FALSE, adder->segment_rate,
|
2006-08-31 12:39:17 +00:00
|
|
|
1.0, GST_FORMAT_TIME, adder->timestamp, -1, adder->segment_position);
|
2006-05-09 16:14:49 +00:00
|
|
|
|
2009-05-18 22:13:34 +00:00
|
|
|
if (event) {
|
|
|
|
if (!gst_pad_push_event (adder->srcpad, event)) {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Sending event %p (%s) failed.",
|
|
|
|
event, GST_EVENT_TYPE_NAME (event));
|
|
|
|
}
|
|
|
|
adder->segment_pending = FALSE;
|
|
|
|
adder->segment_position = 0;
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Creating new segment event for "
|
|
|
|
"start:%" G_GINT64_FORMAT " pos:%" G_GINT64_FORMAT " failed",
|
|
|
|
adder->timestamp, adder->segment_position);
|
|
|
|
}
|
2006-05-09 16:14:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 07:28:54 +00:00
|
|
|
if (G_UNLIKELY (adder->pending_events)) {
|
|
|
|
GList *tmp = adder->pending_events;
|
|
|
|
|
|
|
|
while (tmp) {
|
|
|
|
GstEvent *ev = (GstEvent *) tmp->data;
|
|
|
|
|
|
|
|
gst_pad_push_event (adder->srcpad, ev);
|
|
|
|
tmp = g_list_next (tmp);
|
|
|
|
}
|
|
|
|
g_list_free (adder->pending_events);
|
|
|
|
adder->pending_events = NULL;
|
|
|
|
}
|
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
/* set timestamps on the output buffer */
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = adder->timestamp;
|
|
|
|
GST_BUFFER_OFFSET (outbuf) = adder->offset;
|
2005-05-05 09:46:03 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* for the next timestamp, use the sample counter, which will
|
|
|
|
* never accumulate rounding errors */
|
2008-12-17 08:51:34 +00:00
|
|
|
adder->offset += outsize / adder->bps;
|
2006-05-10 11:54:36 +00:00
|
|
|
adder->timestamp = gst_util_uint64_scale_int (adder->offset,
|
|
|
|
GST_SECOND, adder->rate);
|
2005-05-05 09:46:03 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* now we can set the duration of the buffer */
|
|
|
|
GST_BUFFER_DURATION (outbuf) = adder->timestamp -
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf);
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2008-02-18 13:51:34 +00:00
|
|
|
/* if we only processed silence, mark output again as silence */
|
|
|
|
if (empty)
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
|
|
|
|
|
2003-01-11 16:28:29 +00:00
|
|
|
/* send it out */
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_LOG_OBJECT (adder, "pushing outbuf, timestamp %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
|
2005-05-05 09:46:03 +00:00
|
|
|
ret = gst_pad_push (adder->srcpad, outbuf);
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2009-05-18 22:13:34 +00:00
|
|
|
GST_LOG_OBJECT (adder, "pushed outbuf, result = %s", gst_flow_get_name (ret));
|
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
return ret;
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
/* ERRORS */
|
|
|
|
not_negotiated:
|
|
|
|
{
|
2006-05-10 11:54:36 +00:00
|
|
|
GST_ELEMENT_ERROR (adder, STREAM, FORMAT, (NULL),
|
|
|
|
("Unknown data received, not negotiated"));
|
2005-05-05 09:46:03 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
eos:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (adder, "no data available, must be EOS");
|
|
|
|
gst_pad_push_event (adder->srcpad, gst_event_new_eos ());
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
}
|
2005-05-05 09:46:03 +00:00
|
|
|
}
|
2003-07-19 23:16:25 +00:00
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_adder_change_state (GstElement * element, GstStateChange transition)
|
2003-01-11 16:28:29 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder;
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChangeReturn ret;
|
2002-09-23 09:39:33 +00:00
|
|
|
|
2003-01-11 16:28:29 +00:00
|
|
|
adder = GST_ADDER (element);
|
2002-05-27 04:48:57 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2003-01-11 16:28:29 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2003-01-11 16:28:29 +00:00
|
|
|
adder->timestamp = 0;
|
|
|
|
adder->offset = 0;
|
2009-07-30 10:42:21 +00:00
|
|
|
adder->flush_stop_pending = FALSE;
|
2006-05-09 16:14:49 +00:00
|
|
|
adder->segment_pending = TRUE;
|
2006-08-31 12:39:17 +00:00
|
|
|
adder->segment_position = 0;
|
gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected, gst_adder_change_state): gst/adder/gstadder.h (bps, o...
Original commit message from CVS:
* gst/adder/gstadder.c (gst_adder_src_event, gst_adder_collected,
gst_adder_change_state):
* gst/adder/gstadder.h (bps, offset, collect_event, segment,
segment_pending, segment_position, segment_rate):
Handle playback-rate on adder.
2007-05-08 19:24:01 +00:00
|
|
|
adder->segment_rate = 1.0;
|
2006-05-07 16:39:36 +00:00
|
|
|
gst_segment_init (&adder->segment, GST_FORMAT_UNDEFINED);
|
2005-11-21 11:54:16 +00:00
|
|
|
gst_collect_pads_start (adder->collect);
|
2003-01-11 16:28:29 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2005-05-05 09:46:03 +00:00
|
|
|
break;
|
2005-10-27 09:54:06 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
/* need to unblock the collectpads before calling the
|
|
|
|
* parent change_state so that streaming can finish */
|
2005-11-21 11:54:16 +00:00
|
|
|
gst_collect_pads_stop (adder->collect);
|
2005-10-27 09:54:06 +00:00
|
|
|
break;
|
2005-10-09 08:56:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
2003-01-11 16:28:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-08-01 21:14:22 +00:00
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
return ret;
|
2001-12-22 22:43:48 +00:00
|
|
|
}
|
|
|
|
|
2003-07-19 23:16:25 +00:00
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
2008-12-17 08:51:34 +00:00
|
|
|
/*oil_init (); */
|
|
|
|
|
2003-11-01 01:10:23 +00:00
|
|
|
if (!gst_element_register (plugin, "adder", GST_RANK_NONE, GST_TYPE_ADDER)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-19 23:16:25 +00:00
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"adder",
|
|
|
|
"Adds multiple streams",
|
2005-10-16 13:54:44 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|