@@ -982,6 +982,11 @@ typedef struct RcOverride{
* Do not reset ASS ReadOrder field on flush (subtitles decoding)
*/
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP (1 << 30)
+/**
+ * Closing the codec doesnt release the context priv_data (it becomes
the codec
+ * responsibility)
+ */
+#define AV_CODEC_FLAG2_PRESERVE_PRIVDATA_ONCLOSE (1 << 31)
/* Unsupported options :
* Syntax Arithmetic coding (SAC)
@@ -1211,7 +1211,9 @@ av_cold int avcodec_close(AVCodecContext *avctx)
if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
av_opt_free(avctx->priv_data);
av_opt_free(avctx);
- av_freep(&avctx->priv_data);
+ if (!(avctx->flags2 & AV_CODEC_FLAG2_PRESERVE_PRIVDATA_ONCLOSE))
+ av_freep(&avctx->priv_data);
+
if (av_codec_is_encoder(avctx->codec)) {
av_freep(&avctx->extradata);
#if FF_API_CODED_FRAME