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/audio_renderer_mixer_manager.h" | 5 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "build/build_config.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "content/renderer/media/audio_renderer_sink_cache.h" | 14 #include "content/renderer/media/audio_renderer_sink_cache.h" |
14 #include "media/audio/audio_device_description.h" | 15 #include "media/audio/audio_device_description.h" |
15 #include "media/base/audio_parameters.h" | 16 #include "media/base/audio_parameters.h" |
16 #include "media/base/audio_renderer_mixer.h" | 17 #include "media/base/audio_renderer_mixer.h" |
17 #include "media/base/audio_renderer_mixer_input.h" | 18 #include "media/base/audio_renderer_mixer_input.h" |
18 #include "media/base/fake_audio_render_callback.h" | 19 #include "media/base/fake_audio_render_callback.h" |
19 #include "media/base/mock_audio_renderer_sink.h" | 20 #include "media/base/mock_audio_renderer_sink.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 namespace { | 27 namespace { |
27 const int kBitsPerChannel = 16; | 28 const int kBitsPerChannel = 16; |
28 const int kSampleRate = 48000; | 29 const int kSampleRate = 48000; |
29 const int kBufferSize = 8192; | 30 const int kBufferSize = 8192; |
| 31 const int kHardwareSampleRate = 44100; |
| 32 const int kHardwareBufferSize = 128; |
30 const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; | 33 const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; |
31 const media::ChannelLayout kAnotherChannelLayout = media::CHANNEL_LAYOUT_2_1; | 34 const media::ChannelLayout kAnotherChannelLayout = media::CHANNEL_LAYOUT_2_1; |
32 const char* const kDefaultDeviceId = | 35 const char* const kDefaultDeviceId = |
33 media::AudioDeviceDescription::kDefaultDeviceId; | 36 media::AudioDeviceDescription::kDefaultDeviceId; |
34 const char kAnotherDeviceId[] = "another-device-id"; | 37 const char kAnotherDeviceId[] = "another-device-id"; |
35 const char kMatchedDeviceId[] = "matched-device-id"; | 38 const char kMatchedDeviceId[] = "matched-device-id"; |
36 const char kNonexistentDeviceId[] = "nonexistent-device-id"; | 39 const char kNonexistentDeviceId[] = "nonexistent-device-id"; |
37 | 40 |
38 const int kRenderFrameId = 124; | 41 const int kRenderFrameId = 124; |
39 const int kAnotherRenderFrameId = 678; | 42 const int kAnotherRenderFrameId = 678; |
40 } // namespace; | 43 } // namespace; |
41 | 44 |
42 using media::AudioParameters; | 45 using media::AudioParameters; |
| 46 using media::AudioLatency; |
43 | 47 |
44 class FakeAudioRendererSinkCache : public AudioRendererSinkCache { | 48 class FakeAudioRendererSinkCache : public AudioRendererSinkCache { |
45 public: | 49 public: |
46 using GetSinkCallback = | 50 using GetSinkCallback = |
47 base::Callback<scoped_refptr<media::AudioRendererSink>( | 51 base::Callback<scoped_refptr<media::AudioRendererSink>( |
48 int render_frame_id, | 52 int render_frame_id, |
49 int session_id, | 53 int session_id, |
50 const std::string& device_id, | 54 const std::string& device_id, |
51 const url::Origin& security_origin)>; | 55 const url::Origin& security_origin)>; |
52 | 56 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 class AudioRendererMixerManagerTest : public testing::Test { | 91 class AudioRendererMixerManagerTest : public testing::Test { |
88 public: | 92 public: |
89 AudioRendererMixerManagerTest() | 93 AudioRendererMixerManagerTest() |
90 : manager_(new AudioRendererMixerManager( | 94 : manager_(new AudioRendererMixerManager( |
91 std::unique_ptr<AudioRendererSinkCache>( | 95 std::unique_ptr<AudioRendererSinkCache>( |
92 new FakeAudioRendererSinkCache( | 96 new FakeAudioRendererSinkCache( |
93 base::Bind(&AudioRendererMixerManagerTest::GetSinkPtr, | 97 base::Bind(&AudioRendererMixerManagerTest::GetSinkPtr, |
94 base::Unretained(this)), | 98 base::Unretained(this)), |
95 base::Bind(&AudioRendererMixerManagerTest::ReleaseSinkPtr, | 99 base::Bind(&AudioRendererMixerManagerTest::ReleaseSinkPtr, |
96 base::Unretained(this)))))), | 100 base::Unretained(this)))))), |
97 mock_sink_(new media::MockAudioRendererSink()), | 101 mock_sink_(new media::MockAudioRendererSink( |
| 102 kDefaultDeviceId, |
| 103 media::OUTPUT_DEVICE_STATUS_OK, |
| 104 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, |
| 105 kChannelLayout, |
| 106 kHardwareSampleRate, |
| 107 kBitsPerChannel, |
| 108 kHardwareBufferSize))), |
98 mock_sink_no_device_(new media::MockAudioRendererSink( | 109 mock_sink_no_device_(new media::MockAudioRendererSink( |
99 kNonexistentDeviceId, | 110 kNonexistentDeviceId, |
100 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), | 111 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), |
101 mock_sink_matched_device_( | 112 mock_sink_matched_device_( |
102 new media::MockAudioRendererSink(kMatchedDeviceId, | 113 new media::MockAudioRendererSink(kMatchedDeviceId, |
103 media::OUTPUT_DEVICE_STATUS_OK)), | 114 media::OUTPUT_DEVICE_STATUS_OK)), |
104 kSecurityOrigin2(GURL("http://localhost")) {} | 115 kSecurityOrigin2(GURL("http://localhost")) {} |
105 | 116 |
106 media::AudioRendererMixer* GetMixer( | 117 media::AudioRendererMixer* GetMixer( |
107 int source_render_frame_id, | 118 int source_render_frame_id, |
108 const media::AudioParameters& params, | 119 const media::AudioParameters& params, |
| 120 AudioLatency::LatencyType latency, |
109 const std::string& device_id, | 121 const std::string& device_id, |
110 const url::Origin& security_origin, | 122 const url::Origin& security_origin, |
111 media::OutputDeviceStatus* device_status) { | 123 media::OutputDeviceStatus* device_status) { |
112 return manager_->GetMixer(source_render_frame_id, params, device_id, | 124 return manager_->GetMixer(source_render_frame_id, params, latency, |
113 security_origin, device_status); | 125 device_id, security_origin, device_status); |
114 } | 126 } |
115 | 127 |
116 void ReturnMixer(int source_render_frame_id, | 128 void ReturnMixer(media::AudioRendererMixer* mixer) { |
117 const media::AudioParameters& params, | 129 return manager_->ReturnMixer(mixer); |
118 const std::string& device_id, | |
119 const url::Origin& security_origin) { | |
120 return manager_->ReturnMixer(source_render_frame_id, params, device_id, | |
121 security_origin); | |
122 } | 130 } |
123 | 131 |
124 // Number of instantiated mixers. | 132 // Number of instantiated mixers. |
125 int mixer_count() { | 133 int mixer_count() { |
126 return manager_->mixers_.size(); | 134 return manager_->mixers_.size(); |
127 } | 135 } |
128 | 136 |
129 protected: | 137 protected: |
130 scoped_refptr<media::AudioRendererSink> GetSinkPtr( | 138 scoped_refptr<media::AudioRendererSink> GetSinkPtr( |
131 int source_render_frame_id, | 139 int source_render_frame_id, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // AudioRendererMixerManager to call Start and Stop on our mock twice. | 180 // AudioRendererMixerManager to call Start and Stop on our mock twice. |
173 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 181 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
174 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 182 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
175 | 183 |
176 // We expect 2 mixers to be created; each of them should release the sink. | 184 // We expect 2 mixers to be created; each of them should release the sink. |
177 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 185 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
178 | 186 |
179 // There should be no mixers outstanding to start with. | 187 // There should be no mixers outstanding to start with. |
180 EXPECT_EQ(0, mixer_count()); | 188 EXPECT_EQ(0, mixer_count()); |
181 | 189 |
182 media::AudioParameters params1( | 190 media::AudioParameters params1(media::AudioParameters::AUDIO_PCM_LINEAR, |
183 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 191 kChannelLayout, kSampleRate, kBitsPerChannel, |
184 kBitsPerChannel, kBufferSize); | 192 kBufferSize); |
185 | 193 |
186 media::AudioRendererMixer* mixer1 = GetMixer( | 194 media::AudioRendererMixer* mixer1 = |
187 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 195 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 196 kDefaultDeviceId, kSecurityOrigin, nullptr); |
188 ASSERT_TRUE(mixer1); | 197 ASSERT_TRUE(mixer1); |
189 EXPECT_EQ(1, mixer_count()); | 198 EXPECT_EQ(1, mixer_count()); |
190 | 199 |
191 // The same parameters should return the same mixer1. | 200 // The same parameters should return the same mixer1. |
192 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, | 201 EXPECT_EQ(mixer1, |
193 kSecurityOrigin, nullptr)); | 202 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 203 kDefaultDeviceId, kSecurityOrigin, nullptr)); |
194 EXPECT_EQ(1, mixer_count()); | 204 EXPECT_EQ(1, mixer_count()); |
195 | 205 |
196 // Return the extra mixer we just acquired. | 206 // Return the extra mixer we just acquired. |
197 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 207 ReturnMixer(mixer1); |
198 EXPECT_EQ(1, mixer_count()); | 208 EXPECT_EQ(1, mixer_count()); |
199 | 209 |
200 media::AudioParameters params2( | 210 media::AudioParameters params2( |
201 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, | 211 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, |
202 kBitsPerChannel, kBufferSize * 2); | 212 kBitsPerChannel, kBufferSize * 2); |
203 media::AudioRendererMixer* mixer2 = GetMixer( | 213 media::AudioRendererMixer* mixer2 = |
204 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); | 214 GetMixer(kRenderFrameId, params2, AudioLatency::LATENCY_PLAYBACK, |
| 215 kDefaultDeviceId, kSecurityOrigin, nullptr); |
205 ASSERT_TRUE(mixer2); | 216 ASSERT_TRUE(mixer2); |
206 EXPECT_EQ(2, mixer_count()); | 217 EXPECT_EQ(2, mixer_count()); |
207 | 218 |
208 // Different parameters should result in a different mixer1. | 219 // Different parameters should result in a different mixer1. |
209 EXPECT_NE(mixer1, mixer2); | 220 EXPECT_NE(mixer1, mixer2); |
210 | 221 |
211 // Return both outstanding mixers. | 222 // Return both outstanding mixers. |
212 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 223 ReturnMixer(mixer1); |
213 EXPECT_EQ(1, mixer_count()); | 224 EXPECT_EQ(1, mixer_count()); |
214 ReturnMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 225 ReturnMixer(mixer2); |
215 EXPECT_EQ(0, mixer_count()); | 226 EXPECT_EQ(0, mixer_count()); |
216 } | 227 } |
217 | 228 |
218 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter | 229 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter |
219 // differences. | 230 // differences. |
220 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { | 231 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { |
221 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 232 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
222 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 233 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
223 EXPECT_EQ(mixer_count(), 0); | 234 EXPECT_EQ(mixer_count(), 0); |
224 | 235 |
225 // We expect 2 mixers to be created; each of them should release the sink. | 236 // We expect 2 mixers to be created; each of them should release the sink. |
226 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 237 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
227 | 238 |
228 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, | 239 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, |
229 kChannelLayout, | 240 kChannelLayout, |
230 kSampleRate, | 241 kSampleRate, |
231 kBitsPerChannel, | 242 kBitsPerChannel, |
232 kBufferSize); | 243 kBufferSize); |
233 media::AudioRendererMixer* mixer1 = GetMixer( | 244 media::AudioRendererMixer* mixer1 = |
234 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 245 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 246 kDefaultDeviceId, kSecurityOrigin, nullptr); |
235 ASSERT_TRUE(mixer1); | 247 ASSERT_TRUE(mixer1); |
236 EXPECT_EQ(1, mixer_count()); | 248 EXPECT_EQ(1, mixer_count()); |
237 | 249 |
238 // Different sample rates, formats, bit depths, and buffer sizes should not | 250 // Different sample rates, formats, bit depths, and buffer sizes should not |
239 // result in a different mixer. | 251 // result in a different mixer. |
240 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 252 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
241 kChannelLayout, | 253 kChannelLayout, |
242 kSampleRate * 2, | 254 kSampleRate * 2, |
243 kBitsPerChannel * 2, | 255 kBitsPerChannel * 2, |
244 kBufferSize * 2); | 256 kBufferSize * 2); |
245 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, | 257 media::AudioRendererMixer* mixer2 = |
246 kSecurityOrigin, nullptr)); | 258 GetMixer(kRenderFrameId, params2, AudioLatency::LATENCY_PLAYBACK, |
| 259 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 260 EXPECT_EQ(mixer1, mixer2); |
247 EXPECT_EQ(1, mixer_count()); | 261 EXPECT_EQ(1, mixer_count()); |
248 ReturnMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 262 ReturnMixer(mixer2); |
249 EXPECT_EQ(1, mixer_count()); | 263 EXPECT_EQ(1, mixer_count()); |
250 | 264 |
251 // Modify some parameters that do matter: channel layout | 265 // Modify some parameters that do matter: channel layout |
252 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 266 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
253 kAnotherChannelLayout, | 267 kAnotherChannelLayout, |
254 kSampleRate, | 268 kSampleRate, |
255 kBitsPerChannel, | 269 kBitsPerChannel, |
256 kBufferSize); | 270 kBufferSize); |
257 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); | 271 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); |
258 | 272 media::AudioRendererMixer* mixer3 = |
259 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, | 273 GetMixer(kRenderFrameId, params3, AudioLatency::LATENCY_PLAYBACK, |
260 kSecurityOrigin, nullptr)); | 274 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 275 EXPECT_NE(mixer1, mixer3); |
261 EXPECT_EQ(2, mixer_count()); | 276 EXPECT_EQ(2, mixer_count()); |
262 ReturnMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); | 277 ReturnMixer(mixer3); |
263 EXPECT_EQ(1, mixer_count()); | 278 EXPECT_EQ(1, mixer_count()); |
264 | 279 |
265 // Return final mixer. | 280 // Return final mixer. |
266 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 281 ReturnMixer(mixer1); |
267 EXPECT_EQ(0, mixer_count()); | 282 EXPECT_EQ(0, mixer_count()); |
268 } | 283 } |
269 | 284 |
270 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate | 285 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate |
271 // callbacks and they are working as expected. Also, verify that separate | 286 // callbacks and they are working as expected. Also, verify that separate |
272 // mixers are created for separate RenderFrames, even though the | 287 // mixers are created for separate RenderFrames, even though the |
273 // AudioParameters are the same. | 288 // AudioParameters are the same. |
274 TEST_F(AudioRendererMixerManagerTest, CreateInput) { | 289 TEST_F(AudioRendererMixerManagerTest, CreateInput) { |
275 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice | 290 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice |
276 // each. Note: Under normal conditions, each mixer would get its own sink! | 291 // each. Note: Under normal conditions, each mixer would get its own sink! |
277 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 292 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
278 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 293 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
279 | 294 |
280 // We expect 2 mixers to be created; each of them should release the sink. | 295 // We expect 2 mixers to be created; each of them should release the sink. |
281 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 296 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
282 | 297 |
283 media::AudioParameters params( | 298 media::AudioParameters params( |
284 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 299 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
285 kBitsPerChannel, kBufferSize); | 300 kBitsPerChannel, kBufferSize); |
286 | 301 |
287 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. | 302 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. |
288 EXPECT_EQ(0, mixer_count()); | 303 EXPECT_EQ(0, mixer_count()); |
289 media::FakeAudioRenderCallback callback(0); | 304 media::FakeAudioRenderCallback callback(0); |
290 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput( | 305 scoped_refptr<media::AudioRendererMixerInput> input( |
291 kRenderFrameId, 0, kDefaultDeviceId, kSecurityOrigin)); | 306 manager_->CreateInput(kRenderFrameId, 0, kDefaultDeviceId, |
| 307 kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
292 input->Initialize(params, &callback); | 308 input->Initialize(params, &callback); |
293 EXPECT_EQ(0, mixer_count()); | 309 EXPECT_EQ(0, mixer_count()); |
294 media::FakeAudioRenderCallback another_callback(1); | 310 media::FakeAudioRenderCallback another_callback(1); |
295 scoped_refptr<media::AudioRendererMixerInput> another_input( | 311 scoped_refptr<media::AudioRendererMixerInput> another_input( |
296 manager_->CreateInput(kAnotherRenderFrameId, 0, kDefaultDeviceId, | 312 manager_->CreateInput(kAnotherRenderFrameId, 0, kDefaultDeviceId, |
297 kSecurityOrigin)); | 313 kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
298 another_input->Initialize(params, &another_callback); | 314 another_input->Initialize(params, &another_callback); |
299 EXPECT_EQ(0, mixer_count()); | 315 EXPECT_EQ(0, mixer_count()); |
300 | 316 |
301 // Implicitly test that AudioRendererMixerInput was provided with the expected | 317 // Implicitly test that AudioRendererMixerInput was provided with the expected |
302 // callbacks needed to acquire an AudioRendererMixer and return it. | 318 // callbacks needed to acquire an AudioRendererMixer and return it. |
303 input->Start(); | 319 input->Start(); |
304 EXPECT_EQ(1, mixer_count()); | 320 EXPECT_EQ(1, mixer_count()); |
305 another_input->Start(); | 321 another_input->Start(); |
306 EXPECT_EQ(2, mixer_count()); | 322 EXPECT_EQ(2, mixer_count()); |
307 | 323 |
(...skipping 26 matching lines...) Expand all Loading... |
334 | 350 |
335 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 351 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
336 kChannelLayout, kSampleRate, kBitsPerChannel, | 352 kChannelLayout, kSampleRate, kBitsPerChannel, |
337 kBufferSize); | 353 kBufferSize); |
338 media::FakeAudioRenderCallback callback(0); | 354 media::FakeAudioRenderCallback callback(0); |
339 EXPECT_EQ(0, mixer_count()); | 355 EXPECT_EQ(0, mixer_count()); |
340 | 356 |
341 // Empty device id, zero session id; | 357 // Empty device id, zero session id; |
342 scoped_refptr<media::AudioRendererMixerInput> input_to_default_device( | 358 scoped_refptr<media::AudioRendererMixerInput> input_to_default_device( |
343 manager_->CreateInput(kRenderFrameId, 0, // session_id | 359 manager_->CreateInput(kRenderFrameId, 0, // session_id |
344 std::string(), kSecurityOrigin)); | 360 std::string(), kSecurityOrigin, |
| 361 AudioLatency::LATENCY_PLAYBACK)); |
345 input_to_default_device->Initialize(params, &callback); | 362 input_to_default_device->Initialize(params, &callback); |
346 EXPECT_EQ(0, mixer_count()); | 363 EXPECT_EQ(0, mixer_count()); |
347 | 364 |
348 // Specific device id, zero session id; | 365 // Specific device id, zero session id; |
349 scoped_refptr<media::AudioRendererMixerInput> input_to_matched_device( | 366 scoped_refptr<media::AudioRendererMixerInput> input_to_matched_device( |
350 manager_->CreateInput(kRenderFrameId, 0, // session_id | 367 manager_->CreateInput(kRenderFrameId, 0, // session_id |
351 kMatchedDeviceId, kSecurityOrigin)); | 368 kMatchedDeviceId, kSecurityOrigin, |
| 369 AudioLatency::LATENCY_PLAYBACK)); |
352 input_to_matched_device->Initialize(params, &callback); | 370 input_to_matched_device->Initialize(params, &callback); |
353 EXPECT_EQ(0, mixer_count()); | 371 EXPECT_EQ(0, mixer_count()); |
354 | 372 |
355 // Specific device id, non-zero session id (to be ignored); | 373 // Specific device id, non-zero session id (to be ignored); |
356 scoped_refptr<media::AudioRendererMixerInput> input_to_another_device( | 374 scoped_refptr<media::AudioRendererMixerInput> input_to_another_device( |
357 manager_->CreateInput(kRenderFrameId, 1, // session id | 375 manager_->CreateInput(kRenderFrameId, 1, // session id |
358 kAnotherDeviceId, kSecurityOrigin)); | 376 kAnotherDeviceId, kSecurityOrigin, |
| 377 AudioLatency::LATENCY_PLAYBACK)); |
359 input_to_another_device->Initialize(params, &callback); | 378 input_to_another_device->Initialize(params, &callback); |
360 EXPECT_EQ(0, mixer_count()); | 379 EXPECT_EQ(0, mixer_count()); |
361 | 380 |
362 // Empty device id, non-zero session id; | 381 // Empty device id, non-zero session id; |
363 scoped_refptr<media::AudioRendererMixerInput> | 382 scoped_refptr<media::AudioRendererMixerInput> |
364 input_to_matched_device_with_session_id( | 383 input_to_matched_device_with_session_id(manager_->CreateInput( |
365 manager_->CreateInput(kRenderFrameId, 2, // session id | 384 kRenderFrameId, 2, // session id |
366 std::string(), kSecurityOrigin)); | 385 std::string(), kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
367 input_to_matched_device_with_session_id->Initialize(params, &callback); | 386 input_to_matched_device_with_session_id->Initialize(params, &callback); |
368 EXPECT_EQ(0, mixer_count()); | 387 EXPECT_EQ(0, mixer_count()); |
369 | 388 |
370 // Implicitly test that AudioRendererMixerInput was provided with the expected | 389 // Implicitly test that AudioRendererMixerInput was provided with the expected |
371 // callbacks needed to acquire an AudioRendererMixer and return it. | 390 // callbacks needed to acquire an AudioRendererMixer and return it. |
372 input_to_default_device->Start(); | 391 input_to_default_device->Start(); |
373 EXPECT_EQ(1, mixer_count()); | 392 EXPECT_EQ(1, mixer_count()); |
374 | 393 |
375 input_to_another_device->Start(); | 394 input_to_another_device->Start(); |
376 EXPECT_EQ(2, mixer_count()); | 395 EXPECT_EQ(2, mixer_count()); |
(...skipping 26 matching lines...) Expand all Loading... |
403 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); | 422 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); |
404 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); | 423 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); |
405 EXPECT_EQ(0, mixer_count()); | 424 EXPECT_EQ(0, mixer_count()); |
406 | 425 |
407 // We expect 3 mixers to be created; each of them should release a sink. | 426 // We expect 3 mixers to be created; each of them should release a sink. |
408 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(3); | 427 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(3); |
409 | 428 |
410 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 429 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
411 kChannelLayout, kSampleRate, kBitsPerChannel, | 430 kChannelLayout, kSampleRate, kBitsPerChannel, |
412 kBufferSize); | 431 kBufferSize); |
413 media::AudioRendererMixer* mixer1 = GetMixer( | 432 media::AudioRendererMixer* mixer1 = |
414 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 433 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 434 kDefaultDeviceId, kSecurityOrigin, nullptr); |
415 ASSERT_TRUE(mixer1); | 435 ASSERT_TRUE(mixer1); |
416 EXPECT_EQ(1, mixer_count()); | 436 EXPECT_EQ(1, mixer_count()); |
417 | 437 |
418 media::AudioRendererMixer* mixer2 = GetMixer( | 438 media::AudioRendererMixer* mixer2 = |
419 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin, nullptr); | 439 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 440 kAnotherDeviceId, kSecurityOrigin, nullptr); |
420 ASSERT_TRUE(mixer2); | 441 ASSERT_TRUE(mixer2); |
421 EXPECT_EQ(2, mixer_count()); | 442 EXPECT_EQ(2, mixer_count()); |
422 EXPECT_NE(mixer1, mixer2); | 443 EXPECT_NE(mixer1, mixer2); |
423 | 444 |
424 media::AudioRendererMixer* mixer3 = GetMixer( | 445 media::AudioRendererMixer* mixer3 = |
425 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2, nullptr); | 446 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 447 kAnotherDeviceId, kSecurityOrigin2, nullptr); |
426 ASSERT_TRUE(mixer3); | 448 ASSERT_TRUE(mixer3); |
427 EXPECT_EQ(3, mixer_count()); | 449 EXPECT_EQ(3, mixer_count()); |
428 EXPECT_NE(mixer1, mixer3); | 450 EXPECT_NE(mixer1, mixer3); |
429 EXPECT_NE(mixer2, mixer3); | 451 EXPECT_NE(mixer2, mixer3); |
430 | 452 |
431 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 453 ReturnMixer(mixer1); |
432 EXPECT_EQ(2, mixer_count()); | 454 EXPECT_EQ(2, mixer_count()); |
433 ReturnMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin); | 455 ReturnMixer(mixer2); |
434 EXPECT_EQ(1, mixer_count()); | 456 EXPECT_EQ(1, mixer_count()); |
435 ReturnMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2); | 457 ReturnMixer(mixer3); |
436 EXPECT_EQ(0, mixer_count()); | 458 EXPECT_EQ(0, mixer_count()); |
437 } | 459 } |
438 | 460 |
439 // Verify GetMixer() correctly deduplicate mixers with the same | 461 // Verify GetMixer() correctly deduplicate mixers with the same |
440 // parameters, different security origins but default device ID | 462 // parameters, different security origins but default device ID |
441 TEST_F(AudioRendererMixerManagerTest, OneMixerDifferentOriginsDefaultDevice) { | 463 TEST_F(AudioRendererMixerManagerTest, OneMixerDifferentOriginsDefaultDevice) { |
442 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); | 464 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
443 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); | 465 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
444 EXPECT_EQ(0, mixer_count()); | 466 EXPECT_EQ(0, mixer_count()); |
445 | 467 |
446 // We expect 1 mixer to be created; it should release its sink. | 468 // We expect 1 mixer to be created; it should release its sink. |
447 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); | 469 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
448 | 470 |
449 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 471 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
450 kChannelLayout, kSampleRate, kBitsPerChannel, | 472 kChannelLayout, kSampleRate, kBitsPerChannel, |
451 kBufferSize); | 473 kBufferSize); |
452 media::AudioRendererMixer* mixer1 = GetMixer( | 474 media::AudioRendererMixer* mixer1 = |
453 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 475 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 476 kDefaultDeviceId, kSecurityOrigin, nullptr); |
454 ASSERT_TRUE(mixer1); | 477 ASSERT_TRUE(mixer1); |
455 EXPECT_EQ(1, mixer_count()); | 478 EXPECT_EQ(1, mixer_count()); |
456 | 479 |
457 media::AudioRendererMixer* mixer2 = | 480 media::AudioRendererMixer* mixer2 = |
458 GetMixer(kRenderFrameId, params, std::string(), kSecurityOrigin, nullptr); | 481 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 482 std::string(), kSecurityOrigin, nullptr); |
459 ASSERT_TRUE(mixer2); | 483 ASSERT_TRUE(mixer2); |
460 EXPECT_EQ(1, mixer_count()); | 484 EXPECT_EQ(1, mixer_count()); |
461 EXPECT_EQ(mixer1, mixer2); | 485 EXPECT_EQ(mixer1, mixer2); |
462 | 486 |
463 media::AudioRendererMixer* mixer3 = GetMixer( | 487 media::AudioRendererMixer* mixer3 = |
464 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin2, nullptr); | 488 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 489 kDefaultDeviceId, kSecurityOrigin2, nullptr); |
465 ASSERT_TRUE(mixer3); | 490 ASSERT_TRUE(mixer3); |
466 EXPECT_EQ(1, mixer_count()); | 491 EXPECT_EQ(1, mixer_count()); |
467 EXPECT_EQ(mixer1, mixer3); | 492 EXPECT_EQ(mixer1, mixer3); |
468 | 493 |
469 media::AudioRendererMixer* mixer4 = GetMixer( | 494 media::AudioRendererMixer* mixer4 = |
470 kRenderFrameId, params, std::string(), kSecurityOrigin2, nullptr); | 495 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 496 std::string(), kSecurityOrigin2, nullptr); |
471 ASSERT_TRUE(mixer4); | 497 ASSERT_TRUE(mixer4); |
472 EXPECT_EQ(1, mixer_count()); | 498 EXPECT_EQ(1, mixer_count()); |
473 EXPECT_EQ(mixer1, mixer4); | 499 EXPECT_EQ(mixer1, mixer4); |
474 | 500 |
475 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 501 ReturnMixer(mixer1); |
476 EXPECT_EQ(1, mixer_count()); | 502 EXPECT_EQ(1, mixer_count()); |
477 ReturnMixer(kRenderFrameId, params, std::string(), kSecurityOrigin); | 503 ReturnMixer(mixer2); |
478 EXPECT_EQ(1, mixer_count()); | 504 EXPECT_EQ(1, mixer_count()); |
479 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin2); | 505 ReturnMixer(mixer3); |
480 EXPECT_EQ(1, mixer_count()); | 506 EXPECT_EQ(1, mixer_count()); |
481 ReturnMixer(kRenderFrameId, params, std::string(), kSecurityOrigin2); | 507 ReturnMixer(mixer4); |
482 EXPECT_EQ(0, mixer_count()); | 508 EXPECT_EQ(0, mixer_count()); |
483 } | 509 } |
484 | 510 |
485 // Verify that GetMixer() correctly returns a null mixer and an appropriate | 511 // Verify that GetMixer() correctly returns a null mixer and an appropriate |
486 // status code when a nonexistent device is requested. | 512 // status code when a nonexistent device is requested. |
487 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { | 513 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { |
488 EXPECT_EQ(0, mixer_count()); | 514 EXPECT_EQ(0, mixer_count()); |
489 | 515 |
490 // Mixer manager should release a not-ok sink when failing to create a mixer. | 516 // Mixer manager should release a not-ok sink when failing to create a mixer. |
491 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_no_device_.get())).Times(1); | 517 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_no_device_.get())).Times(1); |
492 | 518 |
493 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 519 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
494 kChannelLayout, kSampleRate, kBitsPerChannel, | 520 kChannelLayout, kSampleRate, kBitsPerChannel, |
495 kBufferSize); | 521 kBufferSize); |
496 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; | 522 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; |
497 | 523 |
498 media::AudioRendererMixer* mixer = | 524 media::AudioRendererMixer* mixer = |
499 GetMixer(kRenderFrameId, params, kNonexistentDeviceId, kSecurityOrigin, | 525 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
500 &device_status); | 526 kNonexistentDeviceId, kSecurityOrigin, &device_status); |
501 | 527 |
502 EXPECT_FALSE(mixer); | 528 EXPECT_FALSE(mixer); |
503 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); | 529 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); |
504 EXPECT_EQ(0, mixer_count()); | 530 EXPECT_EQ(0, mixer_count()); |
505 } | 531 } |
506 | 532 |
| 533 // Verify GetMixer() correctly deduplicate mixers basing on latency |
| 534 // requirements. |
| 535 TEST_F(AudioRendererMixerManagerTest, LatencyMixing) { |
| 536 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); |
| 537 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); |
| 538 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(3); |
| 539 |
| 540 EXPECT_EQ(0, mixer_count()); |
| 541 |
| 542 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 543 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 544 kBufferSize); |
| 545 media::AudioRendererMixer* mixer1 = |
| 546 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 547 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 548 ASSERT_TRUE(mixer1); |
| 549 EXPECT_EQ(1, mixer_count()); |
| 550 |
| 551 media::AudioRendererMixer* mixer2 = |
| 552 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 553 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 554 ASSERT_TRUE(mixer2); |
| 555 EXPECT_EQ(mixer1, mixer2); // Same latency => same mixer. |
| 556 EXPECT_EQ(1, mixer_count()); |
| 557 |
| 558 media::AudioRendererMixer* mixer3 = |
| 559 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_RTC, |
| 560 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 561 ASSERT_TRUE(mixer3); |
| 562 EXPECT_NE(mixer1, mixer3); |
| 563 EXPECT_EQ(2, mixer_count()); // Another latency => another mixer. |
| 564 |
| 565 media::AudioRendererMixer* mixer4 = |
| 566 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_RTC, |
| 567 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 568 EXPECT_EQ(mixer3, mixer4); |
| 569 EXPECT_EQ(2, mixer_count()); // Same latency => same mixer. |
| 570 |
| 571 media::AudioRendererMixer* mixer5 = |
| 572 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_INTERACTIVE, |
| 573 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 574 ASSERT_TRUE(mixer5); |
| 575 EXPECT_EQ(3, mixer_count()); // Another latency => another mixer. |
| 576 |
| 577 media::AudioRendererMixer* mixer6 = |
| 578 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_INTERACTIVE, |
| 579 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 580 EXPECT_EQ(mixer5, mixer6); |
| 581 EXPECT_EQ(3, mixer_count()); // Same latency => same mixer. |
| 582 |
| 583 ReturnMixer(mixer1); |
| 584 EXPECT_EQ(3, mixer_count()); |
| 585 ReturnMixer(mixer2); |
| 586 EXPECT_EQ(2, mixer_count()); |
| 587 ReturnMixer(mixer3); |
| 588 EXPECT_EQ(2, mixer_count()); |
| 589 ReturnMixer(mixer4); |
| 590 EXPECT_EQ(1, mixer_count()); |
| 591 ReturnMixer(mixer5); |
| 592 EXPECT_EQ(1, mixer_count()); |
| 593 ReturnMixer(mixer6); |
| 594 EXPECT_EQ(0, mixer_count()); |
| 595 } |
| 596 |
| 597 // Verify output bufer size of the mixer is correctly adjusted for Playback |
| 598 // latency. |
| 599 TEST_F(AudioRendererMixerManagerTest, MixerParamsLatencyPlayback) { |
| 600 // Expecting hardware buffer size of 128 frames |
| 601 EXPECT_EQ(44100, |
| 602 mock_sink_->GetOutputDeviceInfo().output_params().sample_rate()); |
| 603 // Expecting hardware buffer size of 128 frames |
| 604 EXPECT_EQ( |
| 605 128, |
| 606 mock_sink_->GetOutputDeviceInfo().output_params().frames_per_buffer()); |
| 607 |
| 608 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 609 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 610 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 611 |
| 612 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 613 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 614 |
| 615 media::AudioRendererMixer* mixer = |
| 616 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 617 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 618 |
| 619 #if defined(OS_CHROMEOS) |
| 620 // Expecting input sample rate |
| 621 EXPECT_EQ(32000, mixer->GetOutputParamsForTesting().sample_rate()); |
| 622 // Round up 20 ms (640) to the power of 2. |
| 623 EXPECT_EQ(1024, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 624 |
| 625 #else |
| 626 // Expecting hardware sample rate |
| 627 EXPECT_EQ(44100, mixer->GetOutputParamsForTesting().sample_rate()); |
| 628 |
| 629 // 20 ms at 44100 is 882 frames per buffer. |
| 630 #if defined(OS_WIN) |
| 631 // Round up 882 to the nearest multiple of the output buffer size (128). which |
| 632 // is 7 * 128 = 896 |
| 633 EXPECT_EQ(896, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 634 #else |
| 635 // Round up 882 to the power of 2. |
| 636 EXPECT_EQ(1024, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 637 #endif // defined(OS_WIN) |
| 638 |
| 639 #endif // defined(OS_CHROMEOS) |
| 640 |
| 641 ReturnMixer(mixer); |
| 642 } |
| 643 |
| 644 // Verify output bufer size of the mixer is correctly adjusted for Playback |
| 645 // latency when the device buffer size exceeds 20 ms. |
| 646 TEST_F(AudioRendererMixerManagerTest, |
| 647 MixerParamsLatencyPlaybackLargeDeviceBufferSize) { |
| 648 mock_sink_ = new media::MockAudioRendererSink( |
| 649 std::string(), media::OUTPUT_DEVICE_STATUS_OK, |
| 650 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 44100, |
| 651 kBitsPerChannel, 2048)); |
| 652 |
| 653 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 654 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 655 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 656 |
| 657 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 658 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 659 |
| 660 media::AudioRendererMixer* mixer = |
| 661 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 662 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 663 |
| 664 // 20 ms at 44100 is 882 frames per buffer. |
| 665 #if defined(OS_CHROMEOS) |
| 666 // Expecting input sample rate |
| 667 EXPECT_EQ(32000, mixer->GetOutputParamsForTesting().sample_rate()); |
| 668 // Ignore device buffer size, round up 20 ms (640) to the power of 2. |
| 669 EXPECT_EQ(1024, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 670 #else |
| 671 // Expecting hardware sample rate |
| 672 EXPECT_EQ(44100, mixer->GetOutputParamsForTesting().sample_rate()); |
| 673 // Prefer device buffer size (2048) if is larger than 20 ms buffer size (882). |
| 674 EXPECT_EQ(2048, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 675 #endif |
| 676 |
| 677 ReturnMixer(mixer); |
| 678 } |
| 679 |
| 680 // Verify output bufer size of the mixer is correctly adjusted for Playback |
| 681 // latency when output audio is fake. |
| 682 TEST_F(AudioRendererMixerManagerTest, MixerParamsLatencyPlaybackFakeAudio) { |
| 683 mock_sink_ = new media::MockAudioRendererSink( |
| 684 std::string(), media::OUTPUT_DEVICE_STATUS_OK, |
| 685 AudioParameters(AudioParameters::AUDIO_FAKE, kChannelLayout, 44100, |
| 686 kBitsPerChannel, 2048)); |
| 687 |
| 688 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 689 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 690 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 691 |
| 692 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 693 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 694 |
| 695 media::AudioRendererMixer* mixer = |
| 696 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 697 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 698 |
| 699 // Expecting input sample rate |
| 700 EXPECT_EQ(32000, mixer->GetOutputParamsForTesting().sample_rate()); |
| 701 |
| 702 // 20 ms at 32000 is 640 frames per buffer. |
| 703 #if defined(OS_WIN) |
| 704 // Use 20 ms buffer. |
| 705 EXPECT_EQ(640, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 706 #else |
| 707 // Ignore device buffer size, round up 640 to the power of 2. |
| 708 EXPECT_EQ(1024, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 709 #endif // defined(OS_WIN) |
| 710 |
| 711 ReturnMixer(mixer); |
| 712 } |
| 713 |
| 714 // Verify output bufer size of the mixer is correctly adjusted for RTC latency. |
| 715 TEST_F(AudioRendererMixerManagerTest, MixerParamsLatencyRtc) { |
| 716 // Expecting hardware buffer size of 128 frames |
| 717 EXPECT_EQ(44100, |
| 718 mock_sink_->GetOutputDeviceInfo().output_params().sample_rate()); |
| 719 // Expecting hardware buffer size of 128 frames |
| 720 EXPECT_EQ( |
| 721 128, |
| 722 mock_sink_->GetOutputDeviceInfo().output_params().frames_per_buffer()); |
| 723 |
| 724 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 725 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 726 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 727 |
| 728 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 729 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 730 |
| 731 media::AudioRendererMixer* mixer = |
| 732 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_RTC, |
| 733 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 734 |
| 735 #if defined(OS_CHROMEOS) |
| 736 int output_sample_rate = 32000; |
| 737 #else |
| 738 // Expecting hardware sample rate. |
| 739 int output_sample_rate = 44100; |
| 740 #endif // defined(OS_CHROMEOS) |
| 741 |
| 742 EXPECT_EQ(output_sample_rate, |
| 743 mixer->GetOutputParamsForTesting().sample_rate()); |
| 744 |
| 745 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 746 // Use 10 ms buffer (441 frames per buffer). |
| 747 EXPECT_EQ(output_sample_rate / 100, |
| 748 mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 749 #elif defined(OS_ANDROID) |
| 750 // If hardware buffer size (128) is less than 20 ms (882), use 20 ms buffer |
| 751 // (otherwise, use hardware buffer). |
| 752 EXPECT_EQ(882, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 753 #else |
| 754 // Use hardware buffer size (128). |
| 755 EXPECT_EQ(128, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 756 #endif // defined(OS_LINUX) || defined(OS_MACOSX) |
| 757 |
| 758 ReturnMixer(mixer); |
| 759 } |
| 760 |
| 761 // Verify output bufer size of the mixer is correctly adjusted for RTC latency |
| 762 // when output audio is fake. |
| 763 TEST_F(AudioRendererMixerManagerTest, MixerParamsLatencyRtcFakeAudio) { |
| 764 mock_sink_ = new media::MockAudioRendererSink( |
| 765 std::string(), media::OUTPUT_DEVICE_STATUS_OK, |
| 766 AudioParameters(AudioParameters::AUDIO_FAKE, kChannelLayout, 44100, |
| 767 kBitsPerChannel, 128)); |
| 768 |
| 769 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 770 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 771 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 772 |
| 773 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 774 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 775 |
| 776 media::AudioRendererMixer* mixer = |
| 777 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_RTC, |
| 778 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 779 |
| 780 // Expecting input sample rate. |
| 781 EXPECT_EQ(32000, mixer->GetOutputParamsForTesting().sample_rate()); |
| 782 |
| 783 // 10 ms at 32000 is 320 frames per buffer. Expect it on all the platforms for |
| 784 // fake audio output. |
| 785 EXPECT_EQ(320, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 786 |
| 787 ReturnMixer(mixer); |
| 788 } |
| 789 |
| 790 // Verify output bufer size of the mixer is correctly adjusted for Interactive |
| 791 // latency. |
| 792 TEST_F(AudioRendererMixerManagerTest, MixerParamsLatencyInteractive) { |
| 793 // Expecting hardware buffer size of 128 frames |
| 794 EXPECT_EQ(44100, |
| 795 mock_sink_->GetOutputDeviceInfo().output_params().sample_rate()); |
| 796 // Expecting hardware buffer size of 128 frames |
| 797 EXPECT_EQ( |
| 798 128, |
| 799 mock_sink_->GetOutputDeviceInfo().output_params().frames_per_buffer()); |
| 800 |
| 801 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 802 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 803 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 804 |
| 805 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 806 kChannelLayout, 32000, kBitsPerChannel, 512); |
| 807 |
| 808 media::AudioRendererMixer* mixer = |
| 809 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_INTERACTIVE, |
| 810 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 811 |
| 812 #if defined(OS_CHROMEOS) |
| 813 // Expecting input sample rate. |
| 814 EXPECT_EQ(32000, mixer->GetOutputParamsForTesting().sample_rate()); |
| 815 #else |
| 816 // Expecting hardware sample rate. |
| 817 EXPECT_EQ(44100, mixer->GetOutputParamsForTesting().sample_rate()); |
| 818 #endif // defined(OS_CHROMEOS) |
| 819 |
| 820 #if defined(OS_ANDROID) |
| 821 // If hardware buffer size (128) is less than 1024, use 2048. |
| 822 EXPECT_EQ(2048, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 823 #else |
| 824 // Expect hardware buffer size. |
| 825 EXPECT_EQ(128, mixer->GetOutputParamsForTesting().frames_per_buffer()); |
| 826 #endif |
| 827 |
| 828 ReturnMixer(mixer); |
| 829 } |
| 830 |
507 } // namespace content | 831 } // namespace content |
OLD | NEW |