|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/glue/media/audio_decoder.h" | |
6 | |
7 #include <vector> | |
8 #include "base/basictypes.h" | |
9 #include "base/string_util.h" | |
10 #include "base/time.h" | |
11 #include "media/filters/audio_file_reader.h" | |
12 #include "third_party/WebKit/WebKit/chromium/public/WebAudioBus.h" | |
13 | |
14 using media::AudioFileReader; | |
15 using media::InMemoryDataReader; | |
16 using std::vector; | |
17 using WebKit::WebAudioBus; | |
18 | |
19 namespace webkit_glue { | |
20 | |
21 // Decode in-memory audio file data. | |
22 bool DecodeAudioFileData(WebKit::WebAudioBus* destination_bus, | |
23 const char* data, size_t data_size, double sample_rate) { | |
scherkus (not reviewing)
2010/12/11 02:31:12
wrap these args at (
Chris Rogers
2010/12/13 20:25:27
Done.
| |
24 DCHECK(destination_bus); | |
25 if (!destination_bus) | |
26 return false; | |
27 | |
28 // Uses the FFMPEG library for audio file reading. | |
scherkus (not reviewing)
2010/12/11 02:31:12
nit: FFMPEG -> FFmpeg
(crazy, I know!)
Chris Rogers
2010/12/13 20:25:27
Done.
| |
29 InMemoryDataReader data_reader(data, data_size); | |
30 AudioFileReader reader(&data_reader); | |
31 | |
32 if (!reader.Open()) | |
33 return false; | |
34 | |
35 unsigned number_of_channels = reader.channels(); | |
scherkus (not reviewing)
2010/12/11 02:31:12
nit: unsigned -> size_t
Chris Rogers
2010/12/13 20:25:27
Done.
| |
36 double file_sample_rate = reader.sample_rate(); | |
37 double duration = reader.duration().InSecondsF(); | |
38 size_t number_of_frames = reader.number_of_frames(); | |
39 | |
40 // TODO(crogers) : do sample-rate conversion with FFMPEG. | |
scherkus (not reviewing)
2010/12/11 02:31:12
ditto
Chris Rogers
2010/12/13 20:25:27
Done.
| |
41 // For now, we're ignoring the requested 'sample_rate' and returning | |
42 // the WebAudioBus at the file's sample-rate. | |
43 // double destination_sample_rate = | |
44 // (sample_rate != 0.0) ? sample_rate : file_sample_rate; | |
45 double destination_sample_rate = file_sample_rate; | |
46 | |
47 DLOG(INFO) << "Decoding file data -" | |
48 << " data: " << data | |
scherkus (not reviewing)
2010/12/11 02:31:12
all these extra << lines should be indented by ext
Chris Rogers
2010/12/13 20:25:27
Done.
| |
49 << " data size: " << data_size | |
50 << " duration: " << duration | |
51 << " number of frames: " << number_of_frames | |
52 << " sample rate: " << file_sample_rate | |
53 << " number of channels: " << number_of_channels; | |
54 | |
55 // Change to destination sample-rate. | |
56 number_of_frames *= (destination_sample_rate / file_sample_rate); | |
57 | |
58 // Allocate and configure the output audio channel data. | |
59 destination_bus->initialize(number_of_channels, | |
60 number_of_frames, | |
61 destination_sample_rate); | |
62 | |
63 // Wrap the channel pointers which will receive the decoded PCM audio. | |
64 vector<float*> audio_data; | |
65 audio_data.reserve(number_of_channels); | |
66 for (unsigned i = 0; i < number_of_channels; ++i) { | |
scherkus (not reviewing)
2010/12/11 02:31:12
unsigned -> size_t (or use int, etc...)
Chris Rogers
2010/12/13 20:25:27
Done.
| |
67 audio_data.push_back(destination_bus->channelData(i)); | |
68 } | |
69 | |
70 // Decode the audio file data. | |
71 return reader.Read(audio_data, number_of_frames); | |
72 } | |
73 | |
74 } // namespace webkit_glue | |
OLD | NEW |