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