Commit d8cab5c2 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  http: Remove the custom function for disabling chunked posts
  rtsp: Disable chunked http post through AVOptions
  movdec: Set frame_size for AMR
  h264_weight: remove duplication functions.
  swscale: align vertical filtersize by 2 on x86.
  libavfilter: reindent.
  matroskadec: empty blocks are in fact valid.
  avfilter: don't abort() on zero-size allocations.
  h264: improve calculation of codec delay.
  movenc: Set a correct packet size for AMR-NB mode 15, "no data"
  avformat: Add functions for doing global network initialization
  avformat: Add the https protocol
  avformat: Add the tls protocol, using OpenSSL or gnutls
  avformat: Initialize gnutls in ff_tls_init()
  w32threads: Wrap the mutex functions in inline functions returning int
  configure: Allow linking to the gnutls library
  avformat: Add ff_tls_init()/deinit() that initialize OpenSSL
  configure: Allow linking to openssl
  avcodec: Allow locking and unlocking an avformat specific mutex
  avformat: Split out functions from network.h to a new file, network.c

Conflicts:
	Changelog
	configure
	doc/APIchanges
	libavcodec/internal.h
	libavcodec/version.h
	libavfilter/formats.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/version.h
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 3b4798a8 18ae3626
......@@ -76,6 +76,7 @@ easier to use. The changes are:
- volume audio filter added
- earwax audio filter added
- libv4l2 support (--enable-libv4l2)
- TLS/SSL and HTTPS protocol support
version 0.8:
......
......@@ -166,6 +166,7 @@ External library support:
--enable-libcelt enable CELT decoding via libcelt [no]
--enable-frei0r enable frei0r video filtering
--enable-libaacplus enable AAC+ encoding via libaacplus [no]
--enable-gnutls enable gnutls [no]
--enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
--enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
--enable-libopencv enable video filtering via libopencv [no]
......@@ -199,6 +200,7 @@ External library support:
native MPEG-4/Xvid encoder exists [no]
--enable-openal enable OpenAL 1.1 capture support [no]
--enable-mlib enable Sun medialib [no]
--enable-openssl enable openssl [no]
--enable-zlib enable zlib [autodetect]
Advanced options (experts only):
......@@ -994,6 +996,7 @@ CONFIG_LIST="
ffserver
fft
frei0r
gnutls
golomb
gpl
gray
......@@ -1040,6 +1043,7 @@ CONFIG_LIST="
network
nonfree
openal
openssl
pic
postproc
rdft
......@@ -1589,11 +1593,14 @@ 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"
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
......@@ -2708,6 +2715,7 @@ die_license_disabled gpl x11grab
die_license_disabled nonfree libaacplus
die_license_disabled nonfree libfaac
die_license_disabled nonfree openssl
die_license_disabled version3 libopencore_amrnb
die_license_disabled version3 libopencore_amrwb
......@@ -3036,6 +3044,7 @@ enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
enabled libaacplus && require "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen -laacplus
enabled libdc1394 && require_pkg_config libdc1394-2 dc1394/dc1394.h dc1394_new
enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
enabled libdirac && require_pkg_config dirac \
"libdirac_decoder/dirac_parser.h libdirac_encoder/dirac_encoder.h" \
"dirac_decoder_init dirac_encoder_init"
......@@ -3078,6 +3087,10 @@ enabled openal && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32
{ check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
die "ERROR: openal version must be 1.1 or compatible"; }
enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }
SDL_CONFIG="${cross_prefix}sdl-config"
if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then
......@@ -3367,6 +3380,7 @@ echo "libvdpau enabled ${vdpau-no}"
echo "AVISynth enabled ${avisynth-no}"
echo "libcelt enabled ${libcelt-no}"
echo "frei0r enabled ${frei0r-no}"
echo "gnutls enabled ${gnutls-no}"
echo "libcdio support ${libcdio-no}"
echo "libdc1394 support ${libdc1394-no}"
echo "libdirac enabled ${libdirac-no}"
......@@ -3396,6 +3410,7 @@ echo "libx264 enabled ${libx264-no}"
echo "libxavs enabled ${libxavs-no}"
echo "libxvid enabled ${libxvid-no}"
echo "openal enabled ${openal-no}"
echo "openssl enabled ${openssl-no}"
echo "zlib enabled ${zlib-no}"
echo "bzlib enabled ${bzlib-no}"
echo
......
......@@ -19,6 +19,9 @@ API changes, most recent first:
2011-10-20 - b35e9e1 - lavu 51.22.0
Add av_strtok() to avstring.h.
2011-11-xx - xxxxxxx - lavf 53.13.0
Add avformat_network_init()/avformat_network_uninit()
2011-10-27 - 512557b - lavc 53.15.0
Remove avcodec_parse_frame.
Deprecate AVCodecContext.parse_only and CODEC_CAP_PARSE_ONLY.
......
......@@ -1128,6 +1128,7 @@ int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
av_cold int ff_h264_decode_init(AVCodecContext *avctx){
H264Context *h= avctx->priv_data;
MpegEncContext * const s = &h->s;
int i;
MPV_decode_defaults(s);
......@@ -1152,6 +1153,8 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx){
h->thread_context[0] = h;
h->outputed_poc = h->next_outputed_poc = INT_MIN;
for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
h->last_pocs[i] = INT_MIN;
h->prev_poc_msb= 1<<16;
h->x264_build = -1;
ff_h264_reset_sei(h);
......@@ -1493,11 +1496,23 @@ static void decode_postinit(H264Context *h, int setup_finished){
if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
{ }
else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT)
|| (s->low_delay &&
((h->next_outputed_poc != INT_MIN && out->poc > h->next_outputed_poc + 2)
|| cur->f.pict_type == AV_PICTURE_TYPE_B)))
{
else if (out_of_order && pics-1 == s->avctx->has_b_frames &&
s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) {
int cnt = 0, invalid = 0;
for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) {
cnt += out->poc < h->last_pocs[i];
invalid += h->last_pocs[i] == INT_MIN;
}
if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
s->avctx->has_b_frames = FFMAX(s->avctx->has_b_frames, cnt);
} else if (cnt) {
for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
h->last_pocs[i] = INT_MIN;
}
s->low_delay = 0;
} else if (s->low_delay &&
((h->next_outputed_poc != INT_MIN && out->poc > h->next_outputed_poc + 2) ||
cur->f.pict_type == AV_PICTURE_TYPE_B)) {
s->low_delay = 0;
s->avctx->has_b_frames++;
}
......@@ -1509,6 +1524,8 @@ static void decode_postinit(H264Context *h, int setup_finished){
for(i=out_idx; h->delayed_pic[i]; i++)
h->delayed_pic[i] = h->delayed_pic[i+1];
}
memmove(h->last_pocs, &h->last_pocs[1], sizeof(*h->last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
h->last_pocs[MAX_DELAYED_PIC_COUNT - 1] = out->poc;
if(!out_of_order && pics > s->avctx->has_b_frames){
h->next_output_pic = out;
if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) {
......
......@@ -490,6 +490,7 @@ typedef struct H264Context{
Picture *long_ref[32];
Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture
Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size?
int last_pocs[MAX_DELAYED_PIC_COUNT];
Picture *next_output_pic;
int outputed_poc;
int next_outputed_poc;
......
......@@ -60,4 +60,7 @@ unsigned int avpriv_toupper4(unsigned int x);
*/
void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic);
int avpriv_lock_avformat(void);
int avpriv_unlock_avformat(void);
#endif /* AVCODEC_INTERNAL_H */
......@@ -48,6 +48,7 @@
static int volatile entangled_thread_counter=0;
static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
static void *codec_mutex;
static void *avformat_mutex;
void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
{
......@@ -1378,6 +1379,8 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
if (ff_lockmgr_cb) {
if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
return -1;
if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
return -1;
}
ff_lockmgr_cb = cb;
......@@ -1385,6 +1388,26 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
if (ff_lockmgr_cb) {
if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
return -1;
if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
return -1;
}
return 0;
}
int avpriv_lock_avformat(void)
{
if (ff_lockmgr_cb) {
if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_OBTAIN))
return -1;
}
return 0;
}
int avpriv_unlock_avformat(void)
{
if (ff_lockmgr_cb) {
if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_RELEASE))
return -1;
}
return 0;
}
......
......@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 53
#define LIBAVCODEC_VERSION_MINOR 27
#define LIBAVCODEC_VERSION_MINOR 28
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......
......@@ -91,10 +91,26 @@ static void pthread_join(pthread_t thread, void **value_ptr)
CloseHandle(thread.handle);
}
#define pthread_mutex_init(m, a) InitializeCriticalSection(m)
#define pthread_mutex_destroy(m) DeleteCriticalSection(m)
#define pthread_mutex_lock(m) EnterCriticalSection(m)
#define pthread_mutex_unlock(m) LeaveCriticalSection(m)
static inline int pthread_mutex_init(pthread_mutex_t *m, void* attr)
{
InitializeCriticalSection(m);
return 0;
}
static inline int pthread_mutex_destroy(pthread_mutex_t *m)
{
DeleteCriticalSection(m);
return 0;
}
static inline int pthread_mutex_lock(pthread_mutex_t *m)
{
EnterCriticalSection(m);
return 0;
}
static inline int pthread_mutex_unlock(pthread_mutex_t *m)
{
LeaveCriticalSection(m);
return 0;
}
/* for pre-Windows 6.0 platforms we need to define and use our own condition
* variable and api */
......
......@@ -122,12 +122,8 @@ cglobal h264_weight_%1_%3, 6, 6, %2
INIT_MMX
WEIGHT_FUNC_HALF_MM 4, 0, mmx2
WEIGHT_FUNC_HALF_MM 4, 0, mmx2
WEIGHT_FUNC_HALF_MM 4, 0, mmx2
INIT_XMM
WEIGHT_FUNC_HALF_MM 8, 8, sse2
WEIGHT_FUNC_HALF_MM 8, 8, sse2
WEIGHT_FUNC_HALF_MM 8, 8, sse2
%macro BIWEIGHT_SETUP 0
%ifdef ARCH_X86_64
......
......@@ -16,6 +16,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
......@@ -342,6 +344,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
......@@ -354,6 +357,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
......
......@@ -258,6 +258,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);
......@@ -271,5 +272,6 @@ void av_register_all(void)
#endif
REGISTER_PROTOCOL (RTP, rtp);
REGISTER_PROTOCOL (TCP, tcp);
REGISTER_PROTOCOL (TLS, tls);
REGISTER_PROTOCOL (UDP, udp);
}
......@@ -1855,4 +1855,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 */
......@@ -77,11 +77,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,
......@@ -91,8 +86,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];
......@@ -108,7 +103,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);
......@@ -122,10 +118,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;
......@@ -508,6 +509,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,
......@@ -519,3 +521,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
......@@ -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
......
......@@ -1750,11 +1750,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 res;
}
} else if (size <= 3)
return 0;
st = track->stream;
if (st->discard >= AVDISCARD_ALL)
return res;
......
......@@ -1346,17 +1346,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;
/* force frame_size, too, samples_per_frame isn't always set properly */
st->codec->frame_size = 160;
} else if (st->codec->codec_id == CODEC_ID_AMR_WB) {
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:
......
/*
* 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 "libavutil/avutil.h"
#include "network.h"
#include "libavcodec/internal.h"
#define THREADS (HAVE_PTHREADS || (defined(WIN32) && !defined(__MINGW32CE__)))
#if THREADS
#if HAVE_PTHREADS
#include <pthread.h>
#else
#include "libavcodec/w32pthreads.h"
#endif
#endif
#if CONFIG_OPENSSL
#include <openssl/ssl.h>
static int openssl_init;
#if THREADS
#include <openssl/crypto.h>
#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
#if CONFIG_GNUTLS
#include <gnutls/gnutls.h>
#if THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
#include <gcrypt.h>
#include <errno.h>
#undef malloc
#undef free
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#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
#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();
}
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
#if CONFIG_GNUTLS
gnutls_global_deinit();
#endif
avpriv_unlock_avformat();
}
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;
}
......@@ -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 <sys/types.h>
#include <sys/socket.h>
......@@ -66,31 +56,13 @@ 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);
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);
......@@ -191,18 +163,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 */
......@@ -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"
......@@ -1482,7 +1483,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
......
/*
* 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 <gnutls/gnutls.h>
#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 <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#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 <poll.h>
#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),
};
......@@ -4186,3 +4186,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;
}
......@@ -24,7 +24,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
#define LIBAVFORMAT_VERSION_MINOR 18
#define LIBAVFORMAT_VERSION_MINOR 19
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
......
......@@ -960,7 +960,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
/* precalculate vertical scaler filter coefficients */
{
const int filterAlign=
(HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) && (flags & SWS_ACCURATE_RND) ? 2 :
(HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 2 :
(HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :
1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment