[FFmpeg-devel] [RFC][PATCH 1/2] lavf/avio: Introduce avio_find_protocol

Michael Niedermayer michaelni at gmx.at
Mon Jan 6 00:56:32 CET 2014


On Mon, Jan 06, 2014 at 12:11:10AM +0100, Stefano Sabatini wrote:
> On date Sunday 2014-01-05 03:29:35 +0100, Alexander Strasser encoded:
> > Make it possible to find out what protocol will be chosen
> > for a given URL.
> > 
> > TODO: version bump
> > 
> > Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
> > ---
> >  libavformat/avio.c | 39 +++++++++++++++++++++++++++++----------
> >  libavformat/avio.h |  9 +++++++++
> >  2 files changed, 38 insertions(+), 10 deletions(-)
> > 
> > diff --git a/libavformat/avio.c b/libavformat/avio.c
> > index 225d982..309b854 100644
> > --- a/libavformat/avio.c
> > +++ b/libavformat/avio.c
> > @@ -215,18 +215,12 @@ int ffurl_connect(URLContext *uc, AVDictionary **options)
> >      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                \
> >      "0123456789+-."
> >  
> > -int ffurl_alloc(URLContext **puc, const char *filename, int flags,
> > -                const AVIOInterruptCB *int_cb)
> > +static struct URLProtocol *url_find_protocol(const char *filename)
> >  {
> >      URLProtocol *up = NULL;
> >      char proto_str[128], proto_nested[128], *ptr;
> >      size_t proto_len = strspn(filename, URL_SCHEME_CHARS);
> >  
> > -    if (!first_protocol) {
> > -        av_log(NULL, AV_LOG_WARNING, "No URL Protocols are registered. "
> > -                                     "Missing call to av_register_all()?\n");
> > -    }
> > -
> >      if (filename[proto_len] != ':' &&
> >          (filename[proto_len] != ',' || !strchr(filename + proto_len + 1, ':')) ||
> >          is_dos_path(filename))
> > @@ -243,13 +237,31 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags,
> >  
> >      while (up = ffurl_protocol_next(up)) {
> >          if (!strcmp(proto_str, up->name))
> > -            return url_alloc_for_protocol(puc, up, filename, flags, int_cb);
> > +            break;
> >          if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME &&
> >              !strcmp(proto_nested, up->name))
> > -            return url_alloc_for_protocol(puc, up, filename, flags, int_cb);
> > +            break;
> >      }
> > +
> > +    return up;
> > +}
> > +
> > +int ffurl_alloc(URLContext **puc, const char *filename, int flags,
> > +                const AVIOInterruptCB *int_cb)
> > +{
> > +    URLProtocol *p = NULL;
> > +
> > +    if (!first_protocol) {
> > +        av_log(NULL, AV_LOG_WARNING, "No URL Protocols are registered. "
> > +                                     "Missing call to av_register_all()?\n");
> > +    }
> > +
> > +    p = url_find_protocol(filename);
> > +    if (p)
> > +       return url_alloc_for_protocol(puc, p, filename, flags, int_cb);
> > +
> >      *puc = NULL;
> > -    if (!strcmp("https", proto_str))
> > +    if (av_strstart("https:", filename, NULL))
> >          av_log(NULL, AV_LOG_WARNING, "https protocol not found, recompile with openssl or gnutls enabled.\n");
> >      return AVERROR_PROTOCOL_NOT_FOUND;
> >  }
> > @@ -376,6 +388,13 @@ int ffurl_close(URLContext *h)
> >  }
> >  
> >  
> 
> Nit++: remove superfluous empty line
> 
> > +const char *avio_find_protocol(const char *url)
> > +{
> > +    URLProtocol *p = url_find_protocol(url);
> > +
> > +    return p ? p->name : "";
> > +}
> 
> return p ? p->name : NULL;
> ?
> 
> > +
> >  int avio_check(const char *url, int flags)
> >  {
> >      URLContext *h;
> > diff --git a/libavformat/avio.h b/libavformat/avio.h
> > index 4f4ac3c..737dc40 100644
> > --- a/libavformat/avio.h
> > +++ b/libavformat/avio.h
> > @@ -151,6 +151,15 @@ typedef struct AVIOContext {
> >  /* unbuffered I/O */
> >  
> >  /**
> > + * Return the name of the protocol that will handle the passed URL.
> > + * 
> > + * An empty string is returned if no protocol could be found for the given URL.
> > + *
> > + * @return Name of the protocol or an empty string.
> > + */
> > +const char *avio_find_protocol(const char *url);
> 
> I'd prefer if this would return NULL in case no protocol was
> found, so you can do if (!protocol_str).
> 
> LGTM otherwise (but I'm no avio maintainer).

should be ok

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140106/78d95f93/attachment.asc>


More information about the ffmpeg-devel mailing list