queue2: buffering_ranges query support

Fixes bug 623121
This commit is contained in:
Philippe Normand 2010-08-31 11:37:42 +02:00 committed by Sebastian Dröge
parent 36e1ad94e1
commit 410ca5c164

View file

@ -2444,7 +2444,7 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
goto peer_failed; goto peer_failed;
GST_DEBUG_OBJECT (queue, "buffering forwarded to peer"); GST_DEBUG_OBJECT (queue, "buffering forwarded to peer");
} else { } else {
gint64 start, stop; gint64 start, stop, range_start, range_stop;
guint64 writing_pos; guint64 writing_pos;
gint percent; gint percent;
gint64 estimated_total, buffering_left; gint64 estimated_total, buffering_left;
@ -2452,6 +2452,7 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
gint64 duration; gint64 duration;
gboolean peer_res, is_buffering, is_eos; gboolean peer_res, is_buffering, is_eos;
gdouble byte_in_rate, byte_out_rate; gdouble byte_in_rate, byte_out_rate;
GstQueue2Range *queued_ranges;
/* we need a current download region */ /* we need a current download region */
if (queue->current == NULL) if (queue->current == NULL)
@ -2514,6 +2515,37 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
stop = -1; stop = -1;
break; break;
} }
/* fill out the buffered ranges */
for (queued_ranges = queue->ranges; queued_ranges;
queued_ranges = queued_ranges->next) {
switch (format) {
case GST_FORMAT_PERCENT:
if (duration == -1) {
range_start = 0;
range_stop = 0;
break;
}
range_start = 100 * queued_ranges->offset / duration;
range_stop = 100 * queued_ranges->writing_pos / duration;
break;
case GST_FORMAT_BYTES:
range_start = queued_ranges->offset;
range_stop = queued_ranges->writing_pos;
break;
default:
range_start = -1;
range_stop = -1;
break;
}
if (range_start == range_stop)
continue;
GST_DEBUG_OBJECT (queue,
"range starting at %" G_GINT64_FORMAT " and finishing at %"
G_GINT64_FORMAT, range_start, range_stop);
gst_query_add_buffering_range (query, range_start, range_stop);
}
gst_query_set_buffering_percent (query, is_buffering, percent); gst_query_set_buffering_percent (query, is_buffering, percent);
gst_query_set_buffering_range (query, format, start, stop, gst_query_set_buffering_range (query, format, start, stop,
estimated_total); estimated_total);
@ -2683,7 +2715,7 @@ gst_queue2_src_activate_pull (GstPad * pad, gboolean active)
result = gst_queue2_open_temp_location_file (queue); result = gst_queue2_open_temp_location_file (queue);
} else if (!queue->ring_buffer) { } else if (!queue->ring_buffer) {
queue->ring_buffer = g_malloc (queue->ring_buffer_max_size); queue->ring_buffer = g_malloc (queue->ring_buffer_max_size);
result = ! !queue->ring_buffer; result = !!queue->ring_buffer;
} else { } else {
result = TRUE; result = TRUE;
} }
@ -2886,7 +2918,7 @@ gst_queue2_set_property (GObject * object,
break; break;
case PROP_RING_BUFFER_MAX_SIZE: case PROP_RING_BUFFER_MAX_SIZE:
queue->ring_buffer_max_size = g_value_get_uint64 (value); queue->ring_buffer_max_size = g_value_get_uint64 (value);
queue->use_ring_buffer = ! !queue->ring_buffer_max_size; queue->use_ring_buffer = !!queue->ring_buffer_max_size;
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);