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 * SA 2010 ST-Ericsson <benjamin.gaignard@stericsson.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
27 * SECTION:element-queue2
30 * Data is queued until one of the limits specified by the
31 * #GstQueue2:max-size-buffers, #GstQueue2:max-size-bytes and/or
32 * #GstQueue2:max-size-time properties has been reached. Any attempt to push
33 * more buffers into the queue will block the pushing thread until more space
36 * The queue will create a new thread on the source pad to decouple the
37 * processing on sink and source pad.
39 * You can query how many buffers are queued by reading the
40 * #GstQueue2:current-level-buffers property.
42 * The default queue size limits are 100 buffers, 2MB of data, or
43 * two seconds worth of data, whichever is reached first.
45 * If you set temp-template to a value such as /tmp/gstreamer-XXXXXX, the element
46 * will allocate a random free filename and buffer data in the file.
47 * By using this, it will buffer the entire stream data on the file independently
48 * of the queue size limits, they will only be used for buffering statistics.
50 * The temp-location property will be used to notify the application of the
53 * If the #GstQueue2:use-buffering property is set to TRUE, and any writable
54 * property is modified, #GstQueue2 will attempt to post a buffering message
55 * if the changes to the properties also cause the buffering percentage to be
56 * changed (for example, because the queue's capacity was changed and it already
57 * contains some data).
64 #include "gstqueue2.h"
65 #include "gstcoreelementselements.h"
67 #include <glib/gstdio.h>
69 #include <glib/gi18n-lib.h>
70 #include "gst/glib-compat-private.h"
75 #include <io.h> /* lseek, open, close, read */
77 #define lseek _lseeki64
84 #ifdef __BIONIC__ /* Android */
88 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
93 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
98 GST_DEBUG_CATEGORY_STATIC (queue_debug);
99 #define GST_CAT_DEFAULT (queue_debug)
100 GST_DEBUG_CATEGORY_STATIC (queue_dataflow);
108 #define DEFAULT_BUFFER_SIZE 4096
109 #define QUEUE_IS_USING_TEMP_FILE(queue) ((queue)->temp_template != NULL)
110 #define QUEUE_IS_USING_RING_BUFFER(queue) ((queue)->ring_buffer_max_size != 0) /* for consistency with the above macro */
111 #define QUEUE_IS_USING_QUEUE(queue) (!QUEUE_IS_USING_TEMP_FILE(queue) && !QUEUE_IS_USING_RING_BUFFER (queue))
113 #define QUEUE_MAX_BYTES(queue) MIN((queue)->max_level.bytes, (queue)->ring_buffer_max_size)
115 /* default property values */
116 #define DEFAULT_MAX_SIZE_BUFFERS 100 /* 100 buffers */
117 #define DEFAULT_MAX_SIZE_BYTES (2 * 1024 * 1024) /* 2 MB */
118 #define DEFAULT_MAX_SIZE_TIME 2 * GST_SECOND /* 2 seconds */
119 #define DEFAULT_USE_BUFFERING FALSE
120 #define DEFAULT_USE_TAGS_BITRATE FALSE
121 #define DEFAULT_USE_RATE_ESTIMATE TRUE
122 #define DEFAULT_LOW_PERCENT 10
123 #define DEFAULT_HIGH_PERCENT 99
124 #define DEFAULT_LOW_WATERMARK 0.01
125 #define DEFAULT_HIGH_WATERMARK 0.99
126 #define DEFAULT_TEMP_REMOVE TRUE
127 #define DEFAULT_RING_BUFFER_MAX_SIZE 0
128 #define DEFAULT_USE_BITRATE_QUERY TRUE
133 PROP_CUR_LEVEL_BUFFERS,
134 PROP_CUR_LEVEL_BYTES,
136 PROP_MAX_SIZE_BUFFERS,
140 PROP_USE_TAGS_BITRATE,
141 PROP_USE_RATE_ESTIMATE,
149 PROP_RING_BUFFER_MAX_SIZE,
151 PROP_USE_BITRATE_QUERY,
153 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
158 static GParamSpec *obj_props[PROP_LAST] = { NULL, };
160 /* Explanation for buffer levels and percentages:
162 * The buffering_level functions here return a value in a normalized range
163 * that specifies the queue's current fill level. The range goes from 0 to
164 * MAX_BUFFERING_LEVEL. The low/high watermarks also use this same range.
166 * This is not to be confused with the buffering_percent value, which is
167 * a *relative* quantity - relative to the low/high watermarks.
168 * buffering_percent = 0% means buffering_level is at the low watermark.
169 * buffering_percent = 100% means buffering_level is at the high watermark.
170 * buffering_percent is used for determining if the fill level has reached
171 * the high watermark, and for producing BUFFERING messages. This value
172 * always uses a 0..100 range (since it is a percentage).
174 * To avoid future confusions, whenever "buffering level" is mentioned, it
175 * refers to the absolute level which is in the 0..MAX_BUFFERING_LEVEL
176 * range. Whenever "buffering_percent" is mentioned, it refers to the
177 * percentage value that is relative to the low/high watermark. */
179 /* Using a buffering level range of 0..1000000 to allow for a
180 * resolution in ppm (1 ppm = 0.0001%) */
181 #define MAX_BUFFERING_LEVEL 1000000
183 /* How much 1% makes up in the buffer level range */
184 #define BUF_LEVEL_PERCENT_FACTOR ((MAX_BUFFERING_LEVEL) / 100)
186 #define GST_QUEUE2_CLEAR_LEVEL(l) G_STMT_START { \
193 #define STATUS(queue, pad, msg) \
194 GST_CAT_LOG_OBJECT (queue_dataflow, queue, \
195 "(%s:%s) " msg ": %u of %u buffers, %u of %u " \
196 "bytes, %" G_GUINT64_FORMAT " of %" G_GUINT64_FORMAT \
197 " ns, %"G_GUINT64_FORMAT" items", \
198 GST_DEBUG_PAD_NAME (pad), \
199 queue->cur_level.buffers, \
200 queue->max_level.buffers, \
201 queue->cur_level.bytes, \
202 queue->max_level.bytes, \
203 queue->cur_level.time, \
204 queue->max_level.time, \
205 (guint64) (!QUEUE_IS_USING_QUEUE(queue) ? \
206 queue->current->writing_pos - queue->current->max_reading_pos : \
207 gst_queue_array_get_length(queue->queue)))
209 #define GST_QUEUE2_MUTEX_LOCK(q) G_STMT_START { \
210 g_mutex_lock (&q->qlock); \
213 #define GST_QUEUE2_MUTEX_LOCK_CHECK(q,res,label) G_STMT_START { \
214 GST_QUEUE2_MUTEX_LOCK (q); \
215 if (res != GST_FLOW_OK) \
219 #define GST_QUEUE2_MUTEX_UNLOCK(q) G_STMT_START { \
220 g_mutex_unlock (&q->qlock); \
223 #define GST_QUEUE2_WAIT_DEL_CHECK(q, res, label) G_STMT_START { \
224 if (res != GST_FLOW_OK) { \
227 STATUS (queue, q->sinkpad, "wait for DEL"); \
228 q->waiting_del = TRUE; \
229 g_cond_wait (&q->item_del, &queue->qlock); \
230 q->waiting_del = FALSE; \
231 if (res != GST_FLOW_OK) { \
232 STATUS (queue, q->srcpad, "received DEL wakeup"); \
235 STATUS (queue, q->sinkpad, "received DEL"); \
238 #define GST_QUEUE2_WAIT_ADD_CHECK(q, res, label) G_STMT_START { \
239 if (res != GST_FLOW_OK) { \
242 STATUS (queue, q->srcpad, "wait for ADD"); \
243 q->waiting_add = TRUE; \
244 g_cond_wait (&q->item_add, &q->qlock); \
245 q->waiting_add = FALSE; \
246 if (res != GST_FLOW_OK) { \
247 STATUS (queue, q->srcpad, "received ADD wakeup"); \
250 STATUS (queue, q->srcpad, "received ADD"); \
253 #define GST_QUEUE2_SIGNAL_DEL(q) G_STMT_START { \
254 if (q->waiting_del) { \
255 STATUS (q, q->srcpad, "signal DEL"); \
256 g_cond_signal (&q->item_del); \
260 #define GST_QUEUE2_SIGNAL_ADD(q) G_STMT_START { \
261 if (q->waiting_add) { \
262 STATUS (q, q->sinkpad, "signal ADD"); \
263 g_cond_signal (&q->item_add); \
267 #define SET_PERCENT(q, perc) G_STMT_START { \
268 if (perc != q->buffering_percent) { \
269 q->buffering_percent = perc; \
270 q->percent_changed = TRUE; \
271 GST_DEBUG_OBJECT (q, "buffering %d percent", perc); \
272 get_buffering_stats (q, perc, &q->mode, &q->avg_in, &q->avg_out, \
273 &q->buffering_left); \
278 GST_DEBUG_CATEGORY_INIT (queue_debug, "queue2", 0, "queue element"); \
279 GST_DEBUG_CATEGORY_INIT (queue_dataflow, "queue2_dataflow", 0, \
280 "dataflow inside the queue element");
281 #define gst_queue2_parent_class parent_class
282 G_DEFINE_TYPE_WITH_CODE (GstQueue2, gst_queue2, GST_TYPE_ELEMENT, _do_init);
283 GST_ELEMENT_REGISTER_DEFINE (queue2, "queue2", GST_RANK_NONE, GST_TYPE_QUEUE2);
285 static void gst_queue2_finalize (GObject * object);
287 static void gst_queue2_set_property (GObject * object,
288 guint prop_id, const GValue * value, GParamSpec * pspec);
289 static void gst_queue2_get_property (GObject * object,
290 guint prop_id, GValue * value, GParamSpec * pspec);
292 static GstFlowReturn gst_queue2_chain (GstPad * pad, GstObject * parent,
294 static GstFlowReturn gst_queue2_chain_list (GstPad * pad, GstObject * parent,
295 GstBufferList * buffer_list);
296 static GstFlowReturn gst_queue2_push_one (GstQueue2 * queue);
297 static void gst_queue2_loop (GstPad * pad);
299 static GstFlowReturn gst_queue2_handle_sink_event (GstPad * pad,
300 GstObject * parent, GstEvent * event);
301 static gboolean gst_queue2_handle_sink_query (GstPad * pad, GstObject * parent,
304 static gboolean gst_queue2_handle_src_event (GstPad * pad, GstObject * parent,
306 static gboolean gst_queue2_handle_src_query (GstPad * pad, GstObject * parent,
308 static gboolean gst_queue2_handle_query (GstElement * element,
311 static GstFlowReturn gst_queue2_get_range (GstPad * pad, GstObject * parent,
312 guint64 offset, guint length, GstBuffer ** buffer);
314 static gboolean gst_queue2_src_activate_mode (GstPad * pad, GstObject * parent,
315 GstPadMode mode, gboolean active);
316 static gboolean gst_queue2_sink_activate_mode (GstPad * pad, GstObject * parent,
317 GstPadMode mode, gboolean active);
318 static GstStateChangeReturn gst_queue2_change_state (GstElement * element,
319 GstStateChange transition);
321 static gboolean gst_queue2_is_empty (GstQueue2 * queue);
322 static gboolean gst_queue2_is_filled (GstQueue2 * queue);
324 static void update_cur_level (GstQueue2 * queue, GstQueue2Range * range);
325 static void update_in_rates (GstQueue2 * queue, gboolean force);
326 static GstMessage *gst_queue2_get_buffering_message (GstQueue2 * queue,
328 static void update_buffering (GstQueue2 * queue);
329 static void gst_queue2_post_buffering (GstQueue2 * queue);
333 GST_QUEUE2_ITEM_TYPE_UNKNOWN = 0,
334 GST_QUEUE2_ITEM_TYPE_BUFFER,
335 GST_QUEUE2_ITEM_TYPE_BUFFER_LIST,
336 GST_QUEUE2_ITEM_TYPE_EVENT,
337 GST_QUEUE2_ITEM_TYPE_QUERY
342 GstQueue2ItemType type;
346 /* static guint gst_queue2_signals[LAST_SIGNAL] = { 0 }; */
349 gst_queue2_class_init (GstQueue2Class * klass)
351 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
352 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
354 gobject_class->set_property = gst_queue2_set_property;
355 gobject_class->get_property = gst_queue2_get_property;
358 obj_props[PROP_CUR_LEVEL_BYTES] = g_param_spec_uint ("current-level-bytes",
359 "Current level (kB)", "Current amount of data in the queue (bytes)",
360 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
361 obj_props[PROP_CUR_LEVEL_BUFFERS] =
362 g_param_spec_uint ("current-level-buffers", "Current level (buffers)",
363 "Current number of buffers in the queue",
364 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
365 obj_props[PROP_CUR_LEVEL_TIME] = g_param_spec_uint64 ("current-level-time",
366 "Current level (ns)", "Current amount of data in the queue (in ns)",
367 0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
369 obj_props[PROP_MAX_SIZE_BYTES] = g_param_spec_uint ("max-size-bytes",
370 "Max. size (kB)", "Max. amount of data in the queue (bytes, 0=disable)",
371 0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
372 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
373 obj_props[PROP_MAX_SIZE_BUFFERS] = g_param_spec_uint ("max-size-buffers",
374 "Max. size (buffers)", "Max. number of buffers in the queue (0=disable)",
375 0, G_MAXUINT, DEFAULT_MAX_SIZE_BUFFERS,
376 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
377 obj_props[PROP_MAX_SIZE_TIME] = g_param_spec_uint64 ("max-size-time",
378 "Max. size (ns)", "Max. amount of data in the queue (in ns, 0=disable)",
379 0, G_MAXUINT64, DEFAULT_MAX_SIZE_TIME,
380 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
382 obj_props[PROP_USE_BUFFERING] = g_param_spec_boolean ("use-buffering",
384 "Emit GST_MESSAGE_BUFFERING based on low-/high-percent thresholds "
385 "(0% = low-watermark, 100% = high-watermark)",
386 DEFAULT_USE_BUFFERING,
387 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
388 obj_props[PROP_USE_TAGS_BITRATE] = g_param_spec_boolean ("use-tags-bitrate",
389 "Use bitrate from tags",
390 "Use a bitrate from upstream tags to estimate buffer duration if not provided",
391 DEFAULT_USE_TAGS_BITRATE,
392 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
393 obj_props[PROP_USE_RATE_ESTIMATE] = g_param_spec_boolean ("use-rate-estimate",
395 "Estimate the bitrate of the stream to calculate time level",
396 DEFAULT_USE_RATE_ESTIMATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
397 obj_props[PROP_LOW_PERCENT] = g_param_spec_int ("low-percent", "Low percent",
398 "Low threshold for buffering to start. Only used if use-buffering is True "
399 "(Deprecated: use low-watermark instead)",
400 0, 100, DEFAULT_LOW_WATERMARK * 100,
401 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
402 obj_props[PROP_HIGH_PERCENT] = g_param_spec_int ("high-percent",
404 "High threshold for buffering to finish. Only used if use-buffering is True "
405 "(Deprecated: use high-watermark instead)",
406 0, 100, DEFAULT_HIGH_WATERMARK * 100,
407 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
408 obj_props[PROP_LOW_WATERMARK] = g_param_spec_double ("low-watermark",
410 "Low threshold for buffering to start. Only used if use-buffering is True",
411 0.0, 1.0, DEFAULT_LOW_WATERMARK,
412 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
413 obj_props[PROP_HIGH_WATERMARK] = g_param_spec_double ("high-watermark",
415 "High threshold for buffering to finish. Only used if use-buffering is True",
416 0.0, 1.0, DEFAULT_HIGH_WATERMARK,
417 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
419 obj_props[PROP_TEMP_TEMPLATE] = g_param_spec_string ("temp-template",
420 "Temporary File Template",
421 "File template to store temporary files in, should contain directory "
422 "and XXXXXX. (NULL == disabled)",
423 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
425 obj_props[PROP_TEMP_LOCATION] = g_param_spec_string ("temp-location",
426 "Temporary File Location",
427 "Location to store temporary files in (Only read this property, "
428 "use temp-template to configure the name template)",
429 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
431 obj_props[PROP_USE_BITRATE_QUERY] = g_param_spec_boolean ("use-bitrate-query",
432 "Use bitrate from downstream query",
433 "Use a bitrate from a downstream query to estimate buffer duration if not provided",
434 DEFAULT_USE_BITRATE_QUERY,
435 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
438 * GstQueue2:temp-remove
440 * When temp-template is set, remove the temporary file when going to READY.
442 obj_props[PROP_TEMP_REMOVE] = g_param_spec_boolean ("temp-remove",
443 "Remove the Temporary File", "Remove the temp-location after use",
444 DEFAULT_TEMP_REMOVE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
447 * GstQueue2:ring-buffer-max-size
449 * The maximum size of the ring buffer in bytes. If set to 0, the ring
450 * buffer is disabled. Default 0.
452 obj_props[PROP_RING_BUFFER_MAX_SIZE] =
453 g_param_spec_uint64 ("ring-buffer-max-size",
454 "Max. ring buffer size (bytes)",
455 "Max. amount of data in the ring buffer (bytes, 0 = disabled)",
456 0, G_MAXUINT64, DEFAULT_RING_BUFFER_MAX_SIZE,
457 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
460 * GstQueue2:avg-in-rate
462 * The average input data rate.
464 obj_props[PROP_AVG_IN_RATE] = g_param_spec_int64 ("avg-in-rate",
465 "Input data rate (bytes/s)", "Average input data rate (bytes/s)",
466 0, G_MAXINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
471 * The value used to convert between byte and time values for limiting
472 * the size of the queue. Values are taken from either the upstream tags
473 * or from the downstream bitrate query.
475 obj_props[PROP_BITRATE] = g_param_spec_uint64 ("bitrate", "Bitrate (bits/s)",
476 "Conversion value between data size and time",
477 0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
479 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
481 * GstQueue2:buffer-mode:
483 * Control the buffering mode used by the queue2.
485 obj_props[PROP_BUFFER_MODE] = g_param_spec_enum ("buffer-mode", "Buffer Mode",
486 "Control the buffering algorithm in use",
487 GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
488 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
491 g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
493 /* set several parent class virtual functions */
494 gobject_class->finalize = gst_queue2_finalize;
496 gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
497 gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
499 gst_element_class_set_static_metadata (gstelement_class, "Queue 2",
502 "Erik Walthinsen <omega@cse.ogi.edu>, "
503 "Wim Taymans <wim.taymans@gmail.com>");
505 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_queue2_change_state);
506 gstelement_class->query = GST_DEBUG_FUNCPTR (gst_queue2_handle_query);
510 gst_queue2_init (GstQueue2 * queue)
512 queue->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
514 gst_pad_set_chain_function (queue->sinkpad,
515 GST_DEBUG_FUNCPTR (gst_queue2_chain));
516 gst_pad_set_chain_list_function (queue->sinkpad,
517 GST_DEBUG_FUNCPTR (gst_queue2_chain_list));
518 gst_pad_set_activatemode_function (queue->sinkpad,
519 GST_DEBUG_FUNCPTR (gst_queue2_sink_activate_mode));
520 gst_pad_set_event_full_function (queue->sinkpad,
521 GST_DEBUG_FUNCPTR (gst_queue2_handle_sink_event));
522 gst_pad_set_query_function (queue->sinkpad,
523 GST_DEBUG_FUNCPTR (gst_queue2_handle_sink_query));
524 GST_PAD_SET_PROXY_CAPS (queue->sinkpad);
525 gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
527 queue->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
529 gst_pad_set_activatemode_function (queue->srcpad,
530 GST_DEBUG_FUNCPTR (gst_queue2_src_activate_mode));
531 gst_pad_set_getrange_function (queue->srcpad,
532 GST_DEBUG_FUNCPTR (gst_queue2_get_range));
533 gst_pad_set_event_function (queue->srcpad,
534 GST_DEBUG_FUNCPTR (gst_queue2_handle_src_event));
535 gst_pad_set_query_function (queue->srcpad,
536 GST_DEBUG_FUNCPTR (gst_queue2_handle_src_query));
537 GST_PAD_SET_PROXY_CAPS (queue->srcpad);
538 gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
541 GST_QUEUE2_CLEAR_LEVEL (queue->cur_level);
542 queue->max_level.buffers = DEFAULT_MAX_SIZE_BUFFERS;
543 queue->max_level.bytes = DEFAULT_MAX_SIZE_BYTES;
544 queue->max_level.time = DEFAULT_MAX_SIZE_TIME;
545 queue->max_level.rate_time = DEFAULT_MAX_SIZE_TIME;
546 queue->use_buffering = DEFAULT_USE_BUFFERING;
547 queue->use_rate_estimate = DEFAULT_USE_RATE_ESTIMATE;
548 queue->low_watermark = DEFAULT_LOW_WATERMARK * MAX_BUFFERING_LEVEL;
549 queue->high_watermark = DEFAULT_HIGH_WATERMARK * MAX_BUFFERING_LEVEL;
551 gst_segment_init (&queue->sink_segment, GST_FORMAT_TIME);
552 gst_segment_init (&queue->src_segment, GST_FORMAT_TIME);
554 queue->sinktime = GST_CLOCK_TIME_NONE;
555 queue->srctime = GST_CLOCK_TIME_NONE;
556 queue->sink_tainted = TRUE;
557 queue->src_tainted = TRUE;
559 queue->srcresult = GST_FLOW_FLUSHING;
560 queue->sinkresult = GST_FLOW_FLUSHING;
561 queue->is_eos = FALSE;
562 queue->in_timer = g_timer_new ();
563 queue->out_timer = g_timer_new ();
565 g_mutex_init (&queue->qlock);
566 queue->waiting_add = FALSE;
567 g_cond_init (&queue->item_add);
568 queue->waiting_del = FALSE;
569 g_cond_init (&queue->item_del);
570 queue->queue = gst_queue_array_new_for_struct (sizeof (GstQueue2Item), 32);
572 g_cond_init (&queue->query_handled);
573 queue->last_query = FALSE;
575 g_mutex_init (&queue->buffering_post_lock);
576 queue->buffering_percent = 100;
577 queue->last_posted_buffering_percent = -1;
579 /* tempfile related */
580 queue->temp_template = NULL;
581 queue->temp_location = NULL;
582 queue->temp_remove = DEFAULT_TEMP_REMOVE;
584 queue->ring_buffer = NULL;
585 queue->ring_buffer_max_size = DEFAULT_RING_BUFFER_MAX_SIZE;
587 queue->use_bitrate_query = DEFAULT_USE_BITRATE_QUERY;
589 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
592 GST_DEBUG_OBJECT (queue,
593 "initialized queue's not_empty & not_full conditions");
596 /* called only once, as opposed to dispose */
598 gst_queue2_finalize (GObject * object)
600 GstQueue2 *queue = GST_QUEUE2 (object);
601 GstQueue2Item *qitem;
603 GST_DEBUG_OBJECT (queue, "finalizing queue");
605 while ((qitem = gst_queue_array_pop_head_struct (queue->queue))) {
606 if (qitem->type != GST_QUEUE2_ITEM_TYPE_QUERY)
607 gst_mini_object_unref (qitem->item);
609 gst_queue_array_free (queue->queue);
611 queue->last_query = FALSE;
612 g_mutex_clear (&queue->qlock);
613 g_mutex_clear (&queue->buffering_post_lock);
614 g_cond_clear (&queue->item_add);
615 g_cond_clear (&queue->item_del);
616 g_cond_clear (&queue->query_handled);
617 g_timer_destroy (queue->in_timer);
618 g_timer_destroy (queue->out_timer);
620 /* temp_file path cleanup */
621 g_free (queue->temp_template);
622 g_free (queue->temp_location);
624 G_OBJECT_CLASS (parent_class)->finalize (object);
628 debug_ranges (GstQueue2 * queue)
630 GstQueue2Range *walk;
632 for (walk = queue->ranges; walk; walk = walk->next) {
633 GST_DEBUG_OBJECT (queue,
634 "range [%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT "] (rb [%"
635 G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT "]), reading %" G_GUINT64_FORMAT
636 " current range? %s", walk->offset, walk->writing_pos, walk->rb_offset,
637 walk->rb_writing_pos, walk->reading_pos,
638 walk == queue->current ? "**y**" : " n ");
642 /* clear all the downloaded ranges */
644 clean_ranges (GstQueue2 * queue)
646 GST_DEBUG_OBJECT (queue, "clean queue ranges");
648 g_slice_free_chain (GstQueue2Range, queue->ranges, next);
649 queue->ranges = NULL;
650 queue->current = NULL;
653 /* find a range that contains @offset or NULL when nothing does */
654 static GstQueue2Range *
655 find_range (GstQueue2 * queue, guint64 offset)
657 GstQueue2Range *range = NULL;
658 GstQueue2Range *walk;
660 /* first do a quick check for the current range */
661 for (walk = queue->ranges; walk; walk = walk->next) {
662 if (offset >= walk->offset && offset <= walk->writing_pos) {
663 /* we can reuse an existing range */
669 GST_DEBUG_OBJECT (queue,
670 "found range for %" G_GUINT64_FORMAT ": [%" G_GUINT64_FORMAT "-%"
671 G_GUINT64_FORMAT "]", offset, range->offset, range->writing_pos);
673 GST_DEBUG_OBJECT (queue, "no range for %" G_GUINT64_FORMAT, offset);
679 update_cur_level (GstQueue2 * queue, GstQueue2Range * range)
681 guint64 max_reading_pos, writing_pos;
683 writing_pos = range->writing_pos;
684 max_reading_pos = range->max_reading_pos;
686 if (writing_pos > max_reading_pos)
687 queue->cur_level.bytes = writing_pos - max_reading_pos;
689 queue->cur_level.bytes = 0;
692 /* make a new range for @offset or reuse an existing range */
693 static GstQueue2Range *
694 add_range (GstQueue2 * queue, guint64 offset, gboolean update_existing)
696 GstQueue2Range *range, *prev, *next;
698 GST_DEBUG_OBJECT (queue, "find range for %" G_GUINT64_FORMAT, offset);
700 if ((range = find_range (queue, offset))) {
701 GST_DEBUG_OBJECT (queue,
702 "reusing range %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT, range->offset,
704 if (update_existing && range->writing_pos != offset) {
705 GST_DEBUG_OBJECT (queue, "updating range writing position to "
706 "%" G_GUINT64_FORMAT, offset);
707 range->writing_pos = offset;
710 GST_DEBUG_OBJECT (queue,
711 "new range %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT, offset, offset);
713 range = g_slice_new0 (GstQueue2Range);
714 range->offset = offset;
715 /* we want to write to the next location in the ring buffer */
716 range->rb_offset = queue->current ? queue->current->rb_writing_pos : 0;
717 range->writing_pos = offset;
718 range->rb_writing_pos = range->rb_offset;
719 range->reading_pos = offset;
720 range->max_reading_pos = offset;
724 next = queue->ranges;
726 if (next->offset > offset) {
727 /* insert before next */
728 GST_DEBUG_OBJECT (queue,
729 "insert before range %p, offset %" G_GUINT64_FORMAT, next,
741 queue->ranges = range;
743 debug_ranges (queue);
745 /* update the stats for this range */
746 update_cur_level (queue, range);
752 /* clear and init the download ranges for offset 0 */
754 init_ranges (GstQueue2 * queue)
756 GST_DEBUG_OBJECT (queue, "init queue ranges");
758 /* get rid of all the current ranges */
759 clean_ranges (queue);
760 /* make a range for offset 0 */
761 queue->current = add_range (queue, 0, TRUE);
764 /* calculate the diff between running time on the sink and src of the queue.
765 * This is the total amount of time in the queue. */
767 update_time_level (GstQueue2 * queue)
769 if (queue->sink_tainted) {
771 gst_segment_to_running_time (&queue->sink_segment, GST_FORMAT_TIME,
772 queue->sink_segment.position);
773 queue->sink_tainted = FALSE;
776 if (queue->src_tainted) {
778 gst_segment_to_running_time (&queue->src_segment, GST_FORMAT_TIME,
779 queue->src_segment.position);
780 queue->src_tainted = FALSE;
783 GST_DEBUG_OBJECT (queue, "sink %" GST_TIME_FORMAT ", src %" GST_TIME_FORMAT,
784 GST_TIME_ARGS (queue->sinktime), GST_TIME_ARGS (queue->srctime));
786 if (queue->sinktime != GST_CLOCK_TIME_NONE
787 && queue->srctime != GST_CLOCK_TIME_NONE
788 && queue->sinktime >= queue->srctime)
789 queue->cur_level.time = queue->sinktime - queue->srctime;
791 queue->cur_level.time = 0;
794 /* take a SEGMENT event and apply the values to segment, updating the time
797 apply_segment (GstQueue2 * queue, GstEvent * event, GstSegment * segment,
800 gst_event_copy_segment (event, segment);
802 if (segment->format == GST_FORMAT_BYTES) {
803 if (!QUEUE_IS_USING_QUEUE (queue) && is_sink) {
804 /* start is where we'll be getting from and as such writing next */
805 queue->current = add_range (queue, segment->start, TRUE);
809 /* now configure the values, we use these to track timestamps on the
811 if (segment->format != GST_FORMAT_TIME) {
812 /* non-time format, pretend the current time segment is closed with a
813 * 0 start and unknown stop time. */
814 segment->format = GST_FORMAT_TIME;
820 GST_DEBUG_OBJECT (queue, "configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
823 queue->sink_tainted = TRUE;
825 queue->src_tainted = TRUE;
827 /* segment can update the time level of the queue */
828 update_time_level (queue);
832 apply_gap (GstQueue2 * queue, GstEvent * event,
833 GstSegment * segment, gboolean is_sink)
835 GstClockTime timestamp;
836 GstClockTime duration;
838 gst_event_parse_gap (event, ×tamp, &duration);
840 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
842 if (GST_CLOCK_TIME_IS_VALID (duration)) {
843 timestamp += duration;
846 segment->position = timestamp;
849 queue->sink_tainted = TRUE;
851 queue->src_tainted = TRUE;
853 /* calc diff with other end */
854 update_time_level (queue);
859 query_downstream_bitrate (GstQueue2 * queue)
861 GstQuery *query = gst_query_new_bitrate ();
862 guint downstream_bitrate = 0;
865 if (gst_pad_peer_query (queue->srcpad, query)) {
866 gst_query_parse_bitrate (query, &downstream_bitrate);
867 GST_DEBUG_OBJECT (queue, "Got bitrate of %u from downstream",
870 GST_DEBUG_OBJECT (queue, "Failed to query bitrate from downstream");
873 gst_query_unref (query);
875 GST_QUEUE2_MUTEX_LOCK (queue);
876 changed = queue->downstream_bitrate != downstream_bitrate;
877 queue->downstream_bitrate = downstream_bitrate;
878 GST_QUEUE2_MUTEX_UNLOCK (queue);
881 if (queue->use_buffering)
882 update_buffering (queue);
883 gst_queue2_post_buffering (queue);
885 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_BITRATE]);
889 /* take a buffer and update segment, updating the time level of the queue. */
891 apply_buffer (GstQueue2 * queue, GstBuffer * buffer, GstSegment * segment,
892 guint64 size, gboolean is_sink)
894 GstClockTime duration, timestamp;
896 timestamp = GST_BUFFER_DTS_OR_PTS (buffer);
897 duration = GST_BUFFER_DURATION (buffer);
899 /* If we have no duration, pick one from the bitrate if we can */
900 if (duration == GST_CLOCK_TIME_NONE) {
901 if (queue->use_tags_bitrate) {
903 is_sink ? queue->sink_tags_bitrate : queue->src_tags_bitrate;
905 duration = gst_util_uint64_scale (size, 8 * GST_SECOND, bitrate);
907 if (duration == GST_CLOCK_TIME_NONE && !is_sink && queue->use_bitrate_query) {
908 if (queue->downstream_bitrate > 0) {
910 gst_util_uint64_scale (size, 8 * GST_SECOND,
911 queue->downstream_bitrate);
913 GST_LOG_OBJECT (queue, "got bitrate %u resulting in estimated "
914 "duration %" GST_TIME_FORMAT, queue->downstream_bitrate,
915 GST_TIME_ARGS (duration));
920 /* if no timestamp is set, assume it's continuous with the previous
922 if (timestamp == GST_CLOCK_TIME_NONE)
923 timestamp = segment->position;
926 if (duration != GST_CLOCK_TIME_NONE)
927 timestamp += duration;
929 GST_DEBUG_OBJECT (queue, "position updated to %" GST_TIME_FORMAT,
930 GST_TIME_ARGS (timestamp));
932 segment->position = timestamp;
935 queue->sink_tainted = TRUE;
937 queue->src_tainted = TRUE;
939 /* calc diff with other end */
940 update_time_level (queue);
945 GstClockTime timestamp;
950 buffer_list_apply_time (GstBuffer ** buf, guint idx, gpointer data)
952 struct BufListData *bld = data;
953 GstClockTime *timestamp = &bld->timestamp;
956 GST_TRACE ("buffer %u has pts %" GST_TIME_FORMAT " dts %" GST_TIME_FORMAT
957 " duration %" GST_TIME_FORMAT, idx,
958 GST_TIME_ARGS (GST_BUFFER_PTS (*buf)),
959 GST_TIME_ARGS (GST_BUFFER_DTS (*buf)),
960 GST_TIME_ARGS (GST_BUFFER_DURATION (*buf)));
962 btime = GST_BUFFER_DTS_OR_PTS (*buf);
963 if (GST_CLOCK_TIME_IS_VALID (btime))
966 if (GST_BUFFER_DURATION_IS_VALID (*buf))
967 *timestamp += GST_BUFFER_DURATION (*buf);
968 else if (bld->bitrate != 0) {
969 guint64 size = gst_buffer_get_size (*buf);
971 /* If we have no duration, pick one from the bitrate if we can */
972 *timestamp += gst_util_uint64_scale (bld->bitrate, 8 * GST_SECOND, size);
976 GST_TRACE ("ts now %" GST_TIME_FORMAT, GST_TIME_ARGS (*timestamp));
980 /* take a buffer list and update segment, updating the time level of the queue */
982 apply_buffer_list (GstQueue2 * queue, GstBufferList * buffer_list,
983 GstSegment * segment, gboolean is_sink)
985 struct BufListData bld;
987 /* if no timestamp is set, assume it's continuous with the previous time */
988 bld.timestamp = segment->position;
991 if (queue->use_tags_bitrate) {
993 bld.bitrate = queue->sink_tags_bitrate;
995 bld.bitrate = queue->src_tags_bitrate;
997 if (!is_sink && bld.bitrate == 0 && queue->use_bitrate_query) {
998 bld.bitrate = queue->downstream_bitrate;
1001 gst_buffer_list_foreach (buffer_list, buffer_list_apply_time, &bld);
1003 GST_DEBUG_OBJECT (queue, "last_stop updated to %" GST_TIME_FORMAT,
1004 GST_TIME_ARGS (bld.timestamp));
1006 segment->position = bld.timestamp;
1009 queue->sink_tainted = TRUE;
1011 queue->src_tainted = TRUE;
1013 /* calc diff with other end */
1014 update_time_level (queue);
1018 normalize_to_buffering_level (guint64 cur_level, guint64 max_level,
1027 p = gst_util_uint64_scale (cur_level, MAX_BUFFERING_LEVEL,
1028 MIN (max_level, alt_max));
1030 p = gst_util_uint64_scale (cur_level, MAX_BUFFERING_LEVEL, max_level);
1032 return MIN (p, MAX_BUFFERING_LEVEL);
1036 get_buffering_level (GstQueue2 * queue, gboolean * is_buffering,
1037 gint * buffering_level)
1039 gint buflevel, buflevel2;
1041 if (queue->high_watermark <= 0) {
1042 if (buffering_level)
1043 *buffering_level = MAX_BUFFERING_LEVEL;
1045 *is_buffering = FALSE;
1048 #define GET_BUFFER_LEVEL_FOR_QUANTITY(format,alt_max) \
1049 normalize_to_buffering_level (queue->cur_level.format,queue->max_level.format,(alt_max))
1051 if (queue->is_eos || queue->srcresult == GST_FLOW_NOT_LINKED) {
1052 /* on EOS and NOT_LINKED we are always 100% full, we set the var
1053 * here so that we can reuse the logic below to stop buffering */
1054 buflevel = MAX_BUFFERING_LEVEL;
1055 GST_LOG_OBJECT (queue, "we are %s", queue->is_eos ? "EOS" : "NOT_LINKED");
1057 GST_LOG_OBJECT (queue,
1058 "Cur level bytes/time/rate-time/buffers %u/%" GST_TIME_FORMAT "/%"
1059 GST_TIME_FORMAT "/%u", queue->cur_level.bytes,
1060 GST_TIME_ARGS (queue->cur_level.time),
1061 GST_TIME_ARGS (queue->cur_level.rate_time), queue->cur_level.buffers);
1063 /* figure out the buffering level we are filled, we take the max of all formats. */
1064 if (!QUEUE_IS_USING_RING_BUFFER (queue)) {
1065 buflevel = GET_BUFFER_LEVEL_FOR_QUANTITY (bytes, 0);
1067 guint64 rb_size = queue->ring_buffer_max_size;
1068 buflevel = GET_BUFFER_LEVEL_FOR_QUANTITY (bytes, rb_size);
1071 buflevel2 = GET_BUFFER_LEVEL_FOR_QUANTITY (time, 0);
1072 buflevel = MAX (buflevel, buflevel2);
1074 buflevel2 = GET_BUFFER_LEVEL_FOR_QUANTITY (buffers, 0);
1075 buflevel = MAX (buflevel, buflevel2);
1077 /* also apply the rate estimate when we need to */
1078 if (queue->use_rate_estimate) {
1079 buflevel2 = GET_BUFFER_LEVEL_FOR_QUANTITY (rate_time, 0);
1080 buflevel = MAX (buflevel, buflevel2);
1083 /* Don't get to 0% unless we're really empty */
1084 if (queue->cur_level.bytes > 0)
1085 buflevel = MAX (1, buflevel);
1087 #undef GET_BUFFER_LEVEL_FOR_QUANTITY
1090 *is_buffering = queue->is_buffering;
1092 if (buffering_level)
1093 *buffering_level = buflevel;
1095 GST_DEBUG_OBJECT (queue, "buffering %d, level %d", queue->is_buffering,
1102 convert_to_buffering_percent (GstQueue2 * queue, gint buffering_level)
1106 /* scale so that if buffering_level equals the high watermark,
1107 * the percentage is 100% */
1108 percent = buffering_level * 100 / queue->high_watermark;
1117 get_buffering_stats (GstQueue2 * queue, gint percent, GstBufferingMode * mode,
1118 gint * avg_in, gint * avg_out, gint64 * buffering_left)
1120 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
1121 if (queue->mode != -1) {
1122 *mode = queue->mode;
1125 if (!QUEUE_IS_USING_QUEUE (queue)) {
1126 if (QUEUE_IS_USING_RING_BUFFER (queue))
1127 *mode = GST_BUFFERING_TIMESHIFT;
1129 *mode = GST_BUFFERING_DOWNLOAD;
1131 *mode = GST_BUFFERING_STREAM;
1137 if (!QUEUE_IS_USING_QUEUE (queue)) {
1138 if (QUEUE_IS_USING_RING_BUFFER (queue))
1139 *mode = GST_BUFFERING_TIMESHIFT;
1141 *mode = GST_BUFFERING_DOWNLOAD;
1143 *mode = GST_BUFFERING_STREAM;
1149 *avg_in = queue->byte_in_rate;
1151 *avg_out = queue->byte_out_rate;
1153 if (buffering_left) {
1154 *buffering_left = (percent == 100 ? 0 : -1);
1156 if (queue->use_rate_estimate) {
1159 max = queue->max_level.rate_time;
1160 cur = queue->cur_level.rate_time;
1162 if (percent != 100 && max > cur)
1163 *buffering_left = (max - cur) / 1000000;
1168 /* Called with the lock taken */
1170 gst_queue2_get_buffering_message (GstQueue2 * queue, gint * percent)
1172 GstMessage *msg = NULL;
1173 if (queue->percent_changed) {
1174 /* Don't change the buffering level if the sinkpad is waiting for
1175 * space to become available. This prevents the situation where,
1176 * upstream is pushing buffers larger than our limits so only 1 buffer
1177 * is ever in the queue at a time.
1178 * Changing the level causes a buffering message to be posted saying that
1179 * we are buffering which the application may pause to wait for another
1180 * 100% buffering message which would be posted very soon after the
1181 * waiting sink thread adds it's buffer to the queue */
1182 /* FIXME: This situation above can still occur later if
1183 * the sink pad is waiting to push a serialized event into the queue and
1184 * the queue becomes empty for a short period of time. */
1185 if (!queue->waiting_del
1186 && queue->last_posted_buffering_percent != queue->buffering_percent) {
1187 *percent = queue->buffering_percent;
1189 GST_DEBUG_OBJECT (queue, "Going to post buffering: %d%%", *percent);
1190 msg = gst_message_new_buffering (GST_OBJECT_CAST (queue), *percent);
1192 gst_message_set_buffering_stats (msg, queue->mode, queue->avg_in,
1193 queue->avg_out, queue->buffering_left);
1201 gst_queue2_post_buffering (GstQueue2 * queue)
1203 GstMessage *msg = NULL;
1206 g_mutex_lock (&queue->buffering_post_lock);
1207 GST_QUEUE2_MUTEX_LOCK (queue);
1208 msg = gst_queue2_get_buffering_message (queue, &percent);
1209 GST_QUEUE2_MUTEX_UNLOCK (queue);
1212 if (gst_element_post_message (GST_ELEMENT_CAST (queue), msg)) {
1213 GST_QUEUE2_MUTEX_LOCK (queue);
1214 /* Set these states only if posting the message succeeded. Otherwise,
1215 * this post attempt failed, and the next one won't be done, because
1216 * gst_queue2_get_buffering_message() checks these states and decides
1217 * based on their values that it won't produce a message. */
1218 queue->last_posted_buffering_percent = percent;
1219 if (percent == queue->buffering_percent)
1220 queue->percent_changed = FALSE;
1221 GST_QUEUE2_MUTEX_UNLOCK (queue);
1222 GST_DEBUG_OBJECT (queue, "successfully posted %d%% buffering message",
1225 GST_DEBUG_OBJECT (queue, "could not post buffering message");
1228 g_mutex_unlock (&queue->buffering_post_lock);
1232 update_buffering (GstQueue2 * queue)
1234 gint buffering_level, percent;
1236 /* Ensure the variables used to calculate buffering state are up-to-date. */
1238 update_cur_level (queue, queue->current);
1239 update_in_rates (queue, FALSE);
1241 if (!get_buffering_level (queue, NULL, &buffering_level))
1244 percent = convert_to_buffering_percent (queue, buffering_level);
1246 if (queue->is_buffering) {
1247 /* if we were buffering see if we reached the high watermark */
1249 queue->is_buffering = FALSE;
1251 SET_PERCENT (queue, percent);
1253 /* we were not buffering, check if we need to start buffering if we drop
1254 * below the low threshold */
1255 if (buffering_level < queue->low_watermark) {
1256 queue->is_buffering = TRUE;
1257 SET_PERCENT (queue, percent);
1263 reset_rate_timer (GstQueue2 * queue)
1265 queue->bytes_in = 0;
1266 queue->bytes_out = 0;
1267 queue->byte_in_rate = 0.0;
1268 queue->byte_in_period = 0;
1269 queue->byte_out_rate = 0.0;
1270 queue->last_update_in_rates_elapsed = 0.0;
1271 queue->last_in_elapsed = 0.0;
1272 queue->last_out_elapsed = 0.0;
1273 queue->in_timer_started = FALSE;
1274 queue->out_timer_started = FALSE;
1277 /* the interval in seconds to recalculate the rate */
1278 #define RATE_INTERVAL 0.2
1279 /* Tuning for rate estimation. We use a large window for the input rate because
1280 * it should be stable when connected to a network. The output rate is less
1281 * stable (the elements preroll, queues behind a demuxer fill, ...) and should
1282 * therefore adapt more quickly.
1283 * However, initial input rate may be subject to a burst, and should therefore
1284 * initially also adapt more quickly to changes, and only later on give higher
1285 * weight to previous values. */
1286 #define AVG_IN(avg,val,w1,w2) ((avg) * (w1) + (val) * (w2)) / ((w1) + (w2))
1287 #define AVG_OUT(avg,val) ((avg) * 3.0 + (val)) / 4.0
1290 update_in_rates (GstQueue2 * queue, gboolean force)
1292 gdouble elapsed, period;
1293 gdouble byte_in_rate;
1295 if (!queue->in_timer_started) {
1296 queue->in_timer_started = TRUE;
1297 g_timer_start (queue->in_timer);
1301 queue->last_update_in_rates_elapsed = elapsed =
1302 g_timer_elapsed (queue->in_timer, NULL);
1304 /* recalc after each interval. */
1305 if (force || queue->last_in_elapsed + RATE_INTERVAL < elapsed) {
1306 period = elapsed - queue->last_in_elapsed;
1308 GST_DEBUG_OBJECT (queue,
1309 "rates: period %f, in %" G_GUINT64_FORMAT ", global period %f",
1310 period, queue->bytes_in, queue->byte_in_period);
1312 byte_in_rate = queue->bytes_in / period;
1314 if (queue->byte_in_rate == 0.0)
1315 queue->byte_in_rate = byte_in_rate;
1317 queue->byte_in_rate = AVG_IN (queue->byte_in_rate, byte_in_rate,
1318 (double) queue->byte_in_period, period);
1320 /* another data point, cap at 16 for long time running average */
1321 if (queue->byte_in_period < 16 * RATE_INTERVAL)
1322 queue->byte_in_period += period;
1324 /* reset the values to calculate rate over the next interval */
1325 queue->last_in_elapsed = elapsed;
1326 queue->bytes_in = 0;
1329 if (queue->use_bitrate_query && queue->downstream_bitrate > 0) {
1330 queue->cur_level.rate_time =
1331 gst_util_uint64_scale (8 * queue->cur_level.bytes, GST_SECOND,
1332 queue->downstream_bitrate);
1333 GST_LOG_OBJECT (queue,
1334 "got bitrate %u with byte level %u resulting in time %"
1335 GST_TIME_FORMAT, queue->downstream_bitrate, queue->cur_level.bytes,
1336 GST_TIME_ARGS (queue->cur_level.rate_time));
1337 } else if (queue->byte_in_rate > 0.0) {
1338 queue->cur_level.rate_time =
1339 queue->cur_level.bytes / queue->byte_in_rate * GST_SECOND;
1341 GST_DEBUG_OBJECT (queue, "rates: in %f, time %" GST_TIME_FORMAT,
1342 queue->byte_in_rate, GST_TIME_ARGS (queue->cur_level.rate_time));
1346 update_out_rates (GstQueue2 * queue)
1348 gdouble elapsed, period;
1349 gdouble byte_out_rate;
1351 if (!queue->out_timer_started) {
1352 queue->out_timer_started = TRUE;
1353 g_timer_start (queue->out_timer);
1357 elapsed = g_timer_elapsed (queue->out_timer, NULL);
1359 /* recalc after each interval. */
1360 if (queue->last_out_elapsed + RATE_INTERVAL < elapsed) {
1361 period = elapsed - queue->last_out_elapsed;
1363 GST_DEBUG_OBJECT (queue,
1364 "rates: period %f, out %" G_GUINT64_FORMAT, period, queue->bytes_out);
1366 byte_out_rate = queue->bytes_out / period;
1368 if (queue->byte_out_rate == 0.0)
1369 queue->byte_out_rate = byte_out_rate;
1371 queue->byte_out_rate = AVG_OUT (queue->byte_out_rate, byte_out_rate);
1373 /* reset the values to calculate rate over the next interval */
1374 queue->last_out_elapsed = elapsed;
1375 queue->bytes_out = 0;
1377 if (queue->byte_in_rate > 0.0) {
1378 queue->cur_level.rate_time =
1379 queue->cur_level.bytes / queue->byte_in_rate * GST_SECOND;
1381 GST_DEBUG_OBJECT (queue, "rates: out %f, time %" GST_TIME_FORMAT,
1382 queue->byte_out_rate, GST_TIME_ARGS (queue->cur_level.rate_time));
1386 update_cur_pos (GstQueue2 * queue, GstQueue2Range * range, guint64 pos)
1388 guint64 reading_pos, max_reading_pos;
1391 max_reading_pos = range->max_reading_pos;
1393 max_reading_pos = MAX (max_reading_pos, reading_pos);
1395 GST_DEBUG_OBJECT (queue,
1396 "updating max_reading_pos from %" G_GUINT64_FORMAT " to %"
1397 G_GUINT64_FORMAT, range->max_reading_pos, max_reading_pos);
1398 range->max_reading_pos = max_reading_pos;
1400 update_cur_level (queue, range);
1404 perform_seek_to_offset (GstQueue2 * queue, guint64 offset)
1409 /* until we receive the FLUSH_STOP from this seek, we skip data */
1410 queue->seeking = TRUE;
1411 GST_QUEUE2_MUTEX_UNLOCK (queue);
1413 debug_ranges (queue);
1415 GST_DEBUG_OBJECT (queue, "Seeking to %" G_GUINT64_FORMAT, offset);
1418 gst_event_new_seek (1.0, GST_FORMAT_BYTES,
1419 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET, offset,
1420 GST_SEEK_TYPE_NONE, -1);
1422 res = gst_pad_push_event (queue->sinkpad, event);
1423 GST_QUEUE2_MUTEX_LOCK (queue);
1426 /* Between us sending the seek event and re-acquiring the lock, the source
1427 * thread might already have pushed data and moved along the range's
1428 * writing_pos beyond the seek offset. In that case we don't want to set
1429 * the writing position back to the requested seek position, as it would
1430 * cause data to be written to the wrong offset in the file or ring buffer.
1431 * We still do the add_range call to switch the current range to the
1432 * requested range, or create one if one doesn't exist yet. */
1433 queue->current = add_range (queue, offset, FALSE);
1439 /* get the threshold for when we decide to seek rather than wait */
1441 get_seek_threshold (GstQueue2 * queue)
1445 /* FIXME, find a good threshold based on the incoming rate. */
1446 threshold = 1024 * 512;
1448 #ifdef TIZEN_FEATURE_SEEK_THRESHOLD
1449 guint64 seek_thresholds[] =
1450 {(1.5*1024*1024), (1*1024*1024), (512*1024), (256*1024)};
1452 for (int i = 0 ; i < G_N_ELEMENTS(seek_thresholds) ; i++) {
1453 if (seek_thresholds[i] < (guint64)queue->byte_in_rate) {
1454 threshold = seek_thresholds[i];
1460 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
1461 threshold = MIN (threshold,
1462 QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes);
1467 /* see if there is enough data in the file to read a full buffer */
1469 gst_queue2_have_data (GstQueue2 * queue, guint64 offset, guint length)
1471 GstQueue2Range *range;
1473 GST_DEBUG_OBJECT (queue, "looking for offset %" G_GUINT64_FORMAT ", len %u",
1476 if ((range = find_range (queue, offset))) {
1477 if (queue->current != range) {
1478 GST_DEBUG_OBJECT (queue, "switching ranges, do seek to range position");
1479 perform_seek_to_offset (queue, range->writing_pos);
1482 GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %" G_GUINT64_FORMAT ")",
1483 queue->cur_level.bytes, QUEUE_MAX_BYTES (queue));
1485 /* we have a range for offset */
1486 GST_DEBUG_OBJECT (queue,
1487 "we have a range %p, offset %" G_GUINT64_FORMAT ", writing_pos %"
1488 G_GUINT64_FORMAT, range, range->offset, range->writing_pos);
1490 if (!QUEUE_IS_USING_RING_BUFFER (queue) && queue->is_eos)
1493 if (offset + length <= range->writing_pos)
1496 GST_DEBUG_OBJECT (queue,
1497 "Need more data (%" G_GUINT64_FORMAT " bytes more)",
1498 (offset + length) - range->writing_pos);
1501 GST_INFO_OBJECT (queue, "not found in any range off %" G_GUINT64_FORMAT
1502 " len %u", offset, length);
1503 /* we don't have the range, see how far away we are */
1504 if (!queue->is_eos && queue->current) {
1505 guint64 threshold = get_seek_threshold (queue);
1507 if (offset >= queue->current->offset && offset <=
1508 queue->current->writing_pos + threshold) {
1509 GST_INFO_OBJECT (queue,
1510 "requested data is within range, wait for data");
1515 /* too far away, do a seek */
1516 perform_seek_to_offset (queue, offset);
1523 #define FSEEK_FILE(file,offset) (fseeko (file, (off_t) offset, SEEK_SET) != 0)
1524 #elif defined (G_OS_UNIX) || defined (G_OS_WIN32)
1525 #define FSEEK_FILE(file,offset) (lseek (fileno (file), (off_t) offset, SEEK_SET) == (off_t) -1)
1527 #define FSEEK_FILE(file,offset) (fseek (file, offset, SEEK_SET) != 0)
1530 static GstFlowReturn
1531 gst_queue2_read_data_at_offset (GstQueue2 * queue, guint64 offset, guint length,
1532 guint8 * dst, gint64 * read_return)
1534 guint8 *ring_buffer;
1537 ring_buffer = queue->ring_buffer;
1539 if (QUEUE_IS_USING_TEMP_FILE (queue) && FSEEK_FILE (queue->temp_file, offset))
1542 /* this should not block */
1543 GST_LOG_OBJECT (queue, "Reading %d bytes from offset %" G_GUINT64_FORMAT,
1545 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
1546 res = fread (dst, 1, length, queue->temp_file);
1548 memcpy (dst, ring_buffer + offset, length);
1552 GST_LOG_OBJECT (queue, "read %" G_GSIZE_FORMAT " bytes", res);
1554 if (G_UNLIKELY (res < length)) {
1555 if (!QUEUE_IS_USING_TEMP_FILE (queue))
1556 goto could_not_read;
1557 /* check for errors or EOF */
1558 if (ferror (queue->temp_file))
1559 goto could_not_read;
1560 if (feof (queue->temp_file) && length > 0)
1570 GST_ELEMENT_ERROR (queue, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM);
1571 return GST_FLOW_ERROR;
1575 GST_ELEMENT_ERROR (queue, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
1576 return GST_FLOW_ERROR;
1580 GST_DEBUG ("non-regular file hits EOS");
1581 return GST_FLOW_EOS;
1585 static GstFlowReturn
1586 gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
1587 GstBuffer ** buffer)
1592 guint64 file_offset;
1593 guint block_length, remaining, read_length;
1597 GstFlowReturn ret = GST_FLOW_OK;
1599 /* allocate the output buffer of the requested size */
1600 if (*buffer == NULL)
1601 buf = gst_buffer_new_allocate (NULL, length, NULL);
1605 if (!gst_buffer_map (buf, &info, GST_MAP_WRITE))
1606 goto buffer_write_fail;
1609 GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length,
1613 rb_size = queue->ring_buffer_max_size;
1614 max_size = QUEUE_MAX_BYTES (queue);
1617 while (remaining > 0) {
1618 /* configure how much/whether to read */
1619 if (!gst_queue2_have_data (queue, rpos, remaining)) {
1622 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
1625 /* calculate how far away the offset is */
1626 if (queue->current->writing_pos > rpos)
1627 level = queue->current->writing_pos - rpos;
1631 GST_DEBUG_OBJECT (queue,
1632 "reading %" G_GUINT64_FORMAT ", writing %" G_GUINT64_FORMAT
1633 ", level %" G_GUINT64_FORMAT ", max %" G_GUINT64_FORMAT,
1634 rpos, queue->current->writing_pos, level, max_size);
1636 if (level >= max_size) {
1637 /* we don't have the data but if we have a ring buffer that is full, we
1639 GST_DEBUG_OBJECT (queue,
1640 "ring buffer full, reading QUEUE_MAX_BYTES %"
1641 G_GUINT64_FORMAT " bytes", max_size);
1642 read_length = max_size;
1643 } else if (queue->is_eos) {
1644 /* won't get any more data so read any data we have */
1646 GST_DEBUG_OBJECT (queue,
1647 "EOS hit but read %" G_GUINT64_FORMAT " bytes that we have",
1649 read_length = level;
1657 if (read_length == 0) {
1658 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
1659 GST_DEBUG_OBJECT (queue,
1660 "update current position [%" G_GUINT64_FORMAT "-%"
1661 G_GUINT64_FORMAT "]", rpos, queue->current->max_reading_pos);
1662 update_cur_pos (queue, queue->current, rpos);
1663 GST_QUEUE2_SIGNAL_DEL (queue);
1666 if (queue->use_buffering)
1667 update_buffering (queue);
1669 GST_DEBUG_OBJECT (queue, "waiting for add");
1670 GST_QUEUE2_WAIT_ADD_CHECK (queue, queue->srcresult, out_flushing);
1674 /* we have the requested data so read it */
1675 read_length = remaining;
1678 /* set range reading_pos to actual reading position for this read */
1679 queue->current->reading_pos = rpos;
1681 /* configure how much and from where to read */
1682 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
1684 (queue->current->rb_offset + (rpos -
1685 queue->current->offset)) % rb_size;
1686 if (file_offset + read_length > rb_size) {
1687 block_length = rb_size - file_offset;
1689 block_length = read_length;
1693 block_length = read_length;
1696 /* while we still have data to read, we loop */
1697 while (read_length > 0) {
1701 gst_queue2_read_data_at_offset (queue, file_offset, block_length,
1702 data, &read_return);
1703 if (ret != GST_FLOW_OK)
1706 file_offset += read_return;
1707 if (QUEUE_IS_USING_RING_BUFFER (queue))
1708 file_offset %= rb_size;
1710 data += read_return;
1711 read_length -= read_return;
1712 block_length = read_length;
1713 remaining -= read_return;
1715 rpos = (queue->current->reading_pos += read_return);
1716 update_cur_pos (queue, queue->current, queue->current->reading_pos);
1718 GST_QUEUE2_SIGNAL_DEL (queue);
1719 GST_DEBUG_OBJECT (queue, "%u bytes left to read", remaining);
1722 gst_buffer_unmap (buf, &info);
1723 gst_buffer_resize (buf, 0, length);
1725 GST_BUFFER_OFFSET (buf) = offset;
1726 GST_BUFFER_OFFSET_END (buf) = offset + length;
1735 GST_DEBUG_OBJECT (queue, "EOS hit and we don't have any requested data");
1736 gst_buffer_unmap (buf, &info);
1737 if (*buffer == NULL)
1738 gst_buffer_unref (buf);
1739 return GST_FLOW_EOS;
1743 GST_DEBUG_OBJECT (queue, "we are flushing");
1744 gst_buffer_unmap (buf, &info);
1745 if (*buffer == NULL)
1746 gst_buffer_unref (buf);
1747 return GST_FLOW_FLUSHING;
1751 GST_DEBUG_OBJECT (queue, "we have a read error");
1752 gst_buffer_unmap (buf, &info);
1753 if (*buffer == NULL)
1754 gst_buffer_unref (buf);
1759 GST_ELEMENT_ERROR (queue, RESOURCE, WRITE, (NULL),
1760 ("Can't write to buffer"));
1761 if (*buffer == NULL)
1762 gst_buffer_unref (buf);
1763 return GST_FLOW_ERROR;
1767 /* should be called with QUEUE_LOCK */
1768 static GstMiniObject *
1769 gst_queue2_read_item_from_file (GstQueue2 * queue)
1771 GstMiniObject *item;
1773 if (queue->stream_start_event != NULL) {
1774 item = GST_MINI_OBJECT_CAST (queue->stream_start_event);
1775 queue->stream_start_event = NULL;
1776 } else if (queue->starting_segment != NULL) {
1777 item = GST_MINI_OBJECT_CAST (queue->starting_segment);
1778 queue->starting_segment = NULL;
1781 GstBuffer *buffer = NULL;
1782 guint64 reading_pos;
1784 reading_pos = queue->current->reading_pos;
1787 gst_queue2_create_read (queue, reading_pos, DEFAULT_BUFFER_SIZE,
1792 item = GST_MINI_OBJECT_CAST (buffer);
1795 item = GST_MINI_OBJECT_CAST (gst_event_new_eos ());
1805 /* must be called with MUTEX_LOCK. Will briefly release the lock when notifying
1806 * the temp filename. */
1808 gst_queue2_open_temp_location_file (GstQueue2 * queue)
1813 if (queue->temp_file)
1814 goto already_opened;
1816 GST_DEBUG_OBJECT (queue, "opening temp file %s", queue->temp_template);
1818 /* If temp_template was set, allocate a filename and open that file */
1821 if (queue->temp_template == NULL)
1824 /* make copy of the template, we don't want to change this */
1825 name = g_strdup (queue->temp_template);
1828 fd = g_mkstemp_full (name, O_RDWR | O_LARGEFILE, S_IRUSR | S_IWUSR);
1830 fd = g_mkstemp (name);
1834 goto mkstemp_failed;
1836 /* open the file for update/writing */
1837 queue->temp_file = fdopen (fd, "wb+");
1838 /* error creating file */
1839 if (queue->temp_file == NULL)
1842 g_free (queue->temp_location);
1843 queue->temp_location = name;
1845 GST_QUEUE2_MUTEX_UNLOCK (queue);
1847 /* we can't emit the notify with the lock */
1848 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_TEMP_LOCATION]);
1850 GST_QUEUE2_MUTEX_LOCK (queue);
1852 GST_DEBUG_OBJECT (queue, "opened temp file %s", queue->temp_template);
1859 GST_DEBUG_OBJECT (queue, "temp file was already open");
1864 GST_ELEMENT_ERROR (queue, RESOURCE, NOT_FOUND,
1865 (_("No Temp directory specified.")), (NULL));
1870 GST_ELEMENT_ERROR (queue, RESOURCE, OPEN_READ,
1871 (_("Could not create temp file \"%s\"."), queue->temp_template),
1878 GST_ELEMENT_ERROR (queue, RESOURCE, OPEN_READ,
1879 (_("Could not open file \"%s\" for reading."), name), GST_ERROR_SYSTEM);
1888 gst_queue2_close_temp_location_file (GstQueue2 * queue)
1891 if (queue->temp_file == NULL)
1894 GST_DEBUG_OBJECT (queue, "closing temp file");
1896 fflush (queue->temp_file);
1897 fclose (queue->temp_file);
1899 if (queue->temp_remove) {
1900 if (remove (queue->temp_location) < 0) {
1901 GST_WARNING_OBJECT (queue, "Failed to remove temporary file %s: %s",
1902 queue->temp_location, g_strerror (errno));
1906 queue->temp_file = NULL;
1907 clean_ranges (queue);
1911 gst_queue2_flush_temp_file (GstQueue2 * queue)
1913 if (queue->temp_file == NULL)
1916 GST_DEBUG_OBJECT (queue, "flushing temp file");
1918 queue->temp_file = g_freopen (queue->temp_location, "wb+", queue->temp_file);
1922 gst_queue2_locked_flush (GstQueue2 * queue, gboolean full, gboolean clear_temp)
1924 if (!QUEUE_IS_USING_QUEUE (queue)) {
1925 if (QUEUE_IS_USING_TEMP_FILE (queue) && clear_temp)
1926 gst_queue2_flush_temp_file (queue);
1927 init_ranges (queue);
1929 GstQueue2Item *qitem;
1931 while ((qitem = gst_queue_array_pop_head_struct (queue->queue))) {
1932 if (!full && qitem->type == GST_QUEUE2_ITEM_TYPE_EVENT
1933 && GST_EVENT_IS_STICKY (qitem->item)
1934 && GST_EVENT_TYPE (qitem->item) != GST_EVENT_SEGMENT
1935 && GST_EVENT_TYPE (qitem->item) != GST_EVENT_EOS) {
1936 gst_pad_store_sticky_event (queue->srcpad,
1937 GST_EVENT_CAST (qitem->item));
1940 /* Then lose another reference because we are supposed to destroy that
1941 data when flushing */
1942 if (qitem->type != GST_QUEUE2_ITEM_TYPE_QUERY)
1943 gst_mini_object_unref (qitem->item);
1946 queue->last_query = FALSE;
1947 g_cond_signal (&queue->query_handled);
1948 GST_QUEUE2_CLEAR_LEVEL (queue->cur_level);
1949 gst_segment_init (&queue->sink_segment, GST_FORMAT_TIME);
1950 gst_segment_init (&queue->src_segment, GST_FORMAT_TIME);
1951 queue->sinktime = queue->srctime = GST_CLOCK_TIME_NONE;
1952 queue->sink_tainted = queue->src_tainted = TRUE;
1953 if (queue->starting_segment != NULL)
1954 gst_event_unref (queue->starting_segment);
1955 queue->starting_segment = NULL;
1956 queue->segment_event_received = FALSE;
1957 gst_event_replace (&queue->stream_start_event, NULL);
1959 /* we deleted a lot of something */
1960 GST_QUEUE2_SIGNAL_DEL (queue);
1964 gst_queue2_wait_free_space (GstQueue2 * queue)
1966 /* We make space available if we're "full" according to whatever
1967 * the user defined as "full". */
1968 if (gst_queue2_is_filled (queue)) {
1971 /* pause the timer while we wait. The fact that we are waiting does not mean
1972 * the byterate on the input pad is lower */
1973 if ((started = queue->in_timer_started))
1974 g_timer_stop (queue->in_timer);
1976 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue,
1977 "queue is full, waiting for free space");
1979 /* Wait for space to be available, we could be unlocked because of a flush. */
1980 GST_QUEUE2_WAIT_DEL_CHECK (queue, queue->sinkresult, out_flushing);
1982 while (gst_queue2_is_filled (queue));
1984 /* and continue if we were running before */
1986 g_timer_continue (queue->in_timer);
1993 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is flushing");
1999 gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
2002 guint8 *data, *ring_buffer;
2003 guint size, rb_size;
2004 guint64 writing_pos, new_writing_pos;
2005 GstQueue2Range *range, *prev, *next;
2006 gboolean do_seek = FALSE;
2008 if (QUEUE_IS_USING_RING_BUFFER (queue))
2009 writing_pos = queue->current->rb_writing_pos;
2011 writing_pos = queue->current->writing_pos;
2012 ring_buffer = queue->ring_buffer;
2013 rb_size = queue->ring_buffer_max_size;
2015 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2016 goto buffer_read_error;
2021 GST_DEBUG_OBJECT (queue, "Writing %u bytes to %" G_GUINT64_FORMAT, size,
2025 if (GST_BUFFER_OFFSET_IS_VALID (buffer) &&
2026 GST_BUFFER_OFFSET (buffer) != queue->current->writing_pos) {
2027 GST_WARNING_OBJECT (queue, "buffer offset does not match current writing "
2028 "position! %" G_GINT64_FORMAT " != %" G_GINT64_FORMAT,
2029 GST_BUFFER_OFFSET (buffer), queue->current->writing_pos);
2035 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
2038 /* calculate the space in the ring buffer not used by data from
2039 * the current range */
2040 while (QUEUE_MAX_BYTES (queue) <= queue->cur_level.bytes) {
2041 /* wait until there is some free space */
2042 GST_QUEUE2_WAIT_DEL_CHECK (queue, queue->sinkresult, out_flushing);
2044 /* get the amount of space we have */
2045 space = QUEUE_MAX_BYTES (queue) - queue->cur_level.bytes;
2047 /* calculate if we need to split or if we can write the entire
2049 to_write = MIN (size, space);
2051 /* the writing position in the ring buffer after writing (part
2052 * or all of) the buffer */
2053 new_writing_pos = (writing_pos + to_write) % rb_size;
2056 range = queue->ranges;
2058 /* if we need to overwrite data in the ring buffer, we need to
2061 * warning: this code is complicated and includes some
2062 * simplifications - pen, paper and diagrams for the cases
2065 guint64 range_data_start, range_data_end;
2066 GstQueue2Range *range_to_destroy = NULL;
2068 #ifndef TIZEN_FEATURE_QUEUE2_MODIFICATION
2069 if (range == queue->current)
2073 range_data_start = range->rb_offset;
2074 range_data_end = range->rb_writing_pos;
2076 /* handle the special case where the range has no data in it */
2077 if (range->writing_pos == range->offset) {
2078 if (range != queue->current) {
2079 GST_DEBUG_OBJECT (queue,
2080 "Removing range: offset %" G_GUINT64_FORMAT ", wpos %"
2081 G_GUINT64_FORMAT, range->offset, range->writing_pos);
2083 range_to_destroy = range;
2085 prev->next = range->next;
2090 if (range_data_end > range_data_start) {
2091 if (writing_pos >= range_data_end && new_writing_pos >= writing_pos)
2094 if (new_writing_pos > range_data_start) {
2095 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
2096 if (new_writing_pos >= range_data_end && range != queue->current) {
2098 if (new_writing_pos >= range_data_end) {
2100 GST_DEBUG_OBJECT (queue,
2101 "Removing range: offset %" G_GUINT64_FORMAT ", wpos %"
2102 G_GUINT64_FORMAT, range->offset, range->writing_pos);
2104 range_to_destroy = range;
2106 prev->next = range->next;
2108 GST_DEBUG_OBJECT (queue,
2109 "advancing offsets from %" G_GUINT64_FORMAT " (%"
2110 G_GUINT64_FORMAT ") to %" G_GUINT64_FORMAT " (%"
2111 G_GUINT64_FORMAT ")", range->offset, range->rb_offset,
2112 range->offset + new_writing_pos - range_data_start,
2114 range->offset += (new_writing_pos - range_data_start);
2115 range->rb_offset = new_writing_pos;
2119 guint64 new_wpos_virt = writing_pos + to_write;
2121 if (new_wpos_virt <= range_data_start)
2124 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
2125 if (new_wpos_virt > rb_size && new_writing_pos >= range_data_end
2126 && range != queue->current) {
2128 if (new_wpos_virt > rb_size && new_writing_pos >= range_data_end) {
2130 GST_DEBUG_OBJECT (queue,
2131 "Removing range: offset %" G_GUINT64_FORMAT ", wpos %"
2132 G_GUINT64_FORMAT, range->offset, range->writing_pos);
2134 range_to_destroy = range;
2136 prev->next = range->next;
2138 GST_DEBUG_OBJECT (queue,
2139 "advancing offsets from %" G_GUINT64_FORMAT " (%"
2140 G_GUINT64_FORMAT ") to %" G_GUINT64_FORMAT " (%"
2141 G_GUINT64_FORMAT ")", range->offset, range->rb_offset,
2142 range->offset + new_writing_pos - range_data_start,
2144 range->offset += (new_wpos_virt - range_data_start);
2145 range->rb_offset = new_writing_pos;
2150 if (!range_to_destroy)
2153 range = range->next;
2154 if (range_to_destroy) {
2155 if (range_to_destroy == queue->ranges)
2156 queue->ranges = range;
2157 g_slice_free (GstQueue2Range, range_to_destroy);
2158 range_to_destroy = NULL;
2163 new_writing_pos = writing_pos + to_write;
2166 if (QUEUE_IS_USING_TEMP_FILE (queue)
2167 && FSEEK_FILE (queue->temp_file, writing_pos))
2170 if (new_writing_pos > writing_pos) {
2171 GST_INFO_OBJECT (queue,
2172 "writing %u bytes to range [%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT
2173 "] (rb wpos %" G_GUINT64_FORMAT ")", to_write, queue->current->offset,
2174 queue->current->writing_pos, queue->current->rb_writing_pos);
2175 /* either not using ring buffer or no wrapping, just write */
2176 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
2177 if (fwrite (data, to_write, 1, queue->temp_file) != 1)
2180 memcpy (ring_buffer + writing_pos, data, to_write);
2183 if (!QUEUE_IS_USING_RING_BUFFER (queue)) {
2184 /* try to merge with next range */
2185 while ((next = queue->current->next)) {
2186 GST_INFO_OBJECT (queue,
2187 "checking merge with next range %" G_GUINT64_FORMAT " < %"
2188 G_GUINT64_FORMAT, new_writing_pos, next->offset);
2189 if (new_writing_pos < next->offset)
2192 GST_DEBUG_OBJECT (queue, "merging ranges %" G_GUINT64_FORMAT,
2195 /* remove the group */
2196 queue->current->next = next->next;
2198 /* We use the threshold to decide if we want to do a seek or simply
2199 * read the data again. If there is not so much data in the range we
2200 * prefer to avoid to seek and read it again. */
2201 if (next->writing_pos > new_writing_pos + get_seek_threshold (queue)) {
2202 /* the new range had more data than the threshold, it's worth keeping
2203 * it and doing a seek. */
2204 new_writing_pos = next->writing_pos;
2207 g_slice_free (GstQueue2Range, next);
2209 goto update_and_signal;
2213 guint block_one, block_two;
2215 block_one = rb_size - writing_pos;
2216 block_two = to_write - block_one;
2218 if (block_one > 0) {
2219 GST_INFO_OBJECT (queue, "writing %u bytes", block_one);
2220 /* write data to end of ring buffer */
2221 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
2222 if (fwrite (data, block_one, 1, queue->temp_file) != 1)
2225 memcpy (ring_buffer + writing_pos, data, block_one);
2229 if (QUEUE_IS_USING_TEMP_FILE (queue) && FSEEK_FILE (queue->temp_file, 0))
2232 if (block_two > 0) {
2233 GST_INFO_OBJECT (queue, "writing %u bytes", block_two);
2234 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
2235 if (fwrite (data + block_one, block_two, 1, queue->temp_file) != 1)
2238 memcpy (ring_buffer, data + block_one, block_two);
2244 /* update the writing positions */
2246 GST_INFO_OBJECT (queue,
2247 "wrote %u bytes to %" G_GUINT64_FORMAT " (%u bytes remaining to write)",
2248 to_write, writing_pos, size);
2250 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
2252 queue->current->writing_pos += to_write;
2253 queue->current->rb_writing_pos = writing_pos = new_writing_pos;
2255 queue->current->writing_pos = writing_pos = new_writing_pos;
2256 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
2258 if (queue->upstream_size == 0 || new_writing_pos < queue->upstream_size)
2259 perform_seek_to_offset (queue, new_writing_pos);
2261 queue->is_eos = TRUE;
2266 #ifndef TIZEN_FEATURE_QUEUE2_MODIFICATION
2268 perform_seek_to_offset (queue, new_writing_pos);
2271 update_cur_level (queue, queue->current);
2273 /* update the buffering status */
2274 if (queue->use_buffering) {
2277 update_buffering (queue);
2278 msg = gst_queue2_get_buffering_message (queue, &percent);
2282 GST_QUEUE2_MUTEX_UNLOCK (queue);
2284 g_mutex_lock (&queue->buffering_post_lock);
2285 post_ok = gst_element_post_message (GST_ELEMENT_CAST (queue), msg);
2287 GST_QUEUE2_MUTEX_LOCK (queue);
2290 /* Set these states only if posting the message succeeded. Otherwise,
2291 * this post attempt failed, and the next one won't be done, because
2292 * gst_queue2_get_buffering_message() checks these states and decides
2293 * based on their values that it won't produce a message. */
2294 queue->last_posted_buffering_percent = percent;
2295 if (percent == queue->buffering_percent)
2296 queue->percent_changed = FALSE;
2297 GST_DEBUG_OBJECT (queue, "successfully posted %d%% buffering message",
2300 GST_DEBUG_OBJECT (queue, "could not post buffering message");
2302 g_mutex_unlock (&queue->buffering_post_lock);
2306 GST_INFO_OBJECT (queue, "cur_level.bytes %u (max %" G_GUINT64_FORMAT ")",
2307 queue->cur_level.bytes, QUEUE_MAX_BYTES (queue));
2309 GST_QUEUE2_SIGNAL_ADD (queue);
2312 gst_buffer_unmap (buffer, &info);
2319 GST_DEBUG_OBJECT (queue, "we are flushing");
2320 gst_buffer_unmap (buffer, &info);
2321 /* FIXME - GST_FLOW_EOS ? */
2326 GST_ELEMENT_ERROR (queue, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM);
2327 gst_buffer_unmap (buffer, &info);
2334 GST_ELEMENT_ERROR (queue, RESOURCE, NO_SPACE_LEFT, (NULL), (NULL));
2338 GST_ELEMENT_ERROR (queue, RESOURCE, WRITE,
2339 (_("Error while writing to download file.")),
2340 ("%s", g_strerror (errno)));
2343 gst_buffer_unmap (buffer, &info);
2348 GST_ELEMENT_ERROR (queue, RESOURCE, READ, (NULL),
2349 ("Can't read from buffer"));
2355 buffer_list_create_write (GstBuffer ** buf, guint idx, gpointer q)
2357 GstQueue2 *queue = q;
2359 GST_TRACE_OBJECT (queue,
2360 "writing buffer %u of size %" G_GSIZE_FORMAT " bytes", idx,
2361 gst_buffer_get_size (*buf));
2363 if (!gst_queue2_create_write (queue, *buf)) {
2364 GST_INFO_OBJECT (queue, "create_write() returned FALSE, bailing out");
2370 /* enqueue an item an update the level stats */
2372 gst_queue2_locked_enqueue (GstQueue2 * queue, gpointer item,
2373 GstQueue2ItemType item_type)
2375 if (item_type == GST_QUEUE2_ITEM_TYPE_BUFFER) {
2379 buffer = GST_BUFFER_CAST (item);
2380 size = gst_buffer_get_size (buffer);
2382 /* add buffer to the statistics */
2383 if (QUEUE_IS_USING_QUEUE (queue)) {
2384 queue->cur_level.buffers++;
2385 queue->cur_level.bytes += size;
2387 queue->bytes_in += size;
2389 /* apply new buffer to segment stats */
2390 apply_buffer (queue, buffer, &queue->sink_segment, size, TRUE);
2391 /* update the byterate stats */
2392 update_in_rates (queue, FALSE);
2394 if (!QUEUE_IS_USING_QUEUE (queue)) {
2395 /* FIXME - check return value? */
2396 gst_queue2_create_write (queue, buffer);
2398 } else if (item_type == GST_QUEUE2_ITEM_TYPE_BUFFER_LIST) {
2399 GstBufferList *buffer_list;
2402 buffer_list = GST_BUFFER_LIST_CAST (item);
2404 size = gst_buffer_list_calculate_size (buffer_list);
2405 GST_LOG_OBJECT (queue, "total size of buffer list: %u bytes", size);
2407 /* add buffer to the statistics */
2408 if (QUEUE_IS_USING_QUEUE (queue)) {
2409 queue->cur_level.buffers += gst_buffer_list_length (buffer_list);
2410 queue->cur_level.bytes += size;
2412 queue->bytes_in += size;
2414 /* apply new buffer to segment stats */
2415 apply_buffer_list (queue, buffer_list, &queue->sink_segment, TRUE);
2417 /* update the byterate stats */
2418 update_in_rates (queue, FALSE);
2420 if (!QUEUE_IS_USING_QUEUE (queue)) {
2421 gst_buffer_list_foreach (buffer_list, buffer_list_create_write, queue);
2423 } else if (item_type == GST_QUEUE2_ITEM_TYPE_EVENT) {
2426 event = GST_EVENT_CAST (item);
2428 switch (GST_EVENT_TYPE (event)) {
2430 /* Zero the thresholds, this makes sure the queue is completely
2431 * filled and we can read all data from the queue. */
2432 GST_DEBUG_OBJECT (queue, "we have EOS");
2433 queue->is_eos = TRUE;
2434 /* Force updating the input bitrate */
2435 update_in_rates (queue, TRUE);
2437 case GST_EVENT_SEGMENT:
2438 apply_segment (queue, event, &queue->sink_segment, TRUE);
2439 /* This is our first new segment, we hold it
2440 * as we can't save it on the temp file */
2441 if (!QUEUE_IS_USING_QUEUE (queue)) {
2442 if (queue->segment_event_received)
2443 goto unexpected_event;
2445 queue->segment_event_received = TRUE;
2446 if (queue->starting_segment != NULL)
2447 gst_event_unref (queue->starting_segment);
2448 queue->starting_segment = event;
2451 /* a new segment allows us to accept more buffers if we got EOS
2452 * from downstream */
2453 queue->unexpected = FALSE;
2456 apply_gap (queue, event, &queue->sink_segment, TRUE);
2458 case GST_EVENT_STREAM_START:
2459 if (!QUEUE_IS_USING_QUEUE (queue)) {
2460 gst_event_replace (&queue->stream_start_event, event);
2461 gst_event_unref (event);
2465 case GST_EVENT_CAPS:{
2468 gst_event_parse_caps (event, &caps);
2469 GST_INFO ("got caps: %" GST_PTR_FORMAT, caps);
2471 if (!QUEUE_IS_USING_QUEUE (queue)) {
2472 GST_LOG ("Dropping caps event, not using queue");
2473 gst_event_unref (event);
2479 if (!QUEUE_IS_USING_QUEUE (queue))
2480 goto unexpected_event;
2483 } else if (GST_IS_QUERY (item)) {
2484 /* Can't happen as we check that in the caller */
2485 if (!QUEUE_IS_USING_QUEUE (queue))
2486 g_assert_not_reached ();
2488 g_warning ("Unexpected item %p added in queue %s (refcounting problem?)",
2489 item, GST_OBJECT_NAME (queue));
2490 /* we can't really unref since we don't know what it is */
2495 /* update the buffering status */
2496 if (queue->use_buffering)
2497 update_buffering (queue);
2499 if (QUEUE_IS_USING_QUEUE (queue)) {
2500 GstQueue2Item qitem;
2502 qitem.type = item_type;
2504 gst_queue_array_push_tail_struct (queue->queue, &qitem);
2506 gst_mini_object_unref (GST_MINI_OBJECT_CAST (item));
2509 GST_QUEUE2_SIGNAL_ADD (queue);
2517 gboolean is_custom = GST_EVENT_TYPE (item) < GST_EVENT_CUSTOM_UPSTREAM;
2519 GST_WARNING_OBJECT (queue, "%s%s event can't be added to temp file: "
2520 "%" GST_PTR_FORMAT, is_custom ? "Unexpected " : "",
2521 GST_EVENT_TYPE_NAME (item), GST_EVENT_CAST (item));
2522 gst_event_unref (GST_EVENT_CAST (item));
2527 /* dequeue an item from the queue and update level stats */
2528 static GstMiniObject *
2529 gst_queue2_locked_dequeue (GstQueue2 * queue, GstQueue2ItemType * item_type)
2531 GstMiniObject *item;
2533 if (!QUEUE_IS_USING_QUEUE (queue)) {
2534 item = gst_queue2_read_item_from_file (queue);
2536 GstQueue2Item *qitem = gst_queue_array_pop_head_struct (queue->queue);
2547 if (GST_IS_BUFFER (item)) {
2551 buffer = GST_BUFFER_CAST (item);
2552 size = gst_buffer_get_size (buffer);
2553 *item_type = GST_QUEUE2_ITEM_TYPE_BUFFER;
2555 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
2556 "retrieved buffer %p from queue", buffer);
2558 if (QUEUE_IS_USING_QUEUE (queue)) {
2559 queue->cur_level.buffers--;
2560 queue->cur_level.bytes -= size;
2562 queue->bytes_out += size;
2564 apply_buffer (queue, buffer, &queue->src_segment, size, FALSE);
2565 /* update the byterate stats */
2566 update_out_rates (queue);
2567 /* update the buffering */
2568 if (queue->use_buffering)
2569 update_buffering (queue);
2571 } else if (GST_IS_EVENT (item)) {
2572 GstEvent *event = GST_EVENT_CAST (item);
2574 *item_type = GST_QUEUE2_ITEM_TYPE_EVENT;
2576 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
2577 "retrieved event %p from queue", event);
2579 switch (GST_EVENT_TYPE (event)) {
2581 /* queue is empty now that we dequeued the EOS */
2582 GST_QUEUE2_CLEAR_LEVEL (queue->cur_level);
2584 case GST_EVENT_SEGMENT:
2585 apply_segment (queue, event, &queue->src_segment, FALSE);
2588 apply_gap (queue, event, &queue->src_segment, FALSE);
2593 } else if (GST_IS_BUFFER_LIST (item)) {
2594 GstBufferList *buffer_list;
2597 buffer_list = GST_BUFFER_LIST_CAST (item);
2598 size = gst_buffer_list_calculate_size (buffer_list);
2599 *item_type = GST_QUEUE2_ITEM_TYPE_BUFFER_LIST;
2601 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
2602 "retrieved buffer list %p from queue", buffer_list);
2604 if (QUEUE_IS_USING_QUEUE (queue)) {
2605 queue->cur_level.buffers -= gst_buffer_list_length (buffer_list);
2606 queue->cur_level.bytes -= size;
2608 queue->bytes_out += size;
2610 apply_buffer_list (queue, buffer_list, &queue->src_segment, FALSE);
2611 /* update the byterate stats */
2612 update_out_rates (queue);
2613 /* update the buffering */
2614 if (queue->use_buffering)
2615 update_buffering (queue);
2616 } else if (GST_IS_QUERY (item)) {
2617 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
2618 "retrieved query %p from queue", item);
2619 *item_type = GST_QUEUE2_ITEM_TYPE_QUERY;
2622 ("Unexpected item %p dequeued from queue %s (refcounting problem?)",
2623 item, GST_OBJECT_NAME (queue));
2625 *item_type = GST_QUEUE2_ITEM_TYPE_UNKNOWN;
2627 GST_QUEUE2_SIGNAL_DEL (queue);
2634 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "the queue is empty");
2639 static GstFlowReturn
2640 gst_queue2_handle_sink_event (GstPad * pad, GstObject * parent,
2643 gboolean ret = TRUE;
2646 queue = GST_QUEUE2 (parent);
2648 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "Received event '%s'",
2649 GST_EVENT_TYPE_NAME (event));
2651 switch (GST_EVENT_TYPE (event)) {
2652 case GST_EVENT_FLUSH_START:
2654 if (GST_PAD_MODE (queue->srcpad) == GST_PAD_MODE_PUSH) {
2656 ret = gst_pad_push_event (queue->srcpad, event);
2658 /* now unblock the chain function */
2659 GST_QUEUE2_MUTEX_LOCK (queue);
2660 queue->srcresult = GST_FLOW_FLUSHING;
2661 queue->sinkresult = GST_FLOW_FLUSHING;
2662 /* unblock the loop and chain functions */
2663 GST_QUEUE2_SIGNAL_ADD (queue);
2664 GST_QUEUE2_SIGNAL_DEL (queue);
2665 GST_QUEUE2_MUTEX_UNLOCK (queue);
2667 /* make sure it pauses, this should happen since we sent
2668 * flush_start downstream. */
2669 gst_pad_pause_task (queue->srcpad);
2670 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "loop stopped");
2672 GST_QUEUE2_MUTEX_LOCK (queue);
2673 queue->last_query = FALSE;
2674 g_cond_signal (&queue->query_handled);
2675 GST_QUEUE2_MUTEX_UNLOCK (queue);
2677 GST_QUEUE2_MUTEX_LOCK (queue);
2678 /* flush the sink pad */
2679 queue->sinkresult = GST_FLOW_FLUSHING;
2680 GST_QUEUE2_SIGNAL_DEL (queue);
2681 queue->last_query = FALSE;
2682 g_cond_signal (&queue->query_handled);
2683 GST_QUEUE2_MUTEX_UNLOCK (queue);
2685 gst_event_unref (event);
2689 case GST_EVENT_FLUSH_STOP:
2691 if (GST_PAD_MODE (queue->srcpad) == GST_PAD_MODE_PUSH) {
2693 ret = gst_pad_push_event (queue->srcpad, event);
2695 GST_QUEUE2_MUTEX_LOCK (queue);
2696 gst_queue2_locked_flush (queue, FALSE, TRUE);
2697 queue->srcresult = GST_FLOW_OK;
2698 queue->sinkresult = GST_FLOW_OK;
2699 queue->is_eos = FALSE;
2700 queue->unexpected = FALSE;
2701 queue->seeking = FALSE;
2702 queue->src_tags_bitrate = queue->sink_tags_bitrate = 0;
2703 /* reset rate counters */
2704 reset_rate_timer (queue);
2705 gst_pad_start_task (queue->srcpad, (GstTaskFunction) gst_queue2_loop,
2706 queue->srcpad, NULL);
2707 GST_QUEUE2_MUTEX_UNLOCK (queue);
2709 GST_QUEUE2_MUTEX_LOCK (queue);
2710 queue->segment_event_received = FALSE;
2711 queue->is_eos = FALSE;
2712 queue->unexpected = FALSE;
2713 queue->sinkresult = GST_FLOW_OK;
2714 queue->seeking = FALSE;
2715 queue->src_tags_bitrate = queue->sink_tags_bitrate = 0;
2716 GST_QUEUE2_MUTEX_UNLOCK (queue);
2718 gst_event_unref (event);
2720 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_BITRATE]);
2723 case GST_EVENT_TAG:{
2724 if (queue->use_tags_bitrate) {
2728 gst_event_parse_tag (event, &tags);
2729 if (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &bitrate) ||
2730 gst_tag_list_get_uint (tags, GST_TAG_NOMINAL_BITRATE, &bitrate)) {
2731 GST_QUEUE2_MUTEX_LOCK (queue);
2732 queue->sink_tags_bitrate = bitrate;
2733 GST_QUEUE2_MUTEX_UNLOCK (queue);
2734 GST_LOG_OBJECT (queue, "Sink pad bitrate from tags now %u", bitrate);
2735 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_BITRATE]);
2741 if (GST_EVENT_IS_SERIALIZED (event)) {
2742 gboolean bitrate_changed = TRUE;
2743 /* serialized events go in the queue */
2745 /* STREAM_START and SEGMENT reset the EOS status of a
2746 * pad. Change the cached sinkpad flow result accordingly */
2747 GST_QUEUE2_MUTEX_LOCK (queue);
2748 if (queue->sinkresult == GST_FLOW_EOS
2749 && (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START
2750 || GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT))
2751 queue->sinkresult = GST_FLOW_OK;
2752 else if (queue->sinkresult != GST_FLOW_OK)
2755 if (queue->srcresult != GST_FLOW_OK) {
2756 /* Errors in sticky event pushing are no problem and ignored here
2757 * as they will cause more meaningful errors during data flow.
2758 * For EOS events, that are not followed by data flow, we still
2759 * return FALSE here though and report an error.
2761 if (!GST_EVENT_IS_STICKY (event)) {
2762 goto out_flow_error;
2763 } else if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
2764 if (queue->srcresult == GST_FLOW_NOT_LINKED
2765 || queue->srcresult < GST_FLOW_EOS) {
2766 GST_ELEMENT_FLOW_ERROR (queue, queue->srcresult);
2768 goto out_flow_error;
2772 /* refuse more events on EOS unless they unset the EOS status */
2773 if (queue->is_eos) {
2774 switch (GST_EVENT_TYPE (event)) {
2775 case GST_EVENT_STREAM_START:
2776 case GST_EVENT_SEGMENT:
2777 /* Restart the loop */
2778 if (GST_PAD_MODE (queue->srcpad) == GST_PAD_MODE_PUSH) {
2779 queue->srcresult = GST_FLOW_OK;
2780 queue->is_eos = FALSE;
2781 queue->unexpected = FALSE;
2782 queue->seeking = FALSE;
2783 queue->src_tags_bitrate = queue->sink_tags_bitrate = 0;
2784 /* reset rate counters */
2785 reset_rate_timer (queue);
2786 gst_pad_start_task (queue->srcpad,
2787 (GstTaskFunction) gst_queue2_loop, queue->srcpad, NULL);
2789 queue->is_eos = FALSE;
2790 queue->unexpected = FALSE;
2791 queue->seeking = FALSE;
2792 queue->src_tags_bitrate = queue->sink_tags_bitrate = 0;
2794 bitrate_changed = TRUE;
2802 gst_queue2_locked_enqueue (queue, event, GST_QUEUE2_ITEM_TYPE_EVENT);
2803 GST_QUEUE2_MUTEX_UNLOCK (queue);
2804 gst_queue2_post_buffering (queue);
2805 if (bitrate_changed)
2806 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_BITRATE]);
2808 /* non-serialized events are passed downstream. */
2809 ret = gst_pad_push_event (queue->srcpad, event);
2814 return GST_FLOW_ERROR;
2820 GstFlowReturn ret = queue->sinkresult;
2821 GST_DEBUG_OBJECT (queue, "refusing event, we are %s",
2822 gst_flow_get_name (ret));
2823 GST_QUEUE2_MUTEX_UNLOCK (queue);
2824 gst_event_unref (event);
2829 GST_DEBUG_OBJECT (queue, "refusing event, we are EOS");
2830 GST_QUEUE2_MUTEX_UNLOCK (queue);
2831 gst_event_unref (event);
2832 return GST_FLOW_EOS;
2836 GST_LOG_OBJECT (queue,
2837 "refusing event, we have a downstream flow error: %s",
2838 gst_flow_get_name (queue->srcresult));
2839 GST_QUEUE2_MUTEX_UNLOCK (queue);
2840 gst_event_unref (event);
2841 return queue->srcresult;
2846 gst_queue2_handle_sink_query (GstPad * pad, GstObject * parent,
2852 queue = GST_QUEUE2 (parent);
2854 switch (GST_QUERY_TYPE (query)) {
2856 if (GST_QUERY_IS_SERIALIZED (query)) {
2857 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
2858 "received query %" GST_PTR_FORMAT, query);
2859 /* serialized events go in the queue. We need to be certain that we
2860 * don't cause deadlocks waiting for the query return value. We check if
2861 * the queue is empty (nothing is blocking downstream and the query can
2862 * be pushed for sure) or we are not buffering. If we are buffering,
2863 * the pipeline waits to unblock downstream until our queue fills up
2864 * completely, which can not happen if we block on the query..
2865 * Therefore we only potentially block when we are not buffering.
2867 * Update: Edward Hervey 2021: Realistically when posting buffering
2868 * messages there are no safe places where we can block and forward a
2869 * serialized query due to the potential of causing deadlocks. We
2870 * therefore refuse any serialized queries in such cases. */
2871 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->sinkresult, out_flushing);
2872 if (QUEUE_IS_USING_QUEUE (queue) && !queue->use_buffering) {
2873 if (!g_atomic_int_get (&queue->downstream_may_block)) {
2874 gst_queue2_locked_enqueue (queue, query,
2875 GST_QUEUE2_ITEM_TYPE_QUERY);
2877 STATUS (queue, queue->sinkpad, "wait for QUERY");
2878 while (queue->sinkresult == GST_FLOW_OK &&
2879 queue->last_handled_query != query)
2880 g_cond_wait (&queue->query_handled, &queue->qlock);
2881 queue->last_handled_query = NULL;
2882 if (queue->sinkresult != GST_FLOW_OK)
2884 res = queue->last_query;
2886 GST_DEBUG_OBJECT (queue, "refusing query, downstream might block");
2890 GST_DEBUG_OBJECT (queue,
2891 "refusing query, we are not using the queue or we are posting buffering messages");
2894 GST_QUEUE2_MUTEX_UNLOCK (queue);
2895 gst_queue2_post_buffering (queue);
2897 res = gst_pad_query_default (pad, parent, query);
2906 GST_DEBUG_OBJECT (queue, "refusing query, we are %s",
2907 gst_flow_get_name (queue->sinkresult));
2908 GST_QUEUE2_MUTEX_UNLOCK (queue);
2914 gst_queue2_is_empty (GstQueue2 * queue)
2916 /* never empty on EOS */
2920 if (!QUEUE_IS_USING_QUEUE (queue) && queue->current) {
2921 return queue->current->writing_pos <= queue->current->max_reading_pos;
2923 if (gst_queue_array_get_length (queue->queue) == 0)
2931 gst_queue2_is_filled (GstQueue2 * queue)
2935 /* always filled on EOS */
2939 /* Check the levels if non-null */
2940 #define CHECK_FILLED_REAL(format) \
2941 ((queue->max_level.format) > 0 && (queue->cur_level.format) >= ((queue->max_level.format)))
2942 /* Check the levels if non-null (use the alternative max if non-zero) */
2943 #define CHECK_FILLED_ALT(format,alt_max) ((queue->max_level.format) > 0 && \
2944 (queue->cur_level.format) >= ((alt_max) ? \
2945 MIN ((queue->max_level.format), (alt_max)) : (queue->max_level.format)))
2947 /* if using a ring buffer we're filled if all ring buffer space is used
2948 * _by the current range_ */
2949 if (QUEUE_IS_USING_RING_BUFFER (queue)) {
2950 guint64 rb_size = queue->ring_buffer_max_size;
2951 GST_DEBUG_OBJECT (queue,
2952 "max bytes %u, rb size %" G_GUINT64_FORMAT ", cur bytes %u",
2953 queue->max_level.bytes, rb_size, queue->cur_level.bytes);
2954 return CHECK_FILLED_ALT (bytes, rb_size);
2957 /* if using file, we're never filled if we don't have EOS */
2958 if (QUEUE_IS_USING_TEMP_FILE (queue))
2961 /* we are never filled when we have no buffers at all */
2962 if (queue->cur_level.buffers == 0)
2965 /* we are filled if one of the current levels exceeds the max */
2966 res = CHECK_FILLED_REAL (buffers) || CHECK_FILLED_REAL (bytes)
2967 || CHECK_FILLED_REAL (time);
2969 /* if we need to, use the rate estimate to check against the max time we are
2970 * allowed to queue */
2971 if (queue->use_rate_estimate)
2972 res |= CHECK_FILLED_REAL (rate_time);
2974 #undef CHECK_FILLED_REAL
2975 #undef CHECK_FILLED_ALT
2979 static GstFlowReturn
2980 gst_queue2_chain_buffer_or_buffer_list (GstQueue2 * queue,
2981 GstMiniObject * item, GstQueue2ItemType item_type)
2983 /* we have to lock the queue since we span threads */
2984 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->sinkresult, out_flushing);
2985 /* when we received EOS, we refuse more data */
2988 /* when we received unexpected from downstream, refuse more buffers */
2989 if (queue->unexpected)
2990 goto out_unexpected;
2992 /* while we didn't receive the newsegment, we're seeking and we skip data */
2996 if (!gst_queue2_wait_free_space (queue))
2999 /* put buffer in queue now */
3000 gst_queue2_locked_enqueue (queue, item, item_type);
3001 GST_QUEUE2_MUTEX_UNLOCK (queue);
3002 gst_queue2_post_buffering (queue);
3006 /* special conditions */
3009 GstFlowReturn ret = queue->sinkresult;
3011 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3012 "exit because task paused, reason: %s", gst_flow_get_name (ret));
3013 GST_QUEUE2_MUTEX_UNLOCK (queue);
3014 gst_mini_object_unref (item);
3020 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we received EOS");
3021 GST_QUEUE2_MUTEX_UNLOCK (queue);
3022 gst_mini_object_unref (item);
3024 return GST_FLOW_EOS;
3028 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we are seeking");
3029 GST_QUEUE2_MUTEX_UNLOCK (queue);
3030 gst_mini_object_unref (item);
3036 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we received EOS");
3037 GST_QUEUE2_MUTEX_UNLOCK (queue);
3038 gst_mini_object_unref (item);
3040 return GST_FLOW_EOS;
3044 static GstFlowReturn
3045 gst_queue2_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
3049 queue = GST_QUEUE2 (parent);
3051 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "received buffer %p of "
3052 "size %" G_GSIZE_FORMAT ", time %" GST_TIME_FORMAT ", duration %"
3053 GST_TIME_FORMAT, buffer, gst_buffer_get_size (buffer),
3054 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
3055 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
3057 return gst_queue2_chain_buffer_or_buffer_list (queue,
3058 GST_MINI_OBJECT_CAST (buffer), GST_QUEUE2_ITEM_TYPE_BUFFER);
3061 static GstFlowReturn
3062 gst_queue2_chain_list (GstPad * pad, GstObject * parent,
3063 GstBufferList * buffer_list)
3067 queue = GST_QUEUE2 (parent);
3069 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3070 "received buffer list %p", buffer_list);
3072 return gst_queue2_chain_buffer_or_buffer_list (queue,
3073 GST_MINI_OBJECT_CAST (buffer_list), GST_QUEUE2_ITEM_TYPE_BUFFER_LIST);
3076 static GstMiniObject *
3077 gst_queue2_dequeue_on_eos (GstQueue2 * queue, GstQueue2ItemType * item_type)
3079 GstMiniObject *data;
3081 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "got EOS from downstream");
3083 /* stop pushing buffers, we dequeue all items until we see an item that we
3084 * can push again, which is EOS or SEGMENT. If there is nothing in the
3085 * queue we can push, we set a flag to make the sinkpad refuse more
3086 * buffers with an EOS return value until we receive something
3087 * pushable again or we get flushed. */
3088 while ((data = gst_queue2_locked_dequeue (queue, item_type))) {
3089 if (*item_type == GST_QUEUE2_ITEM_TYPE_BUFFER) {
3090 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3091 "dropping EOS buffer %p", data);
3092 gst_buffer_unref (GST_BUFFER_CAST (data));
3093 } else if (*item_type == GST_QUEUE2_ITEM_TYPE_EVENT) {
3094 GstEvent *event = GST_EVENT_CAST (data);
3095 GstEventType type = GST_EVENT_TYPE (event);
3097 if (type == GST_EVENT_EOS || type == GST_EVENT_SEGMENT
3098 || type == GST_EVENT_STREAM_START) {
3099 /* we found a pushable item in the queue, push it out */
3100 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3101 "pushing pushable event %s after EOS", GST_EVENT_TYPE_NAME (event));
3104 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3105 "dropping EOS event %p", event);
3106 gst_event_unref (event);
3107 } else if (*item_type == GST_QUEUE2_ITEM_TYPE_BUFFER_LIST) {
3108 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3109 "dropping EOS buffer list %p", data);
3110 gst_buffer_list_unref (GST_BUFFER_LIST_CAST (data));
3111 } else if (*item_type == GST_QUEUE2_ITEM_TYPE_QUERY) {
3112 queue->last_query = FALSE;
3113 g_cond_signal (&queue->query_handled);
3114 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "dropping EOS query %p", data);
3117 /* no more items in the queue. Set the unexpected flag so that upstream
3118 * make us refuse any more buffers on the sinkpad. Since we will still
3119 * accept EOS and SEGMENT we return _FLOW_OK to the caller so that the
3120 * task function does not shut down. */
3121 queue->unexpected = TRUE;
3125 /* dequeue an item from the queue an push it downstream. This functions returns
3126 * the result of the push. */
3127 static GstFlowReturn
3128 gst_queue2_push_one (GstQueue2 * queue)
3130 GstFlowReturn result;
3131 GstMiniObject *data;
3132 GstQueue2ItemType item_type;
3134 data = gst_queue2_locked_dequeue (queue, &item_type);
3139 result = queue->srcresult;
3140 STATUS (queue, queue->srcpad, "We have something dequeud");
3141 g_atomic_int_set (&queue->downstream_may_block,
3142 item_type == GST_QUEUE2_ITEM_TYPE_BUFFER ||
3143 item_type == GST_QUEUE2_ITEM_TYPE_BUFFER_LIST);
3144 GST_QUEUE2_MUTEX_UNLOCK (queue);
3145 gst_queue2_post_buffering (queue);
3147 if (gst_pad_check_reconfigure (queue->srcpad)) {
3148 /* If the pad was reconfigured, do a new bitrate query */
3149 query_downstream_bitrate (queue);
3152 if (item_type == GST_QUEUE2_ITEM_TYPE_BUFFER) {
3155 buffer = GST_BUFFER_CAST (data);
3157 result = gst_pad_push (queue->srcpad, buffer);
3158 g_atomic_int_set (&queue->downstream_may_block, 0);
3160 /* need to check for srcresult here as well */
3161 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3162 if (result == GST_FLOW_EOS) {
3163 data = gst_queue2_dequeue_on_eos (queue, &item_type);
3166 /* Since we will still accept EOS and SEGMENT we return _FLOW_OK
3167 * to the caller so that the task function does not shut down */
3168 result = GST_FLOW_OK;
3170 } else if (item_type == GST_QUEUE2_ITEM_TYPE_EVENT) {
3171 GstEvent *event = GST_EVENT_CAST (data);
3172 GstEventType type = GST_EVENT_TYPE (event);
3174 if (type == GST_EVENT_TAG) {
3175 if (queue->use_tags_bitrate) {
3179 gst_event_parse_tag (event, &tags);
3180 if (gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &bitrate) ||
3181 gst_tag_list_get_uint (tags, GST_TAG_NOMINAL_BITRATE, &bitrate)) {
3182 GST_QUEUE2_MUTEX_LOCK (queue);
3183 queue->src_tags_bitrate = bitrate;
3184 GST_QUEUE2_MUTEX_UNLOCK (queue);
3185 GST_LOG_OBJECT (queue, "src pad bitrate from tags now %u", bitrate);
3186 g_object_notify_by_pspec (G_OBJECT (queue), obj_props[PROP_BITRATE]);
3191 gst_pad_push_event (queue->srcpad, event);
3193 /* if we're EOS, return EOS so that the task pauses. */
3194 if (type == GST_EVENT_EOS) {
3195 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3196 "pushed EOS event %p, return EOS", event);
3197 result = GST_FLOW_EOS;
3200 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3201 } else if (item_type == GST_QUEUE2_ITEM_TYPE_BUFFER_LIST) {
3202 GstBufferList *buffer_list;
3204 buffer_list = GST_BUFFER_LIST_CAST (data);
3206 result = gst_pad_push_list (queue->srcpad, buffer_list);
3207 g_atomic_int_set (&queue->downstream_may_block, 0);
3209 /* need to check for srcresult here as well */
3210 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3211 if (result == GST_FLOW_EOS) {
3212 data = gst_queue2_dequeue_on_eos (queue, &item_type);
3215 /* Since we will still accept EOS and SEGMENT we return _FLOW_OK
3216 * to the caller so that the task function does not shut down */
3217 result = GST_FLOW_OK;
3219 } else if (item_type == GST_QUEUE2_ITEM_TYPE_QUERY) {
3220 GstQuery *query = GST_QUERY_CAST (data);
3222 GST_LOG_OBJECT (queue->srcpad, "Peering query %p", query);
3223 queue->last_handled_query = query;
3224 queue->last_query = gst_pad_peer_query (queue->srcpad, query);
3225 GST_LOG_OBJECT (queue->srcpad, "Peered query");
3226 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3227 "did query %p, return %d", query, queue->last_query);
3228 g_cond_signal (&queue->query_handled);
3229 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3230 result = GST_FLOW_OK;
3237 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3238 "exit because we have no item in the queue");
3239 return GST_FLOW_ERROR;
3243 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we are %s",
3244 gst_flow_get_name (queue->srcresult));
3245 return queue->srcresult;
3249 /* called repeatedly with @pad as the source pad. This function should push out
3250 * data to the peer element. */
3252 gst_queue2_loop (GstPad * pad)
3255 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
3256 GstFlowReturn ret = GST_FLOW_OK;
3261 queue = GST_QUEUE2 (GST_PAD_PARENT (pad));
3263 /* have to lock for thread-safety */
3264 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3266 if (gst_queue2_is_empty (queue)) {
3269 /* pause the timer while we wait. The fact that we are waiting does not mean
3270 * the byterate on the output pad is lower */
3271 if ((started = queue->out_timer_started))
3272 g_timer_stop (queue->out_timer);
3274 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue,
3275 "queue is empty, waiting for new data");
3277 /* Wait for data to be available, we could be unlocked because of a flush. */
3278 GST_QUEUE2_WAIT_ADD_CHECK (queue, queue->srcresult, out_flushing);
3280 while (gst_queue2_is_empty (queue));
3282 /* and continue if we were running before */
3284 g_timer_continue (queue->out_timer);
3286 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
3287 /* if buffering mode is GST_BUFFERING_LIVE, it is rtsp streaming */
3288 if (!((queue->mode == GST_BUFFERING_LIVE) && queue->is_buffering)) {
3289 ret = gst_queue2_push_one (queue);
3292 ret = gst_queue2_push_one (queue);
3294 queue->srcresult = ret;
3295 queue->sinkresult = ret;
3296 if (ret != GST_FLOW_OK)
3299 GST_QUEUE2_MUTEX_UNLOCK (queue);
3300 gst_queue2_post_buffering (queue);
3307 gboolean eos = queue->is_eos;
3308 GstFlowReturn ret = queue->srcresult;
3310 gst_pad_pause_task (queue->srcpad);
3311 if (ret == GST_FLOW_FLUSHING) {
3312 gst_queue2_locked_flush (queue, FALSE, FALSE);
3314 GST_QUEUE2_SIGNAL_DEL (queue);
3315 queue->last_query = FALSE;
3316 g_cond_signal (&queue->query_handled);
3318 GST_QUEUE2_MUTEX_UNLOCK (queue);
3319 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
3320 "pause task, reason: %s", gst_flow_get_name (queue->srcresult));
3321 /* Recalculate buffering levels before stopping since the source flow
3322 * might cause a different buffering level (like NOT_LINKED making
3323 * the queue appear as full) */
3324 if (queue->use_buffering)
3325 update_buffering (queue);
3326 gst_queue2_post_buffering (queue);
3327 /* let app know about us giving up if upstream is not expected to do so */
3328 /* EOS is already taken care of elsewhere */
3329 if (eos && (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS)) {
3330 GST_ELEMENT_FLOW_ERROR (queue, ret);
3331 gst_pad_push_event (queue->srcpad, gst_event_new_eos ());
3338 gst_queue2_handle_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
3340 gboolean res = TRUE;
3341 GstQueue2 *queue = GST_QUEUE2 (parent);
3343 #ifndef GST_DISABLE_GST_DEBUG
3344 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "got event %p (%s)",
3345 event, GST_EVENT_TYPE_NAME (event));
3348 switch (GST_EVENT_TYPE (event)) {
3349 case GST_EVENT_FLUSH_START:
3350 if (QUEUE_IS_USING_QUEUE (queue)) {
3351 /* just forward upstream */
3352 res = gst_pad_push_event (queue->sinkpad, event);
3354 /* now unblock the getrange function */
3355 GST_QUEUE2_MUTEX_LOCK (queue);
3356 GST_DEBUG_OBJECT (queue, "flushing");
3357 queue->srcresult = GST_FLOW_FLUSHING;
3358 GST_QUEUE2_SIGNAL_ADD (queue);
3359 GST_QUEUE2_MUTEX_UNLOCK (queue);
3361 /* when using a temp file, we eat the event */
3363 gst_event_unref (event);
3366 case GST_EVENT_FLUSH_STOP:
3367 if (QUEUE_IS_USING_QUEUE (queue)) {
3368 /* just forward upstream */
3369 res = gst_pad_push_event (queue->sinkpad, event);
3371 /* now unblock the getrange function */
3372 GST_QUEUE2_MUTEX_LOCK (queue);
3373 queue->srcresult = GST_FLOW_OK;
3374 GST_QUEUE2_MUTEX_UNLOCK (queue);
3376 /* when using a temp file, we eat the event */
3378 gst_event_unref (event);
3381 case GST_EVENT_RECONFIGURE:
3382 GST_QUEUE2_MUTEX_LOCK (queue);
3383 /* assume downstream is linked now and try to push again */
3384 if (queue->srcresult == GST_FLOW_NOT_LINKED) {
3385 /* Mark the pad as needing reconfiguration, and
3386 * the loop will re-query downstream bitrate
3388 gst_pad_mark_reconfigure (pad);
3389 queue->srcresult = GST_FLOW_OK;
3390 queue->sinkresult = GST_FLOW_OK;
3391 if (GST_PAD_MODE (pad) == GST_PAD_MODE_PUSH) {
3392 gst_pad_start_task (pad, (GstTaskFunction) gst_queue2_loop, pad,
3397 GST_QUEUE2_MUTEX_UNLOCK (queue);
3399 res = gst_pad_push_event (queue->sinkpad, event);
3402 res = gst_pad_push_event (queue->sinkpad, event);
3410 gst_queue2_handle_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
3414 queue = GST_QUEUE2 (parent);
3416 switch (GST_QUERY_TYPE (query)) {
3417 case GST_QUERY_POSITION:
3422 if (!gst_pad_peer_query (queue->sinkpad, query))
3425 /* get peer position */
3426 gst_query_parse_position (query, &format, &peer_pos);
3428 /* FIXME: this code assumes that there's no discont in the queue */
3430 case GST_FORMAT_BYTES:
3431 peer_pos -= queue->cur_level.bytes;
3432 if (peer_pos < 0) /* Clamp result to 0 */
3435 case GST_FORMAT_TIME:
3436 peer_pos -= queue->cur_level.time;
3437 if (peer_pos < 0) /* Clamp result to 0 */
3441 GST_WARNING_OBJECT (queue, "dropping query in %s format, don't "
3442 "know how to adjust value", gst_format_get_name (format));
3445 /* set updated position */
3446 gst_query_set_position (query, format, peer_pos);
3449 case GST_QUERY_DURATION:
3451 GST_DEBUG_OBJECT (queue, "doing peer query");
3453 if (!gst_pad_peer_query (queue->sinkpad, query))
3456 GST_DEBUG_OBJECT (queue, "peer query success");
3459 case GST_QUERY_BUFFERING:
3462 gboolean is_buffering;
3463 GstBufferingMode mode;
3464 gint avg_in, avg_out;
3465 gint64 buffering_left;
3467 GST_DEBUG_OBJECT (queue, "query buffering");
3469 get_buffering_level (queue, &is_buffering, &percent);
3470 percent = convert_to_buffering_percent (queue, percent);
3471 gst_query_set_buffering_percent (query, is_buffering, percent);
3473 get_buffering_stats (queue, percent, &mode, &avg_in, &avg_out,
3475 gst_query_set_buffering_stats (query, mode, avg_in, avg_out,
3478 if (!QUEUE_IS_USING_QUEUE (queue)) {
3479 /* add ranges for download and ringbuffer buffering */
3481 gint64 start, stop, range_start, range_stop;
3482 guint64 writing_pos;
3483 gint64 estimated_total;
3485 gboolean peer_res, is_eos;
3486 GstQueue2Range *queued_ranges;
3488 /* we need a current download region */
3489 if (queue->current == NULL)
3492 writing_pos = queue->current->writing_pos;
3493 is_eos = queue->is_eos;
3496 /* we're EOS, we know the duration in bytes now */
3498 duration = writing_pos;
3500 /* get duration of upstream in bytes */
3501 peer_res = gst_pad_peer_query_duration (queue->sinkpad,
3502 GST_FORMAT_BYTES, &duration);
3505 GST_DEBUG_OBJECT (queue, "percent %d, duration %" G_GINT64_FORMAT
3506 ", writing %" G_GINT64_FORMAT, percent, duration, writing_pos);
3508 /* calculate remaining and total download time */
3509 if (peer_res && avg_in > 0.0)
3510 estimated_total = ((duration - writing_pos) * 1000) / avg_in;
3512 estimated_total = -1;
3514 GST_DEBUG_OBJECT (queue, "estimated-total %" G_GINT64_FORMAT,
3517 gst_query_parse_buffering_range (query, &format, NULL, NULL, NULL);
3520 case GST_FORMAT_PERCENT:
3521 /* we need duration */
3526 /* get our available data relative to the duration */
3529 gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX, writing_pos,
3534 case GST_FORMAT_BYTES:
3544 /* fill out the buffered ranges */
3545 for (queued_ranges = queue->ranges; queued_ranges;
3546 queued_ranges = queued_ranges->next) {
3548 case GST_FORMAT_PERCENT:
3549 if (duration == -1) {
3554 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
3556 gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX,
3557 queued_ranges->reading_pos, duration);
3560 gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX,
3561 queued_ranges->offset, duration);
3564 gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX,
3565 queued_ranges->writing_pos, duration);
3567 case GST_FORMAT_BYTES:
3568 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
3569 range_start = queued_ranges->reading_pos;
3571 range_start = queued_ranges->offset;
3573 range_stop = queued_ranges->writing_pos;
3580 if (range_start == range_stop)
3582 GST_DEBUG_OBJECT (queue,
3583 "range starting at %" G_GINT64_FORMAT " and finishing at %"
3584 G_GINT64_FORMAT, range_start, range_stop);
3585 gst_query_add_buffering_range (query, range_start, range_stop);
3588 gst_query_set_buffering_range (query, format, start, stop,
3593 case GST_QUERY_SCHEDULING:
3596 GstSchedulingFlags flags = 0;
3599 upstream = gst_query_new_scheduling ();
3600 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
3601 if (!(QUEUE_IS_USING_QUEUE (queue)) && !gst_pad_peer_query (queue->sinkpad, upstream)) {
3603 if (!gst_pad_peer_query (queue->sinkpad, upstream)) {
3605 gst_query_unref (upstream);
3609 gst_query_parse_scheduling (upstream, &flags, NULL, NULL, NULL);
3610 gst_query_unref (upstream);
3612 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
3613 if (!(flags & GST_SCHEDULING_FLAG_SEEKABLE)) {
3614 GST_DEBUG_OBJECT(queue, "peer can support only push mode");
3615 gst_query_set_scheduling (query, flags, 0, -1, 0);
3616 gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH);
3620 GST_DEBUG_OBJECT(queue, "peer can support pull mode");
3622 /* we can operate in pull mode when we are using a tempfile */
3623 pull_mode = !QUEUE_IS_USING_QUEUE (queue);
3626 flags |= GST_SCHEDULING_FLAG_SEEKABLE;
3627 gst_query_set_scheduling (query, flags, 0, -1, 0);
3629 gst_query_add_scheduling_mode (query, GST_PAD_MODE_PULL);
3630 gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH);
3634 /* peer handled other queries */
3635 if (!gst_pad_query_default (pad, parent, query))
3645 GST_DEBUG_OBJECT (queue, "failed peer query");
3651 gst_queue2_handle_query (GstElement * element, GstQuery * query)
3653 GstQueue2 *queue = GST_QUEUE2 (element);
3655 /* simply forward to the srcpad query function */
3656 return gst_queue2_handle_src_query (queue->srcpad, GST_OBJECT_CAST (element),
3661 gst_queue2_update_upstream_size (GstQueue2 * queue)
3663 gint64 upstream_size = -1;
3665 if (gst_pad_peer_query_duration (queue->sinkpad, GST_FORMAT_BYTES,
3667 GST_INFO_OBJECT (queue, "upstream size: %" G_GINT64_FORMAT, upstream_size);
3669 /* upstream_size can be negative but queue->upstream_size is unsigned.
3670 * Prevent setting negative values to it (the query can return -1) */
3671 if (upstream_size >= 0)
3672 queue->upstream_size = upstream_size;
3674 queue->upstream_size = 0;
3678 static GstFlowReturn
3679 gst_queue2_get_range (GstPad * pad, GstObject * parent, guint64 offset,
3680 guint length, GstBuffer ** buffer)
3685 queue = GST_QUEUE2_CAST (parent);
3687 length = (length == -1) ? DEFAULT_BUFFER_SIZE : length;
3688 GST_QUEUE2_MUTEX_LOCK_CHECK (queue, queue->srcresult, out_flushing);
3689 offset = (offset == -1) ? queue->current->reading_pos : offset;
3691 GST_DEBUG_OBJECT (queue,
3692 "Getting range: offset %" G_GUINT64_FORMAT ", length %u", offset, length);
3694 /* catch any reads beyond the size of the file here to make sure queue2
3695 * doesn't send seek events beyond the size of the file upstream, since
3696 * that would confuse elements such as souphttpsrc and/or http servers.
3697 * Demuxers often just loop until EOS at the end of the file to figure out
3698 * when they've read all the end-headers or index chunks. */
3699 if (G_UNLIKELY (offset >= queue->upstream_size)) {
3700 gst_queue2_update_upstream_size (queue);
3701 if (queue->upstream_size > 0 && offset >= queue->upstream_size)
3702 goto out_unexpected;
3705 if (G_UNLIKELY (offset + length > queue->upstream_size)) {
3706 gst_queue2_update_upstream_size (queue);
3707 if (queue->upstream_size > 0 && offset + length >= queue->upstream_size) {
3708 length = queue->upstream_size - offset;
3709 GST_DEBUG_OBJECT (queue, "adjusting length downto %d", length);
3713 /* FIXME - function will block when the range is not yet available */
3714 ret = gst_queue2_create_read (queue, offset, length, buffer);
3715 GST_QUEUE2_MUTEX_UNLOCK (queue);
3716 gst_queue2_post_buffering (queue);
3723 ret = queue->srcresult;
3725 GST_DEBUG_OBJECT (queue, "we are %s", gst_flow_get_name (ret));
3726 GST_QUEUE2_MUTEX_UNLOCK (queue);
3731 GST_DEBUG_OBJECT (queue, "read beyond end of file");
3732 GST_QUEUE2_MUTEX_UNLOCK (queue);
3733 return GST_FLOW_EOS;
3737 /* sink currently only operates in push mode */
3739 gst_queue2_sink_activate_mode (GstPad * pad, GstObject * parent,
3740 GstPadMode mode, gboolean active)
3745 queue = GST_QUEUE2 (parent);
3748 case GST_PAD_MODE_PUSH:
3750 GST_QUEUE2_MUTEX_LOCK (queue);
3751 GST_DEBUG_OBJECT (queue, "activating push mode");
3752 queue->srcresult = GST_FLOW_OK;
3753 queue->sinkresult = GST_FLOW_OK;
3754 queue->is_eos = FALSE;
3755 queue->unexpected = FALSE;
3756 reset_rate_timer (queue);
3757 GST_QUEUE2_MUTEX_UNLOCK (queue);
3759 /* unblock chain function */
3760 GST_QUEUE2_MUTEX_LOCK (queue);
3761 GST_DEBUG_OBJECT (queue, "deactivating push mode");
3762 queue->srcresult = GST_FLOW_FLUSHING;
3763 queue->sinkresult = GST_FLOW_FLUSHING;
3764 GST_QUEUE2_SIGNAL_DEL (queue);
3765 GST_QUEUE2_MUTEX_UNLOCK (queue);
3767 /* wait until it is unblocked and clean up */
3768 GST_PAD_STREAM_LOCK (pad);
3769 GST_QUEUE2_MUTEX_LOCK (queue);
3770 gst_queue2_locked_flush (queue, TRUE, FALSE);
3771 GST_QUEUE2_MUTEX_UNLOCK (queue);
3772 GST_PAD_STREAM_UNLOCK (pad);
3783 /* src operating in push mode, we start a task on the source pad that pushes out
3784 * buffers from the queue */
3786 gst_queue2_src_activate_push (GstPad * pad, GstObject * parent, gboolean active)
3788 gboolean result = FALSE;
3791 queue = GST_QUEUE2 (parent);
3794 GST_QUEUE2_MUTEX_LOCK (queue);
3795 GST_DEBUG_OBJECT (queue, "activating push mode");
3796 queue->srcresult = GST_FLOW_OK;
3797 queue->sinkresult = GST_FLOW_OK;
3798 queue->is_eos = FALSE;
3799 queue->unexpected = FALSE;
3801 gst_pad_start_task (pad, (GstTaskFunction) gst_queue2_loop, pad, NULL);
3802 GST_QUEUE2_MUTEX_UNLOCK (queue);
3804 /* unblock loop function */
3805 GST_QUEUE2_MUTEX_LOCK (queue);
3806 GST_DEBUG_OBJECT (queue, "deactivating push mode");
3807 queue->srcresult = GST_FLOW_FLUSHING;
3808 queue->sinkresult = GST_FLOW_FLUSHING;
3809 /* the item add signal will unblock */
3810 GST_QUEUE2_SIGNAL_ADD (queue);
3811 GST_QUEUE2_MUTEX_UNLOCK (queue);
3813 /* step 2, make sure streaming finishes */
3814 result = gst_pad_stop_task (pad);
3816 GST_QUEUE2_MUTEX_LOCK (queue);
3817 gst_queue2_locked_flush (queue, FALSE, FALSE);
3818 GST_QUEUE2_MUTEX_UNLOCK (queue);
3824 /* pull mode, downstream will call our getrange function */
3826 gst_queue2_src_activate_pull (GstPad * pad, GstObject * parent, gboolean active)
3831 queue = GST_QUEUE2 (parent);
3834 GST_QUEUE2_MUTEX_LOCK (queue);
3835 if (!QUEUE_IS_USING_QUEUE (queue)) {
3836 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
3837 /* open the temp file now */
3838 result = gst_queue2_open_temp_location_file (queue);
3839 } else if (!queue->ring_buffer) {
3840 queue->ring_buffer = g_malloc (queue->ring_buffer_max_size);
3841 result = ! !queue->ring_buffer;
3846 GST_DEBUG_OBJECT (queue, "activating pull mode");
3847 init_ranges (queue);
3848 queue->srcresult = GST_FLOW_OK;
3849 queue->sinkresult = GST_FLOW_OK;
3850 queue->is_eos = FALSE;
3851 queue->unexpected = FALSE;
3852 queue->upstream_size = 0;
3854 GST_DEBUG_OBJECT (queue, "no temp file, cannot activate pull mode");
3855 /* this is not allowed, we cannot operate in pull mode without a temp
3857 queue->srcresult = GST_FLOW_FLUSHING;
3858 queue->sinkresult = GST_FLOW_FLUSHING;
3861 GST_QUEUE2_MUTEX_UNLOCK (queue);
3863 GST_QUEUE2_MUTEX_LOCK (queue);
3864 GST_DEBUG_OBJECT (queue, "deactivating pull mode");
3865 queue->srcresult = GST_FLOW_FLUSHING;
3866 queue->sinkresult = GST_FLOW_FLUSHING;
3867 /* this will unlock getrange */
3868 GST_QUEUE2_SIGNAL_ADD (queue);
3870 GST_QUEUE2_MUTEX_UNLOCK (queue);
3877 gst_queue2_src_activate_mode (GstPad * pad, GstObject * parent, GstPadMode mode,
3883 case GST_PAD_MODE_PULL:
3884 res = gst_queue2_src_activate_pull (pad, parent, active);
3886 case GST_PAD_MODE_PUSH:
3887 res = gst_queue2_src_activate_push (pad, parent, active);
3890 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
3897 static GstStateChangeReturn
3898 gst_queue2_change_state (GstElement * element, GstStateChange transition)
3901 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
3903 queue = GST_QUEUE2 (element);
3905 switch (transition) {
3906 case GST_STATE_CHANGE_NULL_TO_READY:
3908 case GST_STATE_CHANGE_READY_TO_PAUSED:
3909 GST_QUEUE2_MUTEX_LOCK (queue);
3910 if (!QUEUE_IS_USING_QUEUE (queue)) {
3911 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
3912 if (!gst_queue2_open_temp_location_file (queue))
3913 ret = GST_STATE_CHANGE_FAILURE;
3915 if (queue->ring_buffer) {
3916 g_free (queue->ring_buffer);
3917 queue->ring_buffer = NULL;
3919 if (!(queue->ring_buffer = g_malloc (queue->ring_buffer_max_size)))
3920 ret = GST_STATE_CHANGE_FAILURE;
3922 init_ranges (queue);
3924 queue->segment_event_received = FALSE;
3925 queue->starting_segment = NULL;
3926 gst_event_replace (&queue->stream_start_event, NULL);
3927 GST_QUEUE2_MUTEX_UNLOCK (queue);
3929 /* Mark the srcpad as reconfigured to trigger querying
3930 * the downstream bitrate next time it tries to push */
3931 gst_pad_mark_reconfigure (queue->srcpad);
3933 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
3934 #ifdef TIZEN_FEATURE_QUEUE2_MODIFICATION
3935 GST_QUEUE2_MUTEX_LOCK (queue);
3936 queue->is_buffering = FALSE;
3937 GST_QUEUE2_MUTEX_UNLOCK (queue);
3944 if (ret == GST_STATE_CHANGE_FAILURE)
3947 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3949 if (ret == GST_STATE_CHANGE_FAILURE)
3952 switch (transition) {
3953 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3955 case GST_STATE_CHANGE_PAUSED_TO_READY:
3956 GST_QUEUE2_MUTEX_LOCK (queue);
3957 if (!QUEUE_IS_USING_QUEUE (queue)) {
3958 if (QUEUE_IS_USING_TEMP_FILE (queue)) {
3959 gst_queue2_close_temp_location_file (queue);
3960 } else if (queue->ring_buffer) {
3961 g_free (queue->ring_buffer);
3962 queue->ring_buffer = NULL;
3964 clean_ranges (queue);
3966 if (queue->starting_segment != NULL) {
3967 gst_event_unref (queue->starting_segment);
3968 queue->starting_segment = NULL;
3970 gst_event_replace (&queue->stream_start_event, NULL);
3971 GST_QUEUE2_MUTEX_UNLOCK (queue);
3973 case GST_STATE_CHANGE_READY_TO_NULL:
3982 /* changing the capacity of the queue must wake up
3983 * the _chain function, it might have more room now
3984 * to store the buffer/event in the queue */
3985 #define QUEUE_CAPACITY_CHANGE(q) \
3986 GST_QUEUE2_SIGNAL_DEL (queue); \
3987 if (queue->use_buffering) \
3988 update_buffering (queue);
3990 /* Changing the minimum required fill level must
3991 * wake up the _loop function as it might now
3992 * be able to preceed.
3994 #define QUEUE_THRESHOLD_CHANGE(q)\
3995 GST_QUEUE2_SIGNAL_ADD (queue);
3998 gst_queue2_set_temp_template (GstQueue2 * queue, const gchar * template)
4002 /* the element must be stopped in order to do this */
4003 GST_OBJECT_LOCK (queue);
4004 state = GST_STATE (queue);
4005 if (state != GST_STATE_READY && state != GST_STATE_NULL)
4007 GST_OBJECT_UNLOCK (queue);
4009 /* set new location */
4010 g_free (queue->temp_template);
4011 queue->temp_template = g_strdup (template);
4018 GST_WARNING_OBJECT (queue, "setting temp-template property in wrong state");
4019 GST_OBJECT_UNLOCK (queue);
4024 gst_queue2_set_property (GObject * object,
4025 guint prop_id, const GValue * value, GParamSpec * pspec)
4027 GstQueue2 *queue = GST_QUEUE2 (object);
4029 /* someone could change levels here, and since this
4030 * affects the get/put funcs, we need to lock for safety. */
4031 GST_QUEUE2_MUTEX_LOCK (queue);
4034 case PROP_MAX_SIZE_BYTES:
4035 queue->max_level.bytes = g_value_get_uint (value);
4036 QUEUE_CAPACITY_CHANGE (queue);
4038 case PROP_MAX_SIZE_BUFFERS:
4039 queue->max_level.buffers = g_value_get_uint (value);
4040 QUEUE_CAPACITY_CHANGE (queue);
4042 case PROP_MAX_SIZE_TIME:
4043 queue->max_level.time = g_value_get_uint64 (value);
4044 /* set rate_time to the same value. We use an extra field in the level
4045 * structure so that we can easily access and compare it */
4046 queue->max_level.rate_time = queue->max_level.time;
4047 QUEUE_CAPACITY_CHANGE (queue);
4049 case PROP_USE_BUFFERING:
4050 queue->use_buffering = g_value_get_boolean (value);
4051 if (!queue->use_buffering && queue->is_buffering) {
4052 GST_DEBUG_OBJECT (queue, "Disabled buffering while buffering, "
4053 "posting 100%% message");
4054 SET_PERCENT (queue, 100);
4055 queue->is_buffering = FALSE;
4058 if (queue->use_buffering) {
4059 queue->is_buffering = TRUE;
4060 update_buffering (queue);
4063 case PROP_USE_TAGS_BITRATE:
4064 queue->use_tags_bitrate = g_value_get_boolean (value);
4066 case PROP_USE_RATE_ESTIMATE:
4067 queue->use_rate_estimate = g_value_get_boolean (value);
4069 case PROP_LOW_PERCENT:
4070 queue->low_watermark = g_value_get_int (value) * BUF_LEVEL_PERCENT_FACTOR;
4071 if (queue->is_buffering)
4072 update_buffering (queue);
4074 case PROP_HIGH_PERCENT:
4075 queue->high_watermark =
4076 g_value_get_int (value) * BUF_LEVEL_PERCENT_FACTOR;
4077 if (queue->is_buffering)
4078 update_buffering (queue);
4080 case PROP_LOW_WATERMARK:
4081 queue->low_watermark = g_value_get_double (value) * MAX_BUFFERING_LEVEL;
4082 if (queue->is_buffering)
4083 update_buffering (queue);
4085 case PROP_HIGH_WATERMARK:
4086 queue->high_watermark = g_value_get_double (value) * MAX_BUFFERING_LEVEL;
4087 if (queue->is_buffering)
4088 update_buffering (queue);
4090 case PROP_TEMP_TEMPLATE:
4091 gst_queue2_set_temp_template (queue, g_value_get_string (value));
4093 case PROP_TEMP_REMOVE:
4094 queue->temp_remove = g_value_get_boolean (value);
4096 case PROP_RING_BUFFER_MAX_SIZE:
4097 queue->ring_buffer_max_size = g_value_get_uint64 (value);
4099 case PROP_USE_BITRATE_QUERY:
4100 queue->use_bitrate_query = g_value_get_boolean (value);
4102 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
4103 case PROP_BUFFER_MODE:
4104 queue->mode = g_value_get_enum (value);
4108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4112 GST_QUEUE2_MUTEX_UNLOCK (queue);
4113 gst_queue2_post_buffering (queue);
4117 gst_queue2_get_property (GObject * object,
4118 guint prop_id, GValue * value, GParamSpec * pspec)
4120 GstQueue2 *queue = GST_QUEUE2 (object);
4122 GST_QUEUE2_MUTEX_LOCK (queue);
4125 case PROP_CUR_LEVEL_BYTES:
4126 g_value_set_uint (value, queue->cur_level.bytes);
4128 case PROP_CUR_LEVEL_BUFFERS:
4129 g_value_set_uint (value, queue->cur_level.buffers);
4131 case PROP_CUR_LEVEL_TIME:
4132 g_value_set_uint64 (value, queue->cur_level.time);
4134 case PROP_MAX_SIZE_BYTES:
4135 g_value_set_uint (value, queue->max_level.bytes);
4137 case PROP_MAX_SIZE_BUFFERS:
4138 g_value_set_uint (value, queue->max_level.buffers);
4140 case PROP_MAX_SIZE_TIME:
4141 g_value_set_uint64 (value, queue->max_level.time);
4143 case PROP_USE_BUFFERING:
4144 g_value_set_boolean (value, queue->use_buffering);
4146 case PROP_USE_TAGS_BITRATE:
4147 g_value_set_boolean (value, queue->use_tags_bitrate);
4149 case PROP_USE_RATE_ESTIMATE:
4150 g_value_set_boolean (value, queue->use_rate_estimate);
4152 case PROP_LOW_PERCENT:
4153 g_value_set_int (value, queue->low_watermark / BUF_LEVEL_PERCENT_FACTOR);
4155 case PROP_HIGH_PERCENT:
4156 g_value_set_int (value, queue->high_watermark / BUF_LEVEL_PERCENT_FACTOR);
4158 case PROP_LOW_WATERMARK:
4159 g_value_set_double (value, queue->low_watermark /
4160 (gdouble) MAX_BUFFERING_LEVEL);
4162 case PROP_HIGH_WATERMARK:
4163 g_value_set_double (value, queue->high_watermark /
4164 (gdouble) MAX_BUFFERING_LEVEL);
4166 case PROP_TEMP_TEMPLATE:
4167 g_value_set_string (value, queue->temp_template);
4169 case PROP_TEMP_LOCATION:
4170 g_value_set_string (value, queue->temp_location);
4172 case PROP_TEMP_REMOVE:
4173 g_value_set_boolean (value, queue->temp_remove);
4175 case PROP_RING_BUFFER_MAX_SIZE:
4176 g_value_set_uint64 (value, queue->ring_buffer_max_size);
4178 case PROP_AVG_IN_RATE:
4180 gdouble in_rate = queue->byte_in_rate;
4182 /* During the first RATE_INTERVAL, byte_in_rate will not have been
4183 * calculated, so calculate it here. */
4184 if (in_rate == 0.0 && queue->bytes_in
4185 && queue->last_update_in_rates_elapsed > 0.0)
4186 in_rate = queue->bytes_in / queue->last_update_in_rates_elapsed;
4188 g_value_set_int64 (value, (gint64) in_rate);
4191 case PROP_USE_BITRATE_QUERY:
4192 g_value_set_boolean (value, queue->use_bitrate_query);
4195 guint64 bitrate = 0;
4196 if (bitrate == 0 && queue->use_tags_bitrate) {
4197 if (queue->sink_tags_bitrate > 0)
4198 bitrate = queue->sink_tags_bitrate;
4199 else if (queue->src_tags_bitrate)
4200 bitrate = queue->src_tags_bitrate;
4202 if (bitrate == 0 && queue->use_bitrate_query) {
4203 bitrate = queue->downstream_bitrate;
4205 g_value_set_uint64 (value, (guint64) bitrate);
4208 #ifdef TIZEN_FEATURE_RTSPSRC_MODIFICATION
4209 case PROP_BUFFER_MODE:
4210 g_value_set_enum (value, queue->mode);
4214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4218 GST_QUEUE2_MUTEX_UNLOCK (queue);