[FFmpeg-devel] [PATCH] Allow setting options on URLContexts before opening the connection
Michael Niedermayer
michaelni
Mon Jun 21 11:15:09 CEST 2010
On Mon, Jun 21, 2010 at 11:36:58AM +0300, Martin Storsj? wrote:
> Hi,
>
> This is the first version of the patch series that allows setting options
> on URLContexts before actually opening the connection. This is a followup
> of a thread discussing this on ffmpeg-soc, with the title "[PATCH] rtsp
> tunneling".
>
> The main things taken care of in this patch series are:
> - Add an av_register_protocol2, that takes a size parameter, that allows
> us to extend the URLProtocol struct without breaking binary compatibility
> with external code that registers their own protocol handlers
> - Split url_open into url_alloc and url_connect
> - Add priv_data_size and priv_data_class to URLProtocol, for allowing the
> common code to allocate the priv_data and setting values within it
>
> - Changes to http.c and rtsp.c to take all this into use
>
> // Martin
> allformats.c | 2 +-
> avio.c | 23 ++++++++++++++++++++++-
> avio.h | 9 ++++++++-
> 3 files changed, 31 insertions(+), 3 deletions(-)
> 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
[...]
> 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;
;)
> +}
> +
> +int url_open_protocol (URLContext **puc, struct URLProtocol *up,
> + const char *filename, int flags)
> +{
> + int ret;
> +
> + ret = url_alloc_for_protocol(puc, up, filename, flags);
> + if (ret)
> + goto fail;
> + ret = url_connect(*puc);
> + if (ret)
> + goto fail;
> + return ret;
> + fail:
> + url_close(*puc);
> + *puc = NULL;
> + return ret;
> +}
> +
> +int url_alloc(URLContext **puc, const char *filename, int flags)
> {
> URLProtocol *up;
> const char *p;
> @@ -166,13 +189,28 @@ int url_open(URLContext **puc, const char *filename, int flags)
> up = first_protocol;
> while (up != NULL) {
> if (!strcmp(proto_str, up->name))
> - return url_open_protocol (puc, up, filename, flags);
> + return url_alloc_for_protocol (puc, up, filename, flags);
> up = up->next;
> }
> *puc = NULL;
> return AVERROR(ENOENT);
> }
>
> +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;
[...]
> avio.c | 9 +++++++++
> avio.h | 2 ++
> 2 files changed, 11 insertions(+)
> 38db65a0f0f98c8f799d550ca0a3100c8252c9d5 0003-Add-priv_data_size-to-URLProtocol-to-allow-url_alloc.patch
> From 2cc7467d28953b9d0300a28e3902423f1a1b8fd9 Mon Sep 17 00:00:00 2001
> From: Martin Storsjo <martin at martin.st>
> Date: Sun, 20 Jun 2010 22:22:51 +0300
> Subject: [PATCH 3/6] Add priv_data_size to URLProtocol, to allow url_alloc allocate the priv_data
ok
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Observe your enemies, for they first find out your faults. -- Antisthenes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100621/233140f3/attachment.pgp>
More information about the ffmpeg-devel
mailing list