#include <math.h>
#include <limits.h>
#include "avformat.h"
+#include "avdevice.h"
+#include "rtsp.h"
#include "swscale.h"
#include "avstring.h"
#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)
aspect_ratio = 0;
else
aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio)
- * is->video_st->codec->width / is->video_st->codec->height;;
+ * is->video_st->codec->width / is->video_st->codec->height;
if (aspect_ratio <= 0.0)
aspect_ratio = (float)is->video_st->codec->width /
(float)is->video_st->codec->height;
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 */
/* 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;
}
/* prepare audio output */
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;
- wanted_spec.silence = 0;
- wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
- wanted_spec.callback = sdl_audio_callback;
- wanted_spec.userdata = is;
- if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
- fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
- return -1;
+ if (enc->channels > 0) {
+ enc->request_channels = FFMIN(2, enc->channels);
+ } else {
+ enc->request_channels = 2;
}
- is->audio_hw_buf_size = spec.size;
}
codec = avcodec_find_decoder(enc->codec_id);
if (!codec ||
avcodec_open(enc, codec) < 0)
return -1;
+
+ /* prepare audio output */
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ wanted_spec.freq = enc->sample_rate;
+ wanted_spec.format = AUDIO_S16SYS;
+ wanted_spec.channels = enc->channels;
+ wanted_spec.silence = 0;
+ wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
+ wanted_spec.callback = sdl_audio_callback;
+ wanted_spec.userdata = is;
+ if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
+ fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
+ return -1;
+ }
+ is->audio_hw_buf_size = spec.size;
+ }
+
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
enc->thread_count= thread_count;
{
VideoState *is = arg;
AVFormatContext *ic;
- int err, i, ret, video_index, audio_index, use_play;
+ int err, i, ret, video_index, audio_index;
AVPacket pkt1, *pkt = &pkt1;
AVFormatParameters params, *ap = ¶ms;
url_set_interrupt_cb(decode_interrupt_cb);
memset(ap, 0, sizeof(*ap));
- ap->initial_pause = 1; /* we force a pause when starting an RTSP
- stream */
ap->width = frame_width;
ap->height= frame_height;
goto fail;
}
is->ic = ic;
-#ifdef CONFIG_RTSP_DEMUXER
- use_play = (ic->iformat == &rtsp_demuxer);
-#else
- use_play = 0;
-#endif
if(genpts)
ic->flags |= AVFMT_FLAG_GENPTS;
- if (!use_play) {
- err = av_find_stream_info(ic);
- if (err < 0) {
- fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
- ret = -1;
- goto fail;
- }
- ic->pb.eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
+ err = av_find_stream_info(ic);
+ if (err < 0) {
+ fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
+ ret = -1;
+ goto fail;
}
+ 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) {
}
}
- /* now we can begin to play (RTSP stream only) */
- av_read_play(ic);
-
- if (use_play) {
- err = av_find_stream_info(ic);
- if (err < 0) {
- fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
- ret = -1;
- goto fail;
- }
- }
-
for(i = 0; i < ic->nb_streams; i++) {
AVCodecContext *enc = ic->streams[i]->codec;
switch(enc->codec_type) {
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);
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
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;
}
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
}
}
-static void opt_width(const char *arg)
+static int opt_width(const char *opt, const char *arg)
{
- screen_width = atoi(arg);
- if(screen_width<=0){
- fprintf(stderr, "invalid width\n");
- exit(1);
- }
+ screen_width = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ return 0;
}
-static void opt_height(const char *arg)
+static int opt_height(const char *opt, const char *arg)
{
- screen_height = atoi(arg);
- if(screen_height<=0){
- fprintf(stderr, "invalid height\n");
- exit(1);
- }
+ screen_height = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ return 0;
}
static void opt_format(const char *arg)
frame_pix_fmt = avcodec_get_pix_fmt(arg);
}
-#ifdef CONFIG_RTSP_DEMUXER
-static void opt_rtp_tcp(void)
-{
- /* only tcp protocol */
- rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
-}
-#endif
-
static void opt_sync(const char *arg)
{
if (!strcmp(arg, "audio"))
}
}
-static void opt_seek(const char *arg)
+static int opt_seek(const char *opt, const char *arg)
{
- start_time = parse_date(arg, 1);
+ start_time = parse_time_or_die(opt, arg, 1);
+ return 0;
}
-static void opt_debug(const char *arg)
+static int opt_debug(const char *opt, const char *arg)
{
- av_log_level = 99;
- debug = atoi(arg);
+ av_log_set_level(99);
+ debug = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
+ return 0;
}
-static void opt_vismv(const char *arg)
+static int opt_vismv(const char *opt, const char *arg)
{
- debug_mv = atoi(arg);
+ debug_mv = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ return 0;
}
-static void opt_thread_count(const char *arg)
+static int opt_thread_count(const char *opt, const char *arg)
{
- thread_count= atoi(arg);
+ thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
#if !defined(HAVE_THREADS)
fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
#endif
+ return 0;
}
static void opt_show_help(void)
const OptionDef options[] = {
{ "h", 0, {(void*)opt_show_help}, "show help" },
- { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
- { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" },
+ { "x", HAS_ARG | OPT_FUNC2, {(void*)opt_width}, "force displayed width", "width" },
+ { "y", HAS_ARG | OPT_FUNC2, {(void*)opt_height}, "force displayed height", "height" },
{ "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
{ "fs", OPT_BOOL, {(void*)&is_full_screen}, "force full screen" },
{ "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
{ "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
{ "ast", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_audio_stream}, "", "" },
{ "vst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_video_stream}, "", "" },
- { "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
+ { "ss", HAS_ARG | OPT_FUNC2, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
{ "bytes", OPT_BOOL, {(void*)&seek_by_bytes}, "seek by bytes" },
{ "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
{ "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" },
{ "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
- { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
+ { "debug", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
{ "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" },
- { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
+ { "vismv", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
{ "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" },
{ "genpts", OPT_BOOL | OPT_EXPERT, {(void*)&genpts}, "generate pts", "" },
{ "drp", OPT_BOOL |OPT_EXPERT, {(void*)&decoder_reorder_pts}, "let decoder reorder pts", ""},
{ "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" },
{ "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_resilience}, "set error detection threshold (0-4)", "threshold" },
{ "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" },
-#ifdef CONFIG_RTSP_DEMUXER
- { "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" },
- { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
+ { "threads", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ NULL, },
};
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",
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) {
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());