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 "content/public/common/content_switches.h" | |
| 11 | |
| 12 #include <math.h> | |
| 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. | |
|
tommi (sloooow) - chröme
2012/09/07 09:58:19
file a bug for tracking?
Chris Rogers
2012/09/07 20:34:01
Done.
| |
| 26 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 27 switches::kEnableWebAudioInput)) { | |
| 28 audio_device_->InitializeIO(params, 2, this); | |
|
tommi (sloooow) - chröme
2012/09/07 09:58:19
won't hardcoding this at 2 be problematic for non-
Chris Rogers
2012/09/07 20:34:01
The Mac-backend will automatically handle this cas
| |
| 29 } else { | |
| 30 audio_device_->Initialize(params, this); | |
| 31 } | |
| 21 } | 32 } |
| 22 | 33 |
| 23 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 34 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
| 24 stop(); | 35 stop(); |
| 25 } | 36 } |
| 26 | 37 |
| 27 void RendererWebAudioDeviceImpl::start() { | 38 void RendererWebAudioDeviceImpl::start() { |
| 28 if (!is_running_) { | 39 if (!is_running_) { |
| 29 audio_device_->Start(); | 40 audio_device_->Start(); |
| 30 is_running_ = true; | 41 is_running_ = true; |
| 31 } | 42 } |
| 32 } | 43 } |
| 33 | 44 |
| 34 void RendererWebAudioDeviceImpl::stop() { | 45 void RendererWebAudioDeviceImpl::stop() { |
| 35 if (is_running_) { | 46 if (is_running_) { |
| 36 audio_device_->Stop(); | 47 audio_device_->Stop(); |
| 37 is_running_ = false; | 48 is_running_ = false; |
| 38 } | 49 } |
| 39 } | 50 } |
| 40 | 51 |
| 41 double RendererWebAudioDeviceImpl::sampleRate() { | 52 double RendererWebAudioDeviceImpl::sampleRate() { |
| 42 return 44100.0; | 53 return 44100.0; |
| 43 } | 54 } |
| 44 | 55 |
| 45 int RendererWebAudioDeviceImpl::Render(media::AudioBus* audio_bus, | 56 int RendererWebAudioDeviceImpl::Render(media::AudioBus* audio_bus, |
| 46 int audio_delay_milliseconds) { | 57 int audio_delay_milliseconds) { |
| 47 // Make the client callback to get rendered audio. | 58 RenderIO(NULL, audio_bus, audio_delay_milliseconds); |
| 59 return audio_bus->frames(); | |
| 60 } | |
| 61 | |
| 62 void RendererWebAudioDeviceImpl::RenderIO(media::AudioBus* audio_input_bus, | |
| 63 media::AudioBus* audio_bus, | |
| 64 int audio_delay_milliseconds) { | |
| 65 // Make the client callback for an I/O cycle. | |
| 48 DCHECK(client_callback_); | 66 DCHECK(client_callback_); |
| 49 if (client_callback_) { | 67 if (client_callback_) { |
| 50 // Wrap the pointers using WebVector. | 68 // Wrap the inputs pointers using WebVector. |
| 69 size_t input_channels = | |
| 70 audio_input_bus ? static_cast<size_t>(audio_input_bus->channels()) : 0; | |
| 71 WebVector<float*> web_audio_input_data(input_channels); | |
| 72 for (size_t i = 0; i < input_channels; ++i) | |
| 73 web_audio_input_data[i] = audio_input_bus->channel(i); | |
| 74 | |
| 75 // Wrap the output pointers using WebVector. | |
| 51 WebVector<float*> web_audio_data( | 76 WebVector<float*> web_audio_data( |
| 52 static_cast<size_t>(audio_bus->channels())); | 77 static_cast<size_t>(audio_bus->channels())); |
| 53 for (int i = 0; i < audio_bus->channels(); ++i) | 78 for (int i = 0; i < audio_bus->channels(); ++i) |
| 54 web_audio_data[i] = audio_bus->channel(i); | 79 web_audio_data[i] = audio_bus->channel(i); |
| 55 | 80 |
| 56 client_callback_->render(web_audio_data, audio_bus->frames()); | 81 client_callback_->render(web_audio_input_data, |
| 82 web_audio_data, | |
| 83 audio_bus->frames()); | |
| 57 } | 84 } |
| 58 return audio_bus->frames(); | |
| 59 } | 85 } |
| 60 | 86 |
| 61 void RendererWebAudioDeviceImpl::OnRenderError() { | 87 void RendererWebAudioDeviceImpl::OnRenderError() { |
| 62 // TODO(crogers): implement error handling. | 88 // TODO(crogers): implement error handling. |
| 63 } | 89 } |
| OLD | NEW |