Chromium Code Reviews| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/renderer/media/audio_device_factory.h" | |
| 9 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 10 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
| 10 #include "ipc/ipc_message.h" | 11 #include "media/audio/audio_input_device.h" |
| 12 #include "media/audio/audio_manager_base.h" | |
| 11 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 12 #include "media/base/audio_hardware_config.h" | |
| 13 #include "media/base/audio_renderer_mixer.h" | 14 #include "media/base/audio_renderer_mixer.h" |
| 14 #include "media/base/audio_renderer_mixer_input.h" | 15 #include "media/base/audio_renderer_mixer_input.h" |
| 15 #include "media/base/fake_audio_render_callback.h" | 16 #include "media/base/fake_audio_render_callback.h" |
| 16 #include "media/base/mock_audio_renderer_sink.h" | 17 #include "media/base/mock_audio_renderer_sink.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" | |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 static const int kBitsPerChannel = 16; | 24 static const int kBitsPerChannel = 16; |
| 23 static const int kSampleRate = 48000; | 25 static const int kSampleRate = 48000; |
| 24 static const int kBufferSize = 8192; | 26 static const int kBufferSize = 8192; |
| 25 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; | 27 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; |
| 26 static const media::ChannelLayout kAnotherChannelLayout = | 28 static const media::ChannelLayout kAnotherChannelLayout = |
| 27 media::CHANNEL_LAYOUT_2_1; | 29 media::CHANNEL_LAYOUT_2_1; |
| 28 static const std::string kDefaultDeviceId; | 30 static const char* const kDefaultDeviceId = |
| 29 static const url::Origin kSecurityOrigin; | 31 media::AudioManagerBase::kDefaultDeviceId; |
| 32 static const char kAnotherDeviceId[] = "another-device-id"; | |
| 33 static const char kNonexistentDeviceId[] = "nonexistent-device-id"; | |
| 30 | 34 |
| 31 static const int kRenderFrameId = 124; | 35 static const int kRenderFrameId = 124; |
| 32 static const int kAnotherRenderFrameId = 678; | 36 static const int kAnotherRenderFrameId = 678; |
| 33 | 37 |
| 34 using media::AudioParameters; | 38 using media::AudioParameters; |
| 35 | 39 |
| 36 class AudioRendererMixerManagerTest : public testing::Test { | 40 class AudioRendererMixerManagerTest : public testing::Test, |
| 41 public AudioDeviceFactory { | |
| 37 public: | 42 public: |
| 38 AudioRendererMixerManagerTest() { | 43 AudioRendererMixerManagerTest() |
| 39 manager_.reset(new AudioRendererMixerManager()); | 44 : manager_(new AudioRendererMixerManager()), |
| 40 | 45 mock_sink_(new media::MockAudioRendererSink()), |
| 41 // We don't want to deal with instantiating a real AudioOutputDevice since | 46 mock_sink_no_device_(new media::MockAudioRendererSink( |
| 42 // it's not important to our testing, so we inject a mock. | 47 kNonexistentDeviceId, |
| 43 mock_sink_ = new media::MockAudioRendererSink(); | 48 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)), |
| 44 manager_->SetAudioRendererSinkForTesting(mock_sink_.get()); | 49 kSecurityOrigin2(GURL("http://localhost")) {} |
| 45 } | |
| 46 | 50 |
| 47 media::AudioRendererMixer* GetMixer( | 51 media::AudioRendererMixer* GetMixer( |
| 48 int source_render_frame_id, | 52 int source_render_frame_id, |
| 49 const media::AudioParameters& params, | 53 const media::AudioParameters& params, |
| 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 media::OutputDeviceStatus* device_status) { | 56 media::OutputDeviceStatus* device_status) { |
| 53 return manager_->GetMixer(source_render_frame_id, params, device_id, | 57 return manager_->GetMixer(source_render_frame_id, params, device_id, |
| 54 security_origin, device_status); | 58 security_origin, device_status); |
| 55 } | 59 } |
| 56 | 60 |
| 57 void RemoveMixer(int source_render_frame_id, | 61 void RemoveMixer(int source_render_frame_id, |
| 58 const media::AudioParameters& params, | 62 const media::AudioParameters& params, |
| 59 const std::string& device_id, | 63 const std::string& device_id, |
| 60 const url::Origin& security_origin) { | 64 const url::Origin& security_origin) { |
| 61 return manager_->RemoveMixer(source_render_frame_id, params, device_id, | 65 return manager_->RemoveMixer(source_render_frame_id, params, device_id, |
| 62 security_origin); | 66 security_origin); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void UseNonexistentSink() { | |
| 66 mock_sink_ = new media::MockAudioRendererSink( | |
| 67 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND); | |
| 68 manager_->SetAudioRendererSinkForTesting(mock_sink_.get()); | |
| 69 } | |
| 70 | |
| 71 // Number of instantiated mixers. | 69 // Number of instantiated mixers. |
| 72 int mixer_count() { | 70 int mixer_count() { |
| 73 return manager_->mixers_.size(); | 71 return manager_->mixers_.size(); |
| 74 } | 72 } |
| 75 | 73 |
| 76 protected: | 74 protected: |
| 75 MOCK_METHOD1(CreateInputDevice, scoped_refptr<media::AudioInputDevice>(int)); | |
| 76 MOCK_METHOD5( | |
| 77 CreateSwitchableAudioRendererSink, | |
| 78 scoped_refptr<media::SwitchableAudioRendererSink>(SourceType, | |
| 79 int, | |
| 80 int, | |
| 81 const std::string&, | |
| 82 const url::Origin&)); | |
| 83 MOCK_METHOD5(CreateAudioRendererSink, | |
| 84 scoped_refptr<media::AudioRendererSink>(SourceType, | |
| 85 int, | |
| 86 int, | |
| 87 const std::string&, | |
| 88 const url::Origin&)); | |
| 89 | |
| 90 scoped_refptr<media::AudioRendererSink> CreateAudioRendererMixerSink( | |
| 91 int render_frame_id, | |
| 92 int session_id, | |
| 93 const std::string& device_id, | |
| 94 const url::Origin& security_origin) { | |
| 95 if ((device_id == kDefaultDeviceId) || (device_id == kAnotherDeviceId)) { | |
| 96 // We don't care about separate sinks for these devices | |
| 97 return mock_sink_; | |
| 98 } | |
| 99 if (device_id == kNonexistentDeviceId) { | |
| 100 return mock_sink_no_device_; | |
| 101 } | |
| 102 if (device_id.empty()) { | |
| 103 return mock_sink_; | |
| 104 } | |
| 105 | |
| 106 NOTREACHED(); | |
| 107 return nullptr; | |
| 108 } | |
| 109 | |
| 77 scoped_ptr<AudioRendererMixerManager> manager_; | 110 scoped_ptr<AudioRendererMixerManager> manager_; |
| 78 scoped_refptr<media::MockAudioRendererSink> mock_sink_; | 111 scoped_refptr<media::MockAudioRendererSink> mock_sink_; |
| 112 scoped_refptr<media::MockAudioRendererSink> mock_sink_no_device_; | |
| 113 | |
| 114 // To avoid global/static non-POD constants. | |
| 115 const url::Origin kSecurityOrigin; | |
| 116 const url::Origin kSecurityOrigin2; | |
| 79 | 117 |
| 80 private: | 118 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); | 119 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); |
| 82 }; | 120 }; |
| 83 | 121 |
| 84 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with | 122 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with |
| 85 // respect to the explicit ref counting done. | 123 // respect to the explicit ref counting done. |
| 86 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { | 124 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { |
| 87 // Since we're testing two different sets of parameters, we expect | 125 // Since we're testing two different sets of parameters, we expect |
| 88 // AudioRendererMixerManager to call Start and Stop on our mock twice. | 126 // AudioRendererMixerManager to call Start and Stop on our mock twice. |
| 89 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 127 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 90 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 128 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 91 | 129 |
| 92 // There should be no mixers outstanding to start with. | 130 // There should be no mixers outstanding to start with. |
| 93 EXPECT_EQ(mixer_count(), 0); | 131 EXPECT_EQ(0, mixer_count()); |
|
Henrik Grunell
2016/03/25 10:44:40
Oh, you changed all these. Kudos! :)
o1ka
2016/03/29 13:39:54
That was easy :)
| |
| 94 | 132 |
| 95 media::AudioParameters params1( | 133 media::AudioParameters params1( |
| 96 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 134 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 97 kBitsPerChannel, kBufferSize); | 135 kBitsPerChannel, kBufferSize); |
| 98 | 136 |
| 99 media::AudioRendererMixer* mixer1 = GetMixer( | 137 media::AudioRendererMixer* mixer1 = GetMixer( |
| 100 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 138 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 101 ASSERT_TRUE(mixer1); | 139 ASSERT_TRUE(mixer1); |
| 102 EXPECT_EQ(mixer_count(), 1); | 140 EXPECT_EQ(1, mixer_count()); |
| 103 | 141 |
| 104 // The same parameters should return the same mixer1. | 142 // The same parameters should return the same mixer1. |
| 105 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, | 143 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params1, kDefaultDeviceId, |
| 106 kSecurityOrigin, nullptr)); | 144 kSecurityOrigin, nullptr)); |
| 107 EXPECT_EQ(mixer_count(), 1); | 145 EXPECT_EQ(1, mixer_count()); |
| 108 | 146 |
| 109 // Remove the extra mixer we just acquired. | 147 // Remove the extra mixer we just acquired. |
| 110 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 148 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
| 111 EXPECT_EQ(mixer_count(), 1); | 149 EXPECT_EQ(1, mixer_count()); |
| 112 | 150 |
| 113 media::AudioParameters params2( | 151 media::AudioParameters params2( |
| 114 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, | 152 AudioParameters::AUDIO_PCM_LINEAR, kAnotherChannelLayout, kSampleRate * 2, |
| 115 kBitsPerChannel, kBufferSize * 2); | 153 kBitsPerChannel, kBufferSize * 2); |
| 116 media::AudioRendererMixer* mixer2 = GetMixer( | 154 media::AudioRendererMixer* mixer2 = GetMixer( |
| 117 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); | 155 kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 118 ASSERT_TRUE(mixer2); | 156 ASSERT_TRUE(mixer2); |
| 119 EXPECT_EQ(mixer_count(), 2); | 157 EXPECT_EQ(2, mixer_count()); |
| 120 | 158 |
| 121 // Different parameters should result in a different mixer1. | 159 // Different parameters should result in a different mixer1. |
| 122 EXPECT_NE(mixer1, mixer2); | 160 EXPECT_NE(mixer1, mixer2); |
| 123 | 161 |
| 124 // Remove both outstanding mixers. | 162 // Remove both outstanding mixers. |
| 125 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 163 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
| 126 EXPECT_EQ(mixer_count(), 1); | 164 EXPECT_EQ(1, mixer_count()); |
| 127 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 165 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); |
| 128 EXPECT_EQ(mixer_count(), 0); | 166 EXPECT_EQ(0, mixer_count()); |
| 129 } | 167 } |
| 130 | 168 |
| 131 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter | 169 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter |
| 132 // differences. | 170 // differences. |
| 133 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { | 171 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { |
| 134 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 172 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 135 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 173 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 136 EXPECT_EQ(mixer_count(), 0); | 174 EXPECT_EQ(mixer_count(), 0); |
| 137 | 175 |
| 138 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, | 176 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, |
| 139 kChannelLayout, | 177 kChannelLayout, |
| 140 kSampleRate, | 178 kSampleRate, |
| 141 kBitsPerChannel, | 179 kBitsPerChannel, |
| 142 kBufferSize); | 180 kBufferSize); |
| 143 media::AudioRendererMixer* mixer1 = GetMixer( | 181 media::AudioRendererMixer* mixer1 = GetMixer( |
| 144 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); | 182 kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 145 ASSERT_TRUE(mixer1); | 183 ASSERT_TRUE(mixer1); |
| 146 EXPECT_EQ(mixer_count(), 1); | 184 EXPECT_EQ(1, mixer_count()); |
| 147 | 185 |
| 148 // Different sample rates, formats, bit depths, and buffer sizes should not | 186 // Different sample rates, formats, bit depths, and buffer sizes should not |
| 149 // result in a different mixer. | 187 // result in a different mixer. |
| 150 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 188 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 151 kChannelLayout, | 189 kChannelLayout, |
| 152 kSampleRate * 2, | 190 kSampleRate * 2, |
| 153 kBitsPerChannel * 2, | 191 kBitsPerChannel * 2, |
| 154 kBufferSize * 2); | 192 kBufferSize * 2); |
| 155 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, | 193 EXPECT_EQ(mixer1, GetMixer(kRenderFrameId, params2, kDefaultDeviceId, |
| 156 kSecurityOrigin, nullptr)); | 194 kSecurityOrigin, nullptr)); |
| 157 EXPECT_EQ(mixer_count(), 1); | 195 EXPECT_EQ(1, mixer_count()); |
| 158 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); | 196 RemoveMixer(kRenderFrameId, params2, kDefaultDeviceId, kSecurityOrigin); |
| 159 EXPECT_EQ(mixer_count(), 1); | 197 EXPECT_EQ(1, mixer_count()); |
| 160 | 198 |
| 161 // Modify some parameters that do matter: channel layout | 199 // Modify some parameters that do matter: channel layout |
| 162 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 200 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 163 kAnotherChannelLayout, | 201 kAnotherChannelLayout, |
| 164 kSampleRate, | 202 kSampleRate, |
| 165 kBitsPerChannel, | 203 kBitsPerChannel, |
| 166 kBufferSize); | 204 kBufferSize); |
| 167 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); | 205 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); |
| 168 | 206 |
| 169 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, | 207 EXPECT_NE(mixer1, GetMixer(kRenderFrameId, params3, kDefaultDeviceId, |
| 170 kSecurityOrigin, nullptr)); | 208 kSecurityOrigin, nullptr)); |
| 171 EXPECT_EQ(mixer_count(), 2); | 209 EXPECT_EQ(2, mixer_count()); |
| 172 RemoveMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); | 210 RemoveMixer(kRenderFrameId, params3, kDefaultDeviceId, kSecurityOrigin); |
| 173 EXPECT_EQ(mixer_count(), 1); | 211 EXPECT_EQ(1, mixer_count()); |
| 174 | 212 |
| 175 // Remove final mixer. | 213 // Remove final mixer. |
| 176 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); | 214 RemoveMixer(kRenderFrameId, params1, kDefaultDeviceId, kSecurityOrigin); |
| 177 EXPECT_EQ(mixer_count(), 0); | 215 EXPECT_EQ(0, mixer_count()); |
| 178 } | 216 } |
| 179 | 217 |
| 180 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate | 218 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate |
| 181 // callbacks and they are working as expected. Also, verify that separate | 219 // callbacks and they are working as expected. Also, verify that separate |
| 182 // mixers are created for separate render views, even though the AudioParameters | 220 // mixers are created for separate render views, even though the AudioParameters |
| 183 // are the same. | 221 // are the same. |
| 184 TEST_F(AudioRendererMixerManagerTest, CreateInput) { | 222 TEST_F(AudioRendererMixerManagerTest, CreateInput) { |
| 185 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice | 223 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice |
| 186 // each. Note: Under normal conditions, each mixer would get its own sink! | 224 // each. Note: Under normal conditions, each mixer would get its own sink! |
| 187 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 225 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 188 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 226 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 189 | 227 |
| 190 media::AudioParameters params( | 228 media::AudioParameters params( |
| 191 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 229 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 192 kBitsPerChannel, kBufferSize); | 230 kBitsPerChannel, kBufferSize); |
| 193 | 231 |
| 194 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. | 232 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. |
| 195 EXPECT_EQ(mixer_count(), 0); | 233 EXPECT_EQ(0, mixer_count()); |
| 196 media::FakeAudioRenderCallback callback(0); | 234 media::FakeAudioRenderCallback callback(0); |
| 197 scoped_refptr<media::AudioRendererMixerInput> input( | 235 scoped_refptr<media::AudioRendererMixerInput> input( |
| 198 manager_->CreateInput(kRenderFrameId, kDefaultDeviceId, kSecurityOrigin)); | 236 manager_->CreateInput(kRenderFrameId, kDefaultDeviceId, kSecurityOrigin)); |
| 199 input->Initialize(params, &callback); | 237 input->Initialize(params, &callback); |
| 200 EXPECT_EQ(mixer_count(), 0); | 238 EXPECT_EQ(0, mixer_count()); |
| 201 media::FakeAudioRenderCallback another_callback(1); | 239 media::FakeAudioRenderCallback another_callback(1); |
| 202 scoped_refptr<media::AudioRendererMixerInput> another_input( | 240 scoped_refptr<media::AudioRendererMixerInput> another_input( |
| 203 manager_->CreateInput(kAnotherRenderFrameId, kDefaultDeviceId, | 241 manager_->CreateInput(kAnotherRenderFrameId, kDefaultDeviceId, |
| 204 kSecurityOrigin)); | 242 kSecurityOrigin)); |
| 205 another_input->Initialize(params, &another_callback); | 243 another_input->Initialize(params, &another_callback); |
| 206 EXPECT_EQ(mixer_count(), 0); | 244 EXPECT_EQ(0, mixer_count()); |
| 207 | 245 |
| 208 // Implicitly test that AudioRendererMixerInput was provided with the expected | 246 // Implicitly test that AudioRendererMixerInput was provided with the expected |
| 209 // callbacks needed to acquire an AudioRendererMixer and remove it. | 247 // callbacks needed to acquire an AudioRendererMixer and remove it. |
| 210 input->Start(); | 248 input->Start(); |
| 211 EXPECT_EQ(mixer_count(), 1); | 249 EXPECT_EQ(1, mixer_count()); |
| 212 another_input->Start(); | 250 another_input->Start(); |
| 213 EXPECT_EQ(mixer_count(), 2); | 251 EXPECT_EQ(2, mixer_count()); |
| 214 | 252 |
| 215 // Destroying the inputs should destroy the mixers. | 253 // Destroying the inputs should destroy the mixers. |
| 216 input->Stop(); | 254 input->Stop(); |
| 217 input = NULL; | 255 input = nullptr; |
| 218 EXPECT_EQ(mixer_count(), 1); | 256 EXPECT_EQ(1, mixer_count()); |
| 219 another_input->Stop(); | 257 another_input->Stop(); |
| 220 another_input = NULL; | 258 another_input = nullptr; |
| 221 EXPECT_EQ(mixer_count(), 0); | 259 EXPECT_EQ(0, mixer_count()); |
| 222 } | 260 } |
| 223 | 261 |
| 224 // Verify GetMixer() correctly creates different mixers with the same | 262 // Verify GetMixer() correctly creates different mixers with the same |
| 225 // parameters, but different device ID and/or security origin | 263 // parameters, but different device ID and/or security origin |
| 226 TEST_F(AudioRendererMixerManagerTest, MixerDevices) { | 264 TEST_F(AudioRendererMixerManagerTest, MixerDevices) { |
| 227 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); | 265 EXPECT_CALL(*mock_sink_.get(), Start()).Times(3); |
| 228 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); | 266 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(3); |
| 229 EXPECT_EQ(mixer_count(), 0); | 267 EXPECT_EQ(0, mixer_count()); |
| 230 | 268 |
| 231 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 269 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 232 kChannelLayout, kSampleRate, kBitsPerChannel, | 270 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 233 kBufferSize); | 271 kBufferSize); |
| 234 media::AudioRendererMixer* mixer1 = GetMixer( | 272 media::AudioRendererMixer* mixer1 = GetMixer( |
| 235 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); | 273 kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin, nullptr); |
| 236 ASSERT_TRUE(mixer1); | 274 ASSERT_TRUE(mixer1); |
| 237 EXPECT_EQ(mixer_count(), 1); | 275 EXPECT_EQ(1, mixer_count()); |
| 238 | 276 |
| 239 std::string device_id2("fake-device-id"); | 277 media::AudioRendererMixer* mixer2 = GetMixer( |
| 240 media::AudioRendererMixer* mixer2 = | 278 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin, nullptr); |
| 241 GetMixer(kRenderFrameId, params, device_id2, kSecurityOrigin, nullptr); | |
| 242 ASSERT_TRUE(mixer2); | 279 ASSERT_TRUE(mixer2); |
| 243 EXPECT_EQ(mixer_count(), 2); | 280 EXPECT_EQ(2, mixer_count()); |
| 244 EXPECT_NE(mixer1, mixer2); | 281 EXPECT_NE(mixer1, mixer2); |
| 245 | 282 |
| 246 url::Origin security_origin2(GURL("http://localhost")); | |
| 247 media::AudioRendererMixer* mixer3 = GetMixer( | 283 media::AudioRendererMixer* mixer3 = GetMixer( |
| 248 kRenderFrameId, params, kDefaultDeviceId, security_origin2, nullptr); | 284 kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2, nullptr); |
| 249 ASSERT_TRUE(mixer3); | 285 ASSERT_TRUE(mixer3); |
| 250 EXPECT_EQ(mixer_count(), 3); | 286 EXPECT_EQ(3, mixer_count()); |
| 251 EXPECT_NE(mixer1, mixer3); | 287 EXPECT_NE(mixer1, mixer3); |
| 252 EXPECT_NE(mixer2, mixer3); | 288 EXPECT_NE(mixer2, mixer3); |
| 253 | 289 |
| 254 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); | 290 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, kSecurityOrigin); |
| 255 EXPECT_EQ(mixer_count(), 2); | 291 EXPECT_EQ(2, mixer_count()); |
| 256 RemoveMixer(kRenderFrameId, params, device_id2, kSecurityOrigin); | 292 RemoveMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin); |
| 257 EXPECT_EQ(mixer_count(), 1); | 293 EXPECT_EQ(1, mixer_count()); |
| 258 RemoveMixer(kRenderFrameId, params, kDefaultDeviceId, security_origin2); | 294 RemoveMixer(kRenderFrameId, params, kAnotherDeviceId, kSecurityOrigin2); |
| 259 EXPECT_EQ(mixer_count(), 0); | 295 EXPECT_EQ(0, mixer_count()); |
| 260 } | 296 } |
| 261 | 297 |
| 262 // Verify that GetMixer() correctly returns a null mixer and an appropriate | 298 // Verify that GetMixer() correctly returns a null mixer and an appropriate |
| 263 // status code when a nonexistent device is requested. | 299 // status code when a nonexistent device is requested. |
| 264 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { | 300 TEST_F(AudioRendererMixerManagerTest, NonexistentDevice) { |
| 265 EXPECT_EQ(mixer_count(), 0); | 301 EXPECT_EQ(0, mixer_count()); |
| 266 UseNonexistentSink(); | |
| 267 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 302 media::AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 268 kChannelLayout, kSampleRate, kBitsPerChannel, | 303 kChannelLayout, kSampleRate, kBitsPerChannel, |
| 269 kBufferSize); | 304 kBufferSize); |
| 270 std::string nonexistent_device_id("nonexistent-device-id"); | |
| 271 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; | 305 media::OutputDeviceStatus device_status = media::OUTPUT_DEVICE_STATUS_OK; |
| 272 EXPECT_CALL(*mock_sink_.get(), Stop()); | 306 EXPECT_CALL(*mock_sink_no_device_.get(), Stop()); |
| 273 media::AudioRendererMixer* mixer = | 307 media::AudioRendererMixer* mixer = |
| 274 GetMixer(kRenderFrameId, params, nonexistent_device_id, kSecurityOrigin, | 308 GetMixer(kRenderFrameId, params, kNonexistentDeviceId, kSecurityOrigin, |
| 275 &device_status); | 309 &device_status); |
| 276 EXPECT_FALSE(mixer); | 310 EXPECT_FALSE(mixer); |
| 277 EXPECT_EQ(device_status, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND); | 311 EXPECT_EQ(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, device_status); |
| 278 EXPECT_EQ(mixer_count(), 0); | 312 EXPECT_EQ(0, mixer_count()); |
| 279 } | 313 } |
| 280 | 314 |
| 281 } // namespace content | 315 } // namespace content |
| OLD | NEW |