34 #include <openssl/ssl.h>
35 static int openssl_init;
37 #include <openssl/crypto.h>
40 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
42 if (mode & CRYPTO_LOCK)
47 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
48 static unsigned long openssl_thread_id(
void)
50 return (intptr_t) pthread_self();
56 #include <gnutls/gnutls.h>
57 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
60 GCRY_THREAD_OPTION_PTHREAD_IMPL;
70 SSL_load_error_strings();
72 if (!CRYPTO_get_locking_callback()) {
75 for (i = 0; i < CRYPTO_num_locks(); i++)
77 CRYPTO_set_locking_callback(openssl_lock);
78 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
79 CRYPTO_set_id_callback(openssl_thread_id);
87 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
88 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
89 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
103 if (CRYPTO_get_locking_callback() == openssl_lock) {
105 CRYPTO_set_locking_callback(
NULL);
106 for (i = 0; i < CRYPTO_num_locks(); i++)
114 gnutls_global_deinit();
127 if (!ff_network_inited_globally)
129 "network initialization. Please use "
130 "avformat_network_init(), this will "
131 "become mandatory later.\n");
133 if (WSAStartup(MAKEWORD(1,1), &wsaData))
141 int ev = write ? POLLOUT : POLLIN;
142 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
144 ret = poll(&p, 1, 100);
145 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
158 int err = WSAGetLastError();
164 case WSAEPROTONOSUPPORT:
165 return AVERROR(EPROTONOSUPPORT);
168 case WSAECONNREFUSED:
179 if (addr->sa_family == AF_INET) {
180 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
182 #if HAVE_STRUCT_SOCKADDR_IN6
183 if (addr->sa_family == AF_INET6) {
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int avpriv_unlock_avformat(void)
memory handling functions
void ff_network_close(void)
int ff_network_inited_globally
#define IN6_IS_ADDR_MULTICAST(a)
int ff_network_init(void)
CRITICAL_SECTION pthread_mutex_t
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int pthread_mutex_init(pthread_mutex_t *m, void *attr)
static int pthread_mutex_unlock(pthread_mutex_t *m)
void av_log(void *avcl, int level, const char *fmt,...)
int avpriv_lock_avformat(void)
int ff_is_multicast_address(struct sockaddr *addr)
static int pthread_mutex_destroy(pthread_mutex_t *m)
static int pthread_mutex_lock(pthread_mutex_t *m)
common internal api header.
w32threads to pthreads wrapper
int ff_network_wait_fd(int fd, int write)