Newer
Older
Fabrice Bellard
committed
}
#if 0
printf("diff=%f adiff=%f sample_diff=%d apts=%0.3f vpts=%0.3f %f\n",
diff, avg_diff, samples_size - samples_size1,
is->audio_clock, is->video_clock, is->audio_diff_threshold);
#endif
Fabrice Bellard
committed
} else {
/* too big difference : may be initial PTS errors, so
reset A-V filter */
is->audio_diff_avg_count = 0;
is->audio_diff_cum = 0;
}
}
return samples_size;
}
/* decode one audio frame and returns its uncompressed size */
static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_ptr)
{
AVPacket *pkt = &is->audio_pkt;
/* NOTE: the audio packet can contain several frames */
while (is->audio_pkt_size > 0) {
len1 = avcodec_decode_audio(&is->audio_st->codec,
(int16_t *)audio_buf, &data_size,
is->audio_pkt_data, is->audio_pkt_size);
if (len1 < 0) {
/* if error, we skip the frame */
is->audio_pkt_size = 0;
is->audio_pkt_data += len1;
is->audio_pkt_size -= len1;
if (data_size <= 0)
continue;
/* if no pts, then compute it */
pts = is->audio_clock;
*pts_ptr = pts;
n = 2 * is->audio_st->codec.channels;
is->audio_clock += (double)data_size /
(double)(n * is->audio_st->codec.sample_rate);
Fabrice Bellard
committed
#if defined(DEBUG_SYNC)
{
static double last_clock;
printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n",
is->audio_clock - last_clock,
is->audio_clock, pts);
last_clock = is->audio_clock;
/* free the current packet */
if (pkt->data)
if (is->paused || is->audioq.abort_request) {
return -1;
}
/* read next packet */
if (packet_queue_get(&is->audioq, pkt, 1) < 0)
return -1;
is->audio_pkt_data = pkt->data;
is->audio_pkt_size = pkt->size;
/* if update the audio clock with the pts */
if (pkt->pts != AV_NOPTS_VALUE) {
is->audio_clock = (double)pkt->pts / AV_TIME_BASE;
}
Fabrice Bellard
committed
/* get the current audio output buffer size, in samples. With SDL, we
cannot have a precise information */
static int audio_write_get_buf_size(VideoState *is)
Fabrice Bellard
committed
return is->audio_hw_buf_size - is->audio_buf_index;
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
}
/* prepare a new audio buffer */
void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
{
VideoState *is = opaque;
int audio_size, len1;
double pts;
audio_callback_time = av_gettime();
while (len > 0) {
if (is->audio_buf_index >= is->audio_buf_size) {
audio_size = audio_decode_frame(is, is->audio_buf, &pts);
if (audio_size < 0) {
/* if error, just output silence */
is->audio_buf_size = 1024;
memset(is->audio_buf, 0, is->audio_buf_size);
} else {
if (is->show_audio)
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
pts);
is->audio_buf_size = audio_size;
}
is->audio_buf_index = 0;
}
len1 = is->audio_buf_size - is->audio_buf_index;
if (len1 > len)
len1 = len;
memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
len -= len1;
stream += len1;
is->audio_buf_index += len1;
}
}
/* open a given stream. Return 0 if OK */
static int stream_component_open(VideoState *is, int stream_index)
{
AVFormatContext *ic = is->ic;
AVCodecContext *enc;
AVCodec *codec;
SDL_AudioSpec wanted_spec, spec;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return -1;
enc = &ic->streams[stream_index]->codec;
/* prepare audio output */
if (enc->codec_type == CODEC_TYPE_AUDIO) {
wanted_spec.freq = enc->sample_rate;
wanted_spec.format = AUDIO_S16SYS;
Fabrice Bellard
committed
/* hack for AC3. XXX: suppress that */
if (enc->channels > 2)
enc->channels = 2;
wanted_spec.channels = enc->channels;
wanted_spec.silence = 0;
Fabrice Bellard
committed
wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
wanted_spec.callback = sdl_audio_callback;
wanted_spec.userdata = is;
Fabrice Bellard
committed
if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
Fabrice Bellard
committed
}
is->audio_hw_buf_size = spec.size;
}
codec = avcodec_find_decoder(enc->codec_id);
enc->debug_mv = debug_mv;
enc->debug = debug;
if(lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
if(fast) enc->flags2 |= CODEC_FLAG2_FAST;
if (!codec ||
avcodec_open(enc, codec) < 0)
return -1;
François Revol
committed
#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
enc->thread_count= thread_count;
Fabrice Bellard
committed
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
is->audio_stream = stream_index;
is->audio_st = ic->streams[stream_index];
is->audio_buf_size = 0;
is->audio_buf_index = 0;
Fabrice Bellard
committed
/* init averaging filter */
is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
is->audio_diff_avg_count = 0;
/* since we do not have a precise anough audio fifo fullness,
we correct audio sync only if larger than this threshold */
is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / enc->sample_rate;
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
packet_queue_init(&is->audioq);
SDL_PauseAudio(0);
break;
case CODEC_TYPE_VIDEO:
is->video_stream = stream_index;
is->video_st = ic->streams[stream_index];
Fabrice Bellard
committed
is->frame_last_delay = 40e-3;
is->frame_timer = (double)av_gettime() / 1000000.0;
is->video_current_pts_time = av_gettime();
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
packet_queue_init(&is->videoq);
is->video_tid = SDL_CreateThread(video_thread, is);
break;
default:
break;
}
return 0;
}
static void stream_component_close(VideoState *is, int stream_index)
{
AVFormatContext *ic = is->ic;
AVCodecContext *enc;
enc = &ic->streams[stream_index]->codec;
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
packet_queue_abort(&is->audioq);
SDL_CloseAudio();
packet_queue_end(&is->audioq);
break;
case CODEC_TYPE_VIDEO:
packet_queue_abort(&is->videoq);
/* note: we also signal this mutex to make sure we deblock the
video thread in all cases */
SDL_LockMutex(is->pictq_mutex);
SDL_CondSignal(is->pictq_cond);
SDL_UnlockMutex(is->pictq_mutex);
SDL_WaitThread(is->video_tid, NULL);
packet_queue_end(&is->videoq);
break;
default:
break;
}
avcodec_close(enc);
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
is->audio_st = NULL;
is->audio_stream = -1;
break;
case CODEC_TYPE_VIDEO:
is->video_st = NULL;
is->video_stream = -1;
break;
default:
break;
}
}
void dump_stream_info(AVFormatContext *s)
{
if (s->track != 0)
fprintf(stderr, "Track: %d\n", s->track);
if (s->title[0] != '\0')
fprintf(stderr, "Title: %s\n", s->title);
if (s->author[0] != '\0')
fprintf(stderr, "Author: %s\n", s->author);
if (s->album[0] != '\0')
fprintf(stderr, "Album: %s\n", s->album);
if (s->year != 0)
fprintf(stderr, "Year: %d\n", s->year);
if (s->genre[0] != '\0')
fprintf(stderr, "Genre: %s\n", s->genre);
}
Fabrice Bellard
committed
/* since we have only one decoding thread, we can use a global
variable instead of a thread local variable */
static VideoState *global_video_state;
static int decode_interrupt_cb(void)
{
return (global_video_state && global_video_state->abort_request);
}
/* this thread gets the stream from the disk or the network */
static int decode_thread(void *arg)
{
VideoState *is = arg;
AVFormatContext *ic;
int err, i, ret, video_index, audio_index, use_play;
Fabrice Bellard
committed
AVFormatParameters params, *ap = ¶ms;
video_index = -1;
audio_index = -1;
is->video_stream = -1;
is->audio_stream = -1;
Fabrice Bellard
committed
global_video_state = is;
url_set_interrupt_cb(decode_interrupt_cb);
Fabrice Bellard
committed
memset(ap, 0, sizeof(*ap));
ap->image_format = image_format;
ap->initial_pause = 1; /* we force a pause when starting an RTSP
stream */
Fabrice Bellard
committed
err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
Fabrice Bellard
committed
if (err < 0) {
print_error(is->filename, err);
ret = -1;
goto fail;
}
#ifdef CONFIG_NETWORK
use_play = (ic->iformat == &rtsp_demux);
#else
use_play = 0;
#endif
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 shouldnt use url_feof() to test for the end
Fabrice Bellard
committed
}
/* if seeking requested, we execute it */
if (start_time != AV_NOPTS_VALUE) {
int64_t timestamp;
timestamp = start_time;
/* add the stream start time */
if (ic->start_time != AV_NOPTS_VALUE)
timestamp += ic->start_time;
ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
if (ret < 0) {
fprintf(stderr, "%s: could not seek to position %0.3f\n",
is->filename, (double)timestamp / AV_TIME_BASE);
}
}
/* 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) {
case CODEC_TYPE_AUDIO:
if (audio_index < 0 && !audio_disable)
audio_index = i;
break;
case CODEC_TYPE_VIDEO:
if (video_index < 0 && !video_disable)
video_index = i;
break;
default:
break;
}
}
if (show_status) {
dump_format(ic, 0, is->filename, 0);
}
/* open the streams */
if (audio_index >= 0) {
stream_component_open(is, audio_index);
}
if (video_index >= 0) {
stream_component_open(is, video_index);
} else {
if (!display_disable)
is->show_audio = 1;
}
if (is->video_stream < 0 && is->audio_stream < 0) {
Fabrice Bellard
committed
fprintf(stderr, "%s: could not open codecs\n", is->filename);
ret = -1;
goto fail;
}
for(;;) {
if (is->abort_request)
break;
Michael Niedermayer
committed
#ifdef CONFIG_NETWORK
Fabrice Bellard
committed
if (is->paused != is->last_paused) {
is->last_paused = is->paused;
if (is->paused)
av_read_pause(ic);
else
av_read_play(ic);
Fabrice Bellard
committed
}
if (is->paused && ic->iformat == &rtsp_demux) {
/* wait 10 ms to avoid trying to get another packet */
/* XXX: horrible */
SDL_Delay(10);
continue;
}
Michael Niedermayer
committed
#endif
if (is->seek_req) {
/* XXX: must lock decoder threads */
ret = av_seek_frame(is->ic, -1, is->seek_pos, is->seek_flags);
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);
Fabrice Bellard
committed
/* if the queue are full, no need to read more */
if (is->audioq.size > MAX_AUDIOQ_SIZE ||
Michael Niedermayer
committed
is->videoq.size > MAX_VIDEOQ_SIZE ||
url_feof(&ic->pb)) {
/* wait 10 ms */
SDL_Delay(10);
continue;
}
if (url_feof(&ic->pb) && url_ferror(&ic->pb) == 0) {
SDL_Delay(100); /* wait for user event */
continue;
} else
break;
}
if (pkt->stream_index == is->audio_stream) {
packet_queue_put(&is->audioq, pkt);
} else if (pkt->stream_index == is->video_stream) {
packet_queue_put(&is->videoq, pkt);
} else {
av_free_packet(pkt);
}
}
/* wait until the end */
while (!is->abort_request) {
SDL_Delay(100);
}
Fabrice Bellard
committed
ret = 0;
Fabrice Bellard
committed
/* disable interrupting */
global_video_state = 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);
Fabrice Bellard
committed
if (is->ic) {
av_close_input_file(is->ic);
is->ic = NULL; /* safety */
}
Fabrice Bellard
committed
url_set_interrupt_cb(NULL);
Fabrice Bellard
committed
if (ret != 0) {
SDL_Event event;
event.type = FF_QUIT_EVENT;
event.user.data1 = is;
SDL_PushEvent(&event);
}
Fabrice Bellard
committed
static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
{
VideoState *is;
is = av_mallocz(sizeof(VideoState));
if (!is)
return NULL;
pstrcpy(is->filename, sizeof(is->filename), filename);
Fabrice Bellard
committed
is->iformat = iformat;
if (screen) {
is->width = screen->w;
is->height = screen->h;
}
is->ytop = 0;
is->xleft = 0;
/* start video display */
is->pictq_mutex = SDL_CreateMutex();
is->pictq_cond = SDL_CreateCond();
/* add the refresh timer to draw the picture */
schedule_refresh(is, 40);
Fabrice Bellard
committed
is->av_sync_type = av_sync_type;
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
is->parse_tid = SDL_CreateThread(decode_thread, is);
if (!is->parse_tid) {
av_free(is);
return NULL;
}
return is;
}
static void stream_close(VideoState *is)
{
VideoPicture *vp;
int i;
/* XXX: use a special url_shutdown call to abort parse cleanly */
is->abort_request = 1;
SDL_WaitThread(is->parse_tid, NULL);
/* free all pictures */
for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
vp = &is->pictq[i];
if (vp->bmp) {
SDL_FreeYUVOverlay(vp->bmp);
vp->bmp = NULL;
}
}
SDL_DestroyMutex(is->pictq_mutex);
SDL_DestroyCond(is->pictq_cond);
}
Fabrice Bellard
committed
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
void stream_cycle_channel(VideoState *is, int codec_type)
{
AVFormatContext *ic = is->ic;
int start_index, stream_index;
AVStream *st;
if (codec_type == CODEC_TYPE_VIDEO)
start_index = is->video_stream;
else
start_index = is->audio_stream;
if (start_index < 0)
return;
stream_index = start_index;
for(;;) {
if (++stream_index >= is->ic->nb_streams)
stream_index = 0;
if (stream_index == start_index)
return;
st = ic->streams[stream_index];
if (st->codec.codec_type == codec_type) {
/* check that parameters are OK */
switch(codec_type) {
case CODEC_TYPE_AUDIO:
if (st->codec.sample_rate != 0 &&
st->codec.channels != 0)
goto the_end;
break;
case CODEC_TYPE_VIDEO:
goto the_end;
default:
break;
}
}
}
the_end:
stream_component_close(is, start_index);
stream_component_open(is, stream_index);
}
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
void toggle_full_screen(void)
{
int w, h, flags;
is_full_screen = !is_full_screen;
if (!fs_screen_width) {
/* use default SDL method */
SDL_WM_ToggleFullScreen(screen);
} else {
/* use the recorded resolution */
flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
if (is_full_screen) {
w = fs_screen_width;
h = fs_screen_height;
flags |= SDL_FULLSCREEN;
} else {
w = screen_width;
h = screen_height;
flags |= SDL_RESIZABLE;
}
screen = SDL_SetVideoMode(w, h, 0, flags);
cur_stream->width = w;
cur_stream->height = h;
}
}
void toggle_pause(void)
{
if (cur_stream)
stream_pause(cur_stream);
Wolfgang Hesseler
committed
step = 0;
}
void step_to_next_frame(void)
{
if (cur_stream) {
if (cur_stream->paused)
cur_stream->paused=0;
cur_stream->video_current_pts = get_video_clock(cur_stream);
}
step = 1;
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
}
void do_exit(void)
{
if (cur_stream) {
stream_close(cur_stream);
cur_stream = NULL;
}
if (show_status)
printf("\n");
SDL_Quit();
exit(0);
}
void toggle_audio_display(void)
{
if (cur_stream) {
cur_stream->show_audio = !cur_stream->show_audio;
}
}
/* handle an event sent by the GUI */
void event_loop(void)
{
SDL_Event event;
Michel Bardiaux
committed
double incr, pos, frac;
for(;;) {
SDL_WaitEvent(&event);
switch(event.type) {
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
case SDLK_q:
do_exit();
break;
case SDLK_f:
toggle_full_screen();
break;
case SDLK_p:
case SDLK_SPACE:
toggle_pause();
break;
Wolfgang Hesseler
committed
case SDLK_s: //S: Step to next frame
step_to_next_frame();
break;
Fabrice Bellard
committed
if (cur_stream)
stream_cycle_channel(cur_stream, CODEC_TYPE_AUDIO);
break;
case SDLK_v:
if (cur_stream)
stream_cycle_channel(cur_stream, CODEC_TYPE_VIDEO);
break;
case SDLK_w:
case SDLK_LEFT:
incr = -10.0;
goto do_seek;
case SDLK_RIGHT:
incr = 10.0;
goto do_seek;
case SDLK_UP:
incr = 60.0;
goto do_seek;
case SDLK_DOWN:
incr = -60.0;
do_seek:
if (cur_stream) {
pos = get_master_clock(cur_stream);
pos += incr;
stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), incr);
Michel Bardiaux
committed
case SDL_MOUSEBUTTONDOWN:
if (cur_stream) {
int ns, hh, mm, ss;
int tns, thh, tmm, tss;
tns = cur_stream->ic->duration/1000000LL;
thh = tns/3600;
tmm = (tns%3600)/60;
tss = (tns%60);
frac = (double)event.button.x/(double)cur_stream->width;
ns = frac*tns;
hh = ns/3600;
mm = (ns%3600)/60;
ss = (ns%60);
fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
hh, mm, ss, thh, tmm, tss);
stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration), 0);
Michel Bardiaux
committed
}
break;
case SDL_VIDEORESIZE:
if (cur_stream) {
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
cur_stream->width = event.resize.w;
cur_stream->height = event.resize.h;
}
break;
case SDL_QUIT:
Fabrice Bellard
committed
case FF_QUIT_EVENT:
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
do_exit();
break;
case FF_ALLOC_EVENT:
alloc_picture(event.user.data1);
break;
case FF_REFRESH_EVENT:
video_refresh_timer(event.user.data1);
break;
default:
break;
}
}
}
void opt_width(const char *arg)
{
screen_width = atoi(arg);
}
void opt_height(const char *arg)
{
screen_height = atoi(arg);
}
static void opt_format(const char *arg)
{
file_iformat = av_find_input_format(arg);
if (!file_iformat) {
fprintf(stderr, "Unknown input format: %s\n", arg);
exit(1);
}
}
Fabrice Bellard
committed
static void opt_image_format(const char *arg)
{
AVImageFormat *f;
for(f = first_image_format; f != NULL; f = f->next) {
if (!strcmp(arg, f->name))
break;
}
if (!f) {
fprintf(stderr, "Unknown image format: '%s'\n", arg);
exit(1);
}
image_format = f;
}
Michael Niedermayer
committed
#ifdef CONFIG_NETWORK
Fabrice Bellard
committed
void opt_rtp_tcp(void)
{
/* only tcp protocol */
rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
}
Michael Niedermayer
committed
#endif
Fabrice Bellard
committed
Fabrice Bellard
committed
void opt_sync(const char *arg)
{
if (!strcmp(arg, "audio"))
av_sync_type = AV_SYNC_AUDIO_MASTER;
else if (!strcmp(arg, "video"))
av_sync_type = AV_SYNC_VIDEO_MASTER;
else if (!strcmp(arg, "ext"))
av_sync_type = AV_SYNC_EXTERNAL_CLOCK;
else
show_help();
}
void opt_seek(const char *arg)
{
start_time = parse_date(arg, 1);
}
Wolfgang Hesseler
committed
static void opt_debug(const char *arg)
{
debug = atoi(arg);
}
Wolfgang Hesseler
committed
static void opt_vismv(const char *arg)
{
debug_mv = atoi(arg);
}
static void opt_thread_count(const char *arg)
{
thread_count= atoi(arg);
François Revol
committed
#if !defined(HAVE_THREADS)
fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
#endif
}
Wolfgang Hesseler
committed
Wolfgang Hesseler
committed
{ "h", 0, {(void*)show_help}, "show help" },
{ "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
{ "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" },
Fabrice Bellard
committed
#if 0
/* disabled as SDL/X11 does not support it correctly on application launch */
{ "fs", OPT_BOOL, {(void*)&is_full_screen}, "force full screen" },
#endif
{ "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
{ "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
{ "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" },
{ "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" },
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
Fabrice Bellard
committed
{ "img", HAS_ARG, {(void*)opt_image_format}, "force image format", "img_fmt" },
{ "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
Wolfgang Hesseler
committed
{ "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
{ "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" },
Wolfgang Hesseler
committed
{ "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
{ "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" },
{ "lowres", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&lowres}, "", "" },
{ "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" },
Michael Niedermayer
committed
#ifdef CONFIG_NETWORK
Fabrice Bellard
committed
{ "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
Michael Niedermayer
committed
#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" },
{ NULL, },
};
void show_help(void)
{
printf("ffplay version " FFMPEG_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
"usage: ffplay [options] input_file\n"
show_help_options(options, "Main options:\n",
OPT_EXPERT, 0);
show_help_options(options, "\nAdvanced options:\n",
OPT_EXPERT, OPT_EXPERT);
printf("\nWhile playing:\n"
"q, ESC quit\n"
"f toggle full screen\n"
"p, SPC pause\n"
Fabrice Bellard
committed
"a cycle audio channel\n"
"v cycle video channel\n"
"w show audio waves\n"
"left/right seek backward/forward 10 seconds\n"
"down/up seek backward/forward 1 minute\n"
Michel Bardiaux
committed
"mouse click seek to percentage in file corresponding to fraction of width\n"
);
exit(1);
}
void parse_arg_file(const char *filename)
{
Michael Niedermayer
committed
if (!strcmp(filename, "-"))
filename = "pipe:";
input_filename = filename;
}
/* Called from the main */
int main(int argc, char **argv)
{
Fabrice Bellard
committed
int flags, w, h;
/* register all codecs, demux and protocols */
av_register_all();
parse_options(argc, argv, options);
if (!input_filename)
show_help();
if (display_disable) {
video_disable = 1;
}
flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
#ifndef CONFIG_WIN32
flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 */
#endif
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
if (!display_disable) {
#ifdef HAVE_X11
/* save the screen resolution... SDL should allow full screen
by resizing the window */
{
Display *dpy;
dpy = XOpenDisplay(NULL);
if (dpy) {
fs_screen_width = DisplayWidth(dpy, DefaultScreen(dpy));
fs_screen_height = DisplayHeight(dpy, DefaultScreen(dpy));
XCloseDisplay(dpy);
}
}
#endif
Fabrice Bellard
committed
flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
if (is_full_screen && fs_screen_width) {
w = fs_screen_width;
h = fs_screen_height;
flags |= SDL_FULLSCREEN;
} else {
w = screen_width;
h = screen_height;
flags |= SDL_RESIZABLE;
}
screen = SDL_SetVideoMode(w, h, 0, flags);
if (!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n");
exit(1);
}
SDL_WM_SetCaption("FFplay", "FFplay");
}
SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
Fabrice Bellard
committed
cur_stream = stream_open(input_filename, file_iformat);
event_loop();
/* never returns */
return 0;
}