Set thread_count in the decoder before to open it.
authorStefano Sabatini <stefano.sabatini-lala@poste.it>
Mon, 28 Dec 2009 21:49:56 +0000 (21:49 +0000)
committerStefano Sabatini <stefano.sabatini-lala@poste.it>
Mon, 28 Dec 2009 21:49:56 +0000 (21:49 +0000)
This is safer since avcodec_open() may initialize some structure using
the thread_count default value which will be changed later, causing
potential security / stability issues.

Also do not explicitely set the thread_count value in the decoder,
since this is already done by avcodec_thread_init().

See the thread:
"[FFmpeg-devel] [PATCH] Make ffplay define in the encoder the number of threads *before* to open it",
started in date 2008-03-08.

Originally committed as revision 20954 to svn://svn.ffmpeg.org/ffmpeg/trunk

ffplay.c

index df9958e..dc83031 100644 (file)
--- a/ffplay.c
+++ b/ffplay.c
@@ -1722,6 +1722,8 @@ static int stream_component_open(VideoState *is, int stream_index)
     enc->skip_loop_filter= skip_loop_filter;
     enc->error_recognition= error_recognition;
     enc->error_concealment= error_concealment;
+    if (thread_count > 1)
+        avcodec_thread_init(enc, thread_count);
 
     set_context_opts(enc, avcodec_opts[enc->codec_type], 0);
 
@@ -1746,9 +1748,6 @@ static int stream_component_open(VideoState *is, int stream_index)
         is->audio_src_fmt= SAMPLE_FMT_S16;
     }
 
-    if(thread_count>1)
-        avcodec_thread_init(enc, thread_count);
-    enc->thread_count= thread_count;
     ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
     switch(enc->codec_type) {
     case CODEC_TYPE_AUDIO: