After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 772330 - adaptivedemux: Improve bitrate estimation
adaptivedemux: Improve bitrate estimation
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other All
: Normal blocker
: 1.10.0
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 733959
Blocks:
 
 
Reported: 2016-10-02 08:41 UTC by Edward Hervey
Modified: 2016-10-31 14:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
adaptivedemux: Calculate values before queue2 (6.45 KB, patch)
2016-10-02 08:42 UTC, Edward Hervey
reviewed Details | Review
adaptivedemux: Calculate values before queue2 (6.52 KB, patch)
2016-10-04 06:28 UTC, Edward Hervey
committed Details | Review

Description Edward Hervey 2016-10-02 08:41:57 UTC
+++ This bug was initially created as a clone of Bug #733959 +++
Comment 1 Edward Hervey 2016-10-02 08:42:19 UTC
Created attachment 336753 [details] [review]
adaptivedemux: Calculate values before queue2

In order to calculate the *actual* bitrate for downloading a fragment
we need to take into account the time since we requested the fragment.

Without this, the bitrate calculations (previously reported by queue2)
would be biased since they wouldn't take into account the request latency
(that is the time between the moment we request a specific URI and the
moment we receive the first byte of that request).

Such examples were it would be biased would be high-bandwith but high-latency
networks. If you download 5MB in 500ms, but it takes 200ms to get the first
byte, queue2 would report 80Mbit/s (5Mb in 500ms) , but taking the request
into account it is only 57Mbit/s (5Mb in 700ms).

While this would not cause too much issues if the above fragment represented
a much longer duration (5s of content), it would cause issues with short
ones (say 1s, or when doing keyframe-only requests which are even shorter)
where the code would expect to be able to download up to 80Mbit/s ... whereas
if we take the request time into account it's much lower (and we would
therefore end up doing late requests).

Also calculate the request latency for debugging purposes and further
usage (it could allow us to figure out the maximum request rate for
example).

https://bugzilla.gnome.org/show_bug.cgi?id=733959
Comment 2 Sebastian Dröge (slomo) 2016-10-02 09:00:18 UTC
Review of attachment 336753 [details] [review]:

::: gst-libs/gst/adaptivedemux/gstadaptivedemux.c
@@ +2375,3 @@
+        stream->last_latency =
+            gst_adaptive_demux_get_monotonic_time (stream->demux) -
+            (stream->download_start_time * GST_USECOND);

While it is currently true here that we only receive the SEGMENT event right before the first buffer, this does not seem guaranteed. There's nothing that forbids sending the SEGMENT event right away (or sending multiple ones).

It would probably be better to watch out for the actual first buffer
Comment 3 Edward Hervey 2016-10-03 06:56:45 UTC
(In reply to Sebastian Dröge (slomo) from comment #2)
> Review of attachment 336753 [details] [review] [review]:
> 
> ::: gst-libs/gst/adaptivedemux/gstadaptivedemux.c
> @@ +2375,3 @@
> +        stream->last_latency =
> +            gst_adaptive_demux_get_monotonic_time (stream->demux) -
> +            (stream->download_start_time * GST_USECOND);
> 
> While it is currently true here that we only receive the SEGMENT event right
> before the first buffer, this does not seem guaranteed. There's nothing that
> forbids sending the SEGMENT event right away (or sending multiple ones).
> 
> It would probably be better to watch out for the actual first buffer

True, I could move that to the buffer part (if bytes_downloaded == 0)
Comment 4 Edward Hervey 2016-10-04 06:28:40 UTC
Created attachment 336854 [details] [review]
adaptivedemux: Calculate values before queue2

In order to calculate the *actual* bitrate for downloading a fragment
we need to take into account the time since we requested the fragment.

Without this, the bitrate calculations (previously reported by queue2)
would be biased since they wouldn't take into account the request latency
(that is the time between the moment we request a specific URI and the
moment we receive the first byte of that request).

Such examples were it would be biased would be high-bandwith but high-latency
networks. If you download 5MB in 500ms, but it takes 200ms to get the first
byte, queue2 would report 80Mbit/s (5Mb in 500ms) , but taking the request
into account it is only 57Mbit/s (5Mb in 700ms).

While this would not cause too much issues if the above fragment represented
a much longer duration (5s of content), it would cause issues with short
ones (say 1s, or when doing keyframe-only requests which are even shorter)
where the code would expect to be able to download up to 80Mbit/s ... whereas
if we take the request time into account it's much lower (and we would
therefore end up doing late requests).

Also calculate the request latency for debugging purposes and further
usage (it could allow us to figure out the maximum request rate for
example).

https://bugzilla.gnome.org/show_bug.cgi?id=733959
Comment 5 Sebastian Dröge (slomo) 2016-10-04 11:13:34 UTC
Review of attachment 336854 [details] [review]:

::: gst-libs/gst/adaptivedemux/gstadaptivedemux.c
@@ +2655,3 @@
     stream->uri_handler = uri_handler;
     stream->queue = queue;
+    stream->src_probe_id = src_probe_id;

This seems unused
Comment 6 Thiago Sousa Santos 2016-10-04 12:54:10 UTC
Review of attachment 336854 [details] [review]:

Looks good to me as well.
Comment 7 Edward Hervey 2016-10-08 12:15:33 UTC
commit 4aadf50012cb057422f29644b41fcaa30c1a2dd2
Author: Edward Hervey <edward@centricular.com>
Date:   Sun Oct 2 09:34:51 2016 +0200

    adaptivedemux: Calculate values before queue2
    
    In order to calculate the *actual* bitrate for downloading a fragment
    we need to take into account the time since we requested the fragment.
    
    Without this, the bitrate calculations (previously reported by queue2)
    would be biased since they wouldn't take into account the request latency
    (that is the time between the moment we request a specific URI and the
    moment we receive the first byte of that request).
    
    Such examples were it would be biased would be high-bandwith but high-latency
    networks. If you download 5MB in 500ms, but it takes 200ms to get the first
    byte, queue2 would report 80Mbit/s (5Mb in 500ms) , but taking the request
    into account it is only 57Mbit/s (5Mb in 700ms).
    
    While this would not cause too much issues if the above fragment represented
    a much longer duration (5s of content), it would cause issues with short
    ones (say 1s, or when doing keyframe-only requests which are even shorter)
    where the code would expect to be able to download up to 80Mbit/s ... whereas
    if we take the request time into account it's much lower (and we would
    therefore end up doing late requests).
    
    Also calculate the request latency for debugging purposes and further
    usage (it could allow us to figure out the maximum request rate for
    example).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733959
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772330