[vlc-devel] [RFC PATCH 4/4] avocodec: flush buffers in case of mt

Thomas Guillem thomas at gllm.fr
Tue Nov 17 16:16:35 CET 2015


The NOTE in comment is not good with multi-threading activated. Indeed, after a
flush, when mt was on, pf_decode could return old pictures from before the
flush.
---
 modules/codec/avcodec/video.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 1b98c5c..0a7a4b6 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -533,17 +533,17 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
             p_sys->i_pts = VLC_TS_INVALID; /* To make sure we recover properly */
 
             p_sys->i_late_frames = 0;
-#if 0
-            /* NOTE: data is good only the timeline changed so do not flush decoder */
-            post_mt( p_sys );
-            if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
+            /* NOTE: when using one thread, data is good, only the timeline
+             * changed so do not flush decoder */
+            if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY
+             && p_context->thread_count > 1 )
             {
+                post_mt( p_sys );
                 p_sys->b_flushing_buffers = true;
                 avcodec_flush_buffers( p_context );
                 p_sys->b_flushing_buffers = false;
+                wait_mt( p_sys );
             }
-            wait_mt( p_sys );
-#endif
             if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
             {
                 block_Release( p_block );
-- 
2.1.4



More information about the vlc-devel mailing list