]> git.sesse.net Git - ffmpeg/blobdiff - ffplay.c
flv dropable p frame support
[ffmpeg] / ffplay.c
index c5c2ca13490fe7d695db2687cabbf3e89bfded11..135b7823caca2cd0f7cd1f5f414634bf8f301620 100644 (file)
--- a/ffplay.c
+++ b/ffplay.c
@@ -168,6 +168,7 @@ static int64_t start_time = AV_NOPTS_VALUE;
 static int debug = 0;
 static int debug_mv = 0;
 static int step = 0;
+static int thread_count = 1;
 
 /* current context */
 static int is_full_screen;
@@ -913,8 +914,8 @@ static int video_thread(void *arg)
             len1 = avcodec_decode_video(&is->video_st->codec, 
                                         frame, &got_picture, 
                                         pkt->data, pkt->size);
-            if (len1 < 0)
-                break;
+//            if (len1 < 0)
+//                break;
             if (got_picture) {
                 if (output_picture2(is, frame, pts) < 0)
                     goto the_end;
@@ -1166,9 +1167,16 @@ static int stream_component_open(VideoState *is, int stream_index)
     }
 
     codec = avcodec_find_decoder(enc->codec_id);
+    enc->debug_mv = debug_mv;
+    enc->debug = debug;
     if (!codec ||
         avcodec_open(enc, codec) < 0)
         return -1;
+#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
+    if(thread_count>1)
+        avcodec_thread_init(enc, thread_count);
+#endif
+    enc->thread_count= thread_count;
     switch(enc->codec_type) {
     case CODEC_TYPE_AUDIO:
         is->audio_stream = stream_index;
@@ -1197,8 +1205,6 @@ static int stream_component_open(VideoState *is, int stream_index)
 
         packet_queue_init(&is->videoq);
         is->video_tid = SDL_CreateThread(video_thread, is);
-        enc->debug = debug;
-        enc->debug_mv = debug_mv;
         break;
     default:
         break;
@@ -1406,22 +1412,25 @@ static int decode_thread(void *arg)
 #endif
         if (is->seek_req) {
             /* XXX: must lock decoder threads */
-            if (is->audio_stream >= 0) {
-                packet_queue_flush(&is->audioq);
-            }
-            if (is->video_stream >= 0) {
-                packet_queue_flush(&is->videoq);
-            }
             ret = av_seek_frame(is->ic, -1, is->seek_pos);
             if (ret < 0) {
                 fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
+            }else{
+                if (is->audio_stream >= 0) {
+                    packet_queue_flush(&is->audioq);
+                }
+                if (is->video_stream >= 0) {
+                    packet_queue_flush(&is->videoq);
+                    avcodec_flush_buffers(&ic->streams[video_index]->codec);
+                }
             }
             is->seek_req = 0;
         }
 
         /* if the queue are full, no need to read more */
         if (is->audioq.size > MAX_AUDIOQ_SIZE ||
-            is->videoq.size > MAX_VIDEOQ_SIZE) {
+            is->videoq.size > MAX_VIDEOQ_SIZE || 
+            url_feof(&ic->pb)) {
             /* wait 10 ms */
             SDL_Delay(10);
             continue;
@@ -1790,6 +1799,14 @@ static void opt_vismv(const char *arg)
 {
     debug_mv = atoi(arg);
 }
+
+static void opt_thread_count(const char *arg)
+{
+    thread_count= atoi(arg);
+#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
+    fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
+#endif
+}
     
 const OptionDef options[] = {
     { "h", 0, {(void*)show_help}, "show help" },    
@@ -1811,7 +1828,8 @@ const OptionDef options[] = {
 #ifdef CONFIG_NETWORK
     { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
 #endif
-    { "sync", HAS_ARG | OPT_EXPERT, {(void*)&opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
+    { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
+    { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
     { NULL, },
 };