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

Side by Side 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: Fix DCHECK. Roll DEPS for fix. Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/audio_file_reader.h" 5 #include "media/filters/audio_file_reader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "media/base/audio_bus.h" 9 #include "media/base/audio_bus.h"
10 #include "media/ffmpeg/ffmpeg_common.h" 10 #include "media/ffmpeg/ffmpeg_common.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 int frames_read = av_frame->nb_samples; 156 int frames_read = av_frame->nb_samples;
157 if (frames_read < 0) { 157 if (frames_read < 0) {
158 continue_decoding = false; 158 continue_decoding = false;
159 break; 159 break;
160 } 160 }
161 161
162 // Truncate, if necessary, if the destination isn't big enough. 162 // Truncate, if necessary, if the destination isn't big enough.
163 if (current_frame + frames_read > audio_bus->frames()) 163 if (current_frame + frames_read > audio_bus->frames())
164 frames_read = audio_bus->frames() - current_frame; 164 frames_read = audio_bus->frames() - current_frame;
165 165
166 // Deinterleave each channel and convert to 32bit floating-point 166 // Deinterleave each channel and convert to 32bit floating-point with
167 // with nominal range -1.0 -> +1.0. 167 // nominal range -1.0 -> +1.0. If the output is already in float planar
168 audio_bus->FromInterleavedPartial( 168 // format, just copy it into the AudioBus.
169 av_frame->data[0], current_frame, frames_read, bytes_per_sample); 169 if (codec_context_->sample_fmt == AV_SAMPLE_FMT_FLT) {
170 float* decoded_audio_data = reinterpret_cast<float*>(av_frame->data[0]);
171 int channels = audio_bus->channels();
172 for (int ch = 0; ch < channels; ++ch) {
173 float* bus_data = audio_bus->channel(ch) + current_frame;
174 for (int i = 0, offset = ch; i < frames_read;
175 ++i, offset += channels) {
176 bus_data[i] = decoded_audio_data[offset];
177 }
178 }
179 } else if (codec_context_->sample_fmt == AV_SAMPLE_FMT_FLTP) {
180 for (int ch = 0; ch < audio_bus->channels(); ++ch) {
181 memcpy(audio_bus->channel(ch) + current_frame,
182 av_frame->extended_data[ch], sizeof(float) * frames_read);
183 }
184 } else {
185 audio_bus->FromInterleavedPartial(
186 av_frame->data[0], current_frame, frames_read, bytes_per_sample);
187 }
170 188
171 current_frame += frames_read; 189 current_frame += frames_read;
172 } while (packet_temp.size > 0); 190 } while (packet_temp.size > 0);
173 av_free_packet(&packet); 191 av_free_packet(&packet);
174 } 192 }
175 193
176 // Zero any remaining frames. 194 // Zero any remaining frames.
177 audio_bus->ZeroFramesPartial( 195 audio_bus->ZeroFramesPartial(
178 current_frame, audio_bus->frames() - current_frame); 196 current_frame, audio_bus->frames() - current_frame);
179 197
180 // Returns the actual number of sample-frames decoded. 198 // Returns the actual number of sample-frames decoded.
181 // Ideally this represents the "true" exact length of the file. 199 // Ideally this represents the "true" exact length of the file.
182 return current_frame; 200 return current_frame;
183 } 201 }
184 202
185 } // namespace media 203 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698