[FFmpeg-cvslog] lavf: factor ff_free_stream() out

Michael Niedermayer git at videolan.org
Tue Aug 21 06:22:23 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Aug 21 06:13:54 2012 +0200| [85a576775e1da9f22058aecd1924762e62a29867] | committer: Michael Niedermayer

lavf: factor ff_free_stream() out

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/internal.h |    2 ++
 libavformat/utils.c    |   37 +++++++++++++++++++++----------------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 56bf2b0..cd91eb1 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -344,4 +344,6 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
                                  AVPacket *pkt, int flush);
 
+void ff_free_stream(AVFormatContext *s, AVStream *st);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index bf8cba4..38d2e08 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2996,6 +2996,25 @@ int av_read_pause(AVFormatContext *s)
     return AVERROR(ENOSYS);
 }
 
+void ff_free_stream(AVFormatContext *s, AVStream *st){
+    av_assert0(s->nb_streams>0);
+    av_assert0(s->streams[ s->nb_streams-1 ] == st);
+
+    if (st->parser) {
+        av_parser_close(st->parser);
+    }
+    if (st->attached_pic.data)
+        av_free_packet(&st->attached_pic);
+    av_dict_free(&st->metadata);
+    av_freep(&st->index_entries);
+    av_freep(&st->codec->extradata);
+    av_freep(&st->codec->subtitle_header);
+    av_freep(&st->codec);
+    av_freep(&st->priv_data);
+    av_freep(&st->info);
+    av_freep(&s->streams[ --s->nb_streams ]);
+}
+
 void avformat_free_context(AVFormatContext *s)
 {
     int i;
@@ -3005,22 +3024,8 @@ void avformat_free_context(AVFormatContext *s)
     if (s->iformat && s->iformat->priv_class && s->priv_data)
         av_opt_free(s->priv_data);
 
-    for(i=0;i<s->nb_streams;i++) {
-        /* free all data in a stream component */
-        st = s->streams[i];
-        if (st->parser) {
-            av_parser_close(st->parser);
-        }
-        if (st->attached_pic.data)
-            av_free_packet(&st->attached_pic);
-        av_dict_free(&st->metadata);
-        av_freep(&st->index_entries);
-        av_freep(&st->codec->extradata);
-        av_freep(&st->codec->subtitle_header);
-        av_freep(&st->codec);
-        av_freep(&st->priv_data);
-        av_freep(&st->info);
-        av_freep(&st);
+    for(i=s->nb_streams-1; i>=0; i--) {
+        ff_free_stream(s, s->streams[i]);
     }
     for(i=s->nb_programs-1; i>=0; i--) {
         av_dict_free(&s->programs[i]->metadata);



More information about the ffmpeg-cvslog mailing list