| OLD | NEW |
| 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 "webkit/media/audio_decoder.h" | 5 #include "webkit/media/audio_decoder.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "media/base/audio_bus.h" |
| 11 #include "media/base/limits.h" | 12 #include "media/base/limits.h" |
| 12 #include "media/filters/audio_file_reader.h" | 13 #include "media/filters/audio_file_reader.h" |
| 13 #include "media/filters/in_memory_url_protocol.h" | 14 #include "media/filters/in_memory_url_protocol.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioBus.
h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioBus.
h" |
| 15 | 16 |
| 17 using media::AudioBus; |
| 16 using media::AudioFileReader; | 18 using media::AudioFileReader; |
| 17 using media::InMemoryUrlProtocol; | 19 using media::InMemoryUrlProtocol; |
| 18 using std::vector; | 20 using std::vector; |
| 19 using WebKit::WebAudioBus; | 21 using WebKit::WebAudioBus; |
| 20 | 22 |
| 21 namespace webkit_media { | 23 namespace webkit_media { |
| 22 | 24 |
| 23 // Decode in-memory audio file data. | 25 // Decode in-memory audio file data. |
| 24 bool DecodeAudioFileData( | 26 bool DecodeAudioFileData( |
| 25 WebKit::WebAudioBus* destination_bus, | 27 WebKit::WebAudioBus* destination_bus, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 size_t number_of_frames = static_cast<size_t>(reader.number_of_frames()); | 44 size_t number_of_frames = static_cast<size_t>(reader.number_of_frames()); |
| 43 | 45 |
| 44 // Apply sanity checks to make sure crazy values aren't coming out of | 46 // Apply sanity checks to make sure crazy values aren't coming out of |
| 45 // FFmpeg. | 47 // FFmpeg. |
| 46 if (!number_of_channels || | 48 if (!number_of_channels || |
| 47 number_of_channels > static_cast<size_t>(media::limits::kMaxChannels) || | 49 number_of_channels > static_cast<size_t>(media::limits::kMaxChannels) || |
| 48 file_sample_rate < media::limits::kMinSampleRate || | 50 file_sample_rate < media::limits::kMinSampleRate || |
| 49 file_sample_rate > media::limits::kMaxSampleRate) | 51 file_sample_rate > media::limits::kMaxSampleRate) |
| 50 return false; | 52 return false; |
| 51 | 53 |
| 52 // TODO(crogers) : do sample-rate conversion with FFmpeg. | |
| 53 // For now, we're ignoring the requested 'sample_rate' and returning | |
| 54 // the WebAudioBus at the file's sample-rate. | |
| 55 // double destination_sample_rate = | |
| 56 // (sample_rate != 0.0) ? sample_rate : file_sample_rate; | |
| 57 double destination_sample_rate = file_sample_rate; | |
| 58 | |
| 59 DVLOG(1) << "Decoding file data -" | 54 DVLOG(1) << "Decoding file data -" |
| 60 << " data: " << data | 55 << " data: " << data |
| 61 << " data size: " << data_size | 56 << " data size: " << data_size |
| 62 << " duration: " << duration | 57 << " duration: " << duration |
| 63 << " number of frames: " << number_of_frames | 58 << " number of frames: " << number_of_frames |
| 64 << " sample rate: " << file_sample_rate | 59 << " sample rate: " << file_sample_rate |
| 65 << " number of channels: " << number_of_channels; | 60 << " number of channels: " << number_of_channels; |
| 66 | 61 |
| 67 // Change to destination sample-rate. | |
| 68 number_of_frames = static_cast<size_t>(number_of_frames * | |
| 69 (destination_sample_rate / file_sample_rate)); | |
| 70 | |
| 71 // Allocate and configure the output audio channel data. | 62 // Allocate and configure the output audio channel data. |
| 72 destination_bus->initialize(number_of_channels, | 63 destination_bus->initialize(number_of_channels, |
| 73 number_of_frames, | 64 number_of_frames, |
| 74 destination_sample_rate); | 65 file_sample_rate); |
| 75 | 66 |
| 76 // Wrap the channel pointers which will receive the decoded PCM audio. | 67 // Wrap the channel pointers which will receive the decoded PCM audio. |
| 77 vector<float*> audio_data; | 68 vector<float*> audio_data; |
| 78 audio_data.reserve(number_of_channels); | 69 audio_data.reserve(number_of_channels); |
| 79 for (size_t i = 0; i < number_of_channels; ++i) { | 70 for (size_t i = 0; i < number_of_channels; ++i) { |
| 80 audio_data.push_back(destination_bus->channelData(i)); | 71 audio_data.push_back(destination_bus->channelData(i)); |
| 81 } | 72 } |
| 82 | 73 |
| 74 scoped_ptr<AudioBus> audio_bus = AudioBus::WrapVector( |
| 75 number_of_frames, audio_data); |
| 76 |
| 83 // Decode the audio file data. | 77 // Decode the audio file data. |
| 84 return reader.Read(audio_data, number_of_frames); | 78 return reader.Read(audio_bus.get()); |
| 85 } | 79 } |
| 86 | 80 |
| 87 } // namespace webkit_media | 81 } // namespace webkit_media |
| OLD | NEW |