On Mon, 9 Apr 2012 17:27:53 -0400, Justin Ruggles <[email protected]> wrote: > --- > avconv.c | 129 +++++++++++++++++++++++++++-------------------------------- > cmdutils.c | 4 +- > 2 files changed, 62 insertions(+), 71 deletions(-) > > diff --git a/avconv.c b/avconv.c > index 2cefe5d..c483536 100644 > --- a/avconv.c > +++ b/avconv.c > @@ -31,6 +31,7 @@ > #include "libavformat/avformat.h" > #include "libavdevice/avdevice.h" > #include "libswscale/swscale.h" > +#include "libavresample/avresample.h" > #include "libavutil/opt.h" > #include "libavcodec/audioconvert.h" > #include "libavutil/audioconvert.h" > @@ -232,12 +233,11 @@ typedef struct OutputStream { > > /* audio only */ > int audio_resample; > - ReSampleContext *resample; /* for audio resampling */ > + AVAudioResampleContext *avr; > int resample_sample_fmt; > int resample_channels; > + uint64_t resample_channel_layout; > int resample_sample_rate; > - int reformat_pair; > - AVAudioConvert *reformat_ctx; > AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */ > FILE *logfile; > > @@ -999,7 +999,7 @@ static int encode_audio_frame(AVFormatContext *s, > OutputStream *ost, > } > > static int alloc_audio_output_buf(AVCodecContext *dec, AVCodecContext *enc, > - int nb_samples) > + int nb_samples, int *buf_linesize) > { > int64_t audio_buf_samples; > int audio_buf_size; > @@ -1012,7 +1012,7 @@ static int alloc_audio_output_buf(AVCodecContext *dec, > AVCodecContext *enc, > if (audio_buf_samples > INT_MAX) > return AVERROR(EINVAL); > > - audio_buf_size = av_samples_get_buffer_size(NULL, enc->channels, > + audio_buf_size = av_samples_get_buffer_size(buf_linesize, enc->channels, > audio_buf_samples, > enc->sample_fmt, 0); > if (audio_buf_size < 0) > @@ -1030,75 +1030,79 @@ static void do_audio_out(AVFormatContext *s, > OutputStream *ost, > { > uint8_t *buftmp; > > - int size_out, frame_bytes, resample_changed; > + int size_out, frame_bytes, resample_changed, ret; > AVCodecContext *enc = ost->st->codec; > AVCodecContext *dec = ist->st->codec; > int osize = av_get_bytes_per_sample(enc->sample_fmt); > int isize = av_get_bytes_per_sample(dec->sample_fmt); > uint8_t *buf = decoded_frame->data[0]; > int size = decoded_frame->nb_samples * dec->channels * isize; > + int out_linesize = 0; > + int buf_linesize = decoded_frame->linesize[0]; > > - if (alloc_audio_output_buf(dec, enc, decoded_frame->nb_samples) < 0) { > + if (alloc_audio_output_buf(dec, enc, decoded_frame->nb_samples, > &out_linesize) < 0) { > av_log(NULL, AV_LOG_FATAL, "Error allocating audio buffer\n"); > exit_program(1); > } > > - if (enc->channels != dec->channels || enc->sample_rate != > dec->sample_rate) > + if (enc->channels != dec->channels || > + enc->channel_layout != dec->channel_layout || > + enc->sample_rate != dec->sample_rate || > + dec->sample_fmt != enc->sample_fmt) > ost->audio_resample = 1; > > resample_changed = ost->resample_sample_fmt != dec->sample_fmt || > ost->resample_channels != dec->channels || > + ost->resample_channel_layout != dec->channel_layout || > ost->resample_sample_rate != dec->sample_rate; > > - if ((ost->audio_resample && !ost->resample) || resample_changed) { > + if ((ost->audio_resample && !ost->avr) || resample_changed) { > if (resample_changed) { > - av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed > from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n", > + av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed > from rate:%d fmt:%s ch:%d chl:0x%"PRIx64" to rate:%d fmt:%s ch:%d > chl:0x%"PRIx64"\n", > ist->file_index, ist->st->index, > - ost->resample_sample_rate, > av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels, > - dec->sample_rate, > av_get_sample_fmt_name(dec->sample_fmt), dec->channels); > + ost->resample_sample_rate, > av_get_sample_fmt_name(ost->resample_sample_fmt), > + ost->resample_channels, ost->resample_channel_layout, > + dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), > + dec->channels, dec->channel_layout); > ost->resample_sample_fmt = dec->sample_fmt; > ost->resample_channels = dec->channels; > + ost->resample_channel_layout = dec->channel_layout; > ost->resample_sample_rate = dec->sample_rate; > - if (ost->resample) > - audio_resample_close(ost->resample); > + if (ost->avr) > + avresample_close(ost->avr); > } > /* if audio_sync_method is >1 the resampler is needed for audio > drift compensation */ > if (audio_sync_method <= 1 && > ost->resample_sample_fmt == enc->sample_fmt && > ost->resample_channels == enc->channels && > + ost->resample_channel_layout == enc->channel_layout && > ost->resample_sample_rate == enc->sample_rate) { > - ost->resample = NULL; > + ost->avr = NULL;
Aren't you leaking avr here? -- Anton Khirnov _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
