[FFmpeg-cvslog] ffplay: close streams and AVFormatContext in the main thread

Marton Balint git at videolan.org
Mon Oct 12 00:13:28 CEST 2015


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Fri Feb  6 01:37:53 2015 +0100| [4ce75387cdcbcef8afbaadc5b66232c25178c0c6] | committer: Marton Balint

ffplay: close streams and AVFormatContext in the main thread

To avoid race conditions.

Signed-off-by: Marton Balint <cus at passwd.hu>

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

 ffplay.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 79f430d..7f73664 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1132,11 +1132,24 @@ static void video_audio_display(VideoState *s)
     }
 }
 
+static void stream_component_close(VideoState *is, int stream_index);
+
 static void stream_close(VideoState *is)
 {
     /* XXX: use a special url_shutdown call to abort parse cleanly */
     is->abort_request = 1;
     SDL_WaitThread(is->read_tid, NULL);
+
+    /* close each stream */
+    if (is->audio_stream >= 0)
+        stream_component_close(is, is->audio_stream);
+    if (is->video_stream >= 0)
+        stream_component_close(is, is->video_stream);
+    if (is->subtitle_stream >= 0)
+        stream_component_close(is, is->subtitle_stream);
+
+    avformat_close_input(&is->ic);
+
     packet_queue_destroy(&is->videoq);
     packet_queue_destroy(&is->audioq);
     packet_queue_destroy(&is->subtitleq);
@@ -3111,24 +3124,11 @@ static int read_thread(void *arg)
             av_free_packet(pkt);
         }
     }
-    /* wait until the end */
-    while (!is->abort_request) {
-        SDL_Delay(100);
-    }
 
     ret = 0;
  fail:
-    /* close each stream */
-    if (is->audio_stream >= 0)
-        stream_component_close(is, is->audio_stream);
-    if (is->video_stream >= 0)
-        stream_component_close(is, is->video_stream);
-    if (is->subtitle_stream >= 0)
-        stream_component_close(is, is->subtitle_stream);
-    if (ic) {
+    if (ic && !is->ic)
         avformat_close_input(&ic);
-        is->ic = NULL;
-    }
 
     if (ret != 0) {
         SDL_Event event;



More information about the ffmpeg-cvslog mailing list