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

Side by Side Diff: webkit/glue/media/audio_decoder.cc

Issue 8570010: Moving media-related files from webkit/glue/ to webkit/media/. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: minor fixes Created 9 years, 1 month 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
« no previous file with comments | « webkit/glue/media/audio_decoder.h ('k') | webkit/glue/media/buffered_data_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/base/limits.h"
12 #include "media/filters/audio_file_reader.h"
13 #include "media/filters/in_memory_url_protocol.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioBus.h"
15
16 using media::AudioFileReader;
17 using media::InMemoryUrlProtocol;
18 using std::vector;
19 using WebKit::WebAudioBus;
20
21 namespace webkit_glue {
22
23 // Decode in-memory audio file data.
24 bool DecodeAudioFileData(
25 WebKit::WebAudioBus* destination_bus,
26 const char* data, size_t data_size, double sample_rate) {
27 DCHECK(destination_bus);
28 if (!destination_bus)
29 return false;
30
31 // Uses the FFmpeg library for audio file reading.
32 InMemoryUrlProtocol url_protocol(reinterpret_cast<const uint8*>(data),
33 data_size, false);
34 AudioFileReader reader(&url_protocol);
35
36 if (!reader.Open())
37 return false;
38
39 size_t number_of_channels = reader.channels();
40 double file_sample_rate = reader.sample_rate();
41 double duration = reader.duration().InSecondsF();
42 size_t number_of_frames = static_cast<size_t>(reader.number_of_frames());
43
44 // Apply sanity checks to make sure crazy values aren't coming out of
45 // FFmpeg.
46 if (!number_of_channels ||
47 number_of_channels > static_cast<size_t>(media::Limits::kMaxChannels) ||
48 file_sample_rate < media::Limits::kMinSampleRate ||
49 file_sample_rate > media::Limits::kMaxSampleRate)
50 return false;
51
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 DLOG(INFO) << "Decoding file data -"
60 << " data: " << data
61 << " data size: " << data_size
62 << " duration: " << duration
63 << " number of frames: " << number_of_frames
64 << " sample rate: " << file_sample_rate
65 << " number of channels: " << number_of_channels;
66
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.
72 destination_bus->initialize(number_of_channels,
73 number_of_frames,
74 destination_sample_rate);
75
76 // Wrap the channel pointers which will receive the decoded PCM audio.
77 vector<float*> audio_data;
78 audio_data.reserve(number_of_channels);
79 for (size_t i = 0; i < number_of_channels; ++i) {
80 audio_data.push_back(destination_bus->channelData(i));
81 }
82
83 // Decode the audio file data.
84 return reader.Read(audio_data, number_of_frames);
85 }
86
87 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/media/audio_decoder.h ('k') | webkit/glue/media/buffered_data_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698