]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_libvmaf.c
vf_tonemap: Update hdr metadata with the new peak value
[ffmpeg] / libavfilter / vf_libvmaf.c
index dfe474c40cb2ad8a46f8407b468649a77548cb30..5d47a743757408626b129e1f37eb7ebc0ef7e710 100644 (file)
@@ -43,6 +43,7 @@ typedef struct LIBVMAFContext {
     int width;
     int height;
     double vmaf_score;
+    int vmaf_thread_created;
     pthread_t vmaf_thread;
     pthread_mutex_t lock;
     pthread_cond_t cond;
@@ -130,6 +131,8 @@ FRAMESYNC_DEFINE_CLASS(libvmaf, LIBVMAFContext, fs);
     \
     ret = !s->frame_set;                                                        \
     \
+    av_frame_unref(s->gref);                                                    \
+    av_frame_unref(s->gmain);                                                   \
     s->frame_set = 0;                                                           \
     \
     pthread_cond_signal(&s->cond);                                              \
@@ -226,6 +229,7 @@ static av_cold int init(AVFilterContext *ctx)
     s->gmain = av_frame_alloc();
     s->error = 0;
 
+    s->vmaf_thread_created = 0;
     pthread_mutex_init(&s->lock, NULL);
     pthread_cond_init (&s->cond, NULL);
 
@@ -273,6 +277,7 @@ static int config_input_ref(AVFilterLink *inlink)
         av_log(ctx, AV_LOG_ERROR, "Thread creation failed.\n");
         return AVERROR(EINVAL);
     }
+    s->vmaf_thread_created = 1;
 
     return 0;
 }
@@ -315,7 +320,11 @@ static av_cold void uninit(AVFilterContext *ctx)
     pthread_cond_signal(&s->cond);
     pthread_mutex_unlock(&s->lock);
 
-    pthread_join(s->vmaf_thread, NULL);
+    if (s->vmaf_thread_created)
+    {
+        pthread_join(s->vmaf_thread, NULL);
+        s->vmaf_thread_created = 0;
+    }
 
     av_frame_free(&s->gref);
     av_frame_free(&s->gmain);