diff mbox

[FFmpeg-devel,v2,2/4] avformat/hls: respect http_persistent only for http playlist urls

Message ID 20171226052301.17509-2-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Karmani Dec. 26, 2017, 5:22 a.m. UTC
From: Aman Gupta <aman@tmm1.net>

Fixes a segfault when reading a live playlist (without end tag) from non-http url (like a file on disk).

Signed-off-by: Aman Gupta <aman@tmm1.net>
---
 libavformat/hls.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

wm4 Dec. 26, 2017, 5:28 a.m. UTC | #1
On Mon, 25 Dec 2017 21:22:59 -0800
Aman Gupta <ffmpeg@tmm1.net> wrote:

> From: Aman Gupta <aman@tmm1.net>
> 
> Fixes a segfault when reading a live playlist (without end tag) from non-http url (like a file on disk).
> 
> Signed-off-by: Aman Gupta <aman@tmm1.net>
> ---
>  libavformat/hls.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 73bf55b791..c30d71a477 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -724,8 +724,9 @@ static int parse_playlist(HLSContext *c, const char *url,
>      struct variant_info variant_info;
>      char tmp_str[MAX_URL_SIZE];
>      struct segment *cur_init_section = NULL;
> +    int is_http = av_strstart(url, "http", NULL);

There got to be a better way to check whether the protocol
implementation is one which works with the http persistent functions. I
can only repeat my suggestion that this should be integrated into
URLContext.

> -    if (!in && c->http_persistent && c->playlist_pb) {
> +    if (!in && is_http && c->http_persistent && c->playlist_pb) {
>          in = c->playlist_pb;
>          ret = open_url_keepalive(c->ctx, &c->playlist_pb, url);
>          if (ret == AVERROR_EXIT) {
> @@ -759,7 +760,7 @@ static int parse_playlist(HLSContext *c, const char *url,
>          if (ret < 0)
>              return ret;
>  
> -        if (c->http_persistent)
> +        if (c->http_persistent && is_http)
>              c->playlist_pb = in;
>          else
>              close_in = 1;
Aman Karmani Dec. 26, 2017, 6:12 a.m. UTC | #2
On Mon, Dec 25, 2017 at 9:28 PM wm4 <nfxjfg@googlemail.com> wrote:

> On Mon, 25 Dec 2017 21:22:59 -0800
> Aman Gupta <ffmpeg@tmm1.net> wrote:
>
> > From: Aman Gupta <aman@tmm1.net>
> >
> > Fixes a segfault when reading a live playlist (without end tag) from
> non-http url (like a file on disk).
> >
> > Signed-off-by: Aman Gupta <aman@tmm1.net>
> > ---
> >  libavformat/hls.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/hls.c b/libavformat/hls.c
> > index 73bf55b791..c30d71a477 100644
> > --- a/libavformat/hls.c
> > +++ b/libavformat/hls.c
> > @@ -724,8 +724,9 @@ static int parse_playlist(HLSContext *c, const char
> *url,
> >      struct variant_info variant_info;
> >      char tmp_str[MAX_URL_SIZE];
> >      struct segment *cur_init_section = NULL;
> > +    int is_http = av_strstart(url, "http", NULL);
>
> There got to be a better way to check whether the protocol
> implementation is one which works with the http persistent functions. I
> can only repeat my suggestion that this should be integrated into
> URLContext.


I could use ffio_geturlcontext() to check if the AVIOContext has a
URLContext, but that implementation seems fragile and I'm not sure if it is
safe to call for non-http protocols.

I don't have a lot of experience with AVIO or URLContext, so if you can
suggest a good API to implement, I'll give it a try.

Aman


>
> > -    if (!in && c->http_persistent && c->playlist_pb) {
> > +    if (!in && is_http && c->http_persistent && c->playlist_pb) {
> >          in = c->playlist_pb;
> >          ret = open_url_keepalive(c->ctx, &c->playlist_pb, url);
> >          if (ret == AVERROR_EXIT) {
> > @@ -759,7 +760,7 @@ static int parse_playlist(HLSContext *c, const char
> *url,
> >          if (ret < 0)
> >              return ret;
> >
> > -        if (c->http_persistent)
> > +        if (c->http_persistent && is_http)
> >              c->playlist_pb = in;
> >          else
> >              close_in = 1;
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 73bf55b791..c30d71a477 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -724,8 +724,9 @@  static int parse_playlist(HLSContext *c, const char *url,
     struct variant_info variant_info;
     char tmp_str[MAX_URL_SIZE];
     struct segment *cur_init_section = NULL;
+    int is_http = av_strstart(url, "http", NULL);
 
-    if (!in && c->http_persistent && c->playlist_pb) {
+    if (!in && is_http && c->http_persistent && c->playlist_pb) {
         in = c->playlist_pb;
         ret = open_url_keepalive(c->ctx, &c->playlist_pb, url);
         if (ret == AVERROR_EXIT) {
@@ -759,7 +760,7 @@  static int parse_playlist(HLSContext *c, const char *url,
         if (ret < 0)
             return ret;
 
-        if (c->http_persistent)
+        if (c->http_persistent && is_http)
             c->playlist_pb = in;
         else
             close_in = 1;