[FFmpeg-devel] [PATCH v2 5/5] avformat/hls: add http_multiple option

Aman Gupta aman at tmm1.net
Sun Dec 17 22:59:45 EET 2017


On Sun, Dec 17, 2017 at 12:53 PM Anssi Hannula <anssi.hannula at iki.fi> wrote:

> Hi!
>
> Aman Gupta kirjoitti 2017-12-13 02:35:
> > From: Aman Gupta <aman at tmm1.net>
> >
> > This improves network throughput of the hls demuxer by avoiding
> > the latency introduced by downloading segments one at a time.
> >
> > The problem is particularly noticable over high-latency network
> > connections: for instance, if RTT is 250ms, there will a 250ms idle
> > period between when one segment response is read and the next one
> > starts.
> >
> > The obvious solution to this is to use HTTP pipelining, where a
> > second request can be sent (on the persistent http/1.1 connection)
> > before the first response is fully read. Unfortunately the way the
> > http protocol is implemented in avformat makes implementing pipleining
> > very complex.
> >
> > Instead, this commit simulates pipelining using two separate persistent
> > http connections. This has the advantage of working independently of
> > the http_persistent option, and can be used with http/1.0 servers as
> > well. The pair of connections is swapped every time a new segment
> > starts
> > downloading, and a request for the next segment is sent on the
> > secondary
> > connection right away. This means the second response will be ready and
> > waiting by the time the current response is fully read.
>
> Thanks, seems like an OK idea and the code seems straight-forward.
>
> Why is this a defaults-to-disabled option, instead of defaulting to
> enabled or just not having an option at all?
> I guess there may be a good reason, but I'd like to hear your thoughts
> on that.


I actually had both options enabled by default but changed it before
submitting. There is no good reason to disable by default other than the
fact that it is new code and may still include bugs. However in my testing
it works quite well so I think it is safe to enable by default and let
users disable if they need to for some reason.


>
> > ---
> >  doc/demuxers.texi |  3 +++
> >  libavformat/hls.c | 51
> > ++++++++++++++++++++++++++++++++++++++++++++++++---
> >  2 files changed, 51 insertions(+), 3 deletions(-)
> >
> > diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> > index 18ff7101ac..f2181fbb93 100644
> > --- a/doc/demuxers.texi
> > +++ b/doc/demuxers.texi
> > @@ -319,6 +319,9 @@ Default value is 1000.
> >
> >  @item http_persistent
> >  Use persistent HTTP connections. Applicable only for HTTP streams.
> > +
> > + at item http_multiple
> > +Use multiple HTTP connections for downloading HTTP segments.
> >  @end table
> >
> >  @section image2
> > diff --git a/libavformat/hls.c b/libavformat/hls.c
> > index f75c8f5eaa..487fa9a82f 100644
> > --- a/libavformat/hls.c
> > +++ b/libavformat/hls.c
> [...]
> > @@ -1426,11 +1440,20 @@ reload:
> >          if (ret)
> >              return ret;
> >
> > -        ret = open_input(c, v, seg, &v->input);
> > +        if (c->http_multiple && v->input_next_requested) {
> > +            AVIOContext *tmp = v->input;
> > +            v->input = v->input_next;
> > +            v->input_next = tmp;
>
> Use FFSWAP().


Cool, didn't know about that one. Will switch.


>
> [...]
>
> --
> Anssi Hannula
>


More information about the ffmpeg-devel mailing list