This is not implemented for all codecs because there might be encoders
that reference internal internal frames via coded_frame.
Also is change affects encoders only since decoders should not use this
context field.

Signed-off-by: Vittorio Giovara <[email protected]>
---
If the idea is sound, I'll add this capability to the various encoders
that would benefit from this.
Vittorio

 libavcodec/internal.h | 5 +++++
 libavcodec/utils.c    | 6 ++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 6f15a78..0304874 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -46,6 +46,11 @@
  * all.
  */
 #define FF_CODEC_CAP_INIT_CLEANUP           (1 << 1)
+/**
+ * The codec will free the context coded_frame in avcodec_close(),
+ * if it is an encoder.
+ */
+#define FF_CODEC_CAP_CLOSE_CODEDFRAME       (1 << 2)
 
 
 #ifdef DEBUG
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f1acd78..129e8d0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1792,7 +1792,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]);
@@ -1809,8 +1808,11 @@ 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);
+        if (avctx->codec->caps_internal & FF_CODEC_CAP_CLOSE_CODEDFRAME)
+            av_frame_free(&avctx->coded_frame);
+    }
     avctx->codec = NULL;
     avctx->active_thread_type = 0;
 
-- 
1.9.5 (Apple Git-50.3)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to