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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-12-22 22:43:48 +00:00
|
|
|
*/
|
2006-03-24 10:42:11 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-adder
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: adder
|
2006-03-24 10:42:11 +00:00
|
|
|
*
|
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.
|
|
|
|
*
|
2015-05-09 21:33:26 +00:00
|
|
|
* Check out the audiomixer element in gst-plugins-bad for a better-behaving
|
|
|
|
* audio mixing element: It will sync input streams correctly and also handle
|
|
|
|
* live inputs properly.
|
|
|
|
*
|
2017-07-14 12:40:07 +00:00
|
|
|
* Caps negotiation is inherently racy with the adder element. You can set
|
2017-07-14 12:48:53 +00:00
|
|
|
* the "caps" property to force adder to operate in a specific audio
|
2017-07-14 12:40:07 +00:00
|
|
|
* format, sample rate and channel count. In this case you may also need
|
|
|
|
* audioconvert and/or audioresample elements for each input stream before the
|
|
|
|
* adder element to make sure the input branch can produce the forced format.
|
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* ## Example launch line
|
2008-07-10 21:06:06 +00:00
|
|
|
* |[
|
2015-05-09 21:33:26 +00:00
|
|
|
* gst-launch-1.0 audiotestsrc freq=100 ! adder name=mix ! audioconvert ! autoaudiosink audiotestsrc freq=500 ! mix.
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* This pipeline produces two sine waves mixed together.
|
|
|
|
*
|
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
|
2012-01-25 11:50:44 +00:00
|
|
|
|
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 */
|
2010-06-07 06:45:58 +00:00
|
|
|
#include "gstadderorc.h"
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2013-05-30 10:46:56 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_adder_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2013-05-30 09:40:01 +00:00
|
|
|
#define DEFAULT_PAD_VOLUME (1.0)
|
|
|
|
#define DEFAULT_PAD_MUTE (FALSE)
|
|
|
|
|
2013-05-30 10:46:56 +00:00
|
|
|
/* some defines for audio processing */
|
|
|
|
/* the volume factor is a range from 0.0 to (arbitrary) VOLUME_MAX_DOUBLE = 10.0
|
|
|
|
* we map 1.0 to VOLUME_UNITY_INT*
|
|
|
|
*/
|
|
|
|
#define VOLUME_UNITY_INT8 8 /* internal int for unity 2^(8-5) */
|
|
|
|
#define VOLUME_UNITY_INT8_BIT_SHIFT 3 /* number of bits to shift for unity */
|
|
|
|
#define VOLUME_UNITY_INT16 2048 /* internal int for unity 2^(16-5) */
|
|
|
|
#define VOLUME_UNITY_INT16_BIT_SHIFT 11 /* number of bits to shift for unity */
|
|
|
|
#define VOLUME_UNITY_INT24 524288 /* internal int for unity 2^(24-5) */
|
|
|
|
#define VOLUME_UNITY_INT24_BIT_SHIFT 19 /* number of bits to shift for unity */
|
|
|
|
#define VOLUME_UNITY_INT32 134217728 /* internal int for unity 2^(32-5) */
|
|
|
|
#define VOLUME_UNITY_INT32_BIT_SHIFT 27
|
|
|
|
|
2013-05-30 09:40:01 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_PAD_0,
|
|
|
|
PROP_PAD_VOLUME,
|
|
|
|
PROP_PAD_MUTE
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstAdderPad, gst_adder_pad, GST_TYPE_PAD);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_pad_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstAdderPad *pad = GST_ADDER_PAD (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_VOLUME:
|
|
|
|
g_value_set_double (value, pad->volume);
|
|
|
|
break;
|
|
|
|
case PROP_PAD_MUTE:
|
|
|
|
g_value_set_boolean (value, pad->mute);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_pad_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstAdderPad *pad = GST_ADDER_PAD (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_VOLUME:
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
pad->volume = g_value_get_double (value);
|
2013-05-30 10:46:56 +00:00
|
|
|
pad->volume_i8 = pad->volume * VOLUME_UNITY_INT8;
|
|
|
|
pad->volume_i16 = pad->volume * VOLUME_UNITY_INT16;
|
|
|
|
pad->volume_i32 = pad->volume * VOLUME_UNITY_INT32;
|
2013-05-30 09:40:01 +00:00
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
break;
|
|
|
|
case PROP_PAD_MUTE:
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
pad->mute = g_value_get_boolean (value);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_pad_class_init (GstAdderPadClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_adder_pad_set_property;
|
|
|
|
gobject_class->get_property = gst_adder_pad_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PAD_VOLUME,
|
|
|
|
g_param_spec_double ("volume", "Volume", "Volume of this pad",
|
|
|
|
0.0, 10.0, DEFAULT_PAD_VOLUME,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PAD_MUTE,
|
|
|
|
g_param_spec_boolean ("mute", "Mute", "Mute this pad",
|
|
|
|
DEFAULT_PAD_MUTE,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_pad_init (GstAdderPad * pad)
|
|
|
|
{
|
|
|
|
pad->volume = DEFAULT_PAD_VOLUME;
|
|
|
|
pad->mute = DEFAULT_PAD_MUTE;
|
|
|
|
}
|
|
|
|
|
2009-07-10 19:06:28 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_FILTER_CAPS
|
|
|
|
};
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2008-05-14 10:58:52 +00:00
|
|
|
|
2011-09-06 10:06:39 +00:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2008-05-14 10:58:52 +00:00
|
|
|
#define CAPS \
|
2011-12-31 13:31:08 +00:00
|
|
|
GST_AUDIO_CAPS_MAKE ("{ S32LE, U32LE, S16LE, U16LE, S8, U8, F32LE, F64LE }") \
|
|
|
|
", layout = (string) { interleaved, non-interleaved }"
|
2011-09-06 10:06:39 +00:00
|
|
|
#else
|
|
|
|
#define CAPS \
|
2011-12-31 13:31:08 +00:00
|
|
|
GST_AUDIO_CAPS_MAKE ("{ S32BE, U32BE, S16BE, U16BE, S8, U8, F32BE, F64BE }") \
|
|
|
|
", layout = (string) { interleaved, non-interleaved }"
|
2011-09-06 10:06:39 +00:00
|
|
|
#endif
|
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 =
|
2011-11-04 09:48:50 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink_%u",
|
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
|
|
|
);
|
|
|
|
|
2013-05-30 16:48:19 +00:00
|
|
|
static void gst_adder_child_proxy_init (gpointer g_iface, gpointer iface_data);
|
|
|
|
|
2011-04-19 09:35:53 +00:00
|
|
|
#define gst_adder_parent_class parent_class
|
2013-05-30 16:48:19 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstAdder, gst_adder, GST_TYPE_ELEMENT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_CHILD_PROXY, gst_adder_child_proxy_init));
|
2010-09-01 07:06:09 +00:00
|
|
|
|
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
|
|
|
|
2011-06-07 08:58:27 +00:00
|
|
|
static gboolean gst_adder_setcaps (GstAdder * adder, GstPad * pad,
|
|
|
|
GstCaps * caps);
|
2011-11-16 16:25:17 +00:00
|
|
|
static gboolean gst_adder_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2013-02-13 20:08:48 +00:00
|
|
|
static gboolean gst_adder_sink_query (GstCollectPads * pads,
|
|
|
|
GstCollectData * pad, GstQuery * query, gpointer user_data);
|
2011-11-17 11:48:25 +00:00
|
|
|
static gboolean gst_adder_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2012-04-17 13:09:27 +00:00
|
|
|
static gboolean gst_adder_sink_event (GstCollectPads * pads,
|
|
|
|
GstCollectData * pad, GstEvent * event, gpointer user_data);
|
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,
|
2011-05-10 14:44:37 +00:00
|
|
|
GstPadTemplate * temp, const gchar * unused, const GstCaps * caps);
|
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
|
|
|
|
2012-04-17 13:09:27 +00:00
|
|
|
static GstFlowReturn gst_adder_do_clip (GstCollectPads * pads,
|
|
|
|
GstCollectData * data, GstBuffer * buffer, GstBuffer ** out,
|
2005-05-05 09:46:03 +00:00
|
|
|
gpointer user_data);
|
2012-04-17 13:09:27 +00:00
|
|
|
static GstFlowReturn gst_adder_collected (GstCollectPads * pads,
|
2005-05-05 09:46:03 +00:00
|
|
|
gpointer user_data);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
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 *
|
2011-05-16 08:52:59 +00:00
|
|
|
gst_adder_sink_getcaps (GstPad * pad, GstCaps * filter)
|
2007-07-03 11:52:47 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder;
|
2013-05-30 12:32:03 +00:00
|
|
|
GstCaps *result, *peercaps, *current_caps, *filter_caps;
|
2013-09-15 19:48:43 +00:00
|
|
|
GstStructure *s;
|
|
|
|
gint i, n;
|
2007-07-03 11:52:47 +00:00
|
|
|
|
|
|
|
adder = GST_ADDER (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (adder);
|
2010-01-28 16:12:34 +00:00
|
|
|
/* take filter */
|
2011-05-16 08:52:59 +00:00
|
|
|
if ((filter_caps = adder->filter_caps)) {
|
|
|
|
if (filter)
|
|
|
|
filter_caps =
|
|
|
|
gst_caps_intersect_full (filter, filter_caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
else
|
|
|
|
gst_caps_ref (filter_caps);
|
|
|
|
} else {
|
2011-11-04 21:00:43 +00:00
|
|
|
filter_caps = filter ? gst_caps_ref (filter) : NULL;
|
2011-05-16 08:52:59 +00:00
|
|
|
}
|
2010-01-28 16:12:34 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
|
2011-05-16 08:52:59 +00:00
|
|
|
if (filter_caps && gst_caps_is_empty (filter_caps)) {
|
|
|
|
GST_WARNING_OBJECT (pad, "Empty filter caps");
|
|
|
|
return filter_caps;
|
|
|
|
}
|
|
|
|
|
2007-07-03 11:52:47 +00:00
|
|
|
/* get the downstream possible caps */
|
2011-11-15 16:17:53 +00:00
|
|
|
peercaps = gst_pad_peer_query_caps (adder->srcpad, filter_caps);
|
2009-07-10 19:06:28 +00:00
|
|
|
|
2011-05-08 11:24:30 +00:00
|
|
|
/* get the allowed caps on this sinkpad */
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
current_caps =
|
|
|
|
adder->current_caps ? gst_caps_ref (adder->current_caps) : NULL;
|
|
|
|
if (current_caps == NULL) {
|
|
|
|
current_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
if (!current_caps)
|
|
|
|
current_caps = gst_caps_new_any ();
|
2011-05-08 11:24:30 +00:00
|
|
|
}
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
2011-05-08 11:24:30 +00:00
|
|
|
|
2007-07-03 11:52:47 +00:00
|
|
|
if (peercaps) {
|
|
|
|
/* if the peer has caps, intersect */
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "intersecting peer and our caps");
|
2011-05-16 08:52:59 +00:00
|
|
|
result =
|
2013-05-30 12:32:03 +00:00
|
|
|
gst_caps_intersect_full (peercaps, current_caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
2007-07-03 11:52:47 +00:00
|
|
|
gst_caps_unref (peercaps);
|
2013-05-30 12:32:03 +00:00
|
|
|
gst_caps_unref (current_caps);
|
2007-07-03 11:52:47 +00:00
|
|
|
} else {
|
|
|
|
/* the peer has no caps (or there is no peer), just use the allowed caps
|
|
|
|
* of this sinkpad. */
|
2009-08-31 19:48:01 +00:00
|
|
|
/* restrict with filter-caps if any */
|
2010-01-28 16:12:34 +00:00
|
|
|
if (filter_caps) {
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "no peer caps, using filtered caps");
|
2011-05-16 08:52:59 +00:00
|
|
|
result =
|
2013-05-30 12:32:03 +00:00
|
|
|
gst_caps_intersect_full (filter_caps, current_caps,
|
2011-05-16 08:52:59 +00:00
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
2013-05-30 12:32:03 +00:00
|
|
|
gst_caps_unref (current_caps);
|
2009-08-31 19:48:01 +00:00
|
|
|
} else {
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "no peer caps, using our caps");
|
|
|
|
result = current_caps;
|
2009-08-31 19:48:01 +00:00
|
|
|
}
|
2007-07-03 11:52:47 +00:00
|
|
|
}
|
2010-01-28 16:12:34 +00:00
|
|
|
|
2013-09-15 19:48:43 +00:00
|
|
|
result = gst_caps_make_writable (result);
|
|
|
|
|
|
|
|
n = gst_caps_get_size (result);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *sref;
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (result, i);
|
|
|
|
sref = gst_structure_copy (s);
|
|
|
|
gst_structure_set (sref, "channels", GST_TYPE_INT_RANGE, 0, 2, NULL);
|
|
|
|
if (gst_structure_is_subset (s, sref)) {
|
|
|
|
/* This field is irrelevant when in mono or stereo */
|
|
|
|
gst_structure_remove_field (s, "channel-mask");
|
|
|
|
}
|
|
|
|
gst_structure_free (sref);
|
|
|
|
}
|
|
|
|
|
2010-01-28 16:12:34 +00:00
|
|
|
if (filter_caps)
|
|
|
|
gst_caps_unref (filter_caps);
|
2007-07-03 11:52:47 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-15 15:30:38 +00:00
|
|
|
static gboolean
|
2013-02-13 20:08:48 +00:00
|
|
|
gst_adder_sink_query (GstCollectPads * pads, GstCollectData * pad,
|
|
|
|
GstQuery * query, gpointer user_data)
|
2011-11-15 15:30:38 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2013-02-13 20:08:48 +00:00
|
|
|
caps = gst_adder_sink_getcaps (pad->pad, filter);
|
2011-11-15 15:30:38 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-02-13 20:08:48 +00:00
|
|
|
res = gst_collect_pads_query_default (pads, pad, query, FALSE);
|
2011-11-15 15:30:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-13 20:08:48 +00:00
|
|
|
|
2011-11-15 15:30:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-07-03 11:52:47 +00:00
|
|
|
/* 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
|
2013-09-15 19:48:43 +00:00
|
|
|
gst_adder_setcaps (GstAdder * adder, GstPad * pad, GstCaps * orig_caps)
|
2002-02-19 05:59:06 +00:00
|
|
|
{
|
2013-09-15 19:48:43 +00:00
|
|
|
GstCaps *caps;
|
2013-05-30 12:45:58 +00:00
|
|
|
GstAudioInfo info;
|
2013-09-15 19:48:43 +00:00
|
|
|
GstStructure *s;
|
|
|
|
gint channels;
|
|
|
|
|
|
|
|
caps = gst_caps_copy (orig_caps);
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
if (gst_structure_get_int (s, "channels", &channels))
|
|
|
|
if (channels <= 2)
|
|
|
|
gst_structure_remove_field (s, "channel-mask");
|
2013-05-30 12:45:58 +00:00
|
|
|
|
|
|
|
if (!gst_audio_info_from_caps (&info, caps))
|
|
|
|
goto invalid_format;
|
|
|
|
|
2013-05-30 16:41:22 +00:00
|
|
|
GST_OBJECT_LOCK (adder);
|
2012-08-04 23:41:10 +00:00
|
|
|
/* don't allow reconfiguration for now; there's still a race between the
|
|
|
|
* different upstream threads doing query_caps + accept_caps + sending
|
|
|
|
* (possibly different) CAPS events, but there's not much we can do about
|
|
|
|
* that, upstream needs to deal with it. */
|
|
|
|
if (adder->current_caps != NULL) {
|
2013-05-30 12:45:58 +00:00
|
|
|
if (gst_audio_info_is_equal (&info, &adder->info)) {
|
2013-05-30 16:41:22 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
2013-09-15 19:48:43 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-08-04 23:41:10 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (pad, "got input caps %" GST_PTR_FORMAT ", but "
|
|
|
|
"current caps are %" GST_PTR_FORMAT, caps, adder->current_caps);
|
2013-05-30 16:41:22 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
2012-08-04 23:41:10 +00:00
|
|
|
gst_pad_push_event (pad, gst_event_new_reconfigure ());
|
2013-09-15 19:48:43 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-08-04 23:41:10 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (pad, "setting caps to %" GST_PTR_FORMAT, caps);
|
|
|
|
adder->current_caps = gst_caps_ref (caps);
|
2013-05-30 12:45:58 +00:00
|
|
|
|
|
|
|
memcpy (&adder->info, &info, sizeof (info));
|
2013-05-30 12:32:03 +00:00
|
|
|
GST_OBJECT_UNLOCK (adder);
|
2012-09-23 12:31:17 +00:00
|
|
|
/* send caps event later, after stream-start event */
|
2007-04-23 20:04:28 +00:00
|
|
|
|
2012-08-04 23:41:10 +00:00
|
|
|
GST_INFO_OBJECT (pad, "handle caps change to %" GST_PTR_FORMAT, caps);
|
2004-01-27 09:00:01 +00:00
|
|
|
|
2013-09-15 19:48:43 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2005-05-05 09:46:03 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2006-07-28 14:14:58 +00:00
|
|
|
/* ERRORS */
|
2011-08-19 15:05:55 +00:00
|
|
|
invalid_format:
|
2005-05-05 09:46:03 +00:00
|
|
|
{
|
2013-09-15 19:48:43 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-08-04 23:41:10 +00:00
|
|
|
GST_WARNING_OBJECT (adder, "invalid 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
|
2011-05-17 09:25:31 +00:00
|
|
|
gst_adder_query_duration (GstAdder * adder, GstQuery * query)
|
2006-05-10 11:54:36 +00:00
|
|
|
{
|
|
|
|
gint64 max;
|
|
|
|
gboolean res;
|
|
|
|
GstFormat format;
|
2006-05-29 15:49:53 +00:00
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
2011-05-05 14:03:52 +00:00
|
|
|
GValue item = { 0, };
|
2006-05-29 15:49:53 +00:00
|
|
|
|
|
|
|
/* parse format */
|
2011-05-17 09:25:31 +00:00
|
|
|
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
|
|
|
ires = gst_iterator_next (it, &item);
|
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
2011-05-05 14:03:52 +00:00
|
|
|
GstPad *pad = g_value_get_object (&item);
|
2006-05-29 15:49:53 +00:00
|
|
|
gint64 duration;
|
|
|
|
|
|
|
|
/* ask sink peer for duration */
|
2011-11-15 16:58:19 +00:00
|
|
|
res &= gst_pad_peer_query_duration (pad, format, &duration);
|
2006-05-29 15:49:53 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
2011-05-05 14:03:52 +00:00
|
|
|
g_value_reset (&item);
|
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
|
|
|
}
|
|
|
|
}
|
2011-05-05 14:03:52 +00:00
|
|
|
g_value_unset (&item);
|
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));
|
2011-05-17 09:25:31 +00:00
|
|
|
gst_query_set_duration (query, format, max);
|
2006-05-29 15:49:53 +00:00
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-10-09 08:56:54 +00:00
|
|
|
static gboolean
|
2011-11-16 16:25:17 +00:00
|
|
|
gst_adder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2005-10-09 08:56:54 +00:00
|
|
|
{
|
2011-11-16 16:25:17 +00:00
|
|
|
GstAdder *adder = GST_ADDER (parent);
|
2005-10-09 08:56:54 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
2011-05-17 09:25:31 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2005-10-09 08:56:54 +00:00
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
2011-05-17 09:25:31 +00:00
|
|
|
gst_query_parse_position (query, &format, NULL);
|
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
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2006-05-10 11:54:36 +00:00
|
|
|
/* FIXME, bring to stream time, might be tricky */
|
2011-05-17 09:25:31 +00:00
|
|
|
gst_query_set_position (query, format, adder->segment.position);
|
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:
|
2011-05-17 09:25:31 +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;
|
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 */
|
2011-11-16 16:25:17 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2005-10-09 08:56:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-02-27 10:57:55 +00:00
|
|
|
/* event handling */
|
|
|
|
|
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
|
2011-05-05 14:03:52 +00:00
|
|
|
forward_event_func (const GValue * val, GValue * ret, EventData * data)
|
2006-05-29 15:49:53 +00:00
|
|
|
{
|
2011-05-05 14:03:52 +00:00
|
|
|
GstPad *pad = g_value_get_object (val);
|
2009-06-23 16:07:31 +00:00
|
|
|
GstEvent *event = data->event;
|
2012-04-03 16:31:24 +00:00
|
|
|
GstPad *peer;
|
2009-06-23 16:07:31 +00:00
|
|
|
|
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));
|
2012-04-03 16:31:24 +00:00
|
|
|
peer = gst_pad_get_peer (pad);
|
|
|
|
/* collect pad might have been set flushing,
|
|
|
|
* so bypass core checking that and send directly to peer */
|
|
|
|
if (!peer || !gst_pad_send_event (peer, event)) {
|
|
|
|
if (!peer)
|
|
|
|
gst_event_unref (event);
|
2006-05-29 15:49:53 +00:00
|
|
|
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)
|
2011-06-10 09:59:53 +00:00
|
|
|
gst_pad_send_event (pad, gst_event_new_flush_stop (TRUE));
|
2006-05-29 15:49:53 +00:00
|
|
|
} else {
|
2009-10-09 21:32:04 +00:00
|
|
|
g_value_set_boolean (ret, TRUE);
|
2006-05-29 15:49:53 +00:00
|
|
|
GST_LOG_OBJECT (pad, "Sent event %p (%s).",
|
|
|
|
event, GST_EVENT_TYPE_NAME (event));
|
|
|
|
}
|
2012-04-03 16:31:24 +00:00
|
|
|
if (peer)
|
|
|
|
gst_object_unref (peer);
|
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);
|
2009-10-09 21:32:04 +00:00
|
|
|
g_value_set_boolean (&vret, FALSE);
|
2006-05-29 15:49:53 +00:00
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
2009-05-18 22:11:45 +00:00
|
|
|
while (TRUE) {
|
2011-05-05 14:03:52 +00:00
|
|
|
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
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_adder_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2006-05-10 11:54:36 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder;
|
|
|
|
gboolean result;
|
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
adder = GST_ADDER (parent);
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2017-07-23 11:13:14 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Got %s event on src pad: %" GST_PTR_FORMAT,
|
|
|
|
GST_EVENT_TYPE_NAME (event), event);
|
2011-07-25 17:11:59 +00:00
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2006-05-29 15:49:53 +00:00
|
|
|
{
|
|
|
|
GstSeekFlags flags;
|
2011-05-16 11:48:11 +00:00
|
|
|
gdouble rate;
|
2013-02-27 20:38:27 +00:00
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstFormat seek_format, dest_format;
|
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 */
|
2013-02-27 20:38:27 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &seek_format, &flags, &start_type,
|
|
|
|
&start, &stop_type, &stop);
|
2006-05-29 15:49:53 +00:00
|
|
|
|
2013-02-27 20:38:27 +00:00
|
|
|
if ((start_type != GST_SEEK_TYPE_NONE)
|
|
|
|
&& (start_type != GST_SEEK_TYPE_SET)) {
|
2010-04-18 17:46:37 +00:00
|
|
|
result = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (adder,
|
2013-02-27 20:38:27 +00:00
|
|
|
"seeking failed, unhandled seek type for start: %d", start_type);
|
2010-04-18 17:46:37 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2013-02-27 20:38:27 +00:00
|
|
|
if ((stop_type != GST_SEEK_TYPE_NONE) && (stop_type != GST_SEEK_TYPE_SET)) {
|
2010-04-18 17:46:37 +00:00
|
|
|
result = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (adder,
|
2013-02-27 20:38:27 +00:00
|
|
|
"seeking failed, unhandled seek type for end: %d", stop_type);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest_format = adder->segment.format;
|
|
|
|
if (seek_format != dest_format) {
|
|
|
|
result = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (adder,
|
|
|
|
"seeking failed, unhandled seek format: %d", seek_format);
|
2010-04-18 17:46:37 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* flushing seek, start flush downstream, the flush will be done
|
2011-12-16 17:25:10 +00:00
|
|
|
* when all pads received a FLUSH_STOP.
|
|
|
|
* Make sure we accept nothing anymore and return WRONG_STATE.
|
|
|
|
* We send a flush-start before, to ensure no streaming is done
|
|
|
|
* as we need to take the stream lock.
|
|
|
|
*/
|
2007-04-23 20:04:28 +00:00
|
|
|
gst_pad_push_event (adder->srcpad, gst_event_new_flush_start ());
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
2010-08-24 09:39:09 +00:00
|
|
|
|
|
|
|
/* We can't send FLUSH_STOP here since upstream could start pushing data
|
|
|
|
* after we unlock adder->collect.
|
|
|
|
* We set flush_stop_pending to TRUE instead and send FLUSH_STOP after
|
|
|
|
* forwarding the seek upstream or from gst_adder_collected,
|
|
|
|
* whichever happens first.
|
|
|
|
*/
|
2013-04-28 18:07:47 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (adder->collect);
|
|
|
|
adder->flush_stop_pending = TRUE;
|
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (adder->collect);
|
2013-02-25 17:50:33 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "mark pending flush stop event");
|
2007-04-23 20:04:28 +00:00
|
|
|
}
|
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. */
|
2012-04-17 13:09:27 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (adder->collect);
|
2017-07-23 11:13:14 +00:00
|
|
|
|
2013-02-27 20:38:27 +00:00
|
|
|
/* clip position and update our segment */
|
|
|
|
if (adder->segment.stop != -1) {
|
|
|
|
adder->segment.position = adder->segment.stop;
|
|
|
|
}
|
|
|
|
gst_segment_do_seek (&adder->segment, rate, seek_format, flags,
|
|
|
|
start_type, start, stop_type, stop, NULL);
|
|
|
|
|
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. */
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
2009-07-05 19:29:40 +00:00
|
|
|
}
|
2012-04-17 13:09:27 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (adder->collect);
|
2009-05-18 22:13:34 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "forwarding seek event: %" GST_PTR_FORMAT,
|
|
|
|
event);
|
2013-02-27 20:38:27 +00:00
|
|
|
GST_DEBUG_OBJECT (adder, "updated segment: %" GST_SEGMENT_FORMAT,
|
|
|
|
&adder->segment);
|
2006-05-29 15:49:53 +00:00
|
|
|
|
2011-07-25 17:39:55 +00:00
|
|
|
/* we're forwarding seek to all upstream peers and wait for one to reply
|
|
|
|
* with a newsegment-event before we send a newsegment-event downstream */
|
2013-05-30 12:57:04 +00:00
|
|
|
g_atomic_int_set (&adder->new_segment_pending, TRUE);
|
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
|
|
|
}
|
2010-08-24 09:39:09 +00:00
|
|
|
if (g_atomic_int_compare_and_exchange (&adder->flush_stop_pending,
|
|
|
|
TRUE, FALSE)) {
|
|
|
|
GST_DEBUG_OBJECT (adder, "pending flush stop");
|
2013-02-25 17:50:33 +00:00
|
|
|
if (!gst_pad_push_event (adder->srcpad,
|
|
|
|
gst_event_new_flush_stop (TRUE))) {
|
|
|
|
GST_WARNING_OBJECT (adder, "Sending flush stop event failed");
|
|
|
|
}
|
2010-08-24 09:39:09 +00:00
|
|
|
}
|
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;
|
2012-04-03 16:31:24 +00:00
|
|
|
gst_event_unref (event);
|
2009-05-18 22:13:34 +00:00
|
|
|
break;
|
2006-05-10 11:54:36 +00:00
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
/* navigation is rather pointless. */
|
|
|
|
result = FALSE;
|
2012-04-03 16:31:24 +00:00
|
|
|
gst_event_unref (event);
|
2006-05-10 11:54:36 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-04-18 17:46:37 +00:00
|
|
|
|
|
|
|
done:
|
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
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_adder_sink_event (GstCollectPads * pads, GstCollectData * pad,
|
2012-02-27 10:57:55 +00:00
|
|
|
GstEvent * event, gpointer user_data)
|
2006-05-10 11:54:36 +00:00
|
|
|
{
|
2012-02-27 10:57:55 +00:00
|
|
|
GstAdder *adder = GST_ADDER (user_data);
|
2012-04-17 11:48:19 +00:00
|
|
|
gboolean res = TRUE, discard = FALSE;
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2012-03-02 09:00:55 +00:00
|
|
|
GST_DEBUG_OBJECT (pad->pad, "Got %s event on sink pad",
|
2011-07-25 17:11:59 +00:00
|
|
|
GST_EVENT_TYPE_NAME (event));
|
2006-05-10 11:54:36 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-06-07 08:58:27 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
2012-03-02 09:00:55 +00:00
|
|
|
res = gst_adder_setcaps (adder, pad->pad, caps);
|
2011-06-07 08:58:27 +00:00
|
|
|
gst_event_unref (event);
|
2012-04-16 14:30:38 +00:00
|
|
|
event = NULL;
|
2013-03-11 21:46:45 +00:00
|
|
|
break;
|
2011-06-07 08:58:27 +00:00
|
|
|
}
|
2013-02-21 07:15:45 +00:00
|
|
|
case GST_EVENT_FLUSH_START:
|
2013-02-27 21:05:36 +00:00
|
|
|
/* ensure that we will send a flush stop */
|
2013-04-28 18:07:47 +00:00
|
|
|
res = gst_collect_pads_event_default (pads, pad, event, discard);
|
|
|
|
event = NULL;
|
2013-07-04 16:54:59 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (adder->collect);
|
|
|
|
adder->flush_stop_pending = TRUE;
|
2013-04-28 18:07:47 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (adder->collect);
|
2013-02-21 07:15:45 +00:00
|
|
|
break;
|
2006-05-10 11:54:36 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2012-02-27 10:57:55 +00:00
|
|
|
/* we received a flush-stop. We will only forward it when
|
|
|
|
* flush_stop_pending is set, and we will unset it then.
|
2006-05-10 11:54:36 +00:00
|
|
|
*/
|
2013-05-30 12:57:04 +00:00
|
|
|
g_atomic_int_set (&adder->new_segment_pending, TRUE);
|
2013-04-28 18:07:47 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (adder->collect);
|
|
|
|
if (adder->flush_stop_pending) {
|
2012-02-27 10:57:55 +00:00
|
|
|
GST_DEBUG_OBJECT (pad->pad, "forwarding flush stop");
|
2013-04-28 18:07:47 +00:00
|
|
|
res = gst_collect_pads_event_default (pads, pad, event, discard);
|
|
|
|
adder->flush_stop_pending = FALSE;
|
|
|
|
event = NULL;
|
2012-02-27 10:57:55 +00:00
|
|
|
} else {
|
2012-04-16 14:30:38 +00:00
|
|
|
discard = TRUE;
|
2012-02-27 10:57:55 +00:00
|
|
|
GST_DEBUG_OBJECT (pad->pad, "eating flush stop");
|
|
|
|
}
|
2013-04-28 18:07:47 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (adder->collect);
|
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;
|
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
break;
|
2009-07-13 07:28:54 +00:00
|
|
|
case GST_EVENT_TAG:
|
2009-12-24 12:58:52 +00:00
|
|
|
/* collect tags here so we can push them out when we collect data */
|
2009-07-13 07:28:54 +00:00
|
|
|
adder->pending_events = g_list_append (adder->pending_events, event);
|
2012-04-17 11:48:19 +00:00
|
|
|
event = NULL;
|
2012-02-27 10:57:55 +00:00
|
|
|
break;
|
2013-06-09 17:20:20 +00:00
|
|
|
case GST_EVENT_SEGMENT:{
|
|
|
|
const GstSegment *segment;
|
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
if (segment->rate != adder->segment.rate) {
|
|
|
|
GST_ERROR_OBJECT (pad->pad,
|
|
|
|
"Got segment event with wrong rate %lf, expected %lf",
|
|
|
|
segment->rate, adder->segment.rate);
|
|
|
|
res = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
event = NULL;
|
|
|
|
}
|
2012-04-16 14:30:38 +00:00
|
|
|
discard = TRUE;
|
2011-07-25 17:39:55 +00:00
|
|
|
break;
|
2013-06-09 17:20:20 +00:00
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:30:38 +00:00
|
|
|
if (G_LIKELY (event))
|
2012-04-17 13:09:27 +00:00
|
|
|
return gst_collect_pads_event_default (pads, pad, event, discard);
|
2012-04-16 14:30:38 +00:00
|
|
|
else
|
|
|
|
return res;
|
2006-05-10 11:54:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 07:06:09 +00:00
|
|
|
static void
|
|
|
|
gst_adder_class_init (GstAdderClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2003-11-01 01:10:23 +00:00
|
|
|
|
2010-09-01 07:06:09 +00:00
|
|
|
gobject_class->set_property = gst_adder_set_property;
|
|
|
|
gobject_class->get_property = gst_adder_get_property;
|
|
|
|
gobject_class->dispose = gst_adder_dispose;
|
2002-09-09 09:26:23 +00:00
|
|
|
|
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));
|
|
|
|
|
2016-03-03 07:46:24 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_adder_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_adder_sink_template);
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "Adder",
|
2016-03-03 07:46:24 +00:00
|
|
|
"Generic/Audio", "Add N audio channels together",
|
2011-04-19 09:35:53 +00:00
|
|
|
"Thomas Vander Stichele <thomas at apestaart dot org>");
|
|
|
|
|
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
|
2011-04-19 09:35:53 +00:00
|
|
|
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_query_function (adder->srcpad,
|
2011-11-15 15:30:38 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_src_query));
|
2006-04-28 19:17:06 +00:00
|
|
|
gst_pad_set_event_function (adder->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_src_event));
|
2011-11-15 15:30:38 +00:00
|
|
|
GST_PAD_SET_PROXY_CAPS (adder->srcpad);
|
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
|
|
|
|
2012-08-04 23:41:10 +00:00
|
|
|
adder->current_caps = NULL;
|
2011-08-19 15:05:55 +00:00
|
|
|
gst_audio_info_init (&adder->info);
|
2006-05-30 16:07:50 +00:00
|
|
|
adder->padcount = 0;
|
2002-01-22 04:45:10 +00:00
|
|
|
|
2009-08-31 19:48:01 +00:00
|
|
|
adder->filter_caps = NULL;
|
2009-07-10 19:06:28 +00:00
|
|
|
|
2001-12-22 22:43:48 +00:00
|
|
|
/* keep track of the sinkpads requested */
|
2012-04-17 13:09:27 +00:00
|
|
|
adder->collect = gst_collect_pads_new ();
|
|
|
|
gst_collect_pads_set_function (adder->collect,
|
2006-03-24 17:11:53 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_collected), adder);
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_collect_pads_set_clip_function (adder->collect,
|
2009-12-24 15:30:23 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_do_clip), adder);
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_collect_pads_set_event_function (adder->collect,
|
2012-02-27 10:57:55 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_sink_event), adder);
|
2013-02-13 20:08:48 +00:00
|
|
|
gst_collect_pads_set_query_function (adder->collect,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_adder_sink_query), 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);
|
2012-08-04 23:41:10 +00:00
|
|
|
gst_caps_replace (&adder->current_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:{
|
2009-08-31 19:48:01 +00:00
|
|
|
GstCaps *new_caps = NULL;
|
2009-07-10 19:06:28 +00:00
|
|
|
GstCaps *old_caps;
|
|
|
|
const GstCaps *new_caps_val = gst_value_get_caps (value);
|
|
|
|
|
2009-08-31 19:48:01 +00:00
|
|
|
if (new_caps_val != NULL) {
|
2009-07-10 19:06:28 +00:00
|
|
|
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);
|
|
|
|
|
2009-08-31 19:48:01 +00:00
|
|
|
if (old_caps)
|
|
|
|
gst_caps_unref (old_caps);
|
2009-07-10 19:06:28 +00:00
|
|
|
|
|
|
|
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,
|
2011-05-10 14:44:37 +00:00
|
|
|
const gchar * unused, const GstCaps * caps)
|
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 */
|
2011-06-04 20:36:55 +00:00
|
|
|
padcount = g_atomic_int_add (&adder->padcount, 1);
|
2006-05-30 16:07:50 +00:00
|
|
|
|
2011-11-04 09:48:50 +00:00
|
|
|
name = g_strdup_printf ("sink_%u", padcount);
|
2013-05-30 09:40:01 +00:00
|
|
|
newpad = g_object_new (GST_TYPE_ADDER_PAD, "name", name, "direction",
|
|
|
|
templ->direction, "template", templ, NULL);
|
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
|
|
|
|
2012-09-12 19:03:21 +00:00
|
|
|
gst_collect_pads_add_pad (adder->collect, newpad, sizeof (GstCollectData),
|
|
|
|
NULL, TRUE);
|
2006-05-07 16:39:36 +00:00
|
|
|
|
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
|
|
|
|
2013-05-30 16:48:19 +00:00
|
|
|
gst_child_proxy_child_added (GST_CHILD_PROXY (adder), G_OBJECT (newpad),
|
|
|
|
GST_OBJECT_NAME (newpad));
|
|
|
|
|
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");
|
2012-04-17 13:09:27 +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));
|
|
|
|
|
2013-05-30 16:48:19 +00:00
|
|
|
gst_child_proxy_child_removed (GST_CHILD_PROXY (adder), G_OBJECT (pad),
|
|
|
|
GST_OBJECT_NAME (pad));
|
2012-01-28 14:53:21 +00:00
|
|
|
if (adder->collect)
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_collect_pads_remove_pad (adder->collect, pad);
|
2006-05-30 16:07:50 +00:00
|
|
|
gst_element_remove_pad (element, pad);
|
|
|
|
}
|
|
|
|
|
2011-12-14 18:26:07 +00:00
|
|
|
static GstFlowReturn
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_adder_do_clip (GstCollectPads * pads, GstCollectData * data,
|
2011-12-14 18:26:07 +00:00
|
|
|
GstBuffer * buffer, GstBuffer ** out, gpointer user_data)
|
2009-12-24 15:30:23 +00:00
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (user_data);
|
2011-08-19 15:05:55 +00:00
|
|
|
gint rate, bpf;
|
|
|
|
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&adder->info);
|
|
|
|
bpf = GST_AUDIO_INFO_BPF (&adder->info);
|
2009-12-24 15:30:23 +00:00
|
|
|
|
2011-08-19 15:05:55 +00:00
|
|
|
buffer = gst_audio_buffer_clip (buffer, &data->segment, rate, bpf);
|
2009-12-24 15:30:23 +00:00
|
|
|
|
2011-12-14 18:26:07 +00:00
|
|
|
*out = buffer;
|
|
|
|
return GST_FLOW_OK;
|
2009-12-24 15:30:23 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:13:14 +00:00
|
|
|
/*
|
|
|
|
* gst_adder_collected:
|
|
|
|
*
|
|
|
|
* Combine audio streams by adding data values.
|
|
|
|
* basic algorithm :
|
|
|
|
* - 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
|
|
|
|
* - if there's an EOS event, remove the input channel
|
|
|
|
* - push out the output buffer
|
|
|
|
*
|
|
|
|
* Note: this code will run in one of the upstream threads.
|
|
|
|
*
|
|
|
|
* TODO: it would be nice to have a mixing mode, instead of only adding
|
|
|
|
* - 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
|
|
|
|
*/
|
2005-05-05 09:46:03 +00:00
|
|
|
static GstFlowReturn
|
2012-04-17 13:09:27 +00:00
|
|
|
gst_adder_collected (GstCollectPads * pads, gpointer user_data)
|
2001-12-22 22:43:48 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
GstAdder *adder;
|
2009-12-24 18:56:55 +00:00
|
|
|
GSList *collected, *next = NULL;
|
2005-05-05 09:46:03 +00:00
|
|
|
GstFlowReturn ret;
|
2009-12-24 18:56:55 +00:00
|
|
|
GstBuffer *outbuf = NULL, *gapbuf = NULL;
|
2012-01-20 15:11:54 +00:00
|
|
|
GstMapInfo outmap = { NULL };
|
2008-12-17 08:51:34 +00:00
|
|
|
guint outsize;
|
2010-04-14 20:31:20 +00:00
|
|
|
gint64 next_offset;
|
|
|
|
gint64 next_timestamp;
|
2011-08-19 15:05:55 +00:00
|
|
|
gint rate, bps, bpf;
|
2013-05-30 10:02:53 +00:00
|
|
|
gboolean had_mute = FALSE;
|
2014-03-25 16:11:34 +00:00
|
|
|
gboolean is_eos = TRUE;
|
2017-02-10 20:28:49 +00:00
|
|
|
gboolean is_discont = FALSE;
|
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 */
|
2013-05-30 10:54:37 +00:00
|
|
|
if (G_UNLIKELY (adder->info.finfo->format == GST_AUDIO_FORMAT_UNKNOWN))
|
2006-05-10 11:54:36 +00:00
|
|
|
goto not_negotiated;
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2014-11-28 13:28:06 +00:00
|
|
|
if (adder->flush_stop_pending) {
|
2013-02-25 17:50:33 +00:00
|
|
|
GST_INFO_OBJECT (adder->srcpad, "send pending flush stop event");
|
|
|
|
if (!gst_pad_push_event (adder->srcpad, gst_event_new_flush_stop (TRUE))) {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Sending flush stop event failed");
|
|
|
|
}
|
2013-04-28 18:07:47 +00:00
|
|
|
|
|
|
|
adder->flush_stop_pending = FALSE;
|
2013-02-25 17:50:33 +00:00
|
|
|
}
|
|
|
|
|
2012-09-23 12:31:17 +00:00
|
|
|
if (adder->send_stream_start) {
|
|
|
|
gchar s_id[32];
|
2014-03-11 21:15:13 +00:00
|
|
|
GstEvent *event;
|
2012-09-23 12:31:17 +00:00
|
|
|
|
2013-02-25 17:50:33 +00:00
|
|
|
GST_INFO_OBJECT (adder->srcpad, "send pending stream start event");
|
2017-02-10 20:28:49 +00:00
|
|
|
/* FIXME: create id based on input ids, we can't use
|
2014-03-11 21:15:13 +00:00
|
|
|
* gst_pad_create_stream_id() though as that only handles 0..1 sink-pad
|
|
|
|
*/
|
2012-09-23 12:31:17 +00:00
|
|
|
g_snprintf (s_id, sizeof (s_id), "adder-%08x", g_random_int ());
|
2014-03-11 21:15:13 +00:00
|
|
|
event = gst_event_new_stream_start (s_id);
|
|
|
|
gst_event_set_group_id (event, gst_util_group_id_next ());
|
|
|
|
|
|
|
|
if (!gst_pad_push_event (adder->srcpad, event)) {
|
2013-02-25 17:50:33 +00:00
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Sending stream start event failed");
|
|
|
|
}
|
2012-09-23 12:31:17 +00:00
|
|
|
adder->send_stream_start = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adder->send_caps) {
|
|
|
|
GstEvent *caps_event;
|
|
|
|
|
|
|
|
caps_event = gst_event_new_caps (adder->current_caps);
|
2013-02-25 17:50:33 +00:00
|
|
|
GST_INFO_OBJECT (adder->srcpad, "send pending caps event %" GST_PTR_FORMAT,
|
|
|
|
caps_event);
|
|
|
|
if (!gst_pad_push_event (adder->srcpad, caps_event)) {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Sending caps event failed");
|
|
|
|
}
|
2012-09-23 12:31:17 +00:00
|
|
|
adder->send_caps = FALSE;
|
|
|
|
}
|
|
|
|
|
2013-09-22 20:55:33 +00:00
|
|
|
rate = GST_AUDIO_INFO_RATE (&adder->info);
|
|
|
|
bps = GST_AUDIO_INFO_BPS (&adder->info);
|
|
|
|
bpf = GST_AUDIO_INFO_BPF (&adder->info);
|
|
|
|
|
|
|
|
if (g_atomic_int_compare_and_exchange (&adder->new_segment_pending, TRUE,
|
|
|
|
FALSE)) {
|
|
|
|
GstEvent *event;
|
|
|
|
|
2017-02-10 20:28:49 +00:00
|
|
|
/*
|
2013-09-22 20:55:33 +00:00
|
|
|
* When seeking we set the start and stop positions as given in the seek
|
|
|
|
* event. We also adjust offset & timestamp accordingly.
|
|
|
|
* This basically ignores all newsegments sent by upstream.
|
|
|
|
*/
|
|
|
|
event = gst_event_new_segment (&adder->segment);
|
|
|
|
if (adder->segment.rate > 0.0) {
|
|
|
|
adder->segment.position = adder->segment.start;
|
|
|
|
} else {
|
|
|
|
adder->segment.position = adder->segment.stop;
|
|
|
|
}
|
|
|
|
adder->offset = gst_util_uint64_scale (adder->segment.position,
|
|
|
|
rate, GST_SECOND);
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (adder->srcpad, "sending pending new segment event %"
|
|
|
|
GST_SEGMENT_FORMAT, &adder->segment);
|
|
|
|
if (event) {
|
|
|
|
if (!gst_pad_push_event (adder->srcpad, event)) {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Sending new segment event failed");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (adder->srcpad, "Creating new segment event for "
|
2017-07-23 11:13:14 +00:00
|
|
|
"start:%" G_GINT64_FORMAT ", end:%" G_GINT64_FORMAT " failed",
|
2013-09-22 20:55:33 +00:00
|
|
|
adder->segment.start, adder->segment.stop);
|
|
|
|
}
|
2017-02-10 20:28:49 +00:00
|
|
|
is_discont = TRUE;
|
2013-09-22 20:55:33 +00:00
|
|
|
}
|
|
|
|
|
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. */
|
2012-04-17 13:09:27 +00:00
|
|
|
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,
|
2011-11-29 13:47:37 +00:00
|
|
|
"starting to cycle through channels, %d bytes available (bps = %d, bpf = %d)",
|
|
|
|
outsize, bps, bpf);
|
2003-07-19 23:16:25 +00:00
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
for (collected = pads->data; collected; collected = next) {
|
2012-04-17 13:09:27 +00:00
|
|
|
GstCollectData *collect_data;
|
2008-02-18 13:51:34 +00:00
|
|
|
GstBuffer *inbuf;
|
2009-12-24 18:56:55 +00:00
|
|
|
gboolean is_gap;
|
2013-05-30 10:02:53 +00:00
|
|
|
GstAdderPad *pad;
|
2013-05-30 09:45:10 +00:00
|
|
|
GstClockTime timestamp, stream_time;
|
2009-12-24 18:56:55 +00:00
|
|
|
|
|
|
|
/* take next to see if this is the last collectdata */
|
|
|
|
next = g_slist_next (collected);
|
2003-01-11 16:28:29 +00:00
|
|
|
|
2012-04-17 13:09:27 +00:00
|
|
|
collect_data = (GstCollectData *) collected->data;
|
2013-05-30 10:02:53 +00:00
|
|
|
pad = GST_ADDER_PAD (collect_data->pad);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
/* get a buffer of size bytes, if we get a buffer, it is at least outsize
|
|
|
|
* bytes big. */
|
2012-04-17 13:09:27 +00:00
|
|
|
inbuf = gst_collect_pads_take_buffer (pads, collect_data, outsize);
|
2014-03-25 16:11:34 +00:00
|
|
|
|
|
|
|
if (!GST_COLLECT_PADS_STATE_IS_SET (collect_data,
|
2014-11-28 13:28:06 +00:00
|
|
|
GST_COLLECT_PADS_STATE_EOS))
|
2014-03-25 16:11:34 +00:00
|
|
|
is_eos = FALSE;
|
|
|
|
|
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
|
|
|
|
2013-05-30 09:45:10 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (inbuf);
|
|
|
|
stream_time =
|
|
|
|
gst_segment_to_stream_time (&collect_data->segment, GST_FORMAT_TIME,
|
|
|
|
timestamp);
|
|
|
|
|
|
|
|
/* sync object properties on stream time */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stream_time))
|
2013-05-30 10:02:53 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (pad), stream_time);
|
|
|
|
|
2013-05-30 10:46:56 +00:00
|
|
|
GST_OBJECT_LOCK (pad);
|
2013-05-30 10:02:53 +00:00
|
|
|
if (pad->mute || pad->volume < G_MINDOUBLE) {
|
|
|
|
had_mute = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (adder, "channel %p: skipping muted pad", collect_data);
|
|
|
|
gst_buffer_unref (inbuf);
|
2013-05-30 10:46:56 +00:00
|
|
|
GST_OBJECT_UNLOCK (pad);
|
2013-05-30 10:02:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-30 09:45:10 +00:00
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
is_gap = GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP);
|
2008-02-18 13:51:34 +00:00
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
/* Try to make an output buffer */
|
2005-05-05 09:46:03 +00:00
|
|
|
if (outbuf == NULL) {
|
2009-12-24 18:56:55 +00:00
|
|
|
/* if this is a gap buffer but we have some more pads to check, skip it.
|
|
|
|
* If we are at the last buffer, take it, regardless if it is a GAP
|
|
|
|
* buffer or not. */
|
|
|
|
if (is_gap && next) {
|
|
|
|
GST_DEBUG_OBJECT (adder, "skipping, non-last GAP buffer");
|
|
|
|
/* we keep the GAP buffer, if we don't have anymore buffers (all pads
|
|
|
|
* EOS, we can use this one as the output buffer. */
|
|
|
|
if (gapbuf == NULL)
|
|
|
|
gapbuf = inbuf;
|
|
|
|
else
|
|
|
|
gst_buffer_unref (inbuf);
|
2013-05-30 10:46:56 +00:00
|
|
|
GST_OBJECT_UNLOCK (pad);
|
2009-12-24 18:56:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-05-10 11:54:36 +00:00
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
GST_LOG_OBJECT (adder, "channel %p: preparing output buffer of %d bytes",
|
|
|
|
collect_data, outsize);
|
2011-03-27 14:35:28 +00:00
|
|
|
|
2011-11-29 13:22:19 +00:00
|
|
|
/* make data and metadata writable, can simply return the inbuf when we
|
|
|
|
* are the only one referencing this buffer. If this is the last (and
|
|
|
|
* only) GAP buffer, it will automatically copy the GAP flag. */
|
|
|
|
outbuf = gst_buffer_make_writable (inbuf);
|
2013-05-30 10:05:02 +00:00
|
|
|
gst_buffer_map (outbuf, &outmap, GST_MAP_READWRITE);
|
2013-05-30 10:46:56 +00:00
|
|
|
|
|
|
|
if (pad->volume != 1.0) {
|
|
|
|
switch (adder->info.finfo->format) {
|
|
|
|
case GST_AUDIO_FORMAT_U8:
|
|
|
|
adder_orc_volume_u8 ((gpointer) outmap.data, pad->volume_i8,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S8:
|
|
|
|
adder_orc_volume_s8 ((gpointer) outmap.data, pad->volume_i8,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U16:
|
|
|
|
adder_orc_volume_u16 ((gpointer) outmap.data, pad->volume_i16,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S16:
|
|
|
|
adder_orc_volume_s16 ((gpointer) outmap.data, pad->volume_i16,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U32:
|
|
|
|
adder_orc_volume_u32 ((gpointer) outmap.data, pad->volume_i32,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S32:
|
|
|
|
adder_orc_volume_s32 ((gpointer) outmap.data, pad->volume_i32,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F32:
|
|
|
|
adder_orc_volume_f32 ((gpointer) outmap.data, pad->volume,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F64:
|
|
|
|
adder_orc_volume_f64 ((gpointer) outmap.data, pad->volume,
|
|
|
|
outmap.size / bps);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-01-11 16:28:29 +00:00
|
|
|
} else {
|
2009-12-24 18:56:55 +00:00
|
|
|
if (!is_gap) {
|
|
|
|
/* we had a previous output buffer, mix this non-GAP buffer */
|
2012-01-20 15:11:54 +00:00
|
|
|
GstMapInfo inmap;
|
2009-12-24 18:56:55 +00:00
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_map (inbuf, &inmap, GST_MAP_READ);
|
2009-12-24 18:56:55 +00:00
|
|
|
|
|
|
|
/* all buffers should have outsize, there are no short buffers because we
|
|
|
|
* asked for the max size above */
|
2012-01-20 15:11:54 +00:00
|
|
|
g_assert (inmap.size == outmap.size);
|
2009-12-24 18:56:55 +00:00
|
|
|
|
2011-08-09 14:39:31 +00:00
|
|
|
GST_LOG_OBJECT (adder, "channel %p: mixing %" G_GSIZE_FORMAT " bytes"
|
2012-01-20 15:11:54 +00:00
|
|
|
" from data %p", collect_data, inmap.size, inmap.data);
|
2009-12-24 18:56:55 +00:00
|
|
|
|
2008-12-17 08:51:34 +00:00
|
|
|
/* further buffers, need to add them */
|
2013-05-30 10:46:56 +00:00
|
|
|
if (pad->volume == 1.0) {
|
2013-05-30 10:54:37 +00:00
|
|
|
switch (adder->info.finfo->format) {
|
|
|
|
case GST_AUDIO_FORMAT_U8:
|
|
|
|
adder_orc_add_u8 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S8:
|
|
|
|
adder_orc_add_s8 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U16:
|
|
|
|
adder_orc_add_u16 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S16:
|
|
|
|
adder_orc_add_s16 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U32:
|
|
|
|
adder_orc_add_u32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S32:
|
|
|
|
adder_orc_add_s32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F32:
|
|
|
|
adder_orc_add_f32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F64:
|
|
|
|
adder_orc_add_f64 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-30 10:46:56 +00:00
|
|
|
} else {
|
|
|
|
switch (adder->info.finfo->format) {
|
|
|
|
case GST_AUDIO_FORMAT_U8:
|
|
|
|
adder_orc_add_volume_u8 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i8, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S8:
|
|
|
|
adder_orc_add_volume_s8 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i8, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U16:
|
|
|
|
adder_orc_add_volume_u16 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i16, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S16:
|
|
|
|
adder_orc_add_volume_s16 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i16, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_U32:
|
|
|
|
adder_orc_add_volume_u32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i32, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S32:
|
|
|
|
adder_orc_add_volume_s32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume_i32, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F32:
|
|
|
|
adder_orc_add_volume_f32 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F64:
|
|
|
|
adder_orc_add_volume_f64 ((gpointer) outmap.data,
|
|
|
|
(gpointer) inmap.data, pad->volume, inmap.size / bps);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_unmap (inbuf, &inmap);
|
2008-02-18 13:51:34 +00:00
|
|
|
} else {
|
2009-12-24 18:56:55 +00:00
|
|
|
/* skip gap buffer */
|
|
|
|
GST_LOG_OBJECT (adder, "channel %p: skipping GAP buffer", collect_data);
|
2008-02-18 13:51:34 +00:00
|
|
|
}
|
2009-12-24 18:56:55 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
2001-12-23 23:01:28 +00:00
|
|
|
}
|
2013-05-30 10:46:56 +00:00
|
|
|
GST_OBJECT_UNLOCK (pad);
|
2004-06-06 23:43:15 +00:00
|
|
|
}
|
2014-03-25 16:11:34 +00:00
|
|
|
|
2011-03-27 14:35:28 +00:00
|
|
|
if (outbuf)
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_unmap (outbuf, &outmap);
|
2001-12-22 22:43:48 +00:00
|
|
|
|
2014-03-25 16:11:34 +00:00
|
|
|
if (is_eos)
|
|
|
|
goto eos;
|
|
|
|
|
2009-12-24 18:56:55 +00:00
|
|
|
if (outbuf == NULL) {
|
|
|
|
/* no output buffer, reuse one of the GAP buffers then if we have one */
|
|
|
|
if (gapbuf) {
|
|
|
|
GST_LOG_OBJECT (adder, "reusing GAP buffer %p", gapbuf);
|
|
|
|
outbuf = gapbuf;
|
2013-05-30 10:02:53 +00:00
|
|
|
} else if (had_mute) {
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
/* Means we had all pads muted, create some silence */
|
|
|
|
outbuf = gst_buffer_new_allocate (NULL, outsize, NULL);
|
|
|
|
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
|
|
|
|
gst_audio_format_fill_silence (adder->info.finfo, map.data, outsize);
|
|
|
|
gst_buffer_unmap (outbuf, &map);
|
2013-05-30 10:57:11 +00:00
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
|
2013-05-30 10:02:53 +00:00
|
|
|
} else {
|
2009-12-24 18:56:55 +00:00
|
|
|
/* assume EOS otherwise, this should not happen, really */
|
|
|
|
goto eos;
|
2013-05-30 10:02:53 +00:00
|
|
|
}
|
|
|
|
} else if (gapbuf) {
|
2009-12-24 18:56:55 +00:00
|
|
|
/* we had an output buffer, unref the gapbuffer we kept */
|
|
|
|
gst_buffer_unref (gapbuf);
|
2013-05-30 10:02:53 +00:00
|
|
|
}
|
2006-05-10 11:54:36 +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;
|
|
|
|
}
|
|
|
|
|
2006-05-10 11:54:36 +00:00
|
|
|
/* for the next timestamp, use the sample counter, which will
|
|
|
|
* never accumulate rounding errors */
|
2011-05-16 11:48:11 +00:00
|
|
|
if (adder->segment.rate > 0.0) {
|
2011-08-19 15:05:55 +00:00
|
|
|
next_offset = adder->offset + outsize / bpf;
|
2010-04-14 20:31:20 +00:00
|
|
|
} else {
|
2011-08-19 15:05:55 +00:00
|
|
|
next_offset = adder->offset - outsize / bpf;
|
2010-04-14 20:31:20 +00:00
|
|
|
}
|
2011-08-19 15:05:55 +00:00
|
|
|
next_timestamp = gst_util_uint64_scale (next_offset, GST_SECOND, rate);
|
2010-04-14 20:31:20 +00:00
|
|
|
|
|
|
|
/* set timestamps on the output buffer */
|
2013-08-06 13:11:05 +00:00
|
|
|
GST_BUFFER_DTS (outbuf) = GST_CLOCK_TIME_NONE;
|
2011-05-16 11:48:11 +00:00
|
|
|
if (adder->segment.rate > 0.0) {
|
2013-08-06 13:11:05 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) = adder->segment.position;
|
2010-04-14 20:31:20 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = adder->offset;
|
2011-02-22 04:34:41 +00:00
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = next_offset;
|
2011-05-16 11:48:11 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = next_timestamp - adder->segment.position;
|
2010-04-11 19:58:15 +00:00
|
|
|
} else {
|
2013-08-06 13:11:05 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) = next_timestamp;
|
2010-04-14 20:31:20 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = next_offset;
|
2011-02-22 04:34:41 +00:00
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = adder->offset;
|
2011-05-16 11:48:11 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = adder->segment.position - next_timestamp;
|
2010-04-11 19:58:15 +00:00
|
|
|
}
|
2017-02-10 20:28:49 +00:00
|
|
|
if (is_discont) {
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
}
|
2005-05-05 09:46:03 +00:00
|
|
|
|
2010-04-14 20:31:20 +00:00
|
|
|
adder->offset = next_offset;
|
2011-05-16 11:48:11 +00:00
|
|
|
adder->segment.position = next_timestamp;
|
2003-01-11 16:28:29 +00:00
|
|
|
|
|
|
|
/* send it out */
|
2010-04-14 20:31:20 +00:00
|
|
|
GST_LOG_OBJECT (adder, "pushing outbuf %p, timestamp %" GST_TIME_FORMAT
|
|
|
|
" offset %" G_GINT64_FORMAT, outbuf,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
|
|
|
|
GST_BUFFER_OFFSET (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 ());
|
2011-10-10 09:39:52 +00:00
|
|
|
return GST_FLOW_EOS;
|
2006-05-10 11:54:36 +00:00
|
|
|
}
|
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->offset = 0;
|
2009-07-30 10:42:21 +00:00
|
|
|
adder->flush_stop_pending = FALSE;
|
2011-07-25 17:39:55 +00:00
|
|
|
adder->new_segment_pending = TRUE;
|
2012-09-23 12:31:17 +00:00
|
|
|
adder->send_stream_start = TRUE;
|
|
|
|
adder->send_caps = TRUE;
|
2012-08-04 23:41:10 +00:00
|
|
|
gst_caps_replace (&adder->current_caps, NULL);
|
2011-05-16 11:48:11 +00:00
|
|
|
gst_segment_init (&adder->segment, GST_FORMAT_TIME);
|
2012-04-17 13:09:27 +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:
|
2012-04-17 13:09:27 +00:00
|
|
|
/* need to unblock the collectpads before calling the
|
2005-10-27 09:54:06 +00:00
|
|
|
* parent change_state so that streaming can finish */
|
2012-04-17 13:09:27 +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
|
|
|
}
|
|
|
|
|
2013-05-30 16:48:19 +00:00
|
|
|
/* GstChildProxy implementation */
|
|
|
|
static GObject *
|
|
|
|
gst_adder_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
|
|
|
|
guint index)
|
|
|
|
{
|
|
|
|
GstAdder *adder = GST_ADDER (child_proxy);
|
|
|
|
GObject *obj = NULL;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
obj = g_list_nth_data (GST_ELEMENT_CAST (adder)->sinkpads, index);
|
|
|
|
if (obj)
|
|
|
|
gst_object_ref (obj);
|
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gst_adder_child_proxy_get_children_count (GstChildProxy * child_proxy)
|
|
|
|
{
|
|
|
|
guint count = 0;
|
|
|
|
GstAdder *adder = GST_ADDER (child_proxy);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (adder);
|
|
|
|
count = GST_ELEMENT_CAST (adder)->numsinkpads;
|
|
|
|
GST_OBJECT_UNLOCK (adder);
|
|
|
|
GST_INFO_OBJECT (adder, "Children Count: %d", count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_adder_child_proxy_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstChildProxyInterface *iface = g_iface;
|
|
|
|
|
|
|
|
GST_INFO ("intializing child proxy interface");
|
|
|
|
iface->get_child_by_index = gst_adder_child_proxy_get_child_by_index;
|
|
|
|
iface->get_children_count = gst_adder_child_proxy_get_children_count;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-09-09 09:12:56 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "adder", 0,
|
|
|
|
"audio channel mixing element");
|
|
|
|
|
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,
|
2012-04-05 13:11:05 +00:00
|
|
|
adder,
|
2004-03-14 22:34:34 +00:00
|
|
|
"Adds multiple streams",
|
2005-10-16 13:54:44 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|