2011-10-28 07:18:55 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
|
|
|
|
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sourceforge.net>
|
|
|
|
* Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
2012-04-17 12:38:01 +00:00
|
|
|
* gstcollectpads.c:
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* 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 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* SECTION:gstcollectpads
|
2011-10-28 07:18:55 +00:00
|
|
|
* @short_description: manages a set of pads that operate in collect mode
|
|
|
|
* @see_also:
|
|
|
|
*
|
|
|
|
* Manages a set of pads that operate in collect mode. This means that control
|
|
|
|
* is given to the manager of this object when all pads have data.
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* Collectpads are created with gst_collect_pads_new(). A callback should then
|
|
|
|
* be installed with gst_collect_pads_set_function ().
|
2011-10-28 07:18:55 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* Pads are added to the collection with gst_collect_pads_add_pad()/
|
|
|
|
* gst_collect_pads_remove_pad(). The pad
|
2011-10-28 07:18:55 +00:00
|
|
|
* has to be a sinkpad. The chain and event functions of the pad are
|
|
|
|
* overridden. The element_private of the pad is used to store
|
|
|
|
* private information for the collectpads.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* For each pad, data is queued in the _chain function or by
|
|
|
|
* performing a pull_range.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* When data is queued on all pads in waiting mode, the callback function is called.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* Data can be dequeued from the pad with the gst_collect_pads_pop() method.
|
|
|
|
* One can peek at the data with the gst_collect_pads_peek() function.
|
2014-06-05 19:38:20 +00:00
|
|
|
* These functions will return %NULL if the pad received an EOS event. When all
|
|
|
|
* pads return %NULL from a gst_collect_pads_peek(), the element can emit an EOS
|
2011-10-28 07:18:55 +00:00
|
|
|
* event itself.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* Data can also be dequeued in byte units using the gst_collect_pads_available(),
|
2013-04-10 22:11:25 +00:00
|
|
|
* gst_collect_pads_read_buffer() and gst_collect_pads_flush() calls.
|
2011-10-28 07:18:55 +00:00
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* Elements should call gst_collect_pads_start() and gst_collect_pads_stop() in
|
2011-10-28 07:18:55 +00:00
|
|
|
* their state change functions to start and stop the processing of the collectpads.
|
2012-04-17 12:38:01 +00:00
|
|
|
* The gst_collect_pads_stop() call should be called before calling the parent
|
2011-10-28 07:18:55 +00:00
|
|
|
* element state change function in the PAUSED_TO_READY state change to ensure
|
|
|
|
* no pad is blocked and the element can finish streaming.
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_waiting() sets a pad to waiting or non-waiting mode.
|
2011-10-28 07:18:55 +00:00
|
|
|
* CollectPads element is not waiting for data to be collected on non-waiting pads.
|
|
|
|
* Thus these pads may but need not have data when the callback is called.
|
|
|
|
* All pads are in waiting mode by default.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
*/
|
|
|
|
|
2011-12-04 14:38:26 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst_private.h>
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
#include "gstcollectpads.h"
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2011-12-04 13:35:38 +00:00
|
|
|
#include "../../../gst/glib-compat-private.h"
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (collect_pads_debug);
|
|
|
|
#define GST_CAT_DEFAULT collect_pads_debug
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
#define parent_class gst_collect_pads_parent_class
|
|
|
|
G_DEFINE_TYPE (GstCollectPads, gst_collect_pads, GST_TYPE_OBJECT);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
struct _GstCollectDataPrivate
|
2012-01-27 14:02:52 +00:00
|
|
|
{
|
|
|
|
/* refcounting for struct, and destroy callback */
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectDataDestroyNotify destroy_notify;
|
2012-01-27 14:02:52 +00:00
|
|
|
gint refcount;
|
|
|
|
};
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
struct _GstCollectPadsPrivate
|
2012-01-27 14:02:52 +00:00
|
|
|
{
|
|
|
|
/* with LOCK and/or STREAM_LOCK */
|
|
|
|
gboolean started;
|
|
|
|
|
|
|
|
/* with STREAM_LOCK */
|
|
|
|
guint32 cookie; /* @data list cookie */
|
|
|
|
guint numpads; /* number of pads in @data */
|
|
|
|
guint queuedpads; /* number of pads with a buffer */
|
|
|
|
guint eospads; /* number of pads that are EOS */
|
|
|
|
GstClockTime earliest_time; /* Current earliest time */
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *earliest_data; /* Pad data for current earliest time */
|
2012-01-27 14:02:52 +00:00
|
|
|
|
|
|
|
/* with LOCK */
|
|
|
|
GSList *pad_list; /* updated pad list */
|
|
|
|
guint32 pad_cookie; /* updated cookie */
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsFunction func; /* function and user_data for callback */
|
2012-01-27 14:02:52 +00:00
|
|
|
gpointer user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsBufferFunction buffer_func; /* function and user_data for buffer callback */
|
2012-01-27 14:02:52 +00:00
|
|
|
gpointer buffer_user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsCompareFunction compare_func;
|
2012-01-27 14:02:52 +00:00
|
|
|
gpointer compare_user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsEventFunction event_func; /* function and data for event callback */
|
2012-01-27 14:02:52 +00:00
|
|
|
gpointer event_user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsQueryFunction query_func;
|
2012-04-16 14:24:18 +00:00
|
|
|
gpointer query_user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsClipFunction clip_func;
|
2012-01-27 14:02:52 +00:00
|
|
|
gpointer clip_user_data;
|
2013-09-16 07:55:58 +00:00
|
|
|
GstCollectPadsFlushFunction flush_func;
|
|
|
|
gpointer flush_user_data;
|
2012-01-27 14:02:52 +00:00
|
|
|
|
|
|
|
/* no other lock needed */
|
2012-01-27 14:09:35 +00:00
|
|
|
GMutex evt_lock; /* these make up sort of poor man's event signaling */
|
|
|
|
GCond evt_cond;
|
2012-01-27 14:02:52 +00:00
|
|
|
guint32 evt_cookie;
|
2013-09-16 07:55:58 +00:00
|
|
|
|
|
|
|
gboolean seeking;
|
|
|
|
gboolean pending_flush_start;
|
|
|
|
gboolean pending_flush_stop;
|
2012-01-27 14:02:52 +00:00
|
|
|
};
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
static void gst_collect_pads_clear (GstCollectPads * pads,
|
|
|
|
GstCollectData * data);
|
|
|
|
static GstFlowReturn gst_collect_pads_chain (GstPad * pad, GstObject * parent,
|
2011-11-17 11:40:45 +00:00
|
|
|
GstBuffer * buffer);
|
2012-04-17 12:38:01 +00:00
|
|
|
static gboolean gst_collect_pads_event (GstPad * pad, GstObject * parent,
|
2011-11-17 11:40:45 +00:00
|
|
|
GstEvent * event);
|
2012-04-17 12:38:01 +00:00
|
|
|
static gboolean gst_collect_pads_query (GstPad * pad, GstObject * parent,
|
2012-04-16 14:24:18 +00:00
|
|
|
GstQuery * query);
|
2012-04-17 12:38:01 +00:00
|
|
|
static void gst_collect_pads_finalize (GObject * object);
|
|
|
|
static GstFlowReturn gst_collect_pads_default_collected (GstCollectPads *
|
2011-10-28 07:18:55 +00:00
|
|
|
pads, gpointer user_data);
|
2012-04-17 12:38:01 +00:00
|
|
|
static gint gst_collect_pads_default_compare_func (GstCollectPads * pads,
|
|
|
|
GstCollectData * data1, GstClockTime timestamp1, GstCollectData * data2,
|
2011-10-28 07:18:55 +00:00
|
|
|
GstClockTime timestamp2, gpointer user_data);
|
2012-04-17 12:38:01 +00:00
|
|
|
static gboolean gst_collect_pads_recalculate_full (GstCollectPads * pads);
|
|
|
|
static void ref_data (GstCollectData * data);
|
|
|
|
static void unref_data (GstCollectData * data);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
static gboolean gst_collect_pads_event_default_internal (GstCollectPads *
|
|
|
|
pads, GstCollectData * data, GstEvent * event, gpointer user_data);
|
|
|
|
static gboolean gst_collect_pads_query_default_internal (GstCollectPads *
|
|
|
|
pads, GstCollectData * data, GstQuery * query, gpointer user_data);
|
2012-04-16 14:24:10 +00:00
|
|
|
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/* Some properties are protected by LOCK, others by STREAM_LOCK
|
|
|
|
* However, manipulating either of these partitions may require
|
|
|
|
* to signal/wake a _WAIT, so use a separate (sort of) event to prevent races
|
|
|
|
* Alternative implementations are possible, e.g. some low-level re-implementing
|
|
|
|
* of the 2 above locks to drop both of them atomically when going into _WAIT.
|
|
|
|
*/
|
2012-04-17 12:38:01 +00:00
|
|
|
#define GST_COLLECT_PADS_GET_EVT_COND(pads) (&((GstCollectPads *)pads)->priv->evt_cond)
|
|
|
|
#define GST_COLLECT_PADS_GET_EVT_LOCK(pads) (&((GstCollectPads *)pads)->priv->evt_lock)
|
|
|
|
#define GST_COLLECT_PADS_EVT_WAIT(pads, cookie) G_STMT_START { \
|
|
|
|
g_mutex_lock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
/* should work unless a lot of event'ing and thread starvation */\
|
2012-04-17 12:38:01 +00:00
|
|
|
while (cookie == ((GstCollectPads *) pads)->priv->evt_cookie) \
|
|
|
|
g_cond_wait (GST_COLLECT_PADS_GET_EVT_COND (pads), \
|
|
|
|
GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
|
|
|
cookie = ((GstCollectPads *) pads)->priv->evt_cookie; \
|
|
|
|
g_mutex_unlock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
} G_STMT_END
|
2012-04-17 12:38:01 +00:00
|
|
|
#define GST_COLLECT_PADS_EVT_WAIT_TIMED(pads, cookie, timeout) G_STMT_START { \
|
2011-10-28 07:18:55 +00:00
|
|
|
GTimeVal __tv; \
|
|
|
|
\
|
|
|
|
g_get_current_time (&tv); \
|
|
|
|
g_time_val_add (&tv, timeout); \
|
|
|
|
\
|
2012-04-17 12:38:01 +00:00
|
|
|
g_mutex_lock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
/* should work unless a lot of event'ing and thread starvation */\
|
2012-04-17 12:38:01 +00:00
|
|
|
while (cookie == ((GstCollectPads *) pads)->priv->evt_cookie) \
|
|
|
|
g_cond_timed_wait (GST_COLLECT_PADS_GET_EVT_COND (pads), \
|
|
|
|
GST_COLLECT_PADS_GET_EVT_LOCK (pads), &tv); \
|
|
|
|
cookie = ((GstCollectPads *) pads)->priv->evt_cookie; \
|
|
|
|
g_mutex_unlock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
} G_STMT_END
|
2012-04-17 12:38:01 +00:00
|
|
|
#define GST_COLLECT_PADS_EVT_BROADCAST(pads) G_STMT_START { \
|
|
|
|
g_mutex_lock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
/* never mind wrap-around */ \
|
2012-04-17 12:38:01 +00:00
|
|
|
++(((GstCollectPads *) pads)->priv->evt_cookie); \
|
|
|
|
g_cond_broadcast (GST_COLLECT_PADS_GET_EVT_COND (pads)); \
|
|
|
|
g_mutex_unlock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
} G_STMT_END
|
2012-04-17 12:38:01 +00:00
|
|
|
#define GST_COLLECT_PADS_EVT_INIT(cookie) G_STMT_START { \
|
|
|
|
g_mutex_lock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
|
|
|
cookie = ((GstCollectPads *) pads)->priv->evt_cookie; \
|
|
|
|
g_mutex_unlock (GST_COLLECT_PADS_GET_EVT_LOCK (pads)); \
|
2011-10-28 07:18:55 +00:00
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_class_init (GstCollectPadsClass * klass)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstCollectPadsPrivate));
|
2012-01-27 14:02:52 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (collect_pads_debug, "collectpads", 0,
|
|
|
|
"GstCollectPads");
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_collect_pads_finalize);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_init (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv =
|
2012-04-17 12:38:01 +00:00
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (pads, GST_TYPE_COLLECT_PADS,
|
|
|
|
GstCollectPadsPrivate);
|
2012-01-27 14:02:52 +00:00
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
pads->data = NULL;
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->cookie = 0;
|
|
|
|
pads->priv->numpads = 0;
|
|
|
|
pads->priv->queuedpads = 0;
|
|
|
|
pads->priv->eospads = 0;
|
|
|
|
pads->priv->started = FALSE;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rec_mutex_init (&pads->stream_lock);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
pads->priv->func = gst_collect_pads_default_collected;
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->user_data = NULL;
|
|
|
|
pads->priv->event_func = NULL;
|
|
|
|
pads->priv->event_user_data = NULL;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* members for default muxing */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->buffer_func = NULL;
|
|
|
|
pads->priv->buffer_user_data = NULL;
|
2012-04-17 12:38:01 +00:00
|
|
|
pads->priv->compare_func = gst_collect_pads_default_compare_func;
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->compare_user_data = NULL;
|
|
|
|
pads->priv->earliest_data = NULL;
|
|
|
|
pads->priv->earliest_time = GST_CLOCK_TIME_NONE;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
pads->priv->event_func = gst_collect_pads_event_default_internal;
|
|
|
|
pads->priv->query_func = gst_collect_pads_query_default_internal;
|
2012-04-16 14:24:10 +00:00
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/* members to manage the pad list */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->pad_cookie = 0;
|
|
|
|
pads->priv->pad_list = NULL;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* members for event */
|
2012-01-27 14:09:35 +00:00
|
|
|
g_mutex_init (&pads->priv->evt_lock);
|
|
|
|
g_cond_init (&pads->priv->evt_cond);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->evt_cookie = 0;
|
2013-09-16 07:55:58 +00:00
|
|
|
|
|
|
|
pads->priv->seeking = FALSE;
|
|
|
|
pads->priv->pending_flush_start = FALSE;
|
|
|
|
pads->priv->pending_flush_stop = FALSE;
|
2013-10-30 22:02:35 +00:00
|
|
|
|
|
|
|
/* clear floating flag */
|
|
|
|
gst_object_ref_sink (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_finalize (GObject * object)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPads *pads = GST_COLLECT_PADS (object);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (object, "finalize");
|
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rec_mutex_clear (&pads->stream_lock);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-01-27 14:09:35 +00:00
|
|
|
g_cond_clear (&pads->priv->evt_cond);
|
|
|
|
g_mutex_clear (&pads->priv->evt_lock);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* Remove pads and free pads list */
|
2012-01-27 14:02:52 +00:00
|
|
|
g_slist_foreach (pads->priv->pad_list, (GFunc) unref_data, NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_slist_foreach (pads->data, (GFunc) unref_data, NULL);
|
|
|
|
g_slist_free (pads->data);
|
2012-01-27 14:02:52 +00:00
|
|
|
g_slist_free (pads->priv->pad_list);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_new:
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
2012-09-19 08:44:08 +00:00
|
|
|
* Create a new instance of #GstCollectPads.
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Returns: (transfer full): a new #GstCollectPads, or %NULL in case of an error.
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPads *
|
|
|
|
gst_collect_pads_new (void)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPads *newcoll;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
newcoll = g_object_new (GST_TYPE_COLLECT_PADS, NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
return newcoll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called with GstObject lock! */
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_buffer_function_locked (GstCollectPads * pads,
|
|
|
|
GstCollectPadsBufferFunction func, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->buffer_func = func;
|
|
|
|
pads->priv->buffer_user_data = user_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_buffer_function:
|
2011-10-28 07:18:55 +00:00
|
|
|
* @pads: the collectpads to use
|
|
|
|
* @func: the function to set
|
2012-02-26 22:11:23 +00:00
|
|
|
* @user_data: (closure): user data passed to the function
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Set the callback function and user data that will be called with
|
2014-06-05 19:38:20 +00:00
|
|
|
* the oldest buffer when all pads have been collected, or %NULL on EOS.
|
2012-10-29 23:04:44 +00:00
|
|
|
* If a buffer is passed, the callback owns a reference and must unref
|
|
|
|
* it.
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_buffer_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsBufferFunction func, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_buffer_function_locked (pads, func, user_data);
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_compare_function:
|
2011-10-28 07:18:55 +00:00
|
|
|
* @pads: the pads to use
|
|
|
|
* @func: the function to set
|
2012-02-26 22:11:23 +00:00
|
|
|
* @user_data: (closure): user data passed to the function
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Set the timestamp comparison function.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
/* NOTE allowing to change comparison seems not advisable;
|
|
|
|
no known use-case, and collaboration with default algorithm is unpredictable.
|
|
|
|
If custom compairing/operation is needed, just use a collect function of
|
|
|
|
your own */
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_compare_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsCompareFunction func, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->compare_func = func;
|
|
|
|
pads->priv->compare_user_data = user_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_function:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 07:18:55 +00:00
|
|
|
* @func: the function to set
|
|
|
|
* @user_data: user data passed to the function
|
|
|
|
*
|
|
|
|
* CollectPads provides a default collection algorithm that will determine
|
|
|
|
* the oldest buffer available on all of its pads, and then delegate
|
|
|
|
* to a configured callback.
|
|
|
|
* However, if circumstances are more complicated and/or more control
|
|
|
|
* is desired, this sets a callback that will be invoked instead when
|
|
|
|
* all the pads added to the collection have buffers queued.
|
|
|
|
* Evidently, this callback is not compatible with
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_buffer_function() callback.
|
2011-10-28 07:18:55 +00:00
|
|
|
* If this callback is set, the former will be unset.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsFunction func, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->func = func;
|
|
|
|
pads->priv->user_data = user_data;
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_buffer_function_locked (pads, NULL, NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
ref_data (GstCollectData * data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_assert (data != NULL);
|
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
g_atomic_int_inc (&(data->priv->refcount));
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
unref_data (GstCollectData * data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_assert (data != NULL);
|
2012-01-27 14:02:52 +00:00
|
|
|
g_assert (data->priv->refcount > 0);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
if (!g_atomic_int_dec_and_test (&(data->priv->refcount)))
|
2011-10-28 07:18:55 +00:00
|
|
|
return;
|
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
if (data->priv->destroy_notify)
|
|
|
|
data->priv->destroy_notify (data);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
g_object_unref (data->pad);
|
|
|
|
if (data->buffer) {
|
|
|
|
gst_buffer_unref (data->buffer);
|
|
|
|
}
|
2012-01-27 14:02:52 +00:00
|
|
|
g_free (data->priv);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_event_function:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 07:18:55 +00:00
|
|
|
* @func: the function to set
|
|
|
|
* @user_data: user data passed to the function
|
|
|
|
*
|
2012-04-16 14:24:10 +00:00
|
|
|
* Set the event callback function and user data that will be called when
|
|
|
|
* collectpads has received an event originating from one of the collected
|
2011-10-28 07:18:55 +00:00
|
|
|
* pads. If the event being processed is a serialized one, this callback is
|
|
|
|
* called with @pads STREAM_LOCK held, otherwise not. As this lock should be
|
|
|
|
* held when calling a number of CollectPads functions, it should be acquired
|
|
|
|
* if so (unusually) needed.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_event_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsEventFunction func, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->event_func = func;
|
|
|
|
pads->priv->event_user_data = user_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:24:18 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_query_function:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-04-16 14:24:18 +00:00
|
|
|
* @func: the function to set
|
|
|
|
* @user_data: user data passed to the function
|
|
|
|
*
|
|
|
|
* Set the query callback function and user data that will be called after
|
|
|
|
* collectpads has received a query originating from one of the collected
|
|
|
|
* pads. If the query being processed is a serialized one, this callback is
|
|
|
|
* called with @pads STREAM_LOCK held, otherwise not. As this lock should be
|
|
|
|
* held when calling a number of CollectPads functions, it should be acquired
|
|
|
|
* if so (unusually) needed.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_query_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsQueryFunction func, gpointer user_data)
|
2012-04-16 14:24:18 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2012-04-16 14:24:18 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
|
|
|
pads->priv->query_func = func;
|
|
|
|
pads->priv->query_user_data = user_data;
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:59:22 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_clip_running_time:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-03-12 22:08:00 +00:00
|
|
|
* @cdata: collect data of corresponding pad
|
2011-12-16 16:59:22 +00:00
|
|
|
* @buf: buffer being clipped
|
2013-07-03 17:03:49 +00:00
|
|
|
* @outbuf: (allow-none): output buffer with running time, or NULL if clipped
|
2011-12-16 16:59:22 +00:00
|
|
|
* @user_data: user data (unused)
|
|
|
|
*
|
|
|
|
* Convenience clipping function that converts incoming buffer's timestamp
|
|
|
|
* to running time, or clips the buffer if outside configured segment.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clip_running_time (GstCollectPads * pads,
|
|
|
|
GstCollectData * cdata, GstBuffer * buf, GstBuffer ** outbuf,
|
2011-12-16 16:59:22 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstClockTime time;
|
|
|
|
|
|
|
|
*outbuf = buf;
|
2013-02-22 22:56:49 +00:00
|
|
|
time = GST_BUFFER_PTS (buf);
|
2011-12-16 16:59:22 +00:00
|
|
|
|
|
|
|
/* invalid left alone and passed */
|
|
|
|
if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (time))) {
|
|
|
|
time = gst_segment_to_running_time (&cdata->segment, GST_FORMAT_TIME, time);
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (time))) {
|
2014-01-08 13:52:04 +00:00
|
|
|
GST_DEBUG_OBJECT (cdata->pad, "clipping buffer on pad outside segment %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
|
2011-12-16 16:59:22 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
*outbuf = NULL;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (cdata->pad, "buffer ts %" GST_TIME_FORMAT " -> %"
|
|
|
|
GST_TIME_FORMAT " running time",
|
2013-02-22 22:56:49 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (time));
|
2011-12-25 12:13:57 +00:00
|
|
|
*outbuf = gst_buffer_make_writable (buf);
|
2013-02-22 22:56:49 +00:00
|
|
|
GST_BUFFER_PTS (*outbuf) = time;
|
|
|
|
GST_BUFFER_DTS (*outbuf) = gst_segment_to_running_time (&cdata->segment,
|
|
|
|
GST_FORMAT_TIME, GST_BUFFER_DTS (*outbuf));
|
2011-12-16 16:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-06 17:41:10 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_clip_function:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 08:17:06 +00:00
|
|
|
* @clipfunc: clip function to install
|
|
|
|
* @user_data: user data to pass to @clip_func
|
|
|
|
*
|
|
|
|
* Install a clipping function that is called right after a buffer is received
|
2012-10-15 18:56:36 +00:00
|
|
|
* on a pad managed by @pads. See #GstCollectPadsClipFunction for more info.
|
2011-10-28 08:17:06 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_clip_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsClipFunction clipfunc, gpointer user_data)
|
2011-10-28 08:17:06 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 08:17:06 +00:00
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->clip_func = clipfunc;
|
|
|
|
pads->priv->clip_user_data = user_data;
|
2011-10-28 08:17:06 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 17:41:10 +00:00
|
|
|
/**
|
|
|
|
* gst_collect_pads_set_flush_function:
|
|
|
|
* @pads: the collectpads to use
|
|
|
|
* @func: flush function to install
|
|
|
|
* @user_data: user data to pass to @func
|
|
|
|
*
|
|
|
|
* Install a flush function that is called when the internal
|
|
|
|
* state of all pads should be flushed as part of flushing seek
|
|
|
|
* handling. See #GstCollectPadsFlushFunction for more info.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2013-09-16 07:55:58 +00:00
|
|
|
void
|
|
|
|
gst_collect_pads_set_flush_function (GstCollectPads * pads,
|
|
|
|
GstCollectPadsFlushFunction func, gpointer user_data)
|
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
|
|
|
|
|
|
|
pads->priv->flush_func = func;
|
|
|
|
pads->priv->flush_user_data = user_data;
|
|
|
|
}
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_add_pad:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-02-26 22:11:23 +00:00
|
|
|
* @pad: (transfer none): the pad to add
|
2012-04-17 12:38:01 +00:00
|
|
|
* @size: the size of the returned #GstCollectData structure
|
|
|
|
* @destroy_notify: function to be called before the returned #GstCollectData
|
2011-10-28 07:18:55 +00:00
|
|
|
* structure is freed
|
|
|
|
* @lock: whether to lock this pad in usual waiting state
|
|
|
|
*
|
|
|
|
* Add a pad to the collection of collect pads. The pad has to be
|
|
|
|
* a sinkpad. The refcount of the pad is incremented. Use
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_remove_pad() to remove the pad from the collection
|
2011-10-28 07:18:55 +00:00
|
|
|
* again.
|
|
|
|
*
|
2012-04-17 12:38:01 +00:00
|
|
|
* You specify a size for the returned #GstCollectData structure
|
2011-10-28 07:18:55 +00:00
|
|
|
* so that you can use it to store additional information.
|
|
|
|
*
|
2012-04-17 12:38:01 +00:00
|
|
|
* You can also specify a #GstCollectDataDestroyNotify that will be called
|
|
|
|
* just before the #GstCollectData structure is freed. It is passed the
|
2011-10-28 07:18:55 +00:00
|
|
|
* pointer to the structure and should free any custom memory and resources
|
|
|
|
* allocated for it.
|
|
|
|
*
|
|
|
|
* Keeping a pad locked in waiting state is only relevant when using
|
|
|
|
* the default collection algorithm (providing the oldest buffer).
|
|
|
|
* It ensures a buffer must be available on this pad for a collection
|
|
|
|
* to take place. This is of typical use to a muxer element where
|
|
|
|
* non-subtitle streams should always be in waiting state,
|
|
|
|
* e.g. to assure that caps information is available on all these streams
|
|
|
|
* when initial headers have to be written.
|
|
|
|
*
|
|
|
|
* The pad will be automatically activated in push mode when @pads is
|
|
|
|
* started.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Returns: a new #GstCollectData to identify the new pad. Or %NULL
|
2011-10-28 07:18:55 +00:00
|
|
|
* if wrong parameters are supplied.
|
|
|
|
*/
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *
|
2012-09-12 18:54:50 +00:00
|
|
|
gst_collect_pads_add_pad (GstCollectPads * pads, GstPad * pad, guint size,
|
|
|
|
GstCollectDataDestroyNotify destroy_notify, gboolean lock)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_PAD_IS_SINK (pad), NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (size >= sizeof (GstCollectData), NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "adding pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
data = g_malloc0 (size);
|
2012-04-17 12:38:01 +00:00
|
|
|
data->priv = g_new0 (GstCollectDataPrivate, 1);
|
2011-10-28 07:18:55 +00:00
|
|
|
data->collect = pads;
|
|
|
|
data->pad = gst_object_ref (pad);
|
|
|
|
data->buffer = NULL;
|
|
|
|
data->pos = 0;
|
|
|
|
gst_segment_init (&data->segment, GST_FORMAT_UNDEFINED);
|
2012-04-17 12:38:01 +00:00
|
|
|
data->state = GST_COLLECT_PADS_STATE_WAITING;
|
|
|
|
data->state |= lock ? GST_COLLECT_PADS_STATE_LOCKED : 0;
|
2012-01-27 14:02:52 +00:00
|
|
|
data->priv->refcount = 1;
|
|
|
|
data->priv->destroy_notify = destroy_notify;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
gst_pad_set_element_private (pad, data);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->pad_list = g_slist_append (pads->priv->pad_list, data);
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_pad_set_chain_function (pad, GST_DEBUG_FUNCPTR (gst_collect_pads_chain));
|
|
|
|
gst_pad_set_event_function (pad, GST_DEBUG_FUNCPTR (gst_collect_pads_event));
|
|
|
|
gst_pad_set_query_function (pad, GST_DEBUG_FUNCPTR (gst_collect_pads_query));
|
2011-10-28 07:18:55 +00:00
|
|
|
/* backward compat, also add to data if stopped, so that the element already
|
|
|
|
* has this in the public data list before going PAUSED (typically)
|
|
|
|
* this can only be done when we are stopped because we don't take the
|
|
|
|
* STREAM_LOCK to protect the pads->data list. */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (!pads->priv->started) {
|
2011-10-28 07:18:55 +00:00
|
|
|
pads->data = g_slist_append (pads->data, data);
|
|
|
|
ref_data (data);
|
|
|
|
}
|
|
|
|
/* activate the pad when needed */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->started)
|
2011-10-28 07:18:55 +00:00
|
|
|
gst_pad_set_active (pad, TRUE);
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->pad_cookie++;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2012-04-17 12:38:01 +00:00
|
|
|
find_pad (GstCollectData * data, GstPad * pad)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
if (data->pad == pad)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_remove_pad:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-02-26 22:11:23 +00:00
|
|
|
* @pad: (transfer none): the pad to remove
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Remove a pad from the collection of collect pads. This function will also
|
2012-04-17 12:38:01 +00:00
|
|
|
* free the #GstCollectData and all the resources that were allocated with
|
|
|
|
* gst_collect_pads_add_pad().
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* The pad will be deactivated automatically when @pads is stopped.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* Returns: %TRUE if the pad could be removed.
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_remove_pad (GstCollectPads * pads, GstPad * pad)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, FALSE);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), FALSE);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (pad != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "removing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
list =
|
|
|
|
g_slist_find_custom (pads->priv->pad_list, pad, (GCompareFunc) find_pad);
|
2011-10-28 07:18:55 +00:00
|
|
|
if (!list)
|
|
|
|
goto unknown_pad;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
data = (GstCollectData *) list->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "found pad %s:%s at %p", GST_DEBUG_PAD_NAME (pad),
|
|
|
|
data);
|
|
|
|
|
|
|
|
/* clear the stuff we configured */
|
|
|
|
gst_pad_set_chain_function (pad, NULL);
|
|
|
|
gst_pad_set_event_function (pad, NULL);
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
gst_pad_set_element_private (pad, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
/* backward compat, also remove from data if stopped, note that this function
|
|
|
|
* can only be called when we are stopped because we don't take the
|
|
|
|
* STREAM_LOCK to protect the pads->data list. */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (!pads->priv->started) {
|
2011-10-28 07:18:55 +00:00
|
|
|
GSList *dlist;
|
|
|
|
|
|
|
|
dlist = g_slist_find_custom (pads->data, pad, (GCompareFunc) find_pad);
|
|
|
|
if (dlist) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *pdata = dlist->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
pads->data = g_slist_delete_link (pads->data, dlist);
|
|
|
|
unref_data (pdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* remove from the pad list */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->pad_list = g_slist_delete_link (pads->priv->pad_list, list);
|
|
|
|
pads->priv->pad_cookie++;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* signal waiters because something changed */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_BROADCAST (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* deactivate the pad when needed */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (!pads->priv->started)
|
2011-10-28 07:18:55 +00:00
|
|
|
gst_pad_set_active (pad, FALSE);
|
|
|
|
|
|
|
|
/* clean and free the collect data */
|
|
|
|
unref_data (data);
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
unknown_pad:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pads, "cannot remove unknown pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-09-24 08:42:06 +00:00
|
|
|
* Must be called with STREAM_LOCK and OBJECT_LOCK.
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_flushing_unlocked (GstCollectPads * pads,
|
2011-10-28 07:18:55 +00:00
|
|
|
gboolean flushing)
|
|
|
|
{
|
|
|
|
GSList *walk = NULL;
|
|
|
|
|
|
|
|
/* Update the pads flushing flag */
|
2013-09-17 21:23:34 +00:00
|
|
|
for (walk = pads->priv->pad_list; walk; walk = g_slist_next (walk)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *cdata = walk->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
if (GST_IS_PAD (cdata->pad)) {
|
|
|
|
GST_OBJECT_LOCK (cdata->pad);
|
|
|
|
if (flushing)
|
|
|
|
GST_PAD_SET_FLUSHING (cdata->pad);
|
|
|
|
else
|
|
|
|
GST_PAD_UNSET_FLUSHING (cdata->pad);
|
|
|
|
if (flushing)
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_SET (cdata, GST_COLLECT_PADS_STATE_FLUSHING);
|
2011-10-28 07:18:55 +00:00
|
|
|
else
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_UNSET (cdata, GST_COLLECT_PADS_STATE_FLUSHING);
|
|
|
|
gst_collect_pads_clear (pads, cdata);
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (cdata->pad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inform _chain of changes */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_BROADCAST (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_flushing:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 07:18:55 +00:00
|
|
|
* @flushing: desired state of the pads
|
|
|
|
*
|
|
|
|
* Change the flushing state of all the pads in the collection. No pad
|
|
|
|
* is able to accept anymore data when @flushing is %TRUE. Calling this
|
|
|
|
* function with @flushing %FALSE makes @pads accept data again.
|
|
|
|
* Caller must ensure that downstream streaming (thread) is not blocked,
|
|
|
|
* e.g. by sending a FLUSH_START downstream.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_flushing (GstCollectPads * pads, gboolean flushing)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* NOTE since this eventually calls _pop, some (STREAM_)LOCK is needed here */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2013-09-24 08:42:06 +00:00
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_flushing_unlocked (pads, flushing);
|
2013-09-24 08:42:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_start:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
2012-04-17 12:38:01 +00:00
|
|
|
* Starts the processing of data in the collect_pads.
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_start (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GSList *collected;
|
|
|
|
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "starting collect pads");
|
|
|
|
|
|
|
|
/* make sure stop and collect cannot be called anymore */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* make pads streamable */
|
|
|
|
GST_OBJECT_LOCK (pads);
|
|
|
|
|
|
|
|
/* loop over the master pad list and reset the segment */
|
2012-01-27 14:02:52 +00:00
|
|
|
collected = pads->priv->pad_list;
|
2011-10-28 07:18:55 +00:00
|
|
|
for (; collected; collected = g_slist_next (collected)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
data = collected->data;
|
|
|
|
gst_segment_init (&data->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
}
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_flushing_unlocked (pads, FALSE);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* Start collect pads */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->started = TRUE;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_stop:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
2012-04-17 12:38:01 +00:00
|
|
|
* Stops the processing of data in the collect_pads. this function
|
2011-10-28 07:18:55 +00:00
|
|
|
* will also unblock any blocking operations.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_stop (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GSList *collected;
|
|
|
|
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "stopping collect pads");
|
|
|
|
|
|
|
|
/* make sure collect and start cannot be called anymore */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* make pads not accept data anymore */
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_flushing_unlocked (pads, TRUE);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* Stop collect pads */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->started = FALSE;
|
|
|
|
pads->priv->eospads = 0;
|
|
|
|
pads->priv->queuedpads = 0;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* loop over the master pad list and flush buffers */
|
2012-01-27 14:02:52 +00:00
|
|
|
collected = pads->priv->pad_list;
|
2011-10-28 07:18:55 +00:00
|
|
|
for (; collected; collected = g_slist_next (collected)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstBuffer **buffer_p;
|
|
|
|
|
|
|
|
data = collected->data;
|
|
|
|
if (data->buffer) {
|
|
|
|
buffer_p = &data->buffer;
|
|
|
|
gst_buffer_replace (buffer_p, NULL);
|
|
|
|
data->pos = 0;
|
|
|
|
}
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_EOS);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->earliest_data)
|
|
|
|
unref_data (pads->priv->earliest_data);
|
|
|
|
pads->priv->earliest_data = NULL;
|
|
|
|
pads->priv->earliest_time = GST_CLOCK_TIME_NONE;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
/* Wake them up so they can end the chain functions. */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_BROADCAST (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_peek:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to peek
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
*
|
|
|
|
* Peek at the buffer currently queued in @data. This function
|
|
|
|
* should be called with the @pads STREAM_LOCK held, such as in the callback
|
|
|
|
* handler.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Returns: The buffer in @data or %NULL if no buffer is queued.
|
2011-10-28 07:18:55 +00:00
|
|
|
* should unref the buffer after usage.
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_peek (GstCollectPads * pads, GstCollectData * data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GstBuffer *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (data != NULL, NULL);
|
|
|
|
|
|
|
|
if ((result = data->buffer))
|
|
|
|
gst_buffer_ref (result);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "Peeking at pad %s:%s: buffer=%p",
|
|
|
|
GST_DEBUG_PAD_NAME (data->pad), result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_pop:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to pop
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
*
|
|
|
|
* Pop the buffer currently queued in @data. This function
|
|
|
|
* should be called with the @pads STREAM_LOCK held, such as in the callback
|
|
|
|
* handler.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Returns: (transfer full): The buffer in @data or %NULL if no buffer was
|
2012-02-26 22:11:23 +00:00
|
|
|
* queued. You should unref the buffer after usage.
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_pop (GstCollectPads * pads, GstCollectData * data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GstBuffer *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (data != NULL, NULL);
|
|
|
|
|
|
|
|
if ((result = data->buffer)) {
|
|
|
|
data->buffer = NULL;
|
|
|
|
data->pos = 0;
|
|
|
|
/* one less pad with queued data now */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_WAITING))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads--;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_BROADCAST (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "Pop buffer on pad %s:%s: buffer=%p",
|
|
|
|
GST_DEBUG_PAD_NAME (data->pad), result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop and unref the currently queued buffer, should be called with STREAM_LOCK
|
|
|
|
* held */
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clear (GstCollectPads * pads, GstCollectData * data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
if ((buf = gst_collect_pads_pop (pads, data)))
|
2011-10-28 07:18:55 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_available:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to query
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Query how much bytes can be read from each queued buffer. This means
|
|
|
|
* that the result of this call is the maximum number of bytes that can
|
|
|
|
* be read from each of the pads.
|
|
|
|
*
|
|
|
|
* This function should be called with @pads STREAM_LOCK held, such as
|
|
|
|
* in the callback.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2011-10-28 07:18:55 +00:00
|
|
|
* Returns: The maximum number of bytes queued on all pads. This function
|
|
|
|
* returns 0 if a pad has no queued buffer.
|
|
|
|
*/
|
|
|
|
/* we might pre-calculate this in some struct field,
|
|
|
|
* but would then have to maintain this in _chain and particularly _pop, etc,
|
|
|
|
* even if element is never interested in this information */
|
|
|
|
guint
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_available (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GSList *collected;
|
|
|
|
guint result = G_MAXUINT;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, 0);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), 0);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
collected = pads->data;
|
|
|
|
for (; collected; collected = g_slist_next (collected)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *pdata;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
gint size;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
pdata = (GstCollectData *) collected->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* ignore pad with EOS */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_UNLIKELY (GST_COLLECT_PADS_STATE_IS_SET (pdata,
|
|
|
|
GST_COLLECT_PADS_STATE_EOS))) {
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_DEBUG_OBJECT (pads, "pad %p is EOS", pdata);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* an empty buffer without EOS is weird when we get here.. */
|
|
|
|
if (G_UNLIKELY ((buffer = pdata->buffer) == NULL)) {
|
|
|
|
GST_WARNING_OBJECT (pads, "pad %p has no buffer", pdata);
|
|
|
|
goto not_filled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the size left of the buffer */
|
2011-10-28 09:30:57 +00:00
|
|
|
size = gst_buffer_get_size (buffer) - pdata->pos;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_DEBUG_OBJECT (pads, "pad %p has %d bytes left", pdata, size);
|
|
|
|
|
|
|
|
/* need to return the min of all available data */
|
|
|
|
if (size < result)
|
|
|
|
result = size;
|
|
|
|
}
|
|
|
|
/* nothing changed, all must be EOS then, return 0 */
|
|
|
|
if (G_UNLIKELY (result == G_MAXUINT))
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
not_filled:
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_flush:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to query
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
* @size: the number of bytes to flush
|
|
|
|
*
|
|
|
|
* Flush @size bytes from the pad @data.
|
|
|
|
*
|
|
|
|
* This function should be called with @pads STREAM_LOCK held, such as
|
|
|
|
* in the callback.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2011-10-28 07:18:55 +00:00
|
|
|
* Returns: The number of bytes flushed This can be less than @size and
|
|
|
|
* is 0 if the pad was end-of-stream.
|
|
|
|
*/
|
|
|
|
guint
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_flush (GstCollectPads * pads, GstCollectData * data,
|
2011-10-28 07:18:55 +00:00
|
|
|
guint size)
|
|
|
|
{
|
|
|
|
guint flushsize;
|
2011-10-28 09:30:57 +00:00
|
|
|
gsize bsize;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, 0);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), 0);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (data != NULL, 0);
|
|
|
|
|
|
|
|
/* no buffer, must be EOS */
|
|
|
|
if ((buffer = data->buffer) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
bsize = gst_buffer_get_size (buffer);
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/* this is what we can flush at max */
|
2011-10-28 09:30:57 +00:00
|
|
|
flushsize = MIN (size, bsize - data->pos);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
data->pos += size;
|
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
if (data->pos >= bsize)
|
2011-10-28 07:18:55 +00:00
|
|
|
/* _clear will also reset data->pos to 0 */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clear (pads, data);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
return flushsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_read_buffer:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to query
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
* @size: the number of bytes to read
|
|
|
|
*
|
|
|
|
* Get a subbuffer of @size bytes from the given pad @data.
|
|
|
|
*
|
|
|
|
* This function should be called with @pads STREAM_LOCK held, such as in the
|
|
|
|
* callback.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2012-02-26 22:11:23 +00:00
|
|
|
* Returns: (transfer full): A sub buffer. The size of the buffer can be less that requested.
|
2014-06-05 19:38:20 +00:00
|
|
|
* A return of %NULL signals that the pad is end-of-stream.
|
2011-10-28 07:18:55 +00:00
|
|
|
* Unref the buffer after use.
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
|
2011-10-28 07:18:55 +00:00
|
|
|
guint size)
|
|
|
|
{
|
|
|
|
guint readsize;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pads != NULL, NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), NULL);
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_val_if_fail (data != NULL, NULL);
|
|
|
|
|
|
|
|
/* no buffer, must be EOS */
|
|
|
|
if ((buffer = data->buffer) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
readsize = MIN (size, gst_buffer_get_size (buffer) - data->pos);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
return gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, data->pos,
|
|
|
|
readsize);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_take_buffer:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to query
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
* @size: the number of bytes to read
|
|
|
|
*
|
|
|
|
* Get a subbuffer of @size bytes from the given pad @data. Flushes the amount
|
|
|
|
* of read bytes.
|
|
|
|
*
|
|
|
|
* This function should be called with @pads STREAM_LOCK held, such as in the
|
|
|
|
* callback.
|
|
|
|
*
|
2012-02-26 21:57:02 +00:00
|
|
|
* MT safe.
|
|
|
|
*
|
2011-10-28 07:18:55 +00:00
|
|
|
* Returns: A sub buffer. The size of the buffer can be less that requested.
|
2014-06-05 19:38:20 +00:00
|
|
|
* A return of %NULL signals that the pad is end-of-stream.
|
2011-10-28 07:18:55 +00:00
|
|
|
* Unref the buffer after use.
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data,
|
2011-10-28 07:18:55 +00:00
|
|
|
guint size)
|
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstBuffer *buffer = gst_collect_pads_read_buffer (pads, data, size);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
if (buffer) {
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_flush (pads, data, gst_buffer_get_size (buffer));
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_set_waiting:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads
|
2011-10-28 07:18:55 +00:00
|
|
|
* @data: the data to use
|
|
|
|
* @waiting: boolean indicating whether this pad should operate
|
|
|
|
* in waiting or non-waiting mode
|
|
|
|
*
|
|
|
|
* Sets a pad to waiting or non-waiting mode, if at least this pad
|
|
|
|
* has not been created with locked waiting state,
|
|
|
|
* in which case nothing happens.
|
|
|
|
*
|
|
|
|
* This function should be called with @pads STREAM_LOCK held, such as
|
|
|
|
* in the callback.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_waiting (GstCollectPads * pads, GstCollectData * data,
|
2011-10-28 07:18:55 +00:00
|
|
|
gboolean waiting)
|
|
|
|
{
|
|
|
|
g_return_if_fail (pads != NULL);
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_if_fail (GST_IS_COLLECT_PADS (pads));
|
2011-10-28 07:18:55 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "Setting pad %s to waiting %d, locked %d",
|
|
|
|
GST_PAD_NAME (data->pad), waiting,
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_LOCKED));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* Do something only on a change and if not locked */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (!GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_LOCKED) &&
|
|
|
|
(GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_WAITING) !=
|
2013-11-06 17:05:22 +00:00
|
|
|
! !waiting)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
/* Set waiting state for this pad */
|
|
|
|
if (waiting)
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_WAITING);
|
2011-10-28 07:18:55 +00:00
|
|
|
else
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_WAITING);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* Update number of queued pads if needed */
|
|
|
|
if (!data->buffer &&
|
2012-04-17 12:38:01 +00:00
|
|
|
!GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_EOS)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
if (waiting)
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads--;
|
2011-10-28 07:18:55 +00:00
|
|
|
else
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads++;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* signal waiters because something changed */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_BROADCAST (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see if pads were added or removed and update our stats. Any pad
|
|
|
|
* added after releasing the LOCK will get collected in the next
|
|
|
|
* round.
|
|
|
|
*
|
|
|
|
* We can do a quick check by checking the cookies, that get changed
|
|
|
|
* whenever the pad list is updated.
|
|
|
|
*
|
|
|
|
* Must be called with STREAM_LOCK.
|
|
|
|
*/
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_check_pads (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
/* the master list and cookie are protected with LOCK */
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
if (G_UNLIKELY (pads->priv->pad_cookie != pads->priv->cookie)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
GSList *collected;
|
|
|
|
|
|
|
|
/* clear list and stats */
|
|
|
|
g_slist_foreach (pads->data, (GFunc) unref_data, NULL);
|
|
|
|
g_slist_free (pads->data);
|
|
|
|
pads->data = NULL;
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->numpads = 0;
|
|
|
|
pads->priv->queuedpads = 0;
|
|
|
|
pads->priv->eospads = 0;
|
|
|
|
if (pads->priv->earliest_data)
|
|
|
|
unref_data (pads->priv->earliest_data);
|
|
|
|
pads->priv->earliest_data = NULL;
|
|
|
|
pads->priv->earliest_time = GST_CLOCK_TIME_NONE;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* loop over the master pad list */
|
2012-01-27 14:02:52 +00:00
|
|
|
collected = pads->priv->pad_list;
|
2011-10-28 07:18:55 +00:00
|
|
|
for (; collected; collected = g_slist_next (collected)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* update the stats */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->numpads++;
|
2011-10-28 07:18:55 +00:00
|
|
|
data = collected->data;
|
2012-04-17 12:38:01 +00:00
|
|
|
if (GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_EOS))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->eospads++;
|
2012-04-17 12:38:01 +00:00
|
|
|
else if (data->buffer || !GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_WAITING))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads++;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* add to the list of pads to collect */
|
|
|
|
ref_data (data);
|
|
|
|
/* preserve order of adding/requesting pads */
|
|
|
|
pads->data = g_slist_append (pads->data, data);
|
|
|
|
}
|
|
|
|
/* and update the cookie */
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->cookie = pads->priv->pad_cookie;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* checks if all the pads are collected and call the collectfunction
|
|
|
|
*
|
|
|
|
* Should be called with STREAM_LOCK.
|
|
|
|
*
|
|
|
|
* Returns: The #GstFlowReturn of collection.
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_check_collected (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn flow_ret = GST_FLOW_OK;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsFunction func;
|
2011-10-28 07:18:55 +00:00
|
|
|
gpointer user_data;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), GST_FLOW_ERROR);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
func = pads->priv->func;
|
|
|
|
user_data = pads->priv->user_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
g_return_val_if_fail (pads->priv->func != NULL, GST_FLOW_NOT_SUPPORTED);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* check for new pads, update stats etc.. */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_check_pads (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
if (G_UNLIKELY (pads->priv->eospads == pads->priv->numpads)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
/* If all our pads are EOS just collect once to let the element
|
|
|
|
* do its final EOS handling. */
|
|
|
|
GST_DEBUG_OBJECT (pads, "All active pads (%d) are EOS, calling %s",
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->numpads, GST_DEBUG_FUNCPTR_NAME (func));
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
if (G_UNLIKELY (g_atomic_int_compare_and_exchange (&pads->priv->seeking,
|
|
|
|
TRUE, FALSE) == TRUE)) {
|
|
|
|
GST_INFO_OBJECT (pads, "finished seeking");
|
|
|
|
}
|
2013-10-09 18:36:48 +00:00
|
|
|
do {
|
|
|
|
flow_ret = func (pads, user_data);
|
|
|
|
} while (flow_ret == GST_FLOW_OK);
|
2011-10-28 07:18:55 +00:00
|
|
|
} else {
|
|
|
|
gboolean collected = FALSE;
|
|
|
|
|
|
|
|
/* We call the collected function as long as our condition matches. */
|
2012-01-27 14:02:52 +00:00
|
|
|
while (((pads->priv->queuedpads + pads->priv->eospads) >=
|
|
|
|
pads->priv->numpads)) {
|
|
|
|
GST_DEBUG_OBJECT (pads,
|
|
|
|
"All active pads (%d + %d >= %d) have data, " "calling %s",
|
|
|
|
pads->priv->queuedpads, pads->priv->eospads, pads->priv->numpads,
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_DEBUG_FUNCPTR_NAME (func));
|
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
if (G_UNLIKELY (g_atomic_int_compare_and_exchange (&pads->priv->seeking,
|
|
|
|
TRUE, FALSE) == TRUE)) {
|
|
|
|
GST_INFO_OBJECT (pads, "finished seeking");
|
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
flow_ret = func (pads, user_data);
|
|
|
|
collected = TRUE;
|
|
|
|
|
|
|
|
/* break on error */
|
|
|
|
if (flow_ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
/* Don't keep looping after telling the element EOS or flushing */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->queuedpads == 0)
|
2011-10-28 07:18:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!collected)
|
|
|
|
GST_DEBUG_OBJECT (pads, "Not all active pads (%d) have data, continuing",
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->numpads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
return flow_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* General overview:
|
|
|
|
* - only pad with a buffer can determine earliest_data (and earliest_time)
|
|
|
|
* - only segment info determines (non-)waiting state
|
|
|
|
* - ? perhaps use _stream_time for comparison
|
|
|
|
* (which muxers might have use as well ?)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to recalculate the waiting state of all pads.
|
|
|
|
*
|
|
|
|
* Must be called with STREAM_LOCK.
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Returns %TRUE if a pad was set to waiting
|
2011-10-28 07:18:55 +00:00
|
|
|
* (from non-waiting state).
|
|
|
|
*/
|
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_recalculate_waiting (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GSList *collected;
|
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
/* If earliest time is not known, there is nothing to do. */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->earliest_data == NULL)
|
2011-10-28 07:18:55 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (collected = pads->data; collected; collected = g_slist_next (collected)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data = (GstCollectData *) collected->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
int cmp_res;
|
2012-09-05 13:37:13 +00:00
|
|
|
GstClockTime comp_time;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* check if pad has a segment */
|
2012-02-03 17:08:35 +00:00
|
|
|
if (data->segment.format == GST_FORMAT_UNDEFINED) {
|
|
|
|
GST_WARNING_OBJECT (pads,
|
2012-04-17 12:38:01 +00:00
|
|
|
"GstCollectPads has no time segment, assuming 0 based.");
|
2012-02-03 17:08:35 +00:00
|
|
|
gst_segment_init (&data->segment, GST_FORMAT_TIME);
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_NEW_SEGMENT);
|
2012-02-03 17:08:35 +00:00
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* check segment format */
|
|
|
|
if (data->segment.format != GST_FORMAT_TIME) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_ERROR_OBJECT (pads, "GstCollectPads can handle only time segments.");
|
2011-10-28 07:18:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the waiting state should be changed */
|
2012-10-10 09:35:01 +00:00
|
|
|
comp_time = data->segment.position;
|
2012-09-05 13:37:13 +00:00
|
|
|
cmp_res = pads->priv->compare_func (pads, data, comp_time,
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->earliest_data, pads->priv->earliest_time,
|
|
|
|
pads->priv->compare_user_data);
|
2011-10-28 07:18:55 +00:00
|
|
|
if (cmp_res > 0)
|
|
|
|
/* stop waiting */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_waiting (pads, data, FALSE);
|
2011-10-28 07:18:55 +00:00
|
|
|
else {
|
2012-04-17 12:38:01 +00:00
|
|
|
if (!GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_WAITING)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
/* start waiting */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_waiting (pads, data, TRUE);
|
2011-10-28 07:18:55 +00:00
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_find_best_pad:
|
2011-10-28 07:18:55 +00:00
|
|
|
* @pads: the collectpads to use
|
|
|
|
* @data: returns the collectdata for earliest data
|
|
|
|
* @time: returns the earliest available buffertime
|
|
|
|
*
|
|
|
|
* Find the oldest/best pad, i.e. pad holding the oldest buffer and
|
2012-04-17 12:38:01 +00:00
|
|
|
* and return the corresponding #GstCollectData and buffertime.
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* This function should be called with STREAM_LOCK held,
|
|
|
|
* such as in the callback.
|
|
|
|
*/
|
|
|
|
static void
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_find_best_pad (GstCollectPads * pads,
|
|
|
|
GstCollectData ** data, GstClockTime * time)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
GSList *collected;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *best = NULL;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstClockTime best_time = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
g_return_if_fail (time != NULL);
|
|
|
|
|
|
|
|
for (collected = pads->data; collected; collected = g_slist_next (collected)) {
|
|
|
|
GstBuffer *buffer;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data = (GstCollectData *) collected->data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstClockTime timestamp;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
buffer = gst_collect_pads_peek (pads, data);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* if we have a buffer check if it is better then the current best one */
|
|
|
|
if (buffer != NULL) {
|
2013-02-22 22:56:49 +00:00
|
|
|
timestamp = GST_BUFFER_DTS (buffer);
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
|
|
|
timestamp = GST_BUFFER_PTS (buffer);
|
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2012-01-27 14:02:52 +00:00
|
|
|
if (best == NULL || pads->priv->compare_func (pads, data, timestamp,
|
|
|
|
best, best_time, pads->priv->compare_user_data) < 0) {
|
2011-10-28 07:18:55 +00:00
|
|
|
best = data;
|
|
|
|
best_time = timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set earliest time */
|
|
|
|
*data = best;
|
|
|
|
*time = best_time;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "best pad %s, best time %" GST_TIME_FORMAT,
|
2012-04-17 12:38:01 +00:00
|
|
|
best ? GST_PAD_NAME (((GstCollectData *) best)->pad) : "(nil)",
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_TIME_ARGS (best_time));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to recalculate earliest_data and earliest_timestamp. This also calls
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_recalculate_waiting
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Must be called with STREAM_LOCK.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_recalculate_full (GstCollectPads * pads)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->earliest_data)
|
|
|
|
unref_data (pads->priv->earliest_data);
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_find_best_pad (pads, &pads->priv->earliest_data,
|
2012-01-27 14:02:52 +00:00
|
|
|
&pads->priv->earliest_time);
|
|
|
|
if (pads->priv->earliest_data)
|
|
|
|
ref_data (pads->priv->earliest_data);
|
2012-04-17 12:38:01 +00:00
|
|
|
return gst_collect_pads_recalculate_waiting (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-04-17 12:38:01 +00:00
|
|
|
* Default collect callback triggered when #GstCollectPads gathered all data.
|
2011-10-28 07:18:55 +00:00
|
|
|
*
|
|
|
|
* Called with STREAM_LOCK.
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_default_collected (GstCollectPads * pads, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *best = NULL;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsBufferFunction func;
|
2011-10-28 07:18:55 +00:00
|
|
|
gpointer buffer_user_data;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), GST_FLOW_ERROR);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
func = pads->priv->buffer_func;
|
|
|
|
buffer_user_data = pads->priv->buffer_user_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
|
|
|
g_return_val_if_fail (func != NULL, GST_FLOW_NOT_SUPPORTED);
|
|
|
|
|
|
|
|
/* Find the oldest pad at all cost */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (gst_collect_pads_recalculate_full (pads)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
/* waiting was switched on,
|
|
|
|
* so give another thread a chance to deliver a possibly
|
|
|
|
* older buffer; don't charge on yet with the current oldest */
|
|
|
|
ret = GST_FLOW_OK;
|
2011-12-15 13:31:05 +00:00
|
|
|
goto done;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 14:02:52 +00:00
|
|
|
best = pads->priv->earliest_data;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* No data collected means EOS. */
|
|
|
|
if (G_UNLIKELY (best == NULL)) {
|
|
|
|
ret = func (pads, best, NULL, buffer_user_data);
|
|
|
|
if (ret == GST_FLOW_OK)
|
2012-01-03 14:25:31 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2011-10-28 07:18:55 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure that the pad we take a buffer from is waiting;
|
|
|
|
* otherwise popping a buffer will seem not to have happened
|
|
|
|
* and collectpads can get into a busy loop */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_waiting (pads, best, TRUE);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* Send buffer */
|
2012-04-17 12:38:01 +00:00
|
|
|
buffer = gst_collect_pads_pop (pads, best);
|
2011-10-28 07:18:55 +00:00
|
|
|
ret = func (pads, best, buffer, buffer_user_data);
|
|
|
|
|
2011-09-27 13:48:52 +00:00
|
|
|
/* maybe non-waiting was forced to waiting above due to
|
|
|
|
* newsegment events coming too sparsely,
|
|
|
|
* so re-check to restore state to avoid hanging/waiting */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_recalculate_full (pads);
|
2011-09-27 13:48:52 +00:00
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default timestamp compare function.
|
|
|
|
*/
|
|
|
|
static gint
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_default_compare_func (GstCollectPads * pads,
|
|
|
|
GstCollectData * data1, GstClockTime timestamp1,
|
|
|
|
GstCollectData * data2, GstClockTime timestamp2, gpointer user_data)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pads, "comparing %" GST_TIME_FORMAT
|
|
|
|
" and %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp1),
|
|
|
|
GST_TIME_ARGS (timestamp2));
|
|
|
|
/* non-valid timestamps go first as they are probably headers or so */
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp1)))
|
|
|
|
return GST_CLOCK_TIME_IS_VALID (timestamp2) ? -1 : 0;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp2)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* compare timestamp */
|
|
|
|
if (timestamp1 < timestamp2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (timestamp1 > timestamp2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-05 13:37:13 +00:00
|
|
|
/* called with STREAM_LOCK */
|
|
|
|
static void
|
|
|
|
gst_collect_pads_handle_position_update (GstCollectPads * pads,
|
|
|
|
GstCollectData * data, GstClockTime new_pos)
|
|
|
|
{
|
|
|
|
gint cmp_res;
|
|
|
|
|
|
|
|
/* If oldest time is not known, or current pad got newsegment;
|
|
|
|
* recalculate the state */
|
|
|
|
if (!pads->priv->earliest_data || pads->priv->earliest_data == data) {
|
|
|
|
gst_collect_pads_recalculate_full (pads);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the waiting state of the pad should change. */
|
|
|
|
cmp_res =
|
|
|
|
pads->priv->compare_func (pads, data, new_pos,
|
|
|
|
pads->priv->earliest_data, pads->priv->earliest_time,
|
|
|
|
pads->priv->compare_user_data);
|
|
|
|
|
|
|
|
if (cmp_res > 0)
|
|
|
|
/* Stop waiting */
|
|
|
|
gst_collect_pads_set_waiting (pads, data, FALSE);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-10 09:35:01 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_collect_pads_clip_time (GstCollectPads * pads, GstCollectData * data,
|
|
|
|
GstClockTime time)
|
|
|
|
{
|
|
|
|
GstClockTime otime = time;
|
|
|
|
GstBuffer *in, *out = NULL;
|
|
|
|
|
|
|
|
if (pads->priv->clip_func) {
|
|
|
|
in = gst_buffer_new ();
|
2013-02-22 22:56:49 +00:00
|
|
|
GST_BUFFER_PTS (in) = time;
|
|
|
|
GST_BUFFER_DTS (in) = time;
|
2012-10-15 16:44:52 +00:00
|
|
|
pads->priv->clip_func (pads, data, in, &out, pads->priv->clip_user_data);
|
2012-10-10 09:35:01 +00:00
|
|
|
if (out) {
|
2013-02-22 22:56:49 +00:00
|
|
|
otime = GST_BUFFER_PTS (out);
|
2012-10-15 18:55:42 +00:00
|
|
|
gst_buffer_unref (out);
|
2012-10-10 09:35:01 +00:00
|
|
|
} else {
|
|
|
|
/* FIXME should distinguish between ahead or after segment,
|
|
|
|
* let's assume after segment and use some large time ... */
|
|
|
|
otime = G_MAXINT64 / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return otime;
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_event_default:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-04-16 14:24:10 +00:00
|
|
|
* @data: collect data of corresponding pad
|
|
|
|
* @event: event being processed
|
|
|
|
* @discard: process but do not send event downstream
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Default #GstCollectPads event handling that elements should always
|
2012-04-16 14:24:10 +00:00
|
|
|
* chain up to to ensure proper operation. Element might however indicate
|
|
|
|
* event should not be forwarded downstream.
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_event_default (GstCollectPads * pads, GstCollectData * data,
|
2012-04-16 14:24:10 +00:00
|
|
|
GstEvent * event, gboolean discard)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-16 14:24:10 +00:00
|
|
|
gboolean res = TRUE;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectPadsBufferFunction buffer_func;
|
2012-04-16 14:24:10 +00:00
|
|
|
GstObject *parent;
|
|
|
|
GstPad *pad;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
2012-01-27 14:02:52 +00:00
|
|
|
buffer_func = pads->priv->buffer_func;
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
pad = data->pad;
|
|
|
|
parent = GST_OBJECT_PARENT (pad);
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
{
|
2013-09-16 07:55:58 +00:00
|
|
|
if (g_atomic_int_get (&pads->priv->seeking)) {
|
|
|
|
/* drop all but the first FLUSH_STARTs when seeking */
|
|
|
|
if (g_atomic_int_compare_and_exchange (&pads->priv->pending_flush_start,
|
|
|
|
TRUE, FALSE) == FALSE)
|
|
|
|
goto eat;
|
|
|
|
|
|
|
|
/* unblock collect pads */
|
|
|
|
gst_pad_event_default (pad, parent, event);
|
|
|
|
event = NULL;
|
|
|
|
|
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
|
|
|
/* Start flushing. We never call gst_collect_pads_set_flushing (FALSE), we
|
|
|
|
* instead wait until each pad gets its FLUSH_STOP and let that reset the pad to
|
|
|
|
* non-flushing (which happens in gst_collect_pads_event_default).
|
|
|
|
*/
|
|
|
|
gst_collect_pads_set_flushing (pads, TRUE);
|
|
|
|
|
|
|
|
if (pads->priv->flush_func)
|
|
|
|
pads->priv->flush_func (pads, pads->priv->flush_user_data);
|
|
|
|
|
|
|
|
g_atomic_int_set (&pads->priv->pending_flush_stop, TRUE);
|
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
|
|
|
|
|
|
|
goto eat;
|
|
|
|
} else {
|
|
|
|
/* forward event to unblock check_collected */
|
|
|
|
GST_DEBUG_OBJECT (pad, "forwarding flush start");
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
event = NULL;
|
|
|
|
|
|
|
|
/* now unblock the chain function.
|
|
|
|
* no cond per pad, so they all unblock,
|
|
|
|
* non-flushing block again */
|
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_FLUSHING);
|
|
|
|
gst_collect_pads_clear (pads, data);
|
|
|
|
|
|
|
|
/* cater for possible default muxing functionality */
|
|
|
|
if (buffer_func) {
|
|
|
|
/* restore to initial state */
|
|
|
|
gst_collect_pads_set_waiting (pads, data, TRUE);
|
|
|
|
/* if the current pad is affected, reset state, recalculate later */
|
|
|
|
if (pads->priv->earliest_data == data) {
|
|
|
|
unref_data (data);
|
|
|
|
pads->priv->earliest_data = NULL;
|
|
|
|
pads->priv->earliest_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
goto eat;
|
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
{
|
|
|
|
/* flush the 1 buffer queue */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
|
|
|
GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_FLUSHING);
|
|
|
|
gst_collect_pads_clear (pads, data);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* we need new segment info after the flush */
|
|
|
|
gst_segment_init (&data->segment, GST_FORMAT_UNDEFINED);
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_NEW_SEGMENT);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* if the pad was EOS, remove the EOS flag and
|
|
|
|
* decrement the number of eospads */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_UNLIKELY (GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_EOS))) {
|
|
|
|
if (!GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_WAITING))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads++;
|
2014-02-19 01:27:36 +00:00
|
|
|
if (!g_atomic_int_get (&pads->priv->seeking)) {
|
|
|
|
pads->priv->eospads--;
|
|
|
|
}
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_EOS);
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
if (g_atomic_int_get (&pads->priv->seeking)) {
|
|
|
|
if (g_atomic_int_compare_and_exchange (&pads->priv->pending_flush_stop,
|
|
|
|
TRUE, FALSE))
|
|
|
|
goto forward;
|
|
|
|
else
|
|
|
|
goto eat;
|
|
|
|
} else {
|
|
|
|
goto forward;
|
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* if the pad was not EOS, make it EOS and so we
|
|
|
|
* have one more eospad */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_LIKELY (!GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_EOS))) {
|
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_EOS);
|
|
|
|
if (!GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_WAITING))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads--;
|
|
|
|
pads->priv->eospads++;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
/* check if we need collecting anything, we ignore the result. */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_check_collected (pads);
|
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
goto eat;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
2011-10-28 09:30:57 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2011-10-28 09:30:57 +00:00
|
|
|
GstSegment seg;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
gst_event_copy_segment (event, &seg);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2011-10-28 09:30:57 +00:00
|
|
|
GST_DEBUG_OBJECT (data->pad, "got segment %" GST_SEGMENT_FORMAT, &seg);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* default collection can not handle other segment formats than time */
|
2012-04-17 10:29:50 +00:00
|
|
|
if (buffer_func && seg.format != GST_FORMAT_TIME) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_WARNING_OBJECT (pads, "GstCollectPads default collecting "
|
2012-02-03 17:08:35 +00:00
|
|
|
"can only handle time segments. Non time segment ignored.");
|
2011-10-28 07:18:55 +00:00
|
|
|
goto newsegment_done;
|
|
|
|
}
|
|
|
|
|
2012-10-10 09:35:01 +00:00
|
|
|
/* need to update segment first */
|
2012-04-16 14:29:34 +00:00
|
|
|
data->segment = seg;
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_NEW_SEGMENT);
|
2012-02-03 17:08:35 +00:00
|
|
|
|
2012-10-10 09:35:01 +00:00
|
|
|
/* now we can use for e.g. running time */
|
2014-01-08 13:52:04 +00:00
|
|
|
seg.position =
|
|
|
|
gst_collect_pads_clip_time (pads, data, seg.start + seg.offset);
|
2012-10-10 09:35:01 +00:00
|
|
|
/* update again */
|
|
|
|
data->segment = seg;
|
|
|
|
|
2012-04-17 10:23:05 +00:00
|
|
|
/* default muxing functionality */
|
|
|
|
if (!buffer_func)
|
|
|
|
goto newsegment_done;
|
|
|
|
|
2012-10-10 09:35:01 +00:00
|
|
|
gst_collect_pads_handle_position_update (pads, data, seg.position);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
newsegment_done:
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* we must not forward this event since multiple segments will be
|
|
|
|
* accumulated and this is certainly not what we want. */
|
2012-04-16 14:24:10 +00:00
|
|
|
goto eat;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
2012-09-05 13:37:13 +00:00
|
|
|
case GST_EVENT_GAP:
|
|
|
|
{
|
|
|
|
GstClockTime start, duration;
|
|
|
|
|
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
|
|
|
|
|
|
|
gst_event_parse_gap (event, &start, &duration);
|
2014-01-08 13:52:04 +00:00
|
|
|
/* FIXME, handle reverse playback case */
|
2012-09-05 13:37:13 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration))
|
|
|
|
start += duration;
|
|
|
|
/* we do not expect another buffer until after gap,
|
|
|
|
* so that is our position now */
|
2012-10-10 09:35:01 +00:00
|
|
|
data->segment.position = gst_collect_pads_clip_time (pads, data, start);
|
2012-09-05 13:37:13 +00:00
|
|
|
|
2012-10-10 09:35:01 +00:00
|
|
|
gst_collect_pads_handle_position_update (pads, data,
|
|
|
|
data->segment.position);
|
2012-09-05 13:37:13 +00:00
|
|
|
|
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
|
|
|
goto eat;
|
|
|
|
}
|
2012-01-27 09:46:02 +00:00
|
|
|
case GST_EVENT_STREAM_START:
|
2012-09-23 11:42:01 +00:00
|
|
|
/* drop stream start events, element must create its own start event,
|
|
|
|
* we can't just forward the first random stream start event we get */
|
|
|
|
goto eat;
|
2012-07-09 17:56:15 +00:00
|
|
|
case GST_EVENT_CAPS:
|
2012-04-16 14:24:10 +00:00
|
|
|
goto eat;
|
2011-10-28 07:18:55 +00:00
|
|
|
default:
|
|
|
|
/* forward other events */
|
2012-04-16 14:24:10 +00:00
|
|
|
goto forward;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
eat:
|
2012-04-23 15:04:57 +00:00
|
|
|
if (event)
|
|
|
|
gst_event_unref (event);
|
2012-04-16 14:24:10 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
forward:
|
|
|
|
if (discard)
|
|
|
|
goto eat;
|
|
|
|
else
|
|
|
|
return gst_pad_event_default (pad, parent, event);
|
|
|
|
}
|
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
gboolean result;
|
|
|
|
} EventData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
event_forward_func (GstPad * pad, EventData * data)
|
|
|
|
{
|
2014-02-16 19:35:09 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
GstPad *peer = gst_pad_get_peer (pad);
|
2013-11-06 17:46:19 +00:00
|
|
|
|
2014-03-16 16:47:06 +00:00
|
|
|
if (peer) {
|
2014-02-16 19:35:09 +00:00
|
|
|
ret = gst_pad_send_event (peer, gst_event_ref (data->event));
|
2014-03-16 16:47:06 +00:00
|
|
|
gst_object_unref (peer);
|
|
|
|
}
|
2014-02-16 19:35:09 +00:00
|
|
|
|
|
|
|
data->result &= ret;
|
2013-11-06 17:46:19 +00:00
|
|
|
/* Always send to all pads */
|
|
|
|
return FALSE;
|
2013-09-16 07:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
forward_event_to_all_sinkpads (GstPad * srcpad, GstEvent * event)
|
|
|
|
{
|
|
|
|
EventData data;
|
|
|
|
|
|
|
|
data.event = event;
|
|
|
|
data.result = TRUE;
|
|
|
|
|
|
|
|
gst_pad_forward (srcpad, (GstPadForwardFunction) event_forward_func, &data);
|
2013-11-06 17:05:22 +00:00
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
return data.result;
|
|
|
|
}
|
|
|
|
|
2013-11-06 17:41:10 +00:00
|
|
|
/**
|
|
|
|
* gst_collect_pads_src_event_default:
|
|
|
|
* @pads: the collectpads to use
|
|
|
|
* @pad: src #GstPad that received the event
|
|
|
|
* @event: event being processed
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Default #GstCollectPads event handling for the src pad of elements.
|
2013-11-06 17:41:10 +00:00
|
|
|
* Elements can chain up to this to let flushing seek event handling
|
|
|
|
* be done by GstCollectPads.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2013-09-16 07:55:58 +00:00
|
|
|
gboolean
|
|
|
|
gst_collect_pads_src_event_default (GstCollectPads * pads, GstPad * pad,
|
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
GstObject *parent;
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
parent = GST_OBJECT_PARENT (pad);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:{
|
|
|
|
GstSeekFlags flags;
|
|
|
|
|
2014-02-19 01:27:36 +00:00
|
|
|
pads->priv->eospads = 0;
|
|
|
|
|
2013-09-16 07:55:58 +00:00
|
|
|
GST_INFO_OBJECT (pads, "starting seek");
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, NULL, NULL, &flags, NULL, NULL, NULL, NULL);
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
g_atomic_int_set (&pads->priv->seeking, TRUE);
|
|
|
|
g_atomic_int_set (&pads->priv->pending_flush_start, TRUE);
|
|
|
|
/* forward the seek upstream */
|
|
|
|
res = forward_event_to_all_sinkpads (pad, event);
|
|
|
|
event = NULL;
|
|
|
|
if (!res) {
|
|
|
|
g_atomic_int_set (&pads->priv->seeking, FALSE);
|
|
|
|
g_atomic_int_set (&pads->priv->pending_flush_start, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (pads, "seek done, result: %d", res);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_event_default_internal (GstCollectPads * pads,
|
|
|
|
GstCollectData * data, GstEvent * event, gpointer user_data)
|
2012-04-16 14:24:10 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
return gst_collect_pads_event_default (pads, data, event, FALSE);
|
2012-04-16 14:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2012-04-16 14:24:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE, need_unlock = FALSE;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
|
|
|
GstCollectPads *pads;
|
|
|
|
GstCollectPadsEventFunction event_func;
|
2012-04-16 14:24:10 +00:00
|
|
|
gpointer event_user_data;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
/* some magic to get the managing collect_pads */
|
2012-04-16 14:24:10 +00:00
|
|
|
GST_OBJECT_LOCK (pad);
|
2012-04-17 12:38:01 +00:00
|
|
|
data = (GstCollectData *) gst_pad_get_element_private (pad);
|
2012-04-16 14:24:10 +00:00
|
|
|
if (G_UNLIKELY (data == NULL))
|
|
|
|
goto pad_removed;
|
|
|
|
ref_data (data);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
pads = data->collect;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (data->pad, "Got %s event on sink pad",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
|
|
|
event_func = pads->priv->event_func;
|
|
|
|
event_user_data = pads->priv->event_user_data;
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
if (GST_EVENT_IS_SERIALIZED (event)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
need_unlock = TRUE;
|
|
|
|
}
|
2012-04-16 14:24:10 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (event_func)) {
|
2011-10-28 07:18:55 +00:00
|
|
|
res = event_func (pads, data, event, event_user_data);
|
|
|
|
}
|
2012-04-16 14:24:10 +00:00
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
if (need_unlock)
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
unref_data (data);
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
pad_removed:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("%s got removed from collectpads", GST_OBJECT_NAME (pad));
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:24:18 +00:00
|
|
|
/**
|
2012-04-17 12:38:01 +00:00
|
|
|
* gst_collect_pads_query_default:
|
2012-09-19 08:44:08 +00:00
|
|
|
* @pads: the collectpads to use
|
2012-04-16 14:24:18 +00:00
|
|
|
* @data: collect data of corresponding pad
|
|
|
|
* @query: query being processed
|
|
|
|
* @discard: process but do not send event downstream
|
|
|
|
*
|
2014-06-05 19:38:20 +00:00
|
|
|
* Default #GstCollectPads query handling that elements should always
|
2012-04-16 14:24:18 +00:00
|
|
|
* chain up to to ensure proper operation. Element might however indicate
|
|
|
|
* query should not be forwarded downstream.
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_query_default (GstCollectPads * pads, GstCollectData * data,
|
2012-04-16 14:24:18 +00:00
|
|
|
GstQuery * query, gboolean discard)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstObject *parent;
|
|
|
|
GstPad *pad;
|
|
|
|
|
|
|
|
pad = data->pad;
|
|
|
|
parent = GST_OBJECT_PARENT (pad);
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_SEEKING:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
/* don't pass it along as some (file)sink might claim it does
|
|
|
|
* whereas with a collectpads in between that will not likely work */
|
|
|
|
gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
|
|
|
|
gst_query_set_seeking (query, format, FALSE, 0, -1);
|
|
|
|
res = TRUE;
|
|
|
|
discard = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!discard)
|
|
|
|
return gst_pad_query_default (pad, parent, query);
|
|
|
|
else
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_query_default_internal (GstCollectPads * pads,
|
|
|
|
GstCollectData * data, GstQuery * query, gpointer user_data)
|
2012-04-16 14:24:18 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
return gst_collect_pads_query_default (pads, data, query, FALSE);
|
2012-04-16 14:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2012-04-16 14:24:18 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE, need_unlock = FALSE;
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
|
|
|
GstCollectPads *pads;
|
|
|
|
GstCollectPadsQueryFunction query_func;
|
2012-04-16 14:24:18 +00:00
|
|
|
gpointer query_user_data;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Got %s query on sink pad",
|
|
|
|
GST_QUERY_TYPE_NAME (query));
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
/* some magic to get the managing collect_pads */
|
2012-04-16 14:24:18 +00:00
|
|
|
GST_OBJECT_LOCK (pad);
|
2012-04-17 12:38:01 +00:00
|
|
|
data = (GstCollectData *) gst_pad_get_element_private (pad);
|
2012-04-16 14:24:18 +00:00
|
|
|
if (G_UNLIKELY (data == NULL))
|
|
|
|
goto pad_removed;
|
|
|
|
ref_data (data);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
pads = data->collect;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pads);
|
|
|
|
query_func = pads->priv->query_func;
|
|
|
|
query_user_data = pads->priv->query_user_data;
|
|
|
|
GST_OBJECT_UNLOCK (pads);
|
|
|
|
|
|
|
|
if (GST_QUERY_IS_SERIALIZED (query)) {
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2012-04-16 14:24:18 +00:00
|
|
|
need_unlock = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (query_func)) {
|
|
|
|
res = query_func (pads, data, query, query_user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_unlock)
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2012-04-16 14:24:18 +00:00
|
|
|
|
|
|
|
unref_data (data);
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
pad_removed:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("%s got removed from collectpads", GST_OBJECT_NAME (pad));
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/* For each buffer we receive we check if our collected condition is reached
|
|
|
|
* and if so we call the collected function. When this is done we check if
|
|
|
|
* data has been unqueued. If data is still queued we wait holding the stream
|
|
|
|
* lock to make sure no EOS event can happen while we are ready to be
|
|
|
|
* collected
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
2012-04-17 12:38:01 +00:00
|
|
|
GstCollectData *data;
|
|
|
|
GstCollectPads *pads;
|
2011-10-28 07:18:55 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
GstBuffer **buffer_p;
|
|
|
|
guint32 cookie;
|
|
|
|
|
|
|
|
GST_DEBUG ("Got buffer for pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
/* some magic to get the managing collect_pads */
|
2011-10-28 07:18:55 +00:00
|
|
|
GST_OBJECT_LOCK (pad);
|
2012-04-17 12:38:01 +00:00
|
|
|
data = (GstCollectData *) gst_pad_get_element_private (pad);
|
2011-10-28 07:18:55 +00:00
|
|
|
if (G_UNLIKELY (data == NULL))
|
|
|
|
goto no_data;
|
|
|
|
ref_data (data);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
pads = data->collect;
|
|
|
|
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* if not started, bail out */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (G_UNLIKELY (!pads->priv->started))
|
2011-10-28 07:18:55 +00:00
|
|
|
goto not_started;
|
|
|
|
/* check if this pad is flushing */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_UNLIKELY (GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_FLUSHING)))
|
2011-10-28 07:18:55 +00:00
|
|
|
goto flushing;
|
|
|
|
/* pad was EOS, we can refuse this data */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_UNLIKELY (GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_EOS)))
|
2012-01-03 14:25:31 +00:00
|
|
|
goto eos;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2011-10-28 08:17:06 +00:00
|
|
|
/* see if we need to clip */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->clip_func) {
|
2011-10-28 08:37:21 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2012-01-27 14:02:52 +00:00
|
|
|
ret =
|
|
|
|
pads->priv->clip_func (pads, data, buffer, &outbuf,
|
|
|
|
pads->priv->clip_user_data);
|
2011-10-28 08:54:19 +00:00
|
|
|
buffer = outbuf;
|
2011-10-28 08:17:06 +00:00
|
|
|
|
2011-10-28 08:37:21 +00:00
|
|
|
if (G_UNLIKELY (outbuf == NULL))
|
2011-10-28 08:17:06 +00:00
|
|
|
goto clipped;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
2012-01-03 14:25:31 +00:00
|
|
|
if (G_UNLIKELY (ret == GST_FLOW_EOS))
|
|
|
|
goto eos;
|
2011-10-28 08:37:21 +00:00
|
|
|
else if (G_UNLIKELY (ret != GST_FLOW_OK))
|
2011-10-28 07:18:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-10-28 08:37:21 +00:00
|
|
|
GST_DEBUG_OBJECT (pads, "Queuing buffer %p for pad %s:%s", buffer,
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2011-10-28 07:18:55 +00:00
|
|
|
/* One more pad has data queued */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (GST_COLLECT_PADS_STATE_IS_SET (data, GST_COLLECT_PADS_STATE_WAITING))
|
2012-01-27 14:02:52 +00:00
|
|
|
pads->priv->queuedpads++;
|
2011-10-28 07:18:55 +00:00
|
|
|
buffer_p = &data->buffer;
|
|
|
|
gst_buffer_replace (buffer_p, buffer);
|
|
|
|
|
|
|
|
/* update segment last position if in TIME */
|
|
|
|
if (G_LIKELY (data->segment.format == GST_FORMAT_TIME)) {
|
2013-02-22 22:56:49 +00:00
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
timestamp = GST_BUFFER_DTS (buffer);
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (timestamp))
|
|
|
|
timestamp = GST_BUFFER_PTS (buffer);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp))
|
2011-10-28 09:30:57 +00:00
|
|
|
data->segment.position = timestamp;
|
2011-10-28 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* While we have data queued on this pad try to collect stuff */
|
|
|
|
do {
|
|
|
|
/* Check if our collected condition is matched and call the collected
|
|
|
|
* function if it is */
|
2012-04-17 12:38:01 +00:00
|
|
|
ret = gst_collect_pads_check_collected (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* when an error occurs, we want to report this back to the caller ASAP
|
|
|
|
* without having to block if the buffer was not popped */
|
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* data was consumed, we can exit and accept new data */
|
|
|
|
if (data->buffer == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Having the _INIT here means we don't care about any broadcast up to here
|
|
|
|
* (most of which occur with STREAM_LOCK held, so could not have happened
|
|
|
|
* anyway). We do care about e.g. a remove initiated broadcast as of this
|
|
|
|
* point. Putting it here also makes this thread ignores any evt it raised
|
|
|
|
* itself (as is a usual WAIT semantic).
|
|
|
|
*/
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_EVT_INIT (cookie);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* pad could be removed and re-added */
|
|
|
|
unref_data (data);
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
if (G_UNLIKELY ((data = gst_pad_get_element_private (pad)) == NULL))
|
|
|
|
goto pad_removed;
|
|
|
|
ref_data (data);
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "Pad %s:%s has a buffer queued, waiting",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
/* wait to be collected, this must happen from another thread triggered
|
|
|
|
* by the _chain function of another pad. We release the lock so we
|
|
|
|
* can get stopped or flushed as well. We can however not get EOS
|
|
|
|
* because we still hold the STREAM_LOCK.
|
|
|
|
*/
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
|
|
|
GST_COLLECT_PADS_EVT_WAIT (pads, cookie);
|
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pads, "Pad %s:%s resuming", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
/* after a signal, we could be stopped */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (G_UNLIKELY (!pads->priv->started))
|
2011-10-28 07:18:55 +00:00
|
|
|
goto not_started;
|
|
|
|
/* check if this pad is flushing */
|
2012-04-17 12:38:01 +00:00
|
|
|
if (G_UNLIKELY (GST_COLLECT_PADS_STATE_IS_SET (data,
|
|
|
|
GST_COLLECT_PADS_STATE_FLUSHING)))
|
2011-10-28 07:18:55 +00:00
|
|
|
goto flushing;
|
|
|
|
}
|
|
|
|
while (data->buffer != NULL);
|
|
|
|
|
|
|
|
unlock_done:
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_UNLOCK (pads);
|
2013-09-05 12:14:42 +00:00
|
|
|
/* data is definitely NULL if pad_removed goto was run. */
|
|
|
|
if (data)
|
|
|
|
unref_data (data);
|
2011-10-28 08:54:19 +00:00
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2011-10-28 07:18:55 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
pad_removed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("%s got removed from collectpads", GST_OBJECT_NAME (pad));
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
ret = GST_FLOW_NOT_LINKED;
|
|
|
|
goto unlock_done;
|
|
|
|
}
|
|
|
|
/* ERRORS */
|
|
|
|
no_data:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("%s got removed from collectpads", GST_OBJECT_NAME (pad));
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
}
|
|
|
|
not_started:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("not started");
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clear (pads, data);
|
2012-02-08 14:16:46 +00:00
|
|
|
ret = GST_FLOW_FLUSHING;
|
2011-10-28 07:18:55 +00:00
|
|
|
goto unlock_done;
|
|
|
|
}
|
|
|
|
flushing:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("pad %s:%s is flushing", GST_DEBUG_PAD_NAME (pad));
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clear (pads, data);
|
2012-02-08 14:16:46 +00:00
|
|
|
ret = GST_FLOW_FLUSHING;
|
2011-10-28 07:18:55 +00:00
|
|
|
goto unlock_done;
|
|
|
|
}
|
2012-01-03 14:25:31 +00:00
|
|
|
eos:
|
2011-10-28 07:18:55 +00:00
|
|
|
{
|
|
|
|
/* we should not post an error for this, just inform upstream that
|
|
|
|
* we don't expect anything anymore */
|
|
|
|
GST_DEBUG ("pad %s:%s is eos", GST_DEBUG_PAD_NAME (pad));
|
2012-01-03 14:25:31 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2011-10-28 07:18:55 +00:00
|
|
|
goto unlock_done;
|
|
|
|
}
|
2011-10-28 08:17:06 +00:00
|
|
|
clipped:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("clipped buffer on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
2011-10-28 08:37:21 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
goto unlock_done;
|
2011-10-28 08:17:06 +00:00
|
|
|
}
|
2011-10-28 07:18:55 +00:00
|
|
|
error:
|
|
|
|
{
|
|
|
|
/* we print the error, the element should post a reasonable error
|
|
|
|
* message for fatal errors */
|
|
|
|
GST_DEBUG ("collect failed, reason %d (%s)", ret, gst_flow_get_name (ret));
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_clear (pads, data);
|
2011-10-28 07:18:55 +00:00
|
|
|
goto unlock_done;
|
|
|
|
}
|
|
|
|
}
|