f1fd9be878478a2867569391496da9c40c997a27
[platform/upstream/gstreamer.git] / libs / gst / base / 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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22
23 #ifndef __GST_DATA_QUEUE_H__
24 #define __GST_DATA_QUEUE_H__
25
26 #include <gst/gst.h>
27
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;
43 typedef struct _GstDataQueuePrivate GstDataQueuePrivate;
44
45 /**
46  * GstDataQueueItem: (skip)
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   /* < private > */
71   gpointer _gst_reserved[GST_PADDING];
72 };
73
74 /**
75  * GstDataQueueSize: (skip)
76  * @visible: number of buffers
77  * @bytes: number of bytes
78  * @time: amount of time
79  *
80  * Structure describing the size of a queue.
81  */
82 struct _GstDataQueueSize
83 {
84   guint visible;
85   guint bytes;
86   guint64 time;
87 };
88
89 /**
90  * GstDataQueueCheckFullFunction: (skip)
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 typedef gboolean (*GstDataQueueCheckFullFunction) (GstDataQueue * queue,
103     guint visible, guint bytes, guint64 time, gpointer checkdata);
104
105 typedef void (*GstDataQueueFullCallback) (GstDataQueue * queue, gpointer checkdata);
106 typedef void (*GstDataQueueEmptyCallback) (GstDataQueue * queue, gpointer checkdata);
107
108 /**
109  * GstDataQueue:
110  * @object: the parent structure
111  *
112  * Opaque #GstDataQueue structure.
113  */
114 struct _GstDataQueue
115 {
116   GObject object;
117
118   /*< private >*/
119   GstDataQueuePrivate *priv;
120   gpointer _gst_reserved[GST_PADDING];
121 };
122
123 /**
124  * GstDataQueueClass:
125  */
126 struct _GstDataQueueClass
127 {
128   GObjectClass parent_class;
129
130   /* signals */
131   void (*empty) (GstDataQueue * queue);
132   void (*full) (GstDataQueue * queue);
133
134   gpointer _gst_reserved[GST_PADDING];
135 };
136
137 GType gst_data_queue_get_type (void);
138
139 GstDataQueue * gst_data_queue_new            (GstDataQueueCheckFullFunction checkfull,
140                                               GstDataQueueFullCallback fullcallback,
141                                               GstDataQueueEmptyCallback emptycallback,
142                                               gpointer checkdata) G_GNUC_MALLOC;
143
144 gboolean       gst_data_queue_push           (GstDataQueue * queue, GstDataQueueItem * item);
145 gboolean       gst_data_queue_push_force     (GstDataQueue * queue, GstDataQueueItem * item);
146
147 gboolean       gst_data_queue_pop            (GstDataQueue * queue, GstDataQueueItem ** item);
148 gboolean       gst_data_queue_peek           (GstDataQueue * queue, GstDataQueueItem ** item);
149
150 void           gst_data_queue_flush          (GstDataQueue * queue);
151
152 void           gst_data_queue_set_flushing   (GstDataQueue * queue, gboolean flushing);
153
154 gboolean       gst_data_queue_drop_head      (GstDataQueue * queue, GType type);
155
156 gboolean       gst_data_queue_is_full        (GstDataQueue * queue);
157
158 gboolean       gst_data_queue_is_empty       (GstDataQueue * queue);
159
160 void           gst_data_queue_get_level      (GstDataQueue * queue, GstDataQueueSize *level);
161
162 void           gst_data_queue_limits_changed (GstDataQueue * queue);
163
164 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
165 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstDataQueue, gst_object_unref)
166 #endif
167
168 G_END_DECLS
169
170 #endif /* __GST_DATA_QUEUE_H__ */