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/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 8 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 static const int kAnotherRenderViewId = 456; | 28 static const int kAnotherRenderViewId = 456; |
29 static const int kAnotherRenderFrameId = 678; | 29 static const int kAnotherRenderFrameId = 678; |
30 | 30 |
31 using media::AudioParameters; | 31 using media::AudioParameters; |
32 | 32 |
33 class AudioRendererMixerManagerTest : public testing::Test { | 33 class AudioRendererMixerManagerTest : public testing::Test { |
34 public: | 34 public: |
35 AudioRendererMixerManagerTest() | 35 AudioRendererMixerManagerTest() |
36 : fake_config_(AudioParameters(), AudioParameters()) { | 36 : fake_config_(AudioParameters(), AudioParameters()) { |
37 AudioParameters output_params( | 37 AudioParameters output_params( |
38 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 38 AudioParameters::AUDIO_PCM_LOW_LATENCY, |
39 media::CHANNEL_LAYOUT_STEREO, | 39 media::CHANNEL_LAYOUT_STEREO, |
40 kSampleRate, | 40 kSampleRate, |
41 16, | 41 16, |
42 kBufferSize); | 42 kBufferSize); |
43 fake_config_.UpdateOutputConfig(output_params); | 43 fake_config_.UpdateOutputConfig(output_params); |
44 | 44 |
45 manager_.reset(new AudioRendererMixerManager(&fake_config_)); | 45 manager_.reset(new AudioRendererMixerManager(&fake_config_)); |
46 | 46 |
47 // We don't want to deal with instantiating a real AudioOutputDevice since | 47 // We don't want to deal with instantiating a real AudioOutputDevice since |
48 // it's not important to our testing, so we inject a mock. | 48 // it's not important to our testing, so we inject a mock. |
(...skipping 29 matching lines...) Expand all Loading... |
78 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { | 78 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { |
79 // Since we're testing two different sets of parameters, we expect | 79 // Since we're testing two different sets of parameters, we expect |
80 // AudioRendererMixerManager to call Start and Stop on our mock twice. | 80 // AudioRendererMixerManager to call Start and Stop on our mock twice. |
81 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 81 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
82 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 82 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
83 | 83 |
84 // There should be no mixers outstanding to start with. | 84 // There should be no mixers outstanding to start with. |
85 EXPECT_EQ(mixer_count(), 0); | 85 EXPECT_EQ(mixer_count(), 0); |
86 | 86 |
87 media::AudioParameters params1( | 87 media::AudioParameters params1( |
88 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 88 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
89 kBitsPerChannel, kBufferSize); | 89 kBitsPerChannel, kBufferSize); |
90 | 90 |
91 media::AudioRendererMixer* mixer1 = GetMixer(kRenderViewId, params1); | 91 media::AudioRendererMixer* mixer1 = GetMixer(kRenderViewId, params1); |
92 ASSERT_TRUE(mixer1); | 92 ASSERT_TRUE(mixer1); |
93 EXPECT_EQ(mixer_count(), 1); | 93 EXPECT_EQ(mixer_count(), 1); |
94 | 94 |
95 // The same parameters should return the same mixer1. | 95 // The same parameters should return the same mixer1. |
96 EXPECT_EQ(mixer1, GetMixer(kRenderViewId, params1)); | 96 EXPECT_EQ(mixer1, GetMixer(kRenderViewId, params1)); |
97 EXPECT_EQ(mixer_count(), 1); | 97 EXPECT_EQ(mixer_count(), 1); |
98 | 98 |
99 // Remove the extra mixer we just acquired. | 99 // Remove the extra mixer we just acquired. |
100 RemoveMixer(kRenderViewId, params1); | 100 RemoveMixer(kRenderViewId, params1); |
101 EXPECT_EQ(mixer_count(), 1); | 101 EXPECT_EQ(mixer_count(), 1); |
102 | 102 |
103 media::AudioParameters params2( | 103 media::AudioParameters params2( |
104 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate * 2, | 104 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate * 2, |
105 kBitsPerChannel, kBufferSize * 2); | 105 kBitsPerChannel, kBufferSize * 2); |
106 media::AudioRendererMixer* mixer2 = GetMixer(kRenderViewId, params2); | 106 media::AudioRendererMixer* mixer2 = GetMixer(kRenderViewId, params2); |
107 ASSERT_TRUE(mixer2); | 107 ASSERT_TRUE(mixer2); |
108 EXPECT_EQ(mixer_count(), 2); | 108 EXPECT_EQ(mixer_count(), 2); |
109 | 109 |
110 // Different parameters should result in a different mixer1. | 110 // Different parameters should result in a different mixer1. |
111 EXPECT_NE(mixer1, mixer2); | 111 EXPECT_NE(mixer1, mixer2); |
112 | 112 |
113 // Remove both outstanding mixers. | 113 // Remove both outstanding mixers. |
114 RemoveMixer(kRenderViewId, params1); | 114 RemoveMixer(kRenderViewId, params1); |
115 EXPECT_EQ(mixer_count(), 1); | 115 EXPECT_EQ(mixer_count(), 1); |
116 RemoveMixer(kRenderViewId, params2); | 116 RemoveMixer(kRenderViewId, params2); |
117 EXPECT_EQ(mixer_count(), 0); | 117 EXPECT_EQ(mixer_count(), 0); |
118 } | 118 } |
119 | 119 |
| 120 // Verify GetMixer() correctly deduplicates mixer with irrelevant AudioParameter |
| 121 // differences. |
| 122 TEST_F(AudioRendererMixerManagerTest, MixerReuse) { |
| 123 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
| 124 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
| 125 EXPECT_EQ(mixer_count(), 0); |
| 126 |
| 127 media::AudioParameters params1(AudioParameters::AUDIO_PCM_LINEAR, |
| 128 kChannelLayout, |
| 129 kSampleRate, |
| 130 kBitsPerChannel, |
| 131 kBufferSize); |
| 132 media::AudioRendererMixer* mixer1 = GetMixer(kRenderViewId, params1); |
| 133 ASSERT_TRUE(mixer1); |
| 134 EXPECT_EQ(mixer_count(), 1); |
| 135 |
| 136 // Different formats, bit depths, and buffer sizes should not result in a |
| 137 // different mixer. |
| 138 media::AudioParameters params2(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 139 kChannelLayout, |
| 140 kSampleRate, |
| 141 kBitsPerChannel * 2, |
| 142 kBufferSize * 2, |
| 143 AudioParameters::NO_EFFECTS); |
| 144 EXPECT_EQ(mixer1, GetMixer(kRenderViewId, params2)); |
| 145 EXPECT_EQ(mixer_count(), 1); |
| 146 RemoveMixer(kRenderViewId, params2); |
| 147 EXPECT_EQ(mixer_count(), 1); |
| 148 |
| 149 // Modify some parameters that do matter. |
| 150 media::AudioParameters params3(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 151 media::CHANNEL_LAYOUT_MONO, |
| 152 kSampleRate * 2, |
| 153 kBitsPerChannel, |
| 154 kBufferSize, |
| 155 AudioParameters::NO_EFFECTS); |
| 156 ASSERT_NE(params3.channel_layout(), params1.channel_layout()); |
| 157 |
| 158 EXPECT_NE(mixer1, GetMixer(kRenderViewId, params3)); |
| 159 EXPECT_EQ(mixer_count(), 2); |
| 160 RemoveMixer(kRenderViewId, params3); |
| 161 EXPECT_EQ(mixer_count(), 1); |
| 162 |
| 163 // Remove final mixer. |
| 164 RemoveMixer(kRenderViewId, params1); |
| 165 EXPECT_EQ(mixer_count(), 0); |
| 166 } |
| 167 |
120 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate | 168 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate |
121 // callbacks and they are working as expected. Also, verify that separate | 169 // callbacks and they are working as expected. Also, verify that separate |
122 // mixers are created for separate render views, even though the AudioParameters | 170 // mixers are created for separate render views, even though the AudioParameters |
123 // are the same. | 171 // are the same. |
124 TEST_F(AudioRendererMixerManagerTest, CreateInput) { | 172 TEST_F(AudioRendererMixerManagerTest, CreateInput) { |
125 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice | 173 // Expect AudioRendererMixerManager to call Start and Stop on our mock twice |
126 // each. Note: Under normal conditions, each mixer would get its own sink! | 174 // each. Note: Under normal conditions, each mixer would get its own sink! |
127 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); | 175 EXPECT_CALL(*mock_sink_.get(), Start()).Times(2); |
128 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); | 176 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(2); |
129 | 177 |
130 media::AudioParameters params( | 178 media::AudioParameters params( |
131 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 179 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
132 kBitsPerChannel, kBufferSize); | 180 kBitsPerChannel, kBufferSize); |
133 | 181 |
134 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. | 182 // Create two mixer inputs and ensure this doesn't instantiate any mixers yet. |
135 EXPECT_EQ(mixer_count(), 0); | 183 EXPECT_EQ(mixer_count(), 0); |
136 media::FakeAudioRenderCallback callback(0); | 184 media::FakeAudioRenderCallback callback(0); |
137 scoped_refptr<media::AudioRendererMixerInput> input( | 185 scoped_refptr<media::AudioRendererMixerInput> input( |
138 manager_->CreateInput(kRenderViewId, kRenderFrameId)); | 186 manager_->CreateInput(kRenderViewId, kRenderFrameId)); |
139 input->Initialize(params, &callback); | 187 input->Initialize(params, &callback); |
140 EXPECT_EQ(mixer_count(), 0); | 188 EXPECT_EQ(mixer_count(), 0); |
141 media::FakeAudioRenderCallback another_callback(1); | 189 media::FakeAudioRenderCallback another_callback(1); |
(...skipping 12 matching lines...) Expand all Loading... |
154 // Destroying the inputs should destroy the mixers. | 202 // Destroying the inputs should destroy the mixers. |
155 input->Stop(); | 203 input->Stop(); |
156 input = NULL; | 204 input = NULL; |
157 EXPECT_EQ(mixer_count(), 1); | 205 EXPECT_EQ(mixer_count(), 1); |
158 another_input->Stop(); | 206 another_input->Stop(); |
159 another_input = NULL; | 207 another_input = NULL; |
160 EXPECT_EQ(mixer_count(), 0); | 208 EXPECT_EQ(mixer_count(), 0); |
161 } | 209 } |
162 | 210 |
163 } // namespace content | 211 } // namespace content |
OLD | NEW |