mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-06-16 04:32:47 +02:00
avcodec/mpegvideo_enc: Port denoise_dct to MpegvideoEncDSPContext
It is very simple to remove the MPVEncContext from it. Notice that this also fixes a bug in x86/mpegvideoenc.c: It only used the SSE2 version of denoise_dct when dct_algo was auto or mmx (and it was therefore unused during FATE). Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
@@ -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;
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user