]> git.sesse.net Git - ffmpeg/blobdiff - ffplay.c
clear internal queue when seeking
[ffmpeg] / ffplay.c
index f13c85d2ca2964ff68948746b509f0ea6a242273..cc4e853440d491e889c1c4f5d85a564d02826567 100644 (file)
--- a/ffplay.c
+++ b/ffplay.c
@@ -22,6 +22,8 @@
 #include <math.h>
 #include <limits.h>
 #include "avformat.h"
+#include "avdevice.h"
+#include "rtsp.h"
 #include "swscale.h"
 #include "avstring.h"
 
@@ -37,6 +39,9 @@
 
 #undef exit
 
+static const char program_name[] = "FFplay";
+static const int program_birth_year = 2003;
+
 //#define DEBUG_SYNC
 
 #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
@@ -865,7 +870,7 @@ static int video_open(VideoState *is){
         w = 640;
         h = 480;
     }
-#ifndef SYS_DARWIN
+#ifndef __APPLE__
     screen = SDL_SetVideoMode(w, h, 0, flags);
 #else
     /* setting bits_per_pixel = 0 or 32 causes blank video on OS X */
@@ -1012,7 +1017,7 @@ static void video_refresh_timer(void *opaque)
 
             /* compute nominal delay */
             delay = vp->pts - is->frame_last_pts;
-            if (delay <= 0 || delay >= 1.0) {
+            if (delay <= 0 || delay >= 2.0) {
                 /* if incorrect delay, use previous one */
                 delay = is->frame_last_delay;
             }
@@ -1690,10 +1695,12 @@ static int stream_component_open(VideoState *is, int stream_index)
     if (enc->codec_type == CODEC_TYPE_AUDIO) {
         wanted_spec.freq = enc->sample_rate;
         wanted_spec.format = AUDIO_S16SYS;
-        /* hack for AC3. XXX: suppress that */
-        if (enc->channels > 2)
-            enc->channels = 2;
-        wanted_spec.channels = enc->channels;
+        if(enc->channels > 2) {
+            wanted_spec.channels = 2;
+            enc->request_channels = 2;
+        } else {
+            wanted_spec.channels = enc->channels;
+        }
         wanted_spec.silence = 0;
         wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
         wanted_spec.callback = sdl_audio_callback;
@@ -1908,7 +1915,8 @@ static int decode_thread(void *arg)
         ret = -1;
         goto fail;
     }
-    ic->pb.eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
+    if(ic->pb)
+        ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
 
     /* if seeking requested, we execute it */
     if (start_time != AV_NOPTS_VALUE) {
@@ -1973,8 +1981,10 @@ static int decode_thread(void *arg)
             else
                 av_read_play(ic);
         }
-#ifdef CONFIG_RTSP_DEMUXER
-        if (is->paused && ic->iformat == &rtsp_demuxer) {
+#if defined(CONFIG_RTSP_DEMUXER) || defined(CONFIG_MMSH_PROTOCOL)
+        if (is->paused &&
+                (!strcmp(ic->iformat->name, "rtsp") ||
+                 (ic->pb && !strcmp(url_fileno(ic->pb)->prot->name, "mmsh")))) {
             /* wait 10 ms to avoid trying to get another packet */
             /* XXX: horrible */
             SDL_Delay(10);
@@ -2017,14 +2027,14 @@ static int decode_thread(void *arg)
         if (is->audioq.size > MAX_AUDIOQ_SIZE ||
             is->videoq.size > MAX_VIDEOQ_SIZE ||
             is->subtitleq.size > MAX_SUBTITLEQ_SIZE ||
-            url_feof(&ic->pb)) {
+            url_feof(ic->pb)) {
             /* wait 10 ms */
             SDL_Delay(10);
             continue;
         }
         ret = av_read_frame(ic, pkt);
         if (ret < 0) {
-            if (url_ferror(&ic->pb) == 0) {
+            if (url_ferror(ic->pb) == 0) {
                 SDL_Delay(100); /* wait for user event */
                 continue;
             } else
@@ -2196,9 +2206,9 @@ static void toggle_pause(void)
 static void step_to_next_frame(void)
 {
     if (cur_stream) {
+        /* if the stream is paused unpause it, then step */
         if (cur_stream->paused)
-            cur_stream->paused=0;
-        cur_stream->video_current_pts = get_video_clock(cur_stream);
+            stream_pause(cur_stream);
     }
     step = 1;
 }
@@ -2276,7 +2286,7 @@ static void event_loop(void)
             do_seek:
                 if (cur_stream) {
                     if (seek_by_bytes) {
-                        pos = url_ftell(&cur_stream->ic->pb);
+                        pos = url_ftell(cur_stream->ic->pb);
                         if (cur_stream->ic->bit_rate)
                             incr *= cur_stream->ic->bit_rate / 60.0;
                         else
@@ -2406,11 +2416,15 @@ static void opt_sync(const char *arg)
 static void opt_seek(const char *arg)
 {
     start_time = parse_date(arg, 1);
+    if (start_time == INT64_MIN) {
+        fprintf(stderr, "Invalid duration specification: %s\n", arg);
+        exit(1);
+    }
 }
 
 static void opt_debug(const char *arg)
 {
-    av_log_level = 99;
+    av_log_set_level(99);
     debug = atoi(arg);
 }
 
@@ -2472,8 +2486,7 @@ const OptionDef options[] = {
 
 void show_help(void)
 {
-    printf("ffplay version " FFMPEG_VERSION ", Copyright (c) 2003-2007 Fabrice Bellard, et al.\n"
-           "usage: ffplay [options] input_file\n"
+    printf("usage: ffplay [options] input_file\n"
            "Simple media player\n");
     printf("\n");
     show_help_options(options, "Main options:\n",
@@ -2507,8 +2520,12 @@ int main(int argc, char **argv)
     int flags;
 
     /* register all codecs, demux and protocols */
+    avcodec_register_all();
+    avdevice_register_all();
     av_register_all();
 
+    show_banner(program_name, program_birth_year);
+
     parse_options(argc, argv, options, opt_input_file);
 
     if (!input_filename) {
@@ -2520,8 +2537,8 @@ int main(int argc, char **argv)
         video_disable = 1;
     }
     flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
-#if !defined(__MINGW32__) && !defined(SYS_DARWIN)
-    flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 or darwin */
+#if !defined(__MINGW32__) && !defined(__APPLE__)
+    flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */
 #endif
     if (SDL_Init (flags)) {
         fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());