avcodec/mpegvideoencdsp: convert stride parameters from int to ptrdiff_t

This commit is contained in:
Ramiro Polla 2024-08-26 15:59:45 +02:00
parent 7753a9d627
commit 6aafe61285
12 changed files with 53 additions and 49 deletions

View File

@ -24,11 +24,11 @@
#include "libavcodec/mpegvideoencdsp.h"
#include "config.h"
int ff_pix_sum16_neon(const uint8_t *pix, int line_size);
int ff_pix_norm1_neon(const uint8_t *pix, int line_size);
int ff_pix_sum16_neon(const uint8_t *pix, ptrdiff_t line_size);
int ff_pix_norm1_neon(const uint8_t *pix, ptrdiff_t line_size);
#if HAVE_DOTPROD
int ff_pix_norm1_neon_dotprod(const uint8_t *pix, int line_size);
int ff_pix_norm1_neon_dotprod(const uint8_t *pix, ptrdiff_t line_size);
#endif
av_cold void ff_mpegvideoencdsp_init_aarch64(MpegvideoEncDSPContext *c,

View File

@ -22,9 +22,8 @@
function ff_pix_sum16_neon, export=1
// x0 const uint8_t *pix
// x1 int line_size
// x1 ptrdiff_t line_size
sxtw x1, w1
add x2, x0, x1
lsl x1, x1, #1
movi v0.16b, #0
@ -46,9 +45,8 @@ endfunc
function ff_pix_norm1_neon, export=1
// x0 const uint8_t *pix
// x1 int line_size
// x1 ptrdiff_t line_size
sxtw x1, w1
movi v0.16b, #0
mov w2, #16
@ -72,9 +70,8 @@ ENABLE_DOTPROD
function ff_pix_norm1_neon_dotprod, export=1
// x0 const uint8_t *pix
// x1 int line_size
// x1 ptrdiff_t line_size
sxtw x1, w1
movi v0.16b, #0
mov w2, #16

View File

@ -24,8 +24,8 @@
#include "libavcodec/avcodec.h"
#include "libavcodec/mpegvideoencdsp.h"
int ff_pix_norm1_armv6(const uint8_t *pix, int line_size);
int ff_pix_sum_armv6(const uint8_t *pix, int line_size);
int ff_pix_norm1_armv6(const uint8_t *pix, ptrdiff_t line_size);
int ff_pix_sum_armv6(const uint8_t *pix, ptrdiff_t line_size);
av_cold void ff_mpegvideoencdsp_init_arm(MpegvideoEncDSPContext *c,
AVCodecContext *avctx)

View File

@ -31,6 +31,6 @@ void ff_dct_unquantize_h263_inter_msa(MpegEncContext *s, int16_t *block,
int32_t index, int32_t q_scale);
void ff_dct_unquantize_h263_intra_msa(MpegEncContext *s, int16_t *block,
int32_t index, int32_t q_scale);
int ff_pix_sum_msa(const uint8_t *pix, int line_size);
int ff_pix_sum_msa(const uint8_t *pix, ptrdiff_t line_size);
#endif // #ifndef AVCODEC_MIPS_H263DSP_MIPS_H

View File

@ -56,7 +56,7 @@ static int32_t sum_u8src_16width_msa(const uint8_t *src, int32_t stride)
return sum;
}
int ff_pix_sum_msa(const uint8_t *pix, int line_size)
int ff_pix_sum_msa(const uint8_t *pix, ptrdiff_t line_size)
{
return sum_u8src_16width_msa(pix, line_size);
}

View File

