Commit 67d4b3f2 authored by Martin Storsjö's avatar Martin Storsjö

Always call ff_network_init/ff_network_close when opening protocols

ff_network_init is a no-op on all platforms except windows, and on
windows the performance penalty is minimal (less than 1 ms in my tests).

Originally committed as revision 22224 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent e5a1c207
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#include "libavcodec/opt.h" #include "libavcodec/opt.h"
#include "os_support.h" #include "os_support.h"
#include "avformat.h" #include "avformat.h"
#if CONFIG_NETWORK
#include "network.h"
#endif
#if LIBAVFORMAT_VERSION_MAJOR >= 53 #if LIBAVFORMAT_VERSION_MAJOR >= 53
/** @name Logging context. */ /** @name Logging context. */
...@@ -76,6 +79,10 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, ...@@ -76,6 +79,10 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
URLContext *uc; URLContext *uc;
int err; int err;
#if CONFIG_NETWORK
if (!ff_network_init())
return AVERROR(EIO);
#endif
uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
if (!uc) { if (!uc) {
err = AVERROR(ENOMEM); err = AVERROR(ENOMEM);
...@@ -93,8 +100,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, ...@@ -93,8 +100,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
err = up->url_open(uc, filename, flags); err = up->url_open(uc, filename, flags);
if (err < 0) { if (err < 0) {
av_free(uc); av_free(uc);
*puc = NULL; goto fail;
return err;
} }
//We must be careful here as url_seek() could be slow, for example for http //We must be careful here as url_seek() could be slow, for example for http
...@@ -106,6 +112,9 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, ...@@ -106,6 +112,9 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
return 0; return 0;
fail: fail:
*puc = NULL; *puc = NULL;
#if CONFIG_NETWORK
ff_network_close();
#endif
return err; return err;
} }
...@@ -204,6 +213,9 @@ int url_close(URLContext *h) ...@@ -204,6 +213,9 @@ int url_close(URLContext *h)
if (h->prot->url_close) if (h->prot->url_close)
ret = h->prot->url_close(h); ret = h->prot->url_close(h);
#if CONFIG_NETWORK
ff_network_close();
#endif
av_free(h); av_free(h);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment