base: make GstQueueArray private to coreelements for now
[platform/upstream/gstreamer.git] / plugins / elements / gstdataqueue.h
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  */
21
22
23 #ifndef __GST_DATA_QUEUE_H__
24 #define __GST_DATA_QUEUE_H__
25
26 #include <gst/gst.h>
27 #include "gstqueuearray.h"
28
29 G_BEGIN_DECLS
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;
44
45 /**
46  * 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.
55  *
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.
58  */
59
60 struct _GstDataQueueItem
61 {
62   GstMiniObject *object;
63   guint size;
64   guint64 duration;
65   gboolean visible;
66
67   /* user supplied destroy function */
68   GDestroyNotify destroy;
69 };
70
71 /**
72  * GstDataQueueSize:
73  * @visible: number of buffers
74  * @bytes: number of bytes
75  * @time: amount of time
76  *
77  * Structure describing the size of a queue.
78  */
79 struct _GstDataQueueSize
80 {
81   guint visible;
82   guint bytes;
83   guint64 time;
84 };
85
86 /**
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.
93  * 
94  * The prototype of the function used to inform the queue that it should be
95  * considered as full.
96  *
97  * Returns: #TRUE if the queue should be considered full.
98  */
99 typedef gboolean (*GstDataQueueCheckFullFunction) (GstDataQueue * queue,
100     guint visible, guint bytes, guint64 time, gpointer checkdata);
101
102 typedef void (*GstDataQueueFullCallback) (GstDataQueue * queue, gpointer checkdata);
103 typedef void (*GstDataQueueEmptyCallback) (GstDataQueue * queue, gpointer checkdata);
104
105 /**
106  * GstDataQueue:
107  * @object: the parent structure
108  *
109  * Opaque #GstDataQueue structure.
110  */
111 struct _GstDataQueue
112 {
113   GObject object;
114
115   /*< private >*/
116   /* the array of data we're keeping our grubby hands on */
117   GstQueueArray *queue;
118
119   GstDataQueueSize cur_level;   /* size of the queue */
120   GstDataQueueCheckFullFunction checkfull;      /* Callback to check if the queue is full */
121   gpointer *checkdata;
122
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;
132
133   /* gpointer _gst_reserved[GST_PADDING]; */
134 };
135
136 struct _GstDataQueueClass
137 {
138   GObjectClass parent_class;
139
140   /* signals */
141   void (*empty) (GstDataQueue * queue);
142   void (*full) (GstDataQueue * queue);
143
144   /* gpointer _gst_reserved[GST_PADDING]; */
145 };
146
147 G_GNUC_INTERNAL
148 GType gst_data_queue_get_type (void);
149
150 G_GNUC_INTERNAL
151 GstDataQueue * gst_data_queue_new            (GstDataQueueCheckFullFunction checkfull,
152                                               gpointer checkdata) G_GNUC_MALLOC;
153
154 G_GNUC_INTERNAL
155 GstDataQueue * gst_data_queue_new_full       (GstDataQueueCheckFullFunction checkfull,
156                                               GstDataQueueFullCallback fullcallback,
157                                               GstDataQueueEmptyCallback emptycallback,
158                                               gpointer checkdata) G_GNUC_MALLOC;
159
160 G_GNUC_INTERNAL
161 gboolean       gst_data_queue_push           (GstDataQueue * queue, GstDataQueueItem * item);
162
163 G_GNUC_INTERNAL
164 gboolean       gst_data_queue_pop            (GstDataQueue * queue, GstDataQueueItem ** item);
165
166 G_GNUC_INTERNAL
167 void           gst_data_queue_flush          (GstDataQueue * queue);
168
169 G_GNUC_INTERNAL
170 void           gst_data_queue_set_flushing   (GstDataQueue * queue, gboolean flushing);
171
172 G_GNUC_INTERNAL
173 gboolean       gst_data_queue_drop_head      (GstDataQueue * queue, GType type);
174
175 G_GNUC_INTERNAL
176 gboolean       gst_data_queue_is_full        (GstDataQueue * queue);
177
178 G_GNUC_INTERNAL
179 gboolean       gst_data_queue_is_empty       (GstDataQueue * queue);
180
181 G_GNUC_INTERNAL
182 void           gst_data_queue_get_level      (GstDataQueue * queue, GstDataQueueSize *level);
183
184 G_GNUC_INTERNAL
185 void           gst_data_queue_limits_changed (GstDataQueue * queue);
186
187 G_END_DECLS
188
189 #endif /* __GST_DATA_QUEUE_H__ */