diff options
author | nfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 21:58:45 +0000 |
---|---|---|
committer | nfullagar@google.com <nfullagar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 21:58:45 +0000 |
commit | 39690e106cdb6a4515df2d488ba8a7e6e2aa00d8 (patch) | |
tree | a0901832bf420b500cf48388142aa2f907166723 /webkit | |
parent | 3deeb6b32551ab2ed209ab361e5efcc404f91bba (diff) | |
download | chromium_src-39690e106cdb6a4515df2d488ba8a7e6e2aa00d8.zip chromium_src-39690e106cdb6a4515df2d488ba8a7e6e2aa00d8.tar.gz chromium_src-39690e106cdb6a4515df2d488ba8a7e6e2aa00d8.tar.bz2 |
changes to audio
- add obtained sample frame count
- add buffer size in bytes arg to callback
- enumerate sample rates
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3572010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/pepper_audio.cc | 40 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_audio.h | 14 |
2 files changed, 39 insertions, 15 deletions
diff --git a/webkit/glue/plugins/pepper_audio.cc b/webkit/glue/plugins/pepper_audio.cc index 3babc2f..ce617e2 100644 --- a/webkit/glue/plugins/pepper_audio.cc +++ b/webkit/glue/plugins/pepper_audio.cc @@ -14,20 +14,24 @@ namespace { // PPB_AudioConfig functions -PP_Resource CreateStereo16bit(PP_Module module_id, uint32_t sample_rate, - uint32_t sample_frame_count) { +PP_Resource CreateStereo16bit(PP_Module module_id, + PP_AudioSampleRate_Dev sample_rate, + uint32_t sample_frame_count, + uint32_t* obtained_frame_count) { PluginModule* module = PluginModule::FromPPModule(module_id); if (!module) return 0; - scoped_refptr<AudioConfig> config(new AudioConfig(module, sample_rate, - sample_frame_count)); + scoped_refptr<AudioConfig> config(new AudioConfig(module, + sample_rate, + sample_frame_count, + obtained_frame_count)); return config->GetReference(); } -uint32_t GetSampleRate(PP_Resource config_id) { +PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); - return config ? config->sample_rate() : 0; + return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; } uint32_t GetSampleFrameCount(PP_Resource config_id) { @@ -96,17 +100,34 @@ const PPB_AudioTrusted_Dev ppb_audiotrusted = { } // namespace -AudioConfig::AudioConfig(PluginModule* module, int32_t sample_rate, - int32_t sample_frame_count) +AudioConfig::AudioConfig(PluginModule* module, + PP_AudioSampleRate_Dev sample_rate, + uint32_t sample_frame_count, + uint32_t* obtained_frame_count) : Resource(module), sample_rate_(sample_rate), sample_frame_count_(sample_frame_count) { + // TODO(audio): adjust obtained frame count as needed. Some systems + // may need to adjust the sample frame count for best performance, for + // example to avoid audio glitching if the requested sample frame size + // reflects too low a latency. For now, do not adjust. + *obtained_frame_count = sample_frame_count; } const PPB_AudioConfig_Dev* AudioConfig::GetInterface() { return &ppb_audioconfig; } +size_t AudioConfig::BufferSize() { + // TODO(audio): as more options become available, we'll need to + // have additional code here to correctly calculate the size in + // bytes of an audio buffer. For now, only support two channel + // int16_t sample buffers. + const int kChannels = 2; + const int kSizeOfSample = sizeof(int16_t); + return static_cast<size_t>(sample_frame_count_ * kSizeOfSample * kChannels); +} + AudioConfig* AudioConfig::AsAudioConfig() { return this; } @@ -211,6 +232,7 @@ void Audio::StreamCreated(base::SharedMemoryHandle shared_memory_handle, void Audio::Run() { int pending_data; void* buffer = shared_memory_->memory(); + size_t buffer_size_in_bytes = config_->BufferSize(); while (sizeof(pending_data) == socket_->Receive(&pending_data, sizeof(pending_data)) && @@ -218,7 +240,7 @@ void Audio::Run() { // Exit the thread on pause. if (pending_data < 0) return; - callback_(buffer, user_data_); + callback_(buffer, buffer_size_in_bytes, user_data_); } } diff --git a/webkit/glue/plugins/pepper_audio.h b/webkit/glue/plugins/pepper_audio.h index d9a9e86..c0d0db0 100644 --- a/webkit/glue/plugins/pepper_audio.h +++ b/webkit/glue/plugins/pepper_audio.h @@ -25,20 +25,22 @@ class PluginModule; class AudioConfig : public Resource { public: - AudioConfig(PluginModule* module, int32_t sample_rate, - int32_t sample_frame_count); - + AudioConfig(PluginModule* module, + PP_AudioSampleRate_Dev sample_rate, + uint32_t sample_frame_count, + uint32_t* obtained_frame_count); + size_t BufferSize(); static const PPB_AudioConfig_Dev* GetInterface(); - uint32_t sample_rate() { return sample_rate_; } + PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; } uint32_t sample_frame_count() { return sample_frame_count_; } private: // Resource override. virtual AudioConfig* AsAudioConfig(); - int sample_rate_; - int sample_frame_count_; + PP_AudioSampleRate_Dev sample_rate_; + uint32_t sample_frame_count_; }; class Audio : public Resource, |