[FFmpeg-devel] [PATCH] Allow setting options on URLContexts before opening the connection

Martin Storsjö martin
Mon Jun 21 11:24:16 CEST 2010


On Mon, 21 Jun 2010, Michael Niedermayer wrote:

> On Mon, Jun 21, 2010 at 11:36:58AM +0300, Martin Storsj? wrote:

> > 83312b536cfd40e0fcb52d15a837741ce7996d21  0001-Add-an-av_register_protocol2-that-takes-a-size-param.patch
> > From 2c775b6cb2ad9b8582f15d8f8c38b4f628adbb0a Mon Sep 17 00:00:00 2001
> > From: Martin Storsjo <martin at martin.st>
> > Date: Mon, 21 Jun 2010 11:05:43 +0300
> > Subject: [PATCH 1/6] Add an av_register_protocol2, that takes a size parameter
> > 
> > This allows extending the URLProtocol struct without breaking binary
> > compatibility with code compiled older definitions of the struct.
> 
> ok unless someone has a better idea

Ok, I'll wait with applying it until the rest of the series is ok'd.

> >  avio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------
> >  avio.h |   19 ++++++++++++++++++
> >  2 files changed, 71 insertions(+), 14 deletions(-)
> > 012993bd97d3377a769a1467854abd62751bc0c4  0002-Split-url_open-and-url_open_protocol-into-url_alloc-.patch
> > From af3919a29e31a1ab172d39aeb9be249ac6c53f29 Mon Sep 17 00:00:00 2001
> > From: Martin Storsjo <martin at martin.st>
> > Date: Sun, 20 Jun 2010 22:13:41 +0300
> > Subject: [PATCH 2/6] Split url_open and url_open_protocol into url_alloc and url_connect
> > 
> > ---
> >  libavformat/avio.c |   66 +++++++++++++++++++++++++++++++++++++++++-----------
> >  libavformat/avio.h |   19 +++++++++++++++
> >  2 files changed, 71 insertions(+), 14 deletions(-)
> > 
> > diff --git a/libavformat/avio.c b/libavformat/avio.c
> > index 3371b40..650bf5b 100644
> > --- a/libavformat/avio.c
> > +++ b/libavformat/avio.c
> > @@ -94,7 +94,7 @@ int register_protocol(URLProtocol *protocol)
> >  }
> >  #endif
> >  
> > -int url_open_protocol (URLContext **puc, struct URLProtocol *up,
> > +static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
> >                         const char *filename, int flags)
> >  {
> >      URLContext *uc;
> > @@ -118,17 +118,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
> >      uc->flags = flags;
> >      uc->is_streamed = 0; /* default = not streamed */
> >      uc->max_packet_size = 0; /* default: stream file */
> > -    err = up->url_open(uc, filename, flags);
> > -    if (err < 0) {
> > -        av_free(uc);
> > -        goto fail;
> > -    }
> >  
> > -    //We must be careful here as url_seek() could be slow, for example for http
> > -    if(   (flags & (URL_WRONLY | URL_RDWR))
> > -       || !strcmp(up->name, "file"))
> > -        if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0)
> > -            uc->is_streamed= 1;
> >      *puc = uc;
> >      return 0;
> >   fail:
> > @@ -139,7 +129,40 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
> >      return err;
> >  }
> >  
> > -int url_open(URLContext **puc, const char *filename, int flags)
> > +int url_connect(URLContext* uc)
> > +{
> > +    int err = uc->prot->url_open(uc, uc->filename, uc->flags);
> > +    if (err)
> > +        goto fail;
> > +    uc->is_connected = 1;
> > +    //We must be careful here as url_seek() could be slow, for example for http
> > +    if(   (uc->flags & (URL_WRONLY | URL_RDWR))
> > +       || !strcmp(uc->prot->name, "file"))
> > +        if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0)
> > +            uc->is_streamed= 1;
> 
> > + fail:
> > +    return err;
> 
> fail:
>     goto really_fail;
> really_fail:
>     goto i_will_reall_ret_ret_now;
> i_will_reall_ret_ret_now:
>     return ret;
> 
> ;)

Hrm, fixed. :-)
 
> > +int url_open(URLContext **puc, const char *filename, int flags)
> > +{
> > +    int ret = url_alloc(puc, filename, flags);
> > +    if (ret)
> > +        return ret;
> > +    ret = url_connect(*puc);
> 
> > +    if (ret)
> > +        goto fail;
> > +    return ret;
> > + fail:
> 
> if(!ret)
>     return 0;

Fixed

Updated version of part 2 attached.

Thanks for the very quick review!

// Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Split-url_open-and-url_open_protocol-into-url_alloc-.patch
Type: text/x-diff
Size: 5134 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100621/169cb502/attachment.patch>



More information about the ffmpeg-devel mailing list