queue2: add more info in the buffering query

Add the estimated download time and estimated time left to the buffering query
results along with the estimated download and playback speed.
This commit is contained in:
Wim Taymans 2010-03-24 19:02:12 +01:00
parent 11304c1257
commit f9c6a0886e

View file

@ -1942,23 +1942,43 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
} else { } else {
gint64 start, stop; gint64 start, stop;
guint64 writing_pos; guint64 writing_pos;
gint64 estimated_total, buffering_left;
GstFormat peer_fmt;
gint64 duration;
gboolean peer_res, is_buffering;
gdouble byte_in_rate, byte_out_rate;
/* we need a current download region */
if (queue->current == NULL)
return FALSE;
writing_pos = queue->current->writing_pos;
byte_in_rate = queue->byte_in_rate;
byte_out_rate = queue->byte_out_rate;
is_buffering = queue->is_buffering;
/* get duration of upstream in bytes */
peer_fmt = GST_FORMAT_BYTES;
peer_res = gst_pad_query_peer_duration (queue->sinkpad, &peer_fmt,
&duration);
/* calculate remaining and total download time */
if (peer_res && byte_in_rate > 0.0) {
estimated_total = (duration * 1000) / byte_in_rate;
buffering_left = ((duration - writing_pos) * 1000) / byte_in_rate;
} else {
estimated_total = -1;
buffering_left = -1;
}
gst_query_parse_buffering_range (query, &format, NULL, NULL, NULL); gst_query_parse_buffering_range (query, &format, NULL, NULL, NULL);
switch (format) { switch (format) {
case GST_FORMAT_PERCENT: case GST_FORMAT_PERCENT:
{ /* we need duration */
gint64 duration; if (!peer_res)
GstFormat peer_fmt;
peer_fmt = GST_FORMAT_BYTES;
if (!gst_pad_query_peer_duration (queue->sinkpad, &peer_fmt,
&duration))
goto peer_failed; goto peer_failed;
writing_pos = queue->current->writing_pos;
GST_DEBUG_OBJECT (queue, "duration %" G_GINT64_FORMAT ", writing %" GST_DEBUG_OBJECT (queue, "duration %" G_GINT64_FORMAT ", writing %"
G_GINT64_FORMAT, duration, writing_pos); G_GINT64_FORMAT, duration, writing_pos);
@ -1969,18 +1989,21 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
else else
stop = -1; stop = -1;
break; break;
}
case GST_FORMAT_BYTES: case GST_FORMAT_BYTES:
start = 0; start = 0;
stop = queue->current->writing_pos; stop = writing_pos;
break; break;
default: default:
start = -1; start = -1;
stop = -1; stop = -1;
break; break;
} }
gst_query_set_buffering_percent (query, queue->is_buffering, 100); /* FIXME, percent buffering is not right */
gst_query_set_buffering_range (query, format, start, stop, -1); gst_query_set_buffering_percent (query, is_buffering, 100);
gst_query_set_buffering_range (query, format, start, stop,
estimated_total);
gst_query_set_buffering_stats (query, GST_BUFFERING_DOWNLOAD,
byte_in_rate, byte_out_rate, buffering_left);
} }
break; break;
} }