[FFmpeg-devel] [RFC] missing close/free functions for avformat?

Reimar Döffinger Reimar.Doeffinger
Sat Dec 15 20:32:53 CET 2007


Hello,
On Sat, Dec 15, 2007 at 08:03:23PM +0100, Michael Niedermayer wrote:
> On Sat, Dec 15, 2007 at 06:21:40PM +0100, matthieu castet wrote:
> > Michael Niedermayer wrote:
> > > On Sat, Dec 15, 2007 at 05:28:51PM +0100, Reimar D?ffinger wrote:
> > >> unless I missed something there are no corresponding close/free
> > >> functions for av_alloc_format_context and av_open_input_stream.
> > >> But these are part of the public API, what use are they if there
> > >> is no proper way in freeing the allocated memory...
> > >> It actually seems to me that almost everything except the url_fclose
> > >> should go into a av_free_format_context, do you agree with that?
> > > 
> > > have you tried:
> > > 
> > > av_open_input_stream()    - av_close_input_file
> > > 
> > This doesn't seem to work because av_close_input_file call url_fclose. 
> > see [1].
> 
> well then make it work, or write a av_close_input_stream() or a universal
> av_close_avfomatcontext()

It's untested, but does something like this look good?

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/utils.c
===================================================================
--- libavformat/utils.c	(revision 11224)
+++ libavformat/utils.c	(working copy)
@@ -2042,9 +2041,9 @@
     return s->iformat->read_pause(s);
 }
 
-void av_close_input_file(AVFormatContext *s)
+void av_close_input_stream(AVFormatContext *s)
 {
-    int i, must_open_file;
+    int i;
     AVStream *st;
 
     /* free previous packet */
@@ -2071,17 +2070,19 @@
         av_freep(&s->programs[i]);
     }
     flush_packet_queue(s);
-    must_open_file = 1;
-    if (s->iformat->flags & AVFMT_NOFILE) {
-        must_open_file = 0;
-    }
-    if (must_open_file) {
-        url_fclose(s->pb);
-    }
     av_freep(&s->priv_data);
     av_free(s);
 }
 
+void av_close_input_file(AVFormatContext *s)
+{
+    ByteIOContext *pb = s->pb;
+    int must_open_file = !(s->iformat->flags & AVFMT_NOFILE);
+    av_close_input_stream(s);
+    if (must_open_file)
+        url_fclose(pb);
+}
+
 AVStream *av_new_stream(AVFormatContext *s, int id)
 {
     AVStream *st;



More information about the ffmpeg-devel mailing list