From e1a7af6f290489812ed47359eaff0edac2f5df95 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 13 Jan 2012 16:14:48 -0500 Subject: [PATCH 01/10] FATE: fix targa tests on big-endian systems --- tests/fate/image.mak | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fate/image.mak b/tests/fate/image.mak index 153a4f397e..7fdbdc4280 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -48,13 +48,13 @@ fate-targa: $(FATE_TARGA) fate-targa-conformance-CBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CBW8.TGA # fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA -fate-targa-conformance-CTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC16.TGA +fate-targa-conformance-CTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC16.TGA -pix_fmt rgb555le fate-targa-conformance-CTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC24.TGA -fate-targa-conformance-CTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC32.TGA +fate-targa-conformance-CTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC32.TGA -pix_fmt bgra fate-targa-conformance-UBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UBW8.TGA # fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA -fate-targa-conformance-UTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC16.TGA +fate-targa-conformance-UTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC16.TGA -pix_fmt rgb555le fate-targa-conformance-UTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC24.TGA -fate-targa-conformance-UTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC32.TGA +fate-targa-conformance-UTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC32.TGA -pix_fmt bgra fate-targa-top-to-bottom: CMD = framecrc -i $(SAMPLES)/targa/lena-top-to-bottom.tga From faaebcdf6bd67880f50e7ec180f24870e7bd8cef Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 2 Jan 2012 15:17:12 -0500 Subject: [PATCH 02/10] targa: add support for rgb555 palette --- libavcodec/targa.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/libavcodec/targa.c b/libavcodec/targa.c index b821d74f8d..00da7587d0 100644 --- a/libavcodec/targa.c +++ b/libavcodec/targa.c @@ -22,6 +22,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/imgutils.h" #include "avcodec.h" +#include "bytestream.h" #include "targa.h" typedef struct TargaContext { @@ -172,27 +173,45 @@ static int decode_frame(AVCodecContext *avctx, } if(colors){ - size_t pal_size; + int pal_size, pal_sample_size; if((colors + first_clr) > 256){ av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr); return -1; } - if(csize != 24){ + switch (csize) { + case 24: pal_sample_size = 3; break; + case 16: + case 15: pal_sample_size = 2; break; + default: av_log(avctx, AV_LOG_ERROR, "Palette entry size %i bits is not supported\n", csize); return -1; } - pal_size = colors * ((csize + 1) >> 3); + pal_size = colors * pal_sample_size; CHECK_BUFFER_SIZE(buf, buf_end, pal_size, "color table"); if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway buf += pal_size; else{ - int r, g, b, t; - int32_t *pal = ((int32_t*)p->data[1]) + first_clr; - for(t = 0; t < colors; t++){ - r = *buf++; - g = *buf++; - b = *buf++; - *pal++ = (b << 16) | (g << 8) | r; + int t; + uint32_t *pal = ((uint32_t *)p->data[1]) + first_clr; + + switch (pal_sample_size) { + case 3: + /* RGB24 */ + for (t = 0; t < colors; t++) + *pal++ = bytestream_get_le24(&buf); + break; + case 2: + /* RGB555 */ + for (t = 0; t < colors; t++) { + uint32_t v = bytestream_get_le16(&buf); + v = ((v & 0x7C00) << 9) | + ((v & 0x03E0) << 6) | + ((v & 0x001F) << 3); + /* left bit replication */ + v |= (v & 0xE0E0E0U) >> 5; + *pal++ = v; + } + break; } p->palette_has_changed = 1; } From 9c2f9b0e2dd5bd570e571890bdfb6e77190c4c55 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 13 Jan 2012 16:41:15 -0500 Subject: [PATCH 03/10] FATE: enable the 2 remaining targa conformance suite tests --- tests/fate/image.mak | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fate/image.mak b/tests/fate/image.mak index 7fdbdc4280..df0603f2ef 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -32,10 +32,12 @@ FATE_TESTS += fate-sunraster-24bit-rle fate-sunraster-24bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-24bit-rle.sun FATE_TARGA = CBW8 \ + CCM8 \ CTC16 \ CTC24 \ CTC32 \ UBW8 \ + UCM8 \ UTC16 \ UTC24 \ UTC32 @@ -47,12 +49,12 @@ FATE_TESTS += $(FATE_TARGA) fate-targa: $(FATE_TARGA) fate-targa-conformance-CBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CBW8.TGA -# fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA +fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA fate-targa-conformance-CTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC16.TGA -pix_fmt rgb555le fate-targa-conformance-CTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC24.TGA fate-targa-conformance-CTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC32.TGA -pix_fmt bgra fate-targa-conformance-UBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UBW8.TGA -# fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA +fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA fate-targa-conformance-UTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC16.TGA -pix_fmt rgb555le fate-targa-conformance-UTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC24.TGA fate-targa-conformance-UTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC32.TGA -pix_fmt bgra From 502bf3b462e40ae64d088c3246ef48fa618e4572 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Fri, 13 Jan 2012 23:52:59 +0100 Subject: [PATCH 04/10] fate: add missing reference files for targa tests in 9c2f9b0e2 Fixes fate-targa-conformance-CCM8 and fate-targa-conformance-UCM8. --- tests/ref/fate/targa-conformance-CCM8 | 1 + tests/ref/fate/targa-conformance-UCM8 | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/ref/fate/targa-conformance-CCM8 create mode 100644 tests/ref/fate/targa-conformance-UCM8 diff --git a/tests/ref/fate/targa-conformance-CCM8 b/tests/ref/fate/targa-conformance-CCM8 new file mode 100644 index 0000000000..3f6be24360 --- /dev/null +++ b/tests/ref/fate/targa-conformance-CCM8 @@ -0,0 +1 @@ +0, 0, 17408, 0x2bc2e306 diff --git a/tests/ref/fate/targa-conformance-UCM8 b/tests/ref/fate/targa-conformance-UCM8 new file mode 100644 index 0000000000..3f6be24360 --- /dev/null +++ b/tests/ref/fate/targa-conformance-UCM8 @@ -0,0 +1 @@ +0, 0, 17408, 0x2bc2e306 From 4c82c6d9932bfdb1a9eb288d566ded9d40ca5e24 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 13 Jan 2012 18:40:12 -0500 Subject: [PATCH 05/10] FATE: convert output to rgba for the targa tests which currently output pal8 fixes the tests on big-endian systems --- tests/fate/image.mak | 4 ++-- tests/ref/fate/targa-conformance-CCM8 | 2 +- tests/ref/fate/targa-conformance-UCM8 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fate/image.mak b/tests/fate/image.mak index df0603f2ef..9714cd8c5a 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -49,12 +49,12 @@ FATE_TESTS += $(FATE_TARGA) fate-targa: $(FATE_TARGA) fate-targa-conformance-CBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CBW8.TGA -fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA +fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA -pix_fmt rgba fate-targa-conformance-CTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC16.TGA -pix_fmt rgb555le fate-targa-conformance-CTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC24.TGA fate-targa-conformance-CTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC32.TGA -pix_fmt bgra fate-targa-conformance-UBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UBW8.TGA -fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA +fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA -pix_fmt rgba fate-targa-conformance-UTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC16.TGA -pix_fmt rgb555le fate-targa-conformance-UTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC24.TGA fate-targa-conformance-UTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC32.TGA -pix_fmt bgra diff --git a/tests/ref/fate/targa-conformance-CCM8 b/tests/ref/fate/targa-conformance-CCM8 index 3f6be24360..acc3068e26 100644 --- a/tests/ref/fate/targa-conformance-CCM8 +++ b/tests/ref/fate/targa-conformance-CCM8 @@ -1 +1 @@ -0, 0, 17408, 0x2bc2e306 +0, 0, 65536, 0xcf98bc29 diff --git a/tests/ref/fate/targa-conformance-UCM8 b/tests/ref/fate/targa-conformance-UCM8 index 3f6be24360..acc3068e26 100644 --- a/tests/ref/fate/targa-conformance-UCM8 +++ b/tests/ref/fate/targa-conformance-UCM8 @@ -1 +1 @@ -0, 0, 17408, 0x2bc2e306 +0, 0, 65536, 0xcf98bc29 From 57facb73ab940b1117c22ef9b70a6e5ec237112d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 13 Jan 2012 23:41:16 +0200 Subject: [PATCH 06/10] libx264: Don't leave max_b_frames as -1 if the user didn't set it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit max_b_frames is initialized to -1 for libx264, to allow distinguishing between an explicit user set 0 and a default not touched 0 (see bb73cda2). If max_b_frames is left as -1, this affects dts generation (where expressions like max_b_frames != 0 are used), so make sure it is left at the default 0 after the libx264 init function returns. This avoids unnecessarily producing dts != pts when using profile=baseline. Signed-off-by: Martin Storsjö --- libavcodec/libx264.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 9b347951fd..b3581f168f 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -448,6 +448,9 @@ static av_cold int X264_init(AVCodecContext *avctx) // update AVCodecContext with x264 parameters avctx->has_b_frames = x4->params.i_bframe ? x4->params.i_bframe_pyramid ? 2 : 1 : 0; + if (avctx->max_b_frames < 0) + avctx->max_b_frames = 0; + avctx->bit_rate = x4->params.rc.i_bitrate*1000; #if FF_API_X264_GLOBAL_OPTS avctx->crf = x4->params.rc.f_rf_constant; From 3c172a41065dd3fe1d11af9f0eb16d789d08daf2 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 13 Jan 2012 11:21:15 -0800 Subject: [PATCH 07/10] swscale: change yuv2yuvX code to use cpuflag(). --- libswscale/x86/output.asm | 119 +++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm index 0ec2038d1d..ae2929c84e 100644 --- a/libswscale/x86/output.asm +++ b/libswscale/x86/output.asm @@ -56,7 +56,7 @@ SECTION .text ; of 2. $offset is either 0 or 3. $dither holds 8 values. ;----------------------------------------------------------------------------- -%macro yuv2planeX_fn 4 +%macro yuv2planeX_fn 3 %ifdef ARCH_X86_32 %define cntr_reg r1 @@ -66,12 +66,12 @@ SECTION .text %define movsx movsxd %endif -cglobal yuv2planeX_%2_%1, %4, 7, %3 -%if %2 == 8 || %2 == 9 || %2 == 10 +cglobal yuv2planeX_%1, %3, 7, %2 +%if %1 == 8 || %1 == 9 || %1 == 10 pxor m6, m6 -%endif ; %2 == 8/9/10 +%endif ; %1 == 8/9/10 -%if %2 == 8 +%if %1 == 8 %ifdef ARCH_X86_32 %assign pad 0x2c - (stack_offset & 15) SUB rsp, pad @@ -120,7 +120,7 @@ cglobal yuv2planeX_%2_%1, %4, 7, %3 mova [rsp+16], m3 mova [rsp+24], m_dith %endif ; mmsize == 8/16 -%endif ; %2 == 8 +%endif ; %1 == 8 xor r5, r5 @@ -130,11 +130,11 @@ cglobal yuv2planeX_%2_%1, %4, 7, %3 ; 8 pixels but we can only handle 2 pixels per register, and thus 4 ; pixels per iteration. In order to not have to keep track of where ; we are w.r.t. dithering, we unroll the mmx/8bit loop x2. -%if %2 == 8 +%if %1 == 8 %rep 16/mmsize -%endif ; %2 == 8 +%endif ; %1 == 8 -%if %2 == 8 +%if %1 == 8 %ifdef ARCH_X86_32 mova m2, [rsp+mmsize*(0+%%i)] mova m1, [rsp+mmsize*(1+%%i)] @@ -142,31 +142,31 @@ cglobal yuv2planeX_%2_%1, %4, 7, %3 mova m2, m8 mova m1, m_dith %endif ; x86-32/64 -%else ; %2 == 9/10/16 - mova m1, [yuv2yuvX_%2_start] +%else ; %1 == 9/10/16 + mova m1, [yuv2yuvX_%1_start] mova m2, m1 -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 movsx cntr_reg, r1m .filterloop_ %+ %%i: ; input pixels mov r6, [r2+gprsize*cntr_reg-2*gprsize] -%if %2 == 16 +%if %1 == 16 mova m3, [r6+r5*4] mova m5, [r6+r5*4+mmsize] -%else ; %2 == 8/9/10 +%else ; %1 == 8/9/10 mova m3, [r6+r5*2] -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 mov r6, [r2+gprsize*cntr_reg-gprsize] -%if %2 == 16 +%if %1 == 16 mova m4, [r6+r5*4] mova m6, [r6+r5*4+mmsize] -%else ; %2 == 8/9/10 +%else ; %1 == 8/9/10 mova m4, [r6+r5*2] -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 ; coefficients movd m0, [r0+2*cntr_reg-4]; coeff[0], coeff[1] -%if %2 == 16 +%if %1 == 16 pshuflw m7, m0, 0 ; coeff[0] pshuflw m0, m0, 0x55 ; coeff[1] pmovsxwd m7, m7 ; word -> dword @@ -181,7 +181,7 @@ cglobal yuv2planeX_%2_%1, %4, 7, %3 paddd m1, m5 paddd m2, m4 paddd m1, m6 -%else ; %2 == 10/9/8 +%else ; %1 == 10/9/8 punpcklwd m5, m3, m4 punpckhwd m3, m4 SPLATD m0, m0 @@ -191,84 +191,83 @@ cglobal yuv2planeX_%2_%1, %4, 7, %3 paddd m2, m5 paddd m1, m3 -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 sub cntr_reg, 2 jg .filterloop_ %+ %%i -%if %2 == 16 - psrad m2, 31 - %2 - psrad m1, 31 - %2 -%else ; %2 == 10/9/8 - psrad m2, 27 - %2 - psrad m1, 27 - %2 -%endif ; %2 == 8/9/10/16 +%if %1 == 16 + psrad m2, 31 - %1 + psrad m1, 31 - %1 +%else ; %1 == 10/9/8 + psrad m2, 27 - %1 + psrad m1, 27 - %1 +%endif ; %1 == 8/9/10/16 -%if %2 == 8 +%if %1 == 8 packssdw m2, m1 packuswb m2, m2 movh [r3+r5*1], m2 -%else ; %2 == 9/10/16 -%if %2 == 16 +%else ; %1 == 9/10/16 +%if %1 == 16 packssdw m2, m1 paddw m2, [minshort] -%else ; %2 == 9/10 -%ifidn %1, sse4 - packusdw m2, m1 -%elifidn %1, avx +%else ; %1 == 9/10 +%if cpuflag(sse4) packusdw m2, m1 %else ; mmx2/sse2 packssdw m2, m1 pmaxsw m2, m6 %endif ; mmx2/sse2/sse4/avx - pminsw m2, [yuv2yuvX_%2_upper] -%endif ; %2 == 9/10/16 + pminsw m2, [yuv2yuvX_%1_upper] +%endif ; %1 == 9/10/16 mova [r3+r5*2], m2 -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 add r5, mmsize/2 sub r4d, mmsize/2 -%if %2 == 8 +%if %1 == 8 %assign %%i %%i+2 %endrep -%endif ; %2 == 8 +%endif ; %1 == 8 jg .pixelloop -%if %2 == 8 +%if %1 == 8 %ifdef ARCH_X86_32 ADD rsp, pad RET %else ; x86-64 REP_RET %endif ; x86-32/64 -%else ; %2 == 9/10/16 +%else ; %1 == 9/10/16 REP_RET -%endif ; %2 == 8/9/10/16 +%endif ; %1 == 8/9/10/16 %endmacro %define PALIGNR PALIGNR_MMX %ifdef ARCH_X86_32 -INIT_MMX -yuv2planeX_fn mmx2, 8, 0, 7 -yuv2planeX_fn mmx2, 9, 0, 5 -yuv2planeX_fn mmx2, 10, 0, 5 +INIT_MMX mmx2 +yuv2planeX_fn 8, 0, 7 +yuv2planeX_fn 9, 0, 5 +yuv2planeX_fn 10, 0, 5 %endif -INIT_XMM -yuv2planeX_fn sse2, 8, 10, 7 -yuv2planeX_fn sse2, 9, 7, 5 -yuv2planeX_fn sse2, 10, 7, 5 +INIT_XMM sse2 +yuv2planeX_fn 8, 10, 7 +yuv2planeX_fn 9, 7, 5 +yuv2planeX_fn 10, 7, 5 %define PALIGNR PALIGNR_SSSE3 -yuv2planeX_fn sse4, 8, 10, 7 -yuv2planeX_fn sse4, 9, 7, 5 -yuv2planeX_fn sse4, 10, 7, 5 -yuv2planeX_fn sse4, 16, 8, 5 - -INIT_AVX -yuv2planeX_fn avx, 8, 10, 7 -yuv2planeX_fn avx, 9, 7, 5 -yuv2planeX_fn avx, 10, 7, 5 +INIT_XMM sse4 +yuv2planeX_fn 8, 10, 7 +yuv2planeX_fn 9, 7, 5 +yuv2planeX_fn 10, 7, 5 +yuv2planeX_fn 16, 8, 5 + +INIT_XMM avx +yuv2planeX_fn 8, 10, 7 +yuv2planeX_fn 9, 7, 5 +yuv2planeX_fn 10, 7, 5 ; %1=outout-bpc, %2=alignment (u/a) %macro yuv2plane1_mainloop 2 From b5c2b5af6a2f5baade1d0688703b3e46fa2f6cf2 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 13 Jan 2012 16:23:55 +0100 Subject: [PATCH 08/10] configure: provide libavfilter/version.h header to get_version() Fix libavfilter library version numbers generation, which was broken in 3167dc9515810bbdd86d99d773bcf84657d2e72a. Signed-off-by: Anton Khirnov --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 3146641724..93b98a96dd 100755 --- a/configure +++ b/configure @@ -3361,7 +3361,7 @@ get_version(){ get_version LIBAVCODEC libavcodec/version.h get_version LIBAVDEVICE libavdevice/avdevice.h -get_version LIBAVFILTER libavfilter/avfilter.h +get_version LIBAVFILTER libavfilter/version.h get_version LIBAVFORMAT libavformat/version.h get_version LIBAVUTIL libavutil/avutil.h get_version LIBPOSTPROC libpostproc/postprocess.h From e44c11e9fa505da3c54738ae2d21123338a28ca6 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 13 Jan 2012 16:35:54 +0100 Subject: [PATCH 09/10] cosmetics: Move static and inline attributes to more standard places. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes several "‘static’ is not at beginning of declaration" warnings. --- libavcodec/g722.c | 2 +- libavcodec/h264_loopfilter.c | 51 ++++++++++++++++++++++++++++++------ libavfilter/vf_fade.c | 2 +- libswscale/utils.c | 2 +- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/libavcodec/g722.c b/libavcodec/g722.c index 7b9ff7243a..a911bc7b37 100644 --- a/libavcodec/g722.c +++ b/libavcodec/g722.c @@ -129,7 +129,7 @@ static void do_adaptive_prediction(struct G722Band *band, const int cur_diff) band->prev_qtzd_reconst = cur_qtzd_reconst; } -static int inline linear_scale_factor(const int log_factor) +static inline int linear_scale_factor(const int log_factor) { const int wd1 = inv_log2_table[(log_factor >> 6) & 31]; const int shift = log_factor >> 11; diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index 64b07e91f0..be750caa6d 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -101,7 +101,11 @@ static const uint8_t tc0_table[52*3][4] = { }; /* intra: 0 if this loopfilter call is guaranteed to be inter (bS < 4), 1 if it might be intra (bS == 4) */ -static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) { +static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride, + const int16_t bS[4], + unsigned int qp, int a, int b, + H264Context *h, int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -118,7 +122,12 @@ static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, const in h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta); } } -static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) { + +static av_always_inline void filter_mb_edgecv(uint8_t *pix, int stride, + const int16_t bS[4], + unsigned int qp, int a, int b, + H264Context *h, int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -136,7 +145,12 @@ static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, const i } } -static void av_always_inline filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, const int16_t bS[7], int bsi, int qp, int a, int b, int intra ) { +static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix, + int stride, + const int16_t bS[7], int bsi, + int qp, int a, int b, + int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -153,7 +167,13 @@ static void av_always_inline filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta); } } -static void av_always_inline filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, const int16_t bS[7], int bsi, int qp, int a, int b, int intra ) { + +static av_always_inline void filter_mb_mbaff_edgecv(H264Context *h, + uint8_t *pix, int stride, + const int16_t bS[7], + int bsi, int qp, int a, + int b, int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -171,7 +191,11 @@ static void av_always_inline filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pi } } -static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) { +static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride, + const int16_t bS[4], + unsigned int qp, int a, int b, + H264Context *h, int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -189,7 +213,11 @@ static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, const in } } -static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) { +static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride, + const int16_t bS[4], + unsigned int qp, int a, int b, + H264Context *h, int intra) +{ const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; @@ -207,8 +235,15 @@ static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, const i } } -static void av_always_inline h264_filter_mb_fast_internal( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, - unsigned int linesize, unsigned int uvlinesize, int pixel_shift) { +static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, + int mb_x, int mb_y, + uint8_t *img_y, + uint8_t *img_cb, + uint8_t *img_cr, + unsigned int linesize, + unsigned int uvlinesize, + int pixel_shift) +{ MpegEncContext * const s = &h->s; int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); int chroma444 = CHROMA444; diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 0c8668ce90..9f748b8882 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -69,7 +69,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) static int query_formats(AVFilterContext *ctx) { - const static enum PixelFormat pix_fmts[] = { + static const enum PixelFormat pix_fmts[] = { PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, diff --git a/libswscale/utils.c b/libswscale/utils.c index d252f2e32d..b49f924244 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -69,7 +69,7 @@ typedef struct FormatEntry { int is_supported_in, is_supported_out; } FormatEntry; -const static FormatEntry format_entries[PIX_FMT_NB] = { +static const FormatEntry format_entries[PIX_FMT_NB] = { [PIX_FMT_YUV420P] = { 1 , 1 }, [PIX_FMT_YUYV422] = { 1 , 1 }, [PIX_FMT_RGB24] = { 1 , 1 }, From 4cd0bdae9a62d1f0366e60603222762af31e5289 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Fri, 13 Jan 2012 23:05:57 +0530 Subject: [PATCH 10/10] sgidec: Use bytestream2 functions to prevent buffer overreads. The patch also adds several bytestream macros to deal with native endian. Signed-off-by: Justin Ruggles --- libavcodec/bytestream.h | 36 ++++++++++++++ libavcodec/sgidec.c | 103 ++++++++++++++++++++-------------------- 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index 9ec74cf9a7..503598a4bc 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -75,6 +75,42 @@ DEF (byte, 1, AV_RB8 , AV_WB8 ) #undef DEF64 #undef DEF_T +#if HAVE_BIGENDIAN +# define bytestream2_get_ne16 bytestream2_get_be16 +# define bytestream2_get_ne24 bytestream2_get_be24 +# define bytestream2_get_ne32 bytestream2_get_be32 +# define bytestream2_get_ne64 bytestream2_get_be64 +# define bytestream2_get_ne16u bytestream2_get_be16u +# define bytestream2_get_ne24u bytestream2_get_be24u +# define bytestream2_get_ne32u bytestream2_get_be32u +# define bytestream2_get_ne64u bytestream2_get_be64u +# define bytestream2_put_ne16 bytestream2_put_be16 +# define bytestream2_put_ne24 bytestream2_put_be24 +# define bytestream2_put_ne32 bytestream2_put_be32 +# define bytestream2_put_ne64 bytestream2_put_be64 +# define bytestream2_peek_ne16 bytestream2_peek_be16 +# define bytestream2_peek_ne24 bytestream2_peek_be24 +# define bytestream2_peek_ne32 bytestream2_peek_be32 +# define bytestream2_peek_ne64 bytestream2_peek_be64 +#else +# define bytestream2_get_ne16 bytestream2_get_le16 +# define bytestream2_get_ne24 bytestream2_get_le24 +# define bytestream2_get_ne32 bytestream2_get_le32 +# define bytestream2_get_ne64 bytestream2_get_le64 +# define bytestream2_get_ne16u bytestream2_get_le16u +# define bytestream2_get_ne24u bytestream2_get_le24u +# define bytestream2_get_ne32u bytestream2_get_le32u +# define bytestream2_get_ne64u bytestream2_get_le64u +# define bytestream2_put_ne16 bytestream2_put_le16 +# define bytestream2_put_ne24 bytestream2_put_le24 +# define bytestream2_put_ne32 bytestream2_put_le32 +# define bytestream2_put_ne64 bytestream2_put_le64 +# define bytestream2_peek_ne16 bytestream2_peek_le16 +# define bytestream2_peek_ne24 bytestream2_peek_le24 +# define bytestream2_peek_ne32 bytestream2_peek_le32 +# define bytestream2_peek_ne64 bytestream2_peek_le64 +#endif + static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size) { diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c index e5b3c5933c..dfa00ed79f 100644 --- a/libavcodec/sgidec.c +++ b/libavcodec/sgidec.c @@ -31,26 +31,27 @@ typedef struct SgiState { unsigned int depth; unsigned int bytes_per_channel; int linesize; + GetByteContext g; } SgiState; /** * Expand an RLE row into a channel. - * @param in_buf input buffer - * @param in_end end of input buffer + * @param s the current image state * @param out_buf Points to one line after the output buffer. * @param out_end end of line in output buffer * @param pixelstride pixel stride of input buffer * @return size of output in bytes, -1 if buffer overflows */ -static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, - unsigned char *out_buf, uint8_t* out_end, int pixelstride) +static int expand_rle_row(SgiState *s, uint8_t *out_buf, + uint8_t *out_end, int pixelstride) { unsigned char pixel, count; unsigned char *orig = out_buf; while (1) { - if(in_buf + 1 > in_end) return -1; - pixel = bytestream_get_byte(&in_buf); + if (bytestream2_get_bytes_left(&s->g) < 1) + return AVERROR_INVALIDDATA; + pixel = bytestream2_get_byteu(&s->g); if (!(count = (pixel & 0x7f))) { return (out_buf - orig) / pixelstride; } @@ -60,11 +61,11 @@ static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, if (pixel & 0x80) { while (count--) { - *out_buf = bytestream_get_byte(&in_buf); + *out_buf = bytestream2_get_byte(&s->g); out_buf += pixelstride; } } else { - pixel = bytestream_get_byte(&in_buf); + pixel = bytestream2_get_byte(&s->g); while (count--) { *out_buf = pixel; @@ -77,37 +78,32 @@ static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, /** * Read a run length encoded SGI image. * @param out_buf output buffer - * @param in_buf input buffer - * @param in_end end of input buffer * @param s the current image state * @return 0 if no error, else return error number. */ -static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf, - const uint8_t *in_end, SgiState* s) +static int read_rle_sgi(uint8_t *out_buf, SgiState *s) { uint8_t *dest_row; unsigned int len = s->height * s->depth * 4; - const uint8_t *start_table = in_buf; + GetByteContext g_table = s->g; unsigned int y, z; unsigned int start_offset; /* size of RLE offset and length tables */ - if(len * 2 > in_end - in_buf) { + if (len * 2 > bytestream2_get_bytes_left(&s->g)) { return AVERROR_INVALIDDATA; } - in_buf -= SGI_HEADER_SIZE; for (z = 0; z < s->depth; z++) { dest_row = out_buf; for (y = 0; y < s->height; y++) { dest_row -= s->linesize; - start_offset = bytestream_get_be32(&start_table); - if(start_offset > in_end - in_buf) { + start_offset = bytestream2_get_be32(&g_table); + bytestream2_seek(&s->g, start_offset, SEEK_SET); + if (expand_rle_row(s, dest_row + z, dest_row + FFABS(s->linesize), + s->depth) != s->width) { return AVERROR_INVALIDDATA; } - if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z, - dest_row + FFABS(s->linesize), s->depth) != s->width) - return AVERROR_INVALIDDATA; } } return 0; @@ -117,32 +113,37 @@ static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf, * Read an uncompressed SGI image. * @param out_buf output buffer * @param out_end end ofoutput buffer - * @param in_buf input buffer - * @param in_end end of input buffer * @param s the current image state * @return 0 if read success, otherwise return -1. */ static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end, - const uint8_t *in_buf, const uint8_t *in_end, SgiState* s) + SgiState *s) { int x, y, z; - const uint8_t *ptr; unsigned int offset = s->height * s->width * s->bytes_per_channel; + GetByteContext gp[4]; /* Test buffer size. */ - if (offset * s->depth > in_end - in_buf) { - return -1; + if (offset * s->depth > bytestream2_get_bytes_left(&s->g)) + return AVERROR_INVALIDDATA; + + /* Create a reader for each plane */ + for (z = 0; z < s->depth; z++) { + gp[z] = s->g; + bytestream2_skip(&gp[z], z * offset); } for (y = s->height - 1; y >= 0; y--) { out_end = out_buf + (y * s->linesize); - for (x = s->width; x > 0; x--) { - ptr = in_buf += s->bytes_per_channel; - for(z = 0; z < s->depth; z ++) { - memcpy(out_end, ptr, s->bytes_per_channel); - out_end += s->bytes_per_channel; - ptr += offset; - } + if (s->bytes_per_channel == 1) { + for (x = s->width; x > 0; x--) + for (z = 0; z < s->depth; z++) + *out_end++ = bytestream2_get_byteu(&gp[z]); + } else { + uint16_t *out16 = (uint16_t *)out_end; + for (x = s->width; x > 0; x--) + for (z = 0; z < s->depth; z++) + *out16++ = bytestream2_get_ne16u(&gp[z]); } } return 0; @@ -152,33 +153,31 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { - const uint8_t *in_buf = avpkt->data; - int buf_size = avpkt->size; SgiState *s = avctx->priv_data; AVFrame *picture = data; AVFrame *p = &s->picture; - const uint8_t *in_end = in_buf + buf_size; unsigned int dimension, rle; int ret = 0; uint8_t *out_buf, *out_end; - if (buf_size < SGI_HEADER_SIZE){ - av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", buf_size); - return -1; + bytestream2_init(&s->g, avpkt->data, avpkt->size); + if (bytestream2_get_bytes_left(&s->g) < SGI_HEADER_SIZE) { + av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", avpkt->size); + return AVERROR_INVALIDDATA; } /* Test for SGI magic. */ - if (bytestream_get_be16(&in_buf) != SGI_MAGIC) { + if (bytestream2_get_be16(&s->g) != SGI_MAGIC) { av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); - return -1; + return AVERROR_INVALIDDATA; } - rle = bytestream_get_byte(&in_buf); - s->bytes_per_channel = bytestream_get_byte(&in_buf); - dimension = bytestream_get_be16(&in_buf); - s->width = bytestream_get_be16(&in_buf); - s->height = bytestream_get_be16(&in_buf); - s->depth = bytestream_get_be16(&in_buf); + rle = bytestream2_get_byte(&s->g); + s->bytes_per_channel = bytestream2_get_byte(&s->g); + dimension = bytestream2_get_be16(&s->g); + s->width = bytestream2_get_be16(&s->g); + s->height = bytestream2_get_be16(&s->g); + s->depth = bytestream2_get_be16(&s->g); if (s->bytes_per_channel != 1 && (s->bytes_per_channel != 2 || rle)) { av_log(avctx, AV_LOG_ERROR, "wrong channel number\n"); @@ -224,19 +223,19 @@ static int decode_frame(AVCodecContext *avctx, s->linesize = p->linesize[0]; /* Skip header. */ - in_buf += SGI_HEADER_SIZE - 12; + bytestream2_seek(&s->g, SGI_HEADER_SIZE, SEEK_SET); if (rle) { - ret = read_rle_sgi(out_end, in_buf, in_end, s); + ret = read_rle_sgi(out_end, s); } else { - ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s); + ret = read_uncompressed_sgi(out_buf, out_end, s); } if (ret == 0) { *picture = s->picture; *data_size = sizeof(AVPicture); - return buf_size; + return avpkt->size; } else { - return -1; + return ret; } }