Mercurial > libavformat.hg
changeset 6160:1b4be334ef89 libavformat
Split url_open and url_open_protocol into url_alloc and url_connect
author | mstorsjo |
---|---|
date | Tue, 22 Jun 2010 14:03:37 +0000 |
parents | 3fcaee5cf416 |
children | f7090c70ed34 |
files | avformat.h avio.c avio.h |
diffstat | 3 files changed, 69 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/avformat.h Tue Jun 22 13:58:48 2010 +0000 +++ b/avformat.h Tue Jun 22 14:03:37 2010 +0000 @@ -22,7 +22,7 @@ #define AVFORMAT_AVFORMAT_H #define LIBAVFORMAT_VERSION_MAJOR 52 -#define LIBAVFORMAT_VERSION_MINOR 69 +#define LIBAVFORMAT_VERSION_MINOR 70 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
--- a/avio.c Tue Jun 22 13:58:48 2010 +0000 +++ b/avio.c Tue Jun 22 14:03:37 2010 +0000 @@ -94,7 +94,7 @@ } #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 @@ 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,38 @@ 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) + return err; + 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; + return 0; +} + +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) + return 0; + 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 +187,27 @@ 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) + return 0; + fail: + url_close(*puc); + *puc = NULL; + return ret; +} + int url_read(URLContext *h, unsigned char *buf, int size) { int ret; @@ -232,7 +267,7 @@ int ret = 0; if (!h) return 0; /* can happen when url_open fails */ - if (h->prot->url_close) + if (h->is_connected && h->prot->url_close) ret = h->prot->url_close(h); #if CONFIG_NETWORK ff_network_close();
--- a/avio.h Tue Jun 22 13:58:48 2010 +0000 +++ b/avio.h Tue Jun 22 14:03:37 2010 +0000 @@ -51,6 +51,7 @@ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ void *priv_data; char *filename; /**< specified URL */ + int is_connected; } URLContext; typedef struct URLPollEntry { @@ -81,6 +82,24 @@ /** * Creates an URLContext for accessing to the resource indicated by + * url, but doesn't initiate the connection yet. + * + * @param puc pointer to the location where, in case of success, the + * function puts the pointer to the created URLContext + * @param flags flags which control how the resource indicated by url + * is to be opened + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ +int url_alloc(URLContext **h, const char *url, int flags); + +/** + * Connect an URLContext that has been allocated by url_alloc + */ +int url_connect(URLContext *h); + +/** + * Creates an URLContext for accessing to the resource indicated by * url, and opens it. * * @param puc pointer to the location where, in case of success, the