adaptivedemux: Handle invalid HTTP duration

The default BYTE DURATION basesrc query handler will return `-1` and TRUE. In
order to properly handle cases where upstream http servers didn't return a valid
Content-Length we also need to check whether it was valid when calculating
bitrates.

Avoids returning completely bogus bitrates with gogol's video streaming services

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1544>
This commit is contained in:
Edward Hervey 2020-08-27 11:18:56 +02:00 committed by Edward Hervey
parent d1d2acead1
commit 298eedad8b

View file

@ -2662,11 +2662,11 @@ _src_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
if (stream->fragment.bitrate == 0 &&
stream->fragment.duration != 0 &&
gst_element_query_duration (stream->uri_handler, GST_FORMAT_BYTES,
&chunk_size)) {
&chunk_size) && chunk_size != -1) {
guint bitrate = MIN (G_MAXUINT, gst_util_uint64_scale (chunk_size,
8 * GST_SECOND, stream->fragment.duration));
GST_LOG_OBJECT (demux,
"Fragment has size %" G_GUINT64_FORMAT " duration %" GST_TIME_FORMAT
"Fragment has size %" G_GINT64_FORMAT " duration %" GST_TIME_FORMAT
" = bitrate %u", chunk_size,
GST_TIME_ARGS (stream->fragment.duration), bitrate);
stream->fragment.bitrate = bitrate;