# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
-# include "libavfilter/vsink_buffer.h"
+# include "libavfilter/buffersink.h"
#endif
#include <SDL.h>
typedef struct VideoPicture {
double pts; ///<presentation time stamp for this picture
double target_clock; ///<av_gettime() time at which this should be displayed ideally
+ double duration; ///<expected duration of the frame
int64_t pos; ///<byte position in file
SDL_Overlay *bmp;
int width, height; /* source height & width */
uint8_t *audio_buf;
unsigned int audio_buf_size; /* in bytes */
int audio_buf_index; /* in bytes */
+ int audio_write_buf_size;
AVPacket audio_pkt_temp;
AVPacket audio_pkt;
enum AVSampleFormat audio_src_fmt;
AVAudioConvert *reformat_ctx;
+ double audio_current_pts;
+ double audio_current_pts_drift;
enum ShowMode {
SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
char filename[1024];
int width, height, xleft, ytop;
+ int step;
#if CONFIG_AVFILTER
AVFilterContext *out_video_filter; ///<the last filter in the video chain
static int av_sync_type = AV_SYNC_AUDIO_MASTER;
static int64_t start_time = AV_NOPTS_VALUE;
static int64_t duration = AV_NOPTS_VALUE;
-static int step = 0;
-static int thread_count = 1;
static int workaround_bugs = 1;
static int fast = 0;
static int genpts = 0;
/* current context */
static int is_full_screen;
-static VideoState *cur_stream;
static int64_t audio_callback_time;
static AVPacket flush_pkt;
static SDL_Surface *screen;
+void exit_program(int ret)
+{
+ exit(ret);
+}
+
static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
{
AVPacketList *pkt1;
}
}
-/* 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)
-{
- return is->audio_buf_size - is->audio_buf_index;
-}
-
static inline int compute_mod(int a, int b)
{
return a < 0 ? a%b + b : a%b;
if (!s->paused) {
int data_used= s->show_mode == SHOW_MODE_WAVES ? s->width : (2*nb_freq);
n = 2 * channels;
- delay = audio_write_get_buf_size(s);
+ delay = s->audio_write_buf_size;
delay /= n;
/* to be more precise, we take into account the time spent since
av_free(is);
}
-static void do_exit(void)
+static void do_exit(VideoState *is)
{
- if (cur_stream) {
- stream_close(cur_stream);
- cur_stream = NULL;
+ if (is) {
+ stream_close(is);
}
+ av_lockmgr_register(NULL);
uninit_opts();
#if CONFIG_AVFILTER
avfilter_uninit();
#endif
if (!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n");
- do_exit();
+ do_exit(is);
}
if (!window_title)
window_title = input_filename;
static void video_display(VideoState *is)
{
if(!screen)
- video_open(cur_stream);
+ video_open(is);
if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is);
else if (is->video_st)
/* get the current audio clock value */
static double get_audio_clock(VideoState *is)
{
- double pts;
- int hw_buf_size, bytes_per_sec;
- pts = is->audio_clock;
- hw_buf_size = audio_write_get_buf_size(is);
- bytes_per_sec = 0;
- if (is->audio_st) {
- bytes_per_sec = is->audio_st->codec->sample_rate *
- 2 * is->audio_st->codec->channels;
+ if (is->paused) {
+ return is->audio_current_pts;
+ } else {
+ return is->audio_current_pts_drift + av_gettime() / 1000000.0;
}
- if (bytes_per_sec)
- pts -= (double)hw_buf_size / bytes_per_sec;
- return pts;
}
/* get the current video clock value */
assert(nextvp->target_clock >= vp->target_clock);
next_target= nextvp->target_clock;
}else{
- next_target= vp->target_clock + is->video_clock - vp->pts; //FIXME pass durations cleanly
+ next_target= vp->target_clock + vp->duration;
}
if((framedrop>0 || (framedrop && is->audio_st)) && time > next_target){
is->skip_frames *= 1.0 + FRAME_SKIP_FACTOR;
- if(is->pictq_size > 1 || time > next_target + 0.5){
+ if(is->pictq_size > 1){
/* update queue size and signal for next picture */
if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
is->pictq_rindex = 0;
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"
"to reduce the image size.\n", vp->width, vp->height );
- do_exit();
+ do_exit(is);
}
SDL_LockMutex(is->pictq_mutex);
vp = &is->pictq[is->pictq_windex];
+ vp->duration = frame_delay;
+
/* alloc or resize hardware picture buffer */
if (!vp->bmp ||
#if CONFIG_AVFILTER
while (!vp->allocated && !is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
}
+ /* if the queue is aborted, we have to pop the pending ALLOC event or wait for the allocation to complete */
+ if (is->videoq.abort_request && SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(FF_ALLOC_EVENT)) != 1) {
+ while (!vp->allocated) {
+ SDL_CondWait(is->pictq_cond, is->pictq_mutex);
+ }
+ }
SDL_UnlockMutex(is->pictq_mutex);
if (is->videoq.abort_request)
static int input_config_props(AVFilterLink *link)
{
FilterPriv *priv = link->src->priv;
- AVCodecContext *c = priv->is->video_st->codec;
+ AVStream *s = priv->is->video_st;
- link->w = c->width;
- link->h = c->height;
- link->sample_aspect_ratio = priv->is->video_st->sample_aspect_ratio;
- link->time_base = priv->is->video_st->time_base;
+ link->w = s->codec->width;
+ link->h = s->codec->height;
+ link->sample_aspect_ratio = s->sample_aspect_ratio.num ?
+ s->sample_aspect_ratio : s->codec->sample_aspect_ratio;
+ link->time_base = s->time_base;
return 0;
}
char sws_flags_str[128];
int ret;
enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
AVFilterContext *filt_src = NULL, *filt_out = NULL;
snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags);
graph->scale_sws_opts = av_strdup(sws_flags_str);
if ((ret = avfilter_graph_create_filter(&filt_src, &input_filter, "src",
NULL, is, graph)) < 0)
return ret;
- if ((ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("buffersink"), "out",
- NULL, pix_fmts, graph)) < 0)
+#if FF_API_OLD_VSINK_API
+ ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("buffersink"), "out",
+ NULL, pix_fmts, graph);
+#else
+ buffersink_params->pixel_fmts = pix_fmts;
+ ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("buffersink"), "out",
+ NULL, buffersink_params, graph);
+#endif
+ av_freep(&buffersink_params);
+ if (ret < 0)
return ret;
if(vfilters) {
if ((ret = avfilter_graph_parse(graph, vfilters, &inputs, &outputs, NULL)) < 0)
return ret;
- av_freep(&vfilters);
} else {
if ((ret = avfilter_link(filt_src, 0, filt_out, 0)) < 0)
return ret;
#if CONFIG_AVFILTER
AVFilterGraph *graph = avfilter_graph_alloc();
AVFilterContext *filt_out = NULL;
+ int last_w = is->video_st->codec->width;
+ int last_h = is->video_st->codec->height;
if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
goto the_end;
while (is->paused && !is->videoq.abort_request)
SDL_Delay(10);
#if CONFIG_AVFILTER
- ret = av_vsink_buffer_get_video_buffer_ref(filt_out, &picref, 0);
+ if ( last_w != is->video_st->codec->width
+ || last_h != is->video_st->codec->height) {
+ av_log(NULL, AV_LOG_INFO, "Frame changed from size:%dx%d to size:%dx%d\n",
+ last_w, last_h, is->video_st->codec->width, is->video_st->codec->height);
+ avfilter_graph_free(&graph);
+ graph = avfilter_graph_alloc();
+ if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
+ goto the_end;
+ filt_out = is->out_video_filter;
+ last_w = is->video_st->codec->width;
+ last_h = is->video_st->codec->height;
+ }
+ ret = av_buffersink_get_buffer_ref(filt_out, &picref, 0);
if (picref) {
avfilter_fill_frame_from_video_buffer_ref(frame, picref);
pts_int = picref->pts;
if (ret < 0) goto the_end;
+#if CONFIG_AVFILTER
if (!picref)
continue;
+#endif
pts = pts_int*av_q2d(is->video_st->time_base);
if (ret < 0)
goto the_end;
- if (step)
- if (cur_stream)
- stream_toggle_pause(cur_stream);
+ if (is->step)
+ stream_toggle_pause(is);
}
the_end:
#if CONFIG_AVFILTER
samples_size = wanted_size;
}
}
-#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
+ av_dlog(NULL, "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);
}
} else {
/* too big difference : may be initial PTS errors, so
AVCodecContext *dec= is->audio_st->codec;
int n, len1, data_size;
double pts;
+ int new_packet = 0;
+ int flush_complete = 0;
for(;;) {
/* NOTE: the audio packet can contain several frames */
- while (pkt_temp->size > 0) {
+ while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet)) {
+ if (flush_complete)
+ break;
+ new_packet = 0;
data_size = sizeof(is->audio_buf1);
len1 = avcodec_decode_audio3(dec,
(int16_t *)is->audio_buf1, &data_size,
pkt_temp->data += len1;
pkt_temp->size -= len1;
- if (data_size <= 0)
+
+ if (data_size <= 0) {
+ /* stop sending empty packets if the decoder is finished */
+ if (!pkt_temp->data && dec->codec->capabilities & CODEC_CAP_DELAY)
+ flush_complete = 1;
continue;
+ }
if (dec->sample_fmt != is->audio_src_fmt) {
if (is->reformat_ctx)
}
/* read next packet */
- if (packet_queue_get(&is->audioq, pkt, 1) < 0)
+ if ((new_packet = packet_queue_get(&is->audioq, pkt, 1)) < 0)
return -1;
- if(pkt->data == flush_pkt.data){
+
+ if (pkt->data == flush_pkt.data)
avcodec_flush_buffers(dec);
- continue;
- }
pkt_temp->data = pkt->data;
pkt_temp->size = pkt->size;
{
VideoState *is = opaque;
int audio_size, len1;
+ int bytes_per_sec;
double pts;
audio_callback_time = av_gettime();
stream += len1;
is->audio_buf_index += len1;
}
+ bytes_per_sec = is->audio_st->codec->sample_rate *
+ 2 * is->audio_st->codec->channels;
+ is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index;
+ /* Let's assume the audio driver that is used by SDL has two periods. */
+ is->audio_current_pts = is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec;
+ is->audio_current_pts_drift = is->audio_current_pts - audio_callback_time / 1000000.0;
}
/* open a given stream. Return 0 if OK */
return -1;
avctx = ic->streams[stream_index]->codec;
- opts = filter_codec_opts(codec_opts, avctx->codec_id, 0);
+ opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index]);
/* prepare audio output */
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
avctx->skip_loop_filter= skip_loop_filter;
avctx->error_recognition= error_recognition;
avctx->error_concealment= error_concealment;
- avctx->thread_count= thread_count;
if(codec->capabilities & CODEC_CAP_DR1)
avctx->flags |= CODEC_FLAG_EMU_EDGE;
+ wanted_spec.freq = avctx->sample_rate;
+ wanted_spec.channels = avctx->channels;
if (!codec ||
avcodec_open2(avctx, codec, &opts) < 0)
return -1;
fprintf(stderr, "Invalid sample rate or channel count\n");
return -1;
}
- wanted_spec.freq = avctx->sample_rate;
wanted_spec.format = AUDIO_S16SYS;
- wanted_spec.channels = avctx->channels;
wanted_spec.silence = 0;
wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
wanted_spec.callback = sdl_audio_callback;
pkt->stream_index= is->video_stream;
packet_queue_put(&is->videoq, pkt);
}
+ if (is->audio_stream >= 0 &&
+ is->audio_st->codec->codec->capabilities & CODEC_CAP_DELAY) {
+ av_init_packet(pkt);
+ pkt->data = NULL;
+ pkt->size = 0;
+ pkt->stream_index = is->audio_stream;
+ packet_queue_put(&is->audioq, pkt);
+ }
SDL_Delay(10);
if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
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){
ret=AVERROR_EOF;
goto fail;
}
-static void toggle_full_screen(void)
+static void toggle_full_screen(VideoState *is)
{
is_full_screen = !is_full_screen;
- video_open(cur_stream);
+ video_open(is);
}
-static void toggle_pause(void)
+static void toggle_pause(VideoState *is)
{
- if (cur_stream)
- stream_toggle_pause(cur_stream);
- step = 0;
+ stream_toggle_pause(is);
+ is->step = 0;
}
-static void step_to_next_frame(void)
+static void step_to_next_frame(VideoState *is)
{
- if (cur_stream) {
- /* if the stream is paused unpause it, then step */
- if (cur_stream->paused)
- stream_toggle_pause(cur_stream);
- }
- step = 1;
+ /* if the stream is paused unpause it, then step */
+ if (is->paused)
+ stream_toggle_pause(is);
+ 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);
- cur_stream->show_mode = (cur_stream->show_mode + 1) % SHOW_MODE_NB;
- fill_rectangle(screen,
- cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height,
- bgcolor);
- SDL_UpdateRect(screen, cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height);
- }
+ int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
+ is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB;
+ fill_rectangle(screen,
+ is->xleft, is->ytop, is->width, is->height,
+ bgcolor);
+ SDL_UpdateRect(screen, is->xleft, is->ytop, is->width, is->height);
}
/* handle an event sent by the GUI */
-static void event_loop(void)
+static void event_loop(VideoState *cur_stream)
{
SDL_Event event;
double incr, pos, frac;
switch(event.type) {
case SDL_KEYDOWN:
if (exit_on_keydown) {
- do_exit();
+ do_exit(cur_stream);
break;
}
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
case SDLK_q:
- do_exit();
+ do_exit(cur_stream);
break;
case SDLK_f:
- toggle_full_screen();
+ toggle_full_screen(cur_stream);
break;
case SDLK_p:
case SDLK_SPACE:
- toggle_pause();
+ toggle_pause(cur_stream);
break;
case SDLK_s: //S: Step to next frame
- step_to_next_frame();
+ step_to_next_frame(cur_stream);
break;
case SDLK_a:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_AUDIO);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_AUDIO);
break;
case SDLK_v:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_VIDEO);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_VIDEO);
break;
case SDLK_t:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
break;
case SDLK_w:
- toggle_audio_display();
+ toggle_audio_display(cur_stream);
break;
case SDLK_LEFT:
incr = -10.0;
case SDLK_DOWN:
incr = -60.0;
do_seek:
- if (cur_stream) {
- if (seek_by_bytes) {
- if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos>=0){
- pos= cur_stream->video_current_pos;
- }else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){
- pos= cur_stream->audio_pkt.pos;
- }else
- pos = avio_tell(cur_stream->ic->pb);
- if (cur_stream->ic->bit_rate)
- incr *= cur_stream->ic->bit_rate / 8.0;
- else
- incr *= 180000.0;
- pos += incr;
- stream_seek(cur_stream, pos, incr, 1);
- } else {
- pos = get_master_clock(cur_stream);
- pos += incr;
- stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
- }
+ if (seek_by_bytes) {
+ if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos>=0){
+ pos= cur_stream->video_current_pos;
+ }else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){
+ pos= cur_stream->audio_pkt.pos;
+ }else
+ pos = avio_tell(cur_stream->ic->pb);
+ if (cur_stream->ic->bit_rate)
+ incr *= cur_stream->ic->bit_rate / 8.0;
+ else
+ incr *= 180000.0;
+ pos += incr;
+ stream_seek(cur_stream, pos, incr, 1);
+ } else {
+ pos = get_master_clock(cur_stream);
+ pos += incr;
+ stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
}
break;
default:
break;
case SDL_MOUSEBUTTONDOWN:
if (exit_on_mousedown) {
- do_exit();
+ do_exit(cur_stream);
break;
}
case SDL_MOUSEMOTION:
break;
x= event.motion.x;
}
- if (cur_stream) {
- if(seek_by_bytes || cur_stream->ic->duration<=0){
- uint64_t size= avio_size(cur_stream->ic->pb);
- stream_seek(cur_stream, size*x/cur_stream->width, 0, 1);
- }else{
- int64_t ts;
- 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 = x/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);
- ts = frac*cur_stream->ic->duration;
- if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
- ts += cur_stream->ic->start_time;
- stream_seek(cur_stream, ts, 0, 0);
- }
+ if(seek_by_bytes || cur_stream->ic->duration<=0){
+ uint64_t size= avio_size(cur_stream->ic->pb);
+ stream_seek(cur_stream, size*x/cur_stream->width, 0, 1);
+ }else{
+ int64_t ts;
+ 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 = x/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);
+ ts = frac*cur_stream->ic->duration;
+ if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
+ ts += cur_stream->ic->start_time;
+ stream_seek(cur_stream, ts, 0, 0);
}
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);
- screen_width = cur_stream->width = event.resize.w;
- screen_height= cur_stream->height= event.resize.h;
- }
+ screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
+ SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
+ screen_width = cur_stream->width = event.resize.w;
+ screen_height= cur_stream->height= event.resize.h;
break;
case SDL_QUIT:
case FF_QUIT_EVENT:
- do_exit();
+ do_exit(cur_stream);
break;
case FF_ALLOC_EVENT:
video_open(event.user.data1);
return 0;
}
-static int opt_thread_count(const char *opt, const char *arg)
-{
- thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-#if !HAVE_THREADS
- fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
-#endif
- return 0;
-}
-
static int opt_show_mode(const char *opt, const char *arg)
{
show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO :
return 0;
}
-static int opt_input_file(const char *opt, const char *filename)
+static void opt_input_file(void *optctx, const char *filename)
{
if (input_filename) {
fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
filename, input_filename);
- exit(1);
+ exit_program(1);
}
if (!strcmp(filename, "-"))
filename = "pipe:";
input_filename = filename;
- return 0;
}
+static int dummy;
+
static const OptionDef options[] = {
#include "cmdutils_common_opts.h"
{ "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
{ "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_recognition}, "set error detection threshold (0-4)", "threshold" },
{ "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" },
{ "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" },
{ "autoexit", OPT_BOOL | OPT_EXPERT, {(void*)&autoexit}, "exit at the end", "" },
{ "exitonkeydown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_keydown}, "exit on key down", "" },
{ "exitonmousedown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_mousedown}, "exit on mouse down", "" },
{ "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, {(void*)&rdftspeed}, "rdft speed", "msecs" },
{ "showmode", HAS_ARG, {(void*)opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
- { "i", HAS_ARG, {(void *)opt_input_file}, "read specified file", "input_file"},
+ { "i", OPT_BOOL, {(void *)&dummy}, "read specified file", "input_file"},
{ NULL, },
};
static void show_usage(void)
{
printf("Simple media player\n");
- printf("usage: ffplay [options] input_file\n");
+ printf("usage: %s [options] input_file\n", program_name);
printf("\n");
}
static int opt_help(const char *opt, const char *arg)
{
+ const AVClass *class;
av_log_set_callback(log_callback_help);
show_usage();
show_help_options(options, "Main options:\n",
show_help_options(options, "\nAdvanced options:\n",
OPT_EXPERT, OPT_EXPERT);
printf("\n");
- av_opt_show2(avcodec_opts[0], NULL,
+ class = avcodec_get_class();
+ av_opt_show2(&class, NULL,
AV_OPT_FLAG_DECODING_PARAM, 0);
printf("\n");
- av_opt_show2(avformat_opts, NULL,
+ class = avformat_get_class();
+ av_opt_show2(&class, NULL,
AV_OPT_FLAG_DECODING_PARAM, 0);
#if !CONFIG_AVFILTER
printf("\n");
- av_opt_show2(sws_opts, NULL,
+ class = sws_get_class();
+ av_opt_show2(&class, NULL,
AV_OPT_FLAG_ENCODING_PARAM, 0);
#endif
printf("\nWhile playing:\n"
return 0;
}
+static int lockmgr(void **mtx, enum AVLockOp op)
+{
+ switch(op) {
+ case AV_LOCK_CREATE:
+ *mtx = SDL_CreateMutex();
+ if(!*mtx)
+ return 1;
+ return 0;
+ case AV_LOCK_OBTAIN:
+ return !!SDL_LockMutex(*mtx);
+ case AV_LOCK_RELEASE:
+ return !!SDL_UnlockMutex(*mtx);
+ case AV_LOCK_DESTROY:
+ SDL_DestroyMutex(*mtx);
+ return 0;
+ }
+ return 1;
+}
+
/* Called from the main */
int main(int argc, char **argv)
{
int flags;
+ VideoState *is;
av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ parse_loglevel(argc, argv, options);
/* register all codecs, demux and protocols */
avcodec_register_all();
show_banner();
- parse_options(argc, argv, options, opt_input_file);
+ parse_options(NULL, argc, argv, options, opt_input_file);
if (!input_filename) {
show_usage();
fprintf(stderr, "An input file must be specified\n");
- fprintf(stderr, "Use -h to get full help or, even better, run 'man ffplay'\n");
+ fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
exit(1);
}
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+ if (av_lockmgr_register(lockmgr)) {
+ fprintf(stderr, "Could not initialize lock manager!\n");
+ do_exit(NULL);
+ }
+
av_init_packet(&flush_pkt);
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 */