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 #ifndef CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 5 #ifndef CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 6 #define CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "content/browser/renderer_host/media/mock_media_observer.h" | 14 #include "content/browser/renderer_host/media/mock_media_observer.h" |
15 #include "content/public/renderer/content_renderer_client.h" | 15 #include "content/public/renderer/content_renderer_client.h" |
16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 17 #include "media/base/audio_hardware_config.h" |
17 #include "media/base/channel_layout.h" | 18 #include "media/base/channel_layout.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/webrtc/common_types.h" | 20 #include "third_party/webrtc/common_types.h" |
20 | 21 |
21 namespace IPC { | 22 namespace IPC { |
22 class Channel; | 23 class Channel; |
23 } | 24 } |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 class AudioManager; | 27 class AudioManager; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 103 |
103 T* operator->() { return ptr_; } | 104 T* operator->() { return ptr_; } |
104 T* get() const { return ptr_; } | 105 T* get() const { return ptr_; } |
105 | 106 |
106 bool valid() const { return ptr_ != NULL; } | 107 bool valid() const { return ptr_ != NULL; } |
107 | 108 |
108 protected: | 109 protected: |
109 T* ptr_; | 110 T* ptr_; |
110 }; | 111 }; |
111 | 112 |
112 // Individual tests can provide an implementation (or mock) of this interface | |
113 // when the audio code queries for hardware capabilities on the IO thread. | |
114 class AudioUtilInterface { | |
115 public: | |
116 virtual ~AudioUtilInterface() {} | |
117 virtual int GetAudioHardwareSampleRate() = 0; | |
118 virtual int GetAudioInputHardwareSampleRate( | |
119 const std::string& device_id) = 0; | |
120 virtual media::ChannelLayout GetAudioInputHardwareChannelLayout( | |
121 const std::string& device_id) = 0; | |
122 }; | |
123 | |
124 // Implemented and defined in the cc file. | 113 // Implemented and defined in the cc file. |
125 class ReplaceContentClientRenderer; | 114 class ReplaceContentClientRenderer; |
126 | 115 |
127 class WebRTCAudioDeviceTest : public ::testing::Test, public IPC::Listener { | 116 class WebRTCAudioDeviceTest : public ::testing::Test, public IPC::Listener { |
128 public: | 117 public: |
129 WebRTCAudioDeviceTest(); | 118 WebRTCAudioDeviceTest(); |
130 virtual ~WebRTCAudioDeviceTest(); | 119 virtual ~WebRTCAudioDeviceTest(); |
131 | 120 |
132 virtual void SetUp() OVERRIDE; | 121 virtual void SetUp() OVERRIDE; |
133 virtual void TearDown() OVERRIDE; | 122 virtual void TearDown() OVERRIDE; |
134 | 123 |
135 // Sends an IPC message to the IO thread channel. | 124 // Sends an IPC message to the IO thread channel. |
136 bool Send(IPC::Message* message); | 125 bool Send(IPC::Message* message); |
137 | 126 |
138 void SetAudioUtilCallback(AudioUtilInterface* callback); | 127 void SetAudioHardwareConfig(media::AudioHardwareConfig* hardware_config); |
139 | 128 |
140 protected: | 129 protected: |
141 void InitializeIOThread(const char* thread_name); | 130 void InitializeIOThread(const char* thread_name); |
142 void UninitializeIOThread(); | 131 void UninitializeIOThread(); |
143 void CreateChannel(const char* name); | 132 void CreateChannel(const char* name); |
144 void DestroyChannel(); | 133 void DestroyChannel(); |
145 | 134 |
146 void OnGetHardwareSampleRate(int* sample_rate); | 135 void OnGetAudioHardwareConfig(int* output_buffer_size, |
147 void OnGetHardwareInputSampleRate(int* sample_rate); | 136 int* output_sample_rate, int* input_sample_rate, |
148 void OnGetHardwareInputChannelLayout(media::ChannelLayout* channels); | 137 media::ChannelLayout* input_channel_layout); |
149 | 138 |
150 // IPC::Listener implementation. | 139 // IPC::Listener implementation. |
151 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 140 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
152 | 141 |
153 // Posts a final task to the IO message loop and waits for completion. | 142 // Posts a final task to the IO message loop and waits for completion. |
154 void WaitForIOThreadCompletion(); | 143 void WaitForIOThreadCompletion(); |
155 void WaitForAudioManagerCompletion(); | 144 void WaitForAudioManagerCompletion(); |
156 void WaitForMessageLoopCompletion(base::MessageLoopProxy* loop); | 145 void WaitForMessageLoopCompletion(base::MessageLoopProxy* loop); |
157 | 146 |
158 // Convenience getter for gmock. | 147 // Convenience getter for gmock. |
(...skipping 11 matching lines...) Expand all Loading... |
170 scoped_ptr<MockMediaObserver> media_observer_; | 159 scoped_ptr<MockMediaObserver> media_observer_; |
171 scoped_ptr<MediaStreamManager> media_stream_manager_; | 160 scoped_ptr<MediaStreamManager> media_stream_manager_; |
172 scoped_ptr<media::AudioManager> audio_manager_; | 161 scoped_ptr<media::AudioManager> audio_manager_; |
173 scoped_ptr<AudioMirroringManager> mirroring_manager_; | 162 scoped_ptr<AudioMirroringManager> mirroring_manager_; |
174 scoped_ptr<net::URLRequestContext> test_request_context_; | 163 scoped_ptr<net::URLRequestContext> test_request_context_; |
175 scoped_ptr<ResourceContext> resource_context_; | 164 scoped_ptr<ResourceContext> resource_context_; |
176 scoped_ptr<IPC::Channel> channel_; | 165 scoped_ptr<IPC::Channel> channel_; |
177 scoped_refptr<AudioRendererHost> audio_render_host_; | 166 scoped_refptr<AudioRendererHost> audio_render_host_; |
178 scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_; | 167 scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_; |
179 | 168 |
180 AudioUtilInterface* audio_util_callback_; // Weak reference. | 169 media::AudioHardwareConfig* audio_hardware_config_; // Weak reference. |
181 | 170 |
182 // Initialized on the main test thread that we mark as the UI thread. | 171 // Initialized on the main test thread that we mark as the UI thread. |
183 scoped_ptr<TestBrowserThread> ui_thread_; | 172 scoped_ptr<TestBrowserThread> ui_thread_; |
184 // Initialized on our IO thread to satisfy BrowserThread::IO checks. | 173 // Initialized on our IO thread to satisfy BrowserThread::IO checks. |
185 scoped_ptr<TestBrowserThread> io_thread_; | 174 scoped_ptr<TestBrowserThread> io_thread_; |
186 | 175 |
187 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
188 // COM initialization on the IO thread. | 177 // COM initialization on the IO thread. |
189 scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_; | 178 scoped_ptr<base::win::ScopedCOMInitializer> initialize_com_; |
190 #endif | 179 #endif |
(...skipping 18 matching lines...) Expand all Loading... |
209 virtual int SendPacket(int channel, const void* data, int len) OVERRIDE; | 198 virtual int SendPacket(int channel, const void* data, int len) OVERRIDE; |
210 virtual int SendRTCPPacket(int channel, const void* data, int len) OVERRIDE; | 199 virtual int SendRTCPPacket(int channel, const void* data, int len) OVERRIDE; |
211 | 200 |
212 private: | 201 private: |
213 webrtc::VoENetwork* network_; | 202 webrtc::VoENetwork* network_; |
214 }; | 203 }; |
215 | 204 |
216 } // namespace content | 205 } // namespace content |
217 | 206 |
218 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ | 207 #endif // CONTENT_TEST_WEBRTC_AUDIO_DEVICE_TEST_H_ |
OLD | NEW |