basesrc: Downgrade EOS warning
[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., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 #ifndef __GST_QUEUE2_H__
25 #define __GST_QUEUE2_H__
26
27 #include <gst/gst.h>
28 #include <stdio.h>
29 #include <gst/base/gstqueuearray.h>
30
31 G_BEGIN_DECLS
32
33 #define GST_TYPE_QUEUE2 \
34   (gst_queue2_get_type())
35 #define GST_QUEUE2(obj) \
36   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QUEUE2,GstQueue2))
37 #define GST_QUEUE2_CLASS(klass) \
38   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QUEUE2,GstQueue2Class))
39 #define GST_IS_QUEUE2(obj) \
40   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QUEUE2))
41 #define GST_IS_QUEUE2_CLASS(klass) \
42   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QUEUE2))
43 #define GST_QUEUE2_CAST(obj) \
44   ((GstQueue2 *)(obj))
45
46 typedef struct _GstQueue2 GstQueue2;
47 typedef struct _GstQueue2Size GstQueue2Size;
48 typedef struct _GstQueue2Class GstQueue2Class;
49 typedef struct _GstQueue2Range GstQueue2Range;
50
51 /* used to keep track of sizes (current and max) */
52 struct _GstQueue2Size
53 {
54   guint buffers;
55   guint bytes;
56   guint64 time;
57   guint64 rate_time;
58 };
59
60 struct _GstQueue2Range
61 {
62   GstQueue2Range *next;
63
64   guint64 offset;          /* offset of range start in source */
65   guint64 rb_offset;       /* offset of range start in ring buffer */
66   guint64 writing_pos;     /* writing position in source */
67   guint64 rb_writing_pos;  /* writing position in ring buffer */
68   guint64 reading_pos;     /* reading position in source */
69   guint64 max_reading_pos; /* latest requested offset in source */
70 };
71
72 struct _GstQueue2
73 {
74   GstElement element;
75
76   /*< private > */
77   GstPad *sinkpad;
78   GstPad *srcpad;
79
80   /* upstream size in bytes (if downstream is operating in pull mode) */
81   guint64 upstream_size;
82
83   /* segments to keep track of timestamps */
84   GstSegment sink_segment;
85   GstSegment src_segment;
86
87   /* Position of src/sink */
88   GstClockTime sinktime, srctime;
89   /* TRUE if either position needs to be recalculated */
90   gboolean sink_tainted, src_tainted;
91   /* Bitrates taken from tags */
92   guint sink_tags_bitrate;
93   guint src_tags_bitrate;
94
95   /* flowreturn when srcpad is paused */
96   GstFlowReturn srcresult;
97   GstFlowReturn sinkresult;
98   gboolean is_eos;
99   gboolean unexpected;
100
101   /* the queue of data we're keeping our hands on */
102   GstQueueArray *queue;
103
104   GCond query_handled;
105   gboolean last_query; /* result of last serialized query */
106   GstQuery *last_handled_query;
107
108   GstQueue2Size cur_level;       /* currently in the queue */
109   GstQueue2Size max_level;       /* max. amount of data allowed in the queue */
110   gboolean use_buffering;
111   gboolean use_tags_bitrate;
112   gboolean use_bitrate_query;
113   gboolean use_rate_estimate;
114   GstClockTime buffering_interval;
115   guint downstream_bitrate;     /* the bitrate reported by downstream */
116
117   /* low/high watermarks for buffering */
118   gint low_watermark;
119   gint high_watermark;
120
121   /* current buffering state */
122   gboolean is_buffering;
123   gint buffering_percent;
124   gint last_posted_buffering_percent;
125
126   /* for measuring input/output rates */
127   GTimer *in_timer;
128   gboolean in_timer_started;
129   gdouble last_update_in_rates_elapsed;
130   gdouble last_in_elapsed;
131   guint64 bytes_in;
132   gdouble byte_in_rate;
133   gdouble byte_in_period;
134
135   GTimer *out_timer;
136   gboolean out_timer_started;
137   gdouble last_out_elapsed;
138   guint64 bytes_out;
139   gdouble byte_out_rate;
140
141   GMutex qlock;                /* lock for queue (vs object lock) */
142   gboolean waiting_add;
143   GCond item_add;              /* signals buffers now available for reading */
144   gboolean waiting_del;
145   GCond item_del;              /* signals space now available for writing */
146
147   /* temp location stuff */
148   gchar *temp_template;
149   gboolean temp_location_set;
150   gchar *temp_location;
151   gboolean temp_remove;
152   FILE *temp_file;
153   /* list of downloaded areas and the current area */
154   GstQueue2Range *ranges;
155   GstQueue2Range *current;
156   /* we need this to send the first new segment event of the stream
157    * because we can't save it on the file */
158   gboolean segment_event_received;
159   GstEvent *starting_segment;
160   gboolean seeking;
161
162   GstEvent *stream_start_event;
163
164   guint64 ring_buffer_max_size;
165   guint8 * ring_buffer;
166
167   volatile gint downstream_may_block;
168
169   GstBufferingMode mode;
170   gint64 buffering_left;
171   gint avg_in;
172   gint avg_out;
173   gboolean percent_changed;
174   GMutex buffering_post_lock; /* assures only one posted at a time */
175 };
176
177 struct _GstQueue2Class
178 {
179   GstElementClass parent_class;
180 };
181
182 G_GNUC_INTERNAL GType gst_queue2_get_type (void);
183
184 G_END_DECLS
185
186 #endif /* __GST_QUEUE2_H__ */