aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-01-24 17:44:59 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-01-28 10:52:24 +0100
commit916f01674178b0949b8d432b0d192169cc98b733 (patch)
treeb632acc7fda48008fdf1fb278a8ca783d04c9955 /libavcodec
parent555879ca7cf50f265c4beae365cc5142f3eb660e (diff)
downloadffmpeg-916f01674178b0949b8d432b0d192169cc98b733.tar.gz
avcodec/dxvenc: Fix data races with slice threading
The old code set a common struct from each thread; this only "worked" (but is still UB) because the values written are the same for each thread. Fix this by moving the assignments to the main thread. (This also avoids casting const away from a const AVFrame*.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/dxvenc.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 10473038cc..94e522d72b 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -130,25 +130,6 @@ typedef struct DXVEncContext {
HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
} DXVEncContext;
-static int compress_texture_thread(AVCodecContext *avctx, void *arg,
- int slice, int thread_nb)
-{
- DXVEncContext *ctx = avctx->priv_data;
- AVFrame *frame = arg;
-
- if (ctx->enc.tex_funct) {
- ctx->enc.tex_data.out = ctx->tex_data;
- ctx->enc.frame_data.in = frame->data[0];
- ctx->enc.stride = frame->linesize[0];
- return ff_texturedsp_compress_thread(avctx, &ctx->enc, slice, thread_nb);
- } else {
- /* unimplemented: YCoCg formats */
- return AVERROR_INVALIDDATA;
- }
-
- return 0;
-}
-
/* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
* Inverse of CHECKPOINT in dxv.c. */
#define PUSH_OP(x) \
@@ -252,7 +233,15 @@ static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt,
if (ret < 0)
return ret;
- avctx->execute2(avctx, compress_texture_thread, (void*)frame, NULL, ctx->enc.slice_count);
+ if (ctx->enc.tex_funct) {
+ ctx->enc.tex_data.out = ctx->tex_data;
+ ctx->enc.frame_data.in = frame->data[0];
+ ctx->enc.stride = frame->linesize[0];
+ avctx->execute2(avctx, ff_texturedsp_compress_thread, &ctx->enc, NULL, ctx->enc.slice_count);
+ } else {
+ /* unimplemented: YCoCg formats */
+ return AVERROR_INVALIDDATA;
+ }
bytestream2_init_writer(pbc, pkt->data, pkt->size);