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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
/**
|
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.
|
2011-10-28 07:18:55 +00:00
|
|
|
* These functions will return NULL if the pad received an EOS event. When all
|
2012-04-17 12:38:01 +00:00
|
|
|
* 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(),
|
|
|
|
* gst_collect_pads_read() 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_collect() and gst_collect_pads_collect_range() can be used by
|
|
|
|
* elements that start a #GstTask to drive the collect_pads. This feature is however
|
2011-10-28 07:18:55 +00:00
|
|
|
* not yet implemented.
|
|
|
|
* </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-10-28 07:38:35 +00:00
|
|
|
* Last reviewed on 2011-10-28 (0.10.36)
|
2011-10-28 07:18:55 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
|
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;
|
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.
|
|
|
|
*
|
2012-04-17 12:38:01 +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
|
2012-10-29 23:04:44 +00:00
|
|
|
* the oldest buffer when all pads have been collected, or NULL on EOS.
|
|
|
|
* 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
|
|
|
|
* @outbuf: output buffer with running time, or NULL if clipped
|
|
|
|
* @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;
|
|
|
|
time = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
|
|
|
/* 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))) {
|
|
|
|
GST_DEBUG_OBJECT (cdata->pad, "clipping buffer on pad outside segment");
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
*outbuf = NULL;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (cdata->pad, "buffer ts %" GST_TIME_FORMAT " -> %"
|
|
|
|
GST_TIME_FORMAT " running time",
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (time));
|
2011-12-25 12:13:57 +00:00
|
|
|
*outbuf = gst_buffer_make_writable (buf);
|
2011-12-16 16:59:22 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (*outbuf) = time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-28 08:17:06 +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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2012-04-17 12:38:01 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be called with STREAM_LOCK.
|
|
|
|
*/
|
|
|
|
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 */
|
|
|
|
for (walk = pads->data; 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);
|
|
|
|
gst_collect_pads_set_flushing_unlocked (pads, flushing);
|
|
|
|
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.
|
|
|
|
*
|
2011-10-28 07:18:55 +00:00
|
|
|
* Returns: The buffer in @data or NULL if no buffer is queued.
|
|
|
|
* 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.
|
|
|
|
*
|
2012-02-26 22:11:23 +00:00
|
|
|
* Returns: (transfer full): The buffer in @data or NULL if no buffer was
|
|
|
|
* 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.
|
2011-10-28 07:18:55 +00:00
|
|
|
* A return of NULL signals that the pad is end-of-stream.
|
|
|
|
* 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.
|
|
|
|
* A return of NULL signals that the pad is end-of-stream.
|
|
|
|
* 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) !=
|
2011-10-28 07:18:55 +00:00
|
|
|
! !waiting)) {
|
|
|
|
/* 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
|
|
|
|
|
|
|
flow_ret = func (pads, user_data);
|
|
|
|
} 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));
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* Returns TRUE if a pad was set to waiting
|
|
|
|
* (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) {
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
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 ();
|
|
|
|
GST_BUFFER_TIMESTAMP (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) {
|
|
|
|
otime = GST_BUFFER_TIMESTAMP (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
|
|
|
|
*
|
2012-04-17 12:38:01 +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:
|
|
|
|
{
|
|
|
|
/* forward event to unblock check_collected */
|
2012-04-16 14:24:10 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "forwarding flush start");
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
2012-04-23 15:04:57 +00:00
|
|
|
event = NULL;
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* now unblock the chain function.
|
2012-04-16 14:24:10 +00:00
|
|
|
* no cond per pad, so they all unblock,
|
2011-10-28 07:18:55 +00:00
|
|
|
* non-flushing block again */
|
2012-04-17 12:38:01 +00:00
|
|
|
GST_COLLECT_PADS_STREAM_LOCK (pads);
|
|
|
|
GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_FLUSHING);
|
|
|
|
gst_collect_pads_clear (pads, data);
|
2011-10-28 07:18:55 +00:00
|
|
|
|
|
|
|
/* cater for possible default muxing functionality */
|
|
|
|
if (buffer_func) {
|
|
|
|
/* restore to initial state */
|
2012-04-17 12:38:01 +00:00
|
|
|
gst_collect_pads_set_waiting (pads, data, TRUE);
|
2011-10-28 07:18:55 +00:00
|
|
|
/* if the current pad is affected, reset state, recalculate later */
|
2012-01-27 14:02:52 +00:00
|
|
|
if (pads->priv->earliest_data == data) {
|
2011-10-28 07:18:55 +00:00
|
|
|
unref_data (data);
|
2012-01-27 14:02:52 +00:00
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
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++;
|
|
|
|
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
|
|
|
|
2012-04-16 14:24:10 +00:00
|
|
|
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 */
|
|
|
|
seg.position = gst_collect_pads_clip_time (pads, data, seg.start);
|
|
|
|
/* 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
2012-04-17 12:38:01 +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)) {
|
|
|
|
GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
|
|
|
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);
|
2011-10-28 07:18:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|