obs-ffmpeg, win-dshow, deps/media-playback: Use recommended API for AVCodecContext

master
wangshaohui 2022-04-01 11:20:43 +08:00 committed by Jim
parent 1ec70ddf2b
commit db8145e8a2
7 changed files with 12 additions and 24 deletions

View File

@ -113,7 +113,8 @@ static int mp_open_codec(struct mp_decode *d, bool hw)
return ret;
fail:
avcodec_close(c);
avcodec_free_context(&c);
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
av_free(d->decoder);
#endif
@ -220,13 +221,10 @@ void mp_decode_free(struct mp_decode *d)
av_frame_unref(d->hw_frame);
av_free(d->hw_frame);
}
if (d->decoder) {
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
if (d->decoder)
avcodec_free_context(&d->decoder);
#else
avcodec_close(d->decoder);
#endif
}
if (d->sw_frame) {
av_frame_unref(d->sw_frame);
av_free(d->sw_frame);

View File

@ -72,11 +72,7 @@ static bool ffmpeg_image_open_decoder_context(struct ffmpeg_image *info)
static void ffmpeg_image_free(struct ffmpeg_image *info)
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
avcodec_free_context(&info->decoder_ctx);
#else
avcodec_close(info->decoder_ctx);
#endif
avformat_close_input(&info->fmt_ctx);
}

View File

@ -150,6 +150,7 @@ static void free_avformat(struct ffmpeg_mux *ffm)
if (ffm->audio_infos) {
for (int i = 0; i < ffm->num_audio_streams; ++i)
avcodec_free_context(&ffm->audio_infos[i].ctx);
free(ffm->audio_infos);
}

View File

@ -124,8 +124,10 @@ static void enc_destroy(void *data)
if (enc->samples[0])
av_freep(&enc->samples[0]);
if (enc->context)
avcodec_close(enc->context);
avcodec_free_context(&enc->context);
if (enc->aframe)
av_frame_free(&enc->aframe);

View File

@ -358,7 +358,7 @@ static void nvenc_destroy(void *data)
flush_remaining_packets(enc);
av_packet_free(&enc->packet);
avcodec_close(enc->context);
avcodec_free_context(&enc->context);
av_frame_unref(enc->vframe);
av_frame_free(&enc->vframe);
da_free(enc->buffer);

View File

@ -457,11 +457,7 @@ static inline bool open_output_file(struct ffmpeg_data *data)
static void close_video(struct ffmpeg_data *data)
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
avcodec_free_context(&data->video_ctx);
#else
avcodec_close(data->video->codec);
#endif
av_frame_unref(data->vframe);
// This format for some reason derefs video frame
@ -481,13 +477,8 @@ static void close_audio(struct ffmpeg_data *data)
if (data->samples[idx][0])
av_freep(&data->samples[idx][0]);
if (data->audio_infos[idx].ctx) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
if (data->audio_infos[idx].ctx)
avcodec_free_context(&data->audio_infos[idx].ctx);
#else
avcodec_close(data->audio_infos[idx].stream->codec);
#endif
}
if (data->aframe[idx])
av_frame_free(&data->aframe[idx]);
}

View File

@ -329,7 +329,7 @@ static void vaapi_destroy(void *data)
flush_remaining_packets(enc);
av_packet_free(&enc->packet);
avcodec_close(enc->context);
avcodec_free_context(&enc->context);
av_frame_unref(enc->vframe);
av_frame_free(&enc->vframe);
av_buffer_unref(&enc->vaframes_ref);