Skip to content

Commit 362586f

Browse files
committed
avfilter/vf_xpsnr: remove duplicated DSP infranstructure
Fully reuse the existing one from vf_psnr, instead of halfways. Signed-off-by: James Almer <[email protected]>
1 parent 496b8d7 commit 362586f

File tree

8 files changed

+77
-100
lines changed

8 files changed

+77
-100
lines changed

libavfilter/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ OBJS-$(CONFIG_PREWITT_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o
438438
OBJS-$(CONFIG_PROCAMP_VAAPI_FILTER) += vf_procamp_vaapi.o vaapi_vpp.o
439439
OBJS-$(CONFIG_PROGRAM_OPENCL_FILTER) += vf_program_opencl.o opencl.o framesync.o
440440
OBJS-$(CONFIG_PSEUDOCOLOR_FILTER) += vf_pseudocolor.o
441-
OBJS-$(CONFIG_PSNR_FILTER) += vf_psnr.o framesync.o
441+
OBJS-$(CONFIG_PSNR_FILTER) += vf_psnr.o framesync.o psnr.o
442442
OBJS-$(CONFIG_PULLUP_FILTER) += vf_pullup.o
443443
OBJS-$(CONFIG_QP_FILTER) += vf_qp.o
444444
OBJS-$(CONFIG_QUIRC_FILTER) += vf_quirc.o
@@ -567,7 +567,7 @@ OBJS-$(CONFIG_XFADE_FILTER) += vf_xfade.o
567567
OBJS-$(CONFIG_XFADE_OPENCL_FILTER) += vf_xfade_opencl.o opencl.o opencl/xfade.o
568568
OBJS-$(CONFIG_XFADE_VULKAN_FILTER) += vf_xfade_vulkan.o vulkan.o vulkan_filter.o
569569
OBJS-$(CONFIG_XMEDIAN_FILTER) += vf_xmedian.o framesync.o
570-
OBJS-$(CONFIG_XPSNR_FILTER) += vf_xpsnr.o framesync.o
570+
OBJS-$(CONFIG_XPSNR_FILTER) += vf_xpsnr.o framesync.o psnr.o
571571
OBJS-$(CONFIG_XSTACK_FILTER) += vf_stack.o framesync.o
572572
OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o yadif_common.o
573573
OBJS-$(CONFIG_YADIF_CUDA_FILTER) += vf_yadif_cuda.o vf_yadif_cuda.ptx.o \

libavfilter/psnr.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2015 Ronald S. Bultje <[email protected]>
3+
*
4+
* This file is part of FFmpeg.
5+
*
6+
* FFmpeg is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2.1 of the License, or (at your option) any later version.
10+
*
11+
* FFmpeg is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with FFmpeg; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "config.h"
22+
23+
#include <stddef.h>
24+
#include <stdint.h>
25+
26+
#include "psnr.h"
27+
28+
static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
29+
{
30+
int j;
31+
unsigned m2 = 0;
32+
33+
for (j = 0; j < outw; j++) {
34+
unsigned error = main_line[j] - ref_line[j];
35+
36+
m2 += error * error;
37+
}
38+
39+
return m2;
40+
}
41+
42+
static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
43+
{
44+
int j;
45+
uint64_t m2 = 0;
46+
const uint16_t *main_line = (const uint16_t *) _main_line;
47+
const uint16_t *ref_line = (const uint16_t *) _ref_line;
48+
49+
for (j = 0; j < outw; j++) {
50+
unsigned error = main_line[j] - ref_line[j];
51+
52+
m2 += error * error;
53+
}
54+
55+
return m2;
56+
}
57+
58+
void ff_psnr_init(PSNRDSPContext *dsp, int bpp)
59+
{
60+
dsp->sse_line = bpp > 8 ? sse_line_16bit : sse_line_8bit;
61+
#if ARCH_X86
62+
ff_psnr_init_x86(dsp, bpp);
63+
#endif
64+
}

libavfilter/psnr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef struct PSNRDSPContext {
2828
uint64_t (*sse_line)(const uint8_t *buf, const uint8_t *ref, int w);
2929
} PSNRDSPContext;
3030

31+
void ff_psnr_init(PSNRDSPContext *dsp, int bpp);
3132
void ff_psnr_init_x86(PSNRDSPContext *dsp, int bpp);
3233

3334
#endif /* AVFILTER_PSNR_H */

libavfilter/vf_psnr.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,6 @@ static inline double get_psnr(double mse, uint64_t nb_frames, int max)
8282
return 10.0 * log10(pow_2(max) / (mse / nb_frames));
8383
}
8484

85-
static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
86-
{
87-
int j;
88-
unsigned m2 = 0;
89-
90-
for (j = 0; j < outw; j++)
91-
m2 += pow_2(main_line[j] - ref_line[j]);
92-
93-
return m2;
94-
}
95-
96-
static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
97-
{
98-
int j;
99-
uint64_t m2 = 0;
100-
const uint16_t *main_line = (const uint16_t *) _main_line;
101-
const uint16_t *ref_line = (const uint16_t *) _ref_line;
102-
103-
for (j = 0; j < outw; j++)
104-
m2 += pow_2(main_line[j] - ref_line[j]);
105-
106-
return m2;
107-
}
108-
10985
typedef struct ThreadData {
11086
const uint8_t *main_data[4];
11187
const uint8_t *ref_data[4];
@@ -358,10 +334,7 @@ static int config_input_ref(AVFilterLink *inlink)
358334
}
359335
s->average_max = lrint(average_max);
360336

