X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=ffplay.c;h=804bcbc33f07e4a8141bb56360deeba492d374b1;hb=9f36ea57ae6eefb42432220feab0350494f4144c;hp=ade515910fa4f1a4afe76d5822b80015d9a628be;hpb=7916f04b89d4e970f17a14776b71b8c61c2b117d;p=ffmpeg diff --git a/ffplay.c b/ffplay.c index ade515910fa..804bcbc33f0 100644 --- a/ffplay.c +++ b/ffplay.c @@ -243,7 +243,6 @@ typedef struct VideoState { AVStream *audio_st; PacketQueue audioq; int audio_hw_buf_size; - uint8_t silence_buf[SDL_AUDIO_MIN_BUFFER_SIZE]; uint8_t *audio_buf; uint8_t *audio_buf1; unsigned int audio_buf_size; /* in bytes */ @@ -642,6 +641,7 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) { static void decoder_destroy(Decoder *d) { av_packet_unref(&d->pkt); + avcodec_free_context(&d->avctx); } static void frame_queue_unref_item(Frame *vp) @@ -1140,13 +1140,13 @@ static void video_audio_display(VideoState *s) 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(); @@ -1176,8 +1176,7 @@ static void stream_component_close(VideoState *is, int stream_index) } 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; @@ -1653,8 +1652,8 @@ display: 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; } @@ -1906,7 +1905,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c 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; @@ -1925,7 +1924,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c "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); @@ -2541,8 +2540,8 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) audio_size = audio_decode_frame(is); if (audio_size < 0) { /* if error, just output silence */ - is->audio_buf = is->silence_buf; - is->audio_buf_size = sizeof(is->silence_buf) / is->audio_tgt.frame_size * is->audio_tgt.frame_size; + is->audio_buf = NULL; + is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE / is->audio_tgt.frame_size * is->audio_tgt.frame_size; } else { if (is->show_mode != SHOW_MODE_VIDEO) update_sample_display(is, (int16_t *)is->audio_buf, audio_size); @@ -2553,11 +2552,11 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) len1 = is->audio_buf_size - is->audio_buf_index; if (len1 > len) len1 = len; - if (!is->muted && is->audio_volume == SDL_MIX_MAXVOLUME) + if (!is->muted && is->audio_buf && is->audio_volume == SDL_MIX_MAXVOLUME) memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1); else { - memset(stream, is->silence_buf[0], len1); - if (!is->muted) + memset(stream, 0, len1); + if (!is->muted && is->audio_buf) SDL_MixAudio(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1, is->audio_volume); } len -= len1; @@ -2652,7 +2651,7 @@ static int stream_component_open(VideoState *is, int stream_index) 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; @@ -2661,7 +2660,15 @@ static int stream_component_open(VideoState *is, int stream_index) 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); @@ -2677,7 +2684,8 @@ static int stream_component_open(VideoState *is, int stream_index) "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; @@ -2763,7 +2771,7 @@ static int stream_component_open(VideoState *is, int stream_index) 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: @@ -2775,7 +2783,7 @@ static int stream_component_open(VideoState *is, int stream_index) 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: @@ -2784,13 +2792,16 @@ static int stream_component_open(VideoState *is, int stream_index) 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; @@ -2929,7 +2940,7 @@ static int read_thread(void *arg) 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) @@ -2964,10 +2975,10 @@ static int read_thread(void *arg) 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 */ @@ -3241,12 +3252,12 @@ static void stream_cycle_channel(VideoState *is, int codec_type) 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: