[FFmpeg-cvslog] lavc/hevcdec: track local context count separately from WPP thread count

Anton Khirnov git at videolan.org
Fri May 31 20:32:29 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Apr  7 11:49:04 2024 +0200| [25ce44efa5f199e4ee0ed47985801077c203e7d8] | committer: Anton Khirnov

lavc/hevcdec: track local context count separately from WPP thread count

The latter can be lowered while decoding, which would lead to memleaks.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=25ce44efa5f199e4ee0ed47985801077c203e7d8
---

 libavcodec/hevcdec.c | 7 +++++--
 libavcodec/hevcdec.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 79dc1c98de..e84f45e3f8 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2697,11 +2697,13 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
     }
 
     for (i = 1; i < s->threads_number; i++) {
-        if (s->local_ctx[i])
+        if (i < s->nb_local_ctx)
             continue;
         s->local_ctx[i] = av_mallocz(sizeof(HEVCLocalContext));
         if (!s->local_ctx[i])
             return AVERROR(ENOMEM);
+        s->nb_local_ctx++;
+
         s->local_ctx[i]->logctx = s->avctx;
         s->local_ctx[i]->parent = s;
         s->local_ctx[i]->common_cabac_state = &s->cabac;
@@ -3473,7 +3475,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
     av_freep(&s->sh.size);
 
     if (s->local_ctx) {
-        for (i = 1; i < s->threads_number; i++) {
+        for (i = 1; i < s->nb_local_ctx; i++) {
             av_freep(&s->local_ctx[i]);
         }
     }
@@ -3502,6 +3504,7 @@ static av_cold int hevc_init_context(AVCodecContext *avctx)
     s->HEVClc->logctx = avctx;
     s->HEVClc->common_cabac_state = &s->cabac;
     s->local_ctx[0] = s->HEVClc;
+    s->nb_local_ctx = 1;
 
     s->output_frame = av_frame_alloc();
     if (!s->output_frame)
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 663f42a7ff..ca68fb54a7 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -446,6 +446,8 @@ typedef struct HEVCContext {
     AVCodecContext *avctx;
 
     HEVCLocalContext    **local_ctx;
+    unsigned           nb_local_ctx;
+
     HEVCLocalContext    *HEVClc;
 
     uint8_t             threads_type;



More information about the ffmpeg-cvslog mailing list