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 11 matching lines...) Expand all Loading... |
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_METHOD4(OnData, | 31 MOCK_METHOD4(OnData, |
32 void(AudioInputStream*, const AudioBus*, uint32, double)); | 32 void(AudioInputStream*, const AudioBus*, uint32_t, 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 14 matching lines...) Expand all Loading... |
57 } | 57 } |
58 | 58 |
59 virtual ~CrasInputStreamTest() { | 59 virtual ~CrasInputStreamTest() { |
60 } | 60 } |
61 | 61 |
62 CrasInputStream* CreateStream(ChannelLayout layout) { | 62 CrasInputStream* CreateStream(ChannelLayout layout) { |
63 return CreateStream(layout, kTestFramesPerPacket); | 63 return CreateStream(layout, kTestFramesPerPacket); |
64 } | 64 } |
65 | 65 |
66 CrasInputStream* CreateStream(ChannelLayout layout, | 66 CrasInputStream* CreateStream(ChannelLayout layout, |
67 int32 samples_per_packet) { | 67 int32_t samples_per_packet) { |
68 return CreateStream(layout, samples_per_packet, | 68 return CreateStream(layout, samples_per_packet, |
69 AudioManagerBase::kDefaultDeviceId); | 69 AudioManagerBase::kDefaultDeviceId); |
70 } | 70 } |
71 | 71 |
72 CrasInputStream* CreateStream(ChannelLayout layout, | 72 CrasInputStream* CreateStream(ChannelLayout layout, |
73 int32 samples_per_packet, | 73 int32_t samples_per_packet, |
74 const std::string& device_id) { | 74 const std::string& device_id) { |
75 AudioParameters params(kTestFormat, | 75 AudioParameters params(kTestFormat, |
76 layout, | 76 layout, |
77 kTestSampleRate, | 77 kTestSampleRate, |
78 kTestBitsPerSample, | 78 kTestBitsPerSample, |
79 samples_per_packet); | 79 samples_per_packet); |
80 return new CrasInputStream(params, mock_manager_.get(), device_id); | 80 return new CrasInputStream(params, mock_manager_.get(), device_id); |
81 } | 81 } |
82 | 82 |
83 void CaptureSomeFrames(const AudioParameters ¶ms, | 83 void CaptureSomeFrames(const AudioParameters ¶ms, |
(...skipping 18 matching lines...) Expand all Loading... |
102 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); | 102 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
103 | 103 |
104 test_stream->Stop(); | 104 test_stream->Stop(); |
105 test_stream->Close(); | 105 test_stream->Close(); |
106 } | 106 } |
107 | 107 |
108 static const unsigned int kTestBitsPerSample; | 108 static const unsigned int kTestBitsPerSample; |
109 static const unsigned int kTestCaptureDurationMs; | 109 static const unsigned int kTestCaptureDurationMs; |
110 static const ChannelLayout kTestChannelLayout; | 110 static const ChannelLayout kTestChannelLayout; |
111 static const AudioParameters::Format kTestFormat; | 111 static const AudioParameters::Format kTestFormat; |
112 static const uint32 kTestFramesPerPacket; | 112 static const uint32_t kTestFramesPerPacket; |
113 static const int kTestSampleRate; | 113 static const int kTestSampleRate; |
114 | 114 |
115 scoped_ptr<StrictMock<MockAudioManagerCrasInput> > mock_manager_; | 115 scoped_ptr<StrictMock<MockAudioManagerCrasInput> > mock_manager_; |
116 | 116 |
117 private: | 117 private: |
118 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); | 118 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); |
119 }; | 119 }; |
120 | 120 |
121 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; | 121 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; |
122 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; | 122 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; |
123 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = | 123 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = |
124 CHANNEL_LAYOUT_STEREO; | 124 CHANNEL_LAYOUT_STEREO; |
125 const AudioParameters::Format CrasInputStreamTest::kTestFormat = | 125 const AudioParameters::Format CrasInputStreamTest::kTestFormat = |
126 AudioParameters::AUDIO_PCM_LINEAR; | 126 AudioParameters::AUDIO_PCM_LINEAR; |
127 const uint32 CrasInputStreamTest::kTestFramesPerPacket = 1000; | 127 const uint32_t CrasInputStreamTest::kTestFramesPerPacket = 1000; |
128 const int CrasInputStreamTest::kTestSampleRate = 44100; | 128 const int CrasInputStreamTest::kTestSampleRate = 44100; |
129 | 129 |
130 TEST_F(CrasInputStreamTest, OpenMono) { | 130 TEST_F(CrasInputStreamTest, OpenMono) { |
131 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO); | 131 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO); |
132 EXPECT_TRUE(test_stream->Open()); | 132 EXPECT_TRUE(test_stream->Open()); |
133 test_stream->Close(); | 133 test_stream->Close(); |
134 } | 134 } |
135 | 135 |
136 TEST_F(CrasInputStreamTest, OpenStereo) { | 136 TEST_F(CrasInputStreamTest, OpenStereo) { |
137 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_STEREO); | 137 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_STEREO); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 TEST_F(CrasInputStreamTest, CaptureLoopback) { | 208 TEST_F(CrasInputStreamTest, CaptureLoopback) { |
209 CrasInputStream* test_stream = CreateStream( | 209 CrasInputStream* test_stream = CreateStream( |
210 CHANNEL_LAYOUT_STEREO, | 210 CHANNEL_LAYOUT_STEREO, |
211 kTestFramesPerPacket, | 211 kTestFramesPerPacket, |
212 AudioManagerBase::kLoopbackInputDeviceId); | 212 AudioManagerBase::kLoopbackInputDeviceId); |
213 EXPECT_TRUE(test_stream->Open()); | 213 EXPECT_TRUE(test_stream->Open()); |
214 test_stream->Close(); | 214 test_stream->Close(); |
215 } | 215 } |
216 | 216 |
217 } // namespace media | 217 } // namespace media |
OLD | NEW |