diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile index 4bbc2f00ea..1d777293d0 100644 --- a/libavcodec/mips/Makefile +++ b/libavcodec/mips/Makefile @@ -54,7 +54,6 @@ OBJS-$(CONFIG_BLOCKDSP) += mips/blockdsp_init_mips.o OBJS-$(CONFIG_PIXBLOCKDSP) += mips/pixblockdsp_init_mips.o OBJS-$(CONFIG_IDCTDSP) += mips/idctdsp_init_mips.o OBJS-$(CONFIG_MPEGVIDEO) += mips/mpegvideo_init_mips.o -OBJS-$(CONFIG_MPEGVIDEOENC) += mips/mpegvideoenc_init_mips.o OBJS-$(CONFIG_MPEGVIDEOENCDSP) += mips/mpegvideoencdsp_init_mips.o OBJS-$(CONFIG_ME_CMP) += mips/me_cmp_init_mips.o OBJS-$(CONFIG_MPEG4_DECODER) += mips/xvididct_init_mips.o @@ -100,7 +99,7 @@ MMI-OBJS-$(CONFIG_H264DSP) += mips/h264dsp_mmi.o MMI-OBJS-$(CONFIG_H264CHROMA) += mips/h264chroma_mmi.o MMI-OBJS-$(CONFIG_H264PRED) += mips/h264pred_mmi.o MMI-OBJS-$(CONFIG_MPEGVIDEO) += mips/mpegvideo_mmi.o -MMI-OBJS-$(CONFIG_MPEGVIDEOENC) += mips/mpegvideoenc_mmi.o +MMI-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += mips/mpegvideoenc_mmi.o MMI-OBJS-$(CONFIG_IDCTDSP) += mips/idctdsp_mmi.o \ mips/simple_idct_mmi.o MMI-OBJS-$(CONFIG_MPEG4_DECODER) += mips/xvid_idct_mmi.o diff --git a/libavcodec/mips/mpegvideo_mips.h b/libavcodec/mips/mpegvideo_mips.h index 72ffed6985..2a9ea4006e 100644 --- a/libavcodec/mips/mpegvideo_mips.h +++ b/libavcodec/mips/mpegvideo_mips.h @@ -22,7 +22,6 @@ #define AVCODEC_MIPS_MPEGVIDEO_MIPS_H #include "libavcodec/mpegvideo.h" -#include "libavcodec/mpegvideoenc.h" void ff_dct_unquantize_h263_intra_mmi(MpegEncContext *s, int16_t *block, int n, int qscale); @@ -34,6 +33,6 @@ void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block, int n, int qscale); void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block, int n, int qscale); -void ff_denoise_dct_mmi(MPVEncContext *s, int16_t *block); +void ff_denoise_dct_mmi(int16_t block[64], int sum[64], const uint16_t offset[64]); #endif /* AVCODEC_MIPS_MPEGVIDEO_MIPS_H */ diff --git a/libavcodec/mips/mpegvideoenc_init_mips.c b/libavcodec/mips/mpegvideoenc_init_mips.c deleted file mode 100644 index 7831973eb8..0000000000 --- a/libavcodec/mips/mpegvideoenc_init_mips.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.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 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. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser 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/attributes.h" -#include "libavutil/mips/cpu.h" -#include "libavcodec/mpegvideoenc.h" -#include "mpegvideo_mips.h" - -av_cold void ff_mpvenc_dct_init_mips(MPVEncContext *s) -{ - int cpu_flags = av_get_cpu_flags(); - - if (have_mmi(cpu_flags)) { - s->denoise_dct = ff_denoise_dct_mmi; - } -} diff --git a/libavcodec/mips/mpegvideoencdsp_init_mips.c b/libavcodec/mips/mpegvideoencdsp_init_mips.c index 24a17b91db..df916282a2 100644 --- a/libavcodec/mips/mpegvideoencdsp_init_mips.c +++ b/libavcodec/mips/mpegvideoencdsp_init_mips.c @@ -23,12 +23,17 @@ #include "libavcodec/bit_depth_template.c" #include "libavcodec/mpegvideoencdsp.h" #include "h263dsp_mips.h" +#include "mpegvideo_mips.h" av_cold void ff_mpegvideoencdsp_init_mips(MpegvideoEncDSPContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); + if (have_mmi(cpu_flags)) { + c->denoise_dct = ff_denoise_dct_mmi; + } + if (have_msa(cpu_flags)) { #if BIT_DEPTH == 8 c->pix_sum = ff_pix_sum_msa; diff --git a/libavcodec/mips/mpegvideoenc_mmi.c b/libavcodec/mips/mpegvideoencdsp_mmi.c similarity index 95% rename from libavcodec/mips/mpegvideoenc_mmi.c rename to libavcodec/mips/mpegvideoencdsp_mmi.c index 085be3b0ec..2239a05978 100644 --- a/libavcodec/mips/mpegvideoenc_mmi.c +++ b/libavcodec/mips/mpegvideoencdsp_mmi.c @@ -25,17 +25,12 @@ #include "mpegvideo_mips.h" #include "libavutil/mips/mmiutils.h" -void ff_denoise_dct_mmi(MPVEncContext *s, int16_t *block) +void ff_denoise_dct_mmi(int16_t block[64], int sum[64], const uint16_t offset[64]) { - const int intra = s->c.mb_intra; - int *sum = s->dct_error_sum[intra]; - uint16_t *offset = s->dct_offset[intra]; double ftmp[8]; mips_reg addr[1]; DECLARE_VAR_ALL64; - s->dct_count[intra]++; - __asm__ volatile( "pxor %[ftmp0], %[ftmp0], %[ftmp0] \n\t" "1: \n\t" diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index ce0ee4bb68..9e83026b51 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -86,7 +86,6 @@ static int encode_picture(MPVMainEncContext *const s, const AVPacket *pkt); static int dct_quantize_refine(MPVEncContext *const s, int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale); static int sse_mb(MPVEncContext *const s); -static void denoise_dct_c(MPVEncContext *const s, int16_t *block); static int dct_quantize_c(MPVEncContext *const s, int16_t *block, int n, int qscale, int *overflow); @@ -300,11 +299,8 @@ static av_cold void mpv_encode_defaults(MPVMainEncContext *const m) av_cold void ff_dct_encode_init(MPVEncContext *const s) { s->dct_quantize = dct_quantize_c; - s->denoise_dct = denoise_dct_c; -#if ARCH_MIPS - ff_mpvenc_dct_init_mips(s); -#elif ARCH_X86 +#if ARCH_X86 ff_dct_encode_init_x86(s); #endif @@ -3955,29 +3951,14 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) return 0; } -static void denoise_dct_c(MPVEncContext *const s, int16_t *block) +static inline void denoise_dct(MPVEncContext *const s, int16_t block[]) { + if (!s->dct_error_sum) + return; + const int intra = s->c.mb_intra; - int i; - s->dct_count[intra]++; - - for(i=0; i<64; i++){ - int level= block[i]; - - if(level){ - if(level>0){ - s->dct_error_sum[intra][i] += level; - level -= s->dct_offset[intra][i]; - if(level<0) level=0; - }else{ - s->dct_error_sum[intra][i] -= level; - level += s->dct_offset[intra][i]; - if(level>0) level=0; - } - block[i]= level; - } - } + s->mpvencdsp.denoise_dct(block, s->dct_error_sum[intra], s->dct_offset[intra]); } static int dct_quantize_trellis_c(MPVEncContext *const s, @@ -4009,8 +3990,8 @@ static int dct_quantize_trellis_c(MPVEncContext *const s, s->fdsp.fdct(block); - if(s->dct_error_sum) - s->denoise_dct(s, block); + denoise_dct(s, block); + qmul= qscale*16; qadd= ((qscale-1)|1)*8; @@ -4678,8 +4659,7 @@ static int dct_quantize_c(MPVEncContext *const s, s->fdsp.fdct(block); - if(s->dct_error_sum) - s->denoise_dct(s, block); + denoise_dct(s, block); if (s->c.mb_intra) { scantable = s->c.intra_scantable.scantable; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index ee115c3611..131908c10a 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -123,7 +123,6 @@ typedef struct MPVEncContext { uint16_t (*q_inter_matrix16)[2][64]; /* noise reduction */ - void (*denoise_dct)(struct MPVEncContext *s, int16_t *block); int (*dct_error_sum)[64]; int dct_count[2]; uint16_t (*dct_offset)[64]; @@ -397,7 +396,6 @@ int ff_mpv_reallocate_putbitbuffer(MPVEncContext *s, size_t threshold, size_t si void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix); void ff_dct_encode_init(MPVEncContext *s); -void ff_mpvenc_dct_init_mips(MPVEncContext *s); void ff_dct_encode_init_x86(MPVEncContext *s); void ff_convert_matrix(MPVEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[2][64], diff --git a/libavcodec/mpegvideoencdsp.c b/libavcodec/mpegvideoencdsp.c index b4fd2af915..3b4a57d58a 100644 --- a/libavcodec/mpegvideoencdsp.c +++ b/libavcodec/mpegvideoencdsp.c @@ -28,6 +28,29 @@ #include "mathops.h" #include "mpegvideoencdsp.h" +static void denoise_dct_c(int16_t block[64], int dct_error_sum[64], + const uint16_t dct_offset[64]) +{ + for (int i = 0; i < 64; ++i) { + int level = block[i]; + + if (level) { + if (level > 0) { + dct_error_sum[i] += level; + level -= dct_offset[i]; + if (level < 0) + level = 0; + } else { + dct_error_sum[i] -= level; + level += dct_offset[i]; + if (level > 0) + level = 0; + } + block[i] = level; + } + } +} + static int try_8x8basis_c(const int16_t rem[64], const int16_t weight[64], const int16_t basis[64], int scale) { @@ -253,6 +276,8 @@ static void shrink88(uint8_t *dst, ptrdiff_t dst_wrap, av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx) { + c->denoise_dct = denoise_dct_c; + c->try_8x8basis = try_8x8basis_c; c->add_8x8basis = add_8x8basis_c; diff --git a/libavcodec/mpegvideoencdsp.h b/libavcodec/mpegvideoencdsp.h index 6ec665677b..989503f25f 100644 --- a/libavcodec/mpegvideoencdsp.h +++ b/libavcodec/mpegvideoencdsp.h @@ -30,6 +30,9 @@ #define EDGE_BOTTOM 2 typedef struct MpegvideoEncDSPContext { + void (*denoise_dct)(int16_t block[64], int dct_error_sum[64], + const uint16_t dct_offset[64]); + int (*try_8x8basis)(const int16_t rem[64], const int16_t weight[64], const int16_t basis[64], int scale); void (*add_8x8basis)(int16_t rem[64], const int16_t basis[64], int scale); diff --git a/libavcodec/x86/mpegvideoenc.c b/libavcodec/x86/mpegvideoenc.c index e5665ac781..c667dcd2a2 100644 --- a/libavcodec/x86/mpegvideoenc.c +++ b/libavcodec/x86/mpegvideoenc.c @@ -57,22 +57,6 @@ DECLARE_ALIGNED(16, static const uint16_t, inv_zigzag_direct16)[64] = { #endif /* HAVE_6REGS */ -#if HAVE_SSE2_EXTERNAL -void ff_mpv_denoise_dct_sse2(int16_t block[64], int dct_error_sum[64], - const uint16_t dct_offset[64]); - -static void denoise_dct_sse2(MPVEncContext *const s, int16_t block[]) -{ - const int intra = s->c.mb_intra; - int *sum= s->dct_error_sum[intra]; - uint16_t *offset= s->dct_offset[intra]; - - s->dct_count[intra]++; - - ff_mpv_denoise_dct_sse2(block, sum, offset); -} -#endif /* HAVE_SSE2_EXTERNAL */ - av_cold void ff_dct_encode_init_x86(MPVEncContext *const s) { const int dct_algo = s->c.avctx->dct_algo; @@ -83,9 +67,6 @@ av_cold void ff_dct_encode_init_x86(MPVEncContext *const s) if (INLINE_SSE2(cpu_flags)) { #if HAVE_6REGS s->dct_quantize = dct_quantize_sse2; -#endif -#if HAVE_SSE2_EXTERNAL - s->denoise_dct = denoise_dct_sse2; #endif } #if HAVE_6REGS && HAVE_SSSE3_INLINE diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c index f0b95c1621..14e993de2b 100644 --- a/libavcodec/x86/mpegvideoenc_template.c +++ b/libavcodec/x86/mpegvideoenc_template.c @@ -76,8 +76,11 @@ static int RENAME(dct_quantize)(MPVEncContext *const s, //s->fdct (block); ff_fdct_sse2(block); // cannot be anything else ... - if(s->dct_error_sum) - s->denoise_dct(s, block); + if (s->dct_error_sum) { + const int intra = s->c.mb_intra; + s->dct_count[intra]++; + s->mpvencdsp.denoise_dct(block, s->dct_error_sum[intra], s->dct_offset[intra]); + } if (s->c.mb_intra) { int dummy; diff --git a/libavcodec/x86/mpegvideoencdsp_init.c b/libavcodec/x86/mpegvideoencdsp_init.c index bf5b722016..f6169b5399 100644 --- a/libavcodec/x86/mpegvideoencdsp_init.c +++ b/libavcodec/x86/mpegvideoencdsp_init.c @@ -27,6 +27,8 @@ #include "libavcodec/avcodec.h" #include "libavcodec/mpegvideoencdsp.h" +void ff_mpv_denoise_dct_sse2(int16_t block[64], int dct_error_sum[64], + const uint16_t dct_offset[64]); int ff_pix_sum16_sse2(const uint8_t *pix, ptrdiff_t line_size); int ff_pix_sum16_xop(const uint8_t *pix, ptrdiff_t line_size); int ff_pix_norm1_sse2(const uint8_t *pix, ptrdiff_t line_size); @@ -209,6 +211,7 @@ av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, int cpu_flags = av_get_cpu_flags(); if (EXTERNAL_SSE2(cpu_flags)) { + c->denoise_dct = ff_mpv_denoise_dct_sse2; c->pix_sum = ff_pix_sum16_sse2; c->pix_norm1 = ff_pix_norm1_sse2; }