2000-12-29 05:38:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
2003-04-17 09:19:34 +00:00
|
|
|
* 2003 Colin Walters <cwalters@gnome.org>
|
2000-12-29 05:38:06 +00:00
|
|
|
*
|
2001-01-20 17:59:25 +00:00
|
|
|
* gstqueue.c:
|
2000-01-30 09:03:00 +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.
|
|
|
|
*/
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gst_private.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gstqueue.h"
|
2001-05-25 21:00:07 +00:00
|
|
|
#include "gstscheduler.h"
|
2001-12-18 19:03:07 +00:00
|
|
|
#include "gstevent.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
static GstElementDetails gst_queue_details = GST_ELEMENT_DETAILS (
|
2000-01-30 09:03:00 +00:00
|
|
|
"Queue",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Generic",
|
2000-01-30 09:03:00 +00:00
|
|
|
"Simple data queue",
|
2003-10-31 19:32:47 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>"
|
|
|
|
);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Queue signals and args */
|
|
|
|
enum {
|
2003-04-17 09:19:34 +00:00
|
|
|
FULL,
|
2000-01-30 09:03:00 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2001-05-25 21:00:07 +00:00
|
|
|
ARG_LEVEL_BUFFERS,
|
|
|
|
ARG_LEVEL_BYTES,
|
|
|
|
ARG_LEVEL_TIME,
|
|
|
|
ARG_SIZE_BUFFERS,
|
|
|
|
ARG_SIZE_BYTES,
|
|
|
|
ARG_SIZE_TIME,
|
|
|
|
ARG_LEAKY,
|
2000-01-30 09:03:00 +00:00
|
|
|
ARG_LEVEL,
|
2000-02-13 15:20:49 +00:00
|
|
|
ARG_MAX_LEVEL,
|
2003-05-30 23:20:02 +00:00
|
|
|
ARG_MIN_THRESHOLD_BYTES,
|
2001-12-22 21:18:17 +00:00
|
|
|
ARG_MAY_DEADLOCK,
|
2002-06-03 15:44:28 +00:00
|
|
|
ARG_BLOCK_TIMEOUT,
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
static void gst_queue_base_init (gpointer g_class);
|
|
|
|
static void gst_queue_class_init (gpointer g_class,
|
|
|
|
gpointer class_data);
|
|
|
|
static void gst_queue_init (GTypeInstance *instance,
|
|
|
|
gpointer g_class);
|
2001-12-22 21:18:17 +00:00
|
|
|
static void gst_queue_dispose (GObject *object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
static void gst_queue_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_queue_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2003-10-08 16:06:02 +00:00
|
|
|
static void gst_queue_chain (GstPad *pad, GstData *data);
|
|
|
|
static GstData * gst_queue_get (GstPad *pad);
|
2001-08-21 20:16:48 +00:00
|
|
|
static GstBufferPool* gst_queue_get_bufferpool (GstPad *pad);
|
2001-04-16 21:45:02 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
static gboolean gst_queue_handle_src_event (GstPad *pad, GstEvent *event);
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_queue_locked_flush (GstQueue *queue);
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
static GstElementStateReturn gst_queue_change_state (GstElement *element);
|
2002-05-26 21:54:27 +00:00
|
|
|
static gboolean gst_queue_release_locks (GstElement *element);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
#define GST_TYPE_QUEUE_LEAKY (queue_leaky_get_type())
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType
|
2001-05-25 21:00:07 +00:00
|
|
|
queue_leaky_get_type(void) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType queue_leaky_type = 0;
|
|
|
|
static GEnumValue queue_leaky[] = {
|
2001-08-21 20:16:48 +00:00
|
|
|
{ GST_QUEUE_NO_LEAK, "0", "Not Leaky" },
|
|
|
|
{ GST_QUEUE_LEAK_UPSTREAM, "1", "Leaky on Upstream" },
|
|
|
|
{ GST_QUEUE_LEAK_DOWNSTREAM, "2", "Leaky on Downstream" },
|
2001-05-25 21:00:07 +00:00
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
if (!queue_leaky_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
queue_leaky_type = g_enum_register_static("GstQueueLeaky", queue_leaky);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
return queue_leaky_type;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-29 02:28:04 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2003-04-17 09:19:34 +00:00
|
|
|
static guint gst_queue_signals[LAST_SIGNAL] = { 0 };
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2001-08-21 20:16:48 +00:00
|
|
|
gst_queue_get_type(void)
|
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType queue_type = 0;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
if (!queue_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo queue_info = {
|
2000-01-30 09:03:00 +00:00
|
|
|
sizeof(GstQueueClass),
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_queue_base_init,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_queue_class_init,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstQueue),
|
|
|
|
4,
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_queue_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +00:00
|
|
|
queue_type = g_type_register_static (GST_TYPE_ELEMENT, "GstQueue", &queue_info, 0);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
return queue_type;
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_queue_base_init (gpointer g_class)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2003-10-31 19:32:47 +00:00
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (gstelement_class, &gst_queue_details);
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
static void
|
|
|
|
gst_queue_class_init (gpointer g_class, gpointer class_data)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstQueueClass *gstqueue_class = GST_QUEUE_CLASS (g_class);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
parent_class = g_type_class_peek_parent (g_class);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-04-17 09:19:34 +00:00
|
|
|
gst_queue_signals[FULL] =
|
2003-10-31 19:32:47 +00:00
|
|
|
g_signal_new ("full", G_TYPE_FROM_CLASS (gstqueue_class), G_SIGNAL_RUN_FIRST,
|
2003-04-17 09:19:34 +00:00
|
|
|
G_STRUCT_OFFSET (GstQueueClass, full), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_LEAKY,
|
2001-12-22 21:18:17 +00:00
|
|
|
g_param_spec_enum ("leaky", "Leaky", "Where the queue leaks, if at all.",
|
|
|
|
GST_TYPE_QUEUE_LEAKY, GST_QUEUE_NO_LEAK, G_PARAM_READWRITE));
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_LEVEL,
|
2001-12-22 21:18:17 +00:00
|
|
|
g_param_spec_int ("level", "Level", "How many buffers are in the queue.",
|
|
|
|
0, G_MAXINT, 0, G_PARAM_READABLE));
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MAX_LEVEL,
|
2001-12-22 21:18:17 +00:00
|
|
|
g_param_spec_int ("max_level", "Maximum Level", "How many buffers the queue holds.",
|
|
|
|
0, G_MAXINT, 100, G_PARAM_READWRITE));
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MIN_THRESHOLD_BYTES,
|
2003-05-30 23:20:02 +00:00
|
|
|
g_param_spec_int ("min_threshold_bytes", "Minimum Threshold",
|
|
|
|
"Minimum bytes required before signalling not_empty to reader.",
|
|
|
|
0, G_MAXINT, 0, G_PARAM_READWRITE));
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MAY_DEADLOCK,
|
2001-12-22 21:18:17 +00:00
|
|
|
g_param_spec_boolean ("may_deadlock", "May Deadlock", "The queue may deadlock if it's full and not PLAYING",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
2003-10-31 19:32:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_BLOCK_TIMEOUT,
|
2002-06-03 15:44:28 +00:00
|
|
|
g_param_spec_int ("block_timeout", "Timeout for Block",
|
|
|
|
"Microseconds until blocked queue times out and returns filler event. "
|
|
|
|
"Value of -1 disables timeout",
|
|
|
|
-1, G_MAXINT, -1, G_PARAM_READWRITE));
|
2001-12-22 21:18:17 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_queue_dispose);
|
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_queue_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_queue_get_property);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_queue_change_state);
|
|
|
|
gstelement_class->release_locks = GST_DEBUG_FUNCPTR(gst_queue_release_locks);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2003-01-09 22:59:37 +00:00
|
|
|
static GstPadLinkReturn
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_queue_link (GstPad *pad, GstCaps *caps)
|
2002-01-13 22:22:42 +00:00
|
|
|
{
|
|
|
|
GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
|
|
|
|
GstPad *otherpad;
|
|
|
|
|
|
|
|
if (pad == queue->srcpad)
|
|
|
|
otherpad = queue->sinkpad;
|
|
|
|
else
|
|
|
|
otherpad = queue->srcpad;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
return gst_pad_proxy_link (otherpad, caps);
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps*
|
|
|
|
gst_queue_getcaps (GstPad *pad, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
|
|
|
|
GstPad *otherpad;
|
|
|
|
|
|
|
|
if (pad == queue->srcpad)
|
2003-01-23 19:49:18 +00:00
|
|
|
otherpad = GST_PAD_PEER (queue->sinkpad);
|
2002-01-13 22:22:42 +00:00
|
|
|
else
|
2003-01-23 19:49:18 +00:00
|
|
|
otherpad = GST_PAD_PEER (queue->srcpad);
|
|
|
|
|
|
|
|
if (otherpad)
|
|
|
|
return gst_pad_get_caps (otherpad);
|
2002-01-13 22:22:42 +00:00
|
|
|
|
2003-01-23 19:49:18 +00:00
|
|
|
return NULL;
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_queue_init (GTypeInstance *instance, gpointer g_class)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2003-10-31 19:32:47 +00:00
|
|
|
GstQueue *queue = GST_QUEUE (instance);
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* scheduling on this kind of element is, well, interesting */
|
2000-12-26 23:51:04 +00:00
|
|
|
GST_FLAG_SET (queue, GST_ELEMENT_DECOUPLED);
|
2001-11-14 21:09:44 +00:00
|
|
|
GST_FLAG_SET (queue, GST_ELEMENT_EVENT_AWARE);
|
2000-12-20 09:39:43 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
queue->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_pad_set_chain_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_chain));
|
2000-12-11 00:24:32 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_pad_set_bufferpool_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_get_bufferpool));
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_link));
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_pad_set_getcaps_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_getcaps));
|
2000-09-24 14:29:49 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
queue->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_pad_set_get_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_get));
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_link));
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_pad_set_getcaps_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_getcaps));
|
2002-05-26 21:54:27 +00:00
|
|
|
gst_pad_set_event_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_handle_src_event));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-29 03:02:14 +00:00
|
|
|
queue->leaky = GST_QUEUE_NO_LEAK;
|
2000-01-30 09:03:00 +00:00
|
|
|
queue->queue = NULL;
|
|
|
|
queue->level_buffers = 0;
|
|
|
|
queue->level_bytes = 0;
|
2003-02-10 20:16:38 +00:00
|
|
|
queue->level_time = G_GINT64_CONSTANT (0);
|
|
|
|
queue->size_buffers = 100; /* 100 buffers */
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->size_bytes = 100 * 1024; /* 100KB */
|
|
|
|
queue->size_time = GST_SECOND; /* 1sec */
|
|
|
|
queue->min_threshold_bytes = 0;
|
2001-12-22 21:18:17 +00:00
|
|
|
queue->may_deadlock = TRUE;
|
2002-06-03 15:44:28 +00:00
|
|
|
queue->block_timeout = -1;
|
2002-06-09 12:13:30 +00:00
|
|
|
queue->interrupt = FALSE;
|
|
|
|
queue->flush = FALSE;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
queue->qlock = g_mutex_new ();
|
|
|
|
queue->not_empty = g_cond_new ();
|
|
|
|
queue->not_full = g_cond_new ();
|
2002-06-08 16:13:18 +00:00
|
|
|
queue->events = g_async_queue_new();
|
2002-07-08 19:22:02 +00:00
|
|
|
queue->queue = g_queue_new ();
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_THREAD, queue, "initialized queue's not_empty & not_full conditions");
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
static void
|
|
|
|
gst_queue_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GstQueue *queue = GST_QUEUE (object);
|
|
|
|
|
2003-04-15 18:46:09 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (queue), GST_STATE_NULL);
|
2003-03-27 03:16:08 +00:00
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
g_mutex_free (queue->qlock);
|
|
|
|
g_cond_free (queue->not_empty);
|
|
|
|
g_cond_free (queue->not_full);
|
2002-07-08 19:22:02 +00:00
|
|
|
g_queue_free (queue->queue);
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2002-06-08 16:13:18 +00:00
|
|
|
g_async_queue_unref(queue->events);
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2001-04-16 21:45:02 +00:00
|
|
|
static GstBufferPool*
|
|
|
|
gst_queue_get_bufferpool (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
return gst_pad_get_bufferpool (queue->srcpad);
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2002-07-08 19:22:02 +00:00
|
|
|
gst_queue_cleanup_data (gpointer data, const gpointer user_data)
|
2000-07-12 22:52:42 +00:00
|
|
|
{
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, user_data, "cleaning buffer %p", data);
|
2001-11-14 21:09:44 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
gst_data_unref (GST_DATA (data));
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2001-10-27 20:28:31 +00:00
|
|
|
gst_queue_locked_flush (GstQueue *queue)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2002-07-08 19:22:02 +00:00
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
while ((data = g_queue_pop_head (queue->queue))) {
|
|
|
|
gst_queue_cleanup_data (data, (gpointer) queue);
|
|
|
|
}
|
2001-01-07 03:42:27 +00:00
|
|
|
queue->timeval = NULL;
|
2002-07-08 19:22:02 +00:00
|
|
|
queue->level_buffers = 0;
|
|
|
|
queue->level_bytes = 0;
|
2003-02-10 20:16:38 +00:00
|
|
|
queue->level_time = G_GINT64_CONSTANT (0);
|
2002-06-09 12:13:30 +00:00
|
|
|
/* make sure any pending buffers to be added are flushed too */
|
|
|
|
queue->flush = TRUE;
|
2003-03-27 03:16:08 +00:00
|
|
|
/* signal not_full, since we apparently aren't full anymore */
|
|
|
|
g_cond_signal (queue->not_full);
|
2000-10-30 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2003-10-08 16:06:02 +00:00
|
|
|
gst_queue_chain (GstPad *pad, GstData *data)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstQueue *queue;
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
2003-10-08 16:06:02 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
2002-06-08 16:13:18 +00:00
|
|
|
|
|
|
|
/* check for events to send upstream */
|
|
|
|
g_async_queue_lock(queue->events);
|
|
|
|
while (g_async_queue_length_unlocked(queue->events) > 0){
|
|
|
|
GstEvent *event = (GstEvent*)g_async_queue_pop_unlocked(queue->events);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "sending event upstream\n");
|
2002-06-08 16:13:18 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "event sent\n");
|
2002-06-08 16:13:18 +00:00
|
|
|
}
|
|
|
|
g_async_queue_unlock(queue->events);
|
2003-10-08 16:06:02 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
restart:
|
2001-10-27 20:28:31 +00:00
|
|
|
/* we have to lock the queue since we span threads */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ());
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_lock (queue->qlock);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locked t:%p", g_thread_self ());
|
2003-10-08 16:06:02 +00:00
|
|
|
|
2002-06-09 12:13:30 +00:00
|
|
|
/* assume don't need to flush this buffer when the queue is filled */
|
|
|
|
queue->flush = FALSE;
|
2003-10-08 16:06:02 +00:00
|
|
|
|
|
|
|
if (GST_IS_EVENT (data)) {
|
|
|
|
switch (GST_EVENT_TYPE (data)) {
|
2001-10-27 20:28:31 +00:00
|
|
|
case GST_EVENT_FLUSH:
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "FLUSH event, flushing queue\n");
|
2001-10-27 20:28:31 +00:00
|
|
|
gst_queue_locked_flush (queue);
|
2001-11-14 21:09:44 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_EOS:
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "eos in on %s %d\n",
|
2003-10-08 16:06:02 +00:00
|
|
|
GST_ELEMENT_NAME (queue), queue->level_buffers);
|
2001-11-14 21:09:44 +00:00
|
|
|
break;
|
2001-10-27 20:28:31 +00:00
|
|
|
default:
|
2002-10-25 19:14:57 +00:00
|
|
|
/* we put the event in the queue, we don't have to act ourselves */
|
2001-11-14 21:09:44 +00:00
|
|
|
break;
|
2001-10-27 20:28:31 +00:00
|
|
|
}
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
2003-10-08 16:06:02 +00:00
|
|
|
|
|
|
|
if (GST_IS_BUFFER (data))
|
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue,
|
|
|
|
"adding buffer %p of size %d", data, GST_BUFFER_SIZE (data));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
if (queue->level_buffers == queue->size_buffers) {
|
2003-04-17 19:51:28 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2003-04-17 09:19:34 +00:00
|
|
|
g_signal_emit (G_OBJECT (queue), gst_queue_signals[FULL], 0);
|
2003-04-17 19:51:28 +00:00
|
|
|
g_mutex_lock (queue->qlock);
|
2003-04-17 09:19:34 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if this is a leaky queue... */
|
2001-05-25 21:00:07 +00:00
|
|
|
if (queue->leaky) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* FIXME don't want to leak events! */
|
|
|
|
/* if we leak on the upstream side, drop the current buffer */
|
2001-05-25 21:00:07 +00:00
|
|
|
if (queue->leaky == GST_QUEUE_LEAK_UPSTREAM) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end");
|
2003-10-08 16:06:02 +00:00
|
|
|
if (GST_IS_EVENT (data))
|
2001-10-27 20:28:31 +00:00
|
|
|
fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
|
|
|
|
GST_ELEMENT_NAME(GST_ELEMENT(queue)),
|
2003-10-08 16:06:02 +00:00
|
|
|
GST_EVENT_TYPE(GST_EVENT(data)));
|
2001-12-14 22:59:21 +00:00
|
|
|
/* now we have to clean up and exit right away */
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2003-03-21 20:53:26 +00:00
|
|
|
goto out_unref;
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-12-14 22:59:21 +00:00
|
|
|
/* otherwise we have to push a buffer off the other end */
|
2001-05-25 21:00:07 +00:00
|
|
|
else {
|
2002-07-08 19:22:02 +00:00
|
|
|
gpointer front;
|
2003-10-08 16:06:02 +00:00
|
|
|
GstData *leak;
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on downstream end");
|
2002-07-08 19:22:02 +00:00
|
|
|
|
|
|
|
front = g_queue_pop_head (queue->queue);
|
2003-10-08 16:06:02 +00:00
|
|
|
leak = GST_DATA (front);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2003-10-08 16:06:02 +00:00
|
|
|
queue->level_buffers--;
|
|
|
|
if (GST_IS_EVENT (leak)) {
|
2001-10-27 20:28:31 +00:00
|
|
|
fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
|
|
|
|
GST_ELEMENT_NAME(GST_ELEMENT(queue)),
|
2003-10-08 16:06:02 +00:00
|
|
|
GST_EVENT_TYPE(GST_EVENT(leak)));
|
|
|
|
} else {
|
|
|
|
queue->level_bytes -= GST_BUFFER_SIZE(leak);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_data_unref (leak);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "pre full wait, level:%d/%d buffers, %d bytes",
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
while (queue->level_buffers == queue->size_buffers) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if there's a pending state change for this queue or its manager, switch */
|
|
|
|
/* back to iterator so bottom half of state change executes */
|
2002-05-26 21:54:27 +00:00
|
|
|
if (queue->interrupt) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "interrupted!!");
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2002-09-12 20:52:03 +00:00
|
|
|
if (gst_scheduler_interrupt (gst_pad_get_scheduler (queue->sinkpad), GST_ELEMENT (queue)))
|
2003-03-21 20:53:26 +00:00
|
|
|
goto out_unref;
|
2003-05-30 23:20:02 +00:00
|
|
|
/* if we got here because we were unlocked after a flush, we don't need
|
2002-06-09 12:13:30 +00:00
|
|
|
* to add the buffer to the queue again */
|
|
|
|
if (queue->flush) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "not adding pending buffer after flush");
|
2003-03-21 20:53:26 +00:00
|
|
|
goto out_unref;
|
2002-06-09 12:13:30 +00:00
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "adding pending buffer after interrupt");
|
2001-12-04 22:12:50 +00:00
|
|
|
goto restart;
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_STATE (queue) != GST_STATE_PLAYING) {
|
|
|
|
/* this means the other end is shut down */
|
|
|
|
/* try to signal to resolve the error */
|
|
|
|
if (!queue->may_deadlock) {
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2003-10-08 16:06:02 +00:00
|
|
|
gst_data_unref (data);
|
2003-09-16 09:57:31 +00:00
|
|
|
gst_element_error (GST_ELEMENT (queue), "deadlock found, source pad elements are shut down");
|
2003-03-21 20:53:26 +00:00
|
|
|
/* we don't want to goto out_unref here, since we want to clean up before calling gst_element_error */
|
2001-12-22 21:18:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2002-03-30 17:05:03 +00:00
|
|
|
g_print ("%s: waiting for the app to restart source pad elements\n", GST_ELEMENT_NAME (queue));
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d buffers, %d bytes",
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2001-10-27 20:28:31 +00:00
|
|
|
g_cond_wait (queue->not_full, queue->qlock);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "got not_full signal");
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "post full wait, level:%d/%d buffers, %d bytes",
|
2003-10-08 16:06:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2000-02-13 13:43:32 +00:00
|
|
|
}
|
|
|
|
|
2000-09-24 14:29:49 +00:00
|
|
|
/* put the buffer on the tail of the list */
|
2003-10-08 16:06:02 +00:00
|
|
|
g_queue_push_tail (queue->queue, data);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2000-05-21 21:58:20 +00:00
|
|
|
queue->level_buffers++;
|
2003-10-08 16:06:02 +00:00
|
|
|
if (GST_IS_BUFFER (data))
|
|
|
|
queue->level_bytes += GST_BUFFER_SIZE (data);
|
2001-12-29 03:02:14 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
/* this assertion _has_ to hold */
|
|
|
|
g_assert (queue->queue->length == queue->level_buffers);
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "(%s:%s)+ level:%d/%d buffers, %d bytes",
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_PAD_NAME(pad),
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2001-10-27 20:28:31 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "signalling not_empty");
|
2003-03-27 03:16:08 +00:00
|
|
|
g_cond_signal (queue->not_empty);
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-03-21 20:53:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
out_unref:
|
2003-10-08 16:06:02 +00:00
|
|
|
gst_data_unref (data);
|
2003-03-21 20:53:26 +00:00
|
|
|
return;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2003-10-08 16:06:02 +00:00
|
|
|
static GstData *
|
2001-01-20 17:59:25 +00:00
|
|
|
gst_queue_get (GstPad *pad)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2001-02-21 20:27:54 +00:00
|
|
|
GstQueue *queue;
|
2003-10-08 16:06:02 +00:00
|
|
|
GstData *data = NULL;
|
2002-07-08 19:22:02 +00:00
|
|
|
gpointer front;
|
Another big set of changes. Connections are now also pullfunc based. gstqueue has been updated, I don't know of any ...
Original commit message from CVS:
Another big set of changes. Connections are now also pullfunc based.
gstqueue has been updated, I don't know of any other connections offhand.
There are still a few things that need doing, specifically the concept
of a source or connection with connections to multiple thread contexts is
not dealt with. This may force us to move the threadstate from the
element to the pad, maybe keeping the element's copy for simple cases.
Then the Bin would create a structure to pass to the cothreaded _wrappers
of any such elements, which would detail the pads that are to be dealt with
by this particular cothread context.
That will speed things up to, since we don't have to look through the list
of all pads for every Src or Connection element for every iteration, we can
simply step through the list provided by the plan. Special case might even
have a single pad pointer sitting there to trump the list, if there's only
one (the common case anyway).
Task 23098 is tracking these changes. The main task 22588 depends on that
subtask, as well as 22240, which is a consistency check on PAD_DISABLED.
2000-12-08 10:33:01 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert(pad != NULL);
|
|
|
|
g_assert(GST_IS_PAD(pad));
|
2001-02-21 20:27:54 +00:00
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
|
|
|
|
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
2001-10-27 20:28:31 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
restart:
|
2000-01-30 09:03:00 +00:00
|
|
|
/* have to lock for thread-safety */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ());
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_lock (queue->qlock);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locked t:%p %p", g_thread_self (), queue->not_empty);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d buffers, %d bytes",
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2001-10-27 20:28:31 +00:00
|
|
|
while (queue->level_buffers == 0) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if there's a pending state change for this queue or its manager, switch
|
|
|
|
* back to iterator so bottom half of state change executes
|
|
|
|
*/
|
2002-05-26 21:54:27 +00:00
|
|
|
//while (GST_STATE_PENDING (queue) != GST_STATE_VOID_PENDING) {
|
|
|
|
if (queue->interrupt) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "interrupted!!");
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2002-09-12 20:52:03 +00:00
|
|
|
if (gst_scheduler_interrupt (gst_pad_get_scheduler (queue->srcpad), GST_ELEMENT (queue)))
|
2003-10-08 16:06:02 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
2001-12-04 22:12:50 +00:00
|
|
|
goto restart;
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_STATE (queue) != GST_STATE_PLAYING) {
|
|
|
|
/* this means the other end is shut down */
|
|
|
|
if (!queue->may_deadlock) {
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2003-09-16 09:57:31 +00:00
|
|
|
gst_element_error (GST_ELEMENT (queue), "deadlock found, sink pad elements are shut down");
|
2001-12-27 00:47:41 +00:00
|
|
|
goto restart;
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-03-30 17:05:03 +00:00
|
|
|
g_print ("%s: waiting for the app to restart source pad elements\n", GST_ELEMENT_NAME (queue));
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d buffers, %d bytes",
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2002-06-03 15:44:28 +00:00
|
|
|
|
2003-03-27 03:16:08 +00:00
|
|
|
/* if (queue->block_timeout > -1){ */
|
2002-07-08 19:22:02 +00:00
|
|
|
if (FALSE) {
|
2002-06-03 15:44:28 +00:00
|
|
|
GTimeVal timeout;
|
|
|
|
g_get_current_time(&timeout);
|
|
|
|
g_time_val_add(&timeout, queue->block_timeout);
|
|
|
|
if (!g_cond_timed_wait (queue->not_empty, queue->qlock, &timeout)){
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2002-07-08 19:22:02 +00:00
|
|
|
g_warning ("filler");
|
2003-10-08 16:06:02 +00:00
|
|
|
return GST_DATA (gst_event_new_filler());
|
2002-06-03 15:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_cond_wait (queue->not_empty, queue->qlock);
|
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "got not_empty signal");
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "post empty wait, level:%d/%d buffers, %d bytes",
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
front = g_queue_pop_head (queue->queue);
|
2003-10-08 16:06:02 +00:00
|
|
|
data = GST_DATA (front);
|
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "retrieved data %p from queue", data);
|
2000-12-21 01:27:27 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
queue->level_buffers--;
|
2003-10-08 16:06:02 +00:00
|
|
|
if (GST_IS_BUFFER (data))
|
|
|
|
queue->level_bytes -= GST_BUFFER_SIZE (data);
|
2001-12-29 03:02:14 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "(%s:%s)- level:%d/%d buffers, %d bytes",
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_PAD_NAME(pad),
|
2003-05-30 23:20:02 +00:00
|
|
|
queue->level_buffers, queue->size_buffers, queue->level_bytes);
|
2001-10-27 20:28:31 +00:00
|
|
|
|
2001-12-29 03:02:14 +00:00
|
|
|
/* this assertion _has_ to hold */
|
2002-07-08 19:22:02 +00:00
|
|
|
g_assert (queue->queue->length == queue->level_buffers);
|
2001-12-29 03:02:14 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "signalling not_full");
|
2003-03-27 03:16:08 +00:00
|
|
|
g_cond_signal (queue->not_full);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* FIXME where should this be? locked? */
|
2003-10-08 16:06:02 +00:00
|
|
|
if (GST_IS_EVENT (data)) {
|
|
|
|
GstEvent *event = GST_EVENT (data);
|
2001-10-27 20:28:31 +00:00
|
|
|
switch (GST_EVENT_TYPE(event)) {
|
|
|
|
case GST_EVENT_EOS:
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue \"%s\" eos", GST_ELEMENT_NAME (queue));
|
2001-12-28 20:20:26 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (queue));
|
2001-10-27 20:28:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-02-13 13:43:32 +00:00
|
|
|
|
2003-10-08 16:06:02 +00:00
|
|
|
return data;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_queue_handle_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
GstQueue *queue;
|
2002-06-08 16:30:43 +00:00
|
|
|
gboolean res;
|
2003-01-12 13:06:44 +00:00
|
|
|
gint event_type;
|
|
|
|
gint flag_flush = 0;
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
2002-06-08 16:13:18 +00:00
|
|
|
g_mutex_lock (queue->qlock);
|
2002-06-08 16:30:43 +00:00
|
|
|
|
|
|
|
if (gst_element_get_state (GST_ELEMENT (queue)) == GST_STATE_PLAYING) {
|
|
|
|
/* push the event to the queue for upstream consumption */
|
|
|
|
g_async_queue_push(queue->events, event);
|
|
|
|
g_warning ("FIXME: sending event in a running queue");
|
|
|
|
/* FIXME wait for delivery of the event here, then return the result
|
|
|
|
* instead of FALSE */
|
2003-01-15 21:01:58 +00:00
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
2002-06-08 16:30:43 +00:00
|
|
|
}
|
|
|
|
|
2003-01-12 13:06:44 +00:00
|
|
|
event_type = GST_EVENT_TYPE (event);
|
|
|
|
if (event_type == GST_EVENT_SEEK)
|
|
|
|
flag_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
2002-06-08 16:30:43 +00:00
|
|
|
res = gst_pad_event_default (pad, event);
|
2003-01-12 13:06:44 +00:00
|
|
|
|
|
|
|
switch (event_type) {
|
2002-06-08 16:13:18 +00:00
|
|
|
case GST_EVENT_FLUSH:
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "FLUSH event, flushing queue\n");
|
2002-06-08 16:13:18 +00:00
|
|
|
gst_queue_locked_flush (queue);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEEK:
|
2003-01-12 13:06:44 +00:00
|
|
|
if (flag_flush) {
|
2002-06-02 15:34:34 +00:00
|
|
|
gst_queue_locked_flush (queue);
|
2002-06-09 12:13:30 +00:00
|
|
|
}
|
2002-06-08 16:13:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
2003-01-15 21:01:58 +00:00
|
|
|
|
|
|
|
done:
|
2002-05-26 21:54:27 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2002-06-02 15:34:34 +00:00
|
|
|
|
2002-06-08 16:13:18 +00:00
|
|
|
/* we have to claim success, but we don't really know */
|
2003-01-15 21:01:58 +00:00
|
|
|
return res;
|
2002-05-26 21:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_queue_release_locks (GstElement *element)
|
|
|
|
{
|
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
queue = GST_QUEUE (element);
|
|
|
|
|
|
|
|
g_mutex_lock (queue->qlock);
|
|
|
|
queue->interrupt = TRUE;
|
|
|
|
g_cond_signal (queue->not_full);
|
|
|
|
g_cond_signal (queue->not_empty);
|
|
|
|
g_mutex_unlock (queue->qlock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_queue_change_state (GstElement *element)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-10-30 21:02:08 +00:00
|
|
|
GstQueue *queue;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElementStateReturn ret;
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
queue = GST_QUEUE (element);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "starting state change");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* lock the queue so another thread (not in sync with this thread's state)
|
|
|
|
* can't call this queue's _get (or whatever)
|
|
|
|
*/
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (queue->qlock);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2003-01-15 21:01:58 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
gst_queue_locked_flush (queue);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
if (!GST_PAD_IS_LINKED (queue->sinkpad)) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, queue, "queue %s is not linked", GST_ELEMENT_NAME (queue));
|
2003-01-15 21:01:58 +00:00
|
|
|
/* FIXME can this be? */
|
2003-03-27 03:16:08 +00:00
|
|
|
g_cond_signal (queue->not_empty);
|
2003-01-15 21:01:58 +00:00
|
|
|
|
|
|
|
ret = GST_STATE_FAILURE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GstScheduler *src_sched, *sink_sched;
|
|
|
|
|
|
|
|
src_sched = gst_pad_get_scheduler (GST_PAD_CAST (queue->srcpad));
|
|
|
|
sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (queue->sinkpad));
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2003-01-15 21:01:58 +00:00
|
|
|
if (src_sched == sink_sched) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, queue, "queue %s does not connect different schedulers",
|
2003-01-15 21:01:58 +00:00
|
|
|
GST_ELEMENT_NAME (queue));
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2003-02-11 21:03:51 +00:00
|
|
|
g_warning ("queue %s does not connect different schedulers",
|
2003-01-15 21:01:58 +00:00
|
|
|
GST_ELEMENT_NAME (queue));
|
|
|
|
|
|
|
|
ret = GST_STATE_FAILURE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queue->interrupt = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
gst_queue_locked_flush (queue);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2003-01-15 21:01:58 +00:00
|
|
|
|
|
|
|
error:
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "done with state change");
|
2001-05-25 21:00:07 +00:00
|
|
|
return ret;
|
2000-10-30 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_queue_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_QUEUE (object));
|
2001-01-20 17:59:25 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
queue = GST_QUEUE (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-05-25 21:00:07 +00:00
|
|
|
case ARG_LEAKY:
|
2002-01-11 15:49:47 +00:00
|
|
|
queue->leaky = g_value_get_enum (value);
|
2000-02-13 15:20:49 +00:00
|
|
|
break;
|
2001-05-25 21:00:07 +00:00
|
|
|
case ARG_MAX_LEVEL:
|
2001-12-22 21:18:17 +00:00
|
|
|
queue->size_buffers = g_value_get_int (value);
|
|
|
|
break;
|
2003-05-30 23:20:02 +00:00
|
|
|
case ARG_MIN_THRESHOLD_BYTES:
|
|
|
|
queue->min_threshold_bytes = g_value_get_int (value);
|
|
|
|
break;
|
2001-12-22 21:18:17 +00:00
|
|
|
case ARG_MAY_DEADLOCK:
|
|
|
|
queue->may_deadlock = g_value_get_boolean (value);
|
2000-12-26 23:51:04 +00:00
|
|
|
break;
|
2002-06-03 15:44:28 +00:00
|
|
|
case ARG_BLOCK_TIMEOUT:
|
|
|
|
queue->block_timeout = g_value_get_int (value);
|
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_queue_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_QUEUE (object));
|
2001-01-20 17:59:25 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
queue = GST_QUEUE (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-05-25 21:00:07 +00:00
|
|
|
case ARG_LEAKY:
|
2002-01-11 15:49:47 +00:00
|
|
|
g_value_set_enum (value, queue->leaky);
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_LEVEL:
|
2001-12-22 21:18:17 +00:00
|
|
|
g_value_set_int (value, queue->level_buffers);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
2000-02-13 15:20:49 +00:00
|
|
|
case ARG_MAX_LEVEL:
|
2001-12-22 21:18:17 +00:00
|
|
|
g_value_set_int (value, queue->size_buffers);
|
|
|
|
break;
|
2003-05-30 23:20:02 +00:00
|
|
|
case ARG_MIN_THRESHOLD_BYTES:
|
|
|
|
g_value_set_int (value, queue->min_threshold_bytes);
|
|
|
|
break;
|
2001-12-22 21:18:17 +00:00
|
|
|
case ARG_MAY_DEADLOCK:
|
|
|
|
g_value_set_boolean (value, queue->may_deadlock);
|
2000-12-26 23:51:04 +00:00
|
|
|
break;
|
2002-06-03 15:44:28 +00:00
|
|
|
case ARG_BLOCK_TIMEOUT:
|
|
|
|
g_value_set_int (value, queue->block_timeout);
|
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|