[FFmpeg-devel] [PATCH 3/6] libavformat: Add a function for freeing an AVFormatContext

Martin Storsjö martin
Thu Feb 3 13:10:14 CET 2011


This function is useful for freeing data structures allocated by
muxers, which currently have to be freed manually by the caller.
---
 libavformat/avformat.h |    6 ++++++
 libavformat/utils.c    |   11 ++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index f9f9be5..1cbe274 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1230,6 +1230,12 @@ void av_close_input_stream(AVFormatContext *s);
 void av_close_input_file(AVFormatContext *s);
 
 /**
+ * Free an AVFormatContext and all its streams.
+ * @param s context to free
+ */
+void av_free_context(AVFormatContext *s);
+
+/**
  * Add a new stream to a media file.
  *
  * Can only be called in the read_header() function. If the flag
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4f51c26..2d0dea5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2541,12 +2541,17 @@ int av_read_pause(AVFormatContext *s)
 
 void av_close_input_stream(AVFormatContext *s)
 {
-    int i;
-    AVStream *st;
-
     flush_packet_queue(s);
     if (s->iformat->read_close)
         s->iformat->read_close(s);
+    av_free_context(s);
+}
+
+void av_free_context(AVFormatContext *s)
+{
+    int i;
+    AVStream *st;
+
     for(i=0;i<s->nb_streams;i++) {
         /* free all data in a stream component */
         st = s->streams[i];
-- 
1.7.3.1




More information about the ffmpeg-devel mailing list