Initialize Tizen 2.3
[framework/multimedia/gstreamer0.10.git] / wearable / 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 typedef struct _GstQueue2Range GstQueue2Range;
49
50 /* used to keep track of sizes (current and max) */
51 struct _GstQueue2Size
52 {
53   guint buffers;
54   guint bytes;
55   guint64 time;
56   guint64 rate_time;
57 };
58
59 struct _GstQueue2Range
60 {
61   GstQueue2Range *next;
62
63   guint64 offset;          /* offset of range start in source */
64   guint64 rb_offset;       /* offset of range start in ring buffer */
65 #ifdef GST_EXT_QUEUE_ENHANCEMENT
66   guint64 fb_offset;       /* offset of range start in file buffer */
67 #endif
68   guint64 writing_pos;     /* writing position in source */
69   guint64 rb_writing_pos;  /* writing position in ring buffer */
70 #ifdef GST_EXT_QUEUE_ENHANCEMENT
71   guint64 fb_writing_pos;       /*  writing position in file buffer */
72 #endif
73   guint64 reading_pos;     /* reading position in source */
74   guint64 max_reading_pos; /* latest requested offset in source */
75 };
76
77 struct _GstQueue2
78 {
79   GstElement element;
80
81   /*< private > */
82   GstPad *sinkpad;
83   GstPad *srcpad;
84
85   /* upstream size in bytes (if downstream is operating in pull mode) */
86   guint64 upstream_size;
87
88   /* segments to keep track of timestamps */
89   GstSegment sink_segment;
90   GstSegment src_segment;
91
92   /* Position of src/sink */
93   GstClockTime sinktime, srctime;
94   /* TRUE if either position needs to be recalculated */
95   gboolean sink_tainted, src_tainted;
96
97   /* flowreturn when srcpad is paused */
98   GstFlowReturn srcresult;
99   GstFlowReturn sinkresult;
100   gboolean is_eos;
101   gboolean unexpected;
102
103   /* the queue of data we're keeping our hands on */
104   GQueue queue;
105
106   GstQueue2Size cur_level;       /* currently in the queue */
107   GstQueue2Size max_level;       /* max. amount of data allowed in the queue */
108   gboolean use_buffering;
109   gboolean use_rate_estimate;
110   GstClockTime buffering_interval;
111 #ifdef GST_EXT_QUEUE_ENHANCEMENT
112   gdouble low_percent;             /* low/high watermarks for buffering */
113   gdouble high_percent;
114 #else
115   gint low_percent;             /* low/high watermarks for buffering */
116   gint high_percent;
117 #endif
118
119   /* current buffering state */
120   gboolean is_buffering;
121   gint buffering_percent;
122   guint buffering_iteration;
123
124   /* for measuring input/output rates */
125   GTimer *in_timer;
126   gboolean in_timer_started;
127   gdouble last_in_elapsed;
128   guint64 bytes_in;
129   gdouble byte_in_rate;
130   gdouble byte_in_period;
131
132   GTimer *out_timer;
133   gboolean out_timer_started;
134   gdouble last_out_elapsed;
135   guint64 bytes_out;
136   gdouble byte_out_rate;
137
138   GMutex *qlock;                /* lock for queue (vs object lock) */
139   gboolean waiting_add;
140   GCond *item_add;              /* signals buffers now available for reading */
141   gboolean waiting_del;
142   GCond *item_del;              /* signals space now available for writing */
143
144   /* temp location stuff */
145   gchar *temp_template;
146   gboolean temp_location_set;
147   gchar *temp_location;
148   gboolean temp_remove;
149 #ifdef GST_EXT_QUEUE_ENHANCEMENT
150   gboolean temp_unlink;
151 #endif
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
161   guint64 ring_buffer_max_size;
162   guint8 * ring_buffer;
163 #ifdef GST_EXT_QUEUE_ENHANCEMENT
164   guint64 file_buffer_max_size;
165 #endif
166 };
167
168 struct _GstQueue2Class
169 {
170   GstElementClass parent_class;
171 };
172
173 GType gst_queue2_get_type (void);
174
175 G_END_DECLS
176
177 #endif /* __GST_QUEUE2_H__ */