summaryrefslogtreecommitdiff
path: root/libavformat/tls_gnutls.c
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2015-05-26 19:25:42 +0200
committerMartin Storsjö <martin@martin.st>2015-05-26 21:48:51 +0300
commit57cde2b180fcec0eaf60aad65f436ab6420546f5 (patch)
tree8f11332b40ddf10dafd3b82a8fd2ac5141466c9f /libavformat/tls_gnutls.c
parentd8ffb2055f0e0fcb5d025bab72eb19c2a886c125 (diff)
lavf: move TLS-related ifdeffery to library specific files
There is no need to have this mess in network.c. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/tls_gnutls.c')
-rw-r--r--libavformat/tls_gnutls.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index e8037fa44e..1d3f57cb35 100644
--- a/libavformat/tls_gnutls.c
+++ b/libavformat/tls_gnutls.c
@@ -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>
@@ -28,10 +30,16 @@
#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;