From 122d5c526a43122b1f9ac9bce79e3938c8354e43 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 7 Aug 2012 12:19:58 -0700 Subject: aacdec: Don't fall back to the old output configuration when no old configuration is present. Fixes MP4 files where the first frame is broken. --- libavcodec/aacdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec') diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 958c9d2f97..1c59ec5937 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -365,7 +365,7 @@ static void push_output_configuration(AACContext *ac) { * configuration is unlocked. */ static void pop_output_configuration(AACContext *ac) { - if (ac->oc[1].status != OC_LOCKED) { + if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { ac->oc[1] = ac->oc[0]; ac->avctx->channels = ac->oc[1].channels; ac->avctx->channel_layout = ac->oc[1].channel_layout; -- cgit v1.2.3 From c318626ce248e55df032146b16e8e0f4ed1d99fb Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 8 Aug 2012 13:51:52 +0100 Subject: x86: rename libavutil/x86_cpu.h to libavutil/x86/asm.h This puts x86-specific things in the x86/ subdirectory where they belong. Signed-off-by: Mans Rullgard --- libavcodec/msmpeg4.c | 2 +- libavcodec/x86/ac3dsp_mmx.c | 2 +- libavcodec/x86/cabac.h | 2 +- libavcodec/x86/cavsdsp_mmx.c | 2 +- libavcodec/x86/dnxhd_mmx.c | 2 +- libavcodec/x86/dsputil_mmx.c | 2 +- libavcodec/x86/dsputil_mmx.h | 2 +- libavcodec/x86/dsputilenc_mmx.c | 2 +- libavcodec/x86/fdct_mmx.c | 2 +- libavcodec/x86/fmtconvert_mmx.c | 2 +- libavcodec/x86/h264dsp_mmx.c | 2 +- libavcodec/x86/idct_sse2_xvid.c | 2 +- libavcodec/x86/lpc_mmx.c | 2 +- libavcodec/x86/mlpdsp.c | 2 +- libavcodec/x86/motion_est_mmx.c | 2 +- libavcodec/x86/mpegaudiodec_mmx.c | 2 +- libavcodec/x86/mpegvideo_mmx.c | 2 +- libavcodec/x86/rv34dsp_init.c | 2 +- libavcodec/x86/snowdsp_mmx.c | 2 +- libavcodec/x86/vc1dsp_mmx.c | 2 +- libavcodec/x86/vp56dsp_init.c | 2 +- libavcodec/x86/vp8dsp-init.c | 2 +- libavfilter/x86/gradfun.c | 2 +- libavfilter/x86/yadif.c | 2 +- libavutil/x86/asm.h | 98 +++++++++++++++++++++++++++++++++++++++ libavutil/x86/cpu.c | 2 +- libavutil/x86_cpu.h | 98 --------------------------------------- libswscale/utils.c | 2 +- libswscale/x86/rgb2rgb.c | 2 +- libswscale/x86/swscale.c | 2 +- libswscale/x86/yuv2rgb.c | 2 +- 31 files changed, 127 insertions(+), 127 deletions(-) create mode 100644 libavutil/x86/asm.h delete mode 100644 libavutil/x86_cpu.h (limited to 'libavcodec') diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index e20f9b251a..c4ef22e74c 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -31,7 +31,7 @@ #include "dsputil.h" #include "mpegvideo.h" #include "msmpeg4.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "h263.h" #include "mpeg4video.h" #include "msmpeg4data.h" diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c index 0ac8685c6d..f3db67a84f 100644 --- a/libavcodec/x86/ac3dsp_mmx.c +++ b/libavcodec/x86/ac3dsp_mmx.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "dsputil_mmx.h" #include "libavcodec/ac3dsp.h" diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 02dbc54db7..389f155745 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -23,7 +23,7 @@ #include "libavcodec/cabac.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/internal.h" #include "config.h" diff --git a/libavcodec/x86/cavsdsp_mmx.c b/libavcodec/x86/cavsdsp_mmx.c index 4ed7d8e598..e94003956f 100644 --- a/libavcodec/x86/cavsdsp_mmx.c +++ b/libavcodec/x86/cavsdsp_mmx.c @@ -24,7 +24,7 @@ #include "libavutil/common.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/cavsdsp.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/dnxhd_mmx.c b/libavcodec/x86/dnxhd_mmx.c index 54293aa280..12fe3ae55f 100644 --- a/libavcodec/x86/dnxhd_mmx.c +++ b/libavcodec/x86/dnxhd_mmx.c @@ -21,7 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dnxhdenc.h" #if HAVE_INLINE_ASM diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index f13e920bed..93f9db8299 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/h264dsp.h" #include "libavcodec/mpegvideo.h" diff --git a/libavcodec/x86/dsputil_mmx.h b/libavcodec/x86/dsputil_mmx.h index f1db78d5c4..316c384d1a 100644 --- a/libavcodec/x86/dsputil_mmx.h +++ b/libavcodec/x86/dsputil_mmx.h @@ -24,7 +24,7 @@ #include #include "libavcodec/dsputil.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" typedef struct { uint64_t a, b; } xmm_reg; diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c index 0ac4d2c10d..c0ef0bac3e 100644 --- a/libavcodec/x86/dsputilenc_mmx.c +++ b/libavcodec/x86/dsputilenc_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "libavcodec/mathops.h" diff --git a/libavcodec/x86/fdct_mmx.c b/libavcodec/x86/fdct_mmx.c index 3614fd151a..f9bd3f2508 100644 --- a/libavcodec/x86/fdct_mmx.c +++ b/libavcodec/x86/fdct_mmx.c @@ -31,7 +31,7 @@ */ #include "libavutil/common.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #if HAVE_INLINE_ASM diff --git a/libavcodec/x86/fmtconvert_mmx.c b/libavcodec/x86/fmtconvert_mmx.c index fbdc5262b9..6f3d14aedc 100644 --- a/libavcodec/x86/fmtconvert_mmx.c +++ b/libavcodec/x86/fmtconvert_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/fmtconvert.h" #include "libavcodec/dsputil.h" diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c index 0612ffbb8b..f24f751fb3 100644 --- a/libavcodec/x86/h264dsp_mmx.c +++ b/libavcodec/x86/h264dsp_mmx.c @@ -19,7 +19,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/h264dsp.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c index 8249e97ccf..b58db79a5a 100644 --- a/libavcodec/x86/idct_sse2_xvid.c +++ b/libavcodec/x86/idct_sse2_xvid.c @@ -39,7 +39,7 @@ */ #include "libavcodec/dsputil.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "idct_xvid.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/lpc_mmx.c b/libavcodec/x86/lpc_mmx.c index 27bebe856a..609f4e5cd2 100644 --- a/libavcodec/x86/lpc_mmx.c +++ b/libavcodec/x86/lpc_mmx.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavcodec/lpc.h" diff --git a/libavcodec/x86/mlpdsp.c b/libavcodec/x86/mlpdsp.c index 400855d7c4..16e38c3313 100644 --- a/libavcodec/x86/mlpdsp.c +++ b/libavcodec/x86/mlpdsp.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mlp.h" diff --git a/libavcodec/x86/motion_est_mmx.c b/libavcodec/x86/motion_est_mmx.c index 68b1633a47..c3136eb1fe 100644 --- a/libavcodec/x86/motion_est_mmx.c +++ b/libavcodec/x86/motion_est_mmx.c @@ -22,7 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/mpegaudiodec_mmx.c b/libavcodec/x86/mpegaudiodec_mmx.c index 88a347796c..701ae75138 100644 --- a/libavcodec/x86/mpegaudiodec_mmx.c +++ b/libavcodec/x86/mpegaudiodec_mmx.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegaudiodsp.h" diff --git a/libavcodec/x86/mpegvideo_mmx.c b/libavcodec/x86/mpegvideo_mmx.c index 85f6866342..46ed30a76d 100644 --- a/libavcodec/x86/mpegvideo_mmx.c +++ b/libavcodec/x86/mpegvideo_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/avcodec.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" diff --git a/libavcodec/x86/rv34dsp_init.c b/libavcodec/x86/rv34dsp_init.c index 7284a9beaf..b07ad89f0e 100644 --- a/libavcodec/x86/rv34dsp_init.c +++ b/libavcodec/x86/rv34dsp_init.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/rv34dsp.h" diff --git a/libavcodec/x86/snowdsp_mmx.c b/libavcodec/x86/snowdsp_mmx.c index 770cc1cc73..fb190d8d8d 100644 --- a/libavcodec/x86/snowdsp_mmx.c +++ b/libavcodec/x86/snowdsp_mmx.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/avcodec.h" #include "libavcodec/snow.h" #include "libavcodec/dwt.h" diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c index aae08c2364..9200798310 100644 --- a/libavcodec/x86/vc1dsp_mmx.c +++ b/libavcodec/x86/vc1dsp_mmx.c @@ -25,7 +25,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" #include "libavcodec/vc1dsp.h" diff --git a/libavcodec/x86/vp56dsp_init.c b/libavcodec/x86/vp56dsp_init.c index 69c197e520..aa5f5e5d4f 100644 --- a/libavcodec/x86/vp56dsp_init.c +++ b/libavcodec/x86/vp56dsp_init.c @@ -21,7 +21,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/vp56dsp.h" diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c index 64dd8ceadf..4568a3864c 100644 --- a/libavcodec/x86/vp8dsp-init.c +++ b/libavcodec/x86/vp8dsp-init.c @@ -21,7 +21,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/vp8dsp.h" #if HAVE_YASM diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c index b45256d011..4cd481c05f 100644 --- a/libavfilter/x86/gradfun.c +++ b/libavfilter/x86/gradfun.c @@ -20,7 +20,7 @@ #include "libavutil/attributes.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavfilter/gradfun.h" #if HAVE_INLINE_ASM diff --git a/libavfilter/x86/yadif.c b/libavfilter/x86/yadif.c index 81b536acda..ee3a016bd0 100644 --- a/libavfilter/x86/yadif.c +++ b/libavfilter/x86/yadif.c @@ -20,7 +20,7 @@ #include "libavutil/attributes.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/x86/dsputil_mmx.h" #include "libavfilter/yadif.h" diff --git a/libavutil/x86/asm.h b/libavutil/x86/asm.h new file mode 100644 index 0000000000..b447fabb57 --- /dev/null +++ b/libavutil/x86/asm.h @@ -0,0 +1,98 @@ +/* + * copyright (c) 2006 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 + */ + +#ifndef AVUTIL_X86_ASM_H +#define AVUTIL_X86_ASM_H + +#include +#include "config.h" + +#if ARCH_X86_64 +# define OPSIZE "q" +# define REG_a "rax" +# define REG_b "rbx" +# define REG_c "rcx" +# define REG_d "rdx" +# define REG_D "rdi" +# define REG_S "rsi" +# define PTR_SIZE "8" +typedef int64_t x86_reg; + +# define REG_SP "rsp" +# define REG_BP "rbp" +# define REGBP rbp +# define REGa rax +# define REGb rbx +# define REGc rcx +# define REGd rdx +# define REGSP rsp + +#elif ARCH_X86_32 + +# define OPSIZE "l" +# define REG_a "eax" +# define REG_b "ebx" +# define REG_c "ecx" +# define REG_d "edx" +# define REG_D "edi" +# define REG_S "esi" +# define PTR_SIZE "4" +typedef int32_t x86_reg; + +# define REG_SP "esp" +# define REG_BP "ebp" +# define REGBP ebp +# define REGa eax +# define REGb ebx +# define REGc ecx +# define REGd edx +# define REGSP esp +#else +typedef int x86_reg; +#endif + +#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE)) +#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE)) + +#if ARCH_X86_64 && defined(PIC) +# define BROKEN_RELOCATIONS 1 +#endif + +/* + * If gcc is not set to support sse (-msse) it will not accept xmm registers + * in the clobber list for inline asm. XMM_CLOBBERS takes a list of xmm + * registers to be marked as clobbered and evaluates to nothing if they are + * not supported, or to the list itself if they are supported. Since a clobber + * list may not be empty, XMM_CLOBBERS_ONLY should be used if the xmm + * registers are the only in the clobber list. + * For example a list with "eax" and "xmm0" as clobbers should become: + * : XMM_CLOBBERS("xmm0",) "eax" + * and a list with only "xmm0" should become: + * XMM_CLOBBERS_ONLY("xmm0") + */ +#if HAVE_XMM_CLOBBERS +# define XMM_CLOBBERS(...) __VA_ARGS__ +# define XMM_CLOBBERS_ONLY(...) : __VA_ARGS__ +#else +# define XMM_CLOBBERS(...) +# define XMM_CLOBBERS_ONLY(...) +#endif + +#endif /* AVUTIL_X86_ASM_H */ diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c index a63b564985..645bb83f77 100644 --- a/libavutil/x86/cpu.c +++ b/libavutil/x86/cpu.c @@ -22,7 +22,7 @@ #include #include -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #if HAVE_INLINE_ASM diff --git a/libavutil/x86_cpu.h b/libavutil/x86_cpu.h deleted file mode 100644 index f84eba67f5..0000000000 --- a/libavutil/x86_cpu.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * copyright (c) 2006 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 - */ - -#ifndef AVUTIL_X86_CPU_H -#define AVUTIL_X86_CPU_H - -#include -#include "config.h" - -#if ARCH_X86_64 -# define OPSIZE "q" -# define REG_a "rax" -# define REG_b "rbx" -# define REG_c "rcx" -# define REG_d "rdx" -# define REG_D "rdi" -# define REG_S "rsi" -# define PTR_SIZE "8" -typedef int64_t x86_reg; - -# define REG_SP "rsp" -# define REG_BP "rbp" -# define REGBP rbp -# define REGa rax -# define REGb rbx -# define REGc rcx -# define REGd rdx -# define REGSP rsp - -#elif ARCH_X86_32 - -# define OPSIZE "l" -# define REG_a "eax" -# define REG_b "ebx" -# define REG_c "ecx" -# define REG_d "edx" -# define REG_D "edi" -# define REG_S "esi" -# define PTR_SIZE "4" -typedef int32_t x86_reg; - -# define REG_SP "esp" -# define REG_BP "ebp" -# define REGBP ebp -# define REGa eax -# define REGb ebx -# define REGc ecx -# define REGd edx -# define REGSP esp -#else -typedef int x86_reg; -#endif - -#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE)) -#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE)) - -#if ARCH_X86_64 && defined(PIC) -# define BROKEN_RELOCATIONS 1 -#endif - -/* - * If gcc is not set to support sse (-msse) it will not accept xmm registers - * in the clobber list for inline asm. XMM_CLOBBERS takes a list of xmm - * registers to be marked as clobbered and evaluates to nothing if they are - * not supported, or to the list itself if they are supported. Since a clobber - * list may not be empty, XMM_CLOBBERS_ONLY should be used if the xmm - * registers are the only in the clobber list. - * For example a list with "eax" and "xmm0" as clobbers should become: - * : XMM_CLOBBERS("xmm0",) "eax" - * and a list with only "xmm0" should become: - * XMM_CLOBBERS_ONLY("xmm0") - */ -#if HAVE_XMM_CLOBBERS -# define XMM_CLOBBERS(...) __VA_ARGS__ -# define XMM_CLOBBERS_ONLY(...) : __VA_ARGS__ -#else -# define XMM_CLOBBERS(...) -# define XMM_CLOBBERS_ONLY(...) -#endif - -#endif /* AVUTIL_X86_CPU_H */ diff --git a/libswscale/utils.c b/libswscale/utils.c index 9a57405d2c..f890b5cee1 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -45,7 +45,7 @@ #include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "rgb2rgb.h" #include "swscale.h" #include "swscale_internal.h" diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c index 066749c22f..f201281fac 100644 --- a/libswscale/x86/rgb2rgb.c +++ b/libswscale/x86/rgb2rgb.c @@ -27,7 +27,7 @@ #include "config.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavutil/bswap.h" #include "libswscale/rgb2rgb.h" diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 57d270b09d..9683c0cedd 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -24,7 +24,7 @@ #include "libswscale/swscale_internal.h" #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavutil/pixdesc.h" diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c index 501993ae42..93755493ab 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -34,7 +34,7 @@ #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #if HAVE_INLINE_ASM -- cgit v1.2.3 From d7a4f8f8b9a4bc309d4d5ab067cfba945e690c0c Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 8 Aug 2012 17:13:26 +0100 Subject: Move MASK_ABS macro to libavcodec/mathops.h This macro is only used in two places, both in libavcodec, so this is a more sensible place for it. Two small tweaks to the macro are made: - removing the trailing semicolon - dropping unnecessary 'volatile' from the x86 asm Signed-off-by: Mans Rullgard --- libavcodec/mathops.h | 7 +++++++ libavcodec/mpeg12enc.c | 2 +- libavcodec/x86/mathops.h | 6 ++++++ libavutil/internal.h | 16 ---------------- 4 files changed, 14 insertions(+), 17 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h index d6eb98ddac..ab545ef504 100644 --- a/libavcodec/mathops.h +++ b/libavcodec/mathops.h @@ -138,6 +138,13 @@ if ((y) < (x)) {\ } #endif +#ifndef MASK_ABS +#define MASK_ABS(mask, level) do { \ + mask = level >> 31; \ + level = (level ^ mask) - mask; \ + } while (0) +#endif + #ifndef NEG_SSR32 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) #endif diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index cb3e9d5a70..a96a23dd6b 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -885,7 +885,7 @@ static void mpeg1_encode_block(MpegEncContext *s, run = i - last_non_zero - 1; alevel= level; - MASK_ABS(sign, alevel) + MASK_ABS(sign, alevel); sign&=1; if (alevel <= mpeg1_max_level[0][run]){ diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h index e056eb0a2d..cd408ac5a6 100644 --- a/libavcodec/x86/mathops.h +++ b/libavcodec/x86/mathops.h @@ -101,6 +101,12 @@ __asm__ volatile(\ ); #endif +#define MASK_ABS(mask, level) \ + __asm__ ("cltd \n\t" \ + "xorl %1, %0 \n\t" \ + "subl %1, %0 \n\t" \ + : "+a"(level), "=&d"(mask)) + // avoid +32 for shift optimization (gcc should do that ...) #define NEG_SSR32 NEG_SSR32 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ diff --git a/libavutil/internal.h b/libavutil/internal.h index 0a7ed83c4f..4c1d2f6648 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -96,22 +96,6 @@ struct AVDictionary { #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) -/* math */ - -#if ARCH_X86 && HAVE_INLINE_ASM -#define MASK_ABS(mask, level)\ - __asm__ volatile(\ - "cltd \n\t"\ - "xorl %1, %0 \n\t"\ - "subl %1, %0 \n\t"\ - : "+a" (level), "=&d" (mask)\ - ); -#else -#define MASK_ABS(mask, level)\ - mask = level >> 31;\ - level = (level ^ mask) - mask; -#endif - /* avoid usage of dangerous/inappropriate system functions */ #undef malloc #define malloc please_use_av_malloc -- cgit v1.2.3 From 18bbca1fd31360b6d21710db70d321fa0333e7a5 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 00:05:46 +0100 Subject: build: factor out mpegvideo.o dependencies to CONFIG_MPEGVIDEO This adds a hidden config variable for the mpegvideo.o dependency and selects from the codecs which require it. Signed-off-by: Mans Rullgard --- configure | 46 ++++++++++++++++++++++--------------- libavcodec/Makefile | 65 ++++++++++++++++++++++++----------------------------- 2 files changed, 57 insertions(+), 54 deletions(-) (limited to 'libavcodec') diff --git a/configure b/configure index 9bdeebde45..241663c07d 100755 --- a/configure +++ b/configure @@ -1226,6 +1226,7 @@ CONFIG_EXTRA=" lgplv3 lpc mpegaudiodsp + mpegvideo nettle rtpdec sinewin @@ -1349,17 +1350,17 @@ atrac1_decoder_select="mdct sinewin" atrac3_decoder_select="mdct" binkaudio_dct_decoder_select="mdct rdft dct sinewin" binkaudio_rdft_decoder_select="mdct rdft sinewin" -cavs_decoder_select="golomb" +cavs_decoder_select="golomb mpegvideo" cook_decoder_select="mdct sinewin" cscd_decoder_suggest="zlib" dca_decoder_select="mdct" -dnxhd_encoder_select="aandcttables" +dnxhd_encoder_select="aandcttables mpegvideo" dxa_decoder_select="zlib" eac3_decoder_select="ac3_decoder" eac3_encoder_select="mdct ac3dsp" eamad_decoder_select="aandcttables" eatgq_decoder_select="aandcttables" -eatqi_decoder_select="aandcttables" +eatqi_decoder_select="aandcttables mpegvideo" ffv1_decoder_select="golomb" flac_decoder_select="golomb" flac_encoder_select="golomb lpc" @@ -1369,13 +1370,14 @@ flashsv2_decoder_select="zlib" flv_decoder_select="h263_decoder" flv_encoder_select="h263_encoder" fraps_decoder_select="huffman" -h261_encoder_select="aandcttables" -h263_decoder_select="h263_parser" -h263_encoder_select="aandcttables" +h261_decoder_select="mpegvideo" +h261_encoder_select="aandcttables mpegvideo" +h263_decoder_select="h263_parser mpegvideo" +h263_encoder_select="aandcttables mpegvideo" h263_vaapi_hwaccel_select="vaapi h263_decoder" h263i_decoder_select="h263_decoder" h263p_encoder_select="h263_encoder" -h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel" +h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel mpegvideo" h264_dxva2_hwaccel_deps="dxva2api_h" h264_dxva2_hwaccel_select="dxva2 h264_decoder" h264_vaapi_hwaccel_select="vaapi h264_decoder" @@ -1385,9 +1387,10 @@ iac_decoder_select="fft mdct sinewin" imc_decoder_select="fft mdct sinewin" jpegls_decoder_select="golomb" jpegls_encoder_select="golomb" -ljpeg_encoder_select="aandcttables" +ljpeg_encoder_select="aandcttables mpegvideo" loco_decoder_select="golomb" -mjpeg_encoder_select="aandcttables" +mdec_decoder_select="mpegvideo" +mjpeg_encoder_select="aandcttables mpegvideo" mlp_decoder_select="mlp_parser" mp1_decoder_select="mpegaudiodsp" mp1float_decoder_select="mpegaudiodsp" @@ -1405,11 +1408,13 @@ mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder" mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" mpeg_xvmc_decoder_select="mpegvideo_decoder" mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder" -mpeg1video_encoder_select="aandcttables" +mpeg1video_decoder_select="mpegvideo" +mpeg1video_encoder_select="aandcttables mpegvideo" mpeg2_dxva2_hwaccel_deps="dxva2api_h" mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder" mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder" -mpeg2video_encoder_select="aandcttables" +mpeg2video_encoder_select="mpegvideo" +mpeg2video_encoder_select="aandcttables mpegvideo" mpeg4_decoder_select="h263_decoder mpeg4video_parser" mpeg4_encoder_select="h263_encoder" mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" @@ -1432,14 +1437,15 @@ rv10_decoder_select="h263_decoder" rv10_encoder_select="h263_encoder" rv20_decoder_select="h263_decoder" rv20_encoder_select="h263_encoder" -rv30_decoder_select="golomb h264chroma h264pred h264qpel" -rv40_decoder_select="golomb h264chroma h264pred h264qpel" +rv30_decoder_select="golomb h264chroma h264pred h264qpel mpegvideo" +rv40_decoder_select="golomb h264chroma h264pred h264qpel mpegvideo" shorten_decoder_select="golomb" sipr_decoder_select="lsp" snow_decoder_select="dwt" -snow_encoder_select="aandcttables dwt" -svq1_encoder_select="aandcttables" -svq3_decoder_select="golomb h264chroma h264dsp h264pred h264qpel" +snow_encoder_select="aandcttables dwt mpegvideo" +svq1_encoder_select="mpegvideo" +svq1_encoder_select="aandcttables mpegvideo" +svq3_decoder_select="golomb h264chroma h264dsp h264pred h264qpel mpegvideo" svq3_decoder_suggest="zlib" theora_decoder_select="vp3_decoder" tiff_decoder_suggest="zlib" @@ -1487,7 +1493,10 @@ vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" # parsers -h264_parser_select="golomb h264dsp h264pred" +h264_parser_select="golomb h264dsp h264pred mpegvideo" +mpeg4video_parser_select="mpegvideo" +mpegvideo_parser_select="mpegvideo" +vc1_parser_select="mpegvideo" # external libraries libfaac_encoder_deps="libfaac" @@ -1531,12 +1540,13 @@ matroska_demuxer_suggest="zlib bzlib" mov_demuxer_suggest="zlib" mp3_demuxer_select="mpegaudio_parser" mp4_muxer_select="mov_muxer" -mpegts_muxer_select="adts_muxer latm_muxer" +mpegts_muxer_select="adts_muxer latm_muxer mpegvideo" mpegtsraw_demuxer_select="mpegts_demuxer" mxf_d10_muxer_select="mxf_muxer" ogg_demuxer_select="golomb" psp_muxer_select="mov_muxer" rtp_demuxer_select="sdp_demuxer" +rtp_muxer_select="mpegvideo" rtpdec_select="asf_demuxer rm_demuxer rtp_protocol mpegts_demuxer mov_demuxer" rtsp_demuxer_select="http_protocol rtpdec" rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9bff68f83e..6dde8a64f4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -50,6 +50,7 @@ OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ mpegaudiodsp_fixed.o \ mpegaudiodsp_float.o +OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) OBJS-$(CONFIG_SINEWIN) += sinewin.o @@ -111,7 +112,7 @@ OBJS-$(CONFIG_BMV_VIDEO_DECODER) += bmv.o OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmv.o OBJS-$(CONFIG_C93_DECODER) += c93.o OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ - mpeg12data.o mpegvideo.o + mpeg12data.o OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o @@ -127,8 +128,7 @@ OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinav.o @@ -146,13 +146,11 @@ OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \ ac3tab.o ac3.o kbdwin.o eac3_data.o OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \ - mpeg12data.o mpegvideo.o \ - error_resilience.o + mpeg12data.o error_resilience.o OBJS-$(CONFIG_EATGQ_DECODER) += eatgq.o eaidct.o OBJS-$(CONFIG_EATGV_DECODER) += eatgv.o OBJS-$(CONFIG_EATQI_DECODER) += eatqi.o eaidct.o mpeg12.o \ - mpeg12data.o mpegvideo.o \ - error_resilience.o + mpeg12data.o error_resilience.o OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER) += 8svx.o OBJS-$(CONFIG_EIGHTSVX_FIB_DECODER) += 8svx.o @@ -176,27 +174,24 @@ OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o -OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o \ - mpegvideo.o error_resilience.o +OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o error_resilience.o OBJS-$(CONFIG_H261_ENCODER) += h261enc.o h261.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_H263_DECODER) += h263dec.o h263.o ituh263dec.o \ mpeg4video.o mpeg4videodec.o flvdec.o\ - intelh263dec.o mpegvideo.o \ - error_resilience.o + intelh263dec.o error_resilience.o OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_H263_ENCODER) += mpegvideo_enc.o mpeg4video.o \ mpeg4videoenc.o motion_est.o \ ratecontrol.o h263.o ituh263enc.o \ flvenc.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_H264_DECODER) += h264.o \ h264_loopfilter.o h264_direct.o \ cabac.o h264_sei.o h264_ps.o \ h264_refs.o h264_cavlc.o h264_cabac.o\ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o @@ -222,19 +217,17 @@ OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o OBJS-$(CONFIG_LAGARITH_DECODER) += lagarith.o lagarithrac.o OBJS-$(CONFIG_LJPEG_ENCODER) += ljpegenc.o mjpegenc.o mjpeg.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_LOCO_DECODER) += loco.o OBJS-$(CONFIG_MACE3_DECODER) += mace.o OBJS-$(CONFIG_MACE6_DECODER) += mace.o OBJS-$(CONFIG_MDEC_DECODER) += mdec.o mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MIMIC_DECODER) += mimic.o OBJS-$(CONFIG_MJPEG_DECODER) += mjpegdec.o mjpeg.o OBJS-$(CONFIG_MJPEG_ENCODER) += mjpegenc.o mjpeg.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_MJPEGB_DECODER) += mjpegbdec.o mjpegdec.o mjpeg.o OBJS-$(CONFIG_MLP_DECODER) += mlpdec.o mlpdsp.o OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o @@ -271,19 +264,19 @@ OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o mpegaudiodec.o \ mpegaudiodata.o OBJS-$(CONFIG_MPEG_XVMC_DECODER) += mpegvideo_xvmc.o OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ motion_est.o ratecontrol.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ motion_est.o ratecontrol.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \ @@ -356,9 +349,9 @@ OBJS-$(CONFIG_RV10_ENCODER) += rv10enc.o OBJS-$(CONFIG_RV20_DECODER) += rv10.o OBJS-$(CONFIG_RV20_ENCODER) += rv20enc.o OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o rv34dsp.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv34dsp.o rv40dsp.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_S302M_DECODER) += s302m.o OBJS-$(CONFIG_SGI_DECODER) += sgidec.o OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o @@ -373,7 +366,7 @@ OBJS-$(CONFIG_SMC_DECODER) += smc.o OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o rangecoder.o OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.o rangecoder.o \ motion_est.o ratecontrol.o \ - h263.o mpegvideo.o \ + h263.o \ error_resilience.o ituh263enc.o \ mpegvideo_enc.o mpeg12data.o OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o @@ -382,17 +375,17 @@ OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_SVQ1_ENCODER) += svq1enc.o svq1.o \ motion_est.o h263.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ ituh263enc.o mpegvideo_enc.o \ ratecontrol.o mpeg12data.o OBJS-$(CONFIG_SVQ3_DECODER) += h264.o svq3.o \ h264_loopfilter.o h264_direct.o \ h264_sei.o h264_ps.o h264_refs.o \ h264_cavlc.o h264_cabac.o cabac.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ svq1dec.o svq1.o h263.o OBJS-$(CONFIG_TARGA_DECODER) += targa.o OBJS-$(CONFIG_TARGA_ENCODER) += targaenc.o rle.o @@ -589,14 +582,14 @@ OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MP3_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o ac3tab.o OBJS-$(CONFIG_MOV_MUXER) += mpeg4audio.o mpegaudiodata.o -OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o mpeg4audio.o +OBJS-$(CONFIG_MPEGTS_MUXER) += mpeg4audio.o OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \ mpeg12data.o vorbis_parser.o \ dirac.o OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o -OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o mpegvideo.o xiph.o +OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o xiph.o OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o OBJS-$(CONFIG_SPDIF_MUXER) += dca.o OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o mpegaudiodata.o \ @@ -658,25 +651,25 @@ OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264.o \ h264_refs.o h264_sei.o h264_direct.o \ h264_loopfilter.o h264_cabac.o \ h264_cavlc.o h264_ps.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_AAC_LATM_PARSER) += latm_parser.o OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o OBJS-$(CONFIG_MLP_PARSER) += mlp_parser.o mlp.o OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ mpeg4videodec.o mpeg4video.o \ ituh263dec.o h263dec.o OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o \ mpegaudiodecheader.o mpegaudiodata.o OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \ msmpeg4.o msmpeg4data.o mpeg4video.o \ - h263.o mpegvideo.o error_resilience.o + h263.o error_resilience.o OBJS-$(CONFIG_VORBIS_PARSER) += vorbis_parser.o xiph.o OBJS-$(CONFIG_VP3_PARSER) += vp3_parser.o OBJS-$(CONFIG_VP8_PARSER) += vp8_parser.o -- cgit v1.2.3 From 7a851153d3fe1a9e0d60bf11053870d1ea8241e6 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 00:50:21 +0100 Subject: mpegvideo: convert mpegvideo_common.h to a .c file This file defines a single, huge function, MPV_motion(), which although being declared inline is not actually inlined by the compiler (for good reason). There is thus no sense in defining this function in a header file, resulting in multiple copies of it in the final library. Signed-off-by: Mans Rullgard --- libavcodec/Makefile | 2 +- libavcodec/dnxhdenc.c | 1 - libavcodec/mpegvideo.c | 5 +- libavcodec/mpegvideo.h | 15 + libavcodec/mpegvideo_common.h | 893 ------------------------------------------ libavcodec/mpegvideo_enc.c | 11 +- libavcodec/mpegvideo_motion.c | 875 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 899 insertions(+), 903 deletions(-) delete mode 100644 libavcodec/mpegvideo_common.h create mode 100644 libavcodec/mpegvideo_motion.c (limited to 'libavcodec') diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 6dde8a64f4..655e828cbc 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -50,7 +50,7 @@ OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ mpegaudiodsp_fixed.o \ mpegaudiodsp_float.o -OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o +OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_motion.o RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) OBJS-$(CONFIG_SINEWIN) += sinewin.o diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index aca54974f7..523d1c078f 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -31,7 +31,6 @@ #include "dsputil.h" #include "internal.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "dnxhdenc.h" #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 4fb5949131..8f3544fa1a 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -33,7 +33,6 @@ #include "dsputil.h" #include "internal.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "mjpegenc.h" #include "msmpeg4.h" #include "xvmc_internal.h" @@ -2035,12 +2034,12 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], op_pix = s->dsp.put_no_rnd_pixels_tab; } if (s->mv_dir & MV_DIR_FORWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); op_pix = s->dsp.avg_pixels_tab; op_qpix= s->me.qpel_avg; } if (s->mv_dir & MV_DIR_BACKWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); } } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 5c537da38f..80fa0fa1bd 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -739,6 +739,13 @@ static const AVClass name ## _class = {\ .version = LIBAVUTIL_VERSION_INT,\ }; +/** + * Set the given MpegEncContext to common defaults (same for encoding + * and decoding). The changed fields will not depend upon the prior + * state of the MpegEncContext. + */ +void ff_MPV_common_defaults(MpegEncContext *s); + void ff_MPV_decode_defaults(MpegEncContext *s); int ff_MPV_common_init(MpegEncContext *s); void ff_MPV_common_end(MpegEncContext *s); @@ -777,10 +784,18 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en int ff_dct_common_init(MpegEncContext *s); void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra); +int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); void ff_init_block_index(MpegEncContext *s); void ff_copy_picture(Picture *dst, Picture *src); +void ff_MPV_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, + uint8_t *dest_cr, int dir, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16]); + /** * Allocate a Picture. * The pixels are allocated/set by calling get_buffer() if shared = 0. diff --git a/libavcodec/mpegvideo_common.h b/libavcodec/mpegvideo_common.h deleted file mode 100644 index 224ec9887a..0000000000 --- a/libavcodec/mpegvideo_common.h +++ /dev/null @@ -1,893 +0,0 @@ -/* - * The simplest mpeg encoder (well, it was the simplest!) - * Copyright (c) 2000,2001 Fabrice Bellard - * Copyright (c) 2002-2004 Michael Niedermayer - * - * 4MV & hq & B-frame encoding stuff by 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 - */ - -/** - * @file - * The simplest mpeg encoder (well, it was the simplest!). - */ - -#ifndef AVCODEC_MPEGVIDEO_COMMON_H -#define AVCODEC_MPEGVIDEO_COMMON_H - -#include -#include "avcodec.h" -#include "dsputil.h" -#include "mpegvideo.h" -#include "mjpegenc.h" -#include "msmpeg4.h" -#include - -int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); - -/** - * Set the given MpegEncContext to common defaults (same for encoding and decoding). - * The changed fields will not depend upon the prior state of the MpegEncContext. - */ -void ff_MPV_common_defaults(MpegEncContext *s); - -static inline void gmc1_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture) -{ - uint8_t *ptr; - int offset, src_x, src_y, linesize, uvlinesize; - int motion_x, motion_y; - int emu=0; - - motion_x= s->sprite_offset[0][0]; - motion_y= s->sprite_offset[0][1]; - src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); - src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); - motion_x<<=(3-s->sprite_warping_accuracy); - motion_y<<=(3-s->sprite_warping_accuracy); - src_x = av_clip(src_x, -16, s->width); - if (src_x == s->width) - motion_x =0; - src_y = av_clip(src_y, -16, s->height); - if (src_y == s->height) - motion_y =0; - - linesize = s->linesize; - uvlinesize = s->uvlinesize; - - ptr = ref_picture[0] + (src_y * linesize) + src_x; - - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) - || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); - ptr= s->edge_emu_buffer; - } - } - - if((motion_x|motion_y)&7){ - s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); - s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); - }else{ - int dxy; - - dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); - if (s->no_rounding){ - s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); - }else{ - s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); - } - } - - if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return; - - motion_x= s->sprite_offset[1][0]; - motion_y= s->sprite_offset[1][1]; - src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); - src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); - motion_x<<=(3-s->sprite_warping_accuracy); - motion_y<<=(3-s->sprite_warping_accuracy); - src_x = av_clip(src_x, -8, s->width>>1); - if (src_x == s->width>>1) - motion_x =0; - src_y = av_clip(src_y, -8, s->height>>1); - if (src_y == s->height>>1) - motion_y =0; - - offset = (src_y * uvlinesize) + src_x; - ptr = ref_picture[1] + offset; - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0) - || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - emu=1; - } - } - s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); - - ptr = ref_picture[2] + offset; - if(emu){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - } - s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); - - return; -} - -static inline void gmc_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture) -{ - uint8_t *ptr; - int linesize, uvlinesize; - const int a= s->sprite_warping_accuracy; - int ox, oy; - - linesize = s->linesize; - uvlinesize = s->uvlinesize; - - ptr = ref_picture[0]; - - ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; - oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; - - s->dsp.gmc(dest_y, ptr, linesize, 16, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos, s->v_edge_pos); - s->dsp.gmc(dest_y+8, ptr, linesize, 16, - ox + s->sprite_delta[0][0]*8, - oy + s->sprite_delta[1][0]*8, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos, s->v_edge_pos); - - if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return; - - ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; - oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; - - ptr = ref_picture[1]; - s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos>>1, s->v_edge_pos>>1); - - ptr = ref_picture[2]; - s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos>>1, s->v_edge_pos>>1); -} - -static inline int hpel_motion(MpegEncContext *s, - uint8_t *dest, uint8_t *src, - int field_based, int field_select, - int src_x, int src_y, - int width, int height, int stride, - int h_edge_pos, int v_edge_pos, - int w, int h, op_pixels_func *pix_op, - int motion_x, int motion_y) -{ - int dxy; - int emu=0; - - dxy = ((motion_y & 1) << 1) | (motion_x & 1); - src_x += motion_x >> 1; - src_y += motion_y >> 1; - - /* WARNING: do no forget half pels */ - src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu? - if (src_x == width) - dxy &= ~1; - src_y = av_clip(src_y, -16, height); - if (src_y == height) - dxy &= ~2; - src += src_y * stride + src_x; - - if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ - if( (unsigned)src_x > FFMAX(h_edge_pos - (motion_x&1) - w, 0) - || (unsigned)src_y > FFMAX(v_edge_pos - (motion_y&1) - h, 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<v_edge_pos); - src= s->edge_emu_buffer; - emu=1; - } - } - if(field_select) - src += s->linesize; - pix_op[dxy](dest, src, stride, h); - return emu; -} - -static av_always_inline -void mpeg_motion_internal(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h, int is_mpeg12, int mb_y) -{ - uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int dxy, uvdxy, mx, my, src_x, src_y, - uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; - -#if 0 -if(s->quarter_sample) -{ - motion_x>>=1; - motion_y>>=1; -} -#endif - - v_edge_pos = s->v_edge_pos >> field_based; - linesize = s->current_picture.f.linesize[0] << field_based; - uvlinesize = s->current_picture.f.linesize[1] << field_based; - - dxy = ((motion_y & 1) << 1) | (motion_x & 1); - src_x = s->mb_x* 16 + (motion_x >> 1); - src_y =( mb_y<<(4-field_based)) + (motion_y >> 1); - - if (!is_mpeg12 && s->out_format == FMT_H263) { - if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ - mx = (motion_x>>1)|(motion_x&1); - my = motion_y >>1; - uvdxy = ((my & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); - }else{ - uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); - uvsrc_x = src_x>>1; - uvsrc_y = src_y>>1; - } - }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261 - mx = motion_x / 4; - my = motion_y / 4; - uvdxy = 0; - uvsrc_x = s->mb_x*8 + mx; - uvsrc_y = mb_y*8 + my; - } else { - if(s->chroma_y_shift){ - mx = motion_x / 2; - my = motion_y / 2; - uvdxy = ((my & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); - } else { - if(s->chroma_x_shift){ - //Chroma422 - mx = motion_x / 2; - uvdxy = ((motion_y & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = src_y; - } else { - //Chroma444 - uvdxy = dxy; - uvsrc_x = src_x; - uvsrc_y = src_y; - } - } - } - - ptr_y = ref_picture[0] + src_y * linesize + src_x; - ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; - ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; - - if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 16, 0) - || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&1) - h , 0)){ - if(is_mpeg12 || s->codec_id == AV_CODEC_ID_MPEG2VIDEO || - s->codec_id == AV_CODEC_ID_MPEG1VIDEO){ - av_log(s->avctx,AV_LOG_DEBUG, - "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y); - return; - } - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, - 17, 17+field_based, - src_x, src_y<h_edge_pos, s->v_edge_pos); - ptr_y = s->edge_emu_buffer; - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; - s->dsp.emulated_edge_mc(uvbuf , - ptr_cb, s->uvlinesize, - 9, 9+field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - s->dsp.emulated_edge_mc(uvbuf+16, - ptr_cr, s->uvlinesize, - 9, 9+field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ptr_cb= uvbuf; - ptr_cr= uvbuf+16; - } - } - - if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data - dest_y += s->linesize; - dest_cb+= s->uvlinesize; - dest_cr+= s->uvlinesize; - } - - if(field_select){ - ptr_y += s->linesize; - ptr_cb+= s->uvlinesize; - ptr_cr+= s->uvlinesize; - } - - pix_op[0][dxy](dest_y, ptr_y, linesize, h); - - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - pix_op[s->chroma_x_shift][uvdxy] - (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); - pix_op[s->chroma_x_shift][uvdxy] - (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); - } - if(!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) && - s->out_format == FMT_H261){ - ff_h261_loop_filter(s); - } -} -/* apply one mpeg motion vector to the three components */ -static av_always_inline -void mpeg_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h, int mb_y) -{ -#if !CONFIG_SMALL - if(s->out_format == FMT_MPEG1) - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, - bottom_field, field_select, ref_picture, pix_op, - motion_x, motion_y, h, 1, mb_y); - else -#endif - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, - bottom_field, field_select, ref_picture, pix_op, - motion_x, motion_y, h, 0, mb_y); -} - -//FIXME move to dsputil, avg variant, 16x16 version -static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ - int x; - uint8_t * const top = src[1]; - uint8_t * const left = src[2]; - uint8_t * const mid = src[0]; - uint8_t * const right = src[3]; - uint8_t * const bottom= src[4]; -#define OBMC_FILTER(x, t, l, m, r, b)\ - dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 -#define OBMC_FILTER4(x, t, l, m, r, b)\ - OBMC_FILTER(x , t, l, m, r, b);\ - OBMC_FILTER(x+1 , t, l, m, r, b);\ - OBMC_FILTER(x +stride, t, l, m, r, b);\ - OBMC_FILTER(x+1+stride, t, l, m, r, b); - - x=0; - OBMC_FILTER (x , 2, 2, 4, 0, 0); - OBMC_FILTER (x+1, 2, 1, 5, 0, 0); - OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); - OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); - OBMC_FILTER (x+6, 2, 0, 5, 1, 0); - OBMC_FILTER (x+7, 2, 0, 4, 2, 0); - x+= stride; - OBMC_FILTER (x , 1, 2, 5, 0, 0); - OBMC_FILTER (x+1, 1, 2, 5, 0, 0); - OBMC_FILTER (x+6, 1, 0, 5, 2, 0); - OBMC_FILTER (x+7, 1, 0, 5, 2, 0); - x+= stride; - OBMC_FILTER4(x , 1, 2, 5, 0, 0); - OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); - OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); - OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); - x+= 2*stride; - OBMC_FILTER4(x , 0, 2, 5, 0, 1); - OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); - OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); - OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); - x+= 2*stride; - OBMC_FILTER (x , 0, 2, 5, 0, 1); - OBMC_FILTER (x+1, 0, 2, 5, 0, 1); - OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); - OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); - OBMC_FILTER (x+6, 0, 0, 5, 2, 1); - OBMC_FILTER (x+7, 0, 0, 5, 2, 1); - x+= stride; - OBMC_FILTER (x , 0, 2, 4, 0, 2); - OBMC_FILTER (x+1, 0, 1, 5, 0, 2); - OBMC_FILTER (x+6, 0, 0, 5, 1, 2); - OBMC_FILTER (x+7, 0, 0, 4, 2, 2); -} - -/* obmc for 1 8x8 luma block */ -static inline void obmc_motion(MpegEncContext *s, - uint8_t *dest, uint8_t *src, - int src_x, int src_y, - op_pixels_func *pix_op, - int16_t mv[5][2]/* mid top left right bottom*/) -#define MID 0 -{ - int i; - uint8_t *ptr[5]; - - assert(s->quarter_sample==0); - - for(i=0; i<5; i++){ - if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ - ptr[i]= ptr[MID]; - }else{ - ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); - hpel_motion(s, ptr[i], src, 0, 0, - src_x, src_y, - s->width, s->height, s->linesize, - s->h_edge_pos, s->v_edge_pos, - 8, 8, pix_op, - mv[i][0], mv[i][1]); - } - } - - put_obmc(dest, ptr, s->linesize); -} - -static inline void qpel_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - qpel_mc_func (*qpix_op)[16], - int motion_x, int motion_y, int h) -{ - uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; - - dxy = ((motion_y & 3) << 2) | (motion_x & 3); - src_x = s->mb_x * 16 + (motion_x >> 2); - src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); - - v_edge_pos = s->v_edge_pos >> field_based; - linesize = s->linesize << field_based; - uvlinesize = s->uvlinesize << field_based; - - if(field_based){ - mx= motion_x/2; - my= motion_y>>1; - }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ - static const int rtab[8]= {0,0,1,1,0,0,0,1}; - mx= (motion_x>>1) + rtab[motion_x&7]; - my= (motion_y>>1) + rtab[motion_y&7]; - }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ - mx= (motion_x>>1)|(motion_x&1); - my= (motion_y>>1)|(motion_y&1); - }else{ - mx= motion_x/2; - my= motion_y/2; - } - mx= (mx>>1)|(mx&1); - my= (my>>1)|(my&1); - - uvdxy= (mx&1) | ((my&1)<<1); - mx>>=1; - my>>=1; - - uvsrc_x = s->mb_x * 8 + mx; - uvsrc_y = s->mb_y * (8 >> field_based) + my; - - ptr_y = ref_picture[0] + src_y * linesize + src_x; - ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; - ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; - - if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0) - || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, - 17, 17+field_based, src_x, src_y<h_edge_pos, s->v_edge_pos); - ptr_y= s->edge_emu_buffer; - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; - s->dsp.emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, - 9, 9 + field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - s->dsp.emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, - 9, 9 + field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ptr_cb= uvbuf; - ptr_cr= uvbuf + 16; - } - } - - if(!field_based) - qpix_op[0][dxy](dest_y, ptr_y, linesize); - else{ - if(bottom_field){ - dest_y += s->linesize; - dest_cb+= s->uvlinesize; - dest_cr+= s->uvlinesize; - } - - if(field_select){ - ptr_y += s->linesize; - ptr_cb += s->uvlinesize; - ptr_cr += s->uvlinesize; - } - //damn interlaced mode - //FIXME boundary mirroring is not exactly correct here - qpix_op[1][dxy](dest_y , ptr_y , linesize); - qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); - } - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); - pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); - } -} - -/** - * h263 chroma 4mv motion compensation. - */ -static inline void chroma_4mv_motion(MpegEncContext *s, - uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture, - op_pixels_func *pix_op, - int mx, int my){ - int dxy, emu=0, src_x, src_y, offset; - uint8_t *ptr; - - /* In case of 8X8, we construct a single chroma motion vector - with a special rounding */ - mx= ff_h263_round_chroma(mx); - my= ff_h263_round_chroma(my); - - dxy = ((my & 1) << 1) | (mx & 1); - mx >>= 1; - my >>= 1; - - src_x = s->mb_x * 8 + mx; - src_y = s->mb_y * 8 + my; - src_x = av_clip(src_x, -8, (s->width >> 1)); - if (src_x == (s->width >> 1)) - dxy &= ~1; - src_y = av_clip(src_y, -8, (s->height >> 1)); - if (src_y == (s->height >> 1)) - dxy &= ~2; - - offset = src_y * s->uvlinesize + src_x; - ptr = ref_picture[1] + offset; - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0) - || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, - 9, 9, src_x, src_y, - s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - emu=1; - } - } - pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); - - ptr = ref_picture[2] + offset; - if(emu){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, - 9, 9, src_x, src_y, - s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - } - pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); -} - -static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ - /* fetch pixels for estimated mv 4 macroblocks ahead - * optimized for 64byte cache lines */ - const int shift = s->quarter_sample ? 2 : 1; - const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8; - const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y; - int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64; - s->dsp.prefetch(pix[0]+off, s->linesize, 4); - off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; - s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2); -} - -/** - * motion compensation of a single macroblock - * @param s context - * @param dest_y luma destination pointer - * @param dest_cb chroma cb/u destination pointer - * @param dest_cr chroma cr/v destination pointer - * @param dir direction (0->forward, 1->backward) - * @param ref_picture array[3] of pointers to the 3 planes of the reference picture - * @param pix_op halfpel motion compensation function (average or put normally) - * @param qpix_op qpel motion compensation function (average or put normally) - * the motion vectors are taken from s->mv and the MV type from s->mv_type - */ -static av_always_inline void MPV_motion_internal(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, - uint8_t *dest_cr, int dir, - uint8_t **ref_picture, - op_pixels_func (*pix_op)[4], - qpel_mc_func (*qpix_op)[16], int is_mpeg12) -{ - int dxy, mx, my, src_x, src_y, motion_x, motion_y; - int mb_x, mb_y, i; - uint8_t *ptr, *dest; - - mb_x = s->mb_x; - mb_y = s->mb_y; - - prefetch_motion(s, ref_picture, dir); - - if(!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B){ - int16_t mv_cache[4][4][2]; - const int xy= s->mb_x + s->mb_y*s->mb_stride; - const int mot_stride= s->b8_stride; - const int mot_xy= mb_x*2 + mb_y*2*mot_stride; - - assert(!s->mb_skipped); - - memcpy(mv_cache[1][1], s->current_picture.f.motion_val[0][mot_xy ], sizeof(int16_t) * 4); - memcpy(mv_cache[2][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); - memcpy(mv_cache[3][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); - - if (mb_y == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - s->mb_stride])) { - memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); - }else{ - memcpy(mv_cache[0][1], s->current_picture.f.motion_val[0][mot_xy - mot_stride], sizeof(int16_t) * 4); - } - - if (mb_x == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - 1])) { - AV_COPY32(mv_cache[1][0], mv_cache[1][1]); - AV_COPY32(mv_cache[2][0], mv_cache[2][1]); - }else{ - AV_COPY32(mv_cache[1][0], s->current_picture.f.motion_val[0][mot_xy - 1]); - AV_COPY32(mv_cache[2][0], s->current_picture.f.motion_val[0][mot_xy - 1 + mot_stride]); - } - - if (mb_x + 1 >= s->mb_width || IS_INTRA(s->current_picture.f.mb_type[xy + 1])) { - AV_COPY32(mv_cache[1][3], mv_cache[1][2]); - AV_COPY32(mv_cache[2][3], mv_cache[2][2]); - }else{ - AV_COPY32(mv_cache[1][3], s->current_picture.f.motion_val[0][mot_xy + 2]); - AV_COPY32(mv_cache[2][3], s->current_picture.f.motion_val[0][mot_xy + 2 + mot_stride]); - } - - mx = 0; - my = 0; - for(i=0;i<4;i++) { - const int x= (i&1)+1; - const int y= (i>>1)+1; - int16_t mv[5][2]= { - {mv_cache[y][x ][0], mv_cache[y][x ][1]}, - {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, - {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, - {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, - {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; - //FIXME cleanup - obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, - ref_picture[0], - mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, - pix_op[1], - mv); - - mx += mv[0][0]; - my += mv[0][1]; - } - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) - chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); - - return; - } - - switch(s->mv_type) { - case MV_TYPE_16X16: - if(s->mcsel){ - if(s->real_sprite_warping_points==1){ - gmc1_motion(s, dest_y, dest_cb, dest_cr, - ref_picture); - }else{ - gmc_motion(s, dest_y, dest_cb, dest_cr, - ref_picture); - } - }else if(!is_mpeg12 && s->quarter_sample){ - qpel_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, - ref_picture, pix_op, qpix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); - } else if (!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && - s->mspel && s->codec_id == AV_CODEC_ID_WMV2) { - ff_mspel_motion(s, dest_y, dest_cb, dest_cr, - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); - }else - { - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y); - } - break; - case MV_TYPE_8X8: - if (!is_mpeg12) { - mx = 0; - my = 0; - if(s->quarter_sample){ - for(i=0;i<4;i++) { - motion_x = s->mv[dir][i][0]; - motion_y = s->mv[dir][i][1]; - - dxy = ((motion_y & 3) << 2) | (motion_x & 3); - src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; - src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; - - /* WARNING: do no forget half pels */ - src_x = av_clip(src_x, -16, s->width); - if (src_x == s->width) - dxy &= ~3; - src_y = av_clip(src_y, -16, s->height); - if (src_y == s->height) - dxy &= ~12; - - ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0) - || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){ - s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, - s->linesize, 9, 9, - src_x, src_y, - s->h_edge_pos, s->v_edge_pos); - ptr= s->edge_emu_buffer; - } - } - dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; - qpix_op[1][dxy](dest, ptr, s->linesize); - - mx += s->mv[dir][i][0]/2; - my += s->mv[dir][i][1]/2; - } - }else{ - for(i=0;i<4;i++) { - hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, - ref_picture[0], 0, 0, - mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, - s->width, s->height, s->linesize, - s->h_edge_pos, s->v_edge_pos, - 8, 8, pix_op[1], - s->mv[dir][i][0], s->mv[dir][i][1]); - - mx += s->mv[dir][i][0]; - my += s->mv[dir][i][1]; - } - } - - if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) - chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); - } - break; - case MV_TYPE_FIELD: - if (s->picture_structure == PICT_FRAME) { - if(!is_mpeg12 && s->quarter_sample){ - for(i=0; i<2; i++){ - qpel_motion(s, dest_y, dest_cb, dest_cr, - 1, i, s->field_select[dir][i], - ref_picture, pix_op, qpix_op, - s->mv[dir][i][0], s->mv[dir][i][1], 8); - } - }else{ - /* top field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); - /* bottom field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 1, s->field_select[dir][1], - ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); - } - } else { - if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ - ref_picture = s->current_picture_ptr->f.data; - } - - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1); - } - break; - case MV_TYPE_16X8: - for(i=0; i<2; i++){ - uint8_t ** ref2picture; - - if(s->picture_structure == s->field_select[dir][i] + 1 - || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){ - ref2picture= ref_picture; - }else{ - ref2picture = s->current_picture_ptr->f.data; - } - - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][i], - ref2picture, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1); - - dest_y += 16*s->linesize; - dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; - dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; - } - break; - case MV_TYPE_DMV: - if(s->picture_structure == PICT_FRAME){ - for(i=0; i<2; i++){ - int j; - for(j=0; j<2; j++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, j, j^i, - ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y); - } - pix_op = s->dsp.avg_pixels_tab; - } - }else{ - for(i=0; i<2; i++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->picture_structure != i+1, - ref_picture, pix_op, - s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1); - - // after put we make avg of the same block - pix_op=s->dsp.avg_pixels_tab; - - //opposite parity is always in the same frame if this is second field - if(!s->first_field){ - ref_picture = s->current_picture_ptr->f.data; - } - } - } - break; - default: assert(0); - } -} - -static inline void MPV_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, - uint8_t *dest_cr, int dir, - uint8_t **ref_picture, - op_pixels_func (*pix_op)[4], - qpel_mc_func (*qpix_op)[16]) -{ -#if !CONFIG_SMALL - if(s->out_format == FMT_MPEG1) - MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir, - ref_picture, pix_op, qpix_op, 1); - else -#endif - MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir, - ref_picture, pix_op, qpix_op, 0); -} -#endif /* AVCODEC_MPEGVIDEO_COMMON_H */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index e84b0dae03..d527ace6dd 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -33,7 +33,6 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "h263.h" #include "mjpegenc.h" #include "msmpeg4.h" @@ -1850,14 +1849,16 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, } if (s->mv_dir & MV_DIR_FORWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, - op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, + s->last_picture.f.data, + op_pix, op_qpix); op_pix = s->dsp.avg_pixels_tab; op_qpix = s->dsp.avg_qpel_pixels_tab; } if (s->mv_dir & MV_DIR_BACKWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, - op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, + s->next_picture.f.data, + op_pix, op_qpix); } if (s->flags & CODEC_FLAG_INTERLACED_DCT) { diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c new file mode 100644 index 0000000000..ea0695323b --- /dev/null +++ b/libavcodec/mpegvideo_motion.c @@ -0,0 +1,875 @@ +/* + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * + * 4MV & hq & B-frame encoding stuff by 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 "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "mjpegenc.h" +#include "msmpeg4.h" +#include + +static inline void gmc1_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture) +{ + uint8_t *ptr; + int offset, src_x, src_y, linesize, uvlinesize; + int motion_x, motion_y; + int emu=0; + + motion_x= s->sprite_offset[0][0]; + motion_y= s->sprite_offset[0][1]; + src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); + src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); + motion_x<<=(3-s->sprite_warping_accuracy); + motion_y<<=(3-s->sprite_warping_accuracy); + src_x = av_clip(src_x, -16, s->width); + if (src_x == s->width) + motion_x =0; + src_y = av_clip(src_y, -16, s->height); + if (src_y == s->height) + motion_y =0; + + linesize = s->linesize; + uvlinesize = s->uvlinesize; + + ptr = ref_picture[0] + (src_y * linesize) + src_x; + + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) + || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); + ptr= s->edge_emu_buffer; + } + } + + if((motion_x|motion_y)&7){ + s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); + s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); + }else{ + int dxy; + + dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); + if (s->no_rounding){ + s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); + }else{ + s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); + } + } + + if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return; + + motion_x= s->sprite_offset[1][0]; + motion_y= s->sprite_offset[1][1]; + src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); + src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); + motion_x<<=(3-s->sprite_warping_accuracy); + motion_y<<=(3-s->sprite_warping_accuracy); + src_x = av_clip(src_x, -8, s->width>>1); + if (src_x == s->width>>1) + motion_x =0; + src_y = av_clip(src_y, -8, s->height>>1); + if (src_y == s->height>>1) + motion_y =0; + + offset = (src_y * uvlinesize) + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0) + || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + emu=1; + } + } + s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); + + ptr = ref_picture[2] + offset; + if(emu){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + } + s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); + + return; +} + +static inline void gmc_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture) +{ + uint8_t *ptr; + int linesize, uvlinesize; + const int a= s->sprite_warping_accuracy; + int ox, oy; + + linesize = s->linesize; + uvlinesize = s->uvlinesize; + + ptr = ref_picture[0]; + + ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; + oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; + + s->dsp.gmc(dest_y, ptr, linesize, 16, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos, s->v_edge_pos); + s->dsp.gmc(dest_y+8, ptr, linesize, 16, + ox + s->sprite_delta[0][0]*8, + oy + s->sprite_delta[1][0]*8, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos, s->v_edge_pos); + + if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return; + + ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; + oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; + + ptr = ref_picture[1]; + s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos>>1, s->v_edge_pos>>1); + + ptr = ref_picture[2]; + s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos>>1, s->v_edge_pos>>1); +} + +static inline int hpel_motion(MpegEncContext *s, + uint8_t *dest, uint8_t *src, + int field_based, int field_select, + int src_x, int src_y, + int width, int height, int stride, + int h_edge_pos, int v_edge_pos, + int w, int h, op_pixels_func *pix_op, + int motion_x, int motion_y) +{ + int dxy; + int emu=0; + + dxy = ((motion_y & 1) << 1) | (motion_x & 1); + src_x += motion_x >> 1; + src_y += motion_y >> 1; + + /* WARNING: do no forget half pels */ + src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu? + if (src_x == width) + dxy &= ~1; + src_y = av_clip(src_y, -16, height); + if (src_y == height) + dxy &= ~2; + src += src_y * stride + src_x; + + if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ + if( (unsigned)src_x > FFMAX(h_edge_pos - (motion_x&1) - w, 0) + || (unsigned)src_y > FFMAX(v_edge_pos - (motion_y&1) - h, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<v_edge_pos); + src= s->edge_emu_buffer; + emu=1; + } + } + if(field_select) + src += s->linesize; + pix_op[dxy](dest, src, stride, h); + return emu; +} + +static av_always_inline +void mpeg_motion_internal(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_based, int bottom_field, int field_select, + uint8_t **ref_picture, op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int is_mpeg12, int mb_y) +{ + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int dxy, uvdxy, mx, my, src_x, src_y, + uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; + +#if 0 +if(s->quarter_sample) +{ + motion_x>>=1; + motion_y>>=1; +} +#endif + + v_edge_pos = s->v_edge_pos >> field_based; + linesize = s->current_picture.f.linesize[0] << field_based; + uvlinesize = s->current_picture.f.linesize[1] << field_based; + + dxy = ((motion_y & 1) << 1) | (motion_x & 1); + src_x = s->mb_x* 16 + (motion_x >> 1); + src_y =( mb_y<<(4-field_based)) + (motion_y >> 1); + + if (!is_mpeg12 && s->out_format == FMT_H263) { + if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ + mx = (motion_x>>1)|(motion_x&1); + my = motion_y >>1; + uvdxy = ((my & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); + }else{ + uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); + uvsrc_x = src_x>>1; + uvsrc_y = src_y>>1; + } + }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261 + mx = motion_x / 4; + my = motion_y / 4; + uvdxy = 0; + uvsrc_x = s->mb_x*8 + mx; + uvsrc_y = mb_y*8 + my; + } else { + if(s->chroma_y_shift){ + mx = motion_x / 2; + my = motion_y / 2; + uvdxy = ((my & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); + } else { + if(s->chroma_x_shift){ + //Chroma422 + mx = motion_x / 2; + uvdxy = ((motion_y & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y = src_y; + } else { + //Chroma444 + uvdxy = dxy; + uvsrc_x = src_x; + uvsrc_y = src_y; + } + } + } + + ptr_y = ref_picture[0] + src_y * linesize + src_x; + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + + if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 16, 0) + || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&1) - h , 0)){ + if(is_mpeg12 || s->codec_id == AV_CODEC_ID_MPEG2VIDEO || + s->codec_id == AV_CODEC_ID_MPEG1VIDEO){ + av_log(s->avctx,AV_LOG_DEBUG, + "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y); + return; + } + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, + 17, 17+field_based, + src_x, src_y<h_edge_pos, s->v_edge_pos); + ptr_y = s->edge_emu_buffer; + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; + s->dsp.emulated_edge_mc(uvbuf , + ptr_cb, s->uvlinesize, + 9, 9+field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + s->dsp.emulated_edge_mc(uvbuf+16, + ptr_cr, s->uvlinesize, + 9, 9+field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ptr_cb= uvbuf; + ptr_cr= uvbuf+16; + } + } + + if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data + dest_y += s->linesize; + dest_cb+= s->uvlinesize; + dest_cr+= s->uvlinesize; + } + + if(field_select){ + ptr_y += s->linesize; + ptr_cb+= s->uvlinesize; + ptr_cr+= s->uvlinesize; + } + + pix_op[0][dxy](dest_y, ptr_y, linesize, h); + + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + pix_op[s->chroma_x_shift][uvdxy] + (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); + pix_op[s->chroma_x_shift][uvdxy] + (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); + } + if(!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) && + s->out_format == FMT_H261){ + ff_h261_loop_filter(s); + } +} +/* apply one mpeg motion vector to the three components */ +static av_always_inline +void mpeg_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_based, int bottom_field, int field_select, + uint8_t **ref_picture, op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int mb_y) +{ +#if !CONFIG_SMALL + if(s->out_format == FMT_MPEG1) + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + bottom_field, field_select, ref_picture, pix_op, + motion_x, motion_y, h, 1, mb_y); + else +#endif + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + bottom_field, field_select, ref_picture, pix_op, + motion_x, motion_y, h, 0, mb_y); +} + +//FIXME move to dsputil, avg variant, 16x16 version +static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ + int x; + uint8_t * const top = src[1]; + uint8_t * const left = src[2]; + uint8_t * const mid = src[0]; + uint8_t * const right = src[3]; + uint8_t * const bottom= src[4]; +#define OBMC_FILTER(x, t, l, m, r, b)\ + dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 +#define OBMC_FILTER4(x, t, l, m, r, b)\ + OBMC_FILTER(x , t, l, m, r, b);\ + OBMC_FILTER(x+1 , t, l, m, r, b);\ + OBMC_FILTER(x +stride, t, l, m, r, b);\ + OBMC_FILTER(x+1+stride, t, l, m, r, b); + + x=0; + OBMC_FILTER (x , 2, 2, 4, 0, 0); + OBMC_FILTER (x+1, 2, 1, 5, 0, 0); + OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); + OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); + OBMC_FILTER (x+6, 2, 0, 5, 1, 0); + OBMC_FILTER (x+7, 2, 0, 4, 2, 0); + x+= stride; + OBMC_FILTER (x , 1, 2, 5, 0, 0); + OBMC_FILTER (x+1, 1, 2, 5, 0, 0); + OBMC_FILTER (x+6, 1, 0, 5, 2, 0); + OBMC_FILTER (x+7, 1, 0, 5, 2, 0); + x+= stride; + OBMC_FILTER4(x , 1, 2, 5, 0, 0); + OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); + OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); + OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); + x+= 2*stride; + OBMC_FILTER4(x , 0, 2, 5, 0, 1); + OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); + OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); + OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); + x+= 2*stride; + OBMC_FILTER (x , 0, 2, 5, 0, 1); + OBMC_FILTER (x+1, 0, 2, 5, 0, 1); + OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); + OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); + OBMC_FILTER (x+6, 0, 0, 5, 2, 1); + OBMC_FILTER (x+7, 0, 0, 5, 2, 1); + x+= stride; + OBMC_FILTER (x , 0, 2, 4, 0, 2); + OBMC_FILTER (x+1, 0, 1, 5, 0, 2); + OBMC_FILTER (x+6, 0, 0, 5, 1, 2); + OBMC_FILTER (x+7, 0, 0, 4, 2, 2); +} + +/* obmc for 1 8x8 luma block */ +static inline void obmc_motion(MpegEncContext *s, + uint8_t *dest, uint8_t *src, + int src_x, int src_y, + op_pixels_func *pix_op, + int16_t mv[5][2]/* mid top left right bottom*/) +#define MID 0 +{ + int i; + uint8_t *ptr[5]; + + assert(s->quarter_sample==0); + + for(i=0; i<5; i++){ + if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ + ptr[i]= ptr[MID]; + }else{ + ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); + hpel_motion(s, ptr[i], src, 0, 0, + src_x, src_y, + s->width, s->height, s->linesize, + s->h_edge_pos, s->v_edge_pos, + 8, 8, pix_op, + mv[i][0], mv[i][1]); + } + } + + put_obmc(dest, ptr, s->linesize); +} + +static inline void qpel_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_based, int bottom_field, int field_select, + uint8_t **ref_picture, op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16], + int motion_x, int motion_y, int h) +{ + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; + + dxy = ((motion_y & 3) << 2) | (motion_x & 3); + src_x = s->mb_x * 16 + (motion_x >> 2); + src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); + + v_edge_pos = s->v_edge_pos >> field_based; + linesize = s->linesize << field_based; + uvlinesize = s->uvlinesize << field_based; + + if(field_based){ + mx= motion_x/2; + my= motion_y>>1; + }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ + static const int rtab[8]= {0,0,1,1,0,0,0,1}; + mx= (motion_x>>1) + rtab[motion_x&7]; + my= (motion_y>>1) + rtab[motion_y&7]; + }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ + mx= (motion_x>>1)|(motion_x&1); + my= (motion_y>>1)|(motion_y&1); + }else{ + mx= motion_x/2; + my= motion_y/2; + } + mx= (mx>>1)|(mx&1); + my= (my>>1)|(my&1); + + uvdxy= (mx&1) | ((my&1)<<1); + mx>>=1; + my>>=1; + + uvsrc_x = s->mb_x * 8 + mx; + uvsrc_y = s->mb_y * (8 >> field_based) + my; + + ptr_y = ref_picture[0] + src_y * linesize + src_x; + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + + if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0) + || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, + 17, 17+field_based, src_x, src_y<h_edge_pos, s->v_edge_pos); + ptr_y= s->edge_emu_buffer; + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; + s->dsp.emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, + 9, 9 + field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + s->dsp.emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, + 9, 9 + field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ptr_cb= uvbuf; + ptr_cr= uvbuf + 16; + } + } + + if(!field_based) + qpix_op[0][dxy](dest_y, ptr_y, linesize); + else{ + if(bottom_field){ + dest_y += s->linesize; + dest_cb+= s->uvlinesize; + dest_cr+= s->uvlinesize; + } + + if(field_select){ + ptr_y += s->linesize; + ptr_cb += s->uvlinesize; + ptr_cr += s->uvlinesize; + } + //damn interlaced mode + //FIXME boundary mirroring is not exactly correct here + qpix_op[1][dxy](dest_y , ptr_y , linesize); + qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); + } + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); + pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); + } +} + +/** + * h263 chroma 4mv motion compensation. + */ +static inline void chroma_4mv_motion(MpegEncContext *s, + uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture, + op_pixels_func *pix_op, + int mx, int my){ + int dxy, emu=0, src_x, src_y, offset; + uint8_t *ptr; + + /* In case of 8X8, we construct a single chroma motion vector + with a special rounding */ + mx= ff_h263_round_chroma(mx); + my= ff_h263_round_chroma(my); + + dxy = ((my & 1) << 1) | (mx & 1); + mx >>= 1; + my >>= 1; + + src_x = s->mb_x * 8 + mx; + src_y = s->mb_y * 8 + my; + src_x = av_clip(src_x, -8, (s->width >> 1)); + if (src_x == (s->width >> 1)) + dxy &= ~1; + src_y = av_clip(src_y, -8, (s->height >> 1)); + if (src_y == (s->height >> 1)) + dxy &= ~2; + + offset = src_y * s->uvlinesize + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0) + || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, + 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + emu=1; + } + } + pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); + + ptr = ref_picture[2] + offset; + if(emu){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, + 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); +} + +static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ + /* fetch pixels for estimated mv 4 macroblocks ahead + * optimized for 64byte cache lines */ + const int shift = s->quarter_sample ? 2 : 1; + const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8; + const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y; + int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64; + s->dsp.prefetch(pix[0]+off, s->linesize, 4); + off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; + s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2); +} + +/** + * motion compensation of a single macroblock + * @param s context + * @param dest_y luma destination pointer + * @param dest_cb chroma cb/u destination pointer + * @param dest_cr chroma cr/v destination pointer + * @param dir direction (0->forward, 1->backward) + * @param ref_picture array[3] of pointers to the 3 planes of the reference picture + * @param pix_op halfpel motion compensation function (average or put normally) + * @param qpix_op qpel motion compensation function (average or put normally) + * the motion vectors are taken from s->mv and the MV type from s->mv_type + */ +static av_always_inline void MPV_motion_internal(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, + uint8_t *dest_cr, int dir, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16], int is_mpeg12) +{ + int dxy, mx, my, src_x, src_y, motion_x, motion_y; + int mb_x, mb_y, i; + uint8_t *ptr, *dest; + + mb_x = s->mb_x; + mb_y = s->mb_y; + + prefetch_motion(s, ref_picture, dir); + + if(!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B){ + int16_t mv_cache[4][4][2]; + const int xy= s->mb_x + s->mb_y*s->mb_stride; + const int mot_stride= s->b8_stride; + const int mot_xy= mb_x*2 + mb_y*2*mot_stride; + + assert(!s->mb_skipped); + + memcpy(mv_cache[1][1], s->current_picture.f.motion_val[0][mot_xy ], sizeof(int16_t) * 4); + memcpy(mv_cache[2][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); + memcpy(mv_cache[3][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); + + if (mb_y == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - s->mb_stride])) { + memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); + }else{ + memcpy(mv_cache[0][1], s->current_picture.f.motion_val[0][mot_xy - mot_stride], sizeof(int16_t) * 4); + } + + if (mb_x == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - 1])) { + AV_COPY32(mv_cache[1][0], mv_cache[1][1]); + AV_COPY32(mv_cache[2][0], mv_cache[2][1]); + }else{ + AV_COPY32(mv_cache[1][0], s->current_picture.f.motion_val[0][mot_xy - 1]); + AV_COPY32(mv_cache[2][0], s->current_picture.f.motion_val[0][mot_xy - 1 + mot_stride]); + } + + if (mb_x + 1 >= s->mb_width || IS_INTRA(s->current_picture.f.mb_type[xy + 1])) { + AV_COPY32(mv_cache[1][3], mv_cache[1][2]); + AV_COPY32(mv_cache[2][3], mv_cache[2][2]); + }else{ + AV_COPY32(mv_cache[1][3], s->current_picture.f.motion_val[0][mot_xy + 2]); + AV_COPY32(mv_cache[2][3], s->current_picture.f.motion_val[0][mot_xy + 2 + mot_stride]); + } + + mx = 0; + my = 0; + for(i=0;i<4;i++) { + const int x= (i&1)+1; + const int y= (i>>1)+1; + int16_t mv[5][2]= { + {mv_cache[y][x ][0], mv_cache[y][x ][1]}, + {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, + {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, + {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, + {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; + //FIXME cleanup + obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, + ref_picture[0], + mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, + pix_op[1], + mv); + + mx += mv[0][0]; + my += mv[0][1]; + } + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) + chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); + + return; + } + + switch(s->mv_type) { + case MV_TYPE_16X16: + if(s->mcsel){ + if(s->real_sprite_warping_points==1){ + gmc1_motion(s, dest_y, dest_cb, dest_cr, + ref_picture); + }else{ + gmc_motion(s, dest_y, dest_cb, dest_cr, + ref_picture); + } + }else if(!is_mpeg12 && s->quarter_sample){ + qpel_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, 0, + ref_picture, pix_op, qpix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + } else if (!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && + s->mspel && s->codec_id == AV_CODEC_ID_WMV2) { + ff_mspel_motion(s, dest_y, dest_cb, dest_cr, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + }else + { + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, 0, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y); + } + break; + case MV_TYPE_8X8: + if (!is_mpeg12) { + mx = 0; + my = 0; + if(s->quarter_sample){ + for(i=0;i<4;i++) { + motion_x = s->mv[dir][i][0]; + motion_y = s->mv[dir][i][1]; + + dxy = ((motion_y & 3) << 2) | (motion_x & 3); + src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; + src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; + + /* WARNING: do no forget half pels */ + src_x = av_clip(src_x, -16, s->width); + if (src_x == s->width) + dxy &= ~3; + src_y = av_clip(src_y, -16, s->height); + if (src_y == s->height) + dxy &= ~12; + + ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0) + || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, + s->linesize, 9, 9, + src_x, src_y, + s->h_edge_pos, s->v_edge_pos); + ptr= s->edge_emu_buffer; + } + } + dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; + qpix_op[1][dxy](dest, ptr, s->linesize); + + mx += s->mv[dir][i][0]/2; + my += s->mv[dir][i][1]/2; + } + }else{ + for(i=0;i<4;i++) { + hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, + ref_picture[0], 0, 0, + mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, + s->width, s->height, s->linesize, + s->h_edge_pos, s->v_edge_pos, + 8, 8, pix_op[1], + s->mv[dir][i][0], s->mv[dir][i][1]); + + mx += s->mv[dir][i][0]; + my += s->mv[dir][i][1]; + } + } + + if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) + chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); + } + break; + case MV_TYPE_FIELD: + if (s->picture_structure == PICT_FRAME) { + if(!is_mpeg12 && s->quarter_sample){ + for(i=0; i<2; i++){ + qpel_motion(s, dest_y, dest_cb, dest_cr, + 1, i, s->field_select[dir][i], + ref_picture, pix_op, qpix_op, + s->mv[dir][i][0], s->mv[dir][i][1], 8); + } + }else{ + /* top field */ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); + /* bottom field */ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, 1, s->field_select[dir][1], + ref_picture, pix_op, + s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); + } + } else { + if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ + ref_picture = s->current_picture_ptr->f.data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1); + } + break; + case MV_TYPE_16X8: + for(i=0; i<2; i++){ + uint8_t ** ref2picture; + + if(s->picture_structure == s->field_select[dir][i] + 1 + || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){ + ref2picture= ref_picture; + }else{ + ref2picture = s->current_picture_ptr->f.data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->field_select[dir][i], + ref2picture, pix_op, + s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1); + + dest_y += 16*s->linesize; + dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; + dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; + } + break; + case MV_TYPE_DMV: + if(s->picture_structure == PICT_FRAME){ + for(i=0; i<2; i++){ + int j; + for(j=0; j<2; j++){ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, j, j^i, + ref_picture, pix_op, + s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y); + } + pix_op = s->dsp.avg_pixels_tab; + } + }else{ + for(i=0; i<2; i++){ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->picture_structure != i+1, + ref_picture, pix_op, + s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1); + + // after put we make avg of the same block + pix_op=s->dsp.avg_pixels_tab; + + //opposite parity is always in the same frame if this is second field + if(!s->first_field){ + ref_picture = s->current_picture_ptr->f.data; + } + } + } + break; + default: assert(0); + } +} + +void ff_MPV_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, + uint8_t *dest_cr, int dir, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16]) +{ +#if !CONFIG_SMALL + if(s->out_format == FMT_MPEG1) + MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir, + ref_picture, pix_op, qpix_op, 1); + else +#endif + MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir, + ref_picture, pix_op, qpix_op, 0); +} -- cgit v1.2.3 From f69f4036f8cc3b673864dce01d2714fd5e49e8da Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 02:30:02 +0100 Subject: mpegvideo: reduce excessive inlining of mpeg_motion() The main benefit of inlining this function is from constant propagation for the 'field_based' argument. Instead of inlining all calls, create two versions of the function for field_based values of 0 and 1. Signed-off-by: Mans Rullgard --- libavcodec/mpegvideo_motion.c | 67 +++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c index ea0695323b..d4c4d6e640 100644 --- a/libavcodec/mpegvideo_motion.c +++ b/libavcodec/mpegvideo_motion.c @@ -339,21 +339,39 @@ if(s->quarter_sample) } } /* apply one mpeg motion vector to the three components */ -static av_always_inline -void mpeg_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h, int mb_y) +static void mpeg_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_select, uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int mb_y) { #if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, + field_select, ref_picture, pix_op, + motion_x, motion_y, h, 1, mb_y); + else +#endif + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, + field_select, ref_picture, pix_op, + motion_x, motion_y, h, 0, mb_y); +} + +static void mpeg_motion_field(MpegEncContext *s, uint8_t *dest_y, + uint8_t *dest_cb, uint8_t *dest_cr, + int bottom_field, int field_select, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int mb_y) +{ +#if !CONFIG_SMALL + if(s->out_format == FMT_MPEG1) + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 1, mb_y); else #endif - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 0, mb_y); } @@ -708,8 +726,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, s->mv[dir][0][0], s->mv[dir][0][1], 16); }else { - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, + mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, ref_picture, pix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y); } @@ -782,15 +799,15 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } }else{ /* top field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); /* bottom field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 1, s->field_select[dir][1], - ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + 1, s->field_select[dir][1], + ref_picture, pix_op, + s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); } } else { if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ @@ -798,7 +815,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][0], + s->field_select[dir][0], ref_picture, pix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1); } @@ -815,7 +832,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][i], + s->field_select[dir][i], ref2picture, pix_op, s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1); @@ -829,17 +846,17 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, for(i=0; i<2; i++){ int j; for(j=0; j<2; j++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, j, j^i, - ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + j, j^i, ref_picture, pix_op, + s->mv[dir][2*i + j][0], + s->mv[dir][2*i + j][1], 8, mb_y); } pix_op = s->dsp.avg_pixels_tab; } }else{ for(i=0; i<2; i++){ mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->picture_structure != i+1, + s->picture_structure != i+1, ref_picture, pix_op, s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1); -- cgit v1.2.3