| 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 "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 media::AudioDeviceDescription::kDefaultDeviceId; | 33 media::AudioDeviceDescription::kDefaultDeviceId; |
| 34 const char kAnotherDeviceId[] = "another-device-id"; | 34 const char kAnotherDeviceId[] = "another-device-id"; |
| 35 const char kMatchedDeviceId[] = "matched-device-id"; | 35 const char kMatchedDeviceId[] = "matched-device-id"; |
| 36 const char kNonexistentDeviceId[] = "nonexistent-device-id"; | 36 const char kNonexistentDeviceId[] = "nonexistent-device-id"; |
| 37 | 37 |
| 38 const int kRenderFrameId = 124; | 38 const int kRenderFrameId = 124; |
| 39 const int kAnotherRenderFrameId = 678; | 39 const int kAnotherRenderFrameId = 678; |
| 40 } // namespace; | 40 } // namespace; |
| 41 | 41 |
| 42 using media::AudioParameters; | 42 using media::AudioParameters; |
| 43 using media::AudioLatency; |
| 43 | 44 |
| 44 class FakeAudioRendererSinkCache : public AudioRendererSinkCache { | 45 class FakeAudioRendererSinkCache : public AudioRendererSinkCache { |
| 45 public: | 46 public: |
| 46 using GetSinkCallback = | 47 using GetSinkCallback = |
| 47 base::Callback<scoped_refptr<media::AudioRendererSink>( | 48 base::Callback<scoped_refptr<media::AudioRendererSink>( |
| 48 int render_frame_id, | 49 int render_frame_id, |
| 49 int session_id, | 50 int session_id, |
| 50 const std::string& device_id, | 51 const std::string& device_id, |
| 51 const url::Origin& security_origin)>; | 52 const url::Origin& security_origin)>; |
| 52 | 53 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 kNonexistentDeviceId, | 100 kNonexistentDeviceId, |
| 100 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), | 101 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), |
| 101 mock_sink_matched_device_( | 102 mock_sink_matched_device_( |
| 102 new media::MockAudioRendererSink(kMatchedDeviceId, | 103 new media::MockAudioRendererSink(kMatchedDeviceId, |
| 103 media::OUTPUT_DEVICE_STATUS_OK)), | 104 media::OUTPUT_DEVICE_STATUS_OK)), |
| 104 kSecurityOrigin2(GURL("http://localhost")) {} | 105 kSecurityOrigin2(GURL("http://localhost")) {} |
| 105 | 106 |
| 106 media::AudioRendererMixer* GetMixer( | 107 media::AudioRendererMixer* GetMixer( |
| 107 int source_render_frame_id, | 108 int source_render_frame_id, |
| 108 const media::AudioParameters& params, | 109 const media::AudioParameters& params, |
| 110 AudioLatency::LatencyType latency, |
| 109 const std::string& device_id, | 111 const std::string& device_id, |
| 110 const url::Origin& security_origin, | 112 const url::Origin& security_origin, |
| 111 media::OutputDeviceStatus* device_status) { | 113 media::OutputDeviceStatus* device_status) { |
| 112 return manager_->GetMixer(source_render_frame_id, params, device_id, | 114 return manager_->GetMixer(source_render_frame_id, params, latency, |
| 113 security_origin, device_status); | 115 device_id, security_origin, device_status); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void ReturnMixer(int source_render_frame_id, | 118 void ReturnMixer(const media::AudioRendererMixer* mixer) { |
| 117 const media::AudioParameters& params, | 119 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 } | 120 } |
| 123 | 121 |
| 124 // Number of instantiated mixers. | 122 // Number of instantiated mixers. |
| 125 int mixer_count() { | 123 int mixer_count() { |
| 126 return manager_->mixers_.size(); | 124 return manager_->mixers_.size(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 protected: | 127 protected: |
| 130 scoped_refptr<media::AudioRendererSink> GetSinkPtr( | 128 scoped_refptr<media::AudioRendererSink> GetSinkPtr( |
| 131 int source_render_frame_id, | 129 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. | 170 // AudioRendererMixerManager to call Start and Stop on our mock twice. |
| 173 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 171 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 174 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 172 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 175 | 173 |
| 176 // We expect 2 mixers to be created; each of them should release the sink. | 174 // We expect 2 mixers to be created; each of them should release the sink. |
| 177 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 175 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
| 178 | 176 |
| 179 // There should be no mixers outstanding to start with. | 177 // There should be no mixers outstanding to start with. |
| 180 EXPECT_EQ(0, mixer_count()); | 178 EXPECT_EQ(0, mixer_count()); |
| 181 | 179 |
| 182 media::AudioParameters params1( | 180 media::AudioParameters params1(media::AudioParameters::AUDIO_PCM_LINEAR, |
| 183 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 181 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 184 kBitsPerChannel, kBufferSize); | 182 kBufferSize); |
| 185 | 183 |
| 186 media::AudioRendererMixer* mixer1 = GetMixer( | 184 media::AudioRendererMixer* mixer1 = |
| 187 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 185 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 186 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 188 ASSERT_TRUE(mixer1); | 187 ASSERT_TRUE(mixer1); |
| 189 EXPECT_EQ(1, mixer_count()); | 188 EXPECT_EQ(1, mixer_count()); |
| 190 | 189 |
| 191 // The same parameters should return the same mixer1. | 190 // The same parameters should return the same mixer1. |
| 192 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, | 191 EXPECT_EQ(mixer1, |
| 193 kSecurityOrigin, nullptr)); | 192 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 193 kDefaultDeviceId, kSecurityOrigin, nullptr)); |
| 194 EXPECT_EQ(1, mixer_count()); | 194 EXPECT_EQ(1, mixer_count()); |
| 195 | 195 |
| 196 // Return the extra mixer we just acquired. | 196 // Return the extra mixer we just acquired. |
| 197 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 197 ReturnMixer(mixer1); |
| 198 EXPECT_EQ(1, mixer_count()); | 198 EXPECT_EQ(1, mixer_count()); |
| 199 | 199 |
| 200 media::AudioParameters params2( | 200 media::AudioParameters params2( |
| 201 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, | 201 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, |
| 202 kBitsPerChannel, kBufferSize * 2); | 202 kBitsPerChannel, kBufferSize * 2); |
| 203 media::AudioRendererMixer* mixer2 = GetMixer( | 203 media::AudioRendererMixer* mixer2 = |
| 204 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); | 204 GetMixer(kRenderFrameId, params2, AudioLatency::LATENCY_PLAYBACK, |
| 205 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 205 ASSERT_TRUE(mixer2); | 206 ASSERT_TRUE(mixer2); |
| 206 EXPECT_EQ(2, mixer_count()); | 207 EXPECT_EQ(2, mixer_count()); |
| 207 | 208 |
| 208 // Different parameters should result in a different mixer1. | 209 // Different parameters should result in a different mixer1. |
| 209 EXPECT_NE(mixer1, mixer2); | 210 EXPECT_NE(mixer1, mixer2); |
| 210 | 211 |
| 211 // Return both outstanding mixers. | 212 // Return both outstanding mixers. |
| 212 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 213 ReturnMixer(mixer1); |
| 213 EXPECT_EQ(1, mixer_count()); | 214 EXPECT_EQ(1, mixer_count()); |
| 214 ReturnMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 215 ReturnMixer(mixer2); |
| 215 EXPECT_EQ(0, mixer_count()); | 216 EXPECT_EQ(0, mixer_count()); |
| 216 } | 217 } |
| 217 | 218 |
| 218 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter | 219 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter |
| 219 // differences. | 220 // differences. |
| 220 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { | 221 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { |
| 221 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 222 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 222 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 223 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 223 EXPECT_EQ(mixer_count(), 0); | 224 EXPECT_EQ(mixer_count(), 0); |
| 224 | 225 |
| 225 // We expect 2 mixers to be created; each of them should release the sink. | 226 // We expect 2 mixers to be created; each of them should release the sink. |
| 226 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 227 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
| 227 | 228 |
| 228 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, | 229 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, |
| 229 kChannelLayout, | 230 kChannelLayout, |
| 230 kSampleRate, | 231 kSampleRate, |
| 231 kBitsPerChannel, | 232 kBitsPerChannel, |
| 232 kBufferSize); | 233 kBufferSize); |
| 233 media::AudioRendererMixer* mixer1 = GetMixer( | 234 media::AudioRendererMixer* mixer1 = |
| 234 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 235 GetMixer(kRenderFrameId, params1, AudioLatency::LATENCY_PLAYBACK, |
| 236 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 235 ASSERT_TRUE(mixer1); | 237 ASSERT_TRUE(mixer1); |
| 236 EXPECT_EQ(1, mixer_count()); | 238 EXPECT_EQ(1, mixer_count()); |
| 237 | 239 |
| 238 // Different sample rates, formats, bit depths, and buffer sizes should not | 240 // Different sample rates, formats, bit depths, and buffer sizes should not |
| 239 // result in a different mixer. | 241 // result in a different mixer. |
| 240 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 242 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 241 kChannelLayout, | 243 kChannelLayout, |
| 242 kSampleRate * 2, | 244 kSampleRate * 2, |
| 243 kBitsPerChannel * 2, | 245 kBitsPerChannel * 2, |
| 244 kBufferSize * 2); | 246 kBufferSize * 2); |
| 245 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, | 247 media::AudioRendererMixer* mixer2 = |
| 246 kSecurityOrigin, nullptr)); | 248 GetMixer(kRenderFrameId, params2, AudioLatency::LATENCY_PLAYBACK, |
| 249 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 250 EXPECT_EQ(mixer1, mixer2); |
| 247 EXPECT_EQ(1, mixer_count()); | 251 EXPECT_EQ(1, mixer_count()); |
| 248 ReturnMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 252 ReturnMixer(mixer2); |
| 249 EXPECT_EQ(1, mixer_count()); | 253 EXPECT_EQ(1, mixer_count()); |
| 250 | 254 |
| 251 // Modify some parameters that do matter: channel layout | 255 // Modify some parameters that do matter: channel layout |
| 252 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 256 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 253 kAnotherChannelLayout, | 257 kAnotherChannelLayout, |
| 254 kSampleRate, | 258 kSampleRate, |
| 255 kBitsPerChannel, | 259 kBitsPerChannel, |
| 256 kBufferSize); | 260 kBufferSize); |
| 257 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); | 261 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); |
| 258 | 262 media::AudioRendererMixer* mixer3 = |
| 259 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, | 263 GetMixer(kRenderFrameId, params3, AudioLatency::LATENCY_PLAYBACK, |
| 260 kSecurityOrigin, nullptr)); | 264 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 265 EXPECT_NE(mixer1, mixer3); |
| 261 EXPECT_EQ(2, mixer_count()); | 266 EXPECT_EQ(2, mixer_count()); |
| 262 ReturnMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); | 267 ReturnMixer(mixer3); |
| 263 EXPECT_EQ(1, mixer_count()); | 268 EXPECT_EQ(1, mixer_count()); |
| 264 | 269 |
| 265 // Return final mixer. | 270 // Return final mixer. |
| 266 ReturnMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 271 ReturnMixer(mixer1); |
| 267 EXPECT_EQ(0, mixer_count()); | 272 EXPECT_EQ(0, mixer_count()); |
| 268 } | 273 } |
| 269 | 274 |
| 270 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate | 275 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate |
| 271 // callbacks and they are working as expected. Also, verify that separate | 276 // callbacks and they are working as expected. Also, verify that separate |
| 272 // mixers are created for separate RenderFrames, even though the | 277 // mixers are created for separate RenderFrames, even though the |
| 273 // AudioParameters are the same. | 278 // AudioParameters are the same. |
| 274 TEST_F(AudioRendererMixerManagerTest, CreateInput) { | 279 TEST_F(AudioRendererMixerManagerTest, CreateInput) { |
| 275 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice | 280 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice |
| 276 // each. Note: Under normal conditions, each mixer would get its own sink! | 281 // each. Note: Under normal conditions, each mixer would get its own sink! |
| 277 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 282 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 278 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 283 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 279 | 284 |
| 280 // We expect 2 mixers to be created; each of them should release the sink. | 285 // We expect 2 mixers to be created; each of them should release the sink. |
| 281 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); | 286 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(2); |
| 282 | 287 |
| 283 media::AudioParameters params( | 288 media::AudioParameters params( |
| 284 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 289 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 285 kBitsPerChannel, kBufferSize); | 290 kBitsPerChannel, kBufferSize); |
| 286 | 291 |
| 287 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. | 292 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. |
| 288 EXPECT_EQ(0, mixer_count()); | 293 EXPECT_EQ(0, mixer_count()); |
| 289 media::FakeAudioRenderCallback callback(0); | 294 media::FakeAudioRenderCallback callback(0); |
| 290 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput( | 295 scoped_refptr<media::AudioRendererMixerInput> input( |
| 291 kRenderFrameId, 0, kDefaultDeviceId, kSecurityOrigin)); | 296 manager_->CreateInput(kRenderFrameId, 0, kDefaultDeviceId, |
| 297 kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
| 292 input->Initialize(params, &callback); | 298 input->Initialize(params, &callback); |
| 293 EXPECT_EQ(0, mixer_count()); | 299 EXPECT_EQ(0, mixer_count()); |
| 294 media::FakeAudioRenderCallback another_callback(1); | 300 media::FakeAudioRenderCallback another_callback(1); |
| 295 scoped_refptr<media::AudioRendererMixerInput> another_input( | 301 scoped_refptr<media::AudioRendererMixerInput> another_input( |
| 296 manager_->CreateInput(kAnotherRenderFrameId, 0, kDefaultDeviceId, | 302 manager_->CreateInput(kAnotherRenderFrameId, 0, kDefaultDeviceId, |
| 297 kSecurityOrigin)); | 303 kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
| 298 another_input->Initialize(params, &another_callback); | 304 another_input->Initialize(params, &another_callback); |
| 299 EXPECT_EQ(0, mixer_count()); | 305 EXPECT_EQ(0, mixer_count()); |
| 300 | 306 |
| 301 // Implicitly test that AudioRendererMixerInput was provided with the expected | 307 // Implicitly test that AudioRendererMixerInput was provided with the expected |
| 302 // callbacks needed to acquire an AudioRendererMixer and return it. | 308 // callbacks needed to acquire an AudioRendererMixer and return it. |
| 303 input->Start(); | 309 input->Start(); |
| 304 EXPECT_EQ(1, mixer_count()); | 310 EXPECT_EQ(1, mixer_count()); |
| 305 another_input->Start(); | 311 another_input->Start(); |
| 306 EXPECT_EQ(2, mixer_count()); | 312 EXPECT_EQ(2, mixer_count()); |
| 307 | 313 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 334 | 340 |
| 335 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 341 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 336 kChannelLayout, kSampleRate, kBitsPerChannel, | 342 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 337 kBufferSize); | 343 kBufferSize); |
| 338 media::FakeAudioRenderCallback callback(0); | 344 media::FakeAudioRenderCallback callback(0); |
| 339 EXPECT_EQ(0, mixer_count()); | 345 EXPECT_EQ(0, mixer_count()); |
| 340 | 346 |
| 341 // Empty device id, zero session id; | 347 // Empty device id, zero session id; |
| 342 scoped_refptr<media::AudioRendererMixerInput> input_to_default_device( | 348 scoped_refptr<media::AudioRendererMixerInput> input_to_default_device( |
| 343 manager_->CreateInput(kRenderFrameId, 0, // session_id | 349 manager_->CreateInput(kRenderFrameId, 0, // session_id |
| 344 std::string(), kSecurityOrigin)); | 350 std::string(), kSecurityOrigin, |
| 351 AudioLatency::LATENCY_PLAYBACK)); |
| 345 input_to_default_device->Initialize(params, &callback); | 352 input_to_default_device->Initialize(params, &callback); |
| 346 EXPECT_EQ(0, mixer_count()); | 353 EXPECT_EQ(0, mixer_count()); |
| 347 | 354 |
| 348 // Specific device id, zero session id; | 355 // Specific device id, zero session id; |
| 349 scoped_refptr<media::AudioRendererMixerInput> input_to_matched_device( | 356 scoped_refptr<media::AudioRendererMixerInput> input_to_matched_device( |
| 350 manager_->CreateInput(kRenderFrameId, 0, // session_id | 357 manager_->CreateInput(kRenderFrameId, 0, // session_id |
| 351 kMatchedDeviceId, kSecurityOrigin)); | 358 kMatchedDeviceId, kSecurityOrigin, |
| 359 AudioLatency::LATENCY_PLAYBACK)); |
| 352 input_to_matched_device->Initialize(params, &callback); | 360 input_to_matched_device->Initialize(params, &callback); |
| 353 EXPECT_EQ(0, mixer_count()); | 361 EXPECT_EQ(0, mixer_count()); |
| 354 | 362 |
| 355 // Specific device id, non-zero session id (to be ignored); | 363 // Specific device id, non-zero session id (to be ignored); |
| 356 scoped_refptr<media::AudioRendererMixerInput> input_to_another_device( | 364 scoped_refptr<media::AudioRendererMixerInput> input_to_another_device( |
| 357 manager_->CreateInput(kRenderFrameId, 1, // session id | 365 manager_->CreateInput(kRenderFrameId, 1, // session id |
| 358 kAnotherDeviceId, kSecurityOrigin)); | 366 kAnotherDeviceId, kSecurityOrigin, |
| 367 AudioLatency::LATENCY_PLAYBACK)); |
| 359 input_to_another_device->Initialize(params, &callback); | 368 input_to_another_device->Initialize(params, &callback); |
| 360 EXPECT_EQ(0, mixer_count()); | 369 EXPECT_EQ(0, mixer_count()); |
| 361 | 370 |
| 362 // Empty device id, non-zero session id; | 371 // Empty device id, non-zero session id; |
| 363 scoped_refptr<media::AudioRendererMixerInput> | 372 scoped_refptr<media::AudioRendererMixerInput> |
| 364 input_to_matched_device_with_session_id( | 373 input_to_matched_device_with_session_id(manager_->CreateInput( |
| 365 manager_->CreateInput(kRenderFrameId, 2, // session id | 374 kRenderFrameId, 2, // session id |
| 366 std::string(), kSecurityOrigin)); | 375 std::string(), kSecurityOrigin, AudioLatency::LATENCY_PLAYBACK)); |
| 367 input_to_matched_device_with_session_id->Initialize(params, &callback); | 376 input_to_matched_device_with_session_id->Initialize(params, &callback); |
| 368 EXPECT_EQ(0, mixer_count()); | 377 EXPECT_EQ(0, mixer_count()); |
| 369 | 378 |
| 370 // Implicitly test that AudioRendererMixerInput was provided with the expected | 379 // Implicitly test that AudioRendererMixerInput was provided with the expected |
| 371 // callbacks needed to acquire an AudioRendererMixer and return it. | 380 // callbacks needed to acquire an AudioRendererMixer and return it. |
| 372 input_to_default_device->Start(); | 381 input_to_default_device->Start(); |
| 373 EXPECT_EQ(1, mixer_count()); | 382 EXPECT_EQ(1, mixer_count()); |
| 374 | 383 |
| 375 input_to_another_device->Start(); | 384 input_to_another_device->Start(); |
| 376 EXPECT_EQ(2, mixer_count()); | 385 EXPECT_EQ(2, mixer_count()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 403 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); | 412 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); |
| 404 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); | 413 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); |
| 405 EXPECT_EQ(0, mixer_count()); | 414 EXPECT_EQ(0, mixer_count()); |
| 406 | 415 |
| 407 // We expect 3 mixers to be created; each of them should release a sink. | 416 // We expect 3 mixers to be created; each of them should release a sink. |
| 408 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(3); | 417 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(3); |
| 409 | 418 |
| 410 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 419 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 411 kChannelLayout, kSampleRate, kBitsPerChannel, | 420 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 412 kBufferSize); | 421 kBufferSize); |
| 413 media::AudioRendererMixer* mixer1 = GetMixer( | 422 media::AudioRendererMixer* mixer1 = |
| 414 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 423 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 424 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 415 ASSERT_TRUE(mixer1); | 425 ASSERT_TRUE(mixer1); |
| 416 EXPECT_EQ(1, mixer_count()); | 426 EXPECT_EQ(1, mixer_count()); |
| 417 | 427 |
| 418 media::AudioRendererMixer* mixer2 = GetMixer( | 428 media::AudioRendererMixer* mixer2 = |
| 419 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin, nullptr); | 429 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 430 kAnotherDeviceId, kSecurityOrigin, nullptr); |
| 420 ASSERT_TRUE(mixer2); | 431 ASSERT_TRUE(mixer2); |
| 421 EXPECT_EQ(2, mixer_count()); | 432 EXPECT_EQ(2, mixer_count()); |
| 422 EXPECT_NE(mixer1, mixer2); | 433 EXPECT_NE(mixer1, mixer2); |
| 423 | 434 |
| 424 media::AudioRendererMixer* mixer3 = GetMixer( | 435 media::AudioRendererMixer* mixer3 = |
| 425 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2, nullptr); | 436 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 437 kAnotherDeviceId, kSecurityOrigin2, nullptr); |
| 426 ASSERT_TRUE(mixer3); | 438 ASSERT_TRUE(mixer3); |
| 427 EXPECT_EQ(3, mixer_count()); | 439 EXPECT_EQ(3, mixer_count()); |
| 428 EXPECT_NE(mixer1, mixer3); | 440 EXPECT_NE(mixer1, mixer3); |
| 429 EXPECT_NE(mixer2, mixer3); | 441 EXPECT_NE(mixer2, mixer3); |
| 430 | 442 |
| 431 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 443 ReturnMixer(mixer1); |
| 432 EXPECT_EQ(2, mixer_count()); | 444 EXPECT_EQ(2, mixer_count()); |
| 433 ReturnMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin); | 445 ReturnMixer(mixer2); |
| 434 EXPECT_EQ(1, mixer_count()); | 446 EXPECT_EQ(1, mixer_count()); |
| 435 ReturnMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2); | 447 ReturnMixer(mixer3); |
| 436 EXPECT_EQ(0, mixer_count()); | 448 EXPECT_EQ(0, mixer_count()); |
| 437 } | 449 } |
| 438 | 450 |
| 439 // Verify GetMixer() correctly deduplicate mixers with the same | 451 // Verify GetMixer() correctly deduplicate mixers with the same |
| 440 // parameters, different security origins but default device ID | 452 // parameters, different security origins but default device ID |
| 441 TEST_F(AudioRendererMixerManagerTest, OneMixerDifferentOriginsDefaultDevice) { | 453 TEST_F(AudioRendererMixerManagerTest, OneMixerDifferentOriginsDefaultDevice) { |
| 442 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); | 454 EXPECT_CALL(*mock_sink_.get(), Start()).Times(1); |
| 443 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); | 455 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(1); |
| 444 EXPECT_EQ(0, mixer_count()); | 456 EXPECT_EQ(0, mixer_count()); |
| 445 | 457 |
| 446 // We expect 1 mixer to be created; it should release its sink. | 458 // We expect 1 mixer to be created; it should release its sink. |
| 447 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); | 459 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(1); |
| 448 | 460 |
| 449 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 461 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 450 kChannelLayout, kSampleRate, kBitsPerChannel, | 462 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 451 kBufferSize); | 463 kBufferSize); |
| 452 media::AudioRendererMixer* mixer1 = GetMixer( | 464 media::AudioRendererMixer* mixer1 = |
| 453 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 465 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 466 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 454 ASSERT_TRUE(mixer1); | 467 ASSERT_TRUE(mixer1); |
| 455 EXPECT_EQ(1, mixer_count()); | 468 EXPECT_EQ(1, mixer_count()); |
| 456 | 469 |
| 457 media::AudioRendererMixer* mixer2 = | 470 media::AudioRendererMixer* mixer2 = |
| 458 GetMixer(kRenderFrameId, params, std::string(), kSecurityOrigin, nullptr); | 471 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 472 std::string(), kSecurityOrigin, nullptr); |
| 459 ASSERT_TRUE(mixer2); | 473 ASSERT_TRUE(mixer2); |
| 460 EXPECT_EQ(1, mixer_count()); | 474 EXPECT_EQ(1, mixer_count()); |
| 461 EXPECT_EQ(mixer1, mixer2); | 475 EXPECT_EQ(mixer1, mixer2); |
| 462 | 476 |
| 463 media::AudioRendererMixer* mixer3 = GetMixer( | 477 media::AudioRendererMixer* mixer3 = |
| 464 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin2, nullptr); | 478 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 479 kDefaultDeviceId, kSecurityOrigin2, nullptr); |
| 465 ASSERT_TRUE(mixer3); | 480 ASSERT_TRUE(mixer3); |
| 466 EXPECT_EQ(1, mixer_count()); | 481 EXPECT_EQ(1, mixer_count()); |
| 467 EXPECT_EQ(mixer1, mixer3); | 482 EXPECT_EQ(mixer1, mixer3); |
| 468 | 483 |
| 469 media::AudioRendererMixer* mixer4 = GetMixer( | 484 media::AudioRendererMixer* mixer4 = |
| 470 kRenderFrameId, params, std::string(), kSecurityOrigin2, nullptr); | 485 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 486 std::string(), kSecurityOrigin2, nullptr); |
| 471 ASSERT_TRUE(mixer4); | 487 ASSERT_TRUE(mixer4); |
| 472 EXPECT_EQ(1, mixer_count()); | 488 EXPECT_EQ(1, mixer_count()); |
| 473 EXPECT_EQ(mixer1, mixer4); | 489 EXPECT_EQ(mixer1, mixer4); |
| 474 | 490 |
| 475 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 491 ReturnMixer(mixer1); |
| 476 EXPECT_EQ(1, mixer_count()); | 492 EXPECT_EQ(1, mixer_count()); |
| 477 ReturnMixer(kRenderFrameId, params, std::string(), kSecurityOrigin); | 493 ReturnMixer(mixer2); |
| 478 EXPECT_EQ(1, mixer_count()); | 494 EXPECT_EQ(1, mixer_count()); |
| 479 ReturnMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin2); | 495 ReturnMixer(mixer3); |
| 480 EXPECT_EQ(1, mixer_count()); | 496 EXPECT_EQ(1, mixer_count()); |
| 481 ReturnMixer(kRenderFrameId, params, std::string(), kSecurityOrigin2); | 497 ReturnMixer(mixer4); |
| 482 EXPECT_EQ(0, mixer_count()); | 498 EXPECT_EQ(0, mixer_count()); |
| 483 } | 499 } |
| 484 | 500 |
| 485 // Verify that GetMixer() correctly returns a null mixer and an appropriate | 501 // Verify that GetMixer() correctly returns a null mixer and an appropriate |
| 486 // status code when a nonexistent device is requested. | 502 // status code when a nonexistent device is requested. |
| 487 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { | 503 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { |
| 488 EXPECT_EQ(0, mixer_count()); | 504 EXPECT_EQ(0, mixer_count()); |
| 489 | 505 |
| 490 // Mixer manager should release a not-ok sink when failing to create a mixer. | 506 // 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); | 507 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_no_device_.get())).Times(1); |
| 492 | 508 |
| 493 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 509 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 494 kChannelLayout, kSampleRate, kBitsPerChannel, | 510 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 495 kBufferSize); | 511 kBufferSize); |
| 496 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; | 512 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; |
| 497 | 513 |
| 498 media::AudioRendererMixer* mixer = | 514 media::AudioRendererMixer* mixer = |
| 499 GetMixer(kRenderFrameId, params, kNonexistentDeviceId, kSecurityOrigin, | 515 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 500 &device_status); | 516 kNonexistentDeviceId, kSecurityOrigin, &device_status); |
| 501 | 517 |
| 502 EXPECT_FALSE(mixer); | 518 EXPECT_FALSE(mixer); |
| 503 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); | 519 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); |
| 504 EXPECT_EQ(0, mixer_count()); | 520 EXPECT_EQ(0, mixer_count()); |
| 505 } | 521 } |
| 506 | 522 |
| 523 // Verify GetMixer() correctly deduplicate mixers basing on latency |
| 524 // requirements. |
| 525 TEST_F(AudioRendererMixerManagerTest, LatencyMixing) { |
| 526 EXPECT_CALL(*mock_sink_.get(), Start()).Times(5); |
| 527 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(5); |
| 528 EXPECT_CALL(*this, ReleaseSinkPtr(mock_sink_.get())).Times(5); |
| 529 |
| 530 EXPECT_EQ(0, mixer_count()); |
| 531 |
| 532 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 533 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 534 kBufferSize); |
| 535 media::AudioRendererMixer* mixer1 = |
| 536 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 537 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 538 ASSERT_TRUE(mixer1); |
| 539 EXPECT_EQ(1, mixer_count()); |
| 540 |
| 541 media::AudioRendererMixer* mixer2 = |
| 542 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_PLAYBACK, |
| 543 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 544 ASSERT_TRUE(mixer2); |
| 545 EXPECT_EQ(mixer1, mixer2); // Same latency => same mixer. |
| 546 EXPECT_EQ(1, mixer_count()); |
| 547 |
| 548 media::AudioRendererMixer* mixer3 = |
| 549 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_RTC, |
| 550 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 551 ASSERT_TRUE(mixer3); |
| 552 EXPECT_NE(mixer1, mixer3); |
| 553 EXPECT_EQ(2, mixer_count()); // Another latency => another mixer. |
| 554 |
| 555 media::AudioRendererMixer* mixer4 = |
| 556 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_INTERACTIVE, |
| 557 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 558 ASSERT_TRUE(mixer4); |
| 559 EXPECT_EQ(3, mixer_count()); // Another latency => another mixer. |
| 560 |
| 561 media::AudioRendererMixer* mixer5 = |
| 562 GetMixer(kRenderFrameId, params, AudioLatency::LATENCY_EXACT_MS, |
| 563 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 564 ASSERT_TRUE(mixer5); |
| 565 EXPECT_EQ(4, mixer_count()); // Another latency => another mixer. |
| 566 |
| 567 media::AudioParameters params2(params); |
| 568 params2.set_frames_per_buffer(params.frames_per_buffer() * 2); |
| 569 params2.set_sample_rate(params.sample_rate() * 2); |
| 570 media::AudioRendererMixer* mixer6 = |
| 571 GetMixer(kRenderFrameId, params2, AudioLatency::LATENCY_EXACT_MS, |
| 572 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 573 ASSERT_TRUE(mixer6); |
| 574 // LATENCY_EXACT_MS, same buffer duraion => same mixer. |
| 575 EXPECT_EQ(mixer5, mixer6); |
| 576 EXPECT_EQ(4, mixer_count()); |
| 577 |
| 578 media::AudioParameters params3(params); |
| 579 params3.set_frames_per_buffer(kBufferSize * 2); |
| 580 media::AudioRendererMixer* mixer7 = |
| 581 GetMixer(kRenderFrameId, params3, AudioLatency::LATENCY_EXACT_MS, |
| 582 kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 583 ASSERT_TRUE(mixer7); |
| 584 // LATENCY_EXACT_MS, another buffer duraion => another mixer. |
| 585 EXPECT_NE(mixer5, mixer7); |
| 586 EXPECT_EQ(5, mixer_count()); |
| 587 |
| 588 ReturnMixer(mixer1); |
| 589 EXPECT_EQ(5, mixer_count()); |
| 590 ReturnMixer(mixer2); |
| 591 EXPECT_EQ(4, mixer_count()); |
| 592 ReturnMixer(mixer3); |
| 593 EXPECT_EQ(3, mixer_count()); |
| 594 ReturnMixer(mixer4); |
| 595 EXPECT_EQ(2, mixer_count()); |
| 596 ReturnMixer(mixer5); |
| 597 EXPECT_EQ(2, mixer_count()); |
| 598 ReturnMixer(mixer6); |
| 599 EXPECT_EQ(1, mixer_count()); |
| 600 ReturnMixer(mixer7); |
| 601 EXPECT_EQ(0, mixer_count()); |
| 602 } |
| 603 |
| 507 } // namespace content | 604 } // namespace content |
| OLD | NEW |