/*
- * ffplay : Simple Media Player based on the FFmpeg libraries
* Copyright (c) 2003 Fabrice Bellard
*
* This file is part of FFmpeg.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * simple media player based on the FFmpeg libraries
+ */
+
#include "config.h"
#include <inttypes.h>
#include <math.h>
exit(0);
}
-static int video_open(VideoState *is){
+static int video_open(VideoState *is, int force_set_video_mode){
int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
int w,h;
h = 480;
}
if(screen && is->width == screen->w && screen->w == w
- && is->height== screen->h && screen->h == h)
+ && is->height== screen->h && screen->h == h && !force_set_video_mode)
return 0;
screen = SDL_SetVideoMode(w, h, 0, flags);
if (!screen) {
static void video_display(VideoState *is)
{
if(!screen)
- video_open(is);
+ video_open(is, 0);
if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is);
else if (is->video_st)
pic->linesize[i] = ref->linesize[i];
}
pic->opaque = ref;
- pic->age = INT_MAX;
pic->type = FF_BUFFER_TYPE_USER;
pic->reordered_opaque = codec->reordered_opaque;
if(codec->pkt) pic->pkt_pts = codec->pkt->pts;
AVPacket *pkt = &is->audio_pkt;
AVCodecContext *dec= is->audio_st->codec;
int len1, len2, data_size, resampled_data_size;
- int64_t dec_channel_layout, got_frame;
+ int64_t dec_channel_layout;
+ int got_frame;
double pts;
int new_packet = 0;
int flush_complete = 0;
/* free the current packet */
if (pkt->data)
av_free_packet(pkt);
+ memset(pkt_temp, 0, sizeof(*pkt_temp));
if (is->paused || is->audioq.abort_request) {
return -1;
}
}
-/* 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 *ctx)
{
- return (global_video_state && global_video_state->abort_request);
+ VideoState *is = ctx;
+ return is->abort_request;
}
/* this thread gets the stream from the disk or the network */
is->audio_stream = -1;
is->subtitle_stream = -1;
- global_video_state = is;
-
ic = avformat_alloc_context();
ic->interrupt_callback.callback = decode_interrupt_cb;
+ ic->interrupt_callback.opaque = is;
err = avformat_open_input(&ic, is->filename, is->iformat, &format_opts);
if (err < 0) {
print_error(is->filename, err);
if(genpts)
ic->flags |= AVFMT_FLAG_GENPTS;
- av_dict_set(&codec_opts, "request_channels", "2", 0);
-
opts = setup_find_stream_info_opts(ic, codec_opts);
orig_nb_streams = ic->nb_streams;
ret = 0;
fail:
- /* disable interrupting */
- global_video_state = NULL;
-
/* close each stream */
if (is->audio_stream >= 0)
stream_component_close(is, is->audio_stream);
if (is->subtitle_stream >= 0)
stream_component_close(is, is->subtitle_stream);
if (is->ic) {
- av_close_input_file(is->ic);
- is->ic = NULL; /* safety */
+ avformat_close_input(&is->ic);
}
- avio_set_interrupt_cb(NULL);
if (ret != 0) {
SDL_Event event;
static void toggle_full_screen(VideoState *is)
{
+ int i;
is_full_screen = !is_full_screen;
#if defined(__APPLE__) && SDL_VERSION_ATLEAST(1, 2, 14)
- /* OSX needs to reallocate the SDL overlays */
- for (int i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) {
+ /* OS X needs to reallocate the SDL overlays */
+ for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) {
is->pictq[i].reallocate = 1;
}
#endif
- video_open(is);
+ video_open(is, 1);
}
static void toggle_pause(VideoState *is)
case SDLK_w:
toggle_audio_display(cur_stream);
break;
+ case SDLK_PAGEUP:
+ incr = 600.0;
+ goto do_seek;
+ case SDLK_PAGEDOWN:
+ incr = -600.0;
+ goto do_seek;
case SDLK_LEFT:
incr = -10.0;
goto do_seek;
do_exit(cur_stream);
break;
case FF_ALLOC_EVENT:
- video_open(event.user.data1);
+ video_open(event.user.data1, 0);
alloc_picture(event.user.data1);
break;
case FF_REFRESH_EVENT:
"s activate frame-step mode\n"
"left/right seek backward/forward 10 seconds\n"
"down/up seek backward/forward 1 minute\n"
+ "page down/page up seek backward/forward 10 minutes\n"
"mouse click seek to percentage in file corresponding to fraction of width\n"
);
return 0;
init_opts();
- show_banner();
+ show_banner(argc, argv, options);
parse_options(NULL, argc, argv, options, opt_input_file);