Chromium Code Reviews| Index: media/filters/audio_file_reader.cc |
| diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc |
| index 974304c1fa9f2c3a59af498dea605a6f5f9b9db9..711bdd8bc7d4787278a6f478e8c6c237b09eb8a1 100644 |
| --- a/media/filters/audio_file_reader.cc |
| +++ b/media/filters/audio_file_reader.cc |
| @@ -124,8 +124,8 @@ bool AudioFileReader::Read(const std::vector<float*>& audio_data, |
| return false; |
| } |
| - scoped_ptr_malloc<int16, ScopedPtrAVFree> output_buffer( |
| - static_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))); |
| + // Holds decoded audio. |
| + scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> avframe(avcodec_alloc_frame()); |
|
scherkus (not reviewing)
2012/06/08 00:51:22
nit: FFVD uses av_frame
DaleCurtis
2012/06/08 01:00:01
Done.
|
| // Read until we hit EOF or we've read the requested number of frames. |
| AVPacket avpkt; |
| @@ -134,11 +134,10 @@ bool AudioFileReader::Read(const std::vector<float*>& audio_data, |
| while (current_frame < number_of_frames && |
| (result = av_read_frame(format_context_, &avpkt)) >= 0) { |
| - int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; |
| - result = avcodec_decode_audio3(codec_context_, |
| - output_buffer.get(), |
| - &out_size, |
| - &avpkt); |
| + avcodec_get_frame_defaults(avframe.get()); |
| + int frame_decoded = 0; |
| + int result = avcodec_decode_audio4( |
| + codec_context_, avframe.get(), &frame_decoded, &avpkt); |
| av_free_packet(&avpkt); |
| if (result < 0) { |
| @@ -150,10 +149,13 @@ bool AudioFileReader::Read(const std::vector<float*>& audio_data, |
| return current_frame > 0; |
| } |
| + if (!frame_decoded) |
| + continue; |
| + |
| // Determine the number of sample-frames we just decoded. |
| size_t bytes_per_sample = |
| av_get_bytes_per_sample(codec_context_->sample_fmt); |
| - size_t frames_read = out_size / (channels * bytes_per_sample); |
| + size_t frames_read = avframe->nb_samples; |
| // Truncate, if necessary, if the destination isn't big enough. |
| if (current_frame + frames_read > number_of_frames) |
| @@ -163,7 +165,7 @@ bool AudioFileReader::Read(const std::vector<float*>& audio_data, |
| // with nominal range -1.0 -> +1.0. |
| for (size_t channel_index = 0; channel_index < channels; |
| ++channel_index) { |
| - if (!DeinterleaveAudioChannel(output_buffer.get(), |
| + if (!DeinterleaveAudioChannel(avframe->data[0], |
| audio_data[channel_index] + current_frame, |
| channels, |
| channel_index, |