static void decoder_destroy(Decoder *d) {
av_packet_unref(&d->pkt);
+ avcodec_free_context(&d->avctx);
}
static void frame_queue_unref_item(Frame *vp)
SDL_UnlockMutex(f->mutex);
}
-/* jump back to the previous frame if available by resetting rindex_shown */
-static int frame_queue_prev(FrameQueue *f)
-{
- int ret = f->rindex_shown;
- f->rindex_shown = 0;
- return ret;
-}
-
/* return the number of undisplayed frames in the queue */
static int frame_queue_nb_remaining(FrameQueue *f)
{
SDL_Rect rect;
int i;
- vp = frame_queue_peek(&is->pictq);
+ vp = frame_queue_peek_last(&is->pictq);
if (vp->bmp) {
if (is->subtitle_st) {
if (frame_queue_nb_remaining(&is->subpq) > 0) {
static void stream_component_close(VideoState *is, int stream_index)
{
AVFormatContext *ic = is->ic;
- AVCodecContext *avctx;
+ AVCodecParameters *codecpar;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return;
- avctx = ic->streams[stream_index]->codec;
+ codecpar = ic->streams[stream_index]->codecpar;
- switch (avctx->codec_type) {
+ switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
decoder_abort(&is->auddec, &is->sampq);
SDL_CloseAudio();
}
ic->streams[stream_index]->discard = AVDISCARD_ALL;
- avcodec_close(avctx);
- switch (avctx->codec_type) {
+ switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
is->audio_st = NULL;
is->audio_stream = -1;
}
if (is->video_st) {
- int redisplay = 0;
- if (is->force_refresh)
- redisplay = frame_queue_prev(&is->pictq);
retry:
if (frame_queue_nb_remaining(&is->pictq) == 0) {
// nothing to do, no picture to display in the queue
if (vp->serial != is->videoq.serial) {
frame_queue_next(&is->pictq);
- redisplay = 0;
goto retry;
}
- if (lastvp->serial != vp->serial && !redisplay)
+ if (lastvp->serial != vp->serial)
is->frame_timer = av_gettime_relative() / 1000000.0;
if (is->paused)
/* compute nominal last_duration */
last_duration = vp_duration(is, lastvp, vp);
- if (redisplay)
- delay = 0.0;
- else
- delay = compute_target_delay(last_duration, is);
+ delay = compute_target_delay(last_duration, is);
time= av_gettime_relative()/1000000.0;
- if (time < is->frame_timer + delay && !redisplay) {
+ if (time < is->frame_timer + delay) {
*remaining_time = FFMIN(is->frame_timer + delay - time, *remaining_time);
- return;
+ goto display;
}
is->frame_timer += delay;
is->frame_timer = time;
SDL_LockMutex(is->pictq.mutex);
- if (!redisplay && !isnan(vp->pts))
+ if (!isnan(vp->pts))
update_video_pts(is, vp->pts, vp->pos, vp->serial);
SDL_UnlockMutex(is->pictq.mutex);
if (frame_queue_nb_remaining(&is->pictq) > 1) {
Frame *nextvp = frame_queue_peek_next(&is->pictq);
duration = vp_duration(is, vp, nextvp);
- if(!is->step && (redisplay || framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){
- if (!redisplay)
- is->frame_drops_late++;
+ if(!is->step && (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){
+ is->frame_drops_late++;
frame_queue_next(&is->pictq);
- redisplay = 0;
goto retry;
}
}
}
}
-display:
- /* display picture */
- if (!display_disable && is->show_mode == SHOW_MODE_VIDEO)
- video_display(is);
-
frame_queue_next(&is->pictq);
+ is->force_refresh = 1;
if (is->step && !is->paused)
stream_toggle_pause(is);
}
+display:
+ /* display picture */
+ if (!display_disable && is->force_refresh && is->show_mode == SHOW_MODE_VIDEO && is->pictq.rindex_shown)
+ video_display(is);
}
is->force_refresh = 0;
if (show_status) {
aqsize / 1024,
vqsize / 1024,
sqsize,
- is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0,
- is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0);
+ is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
+ is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
fflush(stdout);
last_time = cur_time;
}
char buffersrc_args[256];
int ret;
AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
- AVCodecContext *codec = is->video_st->codec;
+ AVCodecParameters *codecpar = is->video_st->codecpar;
AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
AVDictionaryEntry *e = NULL;
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
frame->width, frame->height, frame->format,
is->video_st->time_base.num, is->video_st->time_base.den,
- codec->sample_aspect_ratio.num, FFMAX(codec->sample_aspect_ratio.den, 1));
+ codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1));
if (fr.num && fr.den)
av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
AVCodecContext *avctx;
AVCodec *codec;
const char *forced_codec_name = NULL;
- AVDictionary *opts;
+ AVDictionary *opts = NULL;
AVDictionaryEntry *t = NULL;
int sample_rate, nb_channels;
int64_t channel_layout;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return -1;
- avctx = ic->streams[stream_index]->codec;
+
+ avctx = avcodec_alloc_context3(NULL);
+ if (!avctx)
+ return AVERROR(ENOMEM);
+
+ ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar);
+ if (ret < 0)
+ goto fail;
+ av_codec_set_pkt_timebase(avctx, ic->streams[stream_index]->time_base);
codec = avcodec_find_decoder(avctx->codec_id);
"No codec could be found with name '%s'\n", forced_codec_name);
else av_log(NULL, AV_LOG_WARNING,
"No codec could be found with id %d\n", avctx->codec_id);
- return -1;
+ ret = AVERROR(EINVAL);
+ goto fail;
}
avctx->codec_id = codec->id;
is->auddec.start_pts_tb = is->audio_st->time_base;
}
if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0)
- goto fail;
+ goto out;
SDL_PauseAudio(0);
break;
case AVMEDIA_TYPE_VIDEO:
decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread);
if ((ret = decoder_start(&is->viddec, video_thread, is)) < 0)
- goto fail;
+ goto out;
is->queue_attachments_req = 1;
break;
case AVMEDIA_TYPE_SUBTITLE:
decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread);
if ((ret = decoder_start(&is->subdec, subtitle_thread, is)) < 0)
- goto fail;
+ goto out;
break;
default:
break;
}
+ goto out;
fail:
+ avcodec_free_context(&avctx);
+out:
av_dict_free(&opts);
return ret;
for (i = 0; i < ic->nb_streams; i++) {
AVStream *st = ic->streams[i];
- enum AVMediaType type = st->codec->codec_type;
+ enum AVMediaType type = st->codecpar->codec_type;
st->discard = AVDISCARD_ALL;
if (wanted_stream_spec[type] && st_index[type] == -1)
if (avformat_match_stream_specifier(ic, st, wanted_stream_spec[type]) > 0)
is->show_mode = show_mode;
if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
AVStream *st = ic->streams[st_index[AVMEDIA_TYPE_VIDEO]];
- AVCodecContext *avctx = st->codec;
+ AVCodecParameters *codecpar = st->codecpar;
AVRational sar = av_guess_sample_aspect_ratio(ic, st, NULL);
- if (avctx->width)
- set_default_window_size(avctx->width, avctx->height, sar);
+ if (codecpar->width)
+ set_default_window_size(codecpar->width, codecpar->height, sar);
}
/* open the streams */
if (stream_index == start_index)
return;
st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index];
- if (st->codec->codec_type == codec_type) {
+ if (st->codecpar->codec_type == codec_type) {
/* check that parameters are OK */
switch (codec_type) {
case AVMEDIA_TYPE_AUDIO:
- if (st->codec->sample_rate != 0 &&
- st->codec->channels != 0)
+ if (st->codecpar->sample_rate != 0 &&
+ st->codecpar->channels != 0)
goto the_end;
break;
case AVMEDIA_TYPE_VIDEO:
int flags;
VideoState *is;
char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
+ char alsa_bufsize[] = "SDL_AUDIO_ALSA_SET_BUFFER_SIZE=1";
av_log_set_flags(AV_LOG_SKIP_REPEATED);
parse_loglevel(argc, argv, options);
flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
if (audio_disable)
flags &= ~SDL_INIT_AUDIO;
+ else {
+ /* Try to work around an occasional ALSA buffer underflow issue when the
+ * period size is NPOT due to ALSA resampling by forcing the buffer size. */
+ if (!SDL_getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"))
+ SDL_putenv(alsa_bufsize);
+ }
if (display_disable)
SDL_putenv(dummy_videodriver); /* For the event queue, we always need a video driver. */
#if !defined(_WIN32) && !defined(__APPLE__)