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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/test/test_message_loop.h" | 13 #include "base/test/test_message_loop.h" |
14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "media/audio/audio_device_description.h" | 17 #include "media/audio/audio_device_description.h" |
18 #include "media/audio/cras/audio_manager_cras.h" | 18 #include "media/audio/cras/audio_manager_cras.h" |
19 #include "media/audio/fake_audio_log_factory.h" | 19 #include "media/audio/fake_audio_log_factory.h" |
| 20 #include "media/audio/test_audio_thread.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 // cras_util.h defines custom min/max macros which break compilation, so ensure | 24 // cras_util.h defines custom min/max macros which break compilation, so ensure |
24 // it's not included until last. #if avoids presubmit errors. | 25 // it's not included until last. #if avoids presubmit errors. |
25 #if defined(USE_CRAS) | 26 #if defined(USE_CRAS) |
26 #include "media/audio/cras/cras_input.h" | 27 #include "media/audio/cras/cras_input.h" |
27 #endif | 28 #endif |
28 | 29 |
29 using testing::_; | 30 using testing::_; |
30 using testing::AtLeast; | 31 using testing::AtLeast; |
31 using testing::Ge; | 32 using testing::Ge; |
32 using testing::InvokeWithoutArgs; | 33 using testing::InvokeWithoutArgs; |
33 using testing::StrictMock; | 34 using testing::StrictMock; |
34 | 35 |
35 namespace media { | 36 namespace media { |
36 | 37 |
37 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { | 38 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
38 public: | 39 public: |
39 MOCK_METHOD4(OnData, | 40 MOCK_METHOD4(OnData, |
40 void(AudioInputStream*, const AudioBus*, uint32_t, double)); | 41 void(AudioInputStream*, const AudioBus*, uint32_t, double)); |
41 MOCK_METHOD1(OnError, void(AudioInputStream*)); | 42 MOCK_METHOD1(OnError, void(AudioInputStream*)); |
42 }; | 43 }; |
43 | 44 |
44 class MockAudioManagerCrasInput : public AudioManagerCras { | 45 class MockAudioManagerCrasInput : public AudioManagerCras { |
45 public: | 46 public: |
46 MockAudioManagerCrasInput() | 47 MockAudioManagerCrasInput() |
47 : AudioManagerCras(base::ThreadTaskRunnerHandle::Get(), | 48 : AudioManagerCras(base::MakeUnique<TestAudioThread>(), |
48 base::ThreadTaskRunnerHandle::Get(), | |
49 &fake_audio_log_factory_) {} | 49 &fake_audio_log_factory_) {} |
50 | 50 |
51 // We need to override this function in order to skip checking the number | 51 // We need to override this function in order to skip checking the number |
52 // of active output streams. It is because the number of active streams | 52 // of active output streams. It is because the number of active streams |
53 // is managed inside MakeAudioInputStream, and we don't use | 53 // is managed inside MakeAudioInputStream, and we don't use |
54 // MakeAudioInputStream to create the stream in the tests. | 54 // MakeAudioInputStream to create the stream in the tests. |
55 void ReleaseInputStream(AudioInputStream* stream) override { | 55 void ReleaseInputStream(AudioInputStream* stream) override { |
56 DCHECK(stream); | 56 DCHECK(stream); |
57 delete stream; | 57 delete stream; |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 FakeAudioLogFactory fake_audio_log_factory_; | 61 FakeAudioLogFactory fake_audio_log_factory_; |
62 }; | 62 }; |
63 | 63 |
64 class CrasInputStreamTest : public testing::Test { | 64 class CrasInputStreamTest : public testing::Test { |
65 protected: | 65 protected: |
66 CrasInputStreamTest() { | 66 CrasInputStreamTest() { |
67 mock_manager_.reset(new StrictMock<MockAudioManagerCrasInput>()); | 67 mock_manager_.reset(new StrictMock<MockAudioManagerCrasInput>()); |
68 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
69 } | 69 } |
70 | 70 |
71 ~CrasInputStreamTest() override {} | 71 ~CrasInputStreamTest() override { mock_manager_->Shutdown(); } |
72 | 72 |
73 CrasInputStream* CreateStream(ChannelLayout layout) { | 73 CrasInputStream* CreateStream(ChannelLayout layout) { |
74 return CreateStream(layout, kTestFramesPerPacket); | 74 return CreateStream(layout, kTestFramesPerPacket); |
75 } | 75 } |
76 | 76 |
77 CrasInputStream* CreateStream(ChannelLayout layout, | 77 CrasInputStream* CreateStream(ChannelLayout layout, |
78 int32_t samples_per_packet) { | 78 int32_t samples_per_packet) { |
79 return CreateStream(layout, samples_per_packet, | 79 return CreateStream(layout, samples_per_packet, |
80 AudioDeviceDescription::kDefaultDeviceId); | 80 AudioDeviceDescription::kDefaultDeviceId); |
81 } | 81 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 static const unsigned int kTestBitsPerSample; | 120 static const unsigned int kTestBitsPerSample; |
121 static const unsigned int kTestCaptureDurationMs; | 121 static const unsigned int kTestCaptureDurationMs; |
122 static const ChannelLayout kTestChannelLayout; | 122 static const ChannelLayout kTestChannelLayout; |
123 static const AudioParameters::Format kTestFormat; | 123 static const AudioParameters::Format kTestFormat; |
124 static const uint32_t kTestFramesPerPacket; | 124 static const uint32_t kTestFramesPerPacket; |
125 static const int kTestSampleRate; | 125 static const int kTestSampleRate; |
126 | 126 |
127 base::TestMessageLoop message_loop_; | 127 base::TestMessageLoop message_loop_; |
128 std::unique_ptr<StrictMock<MockAudioManagerCrasInput>, AudioManagerDeleter> | 128 std::unique_ptr<StrictMock<MockAudioManagerCrasInput>> mock_manager_; |
129 mock_manager_; | |
130 | 129 |
131 private: | 130 private: |
132 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); | 131 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); |
133 }; | 132 }; |
134 | 133 |
135 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; | 134 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; |
136 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; | 135 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; |
137 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = | 136 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = |
138 CHANNEL_LAYOUT_STEREO; | 137 CHANNEL_LAYOUT_STEREO; |
139 const AudioParameters::Format CrasInputStreamTest::kTestFormat = | 138 const AudioParameters::Format CrasInputStreamTest::kTestFormat = |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 222 |
224 TEST_F(CrasInputStreamTest, CaptureLoopback) { | 223 TEST_F(CrasInputStreamTest, CaptureLoopback) { |
225 CrasInputStream* test_stream = | 224 CrasInputStream* test_stream = |
226 CreateStream(CHANNEL_LAYOUT_STEREO, kTestFramesPerPacket, | 225 CreateStream(CHANNEL_LAYOUT_STEREO, kTestFramesPerPacket, |
227 AudioDeviceDescription::kLoopbackInputDeviceId); | 226 AudioDeviceDescription::kLoopbackInputDeviceId); |
228 EXPECT_TRUE(test_stream->Open()); | 227 EXPECT_TRUE(test_stream->Open()); |
229 test_stream->Close(); | 228 test_stream->Close(); |
230 } | 229 } |
231 | 230 |
232 } // namespace media | 231 } // namespace media |
OLD | NEW |