lavf: move TLS-related ifdeffery to library specific files
[ffmpeg.git] / libavformat / tls_gnutls.c
index e8037fa..1d3f57c 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <errno.h>
+
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
 #include "os_support.h"
 #include "url.h"
 #include "tls.h"
+#include "libavcodec/internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 
+#if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
+#include <gcrypt.h>
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
+#endif
+
 typedef struct TLSContext {
     const AVClass *class;
     TLSShared tls_shared;
@@ -40,6 +48,24 @@ typedef struct TLSContext {
     int need_shutdown;
 } TLSContext;
 
+void ff_gnutls_init(void)
+{
+    avpriv_lock_avformat();
+#if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
+    if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
+        gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+#endif
+    gnutls_global_init();
+    avpriv_unlock_avformat();
+}
+
+void ff_gnutls_deinit(void)
+{
+    avpriv_lock_avformat();
+    gnutls_global_deinit();
+    avpriv_unlock_avformat();
+}
+
 static int print_tls_error(URLContext *h, int ret)
 {
     switch (ret) {
@@ -67,7 +93,7 @@ static int tls_close(URLContext *h)
         gnutls_certificate_free_credentials(c->cred);
     if (c->tls_shared.tcp)
         ffurl_close(c->tls_shared.tcp);
-    ff_tls_deinit();
+    ff_gnutls_deinit();
     return 0;
 }
 
@@ -103,7 +129,7 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
     TLSShared *c = &p->tls_shared;
     int ret;
 
-    ff_tls_init();
+    ff_gnutls_init();
 
     if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
         goto fail;