queues: Don't return negative position queries.

When subtracting queued data sizes from upstream queries
in queue, queue2, downloadbuffer and typefind, clamp the
result to not go negative, in case upstream returned
a nonsense value that's too small (as could happen if
upstream is estimating, or just broken)
This commit is contained in:
Jan Schmidt 2016-11-15 22:39:43 +11:00
parent 075744a894
commit a6ca8dfb42
4 changed files with 14 additions and 0 deletions

View file

@ -1434,9 +1434,13 @@ gst_download_buffer_handle_src_query (GstPad * pad, GstObject * parent,
switch (format) {
case GST_FORMAT_BYTES:
peer_pos -= dlbuf->cur_level.bytes;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
case GST_FORMAT_TIME:
peer_pos -= dlbuf->cur_level.time;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
default:
GST_WARNING_OBJECT (dlbuf, "dropping query in %s format, don't "

View file

@ -1606,9 +1606,13 @@ gst_queue_handle_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
switch (format) {
case GST_FORMAT_BYTES:
peer_pos -= queue->cur_level.bytes;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
case GST_FORMAT_TIME:
peer_pos -= queue->cur_level.time;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
default:
GST_DEBUG_OBJECT (queue, "Can't adjust query in %s format, don't "

View file

@ -3155,9 +3155,13 @@ gst_queue2_handle_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
switch (format) {
case GST_FORMAT_BYTES:
peer_pos -= queue->cur_level.bytes;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
case GST_FORMAT_TIME:
peer_pos -= queue->cur_level.time;
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
default:
GST_WARNING_OBJECT (queue, "dropping query in %s format, don't "

View file

@ -450,6 +450,8 @@ gst_type_find_handle_src_query (GstPad * pad, GstObject * parent,
switch (format) {
case GST_FORMAT_BYTES:
peer_pos -= gst_adapter_available (typefind->adapter);
if (peer_pos < 0) /* Clamp result to 0 */
peer_pos = 0;
break;
default:
/* FIXME */