diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 20:44:09 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 20:44:09 +0000 |
commit | 949b9944f46a631b50887462ab74e37d9fe2b31a (patch) | |
tree | 0714f906d828f66fcb6aec52b3e3bb62e32e61cd /webkit | |
parent | 90f9a2962b73b2db4192129961648b449f74f651 (diff) | |
download | chromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.zip chromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.tar.gz chromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.tar.bz2 |
(Committing on behalf of Chris Rogers -- original CL http://codereview.chromium.org/5550006/ )
Implement WebKitClientImpl::loadAudioResource() to decode in-memory audio file data for use by WebKit.
Most of the interesting low-level code is being added in the media directory.
BUG=NONE
TEST=NONE (tested locally with web audio API loading files of format .wav .aif .mp3 .m4a 16bit 24bit
In the longer term, WebKit layout tests will comprehensively exercise this code)
Review URL: http://codereview.chromium.org/5880002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69458 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/media/audio_decoder.cc | 76 | ||||
-rw-r--r-- | webkit/glue/media/audio_decoder.h | 20 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 11 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 3 |
5 files changed, 112 insertions, 0 deletions
diff --git a/webkit/glue/media/audio_decoder.cc b/webkit/glue/media/audio_decoder.cc new file mode 100644 index 0000000..3fc05c9 --- /dev/null +++ b/webkit/glue/media/audio_decoder.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/glue/media/audio_decoder.h" + +#include <vector> +#include "base/basictypes.h" +#include "base/string_util.h" +#include "base/time.h" +#include "media/filters/audio_file_reader.h" +#include "third_party/WebKit/WebKit/chromium/public/WebAudioBus.h" + +using media::AudioFileReader; +using media::InMemoryDataReader; +using std::vector; +using WebKit::WebAudioBus; + +namespace webkit_glue { + +// Decode in-memory audio file data. +bool DecodeAudioFileData( + WebKit::WebAudioBus* destination_bus, + const char* data, size_t data_size, double sample_rate) { + DCHECK(destination_bus); + if (!destination_bus) + return false; + + // Uses the FFmpeg library for audio file reading. + InMemoryDataReader data_reader(data, data_size); + AudioFileReader reader(&data_reader); + + if (!reader.Open()) + return false; + + size_t number_of_channels = reader.channels(); + double file_sample_rate = reader.sample_rate(); + double duration = reader.duration().InSecondsF(); + size_t number_of_frames = static_cast<size_t>(reader.number_of_frames()); + + // TODO(crogers) : do sample-rate conversion with FFmpeg. + // For now, we're ignoring the requested 'sample_rate' and returning + // the WebAudioBus at the file's sample-rate. + // double destination_sample_rate = + // (sample_rate != 0.0) ? sample_rate : file_sample_rate; + double destination_sample_rate = file_sample_rate; + + DLOG(INFO) << "Decoding file data -" + << " data: " << data + << " data size: " << data_size + << " duration: " << duration + << " number of frames: " << number_of_frames + << " sample rate: " << file_sample_rate + << " number of channels: " << number_of_channels; + + // Change to destination sample-rate. + number_of_frames = static_cast<size_t>(number_of_frames * + (destination_sample_rate / file_sample_rate)); + + // Allocate and configure the output audio channel data. + destination_bus->initialize(number_of_channels, + number_of_frames, + destination_sample_rate); + + // Wrap the channel pointers which will receive the decoded PCM audio. + vector<float*> audio_data; + audio_data.reserve(number_of_channels); + for (size_t i = 0; i < number_of_channels; ++i) { + audio_data.push_back(destination_bus->channelData(i)); + } + + // Decode the audio file data. + return reader.Read(audio_data, number_of_frames); +} + +} // namespace webkit_glue diff --git a/webkit/glue/media/audio_decoder.h b/webkit/glue/media/audio_decoder.h new file mode 100644 index 0000000..57cc90b --- /dev/null +++ b/webkit/glue/media/audio_decoder.h @@ -0,0 +1,20 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_GLUE_MEDIA_AUDIO_DECODER_H_ +#define WEBKIT_GLUE_MEDIA_AUDIO_DECODER_H_ + +#include "base/basictypes.h" + +namespace WebKit { class WebAudioBus; } + +namespace webkit_glue { + +// Decode in-memory audio file data. +bool DecodeAudioFileData(WebKit::WebAudioBus* destination_bus, const char* data, + size_t data_size, double sample_rate); + +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_MEDIA_AUDIO_DECODER_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index eb5b31b..d986324 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -250,6 +250,8 @@ '../plugins/ppapi/var.h', '../plugins/ppapi/var_object_class.cc', '../plugins/ppapi/var_object_class.h', + 'media/audio_decoder.cc', + 'media/audio_decoder.h', 'media/buffered_data_source.cc', 'media/buffered_data_source.h', 'media/buffered_resource_loader.cc', diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 42e1d1d8..5346181 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -34,6 +34,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "webkit/glue/media/audio_decoder.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/webplugininfo.h" #include "webkit/glue/webkit_glue.h" @@ -44,6 +45,7 @@ #include "v8/include/v8.h" #endif +using WebKit::WebAudioBus; using WebKit::WebCookie; using WebKit::WebData; using WebKit::WebLocalizedString; @@ -352,6 +354,15 @@ WebData WebKitClientImpl::loadResource(const char* name) { return WebData(); } +bool WebKitClientImpl::loadAudioResource( + WebKit::WebAudioBus* destination_bus, const char* audio_file_data, + size_t data_size, double sample_rate) { + return DecodeAudioFileData(destination_bus, + audio_file_data, + data_size, + sample_rate); +} + WebString WebKitClientImpl::queryLocalizedString( WebLocalizedString::Name name) { int message_id = ToMessageID(name); diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index 2836e8e..cc361d3 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -52,6 +52,9 @@ class WebKitClientImpl : public WebKit::WebKitClient { virtual void traceEventBegin(const char* name, void* id, const char* extra); virtual void traceEventEnd(const char* name, void* id, const char* extra); virtual WebKit::WebData loadResource(const char* name); + virtual bool loadAudioResource( + WebKit::WebAudioBus* destination_bus, const char* audio_file_data, + size_t data_size, double sample_rate); virtual WebKit::WebString queryLocalizedString( WebKit::WebLocalizedString::Name name); virtual WebKit::WebString queryLocalizedString( |