summaryrefslogtreecommitdiff
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-07-15 18:41:20 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-07-20 14:16:15 +0100
commitd6604b29ef544793479d7fb4e05ef6622bb3e534 (patch)
tree37d5559063e276f17da8036e4c08bb8aa4b05534 /libavcodec/utils.c
parent91f9b6579ac684c4b51c4cd0dbaed0a4f8295edf (diff)
downloadffmpeg-d6604b29ef544793479d7fb4e05ef6622bb3e534.tar.gz
Gather all coded_frame allocations and free functions to a single place
Allocating coded_frame is what most encoders do anyway, so it makes sense to always allocate and free it in a single place. Moreover a lot of encoders freed the frame with av_freep() instead of the correct API av_frame_free(). This bring uniformity to encoder behaviour and prevents applications from erroneusly accessing this field when not allocated. Additionally this helps isolating encoders that export information with coded_frame, and heavily simplifies its deprecation. Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a1443920e3..d038e90852 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1169,6 +1169,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
if (av_codec_is_encoder(avctx->codec)) {
int i;
+ avctx->coded_frame = av_frame_alloc();
+ if (!avctx->coded_frame) {
+ ret = AVERROR(ENOMEM);
+ goto free_and_end;
+ }
if (avctx->codec->sample_fmts) {
for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
@@ -1296,6 +1301,8 @@ free_and_end:
av_opt_free(avctx->priv_data);
av_opt_free(avctx);
+ av_frame_free(&avctx->coded_frame);
+
av_dict_free(&tmp);
av_freep(&avctx->priv_data);
if (avctx->internal) {
@@ -1797,7 +1804,6 @@ av_cold int avcodec_close(AVCodecContext *avctx)
ff_thread_free(avctx);
if (avctx->codec && avctx->codec->close)
avctx->codec->close(avctx);
- avctx->coded_frame = NULL;
av_frame_free(&avctx->internal->to_free);
for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
av_buffer_pool_uninit(&pool->pools[i]);
@@ -1814,8 +1820,10 @@ av_cold int avcodec_close(AVCodecContext *avctx)
av_opt_free(avctx->priv_data);
av_opt_free(avctx);
av_freep(&avctx->priv_data);
- if (av_codec_is_encoder(avctx->codec))
+ if (av_codec_is_encoder(avctx->codec)) {
av_freep(&avctx->extradata);
+ av_frame_free(&avctx->coded_frame);
+ }
avctx->codec = NULL;
avctx->active_thread_type = 0;