@ -57,7 +57,7 @@ static void add_8x8basis_c(int16_t rem[64], const int16_t basis[64], int scale)
(BASIS_SHIFT - RECON_SHIFT);
}
static int pix_sum_c(const uint8_t *pix, int line_size)
static int pix_sum_c(const uint8_t *pix, ptrdiff_t line_size)
{
int s = 0, i, j;
@ -78,7 +78,7 @@ static int pix_sum_c(const uint8_t *pix, int line_size)
return s;
}
static int pix_norm1_c(const uint8_t *pix, int line_size)
static int pix_norm1_c(const uint8_t *pix, ptrdiff_t line_size)
{
int s = 0, i, j;
const uint32_t *sq = ff_square_tab + 256;
@ -114,7 +114,7 @@ static int pix_norm1_c(const uint8_t *pix, int line_size)
return s;
}
static av_always_inline void draw_edges_lr(uint8_t *ptr, int wrap, int width, int height, int w)
static av_always_inline void draw_edges_lr(uint8_t *ptr, ptrdiff_t wrap, int width, int height, int w)
{
for (int i = 0; i < height; i++) {
memset(ptr - w, ptr[0], w);
@ -125,7 +125,7 @@ static av_always_inline void draw_edges_lr(uint8_t *ptr, int wrap, int width, in
/* draw the edges of width 'w' of an image of size width, height */
// FIXME: Check that this is OK for MPEG-4 interlaced.
static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
static void draw_edges_8_c(uint8_t *buf, ptrdiff_t wrap, int width, int height,
int w, int h, int sides)
{
uint8_t *last_line;
@ -154,9 +154,18 @@ static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
}
/* This wrapper function only serves to convert the stride parameters
* from ptrdiff_t to int for av_image_copy_plane(). */
static void copy_plane_wrapper(uint8_t *dst, ptrdiff_t dst_wrap,
const uint8_t *src, ptrdiff_t src_wrap,
int width, int height)
{
av_image_copy_plane(dst, dst_wrap, src, src_wrap, width, height);
}
/* 2x2 -> 1x1 */
static void shrink22(uint8_t *dst, int dst_wrap,
const uint8_t *src, int src_wrap,
static void shrink22(uint8_t *dst, ptrdiff_t dst_wrap,
const uint8_t *src, ptrdiff_t src_wrap,
int width, int height)
{
int w;
@ -188,8 +197,8 @@ static void shrink22(uint8_t *dst, int dst_wrap,
}
/* 4x4 -> 1x1 */
static void shrink44(uint8_t *dst, int dst_wrap,
const uint8_t *src, int src_wrap,
static void shrink44(uint8_t *dst, ptrdiff_t dst_wrap,
const uint8_t *src, ptrdiff_t src_wrap,
int width, int height)
{
int w;
@ -219,8 +228,8 @@ static void shrink44(uint8_t *dst, int dst_wrap,
}
/* 8x8 -> 1x1 */
static void shrink88(uint8_t *dst, int dst_wrap,
const uint8_t *src, int src_wrap,
static void shrink88(uint8_t *dst, ptrdiff_t dst_wrap,
const uint8_t *src, ptrdiff_t src_wrap,
int width, int height)
{
int w, i;
@ -247,7 +256,7 @@ av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
c->try_8x8basis = try_8x8basis_c;
c->add_8x8basis = add_8x8basis_c;
c->shrink[0] = av_image_copy_plane;
c->shrink[0] = copy_plane_wrapper;
c->shrink[1] = shrink22;
c->shrink[2] = shrink44;
c->shrink[3] = shrink88;

View File

@ -34,13 +34,13 @@ typedef struct MpegvideoEncDSPContext {
const int16_t basis[64], int scale);
void (*add_8x8basis)(int16_t rem[64], const int16_t basis[64], int scale);
int (*pix_sum)(const uint8_t *pix, int line_size);
int (*pix_norm1)(const uint8_t *pix, int line_size);
int (*pix_sum)(const uint8_t *pix, ptrdiff_t line_size);
int (*pix_norm1)(const uint8_t *pix, ptrdiff_t line_size);
void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
int src_wrap, int width, int height);
void (*shrink[4])(uint8_t *dst, ptrdiff_t dst_wrap, const uint8_t *src,
ptrdiff_t src_wrap, int width, int height);
void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
void (*draw_edges)(uint8_t *buf, ptrdiff_t wrap, int width, int height,
int w, int h, int sides);
} MpegvideoEncDSPContext;

View File

@ -30,7 +30,7 @@
#if HAVE_ALTIVEC
#if HAVE_VSX
static int pix_norm1_altivec(const uint8_t *pix, int line_size)
static int pix_norm1_altivec(const uint8_t *pix, ptrdiff_t line_size)
{
int i, s = 0;
const vector unsigned int zero =
@ -57,7 +57,7 @@ static int pix_norm1_altivec(const uint8_t *pix, int line_size)
return s;
}
#else
static int pix_norm1_altivec(const uint8_t *pix, int line_size)
static int pix_norm1_altivec(const uint8_t *pix, ptrdiff_t line_size)
{
int i, s = 0;
const vector unsigned int zero =
@ -87,7 +87,7 @@ static int pix_norm1_altivec(const uint8_t *pix, int line_size)
#endif /* HAVE_VSX */
#if HAVE_VSX
static int pix_sum_altivec(const uint8_t *pix, int line_size)
static int pix_sum_altivec(const uint8_t *pix, ptrdiff_t line_size)
{
int i, s;
const vector unsigned int zero =
@ -115,7 +115,7 @@ static int pix_sum_altivec(const uint8_t *pix, int line_size)
return s;
}
#else
static int pix_sum_altivec(const uint8_t *pix, int line_size)
static int pix_sum_altivec(const uint8_t *pix, ptrdiff_t line_size)
{
int i, s;
const vector unsigned int zero =

View File

@ -26,8 +26,8 @@
int ff_try_8x8basis_rvv(const int16_t rem[64], const int16_t weight[64],
const int16_t basis[16], int scale);
void ff_add_8x8basis_rvv(int16_t rem[64], const int16_t basis[16], int scale);
int ff_pix_sum_rvv(const uint8_t *pix, int line_size);
int ff_pix_norm1_rvv(const uint8_t *pix, int line_size);
int ff_pix_sum_rvv(const uint8_t *pix, ptrdiff_t line_size);
int ff_pix_norm1_rvv(const uint8_t *pix, ptrdiff_t line_size);
av_cold void ff_mpegvideoencdsp_init_riscv(MpegvideoEncDSPContext *c,
AVCodecContext *avctx)

View File

@ -24,12 +24,11 @@
%include "libavutil/x86/x86util.asm"
SECTION .text
; int ff_pix_sum16(const uint8_t *pix, int line_size)
; int ff_pix_sum16(const uint8_t *pix, ptrdiff_t line_size)
; %1 = number of loops
; %2 = number of GPRs used
%macro PIX_SUM16 3
cglobal pix_sum16, 2, %2, 6
movsxdifnidn r1, r1d
mov r2, %1
lea r3, [r1*3]
%if notcpuflag(xop)
@ -72,12 +71,11 @@ INIT_XMM xop
PIX_SUM16 4, 4, 4
%endif
; int ff_pix_norm1(const uint8_t *pix, int line_size)
; int ff_pix_norm1(const uint8_t *pix, ptrdiff_t line_size)
; %1 = number of xmm registers used
; %2 = number of loops
%macro PIX_NORM1 2
cglobal pix_norm1, 2, 3, %1
movsxdifnidn r1, r1d
mov r2, %2
pxor m0, m0
pxor m5, m5

View File

@ -23,9 +23,9 @@
#include "libavcodec/avcodec.h"
#include "libavcodec/mpegvideoencdsp.h"
int ff_pix_sum16_sse2(const uint8_t *pix, int line_size);
int ff_pix_sum16_xop(const uint8_t *pix, int line_size);
int ff_pix_norm1_sse2(const uint8_t *pix, int line_size);
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);
#if HAVE_INLINE_ASM
@ -96,7 +96,7 @@ int ff_pix_norm1_sse2(const uint8_t *pix, int line_size);
#endif /* HAVE_SSSE3_INLINE */
/* Draw the edges of width 'w' of an image of size width, height */
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
static void draw_edges_mmx(uint8_t *buf, ptrdiff_t wrap, int width, int height,
int w, int h, int sides)
{
uint8_t *ptr, *last_line;

View File

@ -34,7 +34,7 @@ static void check_pix_sum(MpegvideoEncDSPContext *c)
{
LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
declare_func(int, const uint8_t *pix, int line_size);
declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
randomize_buffers(src, 16 * 16);
@ -43,7 +43,7 @@ static void check_pix_sum(MpegvideoEncDSPContext *c)
if (check_func(c->pix_sum, "pix_sum%s", negstride_str)) {
int sum0, sum1;
const uint8_t *pix = src + (n ? (15 * 16) : 0);
int line_size = 16 * (n ? -1 : 1);
ptrdiff_t line_size = 16 * (n ? -1 : 1);
sum0 = call_ref(pix, line_size);
sum1 = call_new(pix, line_size);
if (sum0 != sum1)
@ -57,7 +57,7 @@ static void check_pix_norm1(MpegvideoEncDSPContext *c)
{
LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
declare_func(int, const uint8_t *pix, int line_size);
declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
randomize_buffers(src, 16 * 16);
@ -66,7 +66,7 @@ static void check_pix_norm1(MpegvideoEncDSPContext *c)
if (check_func(c->pix_norm1, "pix_norm1%s", negstride_str)) {
int sum0, sum1;
const uint8_t *pix = src + (n ? (15 * 16) : 0);
int line_size = 16 * (n ? -1 : 1);
ptrdiff_t line_size = 16 * (n ? -1 : 1);
sum0 = call_ref(pix, line_size);
sum1 = call_new(pix, line_size);
if (sum0 != sum1)
@ -88,7 +88,7 @@ static void check_draw_edges(MpegvideoEncDSPContext *c)
LOCAL_ALIGNED_16(uint8_t, buf0, [BUFSIZE]);
LOCAL_ALIGNED_16(uint8_t, buf1, [BUFSIZE]);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *buf, int wrap, int width, int height,
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *buf, ptrdiff_t wrap, int width, int height,
int w, int h, int sides);
for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
@ -96,7 +96,7 @@ static void check_draw_edges(MpegvideoEncDSPContext *c)
int negstride = input_size < 0;
const char *negstride_str = negstride ? "_negstride" : "";
int width = FFABS(input_size);
int linesize = EDGE_WIDTH + width + EDGE_WIDTH;
ptrdiff_t linesize = EDGE_WIDTH + width + EDGE_WIDTH;
/* calculate height based on specified width to use the entire buffer. */
int height = (BUFSIZE / linesize) - (2 * EDGE_WIDTH);
uint8_t *dst0 = buf0 + EDGE_WIDTH * linesize + EDGE_WIDTH;