[FFmpeg-devel] [PATCH] Clean up thread init/free code.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Aug 5 19:07:53 CEST 2013


Assert that the active thread type is one of the valid options.
Also do not try freeing thread state if threading is not
actually in use - this seems to fix an actual issue in the MPEG-4
decoder, at least when used by MPlayer, but I did not debug in detail.
---
 libavcodec/pthread.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 8329155..6fda0e6 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -1111,18 +1111,21 @@ int ff_thread_init(AVCodecContext *avctx)
 
     validate_thread_parameters(avctx);
 
-    if (avctx->active_thread_type&FF_THREAD_SLICE)
+    if (avctx->active_thread_type == FF_THREAD_SLICE)
         return thread_init_internal(avctx);
-    else if (avctx->active_thread_type&FF_THREAD_FRAME)
+    else if (avctx->active_thread_type == FF_THREAD_FRAME)
         return frame_thread_init(avctx);
+    av_assert0(avctx->active_thread_type == 0);
 
     return 0;
 }
 
 void ff_thread_free(AVCodecContext *avctx)
 {
-    if (avctx->active_thread_type&FF_THREAD_FRAME)
+    if (avctx->active_thread_type == FF_THREAD_SLICE)
+        thread_free(avctx);
+    else if (avctx->active_thread_type == FF_THREAD_FRAME)
         frame_thread_free(avctx, avctx->thread_count);
     else
-        thread_free(avctx);
+        av_assert0(avctx->active_thread_type == 0);
 }
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list