2 * Copyright (C) 2006 Edward Hervey <edward@fluendo.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_DATA_QUEUE_H__
24 #define __GST_DATA_QUEUE_H__
27 #include "gstqueuearray.h"
30 #define GST_TYPE_DATA_QUEUE \
31 (gst_data_queue_get_type())
32 #define GST_DATA_QUEUE(obj) \
33 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DATA_QUEUE,GstDataQueue))
34 #define GST_DATA_QUEUE_CLASS(klass) \
35 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DATA_QUEUE,GstDataQueueClass))
36 #define GST_IS_DATA_QUEUE(obj) \
37 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DATA_QUEUE))
38 #define GST_IS_DATA_QUEUE_CLASS(klass) \
39 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DATA_QUEUE))
40 typedef struct _GstDataQueue GstDataQueue;
41 typedef struct _GstDataQueueClass GstDataQueueClass;
42 typedef struct _GstDataQueueSize GstDataQueueSize;
43 typedef struct _GstDataQueueItem GstDataQueueItem;
47 * @object: the #GstMiniObject to queue.
48 * @size: the size in bytes of the miniobject.
49 * @duration: the duration in #GstClockTime of the miniobject. Can not be
50 * #GST_CLOCK_TIME_NONE.
51 * @visible: #TRUE if @object should be considered as a visible object.
52 * @destroy: The #GDestroyNotify function to use to free the #GstDataQueueItem.
53 * This function should also drop the reference to @object the owner of the
54 * #GstDataQueueItem is assumed to hold.
56 * Structure used by #GstDataQueue. You can supply a different structure, as
57 * long as the top of the structure is identical to this structure.
60 struct _GstDataQueueItem
62 GstMiniObject *object;
67 /* user supplied destroy function */
68 GDestroyNotify destroy;
73 * @visible: number of buffers
74 * @bytes: number of bytes
75 * @time: amount of time
77 * Structure describing the size of a queue.
79 struct _GstDataQueueSize
87 * GstDataQueueCheckFullFunction:
88 * @queue: a #GstDataQueue.
89 * @visible: The number of visible items currently in the queue.
90 * @bytes: The amount of bytes currently in the queue.
91 * @time: The accumulated duration of the items currently in the queue.
92 * @checkdata: The #gpointer registered when the #GstDataQueue was created.
94 * The prototype of the function used to inform the queue that it should be
97 * Returns: #TRUE if the queue should be considered full.
99 typedef gboolean (*GstDataQueueCheckFullFunction) (GstDataQueue * queue,
100 guint visible, guint bytes, guint64 time, gpointer checkdata);
102 typedef void (*GstDataQueueFullCallback) (GstDataQueue * queue, gpointer checkdata);
103 typedef void (*GstDataQueueEmptyCallback) (GstDataQueue * queue, gpointer checkdata);
107 * @object: the parent structure
109 * Opaque #GstDataQueue structure.
116 /* the array of data we're keeping our grubby hands on */
117 GstQueueArray *queue;
119 GstDataQueueSize cur_level; /* size of the queue */
120 GstDataQueueCheckFullFunction checkfull; /* Callback to check if the queue is full */
123 GMutex qlock; /* lock for queue (vs object lock) */
124 gboolean waiting_add;
125 GCond item_add; /* signals buffers now available for reading */
126 gboolean waiting_del;
127 GCond item_del; /* signals space now available for writing */
128 gboolean flushing; /* indicates whether conditions where signalled because
129 * of external flushing */
130 GstDataQueueFullCallback fullcallback;
131 GstDataQueueEmptyCallback emptycallback;
133 /* gpointer _gst_reserved[GST_PADDING]; */
136 struct _GstDataQueueClass
138 GObjectClass parent_class;
141 void (*empty) (GstDataQueue * queue);
142 void (*full) (GstDataQueue * queue);
144 /* gpointer _gst_reserved[GST_PADDING]; */
148 GType gst_data_queue_get_type (void);
151 GstDataQueue * gst_data_queue_new (GstDataQueueCheckFullFunction checkfull,
152 gpointer checkdata) G_GNUC_MALLOC;
155 GstDataQueue * gst_data_queue_new_full (GstDataQueueCheckFullFunction checkfull,
156 GstDataQueueFullCallback fullcallback,
157 GstDataQueueEmptyCallback emptycallback,
158 gpointer checkdata) G_GNUC_MALLOC;
161 gboolean gst_data_queue_push (GstDataQueue * queue, GstDataQueueItem * item);
164 gboolean gst_data_queue_pop (GstDataQueue * queue, GstDataQueueItem ** item);
167 void gst_data_queue_flush (GstDataQueue * queue);
170 void gst_data_queue_set_flushing (GstDataQueue * queue, gboolean flushing);
173 gboolean gst_data_queue_drop_head (GstDataQueue * queue, GType type);
176 gboolean gst_data_queue_is_full (GstDataQueue * queue);
179 gboolean gst_data_queue_is_empty (GstDataQueue * queue);
182 void gst_data_queue_get_level (GstDataQueue * queue, GstDataQueueSize *level);
185 void gst_data_queue_limits_changed (GstDataQueue * queue);
189 #endif /* __GST_DATA_QUEUE_H__ */