[FFmpeg-cvslog] lavc: add avcodec_free_frame().

Anton Khirnov git at videolan.org
Tue Sep 25 15:19:14 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Sep 21 09:07:02 2012 +0200| [a42aadabc64f50124eece6e37e63eafa46e1a6ce] | committer: Anton Khirnov

lavc: add avcodec_free_frame().

Since an AVFrame now has malloced members (extended_data), it must have
a destructor.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a42aadabc64f50124eece6e37e63eafa46e1a6ce
---

 doc/APIchanges       |    4 ++++
 libavcodec/avcodec.h |   14 +++++++++++++-
 libavcodec/utils.c   |   15 +++++++++++++++
 libavcodec/version.h |    2 +-
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 48fe097..4558ca7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-09-23 - xxxxxxx - lavc 54.28.0 - avcodec.h
+  Add avcodec_free_frame(). This function must now
+  be used for freeing an AVFrame.
+
 2012-09-12 - xxxxxxx - lavu 51.41.0 - audioconvert.h
   Added AV_CH_LOW_FREQUENCY_2 channel mask value.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2bb308f..a89805e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3257,7 +3257,7 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
 
 /**
  * Allocate an AVFrame and set its fields to default values.  The resulting
- * struct can be deallocated by simply calling av_free().
+ * struct must be freed using avcodec_free_frame().
  *
  * @return An AVFrame filled with default values or NULL on failure.
  * @see avcodec_get_frame_defaults
@@ -3272,6 +3272,18 @@ AVFrame *avcodec_alloc_frame(void);
 void avcodec_get_frame_defaults(AVFrame *frame);
 
 /**
+ * Free the frame and any dynamically allocated objects in it,
+ * e.g. extended_data.
+ *
+ * @param frame frame to be freed. The pointer will be set to NULL.
+ *
+ * @warning this function does NOT free the data buffers themselves
+ * (it does not know how, since they might have been allocated with
+ *  a custom get_buffer()).
+ */
+void avcodec_free_frame(AVFrame **frame);
+
+/**
  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  * function the context has to be allocated with avcodec_alloc_context3().
  *
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c2e16c4..0e4048e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -659,6 +659,21 @@ AVFrame *avcodec_alloc_frame(void)
     return frame;
 }
 
+void avcodec_free_frame(AVFrame **frame)
+{
+    AVFrame *f;
+
+    if (!frame || !*frame)
+        return;
+
+    f = *frame;
+
+    if (f->extended_data != f->data)
+        av_freep(&f->extended_data);
+
+    av_freep(frame);
+}
+
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
 {
     int ret = 0;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index b08f00d..c532868 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -27,7 +27,7 @@
  */
 
 #define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 27
+#define LIBAVCODEC_VERSION_MINOR 28
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list