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>
|
|
|
|
*
|
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.
|
|
|
|
*/
|
|
|
|
|
2000-05-21 21:58:20 +00:00
|
|
|
//#define DEBUG_ENABLED
|
2000-06-18 13:50:18 +00:00
|
|
|
//#define STATUS_ENABLED
|
|
|
|
#ifdef STATUS_ENABLED
|
2001-05-25 21:00:07 +00:00
|
|
|
#define STATUS(A) GST_DEBUG(GST_CAT_DATAFLOW, A, GST_ELEMENT_NAME(queue))
|
2000-06-18 13:50:18 +00:00
|
|
|
#else
|
2001-01-20 17:59:25 +00:00
|
|
|
#define STATUS(A)
|
2000-06-18 13:50:18 +00:00
|
|
|
#endif
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#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"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
GstElementDetails gst_queue_details = {
|
|
|
|
"Queue",
|
|
|
|
"Connection",
|
|
|
|
"Simple data queue",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Queue signals and args */
|
|
|
|
enum {
|
2001-05-25 21:00:07 +00:00
|
|
|
LOW_WATERMARK,
|
|
|
|
HIGH_WATERMARK,
|
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,
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
static void gst_queue_class_init (GstQueueClass *klass);
|
|
|
|
static void gst_queue_init (GstQueue *queue);
|
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
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
static GstPadNegotiateReturn gst_queue_handle_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data);
|
2001-04-12 18:11:19 +00:00
|
|
|
static GstPadNegotiateReturn gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data);
|
2001-08-21 20:16:48 +00:00
|
|
|
static void gst_queue_chain (GstPad *pad, GstBuffer *buf);
|
|
|
|
static GstBuffer * gst_queue_get (GstPad *pad);
|
|
|
|
static GstBufferPool* gst_queue_get_bufferpool (GstPad *pad);
|
2001-04-16 21:45:02 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
static void gst_queue_locked_flush (GstQueue *queue);
|
2001-08-21 20:16:48 +00:00
|
|
|
static void gst_queue_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);
|
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;
|
2000-02-27 23:18:38 +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),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_queue_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstQueue),
|
|
|
|
4,
|
|
|
|
(GInstanceInitFunc)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
|
|
|
|
gst_queue_class_init (GstQueueClass *klass)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2000-10-30 21:02:08 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2000-10-30 21:02:08 +00:00
|
|
|
gstelement_class = (GstElementClass*)klass;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LEAKY,
|
|
|
|
g_param_spec_enum("leaky","Leaky","Where the queue leaks, if at all.",
|
|
|
|
GST_TYPE_QUEUE_LEAKY,GST_QUEUE_NO_LEAK,G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LEVEL,
|
|
|
|
g_param_spec_int("level","Level","How many buffers are in the queue.",
|
|
|
|
0,G_MAXINT,0,G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MAX_LEVEL,
|
|
|
|
g_param_spec_int("max_level","Maximum Level","How many buffers the queue holds.",
|
|
|
|
0,G_MAXINT,100,G_PARAM_READWRITE));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
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
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_queue_change_state);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
|
|
|
gst_queue_init (GstQueue *queue)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-12-26 23:51:04 +00:00
|
|
|
// scheduling on this kind of element is, well, interesting
|
|
|
|
GST_FLAG_SET (queue, GST_ELEMENT_DECOUPLED);
|
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);
|
2000-12-20 09:39:43 +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);
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_pad_set_negotiate_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_sink));
|
|
|
|
gst_pad_set_bufferpool_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_get_bufferpool));
|
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);
|
2000-12-20 09:39:43 +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);
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_pad_set_negotiate_function (queue->srcpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_src));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
queue->queue = NULL;
|
|
|
|
queue->level_buffers = 0;
|
|
|
|
queue->level_bytes = 0;
|
2001-05-25 21:00:07 +00:00
|
|
|
queue->level_time = 0LL;
|
|
|
|
queue->size_buffers = 100; // 100 buffers
|
|
|
|
queue->size_bytes = 100 * 1024; // 100KB
|
|
|
|
queue->size_time = 1000000000LL; // 1sec
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
queue->qlock = g_mutex_new ();
|
|
|
|
queue->reader = FALSE;
|
|
|
|
queue->writer = FALSE;
|
|
|
|
queue->not_empty = g_cond_new ();
|
|
|
|
queue->not_full = g_cond_new ();
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_THREAD, queue, "initialized queue's not_empty & not_full conditions\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
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-03-18 02:42:30 +00:00
|
|
|
static GstPadNegotiateReturn
|
2001-04-12 18:11:19 +00:00
|
|
|
gst_queue_handle_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
|
2001-03-12 21:02:12 +00:00
|
|
|
{
|
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
2001-04-12 18:11:19 +00:00
|
|
|
return gst_pad_negotiate_proxy (pad, queue->sinkpad, caps);
|
2001-03-12 21:02:12 +00:00
|
|
|
}
|
|
|
|
|
2001-03-18 02:42:30 +00:00
|
|
|
static GstPadNegotiateReturn
|
2001-04-12 18:11:19 +00:00
|
|
|
gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
|
2001-03-12 21:02:12 +00:00
|
|
|
{
|
|
|
|
GstQueue *queue;
|
|
|
|
|
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
2001-06-01 18:30:40 +00:00
|
|
|
return gst_pad_negotiate_proxy (pad, queue->srcpad, caps);
|
2001-03-12 21:02:12 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
|
|
|
gst_queue_cleanup_buffers (gpointer data, const gpointer user_data)
|
2000-07-12 22:52:42 +00:00
|
|
|
{
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, user_data, "cleaning buffer %p\n", data);
|
2000-11-11 15:13:50 +00:00
|
|
|
gst_buffer_unref (GST_BUFFER (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
|
|
|
{
|
2001-01-20 17:59:25 +00:00
|
|
|
g_slist_foreach (queue->queue, gst_queue_cleanup_buffers,
|
2001-10-27 20:28:31 +00:00
|
|
|
(gpointer) queue);
|
2000-11-25 14:18:47 +00:00
|
|
|
g_slist_free (queue->queue);
|
2001-01-20 17:59:25 +00:00
|
|
|
|
2000-10-30 21:02:08 +00:00
|
|
|
queue->queue = NULL;
|
|
|
|
queue->level_buffers = 0;
|
2001-01-07 03:42:27 +00:00
|
|
|
queue->timeval = NULL;
|
2000-10-30 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
static void
|
|
|
|
gst_queue_flush (GstQueue *queue)
|
|
|
|
{
|
|
|
|
g_mutex_lock (queue->qlock);
|
|
|
|
gst_queue_locked_flush (queue);
|
|
|
|
g_mutex_unlock (queue->qlock);
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
|
|
|
gst_queue_chain (GstPad *pad, GstBuffer *buf)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstQueue *queue;
|
2001-10-27 20:28:31 +00:00
|
|
|
gboolean reader;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
reader = FALSE;
|
2000-12-21 01:27:27 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
/* we have to lock the queue since we span threads */
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
|
|
|
|
g_mutex_lock (queue->qlock);
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld\n", pthread_self ());
|
|
|
|
|
|
|
|
if (GST_IS_EVENT(buf)) {
|
|
|
|
GstEvent *event = GST_EVENT(buf);
|
|
|
|
switch (GST_EVENT_TYPE(event)) {
|
|
|
|
case GST_EVENT_FLUSH:
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "flushing queue\n");
|
|
|
|
gst_queue_locked_flush (queue);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-07-12 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "adding buffer %p of size %d\n",buf,GST_BUFFER_SIZE(buf));
|
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
if (queue->level_buffers == queue->size_buffers) {
|
2001-05-25 21:00:07 +00:00
|
|
|
// if this is a leaky queue...
|
|
|
|
if (queue->leaky) {
|
2001-10-27 20:28:31 +00:00
|
|
|
// FIXME don't want to leak events!
|
2001-05-25 21:00:07 +00:00
|
|
|
// if we leak on the upstream side, drop the current buffer
|
|
|
|
if (queue->leaky == GST_QUEUE_LEAK_UPSTREAM) {
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
|
2001-10-27 20:28:31 +00:00
|
|
|
if (GST_IS_EVENT (buf))
|
|
|
|
fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
|
|
|
|
GST_ELEMENT_NAME(GST_ELEMENT(queue)),
|
|
|
|
GST_EVENT_TYPE(GST_EVENT(buf)));
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_buffer_unref(buf);
|
|
|
|
// now we have to clean up and exit right away
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
2001-05-25 21:00:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// otherwise we have to push a buffer off the other end
|
|
|
|
else {
|
|
|
|
GSList *front;
|
|
|
|
GstBuffer *leakbuf;
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on downstream end\n");
|
|
|
|
front = queue->queue;
|
|
|
|
leakbuf = (GstBuffer *)(front->data);
|
2001-10-27 20:28:31 +00:00
|
|
|
if (GST_IS_EVENT (leakbuf))
|
|
|
|
fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
|
|
|
|
GST_ELEMENT_NAME(GST_ELEMENT(queue)),
|
|
|
|
GST_EVENT_TYPE(GST_EVENT(leakbuf)));
|
2001-05-25 21:00:07 +00:00
|
|
|
queue->level_buffers--;
|
|
|
|
queue->level_bytes -= GST_BUFFER_SIZE(leakbuf);
|
|
|
|
gst_buffer_unref(leakbuf);
|
|
|
|
queue->queue = g_slist_remove_link (queue->queue, front);
|
|
|
|
g_slist_free (front);
|
|
|
|
}
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre full wait, level:%d/%d\n",
|
|
|
|
queue->level_buffers, queue->size_buffers);
|
|
|
|
while (queue->level_buffers == queue->size_buffers) {
|
2001-05-25 21:00:07 +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
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING ||
|
|
|
|
// GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
|
2001-05-25 21:00:07 +00:00
|
|
|
GST_STATE_PENDING(GST_SCHED_PARENT(GST_ELEMENT_SCHED(GST_PAD_PARENT(GST_PAD_PEER(queue->sinkpad))))) !=
|
2001-06-25 01:20:11 +00:00
|
|
|
GST_STATE_VOID_PENDING)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)\n");
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING\n");
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2001-05-25 21:00:07 +00:00
|
|
|
cothread_switch(cothread_current_main());
|
|
|
|
}
|
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
|
|
|
|
if (queue->writer)
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple writers on queue!\n");
|
|
|
|
queue->writer = TRUE;
|
|
|
|
g_cond_wait (queue->not_full, queue->qlock);
|
|
|
|
queue->writer = FALSE;
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_full signal\n");
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post full wait, level:%d/%d\n",
|
|
|
|
queue->level_buffers, queue->size_buffers);
|
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 */
|
2000-11-25 14:18:47 +00:00
|
|
|
queue->queue = g_slist_append (queue->queue, buf);
|
2000-05-21 21:58:20 +00:00
|
|
|
queue->level_buffers++;
|
2001-05-25 21:00:07 +00:00
|
|
|
queue->level_bytes += GST_BUFFER_SIZE(buf);
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)+ level:%d/%d\n",
|
|
|
|
GST_DEBUG_PAD_NAME(pad),
|
|
|
|
queue->level_buffers, queue->size_buffers);
|
|
|
|
|
|
|
|
/* reader waiting on an empty queue */
|
|
|
|
reader = queue->reader;
|
|
|
|
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
if (reader)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_empty\n");
|
|
|
|
g_cond_signal (queue->not_empty);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-21 01:27:27 +00:00
|
|
|
static GstBuffer *
|
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;
|
2000-01-30 09:03:00 +00:00
|
|
|
GstBuffer *buf = NULL;
|
2000-09-24 14:29:49 +00:00
|
|
|
GSList *front;
|
2001-10-27 20:28:31 +00:00
|
|
|
gboolean writer;
|
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
|
|
|
|
|
|
|
writer = FALSE;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
/* have to lock for thread-safety */
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
|
|
|
|
g_mutex_lock (queue->qlock);
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld %p\n", pthread_self (), queue->not_empty);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
|
|
|
|
while (queue->level_buffers == 0) {
|
2001-05-25 21:00:07 +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
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING ||
|
|
|
|
// GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
|
2001-05-25 21:00:07 +00:00
|
|
|
GST_STATE_PENDING(GST_SCHED_PARENT(GST_ELEMENT_SCHED(GST_PAD_PARENT(GST_PAD_PEER(queue->srcpad))))) !=
|
2001-06-25 01:20:11 +00:00
|
|
|
GST_STATE_VOID_PENDING)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)\n");
|
2001-06-25 01:20:11 +00:00
|
|
|
if (GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING\n");
|
|
|
|
g_mutex_unlock (queue->qlock);
|
2001-05-25 21:00:07 +00:00
|
|
|
cothread_switch(cothread_current_main());
|
|
|
|
}
|
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
|
|
|
|
if (queue->reader)
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple readers on queue!\n");
|
|
|
|
queue->reader = TRUE;
|
|
|
|
g_cond_wait (queue->not_empty, queue->qlock);
|
|
|
|
queue->reader = FALSE;
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_empty signal\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
front = queue->queue;
|
|
|
|
buf = (GstBuffer *)(front->data);
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "retrieved buffer %p from queue\n", buf);
|
2000-11-25 14:18:47 +00:00
|
|
|
queue->queue = g_slist_remove_link (queue->queue, front);
|
|
|
|
g_slist_free (front);
|
2000-12-21 01:27:27 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
queue->level_buffers--;
|
|
|
|
queue->level_bytes -= GST_BUFFER_SIZE(buf);
|
2001-10-27 20:28:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)- level:%d/%d\n",
|
|
|
|
GST_DEBUG_PAD_NAME(pad),
|
|
|
|
queue->level_buffers, queue->size_buffers);
|
|
|
|
|
|
|
|
/* writer waiting on a full queue */
|
|
|
|
writer = queue->writer;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-10-27 20:28:31 +00:00
|
|
|
g_mutex_unlock (queue->qlock);
|
|
|
|
|
|
|
|
if (writer)
|
|
|
|
{
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_full\n");
|
|
|
|
g_cond_signal (queue->not_full);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME where should this be? locked?
|
|
|
|
if (GST_IS_EVENT(buf)) {
|
|
|
|
GstEvent *event = GST_EVENT(buf);
|
|
|
|
switch (GST_EVENT_TYPE(event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue eos\n");
|
|
|
|
gst_element_set_state (GST_ELEMENT (queue), GST_STATE_PAUSED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-02-13 13:43:32 +00:00
|
|
|
|
2000-12-21 01:27:27 +00:00
|
|
|
return buf;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
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-11-25 14:18:47 +00:00
|
|
|
g_return_val_if_fail (GST_IS_QUEUE (element), GST_STATE_FAILURE);
|
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
|
|
|
|
|
|
|
// lock the queue so another thread (not in sync with this thread's state)
|
|
|
|
// can't call this queue's _get (or whatever)
|
|
|
|
GST_LOCK (queue);
|
2000-10-30 21:02:08 +00:00
|
|
|
|
|
|
|
/* if going down into NULL state, clear out buffers*/
|
2000-11-25 14:18:47 +00:00
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_READY) {
|
2000-10-30 21:02:08 +00:00
|
|
|
/* otherwise (READY or higher) we need to open the file */
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_queue_flush (queue);
|
2000-10-30 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
// if we haven't failed already, give the parent class a chance to ;-)
|
2000-11-25 14:18:47 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
|
|
|
gboolean valid_handler = FALSE;
|
2001-06-25 01:20:11 +00:00
|
|
|
guint state_change_id = g_signal_lookup("state_change", G_OBJECT_TYPE(element));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
// determine whether we need to block the parent (element) class'
|
|
|
|
// STATE_CHANGE signal so we can UNLOCK before returning. we block
|
|
|
|
// it if we could find the state_change signal AND there's a signal
|
|
|
|
// handler attached to it.
|
|
|
|
//
|
|
|
|
// note: this assumes that change_state() *only* emits state_change signal.
|
|
|
|
// if element change_state() emits other signals, they need to be blocked
|
|
|
|
// as well.
|
|
|
|
if (state_change_id &&
|
2001-06-25 01:20:11 +00:00
|
|
|
g_signal_has_handler_pending(G_OBJECT(element), state_change_id, 0, FALSE))
|
2001-05-25 21:00:07 +00:00
|
|
|
valid_handler = TRUE;
|
|
|
|
if (valid_handler)
|
2001-06-25 01:20:11 +00:00
|
|
|
g_signal_handler_block(G_OBJECT(element), state_change_id);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
if (valid_handler)
|
2001-06-25 01:20:11 +00:00
|
|
|
g_signal_handler_unblock(G_OBJECT(element), state_change_id);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
// UNLOCK, *then* emit signal (if there's one there)
|
|
|
|
GST_UNLOCK(queue);
|
|
|
|
if (valid_handler)
|
2001-06-25 01:20:11 +00:00
|
|
|
g_signal_emit(G_OBJECT (element), state_change_id, 0, GST_STATE(element));
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = GST_STATE_SUCCESS;
|
|
|
|
GST_UNLOCK(queue);
|
|
|
|
}
|
2000-10-30 21:02:08 +00:00
|
|
|
|
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:
|
2001-06-25 01:20:11 +00:00
|
|
|
queue->leaky = g_value_get_int(value);
|
2000-02-13 15:20:49 +00:00
|
|
|
break;
|
2001-05-25 21:00:07 +00:00
|
|
|
case ARG_MAX_LEVEL:
|
2001-06-25 01:20:11 +00:00
|
|
|
queue->size_buffers = g_value_get_int(value);
|
2000-12-26 23:51:04 +00:00
|
|
|
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:
|
2001-06-25 01:20:11 +00:00
|
|
|
g_value_set_int(value, queue->leaky);
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_LEVEL:
|
2001-06-25 01:20:11 +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-06-25 01:20:11 +00:00
|
|
|
g_value_set_int(value, queue->size_buffers);
|
2000-12-26 23:51:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|