changeset 5754:65b77d0674d0 libavformat

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).
author mstorsjo
date Fri, 05 Mar 2010 22:30:21 +0000
parents 2e5aecabfb1e
children dbc61b2840eb
files avio.c
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/avio.c	Fri Mar 05 17:26:34 2010 +0000
+++ b/avio.c	Fri Mar 05 22:30:21 2010 +0000
@@ -26,6 +26,9 @@
 #include "libavcodec/opt.h"
 #include "os_support.h"
 #include "avformat.h"
+#if CONFIG_NETWORK
+#include "network.h"
+#endif
 
 #if LIBAVFORMAT_VERSION_MAJOR >= 53
 /** @name Logging context. */
@@ -76,6 +79,10 @@
     URLContext *uc;
     int err;
 
+#if CONFIG_NETWORK
+    if (!ff_network_init())
+        return AVERROR(EIO);
+#endif
     uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
     if (!uc) {
         err = AVERROR(ENOMEM);
@@ -93,8 +100,7 @@
     err = up->url_open(uc, filename, flags);
     if (err < 0) {
         av_free(uc);
-        *puc = NULL;
-        return err;
+        goto fail;
     }
 
     //We must be careful here as url_seek() could be slow, for example for http
@@ -106,6 +112,9 @@
     return 0;
  fail:
     *puc = NULL;
+#if CONFIG_NETWORK
+    ff_network_close();
+#endif
     return err;
 }
 
@@ -204,6 +213,9 @@
 
     if (h->prot->url_close)
         ret = h->prot->url_close(h);
+#if CONFIG_NETWORK
+    ff_network_close();
+#endif
     av_free(h);
     return ret;
 }