summaryrefslogtreecommitdiff
path: root/libavformat/tls_gnutls.c
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2015-05-27 12:57:51 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-05-27 22:24:00 +0200
commita9f1d584e53fb39d983201585cb136986a85cac8 (patch)
tree894d369cab04efe2e40db0fc67f98d08699aaf93 /libavformat/tls_gnutls.c
parentfbf9583f9f88b24e0cb7c35b253193ae8f35e93d (diff)
downloadffmpeg-a9f1d584e53fb39d983201585cb136986a85cac8.tar.gz
lavf: move TLS-related ifdeffery to library specific files
There is no need to have this mess in network.c. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/tls_gnutls.c')
-rw-r--r--libavformat/tls_gnutls.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index 92a88c164f..b846bc4469 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,8 +129,7 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
TLSShared *c = &p->tls_shared;
int ret;
- if ((ret = ff_tls_init()) < 0)
- return ret;
+ ff_gnutls_init();
if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
goto fail;