[PR] [release/9.0] avcodec/pthread_frame: sync decoded side data to all worker threads (PR #24150)

ffmpeg-devel via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178671158182.59.9110723474987638715@29965ddac10e>
PR #24150 opened by ffmpeg-devel
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24150
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24150.patch

**Backport:** https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23989

Previously only the first thread's context and the user-facing one had
it, so frames decoded by the remaining worker threads were missing
global side data whenever the per-frame state could not provide it, e.g.
extradata-derived HDR metadata after avcodec_flush_buffers().


From eee63b86fae4a719ad83a1ccb8856bf464512ab4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Sun, 2 Aug 2026 22:22:58 +0200
Subject: [PATCH] avcodec/pthread_frame: sync decoded side data to all worker
 threads
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously only the first thread's context and the user-facing one had
it, so frames decoded by the remaining worker threads were missing
global side data whenever the per-frame state could not provide it, e.g.
extradata-derived HDR metadata after avcodec_flush_buffers().

Signed-off-by: Kacper Michajłow <[email protected]>
(cherry picked from commit c48230eb86ff02246f6a14fa1475a0d9398363b4)
---
 libavcodec/pthread_frame.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index e6dcc23c15..1814ab2768 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -882,17 +882,18 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free,
     }
     p->thread_init = NEEDS_CLOSE;
 
-    if (first) {
+    if (first)
         update_context_from_thread(avctx, copy, 1);
 
-        av_frame_side_data_free(&avctx->decoded_side_data, &avctx->nb_decoded_side_data);
-        for (int i = 0; i < copy->nb_decoded_side_data; i++) {
-            err = av_frame_side_data_clone(&avctx->decoded_side_data,
-                                           &avctx->nb_decoded_side_data,
-                                           copy->decoded_side_data[i], 0);
-            if (err < 0)
-                return err;
-        }
+    const AVCodecContext *src = first ? copy : avctx;
+    AVCodecContext       *dst = first ? avctx : copy;
+    av_frame_side_data_free(&dst->decoded_side_data, &dst->nb_decoded_side_data);
+    for (int i = 0; i < src->nb_decoded_side_data; i++) {
+        err = av_frame_side_data_clone(&dst->decoded_side_data,
+                                       &dst->nb_decoded_side_data,
+                                       src->decoded_side_data[i], 0);
+        if (err < 0)
+            return err;
     }
 
     atomic_init(&p->debug_threads, (copy->debug & FF_DEBUG_THREADS) != 0);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.