summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/decode/ad_spdif.c5
-rw-r--r--audio/filter/af_lavcac3enc.c5
-rw-r--r--common/encode_lavc.c10
-rw-r--r--demux/demux_mkv.c6
-rw-r--r--sub/sd_lavc.c4
-rw-r--r--video/image_writer.c4
6 files changed, 7 insertions, 27 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 78e4c4e976..4b3e8149ec 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -137,11 +137,8 @@ static void determine_codec_params(struct dec_audio *da, AVPacket *pkt,
if (!ctx)
goto done;
- if (avcodec_open2(ctx, codec, NULL) < 0) {
- av_free(ctx); // don't attempt to avcodec_close() an unopened ctx
- ctx = NULL;
+ if (avcodec_open2(ctx, codec, NULL) < 0)
goto done;
- }
if (avcodec_send_packet(ctx, pkt) < 0)
goto done;
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index d5c2d25ad2..33e685eddb 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -192,10 +192,7 @@ static void uninit(struct af_instance* af)
af_ac3enc_t *s = af->priv;
if (s) {
- if(s->lavc_actx) {
- avcodec_close(s->lavc_actx);
- av_free(s->lavc_actx);
- }
+ avcodec_free_context(&s->lavc_actx);
talloc_free(s->pending);
}
}
diff --git a/common/encode_lavc.c b/common/encode_lavc.c
index 2ae9eef6bd..dca8f8b0e7 100644
--- a/common/encode_lavc.c
+++ b/common/encode_lavc.c
@@ -384,10 +384,7 @@ void encode_lavc_finish(struct encode_lavc_context *ctx)
stream_write_buffer(ctx->twopass_bytebuffer_v,
stats, strlen(stats));
}
- avcodec_close(ctx->vcc);
- talloc_free(ctx->vcc->stats_in);
- av_free(ctx->vcc);
- ctx->vcc = NULL;
+ avcodec_free_context(&ctx->vcc);
}
if (ctx->acc) {
@@ -397,10 +394,7 @@ void encode_lavc_finish(struct encode_lavc_context *ctx)
stream_write_buffer(ctx->twopass_bytebuffer_a,
stats, strlen(stats));
}
- avcodec_close(ctx->acc);
- talloc_free(ctx->acc->stats_in);
- av_free(ctx->acc);
- ctx->acc = NULL;
+ avcodec_free_context(&ctx->acc);
}
for (i = 0; i < ctx->avc->nb_streams; i++) {
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index a45793ca13..c3ffdac6b2 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -2239,11 +2239,7 @@ static void mkv_seek_reset(demuxer_t *demuxer)
if (track->av_parser)
av_parser_close(track->av_parser);
track->av_parser = NULL;
- if (track->av_parser_codec) {
- avcodec_close(track->av_parser_codec);
- av_free(track->av_parser_codec);
- }
- track->av_parser_codec = NULL;
+ avcodec_free_context(&track->av_parser_codec);
}
free_block(&mkv_d->tmp_block);
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 169a2883df..e805d5c34c 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -500,9 +500,7 @@ static void uninit(struct sd *sd)
for (int n = 0; n < MAX_QUEUE; n++)
clear_sub(&priv->subs[n]);
- avcodec_close(priv->avctx);
- av_free(priv->avctx->extradata);
- av_free(priv->avctx);
+ avcodec_free_context(&priv->avctx);
talloc_free(priv);
}
diff --git a/video/image_writer.c b/video/image_writer.c
index ec5f578e2b..6fc933e34d 100644
--- a/video/image_writer.c
+++ b/video/image_writer.c
@@ -160,9 +160,7 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp
success = !!got_output;
error_exit:
- if (avctx)
- avcodec_close(avctx);
- av_free(avctx);
+ avcodec_free_context(&avctx);
av_frame_free(&pic);
av_packet_unref(&pkt);
return success;