Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: media/audio/cras/cras_input_unittest.cc

Issue 1892433002: Moving device description utils from AudioManager[Base] into AudioDeviceDescription; to be shared b… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/cras/cras_input.cc ('k') | media/audio/mac/audio_low_latency_input_mac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/thread_task_runner_handle.h" 15 #include "base/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/cras/audio_manager_cras.h" 18 #include "media/audio/cras/audio_manager_cras.h"
18 #include "media/audio/fake_audio_log_factory.h" 19 #include "media/audio/fake_audio_log_factory.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 // cras_util.h defines custom min/max macros which break compilation, so ensure 23 // cras_util.h defines custom min/max macros which break compilation, so ensure
23 // it's not included until last. #if avoids presubmit errors. 24 // it's not included until last. #if avoids presubmit errors.
24 #if defined(USE_CRAS) 25 #if defined(USE_CRAS)
25 #include "media/audio/cras/cras_input.h" 26 #include "media/audio/cras/cras_input.h"
26 #endif 27 #endif
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 ~CrasInputStreamTest() override {} 71 ~CrasInputStreamTest() override {}
71 72
72 CrasInputStream* CreateStream(ChannelLayout layout) { 73 CrasInputStream* CreateStream(ChannelLayout layout) {
73 return CreateStream(layout, kTestFramesPerPacket); 74 return CreateStream(layout, kTestFramesPerPacket);
74 } 75 }
75 76
76 CrasInputStream* CreateStream(ChannelLayout layout, 77 CrasInputStream* CreateStream(ChannelLayout layout,
77 int32_t samples_per_packet) { 78 int32_t samples_per_packet) {
78 return CreateStream(layout, samples_per_packet, 79 return CreateStream(layout, samples_per_packet,
79 AudioManagerBase::kDefaultDeviceId); 80 AudioDeviceDescription::kDefaultDeviceId);
80 } 81 }
81 82
82 CrasInputStream* CreateStream(ChannelLayout layout, 83 CrasInputStream* CreateStream(ChannelLayout layout,
83 int32_t samples_per_packet, 84 int32_t samples_per_packet,
84 const std::string& device_id) { 85 const std::string& device_id) {
85 AudioParameters params(kTestFormat, 86 AudioParameters params(kTestFormat,
86 layout, 87 layout,
87 kTestSampleRate, 88 kTestSampleRate,
88 kTestBitsPerSample, 89 kTestBitsPerSample,
89 samples_per_packet); 90 samples_per_packet);
90 return new CrasInputStream(params, mock_manager_.get(), device_id); 91 return new CrasInputStream(params, mock_manager_.get(), device_id);
91 } 92 }
92 93
93 void CaptureSomeFrames(const AudioParameters &params, 94 void CaptureSomeFrames(const AudioParameters &params,
94 unsigned int duration_ms) { 95 unsigned int duration_ms) {
95 CrasInputStream* test_stream = new CrasInputStream( 96 CrasInputStream* test_stream = new CrasInputStream(
96 params, mock_manager_.get(), AudioManagerBase::kDefaultDeviceId); 97 params, mock_manager_.get(), AudioDeviceDescription::kDefaultDeviceId);
97 98
98 ASSERT_TRUE(test_stream->Open()); 99 ASSERT_TRUE(test_stream->Open());
99 100
100 // Allow 8 frames variance for SRC in the callback. Different numbers of 101 // Allow 8 frames variance for SRC in the callback. Different numbers of
101 // samples can be provided when doing non-integer SRC. For example 102 // samples can be provided when doing non-integer SRC. For example
102 // converting from 192k to 44.1k is a ratio of 4.35 to 1. 103 // converting from 192k to 44.1k is a ratio of 4.35 to 1.
103 MockAudioInputCallback mock_callback; 104 MockAudioInputCallback mock_callback;
104 base::WaitableEvent event(false, false); 105 base::WaitableEvent event(false, false);
105 106
106 EXPECT_CALL(mock_callback, OnData(test_stream, _, _, _)) 107 EXPECT_CALL(mock_callback, OnData(test_stream, _, _, _))
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 EXPECT_TRUE(test_stream->Open()); 151 EXPECT_TRUE(test_stream->Open());
151 test_stream->Close(); 152 test_stream->Close();
152 } 153 }
153 154
154 TEST_F(CrasInputStreamTest, BadBitsPerSample) { 155 TEST_F(CrasInputStreamTest, BadBitsPerSample) {
155 AudioParameters bad_bps_params(kTestFormat, 156 AudioParameters bad_bps_params(kTestFormat,
156 kTestChannelLayout, 157 kTestChannelLayout,
157 kTestSampleRate, 158 kTestSampleRate,
158 kTestBitsPerSample - 1, 159 kTestBitsPerSample - 1,
159 kTestFramesPerPacket); 160 kTestFramesPerPacket);
160 CrasInputStream* test_stream = new CrasInputStream( 161 CrasInputStream* test_stream =
161 bad_bps_params, mock_manager_.get(), AudioManagerBase::kDefaultDeviceId); 162 new CrasInputStream(bad_bps_params, mock_manager_.get(),
163 AudioDeviceDescription::kDefaultDeviceId);
162 EXPECT_FALSE(test_stream->Open()); 164 EXPECT_FALSE(test_stream->Open());
163 test_stream->Close(); 165 test_stream->Close();
164 } 166 }
165 167
166 TEST_F(CrasInputStreamTest, BadSampleRate) { 168 TEST_F(CrasInputStreamTest, BadSampleRate) {
167 AudioParameters bad_rate_params(kTestFormat, 169 AudioParameters bad_rate_params(kTestFormat,
168 kTestChannelLayout, 170 kTestChannelLayout,
169 0, 171 0,
170 kTestBitsPerSample, 172 kTestBitsPerSample,
171 kTestFramesPerPacket); 173 kTestFramesPerPacket);
172 CrasInputStream* test_stream = new CrasInputStream( 174 CrasInputStream* test_stream =
173 bad_rate_params, mock_manager_.get(), AudioManagerBase::kDefaultDeviceId); 175 new CrasInputStream(bad_rate_params, mock_manager_.get(),
176 AudioDeviceDescription::kDefaultDeviceId);
174 EXPECT_FALSE(test_stream->Open()); 177 EXPECT_FALSE(test_stream->Open());
175 test_stream->Close(); 178 test_stream->Close();
176 } 179 }
177 180
178 TEST_F(CrasInputStreamTest, SetGetVolume) { 181 TEST_F(CrasInputStreamTest, SetGetVolume) {
179 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO); 182 CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
180 EXPECT_TRUE(test_stream->Open()); 183 EXPECT_TRUE(test_stream->Open());
181 184
182 double max_volume = test_stream->GetMaxVolume(); 185 double max_volume = test_stream->GetMaxVolume();
183 EXPECT_GE(max_volume, 1.0); 186 EXPECT_GE(max_volume, 1.0);
(...skipping 27 matching lines...) Expand all
211 AudioParameters params_stereo(kTestFormat, 214 AudioParameters params_stereo(kTestFormat,
212 CHANNEL_LAYOUT_STEREO, 215 CHANNEL_LAYOUT_STEREO,
213 rates[i], 216 rates[i],
214 kTestBitsPerSample, 217 kTestBitsPerSample,
215 kTestFramesPerPacket); 218 kTestFramesPerPacket);
216 CaptureSomeFrames(params_stereo, kTestCaptureDurationMs); 219 CaptureSomeFrames(params_stereo, kTestCaptureDurationMs);
217 } 220 }
218 } 221 }
219 222
220 TEST_F(CrasInputStreamTest, CaptureLoopback) { 223 TEST_F(CrasInputStreamTest, CaptureLoopback) {
221 CrasInputStream* test_stream = CreateStream( 224 CrasInputStream* test_stream =
222 CHANNEL_LAYOUT_STEREO, 225 CreateStream(CHANNEL_LAYOUT_STEREO, kTestFramesPerPacket,
223 kTestFramesPerPacket, 226 AudioDeviceDescription::kLoopbackInputDeviceId);
224 AudioManagerBase::kLoopbackInputDeviceId);
225 EXPECT_TRUE(test_stream->Open()); 227 EXPECT_TRUE(test_stream->Open());
226 test_stream->Close(); 228 test_stream->Close();
227 } 229 }
228 230
229 } // namespace media 231 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cras/cras_input.cc ('k') | media/audio/mac/audio_low_latency_input_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698