361-
s->dsp.sse_line = desc->comp[0].depth > 8 ? sse_line_16bit : sse_line_8bit;
362-
#if ARCH_X86
363-
ff_psnr_init_x86(&s->dsp, desc->comp[0].depth);
364-
#endif
337+
ff_psnr_init(&s->dsp, desc->comp[0].depth);
365338

366339
s->score = av_calloc(s->nb_threads, sizeof(*s->score));
367340
if (!s->score)

libavfilter/vf_xpsnr.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "drawutils.h"
3737
#include "filters.h"
3838
#include "framesync.h"
39+
#include "psnr.h"
3940
#include "xpsnr.h"
4041

4142
/* XPSNR structure definition */
@@ -68,7 +69,8 @@ typedef struct XPSNRContext {
6869
double sum_xpsnr [3];
6970
int and_is_inf[3];
7071
int is_rgb;
71-
PSNRDSPContext dsp;
72+
XPSNRDSPContext dsp;
73+
PSNRDSPContext pdsp;
7274
} XPSNRContext;
7375

7476
/* required macro definitions */
@@ -142,22 +144,6 @@ static uint64_t diff2nd(const uint32_t w_act, const uint32_t h_act, const int16_
142144
return (ta_act * XPSNR_GAMMA);
143145
}
144146

145-
static uint64_t sse_line_16bit(const uint8_t *blk_org8, const uint8_t *blk_rec8, int block_width)
146-
{
147-
const uint16_t *blk_org = (const uint16_t *) blk_org8;
148-
const uint16_t *blk_rec = (const uint16_t *) blk_rec8;
149-
uint64_t sse = 0; /* sum for one pixel line */
150-
151-
for (int x = 0; x < block_width; x++) {
152-
const int64_t error = (int64_t) blk_org[x] - (int64_t) blk_rec[x];
153-
154-
sse += error * error;
155-
}
156-
157-
/* sum of squared errors for the pixel line */
158-
return sse;
159-
}
160-
161147
static inline uint64_t calc_squared_error(XPSNRContext const *s,
162148
const int16_t *blk_org, const uint32_t stride_org,
163149
const int16_t *blk_rec, const uint32_t stride_rec,
@@ -166,7 +152,7 @@ static inline uint64_t calc_squared_error(XPSNRContext const *s,
166152
uint64_t sse = 0; /* sum of squared errors */
167153

168154
for (uint32_t y = 0; y < block_height; y++) {
169-
sse += s->dsp.sse_line((const uint8_t *) blk_org, (const uint8_t *) blk_rec, (int) block_width);
155+
sse += s->pdsp.sse_line((const uint8_t *) blk_org, (const uint8_t *) blk_rec, (int) block_width);
170156
blk_org += stride_org;
171157
blk_rec += stride_rec;
172158
}
@@ -609,13 +595,11 @@ static int config_input_ref(AVFilterLink *inlink)
609595
s->plane_height[1] = s->plane_height[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
610596
s->plane_height[0] = s->plane_height[3] = inlink->h;
611597

612-
s->dsp.sse_line = sse_line_16bit;
598+
/* XPSNR always operates with 16-bit internal precision */
599+
ff_psnr_init(&s->pdsp, 15);
613600
s->dsp.highds_func = highds; /* initialize filtering methods */
614601
s->dsp.diff1st_func = diff1st;
615602
s->dsp.diff2nd_func = diff2nd;
616-
#if ARCH_X86
617-
ff_xpsnr_init_x86(&s->dsp, 15); /* initialize x86 SSE method */
618-
#endif
619603

620604
return 0;
621605
}

libavfilter/x86/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose_init.o
4040
OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume_init.o
4141
OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360_init.o
4242
OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif_init.o
43-
OBJS-$(CONFIG_XPSNR_FILTER) += x86/vf_xpsnr_init.o
43+
OBJS-$(CONFIG_XPSNR_FILTER) += x86/vf_psnr_init.o
4444
OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif_init.o
4545

4646
X86ASM-OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad.o
@@ -85,4 +85,5 @@ X86ASM-OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose.o
8585
X86ASM-OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume.o
8686
X86ASM-OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360.o
8787
X86ASM-OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif.o
88+
X86ASM-OBJS-$(CONFIG_XPSNR_FILTER) += x86/vf_psnr.o
8889
X86ASM-OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif.o x86/yadif-16.o x86/yadif-10.o

libavfilter/x86/vf_xpsnr_init.c

Lines changed: 0 additions & 43 deletions
This file was deleted.

libavfilter/xpsnr.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@
3737
/* public XPSNR DSP structure definition */
3838

3939
typedef struct XPSNRDSPContext {
40-
uint64_t (*sse_line) (const uint8_t *buf, const uint8_t *ref, const int w);
4140
uint64_t (*highds_func) (const int x_act, const int y_act, const int w_act, const int h_act, const int16_t *o_m0, const int o);
4241
uint64_t (*diff1st_func)(const uint32_t w_act, const uint32_t h_act, const int16_t *o_m0, int16_t *o_m1, const int o);
4342
uint64_t (*diff2nd_func)(const uint32_t w_act, const uint32_t h_act, const int16_t *o_m0, int16_t *o_m1, int16_t *o_m2, const int o);
44-
} PSNRDSPContext;
45-
46-
void ff_xpsnr_init_x86(PSNRDSPContext *dsp, const int bpp);
43+
} XPSNRDSPContext;
4744

4845
#endif /* AVFILTER_XPSNR_H */

0 commit comments

Comments
 (0)