From f6d371009678e46877e6f81ab0eae475d41b1f57 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Mon, 7 Feb 2011 12:59:50 +0200 Subject: avformat: Split out functions from network.h to a new file, network.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/Makefile | 2 ++ libavformat/network.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/network.h | 55 ++++--------------------------------- 3 files changed, 84 insertions(+), 49 deletions(-) create mode 100644 libavformat/network.c (limited to 'libavformat') diff --git a/libavformat/Makefile b/libavformat/Makefile index ca4ceef54f..e9bcd28a93 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -14,6 +14,8 @@ OBJS = allformats.o \ seek.o \ utils.o \ +OBJS-$(CONFIG_NETWORK) += network.o + # muxers/demuxers OBJS-$(CONFIG_A64_MUXER) += a64.o OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o rawdec.o diff --git a/libavformat/network.c b/libavformat/network.c new file mode 100644 index 0000000000..f694614e8b --- /dev/null +++ b/libavformat/network.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2007 The Libav Project + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "network.h" + +int ff_network_init(void) +{ +#if HAVE_WINSOCK2_H + WSADATA wsaData; + if (WSAStartup(MAKEWORD(1,1), &wsaData)) + return 0; +#endif + return 1; +} + +int ff_network_wait_fd(int fd, int write) +{ + int ev = write ? POLLOUT : POLLIN; + struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; + int ret; + ret = poll(&p, 1, 100); + return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN); +} + +void ff_network_close(void) +{ +#if HAVE_WINSOCK2_H + WSACleanup(); +#endif +} + +#if HAVE_WINSOCK2_H +int ff_neterrno(void) +{ + int err = WSAGetLastError(); + switch (err) { + case WSAEWOULDBLOCK: + return AVERROR(EAGAIN); + case WSAEINTR: + return AVERROR(EINTR); + } + return -err; +} +#endif + +int ff_is_multicast_address(struct sockaddr *addr) +{ + if (addr->sa_family == AF_INET) { + return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); + } +#if HAVE_STRUCT_SOCKADDR_IN6 + if (addr->sa_family == AF_INET6) { + return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); + } +#endif + + return 0; +} + diff --git a/libavformat/network.h b/libavformat/network.h index 80d094a0de..00daed8759 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -36,17 +36,7 @@ #define ECONNREFUSED WSAECONNREFUSED #define EINPROGRESS WSAEINPROGRESS -static inline int ff_neterrno(void) -{ - int err = WSAGetLastError(); - switch (err) { - case WSAEWOULDBLOCK: - return AVERROR(EAGAIN); - case WSAEINTR: - return AVERROR(EINTR); - } - return -err; -} +int ff_neterrno(void); #else #include #include @@ -66,31 +56,10 @@ static inline int ff_neterrno(void) int ff_socket_nonblock(int socket, int enable); -static inline int ff_network_init(void) -{ -#if HAVE_WINSOCK2_H - WSADATA wsaData; - if (WSAStartup(MAKEWORD(1,1), &wsaData)) - return 0; -#endif - return 1; -} - -static inline int ff_network_wait_fd(int fd, int write) -{ - int ev = write ? POLLOUT : POLLIN; - struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; - int ret; - ret = poll(&p, 1, 100); - return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN); -} - -static inline void ff_network_close(void) -{ -#if HAVE_WINSOCK2_H - WSACleanup(); -#endif -} +int ff_network_init(void); +void ff_network_close(void); + +int ff_network_wait_fd(int fd, int write); int ff_inet_aton (const char * str, struct in_addr * add); @@ -191,18 +160,6 @@ const char *ff_gai_strerror(int ecode); #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) #endif -static inline int ff_is_multicast_address(struct sockaddr *addr) -{ - if (addr->sa_family == AF_INET) { - return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); - } -#if HAVE_STRUCT_SOCKADDR_IN6 - if (addr->sa_family == AF_INET6) { - return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); - } -#endif - - return 0; -} +int ff_is_multicast_address(struct sockaddr *addr); #endif /* AVFORMAT_NETWORK_H */ -- cgit v1.2.3 From 48e59ad8e776546d172c4628223fcb6b0695f9f2 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sat, 5 Feb 2011 00:25:07 +0200 Subject: avformat: Add ff_tls_init()/deinit() that initialize OpenSSL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the application hasn't set up mutex callbacks, we set up our own using pthreads (or w32pthreads). Signed-off-by: Martin Storsjö --- libavformat/network.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/network.h | 3 ++ 2 files changed, 82 insertions(+) (limited to 'libavformat') diff --git a/libavformat/network.c b/libavformat/network.c index f694614e8b..6ef609f2ed 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -19,6 +19,85 @@ */ #include "network.h" +#include "libavcodec/internal.h" + +#define THREADS (HAVE_PTHREADS || (defined(WIN32) && !defined(__MINGW32CE__))) + +#if THREADS +#if HAVE_PTHREADS +#include +#else +#include "libavcodec/w32pthreads.h" +#endif +#endif + +#if CONFIG_OPENSSL +#include +static int openssl_init; +#if THREADS +#include +#include "libavutil/avutil.h" +pthread_mutex_t *openssl_mutexes; +static void openssl_lock(int mode, int type, const char *file, int line) +{ + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(&openssl_mutexes[type]); + else + pthread_mutex_unlock(&openssl_mutexes[type]); +} +#ifndef WIN32 +static unsigned long openssl_thread_id(void) +{ + return (intptr_t) pthread_self(); +} +#endif +#endif +#endif + +void ff_tls_init(void) +{ + avpriv_lock_avformat(); +#if CONFIG_OPENSSL + if (!openssl_init) { + SSL_library_init(); + SSL_load_error_strings(); +#if THREADS + if (!CRYPTO_get_locking_callback()) { + int i; + openssl_mutexes = av_malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks()); + for (i = 0; i < CRYPTO_num_locks(); i++) + pthread_mutex_init(&openssl_mutexes[i], NULL); + CRYPTO_set_locking_callback(openssl_lock); +#ifndef WIN32 + CRYPTO_set_id_callback(openssl_thread_id); +#endif + } +#endif + } + openssl_init++; +#endif + avpriv_unlock_avformat(); +} + +void ff_tls_deinit(void) +{ + avpriv_lock_avformat(); +#if CONFIG_OPENSSL + openssl_init--; + if (!openssl_init) { +#if 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 + } +#endif + avpriv_unlock_avformat(); +} int ff_network_init(void) { diff --git a/libavformat/network.h b/libavformat/network.h index 00daed8759..df79f4598f 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -59,6 +59,9 @@ int ff_socket_nonblock(int socket, int enable); int ff_network_init(void); void ff_network_close(void); +void ff_tls_init(void); +void ff_tls_deinit(void); + int ff_network_wait_fd(int fd, int write); int ff_inet_aton (const char * str, struct in_addr * add); -- cgit v1.2.3 From 1606e551ff4ace23da8a372ebb1147da36566372 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 6 Feb 2011 00:06:49 +0100 Subject: avformat: Initialize gnutls in ff_tls_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/network.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libavformat') diff --git a/libavformat/network.c b/libavformat/network.c index 6ef609f2ed..d50e1e70f8 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -53,6 +53,16 @@ static unsigned long openssl_thread_id(void) #endif #endif #endif +#if CONFIG_GNUTLS +#include +#if THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00 +#include +#include +#undef malloc +#undef free +GCRY_THREAD_OPTION_PTHREAD_IMPL; +#endif +#endif void ff_tls_init(void) { @@ -75,6 +85,13 @@ void ff_tls_init(void) #endif } openssl_init++; +#endif +#if CONFIG_GNUTLS +#if 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(); #endif avpriv_unlock_avformat(); } @@ -95,6 +112,9 @@ void ff_tls_deinit(void) } #endif } +#endif +#if CONFIG_GNUTLS + gnutls_global_deinit(); #endif avpriv_unlock_avformat(); } -- cgit v1.2.3 From 558d192d23bf76a476c0d84d212611e529c64529 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 6 Feb 2011 00:19:49 +0200 Subject: avformat: Add the tls protocol, using OpenSSL or gnutls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note, this protocol doesn't yet check verify the server certificate against a local database of trusted CA root certificates. Signed-off-by: Martin Storsjö --- configure | 2 + libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/tls.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 2 +- 5 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 libavformat/tls.c (limited to 'libavformat') diff --git a/configure b/configure index f28dd561de..89a39b269b 100755 --- a/configure +++ b/configure @@ -1483,6 +1483,8 @@ mmst_protocol_deps="network" rtmp_protocol_select="tcp_protocol" rtp_protocol_select="udp_protocol" tcp_protocol_deps="network" +tls_protocol_deps_any="openssl gnutls" +tls_protocol_select="tcp_protocol" udp_protocol_deps="network" # filters diff --git a/libavformat/Makefile b/libavformat/Makefile index e9bcd28a93..5da01aa60b 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -334,6 +334,7 @@ OBJS-$(CONFIG_RTMP_PROTOCOL) += $(RTMP-OBJS-yes) OBJS-$(CONFIG_RTP_PROTOCOL) += rtpproto.o OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o +OBJS-$(CONFIG_TLS_PROTOCOL) += tls.o OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o EXAMPLES = metadata output diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 8e89b2f4ff..d078a154dc 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -254,5 +254,6 @@ void av_register_all(void) #endif REGISTER_PROTOCOL (RTP, rtp); REGISTER_PROTOCOL (TCP, tcp); + REGISTER_PROTOCOL (TLS, tls); REGISTER_PROTOCOL (UDP, udp); } diff --git a/libavformat/tls.c b/libavformat/tls.c new file mode 100644 index 0000000000..85bf46f903 --- /dev/null +++ b/libavformat/tls.c @@ -0,0 +1,234 @@ +/* + * TLS/SSL Protocol + * Copyright (c) 2011 Martin Storsjo + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "url.h" +#include "libavutil/avstring.h" +#if CONFIG_GNUTLS +#include +#define TLS_read(c, buf, size) gnutls_record_recv(c->session, buf, size) +#define TLS_write(c, buf, size) gnutls_record_send(c->session, buf, size) +#define TLS_shutdown(c) gnutls_bye(c->session, GNUTLS_SHUT_RDWR) +#define TLS_free(c) do { \ + if (c->session) \ + gnutls_deinit(c->session); \ + if (c->cred) \ + gnutls_certificate_free_credentials(c->cred); \ + } while (0) +#elif CONFIG_OPENSSL +#include +#include +#include +#define TLS_read(c, buf, size) SSL_read(c->ssl, buf, size) +#define TLS_write(c, buf, size) SSL_write(c->ssl, buf, size) +#define TLS_shutdown(c) SSL_shutdown(c->ssl) +#define TLS_free(c) do { \ + if (c->ssl) \ + SSL_free(c->ssl); \ + if (c->ctx) \ + SSL_CTX_free(c->ctx); \ + } while (0) +#endif +#include "network.h" +#include "os_support.h" +#include "internal.h" +#if HAVE_POLL_H +#include +#endif + +typedef struct { + const AVClass *class; + URLContext *tcp; +#if CONFIG_GNUTLS + gnutls_session_t session; + gnutls_certificate_credentials_t cred; +#elif CONFIG_OPENSSL + SSL_CTX *ctx; + SSL *ssl; +#endif + int fd; +} TLSContext; + +static int do_tls_poll(URLContext *h, int ret) +{ + TLSContext *c = h->priv_data; + struct pollfd p = { c->fd, 0, 0 }; +#if CONFIG_GNUTLS + if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) { + av_log(NULL, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret)); + return AVERROR(EIO); + } + if (gnutls_record_get_direction(c->session)) + p.events = POLLOUT; + else + p.events = POLLIN; +#elif CONFIG_OPENSSL + ret = SSL_get_error(c->ssl, ret); + if (ret == SSL_ERROR_WANT_READ) { + p.events = POLLIN; + } else if (ret == SSL_ERROR_WANT_WRITE) { + p.events = POLLOUT; + } else { + av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ret, NULL)); + return AVERROR(EIO); + } +#endif + if (h->flags & URL_FLAG_NONBLOCK) + return AVERROR(EAGAIN); + while (1) { + int n = poll(&p, 1, 100); + if (n > 0) + break; + if (url_interrupt_cb()) + return AVERROR(EINTR); + } + return 0; +} + +static int tls_open(URLContext *h, const char *uri, int flags) +{ + TLSContext *c = h->priv_data; + int ret; + int port; + char buf[200], host[200]; + int numerichost = 0; + struct addrinfo hints = { 0 }, *ai = NULL; + + ff_tls_init(); + + av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri); + ff_url_join(buf, sizeof(buf), "tcp", NULL, host, port, NULL); + + hints.ai_flags = AI_NUMERICHOST; + if (!getaddrinfo(host, NULL, &hints, &ai)) { + numerichost = 1; + freeaddrinfo(ai); + } + + ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE); + if (ret) + goto fail; + c->fd = ffurl_get_file_handle(c->tcp); + +#if CONFIG_GNUTLS + gnutls_init(&c->session, GNUTLS_CLIENT); + if (!numerichost) + gnutls_server_name_set(c->session, GNUTLS_NAME_DNS, host, strlen(host)); + gnutls_certificate_allocate_credentials(&c->cred); + gnutls_certificate_set_verify_flags(c->cred, 0); + gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, c->cred); + gnutls_transport_set_ptr(c->session, (gnutls_transport_ptr_t) + (intptr_t) c->fd); + gnutls_priority_set_direct(c->session, "NORMAL", NULL); + while (1) { + ret = gnutls_handshake(c->session); + if (ret == 0) + break; + if ((ret = do_tls_poll(h, ret)) < 0) + goto fail; + } +#elif CONFIG_OPENSSL + c->ctx = SSL_CTX_new(SSLv3_client_method()); + if (!c->ctx) { + av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL)); + ret = AVERROR(EIO); + goto fail; + } + c->ssl = SSL_new(c->ctx); + if (!c->ssl) { + av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL)); + ret = AVERROR(EIO); + goto fail; + } + SSL_set_fd(c->ssl, c->fd); + if (!numerichost) + SSL_set_tlsext_host_name(c->ssl, host); + while (1) { + ret = SSL_connect(c->ssl); + if (ret > 0) + break; + if (ret == 0) { + av_log(NULL, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n"); + ret = AVERROR(EIO); + goto fail; + } + if ((ret = do_tls_poll(h, ret)) < 0) + goto fail; + } +#endif + return 0; +fail: + TLS_free(c); + if (c->tcp) + ffurl_close(c->tcp); + ff_tls_deinit(); + return ret; +} + +static int tls_read(URLContext *h, uint8_t *buf, int size) +{ + TLSContext *c = h->priv_data; + while (1) { + int ret = TLS_read(c, buf, size); + if (ret > 0) + return ret; + if (ret == 0) + return AVERROR(EIO); + if ((ret = do_tls_poll(h, ret)) < 0) + return ret; + } + return 0; +} + +static int tls_write(URLContext *h, const uint8_t *buf, int size) +{ + TLSContext *c = h->priv_data; + while (1) { + int ret = TLS_write(c, buf, size); + if (ret > 0) + return ret; + if (ret == 0) + return AVERROR(EIO); + if ((ret = do_tls_poll(h, ret)) < 0) + return ret; + } + return 0; +} + +static int tls_close(URLContext *h) +{ + TLSContext *c = h->priv_data; + TLS_shutdown(c); + TLS_free(c); + ffurl_close(c->tcp); + ff_tls_deinit(); + return 0; +} + +URLProtocol ff_tls_protocol = { + .name = "tls", + .url_open = tls_open, + .url_read = tls_read, + .url_write = tls_write, + .url_seek = NULL, + .url_close = tls_close, + .priv_data_size = sizeof(TLSContext), +}; diff --git a/libavformat/version.h b/libavformat/version.h index b0c1f9481e..2b1ef9530c 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -24,7 +24,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 10 +#define LIBAVFORMAT_VERSION_MINOR 11 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ -- cgit v1.2.3 From 183baeadca74f4087b58dc5a94a649473f28470c Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 6 Feb 2011 00:20:26 +0200 Subject: avformat: Add the https protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- Changelog | 1 + configure | 1 + libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/http.c | 29 +++++++++++++++++++++++++---- libavformat/version.h | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) (limited to 'libavformat') diff --git a/Changelog b/Changelog index 4d89510748..34ec3c65e1 100644 --- a/Changelog +++ b/Changelog @@ -57,6 +57,7 @@ easier to use. The changes are: - 4:2:2 H.264 decoding support - Pulseaudio input device - replacement Indeo 3 decoder +- TLS/SSL and HTTPS protocol support version 0.7: diff --git a/configure b/configure index 89a39b269b..fa23619d39 100755 --- a/configure +++ b/configure @@ -1478,6 +1478,7 @@ x11_grab_device_indev_extralibs="-lX11 -lXext -lXfixes" gopher_protocol_deps="network" http_protocol_deps="network" http_protocol_select="tcp_protocol" +https_protocol_select="tls_protocol" mmsh_protocol_select="http_protocol" mmst_protocol_deps="network" rtmp_protocol_select="tcp_protocol" diff --git a/libavformat/Makefile b/libavformat/Makefile index 5da01aa60b..54bc8a1645 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -322,6 +322,7 @@ OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o +OBJS-$(CONFIG_HTTPS_PROTOCOL) += http.o httpauth.o OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index d078a154dc..01900e8a73 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -241,6 +241,7 @@ void av_register_all(void) REGISTER_PROTOCOL (FILE, file); REGISTER_PROTOCOL (GOPHER, gopher); REGISTER_PROTOCOL (HTTP, http); + REGISTER_PROTOCOL (HTTPS, https); REGISTER_PROTOCOL (MMSH, mmsh); REGISTER_PROTOCOL (MMST, mmst); REGISTER_PROTOCOL (MD5, md5); diff --git a/libavformat/http.c b/libavformat/http.c index 1db9e82cc4..0030bc7dc1 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -92,8 +92,8 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src) /* return non zero if error */ static int http_open_cnx(URLContext *h) { - const char *path, *proxy_path; - char hostname[1024], hoststr[1024]; + const char *path, *proxy_path, *lower_proto = "tcp"; + char hostname[1024], hoststr[1024], proto[10]; char auth[1024]; char path1[1024]; char buf[1024]; @@ -109,7 +109,8 @@ static int http_open_cnx(URLContext *h) /* fill the dest addr */ redo: /* needed in any case to build the host string */ - av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, + av_url_split(proto, sizeof(proto), auth, sizeof(auth), + hostname, sizeof(hostname), &port, path1, sizeof(path1), s->location); ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); @@ -123,10 +124,15 @@ static int http_open_cnx(URLContext *h) else path = path1; } + if (!strcmp(proto, "https")) { + lower_proto = "tls"; + if (port < 0) + port = 443; + } if (port < 0) port = 80; - ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); + ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE); if (err < 0) goto fail; @@ -509,6 +515,7 @@ http_get_file_handle(URLContext *h) return ffurl_get_file_handle(s->hd); } +#if CONFIG_HTTP_PROTOCOL URLProtocol ff_http_protocol = { .name = "http", .url_open = http_open, @@ -520,3 +527,17 @@ URLProtocol ff_http_protocol = { .priv_data_size = sizeof(HTTPContext), .priv_data_class = &httpcontext_class, }; +#endif +#if CONFIG_HTTPS_PROTOCOL +URLProtocol ff_https_protocol = { + .name = "https", + .url_open = http_open, + .url_read = http_read, + .url_write = http_write, + .url_seek = http_seek, + .url_close = http_close, + .url_get_file_handle = http_get_file_handle, + .priv_data_size = sizeof(HTTPContext), + .priv_data_class = &httpcontext_class, +}; +#endif diff --git a/libavformat/version.h b/libavformat/version.h index 2b1ef9530c..c7b07783c9 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -24,7 +24,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 11 +#define LIBAVFORMAT_VERSION_MINOR 12 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ -- cgit v1.2.3 From b6d08f40aa9893c77a982fc17c289da0c27ccd96 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Tue, 1 Nov 2011 13:40:04 +0200 Subject: avformat: Add functions for doing global network initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- doc/APIchanges | 3 +++ libavformat/avformat.h | 15 +++++++++++++++ libavformat/utils.c | 20 ++++++++++++++++++++ libavformat/version.h | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) (limited to 'libavformat') diff --git a/doc/APIchanges b/doc/APIchanges index 79aa202ec1..1e6adf5a62 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-11-xx - xxxxxxx - lavf 53.13.0 + Add avformat_network_init()/avformat_network_uninit() + 2011-xx-xx - xxxxxxx - lavc 53.15.0 Remove avcodec_parse_frame. Deprecate AVCodecContext.parse_only and CODEC_CAP_PARSE_ONLY. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index dd40c7fafb..43563031c1 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1743,4 +1743,19 @@ int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_co */ const AVClass *avformat_get_class(void); +/** + * Do global initialization of network components. This is optional, + * but recommended, since it avoids the overhead of implicitly + * doing the setup for each session. + * + * Since the next major version bump, calling this function will become + * mandatory if using network protocols. + */ +int avformat_network_init(void); + +/** + * Undo the initialization done by avformat_network_init. + */ +int avformat_network_deinit(void); + #endif /* AVFORMAT_AVFORMAT_H */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 1158079992..c13ce3da0c 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3964,3 +3964,23 @@ int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_co } return AVERROR_PATCHWELCOME; } + +int avformat_network_init(void) +{ +#if CONFIG_NETWORK + int ret; + if ((ret = ff_network_init()) < 0) + return ret; + ff_tls_init(); +#endif + return 0; +} + +int avformat_network_deinit(void) +{ +#if CONFIG_NETWORK + ff_network_close(); + ff_tls_deinit(); +#endif + return 0; +} diff --git a/libavformat/version.h b/libavformat/version.h index c7b07783c9..48f2303f9e 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -24,7 +24,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 12 +#define LIBAVFORMAT_VERSION_MINOR 13 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ -- cgit v1.2.3 From ed669c9becf9d03c25e78ee98c2e4de564b854fc Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Wed, 19 Oct 2011 11:20:48 +0200 Subject: movenc: Set a correct packet size for AMR-NB mode 15, "no data" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These packets are valid packets, and consist of 1 byte (which contains the mode bits). This had been analyzed and reported by Igor Levin, igor d levin comverse com. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/movenc.c b/libavformat/movenc.c index fb8749c6d5..b7314dca41 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2004,7 +2004,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) if (enc->codec_id == CODEC_ID_AMR_NB) { /* We must find out how many AMR blocks there are in one packet */ static uint16_t packed_size[16] = - {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0}; + {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1}; int len = 0; while (len < size && samplesInChunk < 100) { -- cgit v1.2.3 From d31fb1a9e77f37ee1bbc0faabc655390eb91b579 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 29 Oct 2011 16:17:51 -0700 Subject: matroskadec: empty blocks are in fact valid. --- libavformat/matroskadec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libavformat') diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3f48a72c8e..a40aa1c469 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1679,11 +1679,12 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, size -= n; track = matroska_find_track_by_num(matroska, num); - if (size <= 3 || !track || !track->stream) { + if (!track || !track->stream) { av_log(matroska->ctx, AV_LOG_INFO, "Invalid stream %"PRIu64" or size %u\n", num, size); return AVERROR_INVALIDDATA; - } + } else if (size <= 3) + return 0; st = track->stream; if (st->discard >= AVDISCARD_ALL) return res; -- cgit v1.2.3 From 237f13290bcc1c69cf103dede7f546a2a0706b5c Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Thu, 3 Nov 2011 20:20:58 +0100 Subject: movdec: Set frame_size for AMR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier, sc->samples_per_frame was used for setting the frame size, but all files don't have that set properly. The frame size is a known constant for these codecs. If frame_size isn't set, the mov/3gp muxer refuses to mux it. This fixes stream copy of audio from https://roundup.libav.org/file1248/Video_With_AMR-NB_Audio.3gp to another 3gp file (roundup issue 2468). Signed-off-by: Martin Storsjö --- libavformat/mov.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mov.c b/libavformat/mov.c index 2036f5134a..351058c968 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1291,14 +1291,16 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) st->codec->channels= 1; /* really needed */ break; case CODEC_ID_AMR_NB: - case CODEC_ID_AMR_WB: - st->codec->frame_size= sc->samples_per_frame; st->codec->channels= 1; /* really needed */ /* force sample rate for amr, stsd in 3gp does not store sample rate */ - if (st->codec->codec_id == CODEC_ID_AMR_NB) - st->codec->sample_rate = 8000; - else if (st->codec->codec_id == CODEC_ID_AMR_WB) - st->codec->sample_rate = 16000; + st->codec->sample_rate = 8000; + /* force frame_size, too, samples_per_frame isn't always set properly */ + st->codec->frame_size = 160; + break; + case CODEC_ID_AMR_WB: + st->codec->channels = 1; + st->codec->sample_rate = 16000; + st->codec->frame_size = 320; break; case CODEC_ID_MP2: case CODEC_ID_MP3: -- cgit v1.2.3 From d450cc4f4a7c4b072d6abc7af659347393e35314 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 20 Jun 2010 23:58:22 +0300 Subject: rtsp: Disable chunked http post through AVOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids having to use a private function. Signed-off-by: Martin Storsjö --- libavformat/rtsp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index b9ef0bfe84..b9f340d7b1 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -26,6 +26,7 @@ #include "libavutil/parseutils.h" #include "libavutil/random_seed.h" #include "libavutil/dict.h" +#include "libavutil/opt.h" #include "avformat.h" #include "avio_internal.h" @@ -1483,7 +1484,7 @@ redirect: "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n", sessioncookie); ff_http_set_headers(rt->rtsp_hd_out, headers); - ff_http_set_chunked_transfer_encoding(rt->rtsp_hd_out, 0); + av_opt_set(rt->rtsp_hd_out->priv_data, "chunksize", "-1", 0); /* Initialize the authentication state for the POST session. The HTTP * protocol implementation doesn't properly handle multi-pass -- cgit v1.2.3 From 18ae3626405a8b3d6dbb7e5b848d354cd7bf9a47 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 20 Jun 2010 23:59:15 +0300 Subject: http: Remove the custom function for disabling chunked posts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/http.c | 5 ----- libavformat/http.h | 8 -------- 2 files changed, 13 deletions(-) (limited to 'libavformat') diff --git a/libavformat/http.c b/libavformat/http.c index 0030bc7dc1..243a4d78e3 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -78,11 +78,6 @@ void ff_http_set_headers(URLContext *h, const char *headers) av_strlcpy(s->headers, headers, sizeof(s->headers)); } -void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked) -{ - ((HTTPContext*)h->priv_data)->chunksize = is_chunked ? 0 : -1; -} - void ff_http_init_auth_state(URLContext *dest, const URLContext *src) { memcpy(&((HTTPContext*)dest->priv_data)->auth_state, diff --git a/libavformat/http.h b/libavformat/http.h index c5ff5e134c..bd63a190dc 100644 --- a/libavformat/http.h +++ b/libavformat/http.h @@ -42,14 +42,6 @@ */ void ff_http_set_headers(URLContext *h, const char *headers); -/** - * Enable or disable chunked transfer encoding. (default is enabled) - * - * @param h URL context for this HTTP connection - * @param is_chunked 0 to disable chunking, nonzero otherwise. - */ -void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked); - /** * Initialize the authentication state based on another HTTP URLContext. * This can be used to pre-initialize the authentication parameters if -- cgit v1.2.3