renatofilho@787: /* GStreamer renatofilho@787: * Copyright (C) 2006 Edward Hervey renatofilho@787: * renatofilho@787: * gstdataqueue.h: renatofilho@787: * renatofilho@787: * This library is free software; you can redistribute it and/or renatofilho@787: * modify it under the terms of the GNU Library General Public renatofilho@787: * License as published by the Free Software Foundation; either renatofilho@787: * version 2 of the License, or (at your option) any later version. renatofilho@787: * renatofilho@787: * This library is distributed in the hope that it will be useful, renatofilho@787: * but WITHOUT ANY WARRANTY; without even the implied warranty of renatofilho@787: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU renatofilho@787: * Library General Public License for more details. renatofilho@787: * renatofilho@787: * You should have received a copy of the GNU Library General Public renatofilho@787: * License along with this library; if not, write to the renatofilho@787: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, renatofilho@787: * Boston, MA 02111-1307, USA. renatofilho@787: */ renatofilho@787: renatofilho@787: renatofilho@787: #ifndef __GST_DATA_QUEUE_H__ renatofilho@787: #define __GST_DATA_QUEUE_H__ renatofilho@787: renatofilho@787: #include renatofilho@787: renatofilho@787: G_BEGIN_DECLS renatofilho@787: #define GST_TYPE_DATA_QUEUE \ renatofilho@787: (gst_data_queue_get_type()) renatofilho@787: #define GST_DATA_QUEUE(obj) \ renatofilho@787: (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DATA_QUEUE,GstDataQueue)) renatofilho@787: #define GST_DATA_QUEUE_CLASS(klass) \ renatofilho@787: (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DATA_QUEUE,GstDataQueueClass)) renatofilho@787: #define GST_IS_DATA_QUEUE(obj) \ renatofilho@787: (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DATA_QUEUE)) renatofilho@787: #define GST_IS_DATA_QUEUE_CLASS(klass) \ renatofilho@787: (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DATA_QUEUE)) renatofilho@787: typedef struct _GstDataQueue GstDataQueue; renatofilho@787: typedef struct _GstDataQueueClass GstDataQueueClass; renatofilho@787: typedef struct _GstDataQueueSize GstDataQueueSize; renatofilho@787: typedef struct _GstDataQueueItem GstDataQueueItem; renatofilho@787: renatofilho@787: /** renatofilho@787: * GstDataQueueItem: renatofilho@787: * @object: the #GstMiniObject to queue. renatofilho@787: * @size: the size in bytes of the miniobject. renatofilho@787: * @duration: the duration in #GstClockTime of the miniobject. Can not be renatofilho@787: * #GST_CLOCK_TIME_NONE. renatofilho@787: * @visible: #TRUE if @object should be considered as a visible object. renatofilho@787: * @destroy: The #GDestroyNotify function to use to free the #GstDataQueueItem. renatofilho@787: * This function should also drop the reference to @object the owner of the renatofilho@787: * #GstDataQueueItem is assumed to hold. renatofilho@787: * renatofilho@787: * Structure used by #GstDataQueue. You can supply a different structure, as renatofilho@787: * long as the top of the structure is identical to this structure. renatofilho@787: */ renatofilho@787: renatofilho@787: struct _GstDataQueueItem renatofilho@787: { renatofilho@787: GstMiniObject *object; renatofilho@787: guint size; renatofilho@787: guint64 duration; renatofilho@787: gboolean visible; renatofilho@787: renatofilho@787: /* user supplied destroy function */ renatofilho@787: GDestroyNotify destroy; renatofilho@787: }; renatofilho@787: renatofilho@787: /** renatofilho@787: * GstDataQueueSize: renatofilho@787: * @visible: number of buffers renatofilho@787: * @bytes: number of bytes renatofilho@787: * @time: amount of time renatofilho@787: * renatofilho@787: * Structure describing the size of a queue. renatofilho@787: */ renatofilho@787: struct _GstDataQueueSize renatofilho@787: { renatofilho@787: guint visible; renatofilho@787: guint bytes; renatofilho@787: guint64 time; renatofilho@787: }; renatofilho@787: renatofilho@787: /** renatofilho@787: * GstDataQueueCheckFullFunction: renatofilho@787: * @queue: a #GstDataQueue. renatofilho@787: * @visible: The number of visible items currently in the queue. renatofilho@787: * @bytes: The amount of bytes currently in the queue. renatofilho@787: * @time: The accumulated duration of the items currently in the queue. renatofilho@787: * @checkdata: The #gpointer registered when the #GstDataQueue was created. renatofilho@787: * renatofilho@787: * The prototype of the function used to inform the queue that it should be renatofilho@787: * considered as full. renatofilho@787: * renatofilho@787: * Returns: #TRUE if the queue should be considered full. renatofilho@787: */ renatofilho@787: typedef gboolean (*GstDataQueueCheckFullFunction) (GstDataQueue * queue, renatofilho@787: guint visible, guint bytes, guint64 time, gpointer checkdata); renatofilho@787: renatofilho@787: /** renatofilho@787: * GstDataQueue: renatofilho@787: * renatofilho@787: * Opaque #GstDataQueue structure. renatofilho@787: */ renatofilho@787: struct _GstDataQueue renatofilho@787: { renatofilho@787: GObject object; renatofilho@787: renatofilho@787: /*< private > */ renatofilho@787: /* the queue of data we're keeping our grubby hands on */ renatofilho@787: GQueue *queue; renatofilho@787: renatofilho@787: GstDataQueueSize cur_level; /* size of the queue */ renatofilho@787: GstDataQueueCheckFullFunction checkfull; /* Callback to check if the queue is full */ renatofilho@787: gpointer *checkdata; renatofilho@787: renatofilho@787: GMutex *qlock; /* lock for queue (vs object lock) */ renatofilho@787: GCond *item_add; /* signals buffers now available for reading */ renatofilho@787: GCond *item_del; /* signals space now available for writing */ renatofilho@787: gboolean flushing; /* indicates whether conditions where signalled because renatofilho@787: * of external flushing */ renatofilho@787: renatofilho@787: gpointer _gst_reserved[GST_PADDING]; renatofilho@787: }; renatofilho@787: renatofilho@787: struct _GstDataQueueClass renatofilho@787: { renatofilho@787: GObjectClass parent_class; renatofilho@787: renatofilho@787: /* signals */ renatofilho@787: void (*empty) (GstDataQueue * queue); renatofilho@787: void (*full) (GstDataQueue * queue); renatofilho@787: renatofilho@787: gpointer _gst_reserved[GST_PADDING]; renatofilho@787: }; renatofilho@787: renatofilho@787: GType gst_data_queue_get_type (void); renatofilho@787: renatofilho@787: GstDataQueue * gst_data_queue_new (GstDataQueueCheckFullFunction checkfull, renatofilho@787: gpointer checkdata); renatofilho@787: renatofilho@787: gboolean gst_data_queue_push (GstDataQueue * queue, GstDataQueueItem * item); renatofilho@787: gboolean gst_data_queue_pop (GstDataQueue * queue, GstDataQueueItem ** item); renatofilho@787: renatofilho@787: void gst_data_queue_flush (GstDataQueue * queue); renatofilho@787: void gst_data_queue_set_flushing (GstDataQueue * queue, gboolean flushing); renatofilho@787: renatofilho@787: gboolean gst_data_queue_drop_head (GstDataQueue * queue, GType type); renatofilho@787: renatofilho@787: gboolean gst_data_queue_is_full (GstDataQueue * queue); renatofilho@787: gboolean gst_data_queue_is_empty (GstDataQueue * queue); renatofilho@787: renatofilho@787: void gst_data_queue_get_level (GstDataQueue * queue, GstDataQueueSize *level); renatofilho@787: void gst_data_queue_limits_changed (GstDataQueue * queue); renatofilho@787: renatofilho@787: G_END_DECLS renatofilho@787: renatofilho@787: #endif /* __GST_DATA_QUEUE_H__ */