diff options
-rw-r--r-- | LICENSE.md | 1 | ||||
-rw-r--r-- | libavcodec/flacenc.c | 2 | ||||
-rw-r--r-- | libavcodec/x86/Makefile | 3 | ||||
-rw-r--r-- | libavcodec/x86/flac_dsp_gpl.asm | 85 | ||||
-rw-r--r-- | libavcodec/x86/flacdsp_init.c | 4 |
5 files changed, 94 insertions, 1 deletions
diff --git a/LICENSE.md b/LICENSE.md index 04decbf46a..e78d932b0b 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -15,6 +15,7 @@ Specifically, the GPL parts of FFmpeg are: - libpostproc - libmpcodecs - optional x86 optimizations in the files + libavcodec/x86/flac_dsp_gpl.asm libavcodec/x86/idct_mmx.c - libutvideo encoding/decoding wrappers in libavcodec/libutvideo*.cpp diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 3a3b2ae9f7..f37bab8f3e 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -80,7 +80,7 @@ typedef struct FlacSubframe { int shift; RiceContext rc; int32_t samples[FLAC_MAX_BLOCKSIZE]; - int32_t residual[FLAC_MAX_BLOCKSIZE+1]; + int32_t residual[FLAC_MAX_BLOCKSIZE+3]; } FlacSubframe; typedef struct FlacFrame { diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile index 53e643b5d4..4298262031 100644 --- a/libavcodec/x86/Makefile +++ b/libavcodec/x86/Makefile @@ -83,6 +83,9 @@ YASM-OBJS-$(CONFIG_DIRAC_DECODER) += x86/diracdsp_mmx.o x86/diracdsp_yasm.o YASM-OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhdenc.o YASM-OBJS-$(CONFIG_FFT) += x86/fft.o YASM-OBJS-$(CONFIG_FLAC_DECODER) += x86/flacdsp.o +ifdef CONFIG_GPL +YASM-OBJS-$(CONFIG_FLAC_ENCODER) += x86/flac_dsp_gpl.o +endif YASM-OBJS-$(CONFIG_H263DSP) += x86/h263_loopfilter.o YASM-OBJS-$(CONFIG_H264CHROMA) += x86/h264_chromamc.o \ x86/h264_chromamc_10bit.o diff --git a/libavcodec/x86/flac_dsp_gpl.asm b/libavcodec/x86/flac_dsp_gpl.asm new file mode 100644 index 0000000000..1f28be132a --- /dev/null +++ b/libavcodec/x86/flac_dsp_gpl.asm @@ -0,0 +1,85 @@ +;****************************************************************************** +;* FLAC DSP functions +;* +;* Copyright (c) 2014 James Darnley <james.darnley@gmail.com> +;* +;* This file is part of FFmpeg. +;* +;* FFmpeg is free software; you can redistribute it and/or modify +;* it under the terms of the GNU General Public License as published by +;* the Free Software Foundation; either version 2 of the License, or +;* (at your option) any later version. +;* +;* FFmpeg 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 General Public License for more details. +;* +;* You should have received a copy of the GNU General Public License along +;* with FFmpeg; if not, write to the Free Software Foundation, Inc., +;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +;****************************************************************************** + +%include "libavutil/x86/x86util.asm" + +SECTION_TEXT + +INIT_XMM sse4 +%if ARCH_X86_64 + cglobal flac_enc_lpc_16, 5, 7, 4, 0, res, smp, len, order, coefs + DECLARE_REG_TMP 5, 6 + %define length r2d + + movsxd orderq, orderd +%else + cglobal flac_enc_lpc_16, 5, 6, 4, 0, res, smp, len, order, coefs + DECLARE_REG_TMP 2, 5 + %define length r2mp +%endif + +; Here we assume that the maximum order value is 32. This means that we only +; need to copy a maximum of 32 samples. Therefore we let the preprocessor +; unroll this loop and copy all 32. +%assign iter 0 +%rep 32/(mmsize/4) + movu m0, [smpq+iter] + movu [resq+iter], m0 + %assign iter iter+mmsize +%endrep + +lea resq, [resq+orderq*4] +lea smpq, [smpq+orderq*4] +lea coefsq, [coefsq+orderq*4] +sub length, orderd +movd m3, r5m +neg orderq + +%define posj t0q +%define negj t1q + +.looplen: + pxor m0, m0 + mov posj, orderq + xor negj, negj + + .looporder: + movd m2, [coefsq+posj*4] ; c = coefs[j] + SPLATD m2 + movu m1, [smpq+negj*4-4] ; s = smp[i-j-1] + pmulld m1, m2 + paddd m0, m1 ; p += c * s + + dec negj + inc posj + jnz .looporder + + psrad m0, m3 ; p >>= shift + movu m1, [smpq] + psubd m1, m0 ; smp[i] - p + movu [resq], m1 ; res[i] = smp[i] - (p >> shift) + + add resq, mmsize + add smpq, mmsize + sub length, mmsize/4 +jg .looplen +RET diff --git a/libavcodec/x86/flacdsp_init.c b/libavcodec/x86/flacdsp_init.c index a071b3d3b7..ad88e5bbd1 100644 --- a/libavcodec/x86/flacdsp_init.c +++ b/libavcodec/x86/flacdsp_init.c @@ -27,6 +27,8 @@ void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order, void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order, int qlevel, int len); +void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *,int); + av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int bps) { @@ -36,6 +38,8 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, if (EXTERNAL_SSE4(cpu_flags)) { if (bps > 16 && CONFIG_FLAC_DECODER) c->lpc = ff_flac_lpc_32_sse4; + if (bps == 16 && CONFIG_FLAC_ENCODER && CONFIG_GPL) + c->lpc_encode = ff_flac_enc_lpc_16_sse4; } if (EXTERNAL_XOP(cpu_flags)) { if (bps > 16 && CONFIG_FLAC_DECODER) |