Commit 2ab8a150 authored by jbr's avatar jbr

Allocate enough memory for audio_buf to fit a full output frame.

Also, use audio_buf when encoding the final frame.
Fixes Issue 1921.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@23570 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent d07159e9
...@@ -813,6 +813,7 @@ need_realloc: ...@@ -813,6 +813,7 @@ need_realloc:
audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels); audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels);
audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate; audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate;
audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API
audio_buf_size= FFMAX(audio_buf_size, enc->frame_size);
audio_buf_size*= osize*enc->channels; audio_buf_size*= osize*enc->channels;
audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels); audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels);
...@@ -1832,17 +1833,17 @@ static int output_packet(AVInputStream *ist, int ist_index, ...@@ -1832,17 +1833,17 @@ static int output_packet(AVInputStream *ist, int ist_index,
int osize = av_get_bits_per_sample_format(enc->sample_fmt) >> 3; int osize = av_get_bits_per_sample_format(enc->sample_fmt) >> 3;
int fs_tmp = enc->frame_size; int fs_tmp = enc->frame_size;
av_fifo_generic_read(ost->fifo, samples, fifo_bytes, NULL); av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
enc->frame_size = fifo_bytes / (osize * enc->channels); enc->frame_size = fifo_bytes / (osize * enc->channels);
} else { /* pad */ } else { /* pad */
int frame_bytes = enc->frame_size*osize*enc->channels; int frame_bytes = enc->frame_size*osize*enc->channels;
if (samples_size < frame_bytes) if (allocated_audio_buf_size < frame_bytes)
av_exit(1); av_exit(1);
memset((uint8_t*)samples+fifo_bytes, 0, frame_bytes - fifo_bytes); memset((uint8_t*)audio_buf+fifo_bytes, 0, frame_bytes - fifo_bytes);
} }
ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples); ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);
pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den, pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
ost->st->time_base.num, enc->sample_rate); ost->st->time_base.num, enc->sample_rate);
enc->frame_size = fs_tmp; enc->frame_size = fs_tmp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment