Skip to content

Commit 423b6a7

Browse files
committed
avutil/imgutils: Add wrapper for av_image_copy() to avoid casts
av_image_copy() accepts const uint8_t* const * as source; lots of user have uint8_t* const * and therefore either cast (the majority) or copy the array of pointers. This commit changes this by adding a static inline wrapper for av_image_copy() that casts between the two types so that we do not need to add casts everywhere else. Signed-off-by: Andreas Rheinhardt <[email protected]>
1 parent 5094d1f commit 423b6a7

22 files changed

+79
-68
lines changed

doc/APIchanges

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2023-02-09
22

33
API changes, most recent first:
44

5+
2023-09-07 - xxxxxxxxxx - lavu 58.24.100 - imgutils.h
6+
Add av_image_copy2(), a wrapper around the av_image_copy()
7+
to overcome limitations of automatic conversions.
8+
59
2023-09-07 - xxxxxxxxxx - lavu 58.23.100 - fifo.h
610
Constify the AVFifo pointees in av_fifo_peek() and av_fifo_peek_to_cb().
711

doc/examples/demux_decode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ static int output_video_frame(AVFrame *frame)
7878

7979
/* copy decoded frame to destination buffer:
8080
* this is required since rawvideo expects non aligned data */
81-
av_image_copy(video_dst_data, video_dst_linesize,
82-
(const uint8_t **)(frame->data), frame->linesize,
83-
pix_fmt, width, height);
81+
av_image_copy2(video_dst_data, video_dst_linesize,
82+
frame->data, frame->linesize,
83+
pix_fmt, width, height);
8484

8585
/* write to rawvideo file */
8686
fwrite(video_dst_data[0], 1, video_dst_bufsize, video_dst_file);

libavcodec/amfenc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
430430
dst_data[i] = plane->pVtbl->GetNative(plane);
431431
dst_linesize[i] = plane->pVtbl->GetHPitch(plane);
432432
}
433-
av_image_copy(dst_data, dst_linesize,
434-
(const uint8_t**)frame->data, frame->linesize, frame->format,
435-
avctx->width, avctx->height);
433+
av_image_copy2(dst_data, dst_linesize,
434+
frame->data, frame->linesize, frame->format,
435+
avctx->width, avctx->height);
436436

437437
return 0;
438438
}

libavcodec/libkvazaar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ static int libkvazaar_encode(AVCodecContext *avctx,
221221
frame->width / 2,
222222
0
223223
};
224-
av_image_copy(dst, dst_linesizes,
225-
(const uint8_t **)frame->data, frame->linesize,
226-
frame->format, frame->width, frame->height);
224+
av_image_copy2(dst, dst_linesizes,
225+
frame->data, frame->linesize,
226+
frame->format, frame->width, frame->height);
227227
}
228228

229229
input_pic->pts = frame->pts;

libavcodec/libopenh264dec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ static int svc_decode_frame(AVCodecContext *avctx, AVFrame *avframe,
141141
linesize[0] = info.UsrData.sSystemBuffer.iStride[0];
142142
linesize[1] = linesize[2] = info.UsrData.sSystemBuffer.iStride[1];
143143
linesize[3] = 0;
144-
av_image_copy(avframe->data, avframe->linesize, (const uint8_t **) ptrs, linesize, avctx->pix_fmt, avctx->width, avctx->height);
144+
av_image_copy2(avframe->data, avframe->linesize, ptrs, linesize,
145+
avctx->pix_fmt, avctx->width, avctx->height);
145146

146147
avframe->pts = info.uiOutYuvTimeStamp;
147148
avframe->pkt_dts = AV_NOPTS_VALUE;

libavcodec/libvpxdec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ static int vpx_decode(AVCodecContext *avctx, AVFrame *picture,
329329
} else {
330330
if ((ret = ff_get_buffer(avctx, picture, 0)) < 0)
331331
return ret;
332-
av_image_copy(picture->data, picture->linesize, (const uint8_t**)planes,
333-
linesizes, avctx->pix_fmt, img->d_w, img->d_h);
332+
av_image_copy2(picture->data, picture->linesize, planes,
333+
linesizes, avctx->pix_fmt, img->d_w, img->d_h);
334334
}
335335
*got_frame = 1;
336336
}

libavcodec/mediacodecenc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,6 @@ static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, ui
428428
MediaCodecEncContext *s = avctx->priv_data;
429429
uint8_t *dst_data[4] = {};
430430
int dst_linesize[4] = {};
431-
const uint8_t *src_data[4] = {
432-
frame->data[0], frame->data[1], frame->data[2], frame->data[3]
433-
};
434431

435432
if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
436433
dst_data[0] = dst;
@@ -449,8 +446,8 @@ static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, ui
449446
av_assert0(0);
450447
}
451448

452-
av_image_copy(dst_data, dst_linesize, src_data, frame->linesize,
453-
avctx->pix_fmt, avctx->width, avctx->height);
449+
av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
450+
avctx->pix_fmt, avctx->width, avctx->height);
454451
}
455452

456453
static int mediacodec_send(AVCodecContext *avctx,

libavcodec/mmaldec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ static int ffmal_copy_frame(AVCodecContext *avctx, AVFrame *frame,
648648
av_image_fill_arrays(src, linesize,
649649
buffer->data + buffer->type->video.offset[0],
650650
avctx->pix_fmt, w, h, 1);
651-
av_image_copy(frame->data, frame->linesize, (const uint8_t **)src, linesize,
652-
avctx->pix_fmt, avctx->width, avctx->height);
651+
av_image_copy2(frame->data, frame->linesize, src, linesize,
652+
avctx->pix_fmt, avctx->width, avctx->height);
653653
}
654654

655655
frame->sample_aspect_ratio = avctx->sample_aspect_ratio;

libavcodec/nuv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static void copy_frame(AVFrame *f, const uint8_t *src, int width, int height)
5656
int src_linesize[4];
5757
av_image_fill_arrays(src_data, src_linesize, src,
5858
f->format, width, height, 1);
59-
av_image_copy(f->data, f->linesize, (const uint8_t **)src_data, src_linesize,
60-
f->format, width, height);
59+
av_image_copy2(f->data, f->linesize, src_data, src_linesize,
60+
f->format, width, height);
6161
}
6262

6363
/**

libavcodec/nvenc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,9 +2008,9 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *nv_surface,
20082008
if (frame->format == AV_PIX_FMT_YUV420P)
20092009
FFSWAP(uint8_t*, dst_data[1], dst_data[2]);
20102010

2011-
av_image_copy(dst_data, dst_linesize,
2012-
(const uint8_t**)frame->data, frame->linesize, frame->format,
2013-
avctx->width, avctx->height);
2011+
av_image_copy2(dst_data, dst_linesize,
2012+
frame->data, frame->linesize, frame->format,
2013+
avctx->width, avctx->height);
20142014

20152015
return 0;
20162016
}

0 commit comments

Comments
 (0)