Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/media/renderer_webaudiodevice_impl.h" | 5 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "content/renderer/media/audio_device_factory.h" | 9 #include "content/renderer/media/audio_device_factory.h" |
| 10 #include "media/base/media_switches.h" | |
| 11 | |
| 12 #include <math.h> | |
|
scherkus (not reviewing)
2012/09/10 11:46:32
where's the math.h usage?
Chris Rogers
2012/09/10 19:21:38
Sorry, that was only needed for testing -- removed
| |
| 9 | 13 |
| 10 using content::AudioDeviceFactory; | 14 using content::AudioDeviceFactory; |
| 11 using WebKit::WebAudioDevice; | 15 using WebKit::WebAudioDevice; |
| 12 using WebKit::WebVector; | 16 using WebKit::WebVector; |
| 13 | 17 |
| 14 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( | 18 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( |
| 15 const media::AudioParameters& params, | 19 const media::AudioParameters& params, |
| 16 WebAudioDevice::RenderCallback* callback) | 20 WebAudioDevice::RenderCallback* callback) |
| 17 : is_running_(false), | 21 : is_running_(false), |
| 18 client_callback_(callback) { | 22 client_callback_(callback) { |
| 19 audio_device_ = AudioDeviceFactory::NewOutputDevice(); | 23 audio_device_ = AudioDeviceFactory::NewOutputDevice(); |
| 20 audio_device_->Initialize(params, this); | 24 |
| 25 // TODO(crogers): remove once we properly handle input device selection. | |
| 26 // https://code.google.com/p/chromium/issues/detail?id=147327 | |
| 27 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 28 switches::kEnableWebAudioInput)) { | |
| 29 // TODO(crogers): support more than hard-coded stereo: | |
| 30 // https://code.google.com/p/chromium/issues/detail?id=147326 | |
| 31 audio_device_->InitializeIO(params, 2, this); | |
| 32 } else { | |
| 33 audio_device_->Initialize(params, this); | |
| 34 } | |
| 21 } | 35 } |
| 22 | 36 |
| 23 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 37 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
| 24 stop(); | 38 stop(); |
| 25 } | 39 } |
| 26 | 40 |
| 27 void RendererWebAudioDeviceImpl::start() { | 41 void RendererWebAudioDeviceImpl::start() { |
| 28 if (!is_running_) { | 42 if (!is_running_) { |
| 29 audio_device_->Start(); | 43 audio_device_->Start(); |
| 30 is_running_ = true; | 44 is_running_ = true; |
| 31 } | 45 } |
| 32 } | 46 } |
| 33 | 47 |
| 34 void RendererWebAudioDeviceImpl::stop() { | 48 void RendererWebAudioDeviceImpl::stop() { |
| 35 if (is_running_) { | 49 if (is_running_) { |
| 36 audio_device_->Stop(); | 50 audio_device_->Stop(); |
| 37 is_running_ = false; | 51 is_running_ = false; |
| 38 } | 52 } |
| 39 } | 53 } |
| 40 | 54 |
| 41 double RendererWebAudioDeviceImpl::sampleRate() { | 55 double RendererWebAudioDeviceImpl::sampleRate() { |
| 42 return 44100.0; | 56 return 44100.0; |
| 43 } | 57 } |
| 44 | 58 |
| 45 int RendererWebAudioDeviceImpl::Render(media::AudioBus* audio_bus, | 59 int RendererWebAudioDeviceImpl::Render(media::AudioBus* audio_bus, |
| 46 int audio_delay_milliseconds) { | 60 int audio_delay_milliseconds) { |
| 47 // Make the client callback to get rendered audio. | 61 RenderIO(NULL, audio_bus, audio_delay_milliseconds); |
| 62 return audio_bus->frames(); | |
| 63 } | |
| 64 | |
| 65 void RendererWebAudioDeviceImpl::RenderIO(media::AudioBus* audio_input_bus, | |
| 66 media::AudioBus* audio_bus, | |
| 67 int audio_delay_milliseconds) { | |
| 68 // Make the client callback for an I/O cycle. | |
| 48 DCHECK(client_callback_); | 69 DCHECK(client_callback_); |
| 49 if (client_callback_) { | 70 if (client_callback_) { |
| 50 // Wrap the pointers using WebVector. | 71 // Wrap the inputs pointers using WebVector. |
|
scherkus (not reviewing)
2012/09/10 11:46:32
s/inputs/input/?
Chris Rogers
2012/09/10 19:21:38
Done.
| |
| 72 size_t input_channels = | |
| 73 audio_input_bus ? static_cast<size_t>(audio_input_bus->channels()) : 0; | |
| 74 WebVector<float*> web_audio_input_data(input_channels); | |
| 75 for (size_t i = 0; i < input_channels; ++i) | |
| 76 web_audio_input_data[i] = audio_input_bus->channel(i); | |
| 77 | |
| 78 // Wrap the output pointers using WebVector. | |
| 51 WebVector<float*> web_audio_data( | 79 WebVector<float*> web_audio_data( |
| 52 static_cast<size_t>(audio_bus->channels())); | 80 static_cast<size_t>(audio_bus->channels())); |
| 53 for (int i = 0; i < audio_bus->channels(); ++i) | 81 for (int i = 0; i < audio_bus->channels(); ++i) |
| 54 web_audio_data[i] = audio_bus->channel(i); | 82 web_audio_data[i] = audio_bus->channel(i); |
| 55 | 83 |
| 56 client_callback_->render(web_audio_data, audio_bus->frames()); | 84 client_callback_->render(web_audio_input_data, |
| 85 web_audio_data, | |
| 86 audio_bus->frames()); | |
| 57 } | 87 } |
| 58 return audio_bus->frames(); | |
| 59 } | 88 } |
| 60 | 89 |
| 61 void RendererWebAudioDeviceImpl::OnRenderError() { | 90 void RendererWebAudioDeviceImpl::OnRenderError() { |
| 62 // TODO(crogers): implement error handling. | 91 // TODO(crogers): implement error handling. |
| 63 } | 92 } |
| OLD | NEW |