OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 5 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
| 12 #include "base/memory/ptr_util.h" |
12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "chromecast/media/cma/backend/alsa/mock_alsa_wrapper.h" | 17 #include "chromecast/media/cma/backend/alsa/mock_alsa_wrapper.h" |
17 #include "media/base/audio_bus.h" | 18 #include "media/base/audio_bus.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using testing::_; | 22 using testing::_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 -850779335, 1666492408, | 108 -850779335, 1666492408, |
108 1290349909, -492418001, | 109 1290349909, -492418001, |
109 659200170, -542374913, | 110 659200170, -542374913, |
110 -120005682, 1030923147, | 111 -120005682, 1030923147, |
111 -877887021, -870241979, | 112 -877887021, -870241979, |
112 1322678128, -344799975, | 113 1322678128, -344799975, |
113 } | 114 } |
114 }; | 115 }; |
115 | 116 |
116 // Return a scoped pointer filled with the data laid out at |index| above. | 117 // Return a scoped pointer filled with the data laid out at |index| above. |
117 scoped_ptr<::media::AudioBus> GetTestData(size_t index) { | 118 std::unique_ptr<::media::AudioBus> GetTestData(size_t index) { |
118 CHECK_LT(index, NUM_DATA_SETS); | 119 CHECK_LT(index, NUM_DATA_SETS); |
119 int frames = NUM_SAMPLES / kNumChannels; | 120 int frames = NUM_SAMPLES / kNumChannels; |
120 auto data = ::media::AudioBus::Create(kNumChannels, frames); | 121 auto data = ::media::AudioBus::Create(kNumChannels, frames); |
121 data->FromInterleaved(kTestData[index], frames, kBytesPerSample); | 122 data->FromInterleaved(kTestData[index], frames, kBytesPerSample); |
122 return data; | 123 return data; |
123 } | 124 } |
124 | 125 |
125 class MockInputQueue : public StreamMixerAlsa::InputQueue { | 126 class MockInputQueue : public StreamMixerAlsa::InputQueue { |
126 public: | 127 public: |
127 explicit MockInputQueue(int samples_per_second) | 128 explicit MockInputQueue(int samples_per_second) |
(...skipping 24 matching lines...) Expand all Loading... |
152 MOCK_METHOD2(GetResampledData, void(::media::AudioBus* dest, int frames)); | 153 MOCK_METHOD2(GetResampledData, void(::media::AudioBus* dest, int frames)); |
153 MOCK_METHOD1(AfterWriteFrames, | 154 MOCK_METHOD1(AfterWriteFrames, |
154 void(const MediaPipelineBackendAlsa::RenderingDelay& | 155 void(const MediaPipelineBackendAlsa::RenderingDelay& |
155 mixer_rendering_delay)); | 156 mixer_rendering_delay)); |
156 MOCK_METHOD0(SignalError, void()); | 157 MOCK_METHOD0(SignalError, void()); |
157 MOCK_METHOD1(PrepareToDelete, void(const OnReadyToDeleteCb& delete_cb)); | 158 MOCK_METHOD1(PrepareToDelete, void(const OnReadyToDeleteCb& delete_cb)); |
158 | 159 |
159 // Setters and getters for test control. | 160 // Setters and getters for test control. |
160 void SetPaused(bool paused) { paused_ = paused; } | 161 void SetPaused(bool paused) { paused_ = paused; } |
161 void SetMaxReadSize(int max_read_size) { max_read_size_ = max_read_size; } | 162 void SetMaxReadSize(int max_read_size) { max_read_size_ = max_read_size; } |
162 void SetData(scoped_ptr<::media::AudioBus> data) { | 163 void SetData(std::unique_ptr<::media::AudioBus> data) { |
163 CHECK(!data_); | 164 CHECK(!data_); |
164 data_ = std::move(data); | 165 data_ = std::move(data); |
165 max_read_size_ = data_->frames(); | 166 max_read_size_ = data_->frames(); |
166 } | 167 } |
167 void SetVolumeMultiplier(float multiplier) { | 168 void SetVolumeMultiplier(float multiplier) { |
168 CHECK(multiplier >= 0.0 && multiplier <= 1.0); | 169 CHECK(multiplier >= 0.0 && multiplier <= 1.0); |
169 multiplier_ = multiplier; | 170 multiplier_ = multiplier; |
170 } | 171 } |
171 void SetPrimary(bool primary) { primary_ = primary; } | 172 void SetPrimary(bool primary) { primary_ = primary; } |
172 const ::media::AudioBus& data() { | 173 const ::media::AudioBus& data() { |
(...skipping 17 matching lines...) Expand all Loading... |
190 deleting_ = true; | 191 deleting_ = true; |
191 delete_cb.Run(this); | 192 delete_cb.Run(this); |
192 } | 193 } |
193 | 194 |
194 bool paused_; | 195 bool paused_; |
195 int samples_per_second_; | 196 int samples_per_second_; |
196 int max_read_size_; | 197 int max_read_size_; |
197 float multiplier_; | 198 float multiplier_; |
198 bool primary_; | 199 bool primary_; |
199 bool deleting_; | 200 bool deleting_; |
200 scoped_ptr<::media::AudioBus> data_; | 201 std::unique_ptr<::media::AudioBus> data_; |
201 | 202 |
202 DISALLOW_COPY_AND_ASSIGN(MockInputQueue); | 203 DISALLOW_COPY_AND_ASSIGN(MockInputQueue); |
203 }; | 204 }; |
204 | 205 |
205 // Given |inputs|, returns mixed audio data according to the mixing method used | 206 // Given |inputs|, returns mixed audio data according to the mixing method used |
206 // by the mixer. | 207 // by the mixer. |
207 scoped_ptr<::media::AudioBus> GetMixedAudioData( | 208 std::unique_ptr<::media::AudioBus> GetMixedAudioData( |
208 const std::vector<testing::StrictMock<MockInputQueue>*>& inputs) { | 209 const std::vector<testing::StrictMock<MockInputQueue>*>& inputs) { |
209 int read_size = std::numeric_limits<int>::max(); | 210 int read_size = std::numeric_limits<int>::max(); |
210 for (const auto input : inputs) { | 211 for (const auto input : inputs) { |
211 CHECK(input); | 212 CHECK(input); |
212 read_size = std::min(input->MaxReadSize(), read_size); | 213 read_size = std::min(input->MaxReadSize(), read_size); |
213 } | 214 } |
214 | 215 |
215 // Verify all inputs are the right size. | 216 // Verify all inputs are the right size. |
216 for (const auto input : inputs) { | 217 for (const auto input : inputs) { |
217 CHECK_EQ(kNumChannels, input->data().channels()); | 218 CHECK_EQ(kNumChannels, input->data().channels()); |
(...skipping 14 matching lines...) Expand all Loading... |
232 | 233 |
233 // Clamp the mixed sample between 1.0 and -1.0. | 234 // Clamp the mixed sample between 1.0 and -1.0. |
234 *result = std::min(1.0f, std::max(-1.0f, *result)); | 235 *result = std::min(1.0f, std::max(-1.0f, *result)); |
235 } | 236 } |
236 } | 237 } |
237 return mixed; | 238 return mixed; |
238 } | 239 } |
239 | 240 |
240 // Like the method above, but accepts a single input. This returns an AudioBus | 241 // Like the method above, but accepts a single input. This returns an AudioBus |
241 // with this input after it is scaled and clipped. | 242 // with this input after it is scaled and clipped. |
242 scoped_ptr<::media::AudioBus> GetMixedAudioData( | 243 std::unique_ptr<::media::AudioBus> GetMixedAudioData( |
243 testing::StrictMock<MockInputQueue>* input) { | 244 testing::StrictMock<MockInputQueue>* input) { |
244 return GetMixedAudioData( | 245 return GetMixedAudioData( |
245 std::vector<testing::StrictMock<MockInputQueue>*>(1, input)); | 246 std::vector<testing::StrictMock<MockInputQueue>*>(1, input)); |
246 } | 247 } |
247 | 248 |
248 // Asserts that |expected| matches |actual| exactly. | 249 // Asserts that |expected| matches |actual| exactly. |
249 void CompareAudioData(const ::media::AudioBus& expected, | 250 void CompareAudioData(const ::media::AudioBus& expected, |
250 const ::media::AudioBus& actual) { | 251 const ::media::AudioBus& actual) { |
251 ASSERT_EQ(expected.channels(), actual.channels()); | 252 ASSERT_EQ(expected.channels(), actual.channels()); |
252 ASSERT_EQ(expected.frames(), actual.frames()); | 253 ASSERT_EQ(expected.frames(), actual.frames()); |
253 for (int c = 0; c < expected.channels(); ++c) { | 254 for (int c = 0; c < expected.channels(); ++c) { |
254 const float* expected_data = expected.channel(c); | 255 const float* expected_data = expected.channel(c); |
255 const float* actual_data = actual.channel(c); | 256 const float* actual_data = actual.channel(c); |
256 for (int f = 0; f < expected.frames(); ++f) | 257 for (int f = 0; f < expected.frames(); ++f) |
257 ASSERT_FLOAT_EQ(*expected_data++, *actual_data++) << c << " " << f; | 258 ASSERT_FLOAT_EQ(*expected_data++, *actual_data++) << c << " " << f; |
258 } | 259 } |
259 } | 260 } |
260 | 261 |
261 } // namespace | 262 } // namespace |
262 | 263 |
263 class StreamMixerAlsaTest : public testing::Test { | 264 class StreamMixerAlsaTest : public testing::Test { |
264 protected: | 265 protected: |
265 StreamMixerAlsaTest() | 266 StreamMixerAlsaTest() |
266 : message_loop_(new base::MessageLoop()), | 267 : message_loop_(new base::MessageLoop()), |
267 mock_alsa_(new testing::NiceMock<MockAlsaWrapper>()) { | 268 mock_alsa_(new testing::NiceMock<MockAlsaWrapper>()) { |
268 StreamMixerAlsa::MakeSingleThreadedForTest(); | 269 StreamMixerAlsa::MakeSingleThreadedForTest(); |
269 StreamMixerAlsa::Get()->SetAlsaWrapperForTest(make_scoped_ptr(mock_alsa_)); | 270 StreamMixerAlsa::Get()->SetAlsaWrapperForTest(base::WrapUnique(mock_alsa_)); |
270 } | 271 } |
271 | 272 |
272 ~StreamMixerAlsaTest() override { | 273 ~StreamMixerAlsaTest() override { |
273 StreamMixerAlsa::Get()->ClearInputsForTest(); | 274 StreamMixerAlsa::Get()->ClearInputsForTest(); |
274 } | 275 } |
275 | 276 |
276 MockAlsaWrapper* mock_alsa() { return mock_alsa_; } | 277 MockAlsaWrapper* mock_alsa() { return mock_alsa_; } |
277 | 278 |
278 private: | 279 private: |
279 const scoped_ptr<base::MessageLoop> message_loop_; | 280 const std::unique_ptr<base::MessageLoop> message_loop_; |
280 testing::NiceMock<MockAlsaWrapper>* mock_alsa_; | 281 testing::NiceMock<MockAlsaWrapper>* mock_alsa_; |
281 | 282 |
282 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaTest); | 283 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaTest); |
283 }; | 284 }; |
284 | 285 |
285 TEST_F(StreamMixerAlsaTest, AddSingleInput) { | 286 TEST_F(StreamMixerAlsaTest, AddSingleInput) { |
286 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); | 287 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); |
287 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 288 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
288 | 289 |
289 EXPECT_CALL(*input, Initialize(_)).Times(1); | 290 EXPECT_CALL(*input, Initialize(_)).Times(1); |
290 mixer->AddInput(make_scoped_ptr(input)); | 291 mixer->AddInput(base::WrapUnique(input)); |
291 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 292 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
292 } | 293 } |
293 | 294 |
294 TEST_F(StreamMixerAlsaTest, AddMultipleInputs) { | 295 TEST_F(StreamMixerAlsaTest, AddMultipleInputs) { |
295 auto input1 = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); | 296 auto input1 = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); |
296 auto input2 = | 297 auto input2 = |
297 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond * 2); | 298 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond * 2); |
298 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 299 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
299 | 300 |
300 EXPECT_CALL(*input1, Initialize(_)).Times(1); | 301 EXPECT_CALL(*input1, Initialize(_)).Times(1); |
301 EXPECT_CALL(*input2, Initialize(_)).Times(1); | 302 EXPECT_CALL(*input2, Initialize(_)).Times(1); |
302 mixer->AddInput(make_scoped_ptr(input1)); | 303 mixer->AddInput(base::WrapUnique(input1)); |
303 mixer->AddInput(make_scoped_ptr(input2)); | 304 mixer->AddInput(base::WrapUnique(input2)); |
304 | 305 |
305 // The mixer should be ready to play, and should sample to the initial | 306 // The mixer should be ready to play, and should sample to the initial |
306 // sample rate. | 307 // sample rate. |
307 EXPECT_EQ(kTestSamplesPerSecond, mixer->output_samples_per_second()); | 308 EXPECT_EQ(kTestSamplesPerSecond, mixer->output_samples_per_second()); |
308 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 309 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
309 } | 310 } |
310 | 311 |
311 TEST_F(StreamMixerAlsaTest, RemoveInput) { | 312 TEST_F(StreamMixerAlsaTest, RemoveInput) { |
312 std::vector<testing::StrictMock<MockInputQueue>*> inputs; | 313 std::vector<testing::StrictMock<MockInputQueue>*> inputs; |
313 const int kNumInputs = 3; | 314 const int kNumInputs = 3; |
314 for (int i = 0; i < kNumInputs; ++i) { | 315 for (int i = 0; i < kNumInputs; ++i) { |
315 inputs.push_back(new testing::StrictMock<MockInputQueue>( | 316 inputs.push_back(new testing::StrictMock<MockInputQueue>( |
316 kTestSamplesPerSecond * (i + 1))); | 317 kTestSamplesPerSecond * (i + 1))); |
317 } | 318 } |
318 | 319 |
319 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 320 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
320 for (size_t i = 0; i < inputs.size(); ++i) { | 321 for (size_t i = 0; i < inputs.size(); ++i) { |
321 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); | 322 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); |
322 mixer->AddInput(make_scoped_ptr(inputs[i])); | 323 mixer->AddInput(base::WrapUnique(inputs[i])); |
323 } | 324 } |
324 | 325 |
325 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 326 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
326 | 327 |
327 for (size_t i = 0; i < inputs.size(); ++i) { | 328 for (size_t i = 0; i < inputs.size(); ++i) { |
328 EXPECT_CALL(*inputs[i], PrepareToDelete(_)).Times(1); | 329 EXPECT_CALL(*inputs[i], PrepareToDelete(_)).Times(1); |
329 mixer->RemoveInput(inputs[i]); | 330 mixer->RemoveInput(inputs[i]); |
330 } | 331 } |
331 | 332 |
332 // Need to wait for the removal task (it is always posted). | 333 // Need to wait for the removal task (it is always posted). |
333 base::RunLoop().RunUntilIdle(); | 334 base::RunLoop().RunUntilIdle(); |
334 | 335 |
335 EXPECT_TRUE(mixer->empty()); | 336 EXPECT_TRUE(mixer->empty()); |
336 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 337 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
337 } | 338 } |
338 | 339 |
339 TEST_F(StreamMixerAlsaTest, WriteFrames) { | 340 TEST_F(StreamMixerAlsaTest, WriteFrames) { |
340 std::vector<testing::StrictMock<MockInputQueue>*> inputs; | 341 std::vector<testing::StrictMock<MockInputQueue>*> inputs; |
341 const int kNumInputs = 3; | 342 const int kNumInputs = 3; |
342 for (int i = 0; i < kNumInputs; ++i) { | 343 for (int i = 0; i < kNumInputs; ++i) { |
343 inputs.push_back( | 344 inputs.push_back( |
344 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); | 345 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); |
345 inputs.back()->SetPaused(false); | 346 inputs.back()->SetPaused(false); |
346 } | 347 } |
347 | 348 |
348 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 349 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
349 for (size_t i = 0; i < inputs.size(); ++i) { | 350 for (size_t i = 0; i < inputs.size(); ++i) { |
350 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); | 351 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); |
351 mixer->AddInput(make_scoped_ptr(inputs[i])); | 352 mixer->AddInput(base::WrapUnique(inputs[i])); |
352 } | 353 } |
353 | 354 |
354 ASSERT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 355 ASSERT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
355 | 356 |
356 // The mixer should pull data from all streams, using the smallest | 357 // The mixer should pull data from all streams, using the smallest |
357 // MaxReadSize provided by any of the channels. | 358 // MaxReadSize provided by any of the channels. |
358 // TODO(slan): Check that the proper number of frames is pulled. | 359 // TODO(slan): Check that the proper number of frames is pulled. |
359 ASSERT_EQ(3u, inputs.size()); | 360 ASSERT_EQ(3u, inputs.size()); |
360 inputs[0]->SetMaxReadSize(1024); | 361 inputs[0]->SetMaxReadSize(1024); |
361 inputs[1]->SetMaxReadSize(512); | 362 inputs[1]->SetMaxReadSize(512); |
(...skipping 28 matching lines...) Expand all Loading... |
390 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, _)).Times(0); | 391 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, _)).Times(0); |
391 mixer->WriteFramesForTest(); | 392 mixer->WriteFramesForTest(); |
392 } | 393 } |
393 | 394 |
394 TEST_F(StreamMixerAlsaTest, OneStreamMixesProperly) { | 395 TEST_F(StreamMixerAlsaTest, OneStreamMixesProperly) { |
395 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); | 396 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); |
396 input->SetPaused(false); | 397 input->SetPaused(false); |
397 | 398 |
398 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 399 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
399 EXPECT_CALL(*input, Initialize(_)).Times(1); | 400 EXPECT_CALL(*input, Initialize(_)).Times(1); |
400 mixer->AddInput(make_scoped_ptr(input)); | 401 mixer->AddInput(base::WrapUnique(input)); |
401 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 402 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
402 | 403 |
403 // Populate the stream with data. | 404 // Populate the stream with data. |
404 const int kNumFrames = 32; | 405 const int kNumFrames = 32; |
405 input->SetData(GetTestData(0)); | 406 input->SetData(GetTestData(0)); |
406 | 407 |
407 ASSERT_EQ(mock_alsa()->data().size(), 0u); | 408 ASSERT_EQ(mock_alsa()->data().size(), 0u); |
408 | 409 |
409 // Write the stream to ALSA. | 410 // Write the stream to ALSA. |
410 EXPECT_CALL(*input, GetResampledData(_, kNumFrames)); | 411 EXPECT_CALL(*input, GetResampledData(_, kNumFrames)); |
411 EXPECT_CALL(*input, AfterWriteFrames(_)); | 412 EXPECT_CALL(*input, AfterWriteFrames(_)); |
412 mixer->WriteFramesForTest(); | 413 mixer->WriteFramesForTest(); |
413 | 414 |
414 // Get the actual stream rendered to ALSA, and compare it against the | 415 // Get the actual stream rendered to ALSA, and compare it against the |
415 // expected stream. The stream should match exactly. | 416 // expected stream. The stream should match exactly. |
416 auto actual = ::media::AudioBus::Create(kNumChannels, kNumFrames); | 417 auto actual = ::media::AudioBus::Create(kNumChannels, kNumFrames); |
417 ASSERT_GT(mock_alsa()->data().size(), 0u); | 418 ASSERT_GT(mock_alsa()->data().size(), 0u); |
418 actual->FromInterleaved( | 419 actual->FromInterleaved( |
419 &(mock_alsa()->data()[0]), kNumFrames, kBytesPerSample); | 420 &(mock_alsa()->data()[0]), kNumFrames, kBytesPerSample); |
420 CompareAudioData(input->data(), *actual); | 421 CompareAudioData(input->data(), *actual); |
421 } | 422 } |
422 | 423 |
423 TEST_F(StreamMixerAlsaTest, OneStreamIsScaledDownProperly) { | 424 TEST_F(StreamMixerAlsaTest, OneStreamIsScaledDownProperly) { |
424 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); | 425 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); |
425 input->SetPaused(false); | 426 input->SetPaused(false); |
426 | 427 |
427 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 428 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
428 EXPECT_CALL(*input, Initialize(_)).Times(1); | 429 EXPECT_CALL(*input, Initialize(_)).Times(1); |
429 mixer->AddInput(make_scoped_ptr(input)); | 430 mixer->AddInput(base::WrapUnique(input)); |
430 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 431 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
431 | 432 |
432 // Populate the stream with data. | 433 // Populate the stream with data. |
433 const int kNumFrames = 32; | 434 const int kNumFrames = 32; |
434 ASSERT_EQ(sizeof(kTestData[0]), kNumChannels * kNumFrames * kBytesPerSample); | 435 ASSERT_EQ(sizeof(kTestData[0]), kNumChannels * kNumFrames * kBytesPerSample); |
435 auto data = GetTestData(0); | 436 auto data = GetTestData(0); |
436 input->SetData(std::move(data)); | 437 input->SetData(std::move(data)); |
437 | 438 |
438 // Set a volume multiplier on the stream. | 439 // Set a volume multiplier on the stream. |
439 input->SetVolumeMultiplier(0.75); | 440 input->SetVolumeMultiplier(0.75); |
(...skipping 17 matching lines...) Expand all Loading... |
457 const int kNumInputs = 2; | 458 const int kNumInputs = 2; |
458 for (int i = 0; i < kNumInputs; ++i) { | 459 for (int i = 0; i < kNumInputs; ++i) { |
459 inputs.push_back( | 460 inputs.push_back( |
460 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); | 461 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); |
461 inputs.back()->SetPaused(false); | 462 inputs.back()->SetPaused(false); |
462 } | 463 } |
463 | 464 |
464 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 465 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
465 for (size_t i = 0; i < inputs.size(); ++i) { | 466 for (size_t i = 0; i < inputs.size(); ++i) { |
466 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); | 467 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); |
467 mixer->AddInput(make_scoped_ptr(inputs[i])); | 468 mixer->AddInput(base::WrapUnique(inputs[i])); |
468 } | 469 } |
469 | 470 |
470 // Poll the inputs for data. | 471 // Poll the inputs for data. |
471 const int kNumFrames = 32; | 472 const int kNumFrames = 32; |
472 for (size_t i = 0; i < inputs.size(); ++i) { | 473 for (size_t i = 0; i < inputs.size(); ++i) { |
473 inputs[i]->SetData(GetTestData(i)); | 474 inputs[i]->SetData(GetTestData(i)); |
474 EXPECT_CALL(*inputs[i], GetResampledData(_, kNumFrames)); | 475 EXPECT_CALL(*inputs[i], GetResampledData(_, kNumFrames)); |
475 EXPECT_CALL(*inputs[i], AfterWriteFrames(_)); | 476 EXPECT_CALL(*inputs[i], AfterWriteFrames(_)); |
476 } | 477 } |
477 | 478 |
(...skipping 17 matching lines...) Expand all Loading... |
495 const int kNumInputs = 2; | 496 const int kNumInputs = 2; |
496 for (int i = 0; i < kNumInputs; ++i) { | 497 for (int i = 0; i < kNumInputs; ++i) { |
497 inputs.push_back( | 498 inputs.push_back( |
498 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); | 499 new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond)); |
499 inputs.back()->SetPaused(false); | 500 inputs.back()->SetPaused(false); |
500 } | 501 } |
501 | 502 |
502 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 503 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
503 for (size_t i = 0; i < inputs.size(); ++i) { | 504 for (size_t i = 0; i < inputs.size(); ++i) { |
504 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); | 505 EXPECT_CALL(*inputs[i], Initialize(_)).Times(1); |
505 mixer->AddInput(make_scoped_ptr(inputs[i])); | 506 mixer->AddInput(base::WrapUnique(inputs[i])); |
506 } | 507 } |
507 | 508 |
508 // Create edge case data for the inputs. By mixing these two short streams, | 509 // Create edge case data for the inputs. By mixing these two short streams, |
509 // every combination of {-(2^31), 0, 2^31-1} is tested. This test case is | 510 // every combination of {-(2^31), 0, 2^31-1} is tested. This test case is |
510 // intended to be a hand-checkable gut check. | 511 // intended to be a hand-checkable gut check. |
511 // Note: Test data should be represented as 32-bit integers and copied into | 512 // Note: Test data should be represented as 32-bit integers and copied into |
512 // ::media::AudioBus instances, rather than wrapping statically declared float | 513 // ::media::AudioBus instances, rather than wrapping statically declared float |
513 // arrays. The latter method is brittle, as ::media::AudioBus requires 16-bit | 514 // arrays. The latter method is brittle, as ::media::AudioBus requires 16-bit |
514 // alignment for internal data. | 515 // alignment for internal data. |
515 const int kNumFrames = 3; | 516 const int kNumFrames = 3; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 &(mock_alsa()->data()[0]), kNumFrames, kBytesPerSample); | 562 &(mock_alsa()->data()[0]), kNumFrames, kBytesPerSample); |
562 CompareAudioData(*expected, *actual); | 563 CompareAudioData(*expected, *actual); |
563 } | 564 } |
564 | 565 |
565 TEST_F(StreamMixerAlsaTest, WriteBuffersOfVaryingLength) { | 566 TEST_F(StreamMixerAlsaTest, WriteBuffersOfVaryingLength) { |
566 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); | 567 auto input = new testing::StrictMock<MockInputQueue>(kTestSamplesPerSecond); |
567 input->SetPaused(false); | 568 input->SetPaused(false); |
568 | 569 |
569 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); | 570 StreamMixerAlsa* mixer = StreamMixerAlsa::Get(); |
570 EXPECT_CALL(*input, Initialize(_)).Times(1); | 571 EXPECT_CALL(*input, Initialize(_)).Times(1); |
571 mixer->AddInput(make_scoped_ptr(input)); | 572 mixer->AddInput(base::WrapUnique(input)); |
572 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); | 573 EXPECT_EQ(StreamMixerAlsa::kStateNormalPlayback, mixer->state()); |
573 | 574 |
574 // The input stream will provide buffers of several different lengths. | 575 // The input stream will provide buffers of several different lengths. |
575 input->SetMaxReadSize(7); | 576 input->SetMaxReadSize(7); |
576 EXPECT_CALL(*input, GetResampledData(_, 7)); | 577 EXPECT_CALL(*input, GetResampledData(_, 7)); |
577 EXPECT_CALL(*input, AfterWriteFrames(_)); | 578 EXPECT_CALL(*input, AfterWriteFrames(_)); |
578 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, 7)).Times(1); | 579 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, 7)).Times(1); |
579 mixer->WriteFramesForTest(); | 580 mixer->WriteFramesForTest(); |
580 | 581 |
581 input->SetMaxReadSize(100); | 582 input->SetMaxReadSize(100); |
(...skipping 10 matching lines...) Expand all Loading... |
592 | 593 |
593 input->SetMaxReadSize(1024); | 594 input->SetMaxReadSize(1024); |
594 EXPECT_CALL(*input, GetResampledData(_, 1024)); | 595 EXPECT_CALL(*input, GetResampledData(_, 1024)); |
595 EXPECT_CALL(*input, AfterWriteFrames(_)); | 596 EXPECT_CALL(*input, AfterWriteFrames(_)); |
596 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, 1024)).Times(1); | 597 EXPECT_CALL(*mock_alsa(), PcmWritei(_, _, 1024)).Times(1); |
597 mixer->WriteFramesForTest(); | 598 mixer->WriteFramesForTest(); |
598 } | 599 } |
599 | 600 |
600 } // namespace media | 601 } // namespace media |
601 } // namespace chromecast | 602 } // namespace chromecast |
OLD | NEW |