From b2704a65d513f63d12e705e941abfbc62676c8fa Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 20 Jul 2012 22:22:18 +0100 Subject: configure: respect CC_O setting in check_cc Use compiler-specific replacements for the -o flag in check_cc. This makes tests work properly with compilers using non-standard flags. The tms470 flags are updated to work with this scheme. Signed-off-by: Mans Rullgard --- configure | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/configure b/configure index dd67f89d72..f00eddd379 100755 --- a/configure +++ b/configure @@ -617,11 +617,15 @@ check_cmd(){ "$@" >> $logfile 2>&1 } +cc_o(){ + eval printf '%s\\n' $CC_O +} + check_cc(){ log check_cc "$@" cat > $TMPC log_file $TMPC - check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC + check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c $(cc_o $TMPO) $TMPC } check_cpp(){ @@ -2094,12 +2098,10 @@ elif $cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then elif $cc -version 2>/dev/null | grep -q TMS470; then cc_type=tms470 cc_ident=$($cc -version | head -n1 | tr -s ' ') - cc="$cc --gcc --abi=eabi -eo=.o -mc -me" - CC_O='-fr=$(@D)' + cc="$cc --gcc --abi=eabi -me" + CC_O='-fe=$@' as_default="${cross_prefix}gcc" ld_default="${cross_prefix}gcc" - TMPO=$(basename $TMPC .c).o - append TMPFILES $TMPO add_cflags -D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__= CC_DEPFLAGS='-ppa -ppd=$(@:.o=.d)' AS_DEPFLAGS='-MMD' -- cgit v1.2.3 From 85a3c19ed127e8a333bcc0700a5465faed1f7753 Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Fri, 20 Jul 2012 18:33:06 -0400 Subject: dsputil: x86: add SHUFFLE_MASK_W macro Simplifies pshufb masks that operate on words. --- libavcodec/x86/dsputil_yasm.asm | 2 +- libavutil/x86/x86util.asm | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libavcodec/x86/dsputil_yasm.asm b/libavcodec/x86/dsputil_yasm.asm index 313e774669..077f3a0db7 100644 --- a/libavcodec/x86/dsputil_yasm.asm +++ b/libavcodec/x86/dsputil_yasm.asm @@ -28,7 +28,7 @@ pb_zzzzzzzz77777777: times 8 db -1 pb_7: times 8 db 7 pb_zzzz3333zzzzbbbb: db -1,-1,-1,-1,3,3,3,3,-1,-1,-1,-1,11,11,11,11 pb_zz11zz55zz99zzdd: db -1,-1,1,1,-1,-1,5,5,-1,-1,9,9,-1,-1,13,13 -pb_revwords: db 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1 +pb_revwords: SHUFFLE_MASK_W 7, 6, 5, 4, 3, 2, 1, 0 pd_16384: times 4 dd 16384 pb_bswap32: db 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12 diff --git a/libavutil/x86/x86util.asm b/libavutil/x86/x86util.asm index 941ec76084..8450acd87c 100644 --- a/libavutil/x86/x86util.asm +++ b/libavutil/x86/x86util.asm @@ -625,3 +625,15 @@ shufps %1, %1, 0 %endif %endmacro + +%macro SHUFFLE_MASK_W 8 + %rep 8 + %if %1>=0x80 + db %1, %1 + %else + db %1*2 + db %1*2+1 + %endif + %rotate 1 + %endrep +%endmacro -- cgit v1.2.3 From a35738f424164c23eea6b6e3f820e5cd3bab64fb Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 22 Jul 2012 14:37:24 -0400 Subject: dsputil: ppc: cosmetics: pretty-print --- libavcodec/ppc/fmtconvert_altivec.c | 126 ++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/libavcodec/ppc/fmtconvert_altivec.c b/libavcodec/ppc/fmtconvert_altivec.c index 20a05d7f8f..9759a2bf87 100644 --- a/libavcodec/ppc/fmtconvert_altivec.c +++ b/libavcodec/ppc/fmtconvert_altivec.c @@ -23,7 +23,8 @@ #include "libavutil/ppc/util_altivec.h" #include "dsputil_altivec.h" -static void int32_to_float_fmul_scalar_altivec(float *dst, const int *src, float mul, int len) +static void int32_to_float_fmul_scalar_altivec(float *dst, const int *src, + float mul, int len) { union { vector float v; @@ -36,7 +37,7 @@ static void int32_to_float_fmul_scalar_altivec(float *dst, const int *src, float mul_u.s[0] = mul; mul_v = vec_splat(mul_u.v, 0); - for(i=0; iint32_to_float_fmul_scalar = int32_to_float_fmul_scalar_altivec; - if(!(avctx->flags & CODEC_FLAG_BITEXACT)) { + if (!(avctx->flags & CODEC_FLAG_BITEXACT)) { c->float_to_int16 = float_to_int16_altivec; c->float_to_int16_interleave = float_to_int16_interleave_altivec; } -- cgit v1.2.3 From a6e922ffa2fdcc467d07fd6454a4557625c750ad Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 22 Jul 2012 14:01:21 -0700 Subject: swscale: place inline assembly bilinear scaler under HAVE_INLINE_ASM. --- libswscale/utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index d8fee588a0..a6b5a186fd 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -576,7 +576,7 @@ fail: return ret; } -#if HAVE_MMX2 +#if HAVE_MMX2 && HAVE_INLINE_ASM static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits) { @@ -739,7 +739,7 @@ static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode, return fragmentPos + 1; } -#endif /* HAVE_MMX2 */ +#endif /* HAVE_MMX2 && HAVE_INLINE_ASM */ static void getSubSampleFactors(int *h, int *v, enum PixelFormat format) { @@ -971,7 +971,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, (FFALIGN(srcW, 16) * 2 * FFALIGN(c->srcBpc, 8) >> 3) + 16, fail); - if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && + if (HAVE_MMX2 && HAVE_INLINE_ASM && cpu_flags & AV_CPU_FLAG_MMX2 && c->srcBpc == 8 && c->dstBpc <= 10) { c->canMMX2BeUsed = (dstW >= srcW && (dstW & 31) == 0 && (srcW & 15) == 0) ? 1 : 0; @@ -1010,7 +1010,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) /* precalculate horizontal scaler filter coefficients */ { -#if HAVE_MMX2 +#if HAVE_MMX2 && HAVE_INLINE_ASM // can't downscale !!! if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { c->lumMmx2FilterCodeSize = initMMX2HScaler(dstW, c->lumXInc, NULL, @@ -1046,7 +1046,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); #endif } else -#endif /* HAVE_MMX2 */ +#endif /* HAVE_MMX2 && HAVE_INLINE_ASM */ { const int filterAlign = (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 4 : -- cgit v1.2.3 From fd4872184945ff4275f04f7b95ee7aba49407f3c Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 21 Jul 2012 16:44:26 -0700 Subject: lavf: use conditional notation for default codec in muxer declarations. This removes the use of macro nesting in these code constructs, which makes it easier to parse in pre-processors. --- libavformat/asfenc.c | 12 ++---------- libavformat/avienc.c | 6 +----- libavformat/flvenc.c | 6 +----- libavformat/matroskaenc.c | 21 ++++++--------------- libavformat/movenc.c | 21 ++++++--------------- libavformat/nutenc.c | 9 ++------- 6 files changed, 18 insertions(+), 57 deletions(-) diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index e45232dea4..a8814eba53 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -884,11 +884,7 @@ AVOutputFormat ff_asf_muxer = { .mime_type = "video/x-ms-asf", .extensions = "asf,wmv,wma", .priv_data_size = sizeof(ASFContext), -#if CONFIG_LIBMP3LAME - .audio_codec = CODEC_ID_MP3, -#else - .audio_codec = CODEC_ID_MP2, -#endif + .audio_codec = CONFIG_LIBMP3LAME ? CODEC_ID_MP3 : CODEC_ID_MP2, .video_codec = CODEC_ID_MSMPEG4V3, .write_header = asf_write_header, .write_packet = asf_write_packet, @@ -907,11 +903,7 @@ AVOutputFormat ff_asf_stream_muxer = { .mime_type = "video/x-ms-asf", .extensions = "asf,wmv,wma", .priv_data_size = sizeof(ASFContext), -#if CONFIG_LIBMP3LAME - .audio_codec = CODEC_ID_MP3, -#else - .audio_codec = CODEC_ID_MP2, -#endif + .audio_codec = CONFIG_LIBMP3LAME ? CODEC_ID_MP3 : CODEC_ID_MP2, .video_codec = CODEC_ID_MSMPEG4V3, .write_header = asf_write_stream_header, .write_packet = asf_write_packet, diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 3689f57f11..e611dcaae2 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -645,11 +645,7 @@ AVOutputFormat ff_avi_muxer = { .mime_type = "video/x-msvideo", .extensions = "avi", .priv_data_size = sizeof(AVIContext), -#if CONFIG_LIBMP3LAME_ENCODER - .audio_codec = CODEC_ID_MP3, -#else - .audio_codec = CODEC_ID_AC3, -#endif + .audio_codec = CONFIG_LIBMP3LAME ? CODEC_ID_MP3 : CODEC_ID_AC3, .video_codec = CODEC_ID_MPEG4, .write_header = avi_write_header, .write_packet = avi_write_packet, diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index d77507dd62..ce1a4e45cc 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -546,11 +546,7 @@ AVOutputFormat ff_flv_muxer = { .mime_type = "video/x-flv", .extensions = "flv", .priv_data_size = sizeof(FLVContext), -#if CONFIG_LIBMP3LAME - .audio_codec = CODEC_ID_MP3, -#else // CONFIG_LIBMP3LAME - .audio_codec = CODEC_ID_ADPCM_SWF, -#endif // CONFIG_LIBMP3LAME + .audio_codec = CONFIG_LIBMP3LAME ? CODEC_ID_MP3 : CODEC_ID_ADPCM_SWF, .video_codec = CODEC_ID_FLV1, .write_header = flv_write_header, .write_packet = flv_write_packet, diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 61a91d7117..4504d295ea 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1292,16 +1292,10 @@ AVOutputFormat ff_matroska_muxer = { .mime_type = "video/x-matroska", .extensions = "mkv", .priv_data_size = sizeof(MatroskaMuxContext), -#if CONFIG_LIBVORBIS_ENCODER - .audio_codec = CODEC_ID_VORBIS, -#else - .audio_codec = CODEC_ID_AC3, -#endif -#if CONFIG_LIBX264_ENCODER - .video_codec = CODEC_ID_H264, -#else - .video_codec = CODEC_ID_MPEG4, -#endif + .audio_codec = CONFIG_LIBVORBIS_ENCODER ? + CODEC_ID_VORBIS : CODEC_ID_AC3, + .video_codec = CONFIG_LIBX264_ENCODER ? + CODEC_ID_H264 : CODEC_ID_MPEG4, .write_header = mkv_write_header, .write_packet = mkv_write_packet, .write_trailer = mkv_write_trailer, @@ -1339,11 +1333,8 @@ AVOutputFormat ff_matroska_audio_muxer = { .mime_type = "audio/x-matroska", .extensions = "mka", .priv_data_size = sizeof(MatroskaMuxContext), -#if CONFIG_LIBVORBIS_ENCODER - .audio_codec = CODEC_ID_VORBIS, -#else - .audio_codec = CODEC_ID_AC3, -#endif + .audio_codec = CONFIG_LIBVORBIS_ENCODER ? + CODEC_ID_VORBIS : CODEC_ID_AC3, .video_codec = CODEC_ID_NONE, .write_header = mkv_write_header, .write_packet = mkv_write_packet, diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 2a5f1d7a3c..a97045cfc5 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3252,11 +3252,8 @@ AVOutputFormat ff_mov_muxer = { .extensions = "mov", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, -#if CONFIG_LIBX264_ENCODER - .video_codec = CODEC_ID_H264, -#else - .video_codec = CODEC_ID_MPEG4, -#endif + .video_codec = CONFIG_LIBX264_ENCODER ? + CODEC_ID_H264 : CODEC_ID_MPEG4, .write_header = mov_write_header, .write_packet = mov_write_packet, .write_trailer = mov_write_trailer, @@ -3293,11 +3290,8 @@ AVOutputFormat ff_mp4_muxer = { .extensions = "mp4", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, -#if CONFIG_LIBX264_ENCODER - .video_codec = CODEC_ID_H264, -#else - .video_codec = CODEC_ID_MPEG4, -#endif + .video_codec = CONFIG_LIBX264_ENCODER ? + CODEC_ID_H264 : CODEC_ID_MPEG4, .write_header = mov_write_header, .write_packet = mov_write_packet, .write_trailer = mov_write_trailer, @@ -3314,11 +3308,8 @@ AVOutputFormat ff_psp_muxer = { .extensions = "mp4,psp", .priv_data_size = sizeof(MOVMuxContext), .audio_codec = CODEC_ID_AAC, -#if CONFIG_LIBX264_ENCODER - .video_codec = CODEC_ID_H264, -#else - .video_codec = CODEC_ID_MPEG4, -#endif + .video_codec = CONFIG_LIBX264_ENCODER ? + CODEC_ID_H264 : CODEC_ID_MPEG4, .write_header = mov_write_header, .write_packet = mov_write_packet, .write_trailer = mov_write_trailer, diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 21af7ca9cf..76d5852ce0 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -866,13 +866,8 @@ AVOutputFormat ff_nut_muxer = { .mime_type = "video/x-nut", .extensions = "nut", .priv_data_size = sizeof(NUTContext), -#if CONFIG_LIBVORBIS - .audio_codec = CODEC_ID_VORBIS, -#elif CONFIG_LIBMP3LAME - .audio_codec = CODEC_ID_MP3, -#else - .audio_codec = CODEC_ID_MP2, -#endif + .audio_codec = CONFIG_LIBVORBIS ? CODEC_ID_VORBIS : + CONFIG_LIBMP3LAME ? CODEC_ID_MP3 : CODEC_ID_MP2, .video_codec = CODEC_ID_MPEG4, .write_header = nut_write_header, .write_packet = nut_write_packet, -- cgit v1.2.3 From 16d2a1a51c1dbdd69ee47b19c8ab66b905b7c5ce Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 21 Jul 2012 22:33:03 +0200 Subject: swscale: x86: Drop pointless _mmx suffix from filenames The files do not contain only MMX code. --- libswscale/x86/Makefile | 4 +- libswscale/x86/swscale.c | 493 +++++++++++++++++++++++++++++++++++++++++++ libswscale/x86/swscale_mmx.c | 493 ------------------------------------------- libswscale/x86/yuv2rgb.c | 114 ++++++++++ libswscale/x86/yuv2rgb_mmx.c | 114 ---------- 5 files changed, 609 insertions(+), 609 deletions(-) create mode 100644 libswscale/x86/swscale.c delete mode 100644 libswscale/x86/swscale_mmx.c create mode 100644 libswscale/x86/yuv2rgb.c delete mode 100644 libswscale/x86/yuv2rgb_mmx.c diff --git a/libswscale/x86/Makefile b/libswscale/x86/Makefile index 7f3779983d..5416d48a4c 100644 --- a/libswscale/x86/Makefile +++ b/libswscale/x86/Makefile @@ -1,8 +1,8 @@ OBJS-$(CONFIG_XMM_CLOBBER_TEST) += x86/w64xmmtest.o MMX-OBJS += x86/rgb2rgb.o \ - x86/swscale_mmx.o \ - x86/yuv2rgb_mmx.o \ + x86/swscale.o \ + x86/yuv2rgb.o \ YASM-OBJS += x86/input.o \ x86/output.o \ diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c new file mode 100644 index 0000000000..b57b7a4c58 --- /dev/null +++ b/libswscale/x86/swscale.c @@ -0,0 +1,493 @@ +/* + * Copyright (C) 2001-2003 Michael Niedermayer + * + * 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 +#include "config.h" +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/x86_cpu.h" +#include "libavutil/cpu.h" +#include "libavutil/pixdesc.h" + +#if HAVE_INLINE_ASM + +#define DITHER1XBPP + +DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; +DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; +DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; +DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL; + +const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = { + 0x0103010301030103LL, + 0x0200020002000200LL,}; + +const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = { + 0x0602060206020602LL, + 0x0004000400040004LL,}; + +DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL; +DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL; +DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL; +DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL; +DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL; +DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL; + +DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL; +DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL; +DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL; + +#ifdef FAST_BGR2YV12 +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL; +#else +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL; +#endif /* FAST_BGR2YV12 */ +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; + +//MMX versions +#if HAVE_MMX +#undef RENAME +#define COMPILE_TEMPLATE_MMX2 0 +#define RENAME(a) a ## _MMX +#include "swscale_template.c" +#endif + +//MMX2 versions +#if HAVE_MMX2 +#undef RENAME +#undef COMPILE_TEMPLATE_MMX2 +#define COMPILE_TEMPLATE_MMX2 1 +#define RENAME(a) a ## _MMX2 +#include "swscale_template.c" +#endif + +void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, + int lastInLumBuf, int lastInChrBuf) +{ + const int dstH= c->dstH; + const int flags= c->flags; + int16_t **lumPixBuf= c->lumPixBuf; + int16_t **chrUPixBuf= c->chrUPixBuf; + int16_t **alpPixBuf= c->alpPixBuf; + const int vLumBufSize= c->vLumBufSize; + const int vChrBufSize= c->vChrBufSize; + int32_t *vLumFilterPos= c->vLumFilterPos; + int32_t *vChrFilterPos= c->vChrFilterPos; + int16_t *vLumFilter= c->vLumFilter; + int16_t *vChrFilter= c->vChrFilter; + int32_t *lumMmxFilter= c->lumMmxFilter; + int32_t *chrMmxFilter= c->chrMmxFilter; + int32_t av_unused *alpMmxFilter= c->alpMmxFilter; + const int vLumFilterSize= c->vLumFilterSize; + const int vChrFilterSize= c->vChrFilterSize; + const int chrDstY= dstY>>c->chrDstVSubSample; + const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input + const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input + + c->blueDither= ff_dither8[dstY&1]; + if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) + c->greenDither= ff_dither8[dstY&1]; + else + c->greenDither= ff_dither4[dstY&1]; + c->redDither= ff_dither8[(dstY+1)&1]; + if (dstY < dstH - 2) { + const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; + const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; + const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; + int i; + + if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) { + const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize; + int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize); + for (i = 0; i < neg; i++) + tmpY[i] = lumSrcPtr[neg]; + for ( ; i < end; i++) + tmpY[i] = lumSrcPtr[i]; + for ( ; i < vLumFilterSize; i++) + tmpY[i] = tmpY[i-1]; + lumSrcPtr = tmpY; + + if (alpSrcPtr) { + const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize; + for (i = 0; i < neg; i++) + tmpA[i] = alpSrcPtr[neg]; + for ( ; i < end; i++) + tmpA[i] = alpSrcPtr[i]; + for ( ; i < vLumFilterSize; i++) + tmpA[i] = tmpA[i - 1]; + alpSrcPtr = tmpA; + } + } + if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) { + const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize; + int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize); + for (i = 0; i < neg; i++) { + tmpU[i] = chrUSrcPtr[neg]; + } + for ( ; i < end; i++) { + tmpU[i] = chrUSrcPtr[i]; + } + for ( ; i < vChrFilterSize; i++) { + tmpU[i] = tmpU[i - 1]; + } + chrUSrcPtr = tmpU; + } + + if (flags & SWS_ACCURATE_RND) { + int s= APCK_SIZE / 8; + for (i=0; i1)]; + lumMmxFilter[s*i+APCK_COEF/4 ]= + lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] + + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); + if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { + *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; + *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; + alpMmxFilter[s*i+APCK_COEF/4 ]= + alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; + } + } + for (i=0; i1)]; + chrMmxFilter[s*i+APCK_COEF/4 ]= + chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] + + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); + } + } else { + for (i=0; isrcBpc == 8) { \ + hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \ + ff_hscale8to19_ ## filtersize ## _ ## opt1; \ + } else if (c->srcBpc == 9) { \ + hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \ + ff_hscale9to19_ ## filtersize ## _ ## opt1; \ + } else if (c->srcBpc == 10) { \ + hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \ + ff_hscale10to19_ ## filtersize ## _ ## opt1; \ + } else /* c->srcBpc == 16 */ { \ + hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \ + ff_hscale16to19_ ## filtersize ## _ ## opt1; \ + } \ +} while (0) +#define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ + switch (filtersize) { \ + case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ + case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ + default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \ + } +#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \ +switch(c->dstBpc){ \ + case 16: do_16_case; break; \ + case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \ + case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \ + default: if (condition_8bit) vscalefn = ff_yuv2planeX_8_ ## opt; break; \ + } +#define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \ + switch(c->dstBpc){ \ + case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \ + case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \ + case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \ + default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \ + } +#define case_rgb(x, X, opt) \ + case PIX_FMT_ ## X: \ + c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \ + if (!c->chrSrcHSubSample) \ + c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \ + break +#if ARCH_X86_32 + if (cpu_flags & AV_CPU_FLAG_MMX) { + ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx); + ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx); + ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMX2); + + switch (c->srcFormat) { + case PIX_FMT_Y400A: + c->lumToYV12 = ff_yuyvToY_mmx; + if (c->alpPixBuf) + c->alpToYV12 = ff_uyvyToY_mmx; + break; + case PIX_FMT_YUYV422: + c->lumToYV12 = ff_yuyvToY_mmx; + c->chrToYV12 = ff_yuyvToUV_mmx; + break; + case PIX_FMT_UYVY422: + c->lumToYV12 = ff_uyvyToY_mmx; + c->chrToYV12 = ff_uyvyToUV_mmx; + break; + case PIX_FMT_NV12: + c->chrToYV12 = ff_nv12ToUV_mmx; + break; + case PIX_FMT_NV21: + c->chrToYV12 = ff_nv21ToUV_mmx; + break; + case_rgb(rgb24, RGB24, mmx); + case_rgb(bgr24, BGR24, mmx); + case_rgb(bgra, BGRA, mmx); + case_rgb(rgba, RGBA, mmx); + case_rgb(abgr, ABGR, mmx); + case_rgb(argb, ARGB, mmx); + default: + break; + } + } + if (cpu_flags & AV_CPU_FLAG_MMX2) { + ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2, , 1); + } +#endif +#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ + switch (filtersize) { \ + case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ + case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ + default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \ + else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \ + break; \ + } + if (cpu_flags & AV_CPU_FLAG_SSE2) { + ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2); + ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2); + ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, , + HAVE_ALIGNED_STACK || ARCH_X86_64); + ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1); + + switch (c->srcFormat) { + case PIX_FMT_Y400A: + c->lumToYV12 = ff_yuyvToY_sse2; + if (c->alpPixBuf) + c->alpToYV12 = ff_uyvyToY_sse2; + break; + case PIX_FMT_YUYV422: + c->lumToYV12 = ff_yuyvToY_sse2; + c->chrToYV12 = ff_yuyvToUV_sse2; + break; + case PIX_FMT_UYVY422: + c->lumToYV12 = ff_uyvyToY_sse2; + c->chrToYV12 = ff_uyvyToUV_sse2; + break; + case PIX_FMT_NV12: + c->chrToYV12 = ff_nv12ToUV_sse2; + break; + case PIX_FMT_NV21: + c->chrToYV12 = ff_nv21ToUV_sse2; + break; + case_rgb(rgb24, RGB24, sse2); + case_rgb(bgr24, BGR24, sse2); + case_rgb(bgra, BGRA, sse2); + case_rgb(rgba, RGBA, sse2); + case_rgb(abgr, ABGR, sse2); + case_rgb(argb, ARGB, sse2); + default: + break; + } + } + if (cpu_flags & AV_CPU_FLAG_SSSE3) { + ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3); + ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3); + switch (c->srcFormat) { + case_rgb(rgb24, RGB24, ssse3); + case_rgb(bgr24, BGR24, ssse3); + default: + break; + } + } + if (cpu_flags & AV_CPU_FLAG_SSE4) { + /* Xto15 don't need special sse4 functions */ + ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3); + ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3); + ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4, + if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4, + HAVE_ALIGNED_STACK || ARCH_X86_64); + if (c->dstBpc == 16 && !isBE(c->dstFormat)) + c->yuv2plane1 = ff_yuv2plane1_16_sse4; + } + + if (cpu_flags & AV_CPU_FLAG_AVX) { + ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, , + HAVE_ALIGNED_STACK || ARCH_X86_64); + ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1); + + switch (c->srcFormat) { + case PIX_FMT_YUYV422: + c->chrToYV12 = ff_yuyvToUV_avx; + break; + case PIX_FMT_UYVY422: + c->chrToYV12 = ff_uyvyToUV_avx; + break; + case PIX_FMT_NV12: + c->chrToYV12 = ff_nv12ToUV_avx; + break; + case PIX_FMT_NV21: + c->chrToYV12 = ff_nv21ToUV_avx; + break; + case_rgb(rgb24, RGB24, avx); + case_rgb(bgr24, BGR24, avx); + case_rgb(bgra, BGRA, avx); + case_rgb(rgba, RGBA, avx); + case_rgb(abgr, ABGR, avx); + case_rgb(argb, ARGB, avx); + default: + break; + } + } +#endif +} diff --git a/libswscale/x86/swscale_mmx.c b/libswscale/x86/swscale_mmx.c deleted file mode 100644 index b57b7a4c58..0000000000 --- a/libswscale/x86/swscale_mmx.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Copyright (C) 2001-2003 Michael Niedermayer - * - * 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 -#include "config.h" -#include "libswscale/swscale.h" -#include "libswscale/swscale_internal.h" -#include "libavutil/intreadwrite.h" -#include "libavutil/x86_cpu.h" -#include "libavutil/cpu.h" -#include "libavutil/pixdesc.h" - -#if HAVE_INLINE_ASM - -#define DITHER1XBPP - -DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; -DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; -DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; -DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL; - -const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = { - 0x0103010301030103LL, - 0x0200020002000200LL,}; - -const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = { - 0x0602060206020602LL, - 0x0004000400040004LL,}; - -DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL; -DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL; -DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL; -DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL; -DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL; -DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL; - -DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL; -DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL; -DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL; - -#ifdef FAST_BGR2YV12 -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL; -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL; -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL; -#else -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL; -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL; -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL; -#endif /* FAST_BGR2YV12 */ -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL; -DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL; -DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; - -//MMX versions -#if HAVE_MMX -#undef RENAME -#define COMPILE_TEMPLATE_MMX2 0 -#define RENAME(a) a ## _MMX -#include "swscale_template.c" -#endif - -//MMX2 versions -#if HAVE_MMX2 -#undef RENAME -#undef COMPILE_TEMPLATE_MMX2 -#define COMPILE_TEMPLATE_MMX2 1 -#define RENAME(a) a ## _MMX2 -#include "swscale_template.c" -#endif - -void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, - int lastInLumBuf, int lastInChrBuf) -{ - const int dstH= c->dstH; - const int flags= c->flags; - int16_t **lumPixBuf= c->lumPixBuf; - int16_t **chrUPixBuf= c->chrUPixBuf; - int16_t **alpPixBuf= c->alpPixBuf; - const int vLumBufSize= c->vLumBufSize; - const int vChrBufSize= c->vChrBufSize; - int32_t *vLumFilterPos= c->vLumFilterPos; - int32_t *vChrFilterPos= c->vChrFilterPos; - int16_t *vLumFilter= c->vLumFilter; - int16_t *vChrFilter= c->vChrFilter; - int32_t *lumMmxFilter= c->lumMmxFilter; - int32_t *chrMmxFilter= c->chrMmxFilter; - int32_t av_unused *alpMmxFilter= c->alpMmxFilter; - const int vLumFilterSize= c->vLumFilterSize; - const int vChrFilterSize= c->vChrFilterSize; - const int chrDstY= dstY>>c->chrDstVSubSample; - const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input - const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input - - c->blueDither= ff_dither8[dstY&1]; - if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) - c->greenDither= ff_dither8[dstY&1]; - else - c->greenDither= ff_dither4[dstY&1]; - c->redDither= ff_dither8[(dstY+1)&1]; - if (dstY < dstH - 2) { - const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; - const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; - const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; - int i; - - if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) { - const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize; - int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize); - for (i = 0; i < neg; i++) - tmpY[i] = lumSrcPtr[neg]; - for ( ; i < end; i++) - tmpY[i] = lumSrcPtr[i]; - for ( ; i < vLumFilterSize; i++) - tmpY[i] = tmpY[i-1]; - lumSrcPtr = tmpY; - - if (alpSrcPtr) { - const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize; - for (i = 0; i < neg; i++) - tmpA[i] = alpSrcPtr[neg]; - for ( ; i < end; i++) - tmpA[i] = alpSrcPtr[i]; - for ( ; i < vLumFilterSize; i++) - tmpA[i] = tmpA[i - 1]; - alpSrcPtr = tmpA; - } - } - if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) { - const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize; - int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize); - for (i = 0; i < neg; i++) { - tmpU[i] = chrUSrcPtr[neg]; - } - for ( ; i < end; i++) { - tmpU[i] = chrUSrcPtr[i]; - } - for ( ; i < vChrFilterSize; i++) { - tmpU[i] = tmpU[i - 1]; - } - chrUSrcPtr = tmpU; - } - - if (flags & SWS_ACCURATE_RND) { - int s= APCK_SIZE / 8; - for (i=0; i1)]; - lumMmxFilter[s*i+APCK_COEF/4 ]= - lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] - + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); - if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { - *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; - *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; - alpMmxFilter[s*i+APCK_COEF/4 ]= - alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; - } - } - for (i=0; i1)]; - chrMmxFilter[s*i+APCK_COEF/4 ]= - chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] - + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); - } - } else { - for (i=0; isrcBpc == 8) { \ - hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \ - ff_hscale8to19_ ## filtersize ## _ ## opt1; \ - } else if (c->srcBpc == 9) { \ - hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \ - ff_hscale9to19_ ## filtersize ## _ ## opt1; \ - } else if (c->srcBpc == 10) { \ - hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \ - ff_hscale10to19_ ## filtersize ## _ ## opt1; \ - } else /* c->srcBpc == 16 */ { \ - hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \ - ff_hscale16to19_ ## filtersize ## _ ## opt1; \ - } \ -} while (0) -#define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ - switch (filtersize) { \ - case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ - case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ - default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \ - } -#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \ -switch(c->dstBpc){ \ - case 16: do_16_case; break; \ - case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \ - case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \ - default: if (condition_8bit) vscalefn = ff_yuv2planeX_8_ ## opt; break; \ - } -#define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \ - switch(c->dstBpc){ \ - case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \ - case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \ - case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \ - default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \ - } -#define case_rgb(x, X, opt) \ - case PIX_FMT_ ## X: \ - c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \ - if (!c->chrSrcHSubSample) \ - c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \ - break -#if ARCH_X86_32 - if (cpu_flags & AV_CPU_FLAG_MMX) { - ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx); - ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx); - ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMX2); - - switch (c->srcFormat) { - case PIX_FMT_Y400A: - c->lumToYV12 = ff_yuyvToY_mmx; - if (c->alpPixBuf) - c->alpToYV12 = ff_uyvyToY_mmx; - break; - case PIX_FMT_YUYV422: - c->lumToYV12 = ff_yuyvToY_mmx; - c->chrToYV12 = ff_yuyvToUV_mmx; - break; - case PIX_FMT_UYVY422: - c->lumToYV12 = ff_uyvyToY_mmx; - c->chrToYV12 = ff_uyvyToUV_mmx; - break; - case PIX_FMT_NV12: - c->chrToYV12 = ff_nv12ToUV_mmx; - break; - case PIX_FMT_NV21: - c->chrToYV12 = ff_nv21ToUV_mmx; - break; - case_rgb(rgb24, RGB24, mmx); - case_rgb(bgr24, BGR24, mmx); - case_rgb(bgra, BGRA, mmx); - case_rgb(rgba, RGBA, mmx); - case_rgb(abgr, ABGR, mmx); - case_rgb(argb, ARGB, mmx); - default: - break; - } - } - if (cpu_flags & AV_CPU_FLAG_MMX2) { - ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2, , 1); - } -#endif -#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ - switch (filtersize) { \ - case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ - case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ - default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \ - else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \ - break; \ - } - if (cpu_flags & AV_CPU_FLAG_SSE2) { - ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2); - ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2); - ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, , - HAVE_ALIGNED_STACK || ARCH_X86_64); - ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1); - - switch (c->srcFormat) { - case PIX_FMT_Y400A: - c->lumToYV12 = ff_yuyvToY_sse2; - if (c->alpPixBuf) - c->alpToYV12 = ff_uyvyToY_sse2; - break; - case PIX_FMT_YUYV422: - c->lumToYV12 = ff_yuyvToY_sse2; - c->chrToYV12 = ff_yuyvToUV_sse2; - break; - case PIX_FMT_UYVY422: - c->lumToYV12 = ff_uyvyToY_sse2; - c->chrToYV12 = ff_uyvyToUV_sse2; - break; - case PIX_FMT_NV12: - c->chrToYV12 = ff_nv12ToUV_sse2; - break; - case PIX_FMT_NV21: - c->chrToYV12 = ff_nv21ToUV_sse2; - break; - case_rgb(rgb24, RGB24, sse2); - case_rgb(bgr24, BGR24, sse2); - case_rgb(bgra, BGRA, sse2); - case_rgb(rgba, RGBA, sse2); - case_rgb(abgr, ABGR, sse2); - case_rgb(argb, ARGB, sse2); - default: - break; - } - } - if (cpu_flags & AV_CPU_FLAG_SSSE3) { - ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3); - ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3); - switch (c->srcFormat) { - case_rgb(rgb24, RGB24, ssse3); - case_rgb(bgr24, BGR24, ssse3); - default: - break; - } - } - if (cpu_flags & AV_CPU_FLAG_SSE4) { - /* Xto15 don't need special sse4 functions */ - ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3); - ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3); - ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4, - if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4, - HAVE_ALIGNED_STACK || ARCH_X86_64); - if (c->dstBpc == 16 && !isBE(c->dstFormat)) - c->yuv2plane1 = ff_yuv2plane1_16_sse4; - } - - if (cpu_flags & AV_CPU_FLAG_AVX) { - ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, , - HAVE_ALIGNED_STACK || ARCH_X86_64); - ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1); - - switch (c->srcFormat) { - case PIX_FMT_YUYV422: - c->chrToYV12 = ff_yuyvToUV_avx; - break; - case PIX_FMT_UYVY422: - c->chrToYV12 = ff_uyvyToUV_avx; - break; - case PIX_FMT_NV12: - c->chrToYV12 = ff_nv12ToUV_avx; - break; - case PIX_FMT_NV21: - c->chrToYV12 = ff_nv21ToUV_avx; - break; - case_rgb(rgb24, RGB24, avx); - case_rgb(bgr24, BGR24, avx); - case_rgb(bgra, BGRA, avx); - case_rgb(rgba, RGBA, avx); - case_rgb(abgr, ABGR, avx); - case_rgb(argb, ARGB, avx); - default: - break; - } - } -#endif -} diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c new file mode 100644 index 0000000000..f534e0e6bd --- /dev/null +++ b/libswscale/x86/yuv2rgb.c @@ -0,0 +1,114 @@ +/* + * software YUV to RGB converter + * + * Copyright (C) 2009 Konstantin Shishkov + * + * MMX/MMX2 template stuff (needed for fast movntq support), + * 1,4,8bpp support and context / deglobalize stuff + * by Michael Niedermayer (michaelni@gmx.at) + * + * 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 +#include +#include +#include + +#include "config.h" +#include "libswscale/rgb2rgb.h" +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" +#include "libavutil/x86_cpu.h" +#include "libavutil/cpu.h" + +#if HAVE_INLINE_ASM + +#define DITHER1XBPP // only for MMX + +/* hope these constant values are cache line aligned */ +DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL; +DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL; +DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL; +DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL; + +//MMX versions +#if HAVE_MMX +#undef RENAME +#undef COMPILE_TEMPLATE_MMX2 +#define COMPILE_TEMPLATE_MMX2 0 +#define RENAME(a) a ## _MMX +#include "yuv2rgb_template.c" +#endif /* HAVE_MMX */ + +//MMX2 versions +#if HAVE_MMX2 +#undef RENAME +#undef COMPILE_TEMPLATE_MMX2 +#define COMPILE_TEMPLATE_MMX2 1 +#define RENAME(a) a ## _MMX2 +#include "yuv2rgb_template.c" +#endif /* HAVE_MMX2 */ + +#endif /* HAVE_INLINE_ASM */ + +SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) +{ +#if HAVE_INLINE_ASM + int cpu_flags = av_get_cpu_flags(); + + if (c->srcFormat != PIX_FMT_YUV420P && + c->srcFormat != PIX_FMT_YUVA420P) + return NULL; + +#if HAVE_MMX2 + if (cpu_flags & AV_CPU_FLAG_MMX2) { + switch (c->dstFormat) { + case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; + case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; + } + } +#endif + + if (cpu_flags & AV_CPU_FLAG_MMX) { + switch (c->dstFormat) { + case PIX_FMT_RGB32: + if (c->srcFormat == PIX_FMT_YUVA420P) { +#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA + return yuva420_rgb32_MMX; +#endif + break; + } else return yuv420_rgb32_MMX; + case PIX_FMT_BGR32: + if (c->srcFormat == PIX_FMT_YUVA420P) { +#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA + return yuva420_bgr32_MMX; +#endif + break; + } else return yuv420_bgr32_MMX; + case PIX_FMT_RGB24: return yuv420_rgb24_MMX; + case PIX_FMT_BGR24: return yuv420_bgr24_MMX; + case PIX_FMT_RGB565: return yuv420_rgb16_MMX; + case PIX_FMT_RGB555: return yuv420_rgb15_MMX; + } + } +#endif /* HAVE_INLINE_ASM */ + + return NULL; +} diff --git a/libswscale/x86/yuv2rgb_mmx.c b/libswscale/x86/yuv2rgb_mmx.c deleted file mode 100644 index f534e0e6bd..0000000000 --- a/libswscale/x86/yuv2rgb_mmx.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * software YUV to RGB converter - * - * Copyright (C) 2009 Konstantin Shishkov - * - * MMX/MMX2 template stuff (needed for fast movntq support), - * 1,4,8bpp support and context / deglobalize stuff - * by Michael Niedermayer (michaelni@gmx.at) - * - * 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 -#include -#include -#include - -#include "config.h" -#include "libswscale/rgb2rgb.h" -#include "libswscale/swscale.h" -#include "libswscale/swscale_internal.h" -#include "libavutil/x86_cpu.h" -#include "libavutil/cpu.h" - -#if HAVE_INLINE_ASM - -#define DITHER1XBPP // only for MMX - -/* hope these constant values are cache line aligned */ -DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL; -DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL; -DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL; -DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL; -DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL; -DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL; - -//MMX versions -#if HAVE_MMX -#undef RENAME -#undef COMPILE_TEMPLATE_MMX2 -#define COMPILE_TEMPLATE_MMX2 0 -#define RENAME(a) a ## _MMX -#include "yuv2rgb_template.c" -#endif /* HAVE_MMX */ - -//MMX2 versions -#if HAVE_MMX2 -#undef RENAME -#undef COMPILE_TEMPLATE_MMX2 -#define COMPILE_TEMPLATE_MMX2 1 -#define RENAME(a) a ## _MMX2 -#include "yuv2rgb_template.c" -#endif /* HAVE_MMX2 */ - -#endif /* HAVE_INLINE_ASM */ - -SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) -{ -#if HAVE_INLINE_ASM - int cpu_flags = av_get_cpu_flags(); - - if (c->srcFormat != PIX_FMT_YUV420P && - c->srcFormat != PIX_FMT_YUVA420P) - return NULL; - -#if HAVE_MMX2 - if (cpu_flags & AV_CPU_FLAG_MMX2) { - switch (c->dstFormat) { - case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; - case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; - } - } -#endif - - if (cpu_flags & AV_CPU_FLAG_MMX) { - switch (c->dstFormat) { - case PIX_FMT_RGB32: - if (c->srcFormat == PIX_FMT_YUVA420P) { -#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA - return yuva420_rgb32_MMX; -#endif - break; - } else return yuv420_rgb32_MMX; - case PIX_FMT_BGR32: - if (c->srcFormat == PIX_FMT_YUVA420P) { -#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA - return yuva420_bgr32_MMX; -#endif - break; - } else return yuv420_bgr32_MMX; - case PIX_FMT_RGB24: return yuv420_rgb24_MMX; - case PIX_FMT_BGR24: return yuv420_bgr24_MMX; - case PIX_FMT_RGB565: return yuv420_rgb16_MMX; - case PIX_FMT_RGB555: return yuv420_rgb15_MMX; - } - } -#endif /* HAVE_INLINE_ASM */ - - return NULL; -} -- cgit v1.2.3 From 5a6e3c039c0eefaf5684c7e4e1687ccb13ae488a Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 22 Jul 2012 12:29:28 +0200 Subject: swscale: Mark all init functions as av_cold --- libswscale/output.c | 15 ++++++++------- libswscale/ppc/swscale_altivec.c | 3 ++- libswscale/ppc/yuv2rgb_altivec.c | 11 +++++++---- libswscale/rgb2rgb.c | 3 ++- libswscale/sparc/yuv2rgb_vis.c | 3 ++- libswscale/utils.c | 4 +++- libswscale/x86/rgb2rgb.c | 3 ++- libswscale/x86/swscale.c | 3 ++- libswscale/x86/yuv2rgb.c | 3 ++- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index b58bda9213..43d5435b98 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -24,6 +24,7 @@ #include #include +#include "libavutil/attributes.h" #include "libavutil/avutil.h" #include "libavutil/bswap.h" #include "libavutil/cpu.h" @@ -1260,13 +1261,13 @@ YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, PIX_FMT_ARGB, 0) YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, PIX_FMT_BGR24, 0) YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, PIX_FMT_RGB24, 0) -void ff_sws_init_output_funcs(SwsContext *c, - yuv2planar1_fn *yuv2plane1, - yuv2planarX_fn *yuv2planeX, - yuv2interleavedX_fn *yuv2nv12cX, - yuv2packed1_fn *yuv2packed1, - yuv2packed2_fn *yuv2packed2, - yuv2packedX_fn *yuv2packedX) +av_cold void ff_sws_init_output_funcs(SwsContext *c, + yuv2planar1_fn *yuv2plane1, + yuv2planarX_fn *yuv2planeX, + yuv2interleavedX_fn *yuv2nv12cX, + yuv2packed1_fn *yuv2packed1, + yuv2packed2_fn *yuv2packed2, + yuv2packedX_fn *yuv2packedX) { enum PixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c index 5537707bd0..0e66ec1f7b 100644 --- a/libswscale/ppc/swscale_altivec.c +++ b/libswscale/ppc/swscale_altivec.c @@ -26,6 +26,7 @@ #include "config.h" #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" +#include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "yuv2rgb_altivec.h" @@ -310,7 +311,7 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW, } } -void ff_sws_init_swScale_altivec(SwsContext *c) +av_cold void ff_sws_init_swScale_altivec(SwsContext *c) { enum PixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c index 3a140cb1f8..380c76f4d1 100644 --- a/libswscale/ppc/yuv2rgb_altivec.c +++ b/libswscale/ppc/yuv2rgb_altivec.c @@ -95,6 +95,7 @@ #include "libswscale/rgb2rgb.h" #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" +#include "libavutil/attributes.h" #include "libavutil/cpu.h" #include "yuv2rgb_altivec.h" @@ -535,7 +536,7 @@ static int altivec_uyvy_rgb32(SwsContext *c, const unsigned char **in, * * So we just fall back to the C codes for this. */ -SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c) { if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return NULL; @@ -595,9 +596,11 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c) return NULL; } -void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], - int brightness, int contrast, - int saturation) +av_cold void ff_yuv2rgb_init_tables_altivec(SwsContext *c, + const int inv_table[4], + int brightness, + int contrast, + int saturation) { union { DECLARE_ALIGNED(16, signed short, tmp)[8]; diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index 14b595f107..26ef64879c 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -25,6 +25,7 @@ #include +#include "libavutil/attributes.h" #include "libavutil/bswap.h" #include "config.h" #include "rgb2rgb.h" @@ -125,7 +126,7 @@ void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, * 32-bit C version, and and&add trick by Michael Niedermayer */ -void sws_rgb2rgb_init(void) +av_cold void sws_rgb2rgb_init(void) { rgb2rgb_init_c(); if (HAVE_MMX) diff --git a/libswscale/sparc/yuv2rgb_vis.c b/libswscale/sparc/yuv2rgb_vis.c index bcd2081aa8..d7102a3a45 100644 --- a/libswscale/sparc/yuv2rgb_vis.c +++ b/libswscale/sparc/yuv2rgb_vis.c @@ -22,6 +22,7 @@ #include #include +#include "libavutil/attributes.h" #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" @@ -184,7 +185,7 @@ static int vis_422P_ARGB32(SwsContext *c, uint8_t *src[], int srcStride[], return srcSliceH; } -SwsFunc ff_yuv2rgb_init_vis(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_vis(SwsContext *c) { c->sparc_coeffs[5] = c->yCoeff; c->sparc_coeffs[6] = c->vgCoeff; diff --git a/libswscale/utils.c b/libswscale/utils.c index a6b5a186fd..4960194f37 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -37,6 +37,7 @@ #include #endif +#include "libavutil/attributes.h" #include "libavutil/avutil.h" #include "libavutil/bswap.h" #include "libavutil/cpu.h" @@ -823,7 +824,8 @@ SwsContext *sws_alloc_context(void) return c; } -int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) +av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, + SwsFilter *dstFilter) { int i; int usesVFilter, usesHFilter; diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c index 353b0aab22..f940888a70 100644 --- a/libswscale/x86/rgb2rgb.c +++ b/libswscale/x86/rgb2rgb.c @@ -26,6 +26,7 @@ #include #include "config.h" +#include "libavutil/attributes.h" #include "libavutil/x86_cpu.h" #include "libavutil/cpu.h" #include "libavutil/bswap.h" @@ -127,7 +128,7 @@ DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; #endif /* HAVE_INLINE_ASM */ -void rgb2rgb_init_x86(void) +av_cold void rgb2rgb_init_x86(void) { #if HAVE_INLINE_ASM int cpu_flags = av_get_cpu_flags(); diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index b57b7a4c58..a0c18c79fc 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -22,6 +22,7 @@ #include "config.h" #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" +#include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" #include "libavutil/x86_cpu.h" #include "libavutil/cpu.h" @@ -300,7 +301,7 @@ INPUT_FUNCS(sse2); INPUT_FUNCS(ssse3); INPUT_FUNCS(avx); -void ff_sws_init_swScale_mmx(SwsContext *c) +av_cold void ff_sws_init_swScale_mmx(SwsContext *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c index f534e0e6bd..b4bcbf53c2 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -33,6 +33,7 @@ #include "libswscale/rgb2rgb.h" #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" +#include "libavutil/attributes.h" #include "libavutil/x86_cpu.h" #include "libavutil/cpu.h" @@ -68,7 +69,7 @@ DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL; #endif /* HAVE_INLINE_ASM */ -SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) { #if HAVE_INLINE_ASM int cpu_flags = av_get_cpu_flags(); -- cgit v1.2.3 From 8d2e3fee0bde0ddd075cf613630619f95517de97 Mon Sep 17 00:00:00 2001 From: Mashiat Sarker Shakkhar Date: Mon, 16 Jul 2012 07:45:23 +0000 Subject: vc1: Add a test for interlaced field pictures Signed-off-by: Derek Buitenhuis --- tests/fate/microsoft.mak | 3 +++ tests/ref/fate/vc1_sa10143 | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/ref/fate/vc1_sa10143 diff --git a/tests/fate/microsoft.mak b/tests/fate/microsoft.mak index 515f6ab6f8..48bdb95389 100644 --- a/tests/fate/microsoft.mak +++ b/tests/fate/microsoft.mak @@ -32,6 +32,9 @@ fate-vc1_sa10091: CMD = framecrc -i $(SAMPLES)/vc1/SA10091.vc1 FATE_VC1 += fate-vc1_sa20021 fate-vc1_sa20021: CMD = framecrc -i $(SAMPLES)/vc1/SA20021.vc1 +FATE_VC1 += fate-vc1_sa10143 +fate-vc1_sa10143: CMD = framecrc -i $(SAMPLES)/vc1/SA10143.vc1 + FATE_VC1 += fate-vc1-ism fate-vc1-ism: CMD = framecrc -i $(SAMPLES)/isom/vc1-wmapro.ism -an diff --git a/tests/ref/fate/vc1_sa10143 b/tests/ref/fate/vc1_sa10143 new file mode 100644 index 0000000000..a008356cf8 --- /dev/null +++ b/tests/ref/fate/vc1_sa10143 @@ -0,0 +1,31 @@ +#tb 0: 1/25 +0, 0, 0, 1, 518400, 0x89407f55 +0, 2, 2, 1, 518400, 0xeb8d84a1 +0, 3, 3, 1, 518400, 0x2121ff57 +0, 4, 4, 1, 518400, 0xd81adb3d +0, 5, 5, 1, 518400, 0x01e36aa2 +0, 6, 6, 1, 518400, 0x6b802361 +0, 7, 7, 1, 518400, 0xc8403c77 +0, 8, 8, 1, 518400, 0xdd342b5d +0, 9, 9, 1, 518400, 0x2100eea5 +0, 10, 10, 1, 518400, 0x92a22da6 +0, 11, 11, 1, 518400, 0x6bacdef7 +0, 12, 12, 1, 518400, 0x4a00715f +0, 13, 13, 1, 518400, 0x59b98727 +0, 14, 14, 1, 518400, 0xbf912ee1 +0, 15, 15, 1, 518400, 0x8c966cd6 +0, 16, 16, 1, 518400, 0x2c9a2535 +0, 17, 17, 1, 518400, 0x29085c06 +0, 18, 18, 1, 518400, 0x46ae6b7d +0, 19, 19, 1, 518400, 0x283100f4 +0, 20, 20, 1, 518400, 0x2731b5ff +0, 21, 21, 1, 518400, 0x1132ea54 +0, 22, 22, 1, 518400, 0x37cbe539 +0, 23, 23, 1, 518400, 0x08ff75cf +0, 24, 24, 1, 518400, 0xafb6bc45 +0, 25, 25, 1, 518400, 0x19d3873d +0, 26, 26, 1, 518400, 0xd494a8be +0, 27, 27, 1, 518400, 0x285f41ef +0, 28, 28, 1, 518400, 0xd4b1ffa1 +0, 29, 29, 1, 518400, 0xc3876c3a +0, 30, 30, 1, 518400, 0xb73dbb62 -- cgit v1.2.3 From 3124886554f202edeb0578bf664e576474a5d40f Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 21 Jul 2012 17:03:12 -0700 Subject: lavfi: place x86 inline assembly under HAVE_INLINE_ASM. This allows compiling this code using compilers that do not understand gcc-style inline assembly. --- libavfilter/x86/gradfun.c | 6 ++++++ libavfilter/x86/yadif.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c index 07569de146..f75268a660 100644 --- a/libavfilter/x86/gradfun.c +++ b/libavfilter/x86/gradfun.c @@ -23,6 +23,8 @@ #include "libavutil/x86_cpu.h" #include "libavfilter/gradfun.h" +#if HAVE_INLINE_ASM + DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F}; DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; @@ -164,10 +166,13 @@ static void gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, } #endif // HAVE_SSE +#endif /* HAVE_INLINE_ASM */ + av_cold void ff_gradfun_init_x86(GradFunContext *gf) { int cpu_flags = av_get_cpu_flags(); +#if HAVE_INLINE_ASM #if HAVE_MMX2 if (cpu_flags & AV_CPU_FLAG_MMX2) gf->filter_line = gradfun_filter_line_mmx2; @@ -180,4 +185,5 @@ av_cold void ff_gradfun_init_x86(GradFunContext *gf) if (cpu_flags & AV_CPU_FLAG_SSE2) gf->blur_line = gradfun_blur_line_sse2; #endif +#endif /* HAVE_INLINE_ASM */ } diff --git a/libavfilter/x86/yadif.c b/libavfilter/x86/yadif.c index 6d9f9b2880..72b06cce0a 100644 --- a/libavfilter/x86/yadif.c +++ b/libavfilter/x86/yadif.c @@ -24,6 +24,8 @@ #include "libavcodec/x86/dsputil_mmx.h" #include "libavfilter/yadif.h" +#if HAVE_INLINE_ASM + DECLARE_ASM_CONST(16, const xmm_reg, pb_1) = {0x0101010101010101ULL, 0x0101010101010101ULL}; DECLARE_ASM_CONST(16, const xmm_reg, pw_1) = {0x0001000100010001ULL, 0x0001000100010001ULL}; @@ -49,10 +51,13 @@ DECLARE_ASM_CONST(16, const xmm_reg, pw_1) = {0x0001000100010001ULL, 0x000100010 #include "yadif_template.c" #endif +#endif /* HAVE_INLINE_ASM */ + av_cold void ff_yadif_init_x86(YADIFContext *yadif) { int cpu_flags = av_get_cpu_flags(); +#if HAVE_INLINE_ASM #if HAVE_MMX if (cpu_flags & AV_CPU_FLAG_MMX) yadif->filter_line = yadif_filter_line_mmx; @@ -65,4 +70,5 @@ av_cold void ff_yadif_init_x86(YADIFContext *yadif) if (cpu_flags & AV_CPU_FLAG_SSSE3) yadif->filter_line = yadif_filter_line_ssse3; #endif +#endif /* HAVE_INLINE_ASM */ } -- cgit v1.2.3 From 3b175384bb6491ecd44761e5282ae4c79567db57 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 22 Jul 2012 13:55:58 -0700 Subject: swscale: add missing HAVE_INLINE_ASM check. The function called in this block is under HAVE_INLINE_ASM itself also. --- libswscale/swscale.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 7ae5af37a8..5cfa7f237d 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -518,7 +518,7 @@ static int swScale(SwsContext *c, const uint8_t *src[], if (!enough_lines) break; // we can't output a dstY line so let's try with the next slice -#if HAVE_MMX +#if HAVE_MMX && HAVE_INLINE_ASM updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf); #endif -- cgit v1.2.3 From 3505d5574e1d87ab8af9ea38337bfa0a1ca6381d Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 5 Jul 2012 13:05:46 +0200 Subject: rtmp: Rename rtmp_calc_digest to ff_rtmp_calc_digest and make it global MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtmp.h | 17 ++++++++++++++++ libavformat/rtmpproto.c | 52 ++++++++++++++++++------------------------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/libavformat/rtmp.h b/libavformat/rtmp.h index f9d9900268..6a19f2e1e1 100644 --- a/libavformat/rtmp.h +++ b/libavformat/rtmp.h @@ -29,6 +29,9 @@ #define RTMP_HANDSHAKE_PACKET_SIZE 1536 +#define HMAC_IPAD_VAL 0x36 +#define HMAC_OPAD_VAL 0x5C + /** * emulated Flash client version - 9.0.124.2 on Linux * @{ @@ -40,4 +43,18 @@ #define RTMP_CLIENT_VER4 2 /** @} */ //version defines +/** + * Calculate HMAC-SHA2 digest for RTMP handshake packets. + * + * @param src input buffer + * @param len input buffer length (should be 1536) + * @param gap offset in buffer where 32 bytes should not be taken into account + * when calculating digest (since it will be used to store that digest) + * @param key digest key + * @param keylen digest key length + * @param dst buffer where calculated digest will be stored (32 bytes) + */ +int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, + const uint8_t *key, int keylen, uint8_t *dst); + #endif /* AVFORMAT_RTMP_H */ diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 5c40eb5517..42856dbf64 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -590,23 +590,8 @@ static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts) return ret; } -//TODO: Move HMAC code somewhere. Eventually. -#define HMAC_IPAD_VAL 0x36 -#define HMAC_OPAD_VAL 0x5C - -/** - * Calculate HMAC-SHA2 digest for RTMP handshake packets. - * - * @param src input buffer - * @param len input buffer length (should be 1536) - * @param gap offset in buffer where 32 bytes should not be taken into account - * when calculating digest (since it will be used to store that digest) - * @param key digest key - * @param keylen digest key length - * @param dst buffer where calculated digest will be stored (32 bytes) - */ -static int rtmp_calc_digest(const uint8_t *src, int len, int gap, - const uint8_t *key, int keylen, uint8_t *dst) +int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, + const uint8_t *key, int keylen, uint8_t *dst) { struct AVSHA *sha; uint8_t hmac_buf[64+32] = {0}; @@ -663,9 +648,9 @@ static int rtmp_handshake_imprint_with_digest(uint8_t *buf) digest_pos += buf[i]; digest_pos = (digest_pos % 728) + 12; - ret = rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, - rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN, - buf + digest_pos); + ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, + rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN, + buf + digest_pos); if (ret < 0) return ret; @@ -689,9 +674,9 @@ static int rtmp_validate_digest(uint8_t *buf, int off) digest_pos += buf[i + off]; digest_pos = (digest_pos % 728) + off + 4; - ret = rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, - rtmp_server_key, SERVER_KEY_OPEN_PART_LEN, - digest); + ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, + rtmp_server_key, SERVER_KEY_OPEN_PART_LEN, + digest); if (ret < 0) return ret; @@ -771,13 +756,14 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) } } - ret = rtmp_calc_digest(tosend + 1 + client_pos, 32, 0, rtmp_server_key, - sizeof(rtmp_server_key), digest); + ret = ff_rtmp_calc_digest(tosend + 1 + client_pos, 32, 0, + rtmp_server_key, sizeof(rtmp_server_key), + digest); if (ret < 0) return ret; - ret = rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0, - digest, 32, digest); + ret = ff_rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE - 32, + 0, digest, 32, digest); if (ret < 0) return ret; @@ -788,15 +774,15 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) for (i = 0; i < RTMP_HANDSHAKE_PACKET_SIZE; i++) tosend[i] = av_lfg_get(&rnd) >> 24; - ret = rtmp_calc_digest(serverdata + 1 + server_pos, 32, 0, - rtmp_player_key, sizeof(rtmp_player_key), - digest); + ret = ff_rtmp_calc_digest(serverdata + 1 + server_pos, 32, 0, + rtmp_player_key, sizeof(rtmp_player_key), + digest); if (ret < 0) return ret; - ret = rtmp_calc_digest(tosend, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0, - digest, 32, - tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); + ret = ff_rtmp_calc_digest(tosend, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0, + digest, 32, + tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); if (ret < 0) return ret; -- cgit v1.2.3 From 0e31088b6c57e7d495deda0abaf5de5adb2c18fa Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 5 Jul 2012 13:06:07 +0200 Subject: rtmp: Add ff_rtmp_calc_digest_pos() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function is used for calculating digest position for RTMP handshake packets. Signed-off-by: Martin Storsjö --- libavformat/rtmp.h | 11 +++++++++++ libavformat/rtmpproto.c | 26 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libavformat/rtmp.h b/libavformat/rtmp.h index 6a19f2e1e1..b9c5f1e430 100644 --- a/libavformat/rtmp.h +++ b/libavformat/rtmp.h @@ -57,4 +57,15 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, const uint8_t *key, int keylen, uint8_t *dst); +/** + * Calculate digest position for RTMP handshake packets. + * + * @param buf input buffer (should be 1536 bytes) + * @param off offset in buffer where to start calculating digest position + * @param mod_val value used for computing modulo + * @param add_val value added at the end (after computing modulo) + */ +int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, + int add_val); + #endif /* AVFORMAT_RTMP_H */ diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 42856dbf64..64704502e9 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -632,6 +632,18 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, return 0; } +int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, + int add_val) +{ + int i, digest_pos = 0; + + for (i = 0; i < 4; i++) + digest_pos += buf[i + off]; + digest_pos = digest_pos % mod_val + add_val; + + return digest_pos; +} + /** * Put HMAC-SHA2 digest of packet data (except for the bytes where this digest * will be stored) into that packet. @@ -641,12 +653,9 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, */ static int rtmp_handshake_imprint_with_digest(uint8_t *buf) { - int i, digest_pos = 0; - int ret; + int ret, digest_pos; - for (i = 8; i < 12; i++) - digest_pos += buf[i]; - digest_pos = (digest_pos % 728) + 12; + digest_pos = ff_rtmp_calc_digest_pos(buf, 8, 728, 12); ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN, @@ -666,13 +675,10 @@ static int rtmp_handshake_imprint_with_digest(uint8_t *buf) */ static int rtmp_validate_digest(uint8_t *buf, int off) { - int i, digest_pos = 0; uint8_t digest[32]; - int ret; + int ret, digest_pos; - for (i = 0; i < 4; i++) - digest_pos += buf[i + off]; - digest_pos = (digest_pos % 728) + off + 4; + digest_pos = ff_rtmp_calc_digest_pos(buf, off, 728, off + 4); ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, rtmp_server_key, SERVER_KEY_OPEN_PART_LEN, -- cgit v1.2.3 From acd554c103459ae7a5d89caa611e91bbc9bf695f Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 19 Jul 2012 14:13:58 +0200 Subject: RTMPE protocol support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds two protocols, but one of them is an internal implementation detail just used as an abstraction layer/generalization in the code. The RTMPE protocol implementation uses ffrtmpcrypt:// as an alternative to the tcp:// protocol. This allows moving most of the lower level logic out from the higher level generic rtmp code. Signed-off-by: Martin Storsjö --- Changelog | 1 + configure | 11 ++ doc/general.texi | 2 +- doc/protocols.texi | 9 ++ libavformat/Makefile | 2 + libavformat/allformats.c | 2 + libavformat/rtmpcrypt.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ libavformat/rtmpcrypt.h | 69 ++++++++++ libavformat/rtmpdh.c | 329 +++++++++++++++++++++++++++++++++++++++++++++++ libavformat/rtmpdh.h | 102 +++++++++++++++ libavformat/rtmpproto.c | 106 ++++++++++++++- libavformat/version.h | 2 +- 12 files changed, 935 insertions(+), 9 deletions(-) create mode 100644 libavformat/rtmpcrypt.c create mode 100644 libavformat/rtmpcrypt.h create mode 100644 libavformat/rtmpdh.c create mode 100644 libavformat/rtmpdh.h diff --git a/Changelog b/Changelog index 3d1325414b..d51f5d3106 100644 --- a/Changelog +++ b/Changelog @@ -39,6 +39,7 @@ version : - RTMPTS protocol support - JPEG 2000 encoding support through OpenJPEG - G.723.1 demuxer and decoder +- RTMPE protocol support version 0.8: diff --git a/configure b/configure index f00eddd379..b862fd3f24 100755 --- a/configure +++ b/configure @@ -950,6 +950,7 @@ CONFIG_LIST=" fastdiv fft frei0r + gcrypt gnutls gpl gray @@ -982,6 +983,7 @@ CONFIG_LIST=" mdct memalign_hack mpegaudiodsp + nettle network nonfree openssl @@ -1543,6 +1545,9 @@ vfwcap_indev_extralibs="-lavicap32" x11_grab_device_indev_deps="x11grab XShmCreateImage" # protocols +ffrtmpcrypt_protocol_deps="!librtmp_protocol" +ffrtmpcrypt_protocol_deps_any="gcrypt nettle openssl" +ffrtmpcrypt_protocol_select="tcp_protocol" ffrtmphttp_protocol_deps="!librtmp_protocol" ffrtmphttp_protocol_select="http_protocol" gopher_protocol_deps="network" @@ -1560,6 +1565,7 @@ mmsh_protocol_select="http_protocol" mmst_protocol_deps="network" rtmp_protocol_deps="!librtmp_protocol" rtmp_protocol_select="tcp_protocol" +rtmpe_protocol_select="ffrtmpcrypt_protocol" rtmps_protocol_deps="!librtmp_protocol" rtmps_protocol_select="tls_protocol" rtmpt_protocol_select="ffrtmphttp_protocol" @@ -3014,6 +3020,11 @@ enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 || die "ERROR: openssl not found"; } +if enabled gnutls; then + { check_lib nettle/bignum.h nettle_mpz_get_str_256 -lnettle -lhogweed -lgmp && enable nettle; } || + { check_lib gcrypt.h gcry_mpi_new -lgcrypt && enable gcrypt; } +fi + # libdc1394 check if enabled libdc1394; then { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 && diff --git a/doc/general.texi b/doc/general.texi index f5c62936b7..c54ac00125 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -844,7 +844,7 @@ performance on systems without hardware floating point support). @item MMST @tab X @item pipe @tab X @item RTMP @tab X -@item RTMPE @tab E +@item RTMPE @tab X @item RTMPS @tab X @item RTMPT @tab X @item RTMPTE @tab E diff --git a/doc/protocols.texi b/doc/protocols.texi index aad7184126..fcb4da801e 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -247,6 +247,15 @@ For example to read with @command{avplay} a multimedia resource named avplay rtmp://myserver/vod/sample @end example +@section rtmpe + +Encrypted Real-Time Messaging Protocol. + +The Encrypted Real-Time Messaging Protocol (RTMPE) is used for +streaming multimedia content within standard cryptographic primitives, +consisting of Diffie-Hellman key exchange and HMACSHA256, generating +a pair of RC4 keys. + @section rtmps Real-Time Messaging Protocol over a secure SSL connection. diff --git a/libavformat/Makefile b/libavformat/Makefile index 43e42243bc..31a53345e7 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -341,6 +341,7 @@ OBJS-$(CONFIG_LIBRTMP) += librtmp.o OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += hlsproto.o OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o +OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpcrypt.o rtmpdh.o OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL) += rtmphttp.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o @@ -353,6 +354,7 @@ OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o OBJS-$(CONFIG_RTMP_PROTOCOL) += rtmpproto.o rtmppkt.o +OBJS-$(CONFIG_RTMPE_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPS_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPT_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPTS_PROTOCOL) += rtmpproto.o rtmppkt.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 34e9d610da..4e694b26fe 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -247,6 +247,7 @@ void av_register_all(void) #endif REGISTER_PROTOCOL (CONCAT, concat); REGISTER_PROTOCOL (CRYPTO, crypto); + REGISTER_PROTOCOL (FFRTMPCRYPT, ffrtmpcrypt); REGISTER_PROTOCOL (FFRTMPHTTP, ffrtmphttp); REGISTER_PROTOCOL (FILE, file); REGISTER_PROTOCOL (GOPHER, gopher); @@ -259,6 +260,7 @@ void av_register_all(void) REGISTER_PROTOCOL (MD5, md5); REGISTER_PROTOCOL (PIPE, pipe); REGISTER_PROTOCOL (RTMP, rtmp); + REGISTER_PROTOCOL (RTMPE, rtmpe); REGISTER_PROTOCOL (RTMPS, rtmps); REGISTER_PROTOCOL (RTMPT, rtmpt); REGISTER_PROTOCOL (RTMPTS, rtmpts); diff --git a/libavformat/rtmpcrypt.c b/libavformat/rtmpcrypt.c new file mode 100644 index 0000000000..e5afcc94ff --- /dev/null +++ b/libavformat/rtmpcrypt.c @@ -0,0 +1,309 @@ +/* + * RTMPE network protocol + * Copyright (c) 2012 Samuel Pitoiset + * + * 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 + */ + +/** + * @file + * RTMPE protocol + */ + +#include "libavutil/blowfish.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/rc4.h" +#include "libavutil/xtea.h" + +#include "internal.h" +#include "rtmp.h" +#include "rtmpdh.h" +#include "rtmpcrypt.h" +#include "url.h" + +/* protocol handler context */ +typedef struct RTMPEContext { + URLContext *stream; ///< TCP stream + FF_DH *dh; ///< Diffie-Hellman context + struct AVRC4 key_in; ///< RC4 key used for decrypt data + struct AVRC4 key_out; ///< RC4 key used for encrypt data + int handshaked; ///< flag indicating when the handshake is performed +} RTMPEContext; + +static const uint8_t rtmpe8_keys[16][16] = { + { 0xbf, 0xf0, 0x34, 0xb2, 0x11, 0xd9, 0x08, 0x1f, + 0xcc, 0xdf, 0xb7, 0x95, 0x74, 0x8d, 0xe7, 0x32 }, + { 0x08, 0x6a, 0x5e, 0xb6, 0x17, 0x43, 0x09, 0x0e, + 0x6e, 0xf0, 0x5a, 0xb8, 0xfe, 0x5a, 0x39, 0xe2 }, + { 0x7b, 0x10, 0x95, 0x6f, 0x76, 0xce, 0x05, 0x21, + 0x23, 0x88, 0xa7, 0x3a, 0x44, 0x01, 0x49, 0xa1 }, + { 0xa9, 0x43, 0xf3, 0x17, 0xeb, 0xf1, 0x1b, 0xb2, + 0xa6, 0x91, 0xa5, 0xee, 0x17, 0xf3, 0x63, 0x39 }, + { 0x7a, 0x30, 0xe0, 0x0a, 0xb5, 0x29, 0xe2, 0x2c, + 0xa0, 0x87, 0xae, 0xa5, 0xc0, 0xcb, 0x79, 0xac }, + { 0xbd, 0xce, 0x0c, 0x23, 0x2f, 0xeb, 0xde, 0xff, + 0x1c, 0xfa, 0xae, 0x16, 0x11, 0x23, 0x23, 0x9d }, + { 0x55, 0xdd, 0x3f, 0x7b, 0x77, 0xe7, 0xe6, 0x2e, + 0x9b, 0xb8, 0xc4, 0x99, 0xc9, 0x48, 0x1e, 0xe4 }, + { 0x40, 0x7b, 0xb6, 0xb4, 0x71, 0xe8, 0x91, 0x36, + 0xa7, 0xae, 0xbf, 0x55, 0xca, 0x33, 0xb8, 0x39 }, + { 0xfc, 0xf6, 0xbd, 0xc3, 0xb6, 0x3c, 0x36, 0x97, + 0x7c, 0xe4, 0xf8, 0x25, 0x04, 0xd9, 0x59, 0xb2 }, + { 0x28, 0xe0, 0x91, 0xfd, 0x41, 0x95, 0x4c, 0x4c, + 0x7f, 0xb7, 0xdb, 0x00, 0xe3, 0xa0, 0x66, 0xf8 }, + { 0x57, 0x84, 0x5b, 0x76, 0x4f, 0x25, 0x1b, 0x03, + 0x46, 0xd4, 0x5b, 0xcd, 0xa2, 0xc3, 0x0d, 0x29 }, + { 0x0a, 0xcc, 0xee, 0xf8, 0xda, 0x55, 0xb5, 0x46, + 0x03, 0x47, 0x34, 0x52, 0x58, 0x63, 0x71, 0x3b }, + { 0xb8, 0x20, 0x75, 0xdc, 0xa7, 0x5f, 0x1f, 0xee, + 0xd8, 0x42, 0x68, 0xe8, 0xa7, 0x2a, 0x44, 0xcc }, + { 0x07, 0xcf, 0x6e, 0x9e, 0xa1, 0x6d, 0x7b, 0x25, + 0x9f, 0xa7, 0xae, 0x6c, 0xd9, 0x2f, 0x56, 0x29 }, + { 0xfe, 0xb1, 0xea, 0xe4, 0x8c, 0x8c, 0x3c, 0xe1, + 0x4e, 0x00, 0x64, 0xa7, 0x6a, 0x38, 0x7c, 0x2a }, + { 0x89, 0x3a, 0x94, 0x27, 0xcc, 0x30, 0x13, 0xa2, + 0xf1, 0x06, 0x38, 0x5b, 0xa8, 0x29, 0xf9, 0x27 } +}; + +static const uint8_t rtmpe9_keys[16][24] = { + { 0x79, 0x34, 0x77, 0x4c, 0x67, 0xd1, 0x38, 0x3a, 0xdf, 0xb3, 0x56, 0xbe, + 0x8b, 0x7b, 0xd0, 0x24, 0x38, 0xe0, 0x73, 0x58, 0x41, 0x5d, 0x69, 0x67, }, + { 0x46, 0xf6, 0xb4, 0xcc, 0x01, 0x93, 0xe3, 0xa1, 0x9e, 0x7d, 0x3c, 0x65, + 0x55, 0x86, 0xfd, 0x09, 0x8f, 0xf7, 0xb3, 0xc4, 0x6f, 0x41, 0xca, 0x5c, }, + { 0x1a, 0xe7, 0xe2, 0xf3, 0xf9, 0x14, 0x79, 0x94, 0xc0, 0xd3, 0x97, 0x43, + 0x08, 0x7b, 0xb3, 0x84, 0x43, 0x2f, 0x9d, 0x84, 0x3f, 0x21, 0x01, 0x9b, }, + { 0xd3, 0xe3, 0x54, 0xb0, 0xf7, 0x1d, 0xf6, 0x2b, 0x5a, 0x43, 0x4d, 0x04, + 0x83, 0x64, 0x3e, 0x0d, 0x59, 0x2f, 0x61, 0xcb, 0xb1, 0x6a, 0x59, 0x0d, }, + { 0xc8, 0xc1, 0xe9, 0xb8, 0x16, 0x56, 0x99, 0x21, 0x7b, 0x5b, 0x36, 0xb7, + 0xb5, 0x9b, 0xdf, 0x06, 0x49, 0x2c, 0x97, 0xf5, 0x95, 0x48, 0x85, 0x7e, }, + { 0xeb, 0xe5, 0xe6, 0x2e, 0xa4, 0xba, 0xd4, 0x2c, 0xf2, 0x16, 0xe0, 0x8f, + 0x66, 0x23, 0xa9, 0x43, 0x41, 0xce, 0x38, 0x14, 0x84, 0x95, 0x00, 0x53, }, + { 0x66, 0xdb, 0x90, 0xf0, 0x3b, 0x4f, 0xf5, 0x6f, 0xe4, 0x9c, 0x20, 0x89, + 0x35, 0x5e, 0xd2, 0xb2, 0xc3, 0x9e, 0x9f, 0x7f, 0x63, 0xb2, 0x28, 0x81, }, + { 0xbb, 0x20, 0xac, 0xed, 0x2a, 0x04, 0x6a, 0x19, 0x94, 0x98, 0x9b, 0xc8, + 0xff, 0xcd, 0x93, 0xef, 0xc6, 0x0d, 0x56, 0xa7, 0xeb, 0x13, 0xd9, 0x30, }, + { 0xbc, 0xf2, 0x43, 0x82, 0x09, 0x40, 0x8a, 0x87, 0x25, 0x43, 0x6d, 0xe6, + 0xbb, 0xa4, 0xb9, 0x44, 0x58, 0x3f, 0x21, 0x7c, 0x99, 0xbb, 0x3f, 0x24, }, + { 0xec, 0x1a, 0xaa, 0xcd, 0xce, 0xbd, 0x53, 0x11, 0xd2, 0xfb, 0x83, 0xb6, + 0xc3, 0xba, 0xab, 0x4f, 0x62, 0x79, 0xe8, 0x65, 0xa9, 0x92, 0x28, 0x76, }, + { 0xc6, 0x0c, 0x30, 0x03, 0x91, 0x18, 0x2d, 0x7b, 0x79, 0xda, 0xe1, 0xd5, + 0x64, 0x77, 0x9a, 0x12, 0xc5, 0xb1, 0xd7, 0x91, 0x4f, 0x96, 0x4c, 0xa3, }, + { 0xd7, 0x7c, 0x2a, 0xbf, 0xa6, 0xe7, 0x85, 0x7c, 0x45, 0xad, 0xff, 0x12, + 0x94, 0xd8, 0xde, 0xa4, 0x5c, 0x3d, 0x79, 0xa4, 0x44, 0x02, 0x5d, 0x22, }, + { 0x16, 0x19, 0x0d, 0x81, 0x6a, 0x4c, 0xc7, 0xf8, 0xb8, 0xf9, 0x4e, 0xcd, + 0x2c, 0x9e, 0x90, 0x84, 0xb2, 0x08, 0x25, 0x60, 0xe1, 0x1e, 0xae, 0x18, }, + { 0xe9, 0x7c, 0x58, 0x26, 0x1b, 0x51, 0x9e, 0x49, 0x82, 0x60, 0x61, 0xfc, + 0xa0, 0xa0, 0x1b, 0xcd, 0xf5, 0x05, 0xd6, 0xa6, 0x6d, 0x07, 0x88, 0xa3, }, + { 0x2b, 0x97, 0x11, 0x8b, 0xd9, 0x4e, 0xd9, 0xdf, 0x20, 0xe3, 0x9c, 0x10, + 0xe6, 0xa1, 0x35, 0x21, 0x11, 0xf9, 0x13, 0x0d, 0x0b, 0x24, 0x65, 0xb2, }, + { 0x53, 0x6a, 0x4c, 0x54, 0xac, 0x8b, 0x9b, 0xb8, 0x97, 0x29, 0xfc, 0x60, + 0x2c, 0x5b, 0x3a, 0x85, 0x68, 0xb5, 0xaa, 0x6a, 0x44, 0xcd, 0x3f, 0xa7, }, +}; + +int ff_rtmpe_gen_pub_key(URLContext *h, uint8_t *buf) +{ + RTMPEContext *rt = h->priv_data; + int offset, ret; + + if (!(rt->dh = ff_dh_init(1024))) + return AVERROR(ENOMEM); + + offset = ff_rtmp_calc_digest_pos(buf, 768, 632, 8); + if (offset < 0) + return offset; + + /* generate a Diffie-Hellmann public key */ + if ((ret = ff_dh_generate_public_key(rt->dh)) < 0) + return ret; + + /* write the public key into the handshake buffer */ + if ((ret = ff_dh_write_public_key(rt->dh, buf + offset, 128)) < 0) + return ret; + + return 0; +} + +int ff_rtmpe_compute_secret_key(URLContext *h, const uint8_t *serverdata, + const uint8_t *clientdata, int type) +{ + RTMPEContext *rt = h->priv_data; + uint8_t secret_key[128], digest[32]; + int server_pos, client_pos; + int ret; + + if (type) { + if ((server_pos = ff_rtmp_calc_digest_pos(serverdata, 1532, 632, 772)) < 0) + return server_pos; + } else { + if ((server_pos = ff_rtmp_calc_digest_pos(serverdata, 768, 632, 8)) < 0) + return server_pos; + } + + if ((client_pos = ff_rtmp_calc_digest_pos(clientdata, 768, 632, 8)) < 0) + return client_pos; + + /* compute the shared secret secret in order to compute RC4 keys */ + if ((ret = ff_dh_compute_shared_secret_key(rt->dh, serverdata + server_pos, + 128, secret_key)) < 0) + return ret; + + /* set output key */ + if ((ret = ff_rtmp_calc_digest(serverdata + server_pos, 128, 0, secret_key, + 128, digest)) < 0) + return ret; + av_rc4_init(&rt->key_out, digest, 16 * 8, 1); + + /* set input key */ + if ((ret = ff_rtmp_calc_digest(clientdata + client_pos, 128, 0, secret_key, + 128, digest)) < 0) + return ret; + av_rc4_init(&rt->key_in, digest, 16 * 8, 1); + + return 0; +} + +static void rtmpe8_sig(const uint8_t *in, uint8_t *out, int key_id) +{ + struct AVXTEA ctx; + + av_xtea_init(&ctx, rtmpe8_keys[key_id]); + av_xtea_crypt(&ctx, out, in, 1, NULL, 0); +} + +static void rtmpe9_sig(const uint8_t *in, uint8_t *out, int key_id) +{ + struct AVBlowfish ctx; + uint32_t xl, xr; + + xl = AV_RL32(in); + xr = AV_RL32(in + 4); + + av_blowfish_init(&ctx, rtmpe9_keys[key_id], 24); + av_blowfish_crypt_ecb(&ctx, &xl, &xr, 0); + + AV_WL32(out, xl); + AV_WL32(out + 4, xr); +} + +void ff_rtmpe_encrypt_sig(URLContext *h, uint8_t *sig, const uint8_t *digest, + int type) +{ + int i; + + for (i = 0; i < 32; i += 8) { + if (type == 8) { + /* RTMPE type 8 uses XTEA on the signature */ + rtmpe8_sig(sig + i, sig + i, digest[i] % 15); + } else if (type == 9) { + /* RTMPE type 9 uses Blowfish on the signature */ + rtmpe9_sig(sig + i, sig + i, digest[i] % 15); + } + } +} + +int ff_rtmpe_update_keystream(URLContext *h) +{ + RTMPEContext *rt = h->priv_data; + char buf[RTMP_HANDSHAKE_PACKET_SIZE]; + + /* skip past 1536 bytes of the RC4 bytestream */ + av_rc4_crypt(&rt->key_in, buf, NULL, sizeof(buf), NULL, 1); + av_rc4_crypt(&rt->key_out, buf, NULL, sizeof(buf), NULL, 1); + + /* the next requests will be encrypted using RC4 keys */ + rt->handshaked = 1; + + return 0; +} + +static int rtmpe_close(URLContext *h) +{ + RTMPEContext *rt = h->priv_data; + + ff_dh_free(rt->dh); + ffurl_close(rt->stream); + + return 0; +} + +static int rtmpe_open(URLContext *h, const char *uri, int flags) +{ + RTMPEContext *rt = h->priv_data; + char host[256], url[1024]; + int ret, port; + + av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri); + + if (port < 0) + port = 1935; + + /* open the tcp connection */ + ff_url_join(url, sizeof(url), "tcp", NULL, host, port, NULL); + if ((ret = ffurl_open(&rt->stream, url, AVIO_FLAG_READ_WRITE, + &h->interrupt_callback, NULL)) < 0) { + rtmpe_close(h); + return ret; + } + + return 0; +} + +static int rtmpe_read(URLContext *h, uint8_t *buf, int size) +{ + RTMPEContext *rt = h->priv_data; + int ret; + + rt->stream->flags |= h->flags & AVIO_FLAG_NONBLOCK; + ret = ffurl_read(rt->stream, buf, size); + rt->stream->flags &= ~AVIO_FLAG_NONBLOCK; + + if (ret < 0 && ret != AVERROR_EOF) + return ret; + + if (rt->handshaked && ret > 0) { + /* decrypt data received by the server */ + av_rc4_crypt(&rt->key_in, buf, buf, ret, NULL, 1); + } + + return ret; +} + +static int rtmpe_write(URLContext *h, const uint8_t *buf, int size) +{ + RTMPEContext *rt = h->priv_data; + int ret; + + if (rt->handshaked) { + /* encrypt data to send to the server */ + av_rc4_crypt(&rt->key_out, buf, buf, size, NULL, 1); + } + + if ((ret = ffurl_write(rt->stream, buf, size)) < 0) + return ret; + + return size; +} + +URLProtocol ff_ffrtmpcrypt_protocol = { + .name = "ffrtmpcrypt", + .url_open = rtmpe_open, + .url_read = rtmpe_read, + .url_write = rtmpe_write, + .url_close = rtmpe_close, + .priv_data_size = sizeof(RTMPEContext), + .flags = URL_PROTOCOL_FLAG_NETWORK, +}; diff --git a/libavformat/rtmpcrypt.h b/libavformat/rtmpcrypt.h new file mode 100644 index 0000000000..27994333df --- /dev/null +++ b/libavformat/rtmpcrypt.h @@ -0,0 +1,69 @@ +/* + * RTMPE encryption utilities + * Copyright (c) 2012 Samuel Pitoiset + * + * 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 + */ + +#ifndef AVFORMAT_RTMPCRYPT_H +#define AVFORMAT_RTMPCRYPT_H + +#include + +#include "url.h" + +/** + * Initialize the Diffie-Hellmann context and generate the public key. + * + * @param h an URLContext + * @param buf handshake data (1536 bytes) + * @return zero on success, negative value otherwise + */ +int ff_rtmpe_gen_pub_key(URLContext *h, uint8_t *buf); + +/** + * Compute the shared secret key and initialize the RC4 encryption. + * + * @param h an URLContext + * @param serverdata server data (1536 bytes) + * @param clientdata client data (1536 bytes) + * @param type the position of the server digest + * @return zero on success, negative value otherwise + */ +int ff_rtmpe_compute_secret_key(URLContext *h, const uint8_t *serverdata, + const uint8_t *clientdata, int type); + +/** + * Encrypt the signature. + * + * @param h an URLContext + * @param signature the signature to encrypt + * @param digest the digest used for finding the encryption key + * @param type type of encryption (8 for XTEA, 9 for Blowfish) + */ +void ff_rtmpe_encrypt_sig(URLContext *h, uint8_t *signature, + const uint8_t *digest, int type); + +/** + * Update the keystream and set RC4 keys for encryption. + * + * @param h an URLContext + * @return zero on success, negative value otherwise + */ +int ff_rtmpe_update_keystream(URLContext *h); + +#endif /* AVFORMAT_RTMPCRYPT_H */ diff --git a/libavformat/rtmpdh.c b/libavformat/rtmpdh.c new file mode 100644 index 0000000000..8ddc5fcee8 --- /dev/null +++ b/libavformat/rtmpdh.c @@ -0,0 +1,329 @@ +/* + * RTMP Diffie-Hellmann utilities + * Copyright (c) 2012 Samuel Pitoiset + * + * 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 + */ + +/** + * @file + * RTMP Diffie-Hellmann utilities + */ + +#include "config.h" +#include "rtmpdh.h" + +#define P1024 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \ + "FFFFFFFFFFFFFFFF" + +#define Q1024 \ + "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \ + "948127044533E63A0105DF531D89CD9128A5043CC71A026E" \ + "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \ + "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \ + "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \ + "FFFFFFFFFFFFFFFF" + +#if CONFIG_NETTLE || CONFIG_GCRYPT +#if CONFIG_NETTLE +#define bn_new(bn) \ + do { \ + bn = av_malloc(sizeof(*bn)); \ + if (bn) \ + mpz_init2(bn, 1); \ + } while (0) +#define bn_free(bn) \ + do { \ + mpz_clear(bn); \ + av_free(bn); \ + } while (0) +#define bn_set_word(bn, w) mpz_set_ui(bn, w) +#define bn_cmp(a, b) mpz_cmp(a, b) +#define bn_copy(to, from) mpz_set(to, from) +#define bn_sub_word(bn, w) mpz_sub_ui(bn, bn, w) +#define bn_cmp_1(bn) mpz_cmp_ui(bn, 1) +#define bn_num_bytes(bn) (mpz_sizeinbase(bn, 2) + 7) / 8 +#define bn_bn2bin(bn, buf, len) nettle_mpz_get_str_256(len, buf, bn) +#define bn_bin2bn(bn, buf, len) \ + do { \ + bn_new(bn); \ + if (bn) \ + nettle_mpz_set_str_256_u(bn, len, buf); \ + } while (0) +#define bn_hex2bn(bn, buf, ret) \ + do { \ + bn_new(bn); \ + if (bn) \ + ret = (mpz_set_str(bn, buf, 16) == 0); \ + } while (0) +#define bn_modexp(bn, y, q, p) mpz_powm(bn, y, q, p) +#define bn_random(bn, num_bytes) mpz_random(bn, num_bytes); +#elif CONFIG_GCRYPT +#define bn_new(bn) bn = gcry_mpi_new(1) +#define bn_free(bn) gcry_mpi_release(bn) +#define bn_set_word(bn, w) gcry_mpi_set_ui(bn, w) +#define bn_cmp(a, b) gcry_mpi_cmp(a, b) +#define bn_copy(to, from) gcry_mpi_set(to, from) +#define bn_sub_word(bn, w) gcry_mpi_sub_ui(bn, bn, w) +#define bn_cmp_1(bn) gcry_mpi_cmp_ui(bn, 1) +#define bn_num_bytes(bn) (gcry_mpi_get_nbits(bn) + 7) / 8 +#define bn_bn2bin(bn, buf, len) gcry_mpi_print(GCRYMPI_FMT_USG, buf, len, NULL, bn) +#define bn_bin2bn(bn, buf, len) gcry_mpi_scan(&bn, GCRYMPI_FMT_USG, buf, len, NULL) +#define bn_hex2bn(bn, buf, ret) ret = (gcry_mpi_scan(&bn, GCRYMPI_FMT_HEX, buf, 0, 0) == 0) +#define bn_modexp(bn, y, q, p) gcry_mpi_powm(bn, y, q, p) +#define bn_random(bn, num_bytes) gcry_mpi_randomize(bn, num_bytes, GCRY_WEAK_RANDOM) +#endif + +#define MAX_BYTES 18000 + +#define dh_new() av_malloc(sizeof(FF_DH)) + +static FFBigNum dh_generate_key(FF_DH *dh) +{ + int num_bytes; + + num_bytes = bn_num_bytes(dh->p) - 1; + if (num_bytes <= 0 || num_bytes > MAX_BYTES) + return NULL; + + bn_new(dh->priv_key); + if (!dh->priv_key) + return NULL; + bn_random(dh->priv_key, num_bytes); + + bn_new(dh->pub_key); + if (!dh->pub_key) { + bn_free(dh->priv_key); + return NULL; + } + + bn_modexp(dh->pub_key, dh->g, dh->priv_key, dh->p); + + return dh->pub_key; +} + +static int dh_compute_key(FF_DH *dh, FFBigNum pub_key_bn, + uint32_t pub_key_len, uint8_t *secret_key) +{ + FFBigNum k; + int num_bytes; + + num_bytes = bn_num_bytes(dh->p); + if (num_bytes <= 0 || num_bytes > MAX_BYTES) + return -1; + + bn_new(k); + if (!k) + return -1; + + bn_modexp(k, pub_key_bn, dh->priv_key, dh->p); + bn_bn2bin(k, secret_key, pub_key_len); + bn_free(k); + + /* return the length of the shared secret key like DH_compute_key */ + return pub_key_len; +} + +void ff_dh_free(FF_DH *dh) +{ + bn_free(dh->p); + bn_free(dh->g); + bn_free(dh->pub_key); + bn_free(dh->priv_key); + av_free(dh); +} +#elif CONFIG_OPENSSL +#define bn_new(bn) bn = BN_new() +#define bn_free(bn) BN_free(bn) +#define bn_set_word(bn, w) BN_set_word(bn, w) +#define bn_cmp(a, b) BN_cmp(a, b) +#define bn_copy(to, from) BN_copy(to, from) +#define bn_sub_word(bn, w) BN_sub_word(bn, w) +#define bn_cmp_1(bn) BN_cmp(bn, BN_value_one()) +#define bn_num_bytes(bn) BN_num_bytes(bn) +#define bn_bn2bin(bn, buf, len) BN_bn2bin(bn, buf) +#define bn_bin2bn(bn, buf, len) bn = BN_bin2bn(buf, len, 0) +#define bn_hex2bn(bn, buf, ret) ret = BN_hex2bn(&bn, buf) +#define bn_modexp(bn, y, q, p) \ + do { \ + BN_CTX *ctx = BN_CTX_new(); \ + if (!ctx) \ + return AVERROR(ENOMEM); \ + if (!BN_mod_exp(bn, y, q, p, ctx)) { \ + BN_CTX_free(ctx); \ + return AVERROR(EINVAL); \ + } \ + BN_CTX_free(ctx); \ + } while (0) + +#define dh_new() DH_new() +#define dh_generate_key(dh) DH_generate_key(dh) +#define dh_compute_key(dh, pub, len, secret) DH_compute_key(secret, pub, dh) + +void ff_dh_free(FF_DH *dh) +{ + DH_free(dh); +} +#endif + +static int dh_is_valid_public_key(FFBigNum y, FFBigNum p, FFBigNum q) +{ + FFBigNum bn = NULL; + int ret = AVERROR(EINVAL); + + bn_new(bn); + if (!bn) + return AVERROR(ENOMEM); + + /* y must lie in [2, p - 1] */ + bn_set_word(bn, 1); + if (!bn_cmp(y, bn)) + goto fail; + + /* bn = p - 2 */ + bn_copy(bn, p); + bn_sub_word(bn, 1); + if (!bn_cmp(y, bn)) + goto fail; + + /* Verify with Sophie-Germain prime + * + * This is a nice test to make sure the public key position is calculated + * correctly. This test will fail in about 50% of the cases if applied to + * random data. + */ + /* y must fulfill y^q mod p = 1 */ + bn_modexp(bn, y, q, p); + + if (bn_cmp_1(bn)) + goto fail; + + ret = 0; +fail: + bn_free(bn); + + return ret; +} + +av_cold FF_DH *ff_dh_init(int key_len) +{ + FF_DH *dh; + int ret; + + if (!(dh = dh_new())) + return NULL; + + bn_new(dh->g); + if (!dh->g) + goto fail; + + bn_hex2bn(dh->p, P1024, ret); + if (!ret) + goto fail; + + bn_set_word(dh->g, 2); + dh->length = key_len; + + return dh; + +fail: + ff_dh_free(dh); + + return NULL; +} + +int ff_dh_generate_public_key(FF_DH *dh) +{ + int ret = 0; + + while (!ret) { + FFBigNum q1 = NULL; + + if (!dh_generate_key(dh)) + return AVERROR(EINVAL); + + bn_hex2bn(q1, Q1024, ret); + if (!ret) + return AVERROR(ENOMEM); + + ret = dh_is_valid_public_key(dh->pub_key, dh->p, q1); + bn_free(q1); + + if (!ret) { + /* the public key is valid */ + break; + } + } + + return ret; +} + +int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len) +{ + int len; + + /* compute the length of the public key */ + len = bn_num_bytes(dh->pub_key); + if (len <= 0 || len > pub_key_len) + return AVERROR(EINVAL); + + /* convert the public key value into big-endian form */ + memset(pub_key, 0, pub_key_len); + bn_bn2bin(dh->pub_key, pub_key + pub_key_len - len, len); + + return 0; +} + +int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key, + int pub_key_len, uint8_t *secret_key) +{ + FFBigNum q1 = NULL, pub_key_bn = NULL; + int ret; + + /* convert the big-endian form of the public key into a bignum */ + bn_bin2bn(pub_key_bn, pub_key, pub_key_len); + if (!pub_key_bn) + return AVERROR(ENOMEM); + + /* convert the string containing a hexadecimal number into a bignum */ + bn_hex2bn(q1, Q1024, ret); + if (!ret) { + ret = AVERROR(ENOMEM); + goto fail; + } + + /* when the public key is valid we have to compute the shared secret key */ + if ((ret = dh_is_valid_public_key(pub_key_bn, dh->p, q1)) < 0) { + goto fail; + } else if ((ret = dh_compute_key(dh, pub_key_bn, pub_key_len, + secret_key)) < 0) { + ret = AVERROR(EINVAL); + goto fail; + } + +fail: + bn_free(pub_key_bn); + bn_free(q1); + + return ret; +} + diff --git a/libavformat/rtmpdh.h b/libavformat/rtmpdh.h new file mode 100644 index 0000000000..5de8bde821 --- /dev/null +++ b/libavformat/rtmpdh.h @@ -0,0 +1,102 @@ +/* + * RTMP Diffie-Hellmann utilities + * Copyright (c) 2012 Samuel Pitoiset + * + * 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 + */ + +#ifndef AVFORMAT_RTMPDH_H +#define AVFORMAT_RTMPDH_H + +#include "avformat.h" +#include "config.h" + +#if CONFIG_NETTLE || CONFIG_GCRYPT +#if CONFIG_NETTLE +#include +#include + +typedef mpz_ptr FFBigNum; +#elif CONFIG_GCRYPT +#include + +typedef gcry_mpi_t FFBigNum; +#endif + +typedef struct FF_DH { + FFBigNum p; + FFBigNum g; + FFBigNum pub_key; + FFBigNum priv_key; + long length; +} FF_DH; + +#elif CONFIG_OPENSSL +#include +#include + +typedef BIGNUM *FFBigNum; +typedef DH FF_DH; +#endif + +/** + * Initialize a Diffie-Hellmann context. + * + * @param key_len length of the key + * @return a new Diffie-Hellmann context on success, NULL otherwise + */ +FF_DH *ff_dh_init(int key_len); + +/** + * Free a Diffie-Hellmann context. + * + * @param dh a Diffie-Hellmann context to free + */ +void ff_dh_free(FF_DH *dh); + +/** + * Generate a public key. + * + * @param dh a Diffie-Hellmann context + * @return zero on success, negative value otherwise + */ +int ff_dh_generate_public_key(FF_DH *dh); + +/** + * Write the public key into the given buffer. + * + * @param dh a Diffie-Hellmann context, containing the public key to write + * @param pub_key the buffer where the public key is written + * @param pub_key_len the length of the buffer + * @return zero on success, negative value otherwise + */ +int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len); + +/** + * Compute the shared secret key from the private FF_DH value and the + * other party's public value. + * + * @param dh a Diffie-Hellmann context, containing the private key + * @param pub_key the buffer containing the public key + * @param pub_key_len the length of the buffer + * @param secret_key the buffer where the secret key is written + * @return length of the shared secret key on success, negative value otherwise + */ +int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key, + int pub_key_len, uint8_t *secret_key); + +#endif /* AVFORMAT_RTMPDH_H */ diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 64704502e9..67a89c5c82 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -37,6 +37,7 @@ #include "flv.h" #include "rtmp.h" +#include "rtmpcrypt.h" #include "rtmppkt.h" #include "url.h" @@ -92,6 +93,7 @@ typedef struct RTMPContext { int server_bw; ///< server bandwidth int client_buffer_time; ///< client buffer time in ms int flush_interval; ///< number of packets flushed in the same request (RTMPT only) + int encrypted; ///< use an encrypted connection (RTMPE only) } RTMPContext; #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing @@ -649,13 +651,17 @@ int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, * will be stored) into that packet. * * @param buf handshake data (1536 bytes) + * @param encrypted use an encrypted connection (RTMPE) * @return offset to the digest inside input data */ -static int rtmp_handshake_imprint_with_digest(uint8_t *buf) +static int rtmp_handshake_imprint_with_digest(uint8_t *buf, int encrypted) { int ret, digest_pos; - digest_pos = ff_rtmp_calc_digest_pos(buf, 8, 728, 12); + if (encrypted) + digest_pos = ff_rtmp_calc_digest_pos(buf, 772, 728, 776); + else + digest_pos = ff_rtmp_calc_digest_pos(buf, 8, 728, 12); ret = ff_rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos, rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN, @@ -712,8 +718,9 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) uint8_t serverdata[RTMP_HANDSHAKE_PACKET_SIZE+1]; int i; int server_pos, client_pos; - uint8_t digest[32]; - int ret; + uint8_t digest[32], signature[32]; + int encrypted = rt->encrypted && CONFIG_FFRTMPCRYPT_PROTOCOL; + int ret, type = 0; av_log(s, AV_LOG_DEBUG, "Handshaking...\n"); @@ -721,7 +728,24 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) // generate handshake packet - 1536 bytes of pseudorandom data for (i = 9; i <= RTMP_HANDSHAKE_PACKET_SIZE; i++) tosend[i] = av_lfg_get(&rnd) >> 24; - client_pos = rtmp_handshake_imprint_with_digest(tosend + 1); + + if (encrypted) { + /* When the client wants to use RTMPE, we have to change the command + * byte to 0x06 which means to use encrypted data and we have to set + * the flash version to at least 9.0.115.0. */ + tosend[0] = 6; + tosend[5] = 128; + tosend[6] = 0; + tosend[7] = 3; + tosend[8] = 2; + + /* Initialize the Diffie-Hellmann context and generate the public key + * to send to the server. */ + if ((ret = ff_rtmpe_gen_pub_key(rt->stream, tosend + 1)) < 0) + return ret; + } + + client_pos = rtmp_handshake_imprint_with_digest(tosend + 1, encrypted); if (client_pos < 0) return client_pos; @@ -743,6 +767,7 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) return ret; } + av_log(s, AV_LOG_DEBUG, "Type answer %d\n", serverdata[0]); av_log(s, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", serverdata[5], serverdata[6], serverdata[7], serverdata[8]); @@ -752,6 +777,7 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) return server_pos; if (!server_pos) { + type = 1; server_pos = rtmp_validate_digest(serverdata + 1, 8); if (server_pos < 0) return server_pos; @@ -769,11 +795,22 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) return ret; ret = ff_rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE - 32, - 0, digest, 32, digest); + 0, digest, 32, signature); if (ret < 0) return ret; - if (memcmp(digest, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) { + if (encrypted) { + /* Compute the shared secret key sent by the server and initialize + * the RC4 encryption. */ + if ((ret = ff_rtmpe_compute_secret_key(rt->stream, serverdata + 1, + tosend + 1, type)) < 0) + return ret; + + /* Encrypt the signature received by the server. */ + ff_rtmpe_encrypt_sig(rt->stream, signature, digest, serverdata[0]); + } + + if (memcmp(signature, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) { av_log(s, AV_LOG_ERROR, "Signature mismatch\n"); return AVERROR(EIO); } @@ -792,14 +829,47 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) if (ret < 0) return ret; + if (encrypted) { + /* Encrypt the signature to be send to the server. */ + ff_rtmpe_encrypt_sig(rt->stream, tosend + + RTMP_HANDSHAKE_PACKET_SIZE - 32, digest, + serverdata[0]); + } + // write reply back to the server if ((ret = ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE)) < 0) return ret; + + if (encrypted) { + /* Set RC4 keys for encryption and update the keystreams. */ + if ((ret = ff_rtmpe_update_keystream(rt->stream)) < 0) + return ret; + } } else { + if (encrypted) { + /* Compute the shared secret key sent by the server and initialize + * the RC4 encryption. */ + if ((ret = ff_rtmpe_compute_secret_key(rt->stream, serverdata + 1, + tosend + 1, 1)) < 0) + return ret; + + if (serverdata[0] == 9) { + /* Encrypt the signature received by the server. */ + ff_rtmpe_encrypt_sig(rt->stream, signature, digest, + serverdata[0]); + } + } + if ((ret = ffurl_write(rt->stream, serverdata + 1, RTMP_HANDSHAKE_PACKET_SIZE)) < 0) return ret; + + if (encrypted) { + /* Set RC4 keys for encryption and update the keystreams. */ + if ((ret = ff_rtmpe_update_keystream(rt->stream)) < 0) + return ret; + } } return 0; @@ -1122,6 +1192,10 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) if (port < 0) port = RTMPS_DEFAULT_PORT; ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port, NULL); + } else if (!strcmp(proto, "rtmpe")) { + /* open the encrypted connection */ + ff_url_join(buf, sizeof(buf), "ffrtmpcrypt", NULL, hostname, port, NULL); + rt->encrypted = 1; } else { /* open the tcp connection */ if (port < 0) @@ -1446,6 +1520,24 @@ URLProtocol ff_rtmp_protocol = { .priv_data_class= &rtmp_class, }; +static const AVClass rtmpe_class = { + .class_name = "rtmpe", + .item_name = av_default_item_name, + .option = rtmp_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +URLProtocol ff_rtmpe_protocol = { + .name = "rtmpe", + .url_open = rtmp_open, + .url_read = rtmp_read, + .url_write = rtmp_write, + .url_close = rtmp_close, + .priv_data_size = sizeof(RTMPContext), + .flags = URL_PROTOCOL_FLAG_NETWORK, + .priv_data_class = &rtmpe_class, +}; + static const AVClass rtmps_class = { .class_name = "rtmps", .item_name = av_default_item_name, diff --git a/libavformat/version.h b/libavformat/version.h index d20b07005a..3681e8db13 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 54 -#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 08cd95e8a37674401ed24e5e6f4f7402edb7fdeb Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 20 Jul 2012 16:36:47 +0200 Subject: RTMPTE protocol support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- Changelog | 1 + configure | 1 + doc/general.texi | 2 +- doc/protocols.texi | 8 ++++++++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/rtmpcrypt.c | 33 +++++++++++++++++++++++++++++---- libavformat/rtmpproto.c | 23 ++++++++++++++++++++++- libavformat/version.h | 2 +- 9 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index d51f5d3106..ea2c353a15 100644 --- a/Changelog +++ b/Changelog @@ -40,6 +40,7 @@ version : - JPEG 2000 encoding support through OpenJPEG - G.723.1 demuxer and decoder - RTMPE protocol support +- RTMPTE protocol support version 0.8: diff --git a/configure b/configure index b862fd3f24..aa5797ab9a 100755 --- a/configure +++ b/configure @@ -1569,6 +1569,7 @@ rtmpe_protocol_select="ffrtmpcrypt_protocol" rtmps_protocol_deps="!librtmp_protocol" rtmps_protocol_select="tls_protocol" rtmpt_protocol_select="ffrtmphttp_protocol" +rtmpte_protocol_select="ffrtmpcrypt_protocol ffrtmphttp_protocol" rtmpts_protocol_select="ffrtmphttp_protocol" rtp_protocol_select="udp_protocol" sctp_protocol_deps="network netinet_sctp_h" diff --git a/doc/general.texi b/doc/general.texi index c54ac00125..05855542bf 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -847,7 +847,7 @@ performance on systems without hardware floating point support). @item RTMPE @tab X @item RTMPS @tab X @item RTMPT @tab X -@item RTMPTE @tab E +@item RTMPTE @tab X @item RTMPTS @tab X @item RTP @tab X @item SCTP @tab X diff --git a/doc/protocols.texi b/doc/protocols.texi index fcb4da801e..7b84f25815 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -271,6 +271,14 @@ The Real-Time Messaging Protocol tunneled through HTTP (RTMPT) is used for streaming multimedia content within HTTP requests to traverse firewalls. +@section rtmpte + +Encrypted Real-Time Messaging Protocol tunneled through HTTP. + +The Encrypted Real-Time Messaging Protocol tunneled through HTTP (RTMPTE) +is used for streaming multimedia content within HTTP requests to traverse +firewalls. + @section rtmpts Real-Time Messaging Protocol tunneled through HTTPS. diff --git a/libavformat/Makefile b/libavformat/Makefile index 31a53345e7..2263b9648d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -357,6 +357,7 @@ OBJS-$(CONFIG_RTMP_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPE_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPS_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPT_PROTOCOL) += rtmpproto.o rtmppkt.o +OBJS-$(CONFIG_RTMPTE_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTMPTS_PROTOCOL) += rtmpproto.o rtmppkt.o OBJS-$(CONFIG_RTP_PROTOCOL) += rtpproto.o OBJS-$(CONFIG_SCTP_PROTOCOL) += sctp.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 4e694b26fe..40770e5253 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -263,6 +263,7 @@ void av_register_all(void) REGISTER_PROTOCOL (RTMPE, rtmpe); REGISTER_PROTOCOL (RTMPS, rtmps); REGISTER_PROTOCOL (RTMPT, rtmpt); + REGISTER_PROTOCOL (RTMPTE, rtmpte); REGISTER_PROTOCOL (RTMPTS, rtmpts); REGISTER_PROTOCOL (RTP, rtp); REGISTER_PROTOCOL (SCTP, sctp); diff --git a/libavformat/rtmpcrypt.c b/libavformat/rtmpcrypt.c index e5afcc94ff..6a4332de86 100644 --- a/libavformat/rtmpcrypt.c +++ b/libavformat/rtmpcrypt.c @@ -26,6 +26,7 @@ #include "libavutil/blowfish.h" #include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" #include "libavutil/rc4.h" #include "libavutil/xtea.h" @@ -37,11 +38,13 @@ /* protocol handler context */ typedef struct RTMPEContext { + const AVClass *class; URLContext *stream; ///< TCP stream FF_DH *dh; ///< Diffie-Hellman context struct AVRC4 key_in; ///< RC4 key used for decrypt data struct AVRC4 key_out; ///< RC4 key used for encrypt data int handshaked; ///< flag indicating when the handshake is performed + int tunneling; ///< use a HTTP connection (RTMPTE) } RTMPEContext; static const uint8_t rtmpe8_keys[16][16] = { @@ -248,11 +251,17 @@ static int rtmpe_open(URLContext *h, const char *uri, int flags) av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri); - if (port < 0) - port = 1935; + if (rt->tunneling) { + if (port < 0) + port = 80; + ff_url_join(url, sizeof(url), "ffrtmphttp", NULL, host, port, NULL); + } else { + if (port < 0) + port = 1935; + ff_url_join(url, sizeof(url), "tcp", NULL, host, port, NULL); + } - /* open the tcp connection */ - ff_url_join(url, sizeof(url), "tcp", NULL, host, port, NULL); + /* open the tcp or ffrtmphttp connection */ if ((ret = ffurl_open(&rt->stream, url, AVIO_FLAG_READ_WRITE, &h->interrupt_callback, NULL)) < 0) { rtmpe_close(h); @@ -298,6 +307,21 @@ static int rtmpe_write(URLContext *h, const uint8_t *buf, int size) return size; } +#define OFFSET(x) offsetof(RTMPEContext, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM + +static const AVOption ffrtmpcrypt_options[] = { + {"ffrtmpcrypt_tunneling", "Use a HTTP tunneling connection (RTMPTE).", OFFSET(tunneling), AV_OPT_TYPE_INT, {0}, 0, 1, DEC}, + { NULL }, +}; + +static const AVClass ffrtmpcrypt_class = { + .class_name = "ffrtmpcrypt", + .item_name = av_default_item_name, + .option = ffrtmpcrypt_options, + .version = LIBAVUTIL_VERSION_INT, +}; + URLProtocol ff_ffrtmpcrypt_protocol = { .name = "ffrtmpcrypt", .url_open = rtmpe_open, @@ -306,4 +330,5 @@ URLProtocol ff_ffrtmpcrypt_protocol = { .url_close = rtmpe_close, .priv_data_size = sizeof(RTMPEContext), .flags = URL_PROTOCOL_FLAG_NETWORK, + .priv_data_class = &ffrtmpcrypt_class, }; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 67a89c5c82..f7ba7d5ef8 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1192,7 +1192,10 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) if (port < 0) port = RTMPS_DEFAULT_PORT; ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port, NULL); - } else if (!strcmp(proto, "rtmpe")) { + } else if (!strcmp(proto, "rtmpe") || (!strcmp(proto, "rtmpte"))) { + if (!strcmp(proto, "rtmpte")) + av_dict_set(&opts, "ffrtmpcrypt_tunneling", "1", 1); + /* open the encrypted connection */ ff_url_join(buf, sizeof(buf), "ffrtmpcrypt", NULL, hostname, port, NULL); rt->encrypted = 1; @@ -1574,6 +1577,24 @@ URLProtocol ff_rtmpt_protocol = { .priv_data_class = &rtmpt_class, }; +static const AVClass rtmpte_class = { + .class_name = "rtmpte", + .item_name = av_default_item_name, + .option = rtmp_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +URLProtocol ff_rtmpte_protocol = { + .name = "rtmpte", + .url_open = rtmp_open, + .url_read = rtmp_read, + .url_write = rtmp_write, + .url_close = rtmp_close, + .priv_data_size = sizeof(RTMPContext), + .flags = URL_PROTOCOL_FLAG_NETWORK, + .priv_data_class = &rtmpte_class, +}; + static const AVClass rtmpts_class = { .class_name = "rtmpts", .item_name = av_default_item_name, diff --git a/libavformat/version.h b/libavformat/version.h index 3681e8db13..bc6cae664b 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 54 -#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 58db34aa1e6c4cb1d876d0abc497c5e902da857e Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 22 Jul 2012 20:46:10 -0700 Subject: h264: refactor NAL decode loop Write out the NAL decoding loops in full so that they are easier to parse for a preprocessor without it having to be aware of macros or other such things in C code. This also makes the code more readable. Signed-off-by: Luca Barbato --- libavcodec/h264.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index a4afcc870e..dcb9e00c43 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -175,42 +175,50 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, src++; length--; +#define STARTCODE_TEST \ + if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \ + if (src[i + 2] != 3) { \ + /* startcode, so we must be past the end */ \ + length = i; \ + } \ + break; \ + } #if HAVE_FAST_UNALIGNED +#define FIND_FIRST_ZERO \ + if (i > 0 && !src[i]) \ + i--; \ + while (src[i]) \ + i++ #if HAVE_FAST_64BIT -#define RS 7 for (i = 0; i + 1 < length; i += 9) { if (!((~AV_RN64A(src + i) & (AV_RN64A(src + i) - 0x0100010001000101ULL)) & 0x8000800080008080ULL)) + continue; + FIND_FIRST_ZERO; + STARTCODE_TEST; + i -= 7; + } #else -#define RS 3 for (i = 0; i + 1 < length; i += 5) { if (!((~AV_RN32A(src + i) & (AV_RN32A(src + i) - 0x01000101U)) & 0x80008080U)) -#endif continue; - if (i > 0 && !src[i]) - i--; - while (src[i]) - i++; + FIND_FIRST_ZERO; + STARTCODE_TEST; + i -= 3; + } +#endif #else -#define RS 0 for (i = 0; i + 1 < length; i += 2) { if (src[i]) continue; if (i > 0 && src[i - 1] == 0) i--; -#endif - if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { - if (src[i + 2] != 3) { - /* startcode, so we must be past the end */ - length = i; - } - break; - } - i -= RS; + STARTCODE_TEST; } +#endif if (i >= length - 1) { // no escaped 0 *dst_length = length; -- cgit v1.2.3 From 37c6ad23451eeda83621d34ff9ab0f6fd2cbf3dd Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Fri, 16 Dec 2011 22:43:35 +0100 Subject: wavpack: set bits_per_raw_sample for S32 samples to properly identify 24-bit Signed-off-by: Michael Niedermayer Signed-off-by: Derek Buitenhuis --- libavcodec/wavpack.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 022a4ce7d5..920e0b5fd9 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -1202,6 +1202,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data, avctx->sample_fmt = AV_SAMPLE_FMT_S16; } else { avctx->sample_fmt = AV_SAMPLE_FMT_S32; + avctx->bits_per_raw_sample = ((frame_flags & 0x03) + 1) << 3; } /* get output buffer */ -- cgit v1.2.3 From 61884b9d1b6be16dbbfae6700cf8628e037ea28b Mon Sep 17 00:00:00 2001 From: Clément Bœsch Date: Thu, 1 Sep 2011 20:06:05 +0200 Subject: wav: init st to NULL to avoid a false-positive warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If st is NULL, it means no 'fmt ' tag is found, but 'data' tag (which needs a previous 'fmt ' tag to be parsed correctly and st initialized) check will make sure st is never dereferenced in that case. Fixes warning: libavformat/wav.c: In function ‘wav_read_header’: libavformat/wav.c:499:44: warning: ‘st’ may be used uninitialized in this function [-Wmaybe-uninitialized] Signed-off-by: Derek Buitenhuis --- libavformat/wav.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/wav.c b/libavformat/wav.c index c01121f9db..1bfe6d5eb6 100644 --- a/libavformat/wav.c +++ b/libavformat/wav.c @@ -387,7 +387,7 @@ static int wav_read_header(AVFormatContext *s) int rf64; uint32_t tag, list_type; AVIOContext *pb = s->pb; - AVStream *st; + AVStream *st = NULL; WAVContext *wav = s->priv_data; int ret, got_fmt = 0; int64_t next_tag_ofs, data_ofs = -1; -- cgit v1.2.3 From 6c8fdfc5e51902c6011d450b7ddc94bd1fe1030e Mon Sep 17 00:00:00 2001 From: Reimar Döffinger Date: Sat, 21 Jul 2012 13:22:04 +0200 Subject: zerocodec: fix direct rendering. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set picture type before calling get_buffer. This allows the DR application to make better decisions. It also fixes a resource leak in case of missing reference frames since it would call get_buffer but never release_buffer. Also use FFSWAP to ensure that the AVFrame is properly initialized in the next get_buffer (in particular that data[0] is NULL). Signed-off-by: Reimar Döffinger Signed-off-by: Derek Buitenhuis --- libavcodec/zerocodec.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c index 487cb32797..4f43d52a6b 100644 --- a/libavcodec/zerocodec.c +++ b/libavcodec/zerocodec.c @@ -33,11 +33,23 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, AVFrame *pic = avctx->coded_frame; AVFrame *prev_pic = &zc->previous_frame; z_stream *zstream = &zc->zstream; - uint8_t *prev, *dst; + uint8_t *prev = prev_pic->data[0], *dst; int i, j, zret; pic->reference = 3; + if (avpkt->flags & AV_PKT_FLAG_KEY) { + pic->key_frame = 1; + pic->pict_type = AV_PICTURE_TYPE_I; + } else { + if (!prev) { + av_log(avctx, AV_LOG_ERROR, "Missing reference frame!\n"); + return AVERROR_INVALIDDATA; + } + pic->key_frame = 0; + pic->pict_type = AV_PICTURE_TYPE_P; + } + if (avctx->get_buffer(avctx, pic) < 0) { av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); return AVERROR(ENOMEM); @@ -53,7 +65,6 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, zstream->next_in = avpkt->data; zstream->avail_in = avpkt->size; - prev = prev_pic->data[0]; dst = pic->data[0]; /** @@ -61,18 +72,6 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, * is the same as the previous frame, set it to 0. */ - if (avpkt->flags & AV_PKT_FLAG_KEY) { - pic->key_frame = 1; - pic->pict_type = AV_PICTURE_TYPE_I; - } else { - if (!prev) { - av_log(avctx, AV_LOG_ERROR, "Missing reference frame!\n"); - return AVERROR_INVALIDDATA; - } - pic->key_frame = 0; - pic->pict_type = AV_PICTURE_TYPE_P; - } - for (i = 0; i < avctx->height; i++) { zstream->next_out = dst; zstream->avail_out = avctx->width << 1; @@ -96,12 +95,13 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, if (prev_pic->data[0]) avctx->release_buffer(avctx, prev_pic); - /* Store the previouse frame for use later */ - *prev_pic = *pic; - *data_size = sizeof(AVFrame); *(AVFrame *)data = *pic; + /* Store the previous frame for use later. + * FFSWAP ensures that e.g. pic->data is NULLed. */ + FFSWAP(AVFrame, *pic, *prev_pic); + return avpkt->size; } -- cgit v1.2.3 From d04c5293ce88927ad359ca276e287bfa63c2329d Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Mon, 23 Jul 2012 11:03:58 -0400 Subject: v410dec: Implement explode mode support Try and decode broken files, but still fail if explode mode is enabled. Signed-off-by: Derek Buitenhuis --- libavcodec/v410dec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/v410dec.c b/libavcodec/v410dec.c index a6f236bd6d..d7660ee4fb 100644 --- a/libavcodec/v410dec.c +++ b/libavcodec/v410dec.c @@ -29,8 +29,12 @@ static av_cold int v410_decode_init(AVCodecContext *avctx) avctx->bits_per_raw_sample = 10; if (avctx->width & 1) { - av_log(avctx, AV_LOG_ERROR, "v410 requires even width.\n"); - return AVERROR_INVALIDDATA; + if (avctx->err_recognition & AV_EF_EXPLODE) { + av_log(avctx, AV_LOG_ERROR, "v410 requires width to be even, continuing anyway.\n"); + return AVERROR_INVALIDDATA; + } else { + av_log(avctx, AV_LOG_WARNING, "v410 requires width to be even.\n"); + } } avctx->coded_frame = avcodec_alloc_frame(); -- cgit v1.2.3