| 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/test/webrtc_audio_device_test.h" | 5 #include "content/test/webrtc_audio_device_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" | 14 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" |
| 15 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 15 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
| 16 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 16 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 17 #include "content/browser/renderer_host/media/media_stream_manager.h" | 17 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 18 #include "content/browser/renderer_host/media/mock_media_observer.h" | 18 #include "content/browser/renderer_host/media/mock_media_observer.h" |
| 19 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/common/content_paths.h" | 21 #include "content/public/common/content_paths.h" |
| 22 #include "content/public/test/mock_resource_context.h" | 22 #include "content/public/test/mock_resource_context.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 24 #include "content/renderer/media/audio_hardware.h" | |
| 25 #include "content/renderer/media/audio_input_message_filter.h" | 24 #include "content/renderer/media/audio_input_message_filter.h" |
| 26 #include "content/renderer/media/audio_message_filter.h" | 25 #include "content/renderer/media/audio_message_filter.h" |
| 27 #include "content/renderer/media/webrtc_audio_device_impl.h" | 26 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 28 #include "content/renderer/render_process.h" | 27 #include "content/renderer/render_process.h" |
| 29 #include "content/renderer/render_thread_impl.h" | 28 #include "content/renderer/render_thread_impl.h" |
| 30 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 29 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
| 30 #include "media/base/audio_hardware_config.h" |
| 31 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" | 34 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" |
| 35 #include "third_party/webrtc/voice_engine/include/voe_base.h" | 35 #include "third_party/webrtc/voice_engine/include/voe_base.h" |
| 36 #include "third_party/webrtc/voice_engine/include/voe_file.h" | 36 #include "third_party/webrtc/voice_engine/include/voe_file.h" |
| 37 #include "third_party/webrtc/voice_engine/include/voe_network.h" | 37 #include "third_party/webrtc/voice_engine/include/voe_network.h" |
| 38 | 38 |
| 39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 40 #include "base/win/scoped_com_initializer.h" | 40 #include "base/win/scoped_com_initializer.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 net::URLRequestContext* test_request_context_; | 108 net::URLRequestContext* test_request_context_; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(MockRTCResourceContext); | 110 DISALLOW_COPY_AND_ASSIGN(MockRTCResourceContext); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 ACTION_P(QuitMessageLoop, loop_or_proxy) { | 113 ACTION_P(QuitMessageLoop, loop_or_proxy) { |
| 114 loop_or_proxy->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 114 loop_or_proxy->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 WebRTCAudioDeviceTest::WebRTCAudioDeviceTest() | 117 WebRTCAudioDeviceTest::WebRTCAudioDeviceTest() |
| 118 : render_thread_(NULL), audio_util_callback_(NULL), | 118 : render_thread_(NULL), audio_hardware_config_(NULL), |
| 119 has_input_devices_(false), has_output_devices_(false) { | 119 has_input_devices_(false), has_output_devices_(false) { |
| 120 } | 120 } |
| 121 | 121 |
| 122 WebRTCAudioDeviceTest::~WebRTCAudioDeviceTest() {} | 122 WebRTCAudioDeviceTest::~WebRTCAudioDeviceTest() {} |
| 123 | 123 |
| 124 void WebRTCAudioDeviceTest::SetUp() { | 124 void WebRTCAudioDeviceTest::SetUp() { |
| 125 // This part sets up a RenderThread environment to ensure that | 125 // This part sets up a RenderThread environment to ensure that |
| 126 // RenderThread::current() (<=> TLS pointer) is valid. | 126 // RenderThread::current() (<=> TLS pointer) is valid. |
| 127 // Main parts are inspired by the RenderViewFakeResourcesTest. | 127 // Main parts are inspired by the RenderViewFakeResourcesTest. |
| 128 // Note that, the IPC part is not utilized in this test. | 128 // Note that, the IPC part is not utilized in this test. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 base::Bind(&WebRTCAudioDeviceTest::InitializeIOThread, | 140 base::Bind(&WebRTCAudioDeviceTest::InitializeIOThread, |
| 141 base::Unretained(this), kThreadName)); | 141 base::Unretained(this), kThreadName)); |
| 142 WaitForIOThreadCompletion(); | 142 WaitForIOThreadCompletion(); |
| 143 | 143 |
| 144 sandbox_was_enabled_ = | 144 sandbox_was_enabled_ = |
| 145 RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting(false); | 145 RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting(false); |
| 146 render_thread_ = new RenderThreadImpl(kThreadName); | 146 render_thread_ = new RenderThreadImpl(kThreadName); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void WebRTCAudioDeviceTest::TearDown() { | 149 void WebRTCAudioDeviceTest::TearDown() { |
| 150 SetAudioUtilCallback(NULL); | 150 SetAudioHardwareConfig(NULL); |
| 151 | 151 |
| 152 // Run any pending cleanup tasks that may have been posted to the main thread. | 152 // Run any pending cleanup tasks that may have been posted to the main thread. |
| 153 ChildProcess::current()->main_thread()->message_loop()->RunUntilIdle(); | 153 ChildProcess::current()->main_thread()->message_loop()->RunUntilIdle(); |
| 154 | 154 |
| 155 // Kick of the cleanup process by closing the channel. This queues up | 155 // Kick of the cleanup process by closing the channel. This queues up |
| 156 // OnStreamClosed calls to be executed on the audio thread. | 156 // OnStreamClosed calls to be executed on the audio thread. |
| 157 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, | 157 ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, |
| 158 base::Bind(&WebRTCAudioDeviceTest::DestroyChannel, | 158 base::Bind(&WebRTCAudioDeviceTest::DestroyChannel, |
| 159 base::Unretained(this))); | 159 base::Unretained(this))); |
| 160 WaitForIOThreadCompletion(); | 160 WaitForIOThreadCompletion(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 176 mirroring_manager_.reset(); | 176 mirroring_manager_.reset(); |
| 177 audio_manager_.reset(); | 177 audio_manager_.reset(); |
| 178 RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting( | 178 RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting( |
| 179 sandbox_was_enabled_); | 179 sandbox_was_enabled_); |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool WebRTCAudioDeviceTest::Send(IPC::Message* message) { | 182 bool WebRTCAudioDeviceTest::Send(IPC::Message* message) { |
| 183 return channel_->Send(message); | 183 return channel_->Send(message); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void WebRTCAudioDeviceTest::SetAudioUtilCallback(AudioUtilInterface* callback) { | 186 void WebRTCAudioDeviceTest::SetAudioHardwareConfig( |
| 187 // Invalidate any potentially cached values since the new callback should | 187 media::AudioHardwareConfig* hardware_config) { |
| 188 // be used for those queries. | 188 audio_hardware_config_ = hardware_config; |
| 189 ResetAudioCache(); | |
| 190 audio_util_callback_ = callback; | |
| 191 } | 189 } |
| 192 | 190 |
| 193 void WebRTCAudioDeviceTest::InitializeIOThread(const char* thread_name) { | 191 void WebRTCAudioDeviceTest::InitializeIOThread(const char* thread_name) { |
| 194 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
| 195 // We initialize COM (STA) on our IO thread as is done in Chrome. | 193 // We initialize COM (STA) on our IO thread as is done in Chrome. |
| 196 // See BrowserProcessSubThread::Init. | 194 // See BrowserProcessSubThread::Init. |
| 197 initialize_com_.reset(new base::win::ScopedCOMInitializer()); | 195 initialize_com_.reset(new base::win::ScopedCOMInitializer()); |
| 198 #endif | 196 #endif |
| 199 | 197 |
| 200 // Set the current thread as the IO thread. | 198 // Set the current thread as the IO thread. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 255 audio_render_host_->OnChannelClosing(); | 253 audio_render_host_->OnChannelClosing(); |
| 256 audio_render_host_->OnFilterRemoved(); | 254 audio_render_host_->OnFilterRemoved(); |
| 257 audio_input_renderer_host_->OnChannelClosing(); | 255 audio_input_renderer_host_->OnChannelClosing(); |
| 258 audio_input_renderer_host_->OnFilterRemoved(); | 256 audio_input_renderer_host_->OnFilterRemoved(); |
| 259 channel_.reset(); | 257 channel_.reset(); |
| 260 audio_render_host_ = NULL; | 258 audio_render_host_ = NULL; |
| 261 audio_input_renderer_host_ = NULL; | 259 audio_input_renderer_host_ = NULL; |
| 262 } | 260 } |
| 263 | 261 |
| 264 void WebRTCAudioDeviceTest::OnGetHardwareSampleRate(int* sample_rate) { | 262 void WebRTCAudioDeviceTest::OnGetAudioHardwareConfig( |
| 265 EXPECT_TRUE(audio_util_callback_); | 263 int* output_buffer_size, int* output_sample_rate, int* input_sample_rate, |
| 266 *sample_rate = audio_util_callback_ ? | 264 media::ChannelLayout* input_channel_layout) { |
| 267 audio_util_callback_->GetAudioHardwareSampleRate() : 0; | 265 ASSERT_TRUE(audio_hardware_config_); |
| 268 } | |
| 269 | 266 |
| 270 void WebRTCAudioDeviceTest::OnGetHardwareInputSampleRate(int* sample_rate) { | 267 *output_buffer_size = audio_hardware_config_->GetOutputBufferSize(); |
| 271 EXPECT_TRUE(audio_util_callback_); | 268 *output_sample_rate = audio_hardware_config_->GetOutputSampleRate(); |
| 272 *sample_rate = audio_util_callback_ ? | |
| 273 audio_util_callback_->GetAudioInputHardwareSampleRate( | |
| 274 media::AudioManagerBase::kDefaultDeviceId) : 0; | |
| 275 } | |
| 276 | 269 |
| 277 void WebRTCAudioDeviceTest::OnGetHardwareInputChannelLayout( | 270 // TODO(henrika): add support for all available input devices. |
| 278 media::ChannelLayout* layout) { | 271 *input_sample_rate = audio_hardware_config_->GetInputSampleRate(); |
| 279 EXPECT_TRUE(audio_util_callback_); | 272 *input_channel_layout = audio_hardware_config_->GetInputChannelLayout(); |
| 280 *layout = !audio_util_callback_ ? media::CHANNEL_LAYOUT_NONE : | |
| 281 audio_util_callback_->GetAudioInputHardwareChannelLayout( | |
| 282 media::AudioManagerBase::kDefaultDeviceId); | |
| 283 } | 273 } |
| 284 | 274 |
| 285 // IPC::Listener implementation. | 275 // IPC::Listener implementation. |
| 286 bool WebRTCAudioDeviceTest::OnMessageReceived(const IPC::Message& message) { | 276 bool WebRTCAudioDeviceTest::OnMessageReceived(const IPC::Message& message) { |
| 287 if (render_thread_) { | 277 if (render_thread_) { |
| 288 IPC::ChannelProxy::MessageFilter* filter = | 278 IPC::ChannelProxy::MessageFilter* filter = |
| 289 render_thread_->audio_input_message_filter(); | 279 render_thread_->audio_input_message_filter(); |
| 290 if (filter->OnMessageReceived(message)) | 280 if (filter->OnMessageReceived(message)) |
| 291 return true; | 281 return true; |
| 292 | 282 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 303 | 293 |
| 304 if (audio_input_renderer_host_.get()) { | 294 if (audio_input_renderer_host_.get()) { |
| 305 bool message_was_ok = false; | 295 bool message_was_ok = false; |
| 306 if (audio_input_renderer_host_->OnMessageReceived(message, &message_was_ok)) | 296 if (audio_input_renderer_host_->OnMessageReceived(message, &message_was_ok)) |
| 307 return true; | 297 return true; |
| 308 } | 298 } |
| 309 | 299 |
| 310 bool handled ALLOW_UNUSED = true; | 300 bool handled ALLOW_UNUSED = true; |
| 311 bool message_is_ok = true; | 301 bool message_is_ok = true; |
| 312 IPC_BEGIN_MESSAGE_MAP_EX(WebRTCAudioDeviceTest, message, message_is_ok) | 302 IPC_BEGIN_MESSAGE_MAP_EX(WebRTCAudioDeviceTest, message, message_is_ok) |
| 313 IPC_MESSAGE_HANDLER(ViewHostMsg_GetHardwareSampleRate, | 303 IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioHardwareConfig, |
| 314 OnGetHardwareSampleRate) | 304 OnGetAudioHardwareConfig) |
| 315 IPC_MESSAGE_HANDLER(ViewHostMsg_GetHardwareInputSampleRate, | |
| 316 OnGetHardwareInputSampleRate) | |
| 317 IPC_MESSAGE_HANDLER(ViewHostMsg_GetHardwareInputChannelLayout, | |
| 318 OnGetHardwareInputChannelLayout) | |
| 319 IPC_MESSAGE_UNHANDLED(handled = false) | 305 IPC_MESSAGE_UNHANDLED(handled = false) |
| 320 IPC_END_MESSAGE_MAP_EX() | 306 IPC_END_MESSAGE_MAP_EX() |
| 321 | 307 |
| 322 EXPECT_TRUE(message_is_ok); | 308 EXPECT_TRUE(message_is_ok); |
| 323 | 309 |
| 324 return true; | 310 return true; |
| 325 } | 311 } |
| 326 | 312 |
| 327 // Posts a final task to the IO message loop and waits for completion. | 313 // Posts a final task to the IO message loop and waits for completion. |
| 328 void WebRTCAudioDeviceTest::WaitForIOThreadCompletion() { | 314 void WebRTCAudioDeviceTest::WaitForIOThreadCompletion() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 int WebRTCTransportImpl::SendPacket(int channel, const void* data, int len) { | 357 int WebRTCTransportImpl::SendPacket(int channel, const void* data, int len) { |
| 372 return network_->ReceivedRTPPacket(channel, data, len); | 358 return network_->ReceivedRTPPacket(channel, data, len); |
| 373 } | 359 } |
| 374 | 360 |
| 375 int WebRTCTransportImpl::SendRTCPPacket(int channel, const void* data, | 361 int WebRTCTransportImpl::SendRTCPPacket(int channel, const void* data, |
| 376 int len) { | 362 int len) { |
| 377 return network_->ReceivedRTCPPacket(channel, data, len); | 363 return network_->ReceivedRTCPPacket(channel, data, len); |
| 378 } | 364 } |
| 379 | 365 |
| 380 } // namespace content | 366 } // namespace content |
| OLD | NEW |