1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

ffplay: get rid of the global cur_stream variable

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Marton Balint 2011-08-21 15:06:09 +02:00 committed by Michael Niedermayer
parent 5db1f94b8d
commit 84506ebd48

View File

@ -267,7 +267,6 @@ static char *vfilters = NULL;
/* current context */ /* current context */
static int is_full_screen; static int is_full_screen;
static VideoState *cur_stream;
static int64_t audio_callback_time; static int64_t audio_callback_time;
static AVPacket flush_pkt; static AVPacket flush_pkt;
@ -887,11 +886,10 @@ static void stream_close(VideoState *is)
av_free(is); av_free(is);
} }
static void do_exit(void) static void do_exit(VideoState *is)
{ {
if (cur_stream) { if (is) {
stream_close(cur_stream); stream_close(is);
cur_stream = NULL;
} }
uninit_opts(); uninit_opts();
#if CONFIG_AVFILTER #if CONFIG_AVFILTER
@ -942,7 +940,7 @@ static int video_open(VideoState *is){
#endif #endif
if (!screen) { if (!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n"); fprintf(stderr, "SDL: could not set video mode - exiting\n");
do_exit(); do_exit(is);
} }
if (!window_title) if (!window_title)
window_title = input_filename; window_title = input_filename;
@ -958,7 +956,7 @@ static int video_open(VideoState *is){
static void video_display(VideoState *is) static void video_display(VideoState *is)
{ {
if(!screen) if(!screen)
video_open(cur_stream); video_open(is);
if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO) if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is); video_audio_display(is);
else if (is->video_st) else if (is->video_st)
@ -1280,7 +1278,7 @@ static void alloc_picture(void *opaque)
fprintf(stderr, "Error: the video system does not support an image\n" fprintf(stderr, "Error: the video system does not support an image\n"
"size of %dx%d pixels. Try using -lowres or -vf \"scale=w:h\"\n" "size of %dx%d pixels. Try using -lowres or -vf \"scale=w:h\"\n"
"to reduce the image size.\n", vp->width, vp->height ); "to reduce the image size.\n", vp->width, vp->height );
do_exit(); do_exit(is);
} }
SDL_LockMutex(is->pictq_mutex); SDL_LockMutex(is->pictq_mutex);
@ -1794,8 +1792,8 @@ static int video_thread(void *arg)
if (ret < 0) if (ret < 0)
goto the_end; goto the_end;
if (cur_stream && cur_stream->step) if (is->step)
stream_toggle_pause(cur_stream); stream_toggle_pause(is);
} }
the_end: the_end:
#if CONFIG_AVFILTER #if CONFIG_AVFILTER
@ -2496,7 +2494,7 @@ static int read_thread(void *arg)
SDL_Delay(10); SDL_Delay(10);
if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){ if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
if(loop!=1 && (!loop || --loop)){ if(loop!=1 && (!loop || --loop)){
stream_seek(cur_stream, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0); stream_seek(is, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
}else if(autoexit){ }else if(autoexit){
ret=AVERROR_EOF; ret=AVERROR_EOF;
goto fail; goto fail;
@ -2641,10 +2639,10 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
} }
static void toggle_full_screen(void) static void toggle_full_screen(VideoState *is)
{ {
is_full_screen = !is_full_screen; is_full_screen = !is_full_screen;
video_open(cur_stream); video_open(is);
} }
static void toggle_pause(VideoState *is) static void toggle_pause(VideoState *is)
@ -2661,20 +2659,18 @@ static void step_to_next_frame(VideoState *is)
is->step = 1; is->step = 1;
} }
static void toggle_audio_display(void) static void toggle_audio_display(VideoState *is)
{ {
if (cur_stream) { int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB;
cur_stream->show_mode = (cur_stream->show_mode + 1) % SHOW_MODE_NB; fill_rectangle(screen,
fill_rectangle(screen, is->xleft, is->ytop, is->width, is->height,
cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height, bgcolor);
bgcolor); SDL_UpdateRect(screen, is->xleft, is->ytop, is->width, is->height);
SDL_UpdateRect(screen, cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height);
}
} }
/* handle an event sent by the GUI */ /* handle an event sent by the GUI */
static void event_loop(void) static void event_loop(VideoState *cur_stream)
{ {
SDL_Event event; SDL_Event event;
double incr, pos, frac; double incr, pos, frac;
@ -2685,16 +2681,16 @@ static void event_loop(void)
switch(event.type) { switch(event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (exit_on_keydown) { if (exit_on_keydown) {
do_exit(); do_exit(cur_stream);
break; break;
} }
switch(event.key.keysym.sym) { switch(event.key.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
case SDLK_q: case SDLK_q:
do_exit(); do_exit(cur_stream);
break; break;
case SDLK_f: case SDLK_f:
toggle_full_screen(); toggle_full_screen(cur_stream);
break; break;
case SDLK_p: case SDLK_p:
case SDLK_SPACE: case SDLK_SPACE:
@ -2718,7 +2714,8 @@ static void event_loop(void)
stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE); stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
break; break;
case SDLK_w: case SDLK_w:
toggle_audio_display(); if (cur_stream)
toggle_audio_display(cur_stream);
break; break;
case SDLK_LEFT: case SDLK_LEFT:
incr = -10.0; incr = -10.0;
@ -2759,7 +2756,7 @@ static void event_loop(void)
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (exit_on_mousedown) { if (exit_on_mousedown) {
do_exit(); do_exit(cur_stream);
break; break;
} }
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
@ -2806,7 +2803,7 @@ static void event_loop(void)
break; break;
case SDL_QUIT: case SDL_QUIT:
case FF_QUIT_EVENT: case FF_QUIT_EVENT:
do_exit(); do_exit(cur_stream);
break; break;
case FF_ALLOC_EVENT: case FF_ALLOC_EVENT:
video_open(event.user.data1); video_open(event.user.data1);
@ -3007,6 +3004,7 @@ static int opt_help(const char *opt, const char *arg)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int flags; int flags;
VideoState *is;
av_log_set_flags(AV_LOG_SKIP_REPEATED); av_log_set_flags(AV_LOG_SKIP_REPEATED);
@ -3063,9 +3061,13 @@ int main(int argc, char **argv)
av_init_packet(&flush_pkt); av_init_packet(&flush_pkt);
flush_pkt.data= "FLUSH"; flush_pkt.data= "FLUSH";
cur_stream = stream_open(input_filename, file_iformat); is = stream_open(input_filename, file_iformat);
if (!is) {
fprintf(stderr, "Failed to initialize VideoState!\n");
do_exit(NULL);
}
event_loop(); event_loop(is);
/* never returns */ /* never returns */