queue2: add option to remove the temp-file
[platform/upstream/gstreamer.git] / plugins / elements / gstqueue2.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2003 Colin Walters <cwalters@gnome.org>
4  *                    2000,2005,2007 Wim Taymans <wim.taymans@gmail.com>
5  *                    2007 Thiago Sousa Santos <thiagoss@lcc.ufcg.edu.br>
6  *
7  * gstqueue2.h:
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24 #ifndef __GST_QUEUE2_H__
25 #define __GST_QUEUE2_H__
26
27 #include <gst/gst.h>
28 #include <stdio.h>
29
30 G_BEGIN_DECLS
31
32 #define GST_TYPE_QUEUE2 \
33   (gst_queue2_get_type())
34 #define GST_QUEUE2(obj) \
35   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QUEUE2,GstQueue2))
36 #define GST_QUEUE2_CLASS(klass) \
37   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QUEUE2,GstQueue2Class))
38 #define GST_IS_QUEUE2(obj) \
39   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QUEUE2))
40 #define GST_IS_QUEUE2_CLASS(klass) \
41   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QUEUE2))
42 #define GST_QUEUE2_CAST(obj) \
43   ((GstQueue2 *)(obj))
44
45 typedef struct _GstQueue2 GstQueue2;
46 typedef struct _GstQueue2Size GstQueue2Size;
47 typedef struct _GstQueue2Class GstQueue2Class;
48
49 /* used to keep track of sizes (current and max) */
50 struct _GstQueue2Size
51 {
52   guint buffers;
53   guint bytes;
54   guint64 time;
55   guint64 rate_time;
56 };
57
58 struct _GstQueue2
59 {
60   GstElement element;
61
62   /*< private > */
63   GstPad *sinkpad;
64   GstPad *srcpad;
65
66   /* segments to keep track of timestamps */
67   GstSegment sink_segment;
68   GstSegment src_segment;
69
70   /* flowreturn when srcpad is paused */
71   GstFlowReturn srcresult;
72   gboolean is_eos;
73   gboolean unexpected;
74
75   /* the queue of data we're keeping our hands on */
76   GQueue *queue;
77
78   GstQueue2Size cur_level;       /* currently in the queue */
79   GstQueue2Size max_level;       /* max. amount of data allowed in the queue */
80   gboolean use_buffering;
81   gboolean use_rate_estimate;
82   GstClockTime buffering_interval;
83   gint low_percent;             /* low/high watermarks for buffering */
84   gint high_percent;
85
86   /* current buffering state */
87   gboolean is_buffering;
88   guint buffering_iteration;
89
90   /* for measuring input/output rates */
91   GTimer *in_timer;
92   gboolean in_timer_started;
93   gdouble last_in_elapsed;
94   guint64 bytes_in;
95   gdouble byte_in_rate;
96
97   GTimer *out_timer;
98   gboolean out_timer_started;
99   gdouble last_out_elapsed;
100   guint64 bytes_out;
101   gdouble byte_out_rate;
102
103   GMutex *qlock;                /* lock for queue (vs object lock) */
104   gboolean waiting_add;
105   GCond *item_add;              /* signals buffers now available for reading */
106   gboolean waiting_del;
107   GCond *item_del;              /* signals space now available for writing */
108
109   /* temp location stuff */
110   gchar *temp_template;
111   gboolean temp_location_set;
112   gchar *temp_location;
113   gboolean temp_remove;
114   FILE *temp_file;
115   guint64 writing_pos;
116   guint64 reading_pos;
117   guint64 max_reading_pos;
118   /* we need this to send the first new segment event of the stream
119    * because we can't save it on the file */
120   gboolean segment_event_received;
121   GstEvent *starting_segment;
122
123 };
124
125 struct _GstQueue2Class
126 {
127   GstElementClass parent_class;
128 };
129
130 GType gst_queue2_get_type (void);
131
132 G_END_DECLS
133
134 #endif /* __GST_QUEUE2_H__ */