[FFmpeg-cvslog] lavc: free the output packet when encoding failed or produced no output.
Anton Khirnov
git at videolan.org
Sun Mar 4 04:47:42 CET 2012
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Feb 24 13:14:02 2012 +0100| [7fb6c9225c309c55b85f6974627e26976817bff5] | committer: Anton Khirnov
lavc: free the output packet when encoding failed or produced no output.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7fb6c9225c309c55b85f6974627e26976817bff5
---
libavcodec/avcodec.h | 8 ++++++++
libavcodec/utils.c | 8 ++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 19f114f..3598aaa 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3788,6 +3788,10 @@ int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx,
* avpkt->data is NULL, the encoder will allocate it.
* The encoder will set avpkt->size to the size of the
* output packet.
+ *
+ * If this function fails or produces no output, avpkt will be
+ * freed using av_free_packet() (i.e. avpkt->destruct will be
+ * called to free the user supplied buffer).
* @param[in] frame AVFrame containing the raw audio data to be encoded.
* May be NULL when flushing an encoder that has the
* CODEC_CAP_DELAY capability set.
@@ -3870,6 +3874,10 @@ int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
* The encoder will set avpkt->size to the size of the
* output packet. The returned data (if any) belongs to the
* caller, he is responsible for freeing it.
+ *
+ * If this function fails or produces no output, avpkt will be
+ * freed using av_free_packet() (i.e. avpkt->destruct will be
+ * called to free the user supplied buffer).
* @param[in] frame AVFrame containing the raw video data to be encoded.
* May be NULL when flushing an encoder that has the
* CODEC_CAP_DELAY capability set.
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a91eab1..f9927a1 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -864,6 +864,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
*got_packet_ptr = 0;
if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
+ av_free_packet(avpkt);
av_init_packet(avpkt);
avpkt->size = 0;
return 0;
@@ -962,6 +963,9 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
if (!ret)
avctx->frame_number++;
+ if (ret < 0 || !*got_packet_ptr)
+ av_free_packet(avpkt);
+
/* NOTE: if we add any audio encoders which output non-keyframe packets,
this needs to be moved to the encoders, but for now we can do it
here to simplify things */
@@ -1095,6 +1099,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
*got_packet_ptr = 0;
if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
+ av_free_packet(avpkt);
av_init_packet(avpkt);
avpkt->size = 0;
return 0;
@@ -1121,6 +1126,9 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avctx->frame_number++;
}
+ if (ret < 0 || !*got_packet_ptr)
+ av_free_packet(avpkt);
+
emms_c();
return ret;
}
More information about the ffmpeg-cvslog
mailing list