1 /* GStreamer
2 * Copyright (C) 2006 Edward Hervey <edward@fluendo.com>
3 *
4 * gstdataqueue.h:
5 *
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.
10 *
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.
15 *
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.
20 */
23 #ifndef __GST_DATA_QUEUE_H__
24 #define __GST_DATA_QUEUE_H__
26 #include <gst/gst.h>
28 G_BEGIN_DECLS
29 #define GST_TYPE_DATA_QUEUE \
30 (gst_data_queue_get_type())
31 #define GST_DATA_QUEUE(obj) \
32 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DATA_QUEUE,GstDataQueue))
33 #define GST_DATA_QUEUE_CLASS(klass) \
34 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DATA_QUEUE,GstDataQueueClass))
35 #define GST_IS_DATA_QUEUE(obj) \
36 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DATA_QUEUE))
37 #define GST_IS_DATA_QUEUE_CLASS(klass) \
38 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DATA_QUEUE))
39 typedef struct _GstDataQueue GstDataQueue;
40 typedef struct _GstDataQueueClass GstDataQueueClass;
41 typedef struct _GstDataQueueSize GstDataQueueSize;
42 typedef struct _GstDataQueueItem GstDataQueueItem;
44 /**
45 * GstDataQueueItem:
46 * @object: the #GstMiniObject to queue.
47 * @size: the size in bytes of the miniobject.
48 * @duration: the duration in #GstClockTime of the miniobject. Can not be
49 * #GST_CLOCK_TIME_NONE.
50 * @visible: #TRUE if @object should be considered as a visible object.
51 * @destroy: The #GDestroyNotify function to use to free the #GstDataQueueItem.
52 * This function should also drop the reference to @object the owner of the
53 * #GstDataQueueItem is assumed to hold.
54 *
55 * Structure used by #GstDataQueue. You can supply a different structure, as
56 * long as the top of the structure is identical to this structure.
57 *
58 * Since: 0.10.11
59 */
61 struct _GstDataQueueItem
62 {
63 GstMiniObject *object;
64 guint size;
65 guint64 duration;
66 gboolean visible;
68 /* user supplied destroy function */
69 GDestroyNotify destroy;
70 };
72 /**
73 * GstDataQueueSize:
74 * @visible: number of buffers
75 * @bytes: number of bytes
76 * @time: amount of time
77 *
78 * Structure describing the size of a queue.
79 *
80 * Since: 0.10.11
81 */
82 struct _GstDataQueueSize
83 {
84 guint visible;
85 guint bytes;
86 guint64 time;
87 };
89 /**
90 * GstDataQueueCheckFullFunction:
91 * @queue: a #GstDataQueue.
92 * @visible: The number of visible items currently in the queue.
93 * @bytes: The amount of bytes currently in the queue.
94 * @time: The accumulated duration of the items currently in the queue.
95 * @checkdata: The #gpointer registered when the #GstDataQueue was created.
96 *
97 * The prototype of the function used to inform the queue that it should be
98 * considered as full.
99 *
100 * Returns: #TRUE if the queue should be considered full.
101 *
102 * Since: 0.10.11
103 */
104 typedef gboolean (*GstDataQueueCheckFullFunction) (GstDataQueue * queue,
105 guint visible, guint bytes, guint64 time, gpointer checkdata);
107 typedef void (*GstDataQueueFullCallback) (GstDataQueue * queue, gpointer checkdata);
108 typedef void (*GstDataQueueEmptyCallback) (GstDataQueue * queue, gpointer checkdata);
110 /**
111 * GstDataQueue:
112 * @object: the parent structure
113 *
114 * Opaque #GstDataQueue structure.
115 *
116 * Since: 0.10.11
117 */
118 struct _GstDataQueue
119 {
120 GObject object;
122 /*< private >*/
123 /* the queue of data we're keeping our grubby hands on */
124 GQueue *queue;
126 GstDataQueueSize cur_level; /* size of the queue */
127 GstDataQueueCheckFullFunction checkfull; /* Callback to check if the queue is full */
128 gpointer *checkdata;
130 GMutex *qlock; /* lock for queue (vs object lock) */
131 GCond *item_add; /* signals buffers now available for reading */
132 GCond *item_del; /* signals space now available for writing */
133 gboolean flushing; /* indicates whether conditions where signalled because
134 * of external flushing */
135 GstDataQueueFullCallback fullcallback;
136 GstDataQueueEmptyCallback emptycallback;
138 union {
139 struct {
140 gboolean waiting_add;
141 gboolean waiting_del;
142 } ABI;
143 gpointer _gst_reserved[GST_PADDING - 2];
144 } abidata;
145 };
147 struct _GstDataQueueClass
148 {
149 GObjectClass parent_class;
151 /* signals */
152 void (*empty) (GstDataQueue * queue);
153 void (*full) (GstDataQueue * queue);
155 gpointer _gst_reserved[GST_PADDING];
156 };
158 GType gst_data_queue_get_type (void);
160 GstDataQueue * gst_data_queue_new (GstDataQueueCheckFullFunction checkfull,
161 gpointer checkdata) G_GNUC_MALLOC;
163 GstDataQueue * gst_data_queue_new_full (GstDataQueueCheckFullFunction checkfull,
164 GstDataQueueFullCallback fullcallback,
165 GstDataQueueEmptyCallback emptycallback,
166 gpointer checkdata) G_GNUC_MALLOC;
168 gboolean gst_data_queue_push (GstDataQueue * queue, GstDataQueueItem * item);
169 gboolean gst_data_queue_pop (GstDataQueue * queue, GstDataQueueItem ** item);
171 void gst_data_queue_flush (GstDataQueue * queue);
172 void gst_data_queue_set_flushing (GstDataQueue * queue, gboolean flushing);
174 gboolean gst_data_queue_drop_head (GstDataQueue * queue, GType type);
176 gboolean gst_data_queue_is_full (GstDataQueue * queue);
177 gboolean gst_data_queue_is_empty (GstDataQueue * queue);
179 void gst_data_queue_get_level (GstDataQueue * queue, GstDataQueueSize *level);
180 void gst_data_queue_limits_changed (GstDataQueue * queue);
182 G_END_DECLS
184 #endif /* __GST_DATA_QUEUE_H__ */