Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Unified Diff: media/filters/audio_file_reader.cc

Issue 11280301: Roll FFMpeg for M26. Fix ffmpeg float audio decoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... rebase Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/audio_file_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_file_reader.cc
diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc
index cf295b6f4467f5c0b93da91f4103636f90f6d14b..4a6bc1201fe63c585542eb06660da7ca52809d0a 100644
--- a/media/filters/audio_file_reader.cc
+++ b/media/filters/audio_file_reader.cc
@@ -79,14 +79,26 @@ bool AudioFileReader::Open() {
AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
if (codec) {
+ // MP3 decodes to S16P which we don't support, tell it to use S16 instead.
+ if (codec_context_->sample_fmt == AV_SAMPLE_FMT_S16P)
+ codec_context_->request_sample_fmt = AV_SAMPLE_FMT_S16;
+
if ((result = avcodec_open2(codec_context_, codec, NULL)) < 0) {
DLOG(WARNING) << "AudioFileReader::Open() : could not open codec -"
- << " result: " << result;
+ << " result: " << result;
+ return false;
+ }
+
+ // Ensure avcodec_open2() respected our format request.
+ if (codec_context_->sample_fmt == AV_SAMPLE_FMT_S16P) {
+ DLOG(ERROR) << "AudioFileReader::Open() : unable to configure a"
+ << " supported sample format - "
+ << codec_context_->sample_fmt;
return false;
}
} else {
DLOG(WARNING) << "AudioFileReader::Open() : could not find codec -"
- << " result: " << result;
+ << " result: " << result;
return false;
}
@@ -163,10 +175,28 @@ int AudioFileReader::Read(AudioBus* audio_bus) {
if (current_frame + frames_read > audio_bus->frames())
frames_read = audio_bus->frames() - current_frame;
- // Deinterleave each channel and convert to 32bit floating-point
- // with nominal range -1.0 -> +1.0.
- audio_bus->FromInterleavedPartial(
- av_frame->data[0], current_frame, frames_read, bytes_per_sample);
+ // Deinterleave each channel and convert to 32bit floating-point with
+ // nominal range -1.0 -> +1.0. If the output is already in float planar
+ // format, just copy it into the AudioBus.
+ if (codec_context_->sample_fmt == AV_SAMPLE_FMT_FLT) {
+ float* decoded_audio_data = reinterpret_cast<float*>(av_frame->data[0]);
+ int channels = audio_bus->channels();
+ for (int ch = 0; ch < channels; ++ch) {
+ float* bus_data = audio_bus->channel(ch) + current_frame;
+ for (int i = 0, offset = ch; i < frames_read;
+ ++i, offset += channels) {
+ bus_data[i] = decoded_audio_data[offset];
+ }
+ }
+ } else if (codec_context_->sample_fmt == AV_SAMPLE_FMT_FLTP) {
+ for (int ch = 0; ch < audio_bus->channels(); ++ch) {
+ memcpy(audio_bus->channel(ch) + current_frame,
+ av_frame->extended_data[ch], sizeof(float) * frames_read);
+ }
+ } else {
+ audio_bus->FromInterleavedPartial(
+ av_frame->data[0], current_frame, frames_read, bytes_per_sample);
+ }
current_frame += frames_read;
} while (packet_temp.size > 0);
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/audio_file_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698