avformat/tls_openssl: move some functions up in the file

Cosmetic change, reduces differences with libav.
This commit is contained in:
James Almer 2017-11-02 23:26:46 -03:00
parent 90adafe6aa
commit eaa25b09e4
1 changed files with 73 additions and 73 deletions

View File

@ -66,6 +66,79 @@ static unsigned long openssl_thread_id(void)
#endif
#endif
int ff_openssl_init(void)
{
avpriv_lock_avformat();
if (!openssl_init) {
SSL_library_init();
SSL_load_error_strings();
#if HAVE_THREADS
if (!CRYPTO_get_locking_callback()) {
int i;
openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
if (!openssl_mutexes) {
avpriv_unlock_avformat();
return AVERROR(ENOMEM);
}
for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_init(&openssl_mutexes[i], NULL);
CRYPTO_set_locking_callback(openssl_lock);
#if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
CRYPTO_set_id_callback(openssl_thread_id);
#endif
}
#endif
}
openssl_init++;
avpriv_unlock_avformat();
return 0;
}
void ff_openssl_deinit(void)
{
avpriv_lock_avformat();
openssl_init--;
if (!openssl_init) {
#if HAVE_THREADS
if (CRYPTO_get_locking_callback() == openssl_lock) {
int i;
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_destroy(&openssl_mutexes[i]);
av_free(openssl_mutexes);
}
#endif
}
avpriv_unlock_avformat();
}
static int print_tls_error(URLContext *h, int ret)
{
av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
return AVERROR(EIO);
}
static int tls_close(URLContext *h)
{
TLSContext *c = h->priv_data;
if (c->ssl) {
SSL_shutdown(c->ssl);
SSL_free(c->ssl);
}
if (c->ctx)
SSL_CTX_free(c->ctx);
if (c->tls_shared.tcp)
ffurl_close(c->tls_shared.tcp);
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
if (c->url_bio_method)
BIO_meth_free(c->url_bio_method);
#endif
ff_openssl_deinit();
return 0;
}
static int url_bio_create(BIO *b)
{
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
@ -143,79 +216,6 @@ static BIO_METHOD url_bio_method = {
};
#endif
int ff_openssl_init(void)
{
avpriv_lock_avformat();
if (!openssl_init) {
SSL_library_init();
SSL_load_error_strings();
#if HAVE_THREADS
if (!CRYPTO_get_locking_callback()) {
int i;
openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
if (!openssl_mutexes) {
avpriv_unlock_avformat();
return AVERROR(ENOMEM);
}
for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_init(&openssl_mutexes[i], NULL);
CRYPTO_set_locking_callback(openssl_lock);
#if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
CRYPTO_set_id_callback(openssl_thread_id);
#endif
}
#endif
}
openssl_init++;
avpriv_unlock_avformat();
return 0;
}
void ff_openssl_deinit(void)
{
avpriv_lock_avformat();
openssl_init--;
if (!openssl_init) {
#if HAVE_THREADS
if (CRYPTO_get_locking_callback() == openssl_lock) {
int i;
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_destroy(&openssl_mutexes[i]);
av_free(openssl_mutexes);
}
#endif
}
avpriv_unlock_avformat();
}
static int print_tls_error(URLContext *h, int ret)
{
av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
return AVERROR(EIO);
}
static int tls_close(URLContext *h)
{
TLSContext *c = h->priv_data;
if (c->ssl) {
SSL_shutdown(c->ssl);
SSL_free(c->ssl);
}
if (c->ctx)
SSL_CTX_free(c->ctx);
if (c->tls_shared.tcp)
ffurl_close(c->tls_shared.tcp);
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
if (c->url_bio_method)
BIO_meth_free(c->url_bio_method);
#endif
ff_openssl_deinit();
return 0;
}
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
{
TLSContext *p = h->priv_data;