Browse code

Use avformat_free_context for cleaning up muxers

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit b22dbb291d41e9fb038884bcebad2394c501cbaf)

Martin Storsjö authored on 2011/02/04 19:04:18
Showing 5 changed files
... ...
@@ -515,25 +515,11 @@ static int ffmpeg_exit(int ret)
515 515
 
516 516
     /* close files */
517 517
     for(i=0;i<nb_output_files;i++) {
518
-        /* maybe av_close_output_file ??? */
519 518
         AVFormatContext *s = output_files[i];
520 519
         int j;
521 520
         if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
522 521
             url_fclose(s->pb);
523
-        for(j=0;j<s->nb_streams;j++) {
524
-            av_metadata_free(&s->streams[j]->metadata);
525
-            av_free(s->streams[j]->codec);
526
-            av_free(s->streams[j]->info);
527
-            av_free(s->streams[j]);
528
-        }
529
-        for(j=0;j<s->nb_programs;j++) {
530
-            av_metadata_free(&s->programs[j]->metadata);
531
-        }
532
-        for(j=0;j<s->nb_chapters;j++) {
533
-            av_metadata_free(&s->chapters[j]->metadata);
534
-        }
535
-        av_metadata_free(&s->metadata);
536
-        av_free(s);
522
+        avformat_free_context(s);
537 523
         av_free(output_streams_for_file[i]);
538 524
     }
539 525
     for(i=0;i<nb_input_files;i++) {
... ...
@@ -81,17 +81,9 @@ fail:
81 81
         url_close_dyn_buf(track->rtp_ctx->pb, &buf);
82 82
         av_free(buf);
83 83
     }
84
-    if (track->rtp_ctx && track->rtp_ctx->streams[0]) {
85
-        av_metadata_free(&track->rtp_ctx->streams[0]->metadata);
86
-        av_free(track->rtp_ctx->streams[0]->codec->extradata);
87
-        av_free(track->rtp_ctx->streams[0]->codec);
88
-        av_free(track->rtp_ctx->streams[0]->info);
89
-        av_free(track->rtp_ctx->streams[0]);
90
-    }
91 84
     if (track->rtp_ctx) {
92
-        av_metadata_free(&track->rtp_ctx->metadata);
93
-        av_free(track->rtp_ctx->priv_data);
94
-        av_freep(&track->rtp_ctx);
85
+        avformat_free_context(track->rtp_ctx);
86
+        track->rtp_ctx = NULL;
95 87
     }
96 88
     av_freep(&track->enc);
97 89
     /* Set a default timescale, to avoid crashes in dump_format */
... ...
@@ -488,12 +480,6 @@ void ff_mov_close_hinting(MOVTrack *track) {
488 488
         url_close_dyn_buf(rtp_ctx->pb, &ptr);
489 489
         av_free(ptr);
490 490
     }
491
-    av_metadata_free(&rtp_ctx->streams[0]->metadata);
492
-    av_metadata_free(&rtp_ctx->metadata);
493
-    av_free(rtp_ctx->streams[0]->codec->extradata);
494
-    av_free(rtp_ctx->streams[0]->codec);
495
-    av_free(rtp_ctx->streams[0]->info);
496
-    av_free(rtp_ctx->streams[0]);
497
-    av_freep(&rtp_ctx);
491
+    avformat_free_context(rtp_ctx);
498 492
 }
499 493
 
... ...
@@ -66,11 +66,7 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
66 66
             url_close_dyn_buf(rtpctx->pb, &ptr);
67 67
             av_free(ptr);
68 68
         }
69
-        av_free(rtpctx->streams[0]->codec->extradata);
70
-        av_free(rtpctx->streams[0]->codec);
71
-        av_free(rtpctx->streams[0]->info);
72
-        av_free(rtpctx->streams[0]);
73
-        av_free(rtpctx);
69
+        avformat_free_context(rtpctx);
74 70
         return NULL;
75 71
     }
76 72
 
... ...
@@ -498,13 +498,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s)
498 498
                 } else {
499 499
                     url_fclose(rtpctx->pb);
500 500
                 }
501
-                av_metadata_free(&rtpctx->streams[0]->metadata);
502
-                av_metadata_free(&rtpctx->metadata);
503
-                av_free(rtpctx->streams[0]->codec->extradata);
504
-                av_free(rtpctx->streams[0]->codec);
505
-                av_free(rtpctx->streams[0]->info);
506
-                av_free(rtpctx->streams[0]);
507
-                av_free(rtpctx);
501
+                avformat_free_context(rtpctx);
508 502
             } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC)
509 503
                 ff_rdt_parse_close(rtsp_st->transport_priv);
510 504
             else if (CONFIG_RTPDEC)
... ...
@@ -46,13 +46,7 @@ static int sap_write_close(AVFormatContext *s)
46 46
             continue;
47 47
         av_write_trailer(rtpctx);
48 48
         url_fclose(rtpctx->pb);
49
-        av_metadata_free(&rtpctx->streams[0]->metadata);
50
-        av_metadata_free(&rtpctx->metadata);
51
-        av_free(rtpctx->streams[0]->codec->extradata);
52
-        av_free(rtpctx->streams[0]->codec);
53
-        av_free(rtpctx->streams[0]->info);
54
-        av_free(rtpctx->streams[0]);
55
-        av_free(rtpctx);
49
+        avformat_free_context(rtpctx);
56 50
         s->streams[i]->priv_data = NULL;
57 51
     }
58 52