| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/media/audio_decoder.h" | 5 #include "webkit/glue/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/filters/audio_file_reader.h" | 11 #include "media/filters/audio_file_reader.h" |
| 12 #include "media/filters/in_memory_url_protocol.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioBus.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioBus.h" |
| 13 | 14 |
| 14 using media::AudioFileReader; | 15 using media::AudioFileReader; |
| 15 using media::InMemoryDataReader; | 16 using media::InMemoryUrlProtocol; |
| 16 using std::vector; | 17 using std::vector; |
| 17 using WebKit::WebAudioBus; | 18 using WebKit::WebAudioBus; |
| 18 | 19 |
| 19 namespace webkit_glue { | 20 namespace webkit_glue { |
| 20 | 21 |
| 21 // Decode in-memory audio file data. | 22 // Decode in-memory audio file data. |
| 22 bool DecodeAudioFileData( | 23 bool DecodeAudioFileData( |
| 23 WebKit::WebAudioBus* destination_bus, | 24 WebKit::WebAudioBus* destination_bus, |
| 24 const char* data, size_t data_size, double sample_rate) { | 25 const char* data, size_t data_size, double sample_rate) { |
| 25 DCHECK(destination_bus); | 26 DCHECK(destination_bus); |
| 26 if (!destination_bus) | 27 if (!destination_bus) |
| 27 return false; | 28 return false; |
| 28 | 29 |
| 29 // Uses the FFmpeg library for audio file reading. | 30 // Uses the FFmpeg library for audio file reading. |
| 30 InMemoryDataReader data_reader(data, data_size); | 31 InMemoryUrlProtocol url_protocol(reinterpret_cast<const uint8*>(data), |
| 31 AudioFileReader reader(&data_reader); | 32 data_size, false); |
| 33 AudioFileReader reader(&url_protocol); |
| 32 | 34 |
| 33 if (!reader.Open()) | 35 if (!reader.Open()) |
| 34 return false; | 36 return false; |
| 35 | 37 |
| 36 size_t number_of_channels = reader.channels(); | 38 size_t number_of_channels = reader.channels(); |
| 37 double file_sample_rate = reader.sample_rate(); | 39 double file_sample_rate = reader.sample_rate(); |
| 38 double duration = reader.duration().InSecondsF(); | 40 double duration = reader.duration().InSecondsF(); |
| 39 size_t number_of_frames = static_cast<size_t>(reader.number_of_frames()); | 41 size_t number_of_frames = static_cast<size_t>(reader.number_of_frames()); |
| 40 | 42 |
| 41 // TODO(crogers) : do sample-rate conversion with FFmpeg. | 43 // TODO(crogers) : do sample-rate conversion with FFmpeg. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 audio_data.reserve(number_of_channels); | 69 audio_data.reserve(number_of_channels); |
| 68 for (size_t i = 0; i < number_of_channels; ++i) { | 70 for (size_t i = 0; i < number_of_channels; ++i) { |
| 69 audio_data.push_back(destination_bus->channelData(i)); | 71 audio_data.push_back(destination_bus->channelData(i)); |
| 70 } | 72 } |
| 71 | 73 |
| 72 // Decode the audio file data. | 74 // Decode the audio file data. |
| 73 return reader.Read(audio_data, number_of_frames); | 75 return reader.Read(audio_data, number_of_frames); |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace webkit_glue | 78 } // namespace webkit_glue |
| OLD | NEW |