From 173f19be75a98fbfcf58a7e99871058232dc9dc2 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 4 Feb 2011 12:04:15 +0200 Subject: libavformat: Use avcodec_copy_context for chained muxers This avoids having the chained AVStream->codec point to the same AVCodecContext owned by the outer AVStream. The downside is that changes to the AVCodecContext made after calling av_write_header cannot be detected automatically within the chained muxer. This avoids having to manually unlink the chained AVStream->codec by setting it to null before freeing the chained muxer via generic freeing functions. Signed-off-by: Ronald S. Bultje (cherry picked from commit 1338dc082354b87c0e26f7f2ab09df5964b7f993) --- libavformat/movenchint.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libavformat/movenchint.c') diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 2aa0f17d54..6a9df076ce 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -57,10 +57,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->rtp_ctx->streams[0]->sample_aspect_ratio = src_st->sample_aspect_ratio; - /* Remove the allocated codec context, link to the original one - * instead, to give the rtp muxer access to codec parameters. */ - av_free(track->rtp_ctx->streams[0]->codec); - track->rtp_ctx->streams[0]->codec = src_st->codec; + avcodec_copy_context(track->rtp_ctx->streams[0]->codec, src_st->codec); if ((ret = url_open_dyn_packet_buf(&track->rtp_ctx->pb, RTP_MAX_PACKET_SIZE)) < 0) @@ -86,6 +83,8 @@ fail: } if (track->rtp_ctx && track->rtp_ctx->streams[0]) { av_metadata_free(&track->rtp_ctx->streams[0]->metadata); + av_free(track->rtp_ctx->streams[0]->codec->extradata); + av_free(track->rtp_ctx->streams[0]->codec); av_free(track->rtp_ctx->streams[0]->info); av_free(track->rtp_ctx->streams[0]); } @@ -491,6 +490,8 @@ void ff_mov_close_hinting(MOVTrack *track) { } av_metadata_free(&rtp_ctx->streams[0]->metadata); av_metadata_free(&rtp_ctx->metadata); + av_free(rtp_ctx->streams[0]->codec->extradata); + av_free(rtp_ctx->streams[0]->codec); av_free(rtp_ctx->streams[0]->info); av_free(rtp_ctx->streams[0]); av_freep(&rtp_ctx); -- cgit v1.2.3