[FFmpeg-cvslog] avcodec/vp9: Check initializing conditions/mutexes

Andreas Rheinhardt git at videolan.org
Sat Sep 4 10:26:08 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Sep  2 13:33:46 2021 +0200| [0e0906726133519c59a2234162df66f53d755de0] | committer: Andreas Rheinhardt

avcodec/vp9: Check initializing conditions/mutexes

Also don't destroy uninitialized conditions/mutexes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavcodec/vp9.c    | 17 +++++++++++------
 libavcodec/vp9dec.h |  1 +
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 5c20a7ec5d..239475cdbe 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -27,6 +27,8 @@
 #include "internal.h"
 #include "profiles.h"
 #include "thread.h"
+#include "pthread_internal.h"
+
 #include "videodsp.h"
 #include "vp56.h"
 #include "vp9.h"
@@ -39,6 +41,10 @@
 #define VP9_SYNCCODE 0x498342
 
 #if HAVE_THREADS
+DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt,
+                    (offsetof(VP9Context, progress_mutex)),
+                    (offsetof(VP9Context, progress_cond)));
+
 static void vp9_free_entries(AVCodecContext *avctx) {
     VP9Context *s = avctx->priv_data;
 
@@ -1248,10 +1254,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
     free_buffers(s);
     vp9_free_entries(avctx);
 #if HAVE_THREADS
-    if (avctx->active_thread_type & FF_THREAD_SLICE) {
-        pthread_mutex_destroy(&s->progress_mutex);
-        pthread_cond_destroy(&s->progress_cond);
-    }
+    ff_pthread_free(s, vp9_context_offsets);
 #endif
     av_freep(&s->td);
     return 0;
@@ -1794,14 +1797,16 @@ static void vp9_decode_flush(AVCodecContext *avctx)
 static av_cold int vp9_decode_init(AVCodecContext *avctx)
 {
     VP9Context *s = avctx->priv_data;
+    int ret;
 
     s->last_bpp = 0;
     s->s.h.filter.sharpness = -1;
 
 #if HAVE_THREADS
     if (avctx->active_thread_type & FF_THREAD_SLICE) {
-        pthread_mutex_init(&s->progress_mutex, NULL);
-        pthread_cond_init(&s->progress_cond, NULL);
+        ret = ff_pthread_init(s, vp9_context_offsets);
+        if (ret < 0)
+            return ret;
     }
 #endif
 
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index d82b258a3d..9cbd5839a8 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -105,6 +105,7 @@ typedef struct VP9Context {
     pthread_mutex_t progress_mutex;
     pthread_cond_t progress_cond;
     atomic_int *entries;
+    unsigned pthread_init_cnt;
 #endif
 
     uint8_t ss_h, ss_v;



More information about the ffmpeg-cvslog mailing list