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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/audio/cras/audio_manager_cras.h" | 10 #include "media/audio/cras/audio_manager_cras.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 using testing::_; | 21 using testing::_; |
22 using testing::AtLeast; | 22 using testing::AtLeast; |
23 using testing::Ge; | 23 using testing::Ge; |
24 using testing::InvokeWithoutArgs; | 24 using testing::InvokeWithoutArgs; |
25 using testing::StrictMock; | 25 using testing::StrictMock; |
26 | 26 |
27 namespace media { | 27 namespace media { |
28 | 28 |
29 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { | 29 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
30 public: | 30 public: |
31 MOCK_METHOD5(OnData, void( | 31 MOCK_METHOD4(OnData, |
32 AudioInputStream*, const uint8*, uint32, uint32, double)); | 32 void(AudioInputStream*, const AudioBus*, uint32, double)); |
33 MOCK_METHOD1(OnError, void(AudioInputStream*)); | 33 MOCK_METHOD1(OnError, void(AudioInputStream*)); |
34 }; | 34 }; |
35 | 35 |
36 class MockAudioManagerCrasInput : public AudioManagerCras { | 36 class MockAudioManagerCrasInput : public AudioManagerCras { |
37 public: | 37 public: |
38 MockAudioManagerCrasInput() : AudioManagerCras(&fake_audio_log_factory_) {} | 38 MockAudioManagerCrasInput() : AudioManagerCras(&fake_audio_log_factory_) {} |
39 | 39 |
40 // We need to override this function in order to skip checking the number | 40 // We need to override this function in order to skip checking the number |
41 // of active output streams. It is because the number of active streams | 41 // of active output streams. It is because the number of active streams |
42 // is managed inside MakeAudioInputStream, and we don't use | 42 // is managed inside MakeAudioInputStream, and we don't use |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 unsigned int duration_ms) { | 78 unsigned int duration_ms) { |
79 CrasInputStream* test_stream = new CrasInputStream( | 79 CrasInputStream* test_stream = new CrasInputStream( |
80 params, mock_manager_.get(), AudioManagerBase::kDefaultDeviceId); | 80 params, mock_manager_.get(), AudioManagerBase::kDefaultDeviceId); |
81 | 81 |
82 ASSERT_TRUE(test_stream->Open()); | 82 ASSERT_TRUE(test_stream->Open()); |
83 | 83 |
84 // Allow 8 frames variance for SRC in the callback. Different numbers of | 84 // Allow 8 frames variance for SRC in the callback. Different numbers of |
85 // samples can be provided when doing non-integer SRC. For example | 85 // samples can be provided when doing non-integer SRC. For example |
86 // converting from 192k to 44.1k is a ratio of 4.35 to 1. | 86 // converting from 192k to 44.1k is a ratio of 4.35 to 1. |
87 MockAudioInputCallback mock_callback; | 87 MockAudioInputCallback mock_callback; |
88 unsigned int expected_size = (kTestFramesPerPacket - 8) * | |
89 params.channels() * | |
90 params.bits_per_sample() / 8; | |
91 | |
92 base::WaitableEvent event(false, false); | 88 base::WaitableEvent event(false, false); |
93 | 89 |
94 EXPECT_CALL(mock_callback, | 90 EXPECT_CALL(mock_callback, OnData(test_stream, _, _, _)) |
95 OnData(test_stream, _, Ge(expected_size), _, _)) | |
96 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); | 91 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
97 | 92 |
98 test_stream->Start(&mock_callback); | 93 test_stream->Start(&mock_callback); |
99 | 94 |
100 // Wait for samples to be captured. | 95 // Wait for samples to be captured. |
101 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); | 96 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
102 | 97 |
103 test_stream->Stop(); | 98 test_stream->Stop(); |
104 test_stream->Close(); | 99 test_stream->Close(); |
105 } | 100 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 AudioParameters params_stereo(kTestFormat, | 206 AudioParameters params_stereo(kTestFormat, |
212 CHANNEL_LAYOUT_STEREO, | 207 CHANNEL_LAYOUT_STEREO, |
213 rates[i], | 208 rates[i], |
214 kTestBitsPerSample, | 209 kTestBitsPerSample, |
215 kTestFramesPerPacket); | 210 kTestFramesPerPacket); |
216 CaptureSomeFrames(params_stereo, kTestCaptureDurationMs); | 211 CaptureSomeFrames(params_stereo, kTestCaptureDurationMs); |
217 } | 212 } |
218 } | 213 } |
219 | 214 |
220 } // namespace media | 215 } // namespace media |
OLD | NEW |