OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <cstring> | 11 #include <cstring> |
12 | 12 |
13 #include "webrtc/base/array_view.h" | |
14 #include "webrtc/base/criticalsection.h" | |
13 #include "webrtc/base/event.h" | 15 #include "webrtc/base/event.h" |
14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
15 #include "webrtc/base/scoped_ref_ptr.h" | 17 #include "webrtc/base/scoped_ref_ptr.h" |
18 #include "webrtc/base/thread_annotations.h" | |
16 #include "webrtc/modules/audio_device/audio_device_impl.h" | 19 #include "webrtc/modules/audio_device/audio_device_impl.h" |
17 #include "webrtc/modules/audio_device/include/audio_device.h" | 20 #include "webrtc/modules/audio_device/include/audio_device.h" |
18 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" | 21 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" |
19 #include "webrtc/system_wrappers/include/sleep.h" | 22 #include "webrtc/system_wrappers/include/sleep.h" |
20 #include "webrtc/test/gmock.h" | 23 #include "webrtc/test/gmock.h" |
21 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
22 | 25 |
23 using ::testing::_; | 26 using ::testing::_; |
24 using ::testing::AtLeast; | 27 using ::testing::AtLeast; |
25 using ::testing::Ge; | 28 using ::testing::Ge; |
(...skipping 15 matching lines...) Expand all Loading... | |
41 #else | 44 #else |
42 // Or if other audio-related requirements are not met. | 45 // Or if other audio-related requirements are not met. |
43 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ | 46 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ |
44 do { \ | 47 do { \ |
45 return; \ | 48 return; \ |
46 } while (false) | 49 } while (false) |
47 #endif | 50 #endif |
48 | 51 |
49 // Number of callbacks (input or output) the tests waits for before we set | 52 // Number of callbacks (input or output) the tests waits for before we set |
50 // an event indicating that the test was OK. | 53 // an event indicating that the test was OK. |
51 static const size_t kNumCallbacks = 10; | 54 static constexpr size_t kNumCallbacks = 10; |
52 // Max amount of time we wait for an event to be set while counting callbacks. | 55 // Max amount of time we wait for an event to be set while counting callbacks. |
53 static const int kTestTimeOutInMilliseconds = 10 * 1000; | 56 static constexpr int kTestTimeOutInMilliseconds = 10 * 1000; |
57 // Average number of audio callbacks per second assuming 10ms packet size. | |
58 static constexpr size_t kNumCallbacksPerSecond = 100; | |
59 // Run the full-duplex test during this time (unit is in seconds). | |
60 static constexpr int kFullDuplexTimeInSec = 5; | |
54 | 61 |
55 enum class TransportType { | 62 enum class TransportType { |
56 kInvalid, | 63 kInvalid, |
57 kPlay, | 64 kPlay, |
58 kRecord, | 65 kRecord, |
59 kPlayAndRecord, | 66 kPlayAndRecord, |
60 }; | 67 }; |
68 | |
69 // Interface for processing the audio stream. Real implementations can e.g. | |
70 // run audio in loopback, read audio from a file or perform latency | |
71 // measurements. | |
72 class AudioStream { | |
73 public: | |
74 virtual void Write(rtc::ArrayView<const int16_t> source, size_t channels) = 0; | |
75 virtual void Read(rtc::ArrayView<int16_t> destination, size_t channels) = 0; | |
76 | |
77 virtual ~AudioStream() = default; | |
78 }; | |
79 | |
61 } // namespace | 80 } // namespace |
62 | 81 |
82 // Simple first in first out (FIFO) class that wraps a list of 16-bit audio | |
83 // buffers of fixed size and allows Write and Read operations. The idea is to | |
84 // store recorded audio buffers (using Write) and then read (using Read) these | |
85 // stored buffers with as short delay as possible when the audio layer needs | |
86 // data to play out. The number of buffers in the FIFO will stabilize under | |
87 // normal conditions since there will be a balance between Write and Read calls. | |
88 // The container is a std::list container and access is protected with a lock | |
89 // since both sides (playout and recording) are driven by its own thread. | |
90 // Note that, we know by design that the size of the audio buffer will not | |
91 // change over time and that both sides will use the same size. | |
92 class FifoAudioStream : public AudioStream { | |
93 public: | |
94 FifoAudioStream() {} | |
95 virtual ~FifoAudioStream() {} | |
kwiberg-webrtc
2017/04/03 20:44:02
You don't need these two lines. The compiler will
henrika_webrtc
2017/04/04 11:27:29
Acknowledged.
| |
96 | |
97 void Write(rtc::ArrayView<const int16_t> source, size_t channels) override { | |
98 EXPECT_EQ(channels, 1u); | |
99 const size_t samples_per_buffer = source.size() * channels; | |
100 const size_t bytes_per_buffer = sizeof(int16_t) * samples_per_buffer; | |
101 std::unique_ptr<int16_t[]> buffer(new int16_t[source.size()]); | |
102 memcpy(static_cast<int16_t*>(buffer.get()), source.data(), | |
kwiberg-webrtc
2017/04/03 20:44:01
Is the cast necessary?
henrika_webrtc
2017/04/04 11:27:28
no ;-)
| |
103 bytes_per_buffer); | |
kwiberg-webrtc
2017/04/03 20:44:01
If channels were ever != 1, this math would be inc
henrika_webrtc
2017/04/04 11:27:29
Ack. I do check that #channels is one in line 98 b
| |
104 const size_t size = [&] { | |
105 rtc::CritScope lock(&lock_); | |
106 fifo_.push_back(std::move(buffer)); | |
107 return fifo_.size(); | |
108 }(); | |
109 if (size > max_size_) { | |
110 max_size_ = size; | |
111 } | |
112 write_count_++; | |
113 written_elements_ += size; | |
114 } | |
115 | |
116 void Read(rtc::ArrayView<int16_t> destination, size_t channels) override { | |
117 EXPECT_EQ(channels, 1u); | |
118 const size_t bytes_per_buffer = | |
119 sizeof(int16_t) * destination.size() * channels; | |
kwiberg-webrtc
2017/04/03 20:44:02
Same problem here: channels > 1 would lead to out-
henrika_webrtc
2017/04/04 11:27:28
Done.
| |
120 rtc::CritScope lock(&lock_); | |
121 if (fifo_.empty()) { | |
122 memset(destination.data(), 0, bytes_per_buffer); | |
123 } else { | |
124 std::unique_ptr<int16_t[]> memory = std::move(fifo_.front()); | |
125 memcpy(destination.data(), static_cast<int16_t*>(memory.get()), | |
kwiberg-webrtc
2017/04/03 20:44:02
Is the cast necessary?
henrika_webrtc
2017/04/04 11:27:29
no
| |
126 bytes_per_buffer); | |
127 fifo_.pop_front(); | |
128 } | |
129 } | |
130 | |
131 size_t size() const { | |
132 rtc::CritScope lock(&lock_); | |
133 return fifo_.size(); | |
134 } | |
135 | |
136 size_t max_size() const { return max_size_; } | |
137 | |
138 size_t average_size() const { | |
139 return 0.5 + static_cast<float>(written_elements_ / write_count_); | |
140 } | |
141 | |
142 rtc::CriticalSection lock_; | |
143 std::list<std::unique_ptr<int16_t[]>> fifo_ GUARDED_BY(lock_); | |
144 size_t write_count_ = 0; | |
145 size_t max_size_ = 0; | |
146 size_t written_elements_ = 0; | |
kwiberg-webrtc
2017/04/03 20:44:02
I can haz a comment that explains why these three
henrika_webrtc
2017/04/04 11:27:29
Well, they are in fact only accessed on the "Play
| |
147 }; | |
148 | |
63 // Mocks the AudioTransport object and proxies actions for the two callbacks | 149 // Mocks the AudioTransport object and proxies actions for the two callbacks |
64 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations | 150 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations |
65 // of AudioStreamInterface. | 151 // of AudioStreamInterface. |
66 class MockAudioTransport : public test::MockAudioTransport { | 152 class MockAudioTransport : public test::MockAudioTransport { |
67 public: | 153 public: |
68 explicit MockAudioTransport(TransportType type) : type_(type) {} | 154 explicit MockAudioTransport(TransportType type) : type_(type) {} |
69 ~MockAudioTransport() {} | 155 ~MockAudioTransport() {} |
70 | 156 |
71 // Set default actions of the mock object. We are delegating to fake | 157 // Set default actions of the mock object. We are delegating to fake |
72 // implementation where the number of callbacks is counted and an event | 158 // implementation where the number of callbacks is counted and an event |
73 // is set after a certain number of callbacks. Audio parameters are also | 159 // is set after a certain number of callbacks. Audio parameters are also |
74 // checked. | 160 // checked. |
75 void HandleCallbacks(rtc::Event* event, int num_callbacks) { | 161 void HandleCallbacks(rtc::Event* event, |
162 AudioStream* audio_stream, | |
163 int num_callbacks) { | |
76 event_ = event; | 164 event_ = event; |
165 audio_stream_ = audio_stream; | |
77 num_callbacks_ = num_callbacks; | 166 num_callbacks_ = num_callbacks; |
78 if (play_mode()) { | 167 if (play_mode()) { |
79 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) | 168 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) |
80 .WillByDefault( | 169 .WillByDefault( |
81 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); | 170 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); |
82 } | 171 } |
83 if (rec_mode()) { | 172 if (rec_mode()) { |
84 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) | 173 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) |
85 .WillByDefault( | 174 .WillByDefault( |
86 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); | 175 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); |
(...skipping 20 matching lines...) Expand all Loading... | |
107 } else { | 196 } else { |
108 EXPECT_EQ(samples_per_channel, record_parameters_.frames_per_buffer()); | 197 EXPECT_EQ(samples_per_channel, record_parameters_.frames_per_buffer()); |
109 EXPECT_EQ(bytes_per_frame, record_parameters_.GetBytesPerFrame()); | 198 EXPECT_EQ(bytes_per_frame, record_parameters_.GetBytesPerFrame()); |
110 EXPECT_EQ(channels, record_parameters_.channels()); | 199 EXPECT_EQ(channels, record_parameters_.channels()); |
111 EXPECT_EQ(static_cast<int>(sample_rate), | 200 EXPECT_EQ(static_cast<int>(sample_rate), |
112 record_parameters_.sample_rate()); | 201 record_parameters_.sample_rate()); |
113 EXPECT_EQ(samples_per_channel, | 202 EXPECT_EQ(samples_per_channel, |
114 record_parameters_.frames_per_10ms_buffer()); | 203 record_parameters_.frames_per_10ms_buffer()); |
115 } | 204 } |
116 rec_count_++; | 205 rec_count_++; |
206 // Write audio data to audio stream object if one has been injected. | |
207 if (audio_stream_) { | |
208 audio_stream_->Write( | |
209 rtc::ArrayView<const int16_t>( | |
210 static_cast<const int16_t*>(audio_buffer), samples_per_channel), | |
211 channels); | |
kwiberg-webrtc
2017/04/03 20:44:02
You have the same problem here if channels != 1. T
henrika_webrtc
2017/04/04 11:27:28
Done.
| |
212 } | |
117 // Signal the event after given amount of callbacks. | 213 // Signal the event after given amount of callbacks. |
118 if (ReceivedEnoughCallbacks()) { | 214 if (ReceivedEnoughCallbacks()) { |
119 event_->Set(); | 215 event_->Set(); |
120 } | 216 } |
121 return 0; | 217 return 0; |
122 } | 218 } |
123 | 219 |
124 int32_t RealNeedMorePlayData(const size_t samples_per_channel, | 220 int32_t RealNeedMorePlayData(const size_t samples_per_channel, |
125 const size_t bytes_per_frame, | 221 const size_t bytes_per_frame, |
126 const size_t channels, | 222 const size_t channels, |
(...skipping 13 matching lines...) Expand all Loading... | |
140 EXPECT_EQ(samples_per_channel, playout_parameters_.frames_per_buffer()); | 236 EXPECT_EQ(samples_per_channel, playout_parameters_.frames_per_buffer()); |
141 EXPECT_EQ(bytes_per_frame, playout_parameters_.GetBytesPerFrame()); | 237 EXPECT_EQ(bytes_per_frame, playout_parameters_.GetBytesPerFrame()); |
142 EXPECT_EQ(channels, playout_parameters_.channels()); | 238 EXPECT_EQ(channels, playout_parameters_.channels()); |
143 EXPECT_EQ(static_cast<int>(sample_rate), | 239 EXPECT_EQ(static_cast<int>(sample_rate), |
144 playout_parameters_.sample_rate()); | 240 playout_parameters_.sample_rate()); |
145 EXPECT_EQ(samples_per_channel, | 241 EXPECT_EQ(samples_per_channel, |
146 playout_parameters_.frames_per_10ms_buffer()); | 242 playout_parameters_.frames_per_10ms_buffer()); |
147 } | 243 } |
148 play_count_++; | 244 play_count_++; |
149 samples_per_channel_out = samples_per_channel; | 245 samples_per_channel_out = samples_per_channel; |
150 // Fill the audio buffer with zeros to avoid disturbing audio. | 246 // Read audio data from audio stream object if one has been injected. |
151 const size_t num_bytes = samples_per_channel * bytes_per_frame; | 247 if (audio_stream_) { |
152 std::memset(audio_buffer, 0, num_bytes); | 248 audio_stream_->Read( |
249 rtc::ArrayView<int16_t>(static_cast<int16_t*>(audio_buffer), | |
250 samples_per_channel), | |
251 channels); | |
kwiberg-webrtc
2017/04/03 20:44:02
And here.
henrika_webrtc
2017/04/04 11:27:29
Done.
| |
252 } else { | |
253 // Fill the audio buffer with zeros to avoid disturbing audio. | |
254 const size_t num_bytes = samples_per_channel * bytes_per_frame; | |
255 std::memset(audio_buffer, 0, num_bytes); | |
256 } | |
153 // Signal the event after given amount of callbacks. | 257 // Signal the event after given amount of callbacks. |
154 if (ReceivedEnoughCallbacks()) { | 258 if (ReceivedEnoughCallbacks()) { |
155 event_->Set(); | 259 event_->Set(); |
156 } | 260 } |
157 return 0; | 261 return 0; |
158 } | 262 } |
159 | 263 |
160 bool ReceivedEnoughCallbacks() { | 264 bool ReceivedEnoughCallbacks() { |
161 bool recording_done = false; | 265 bool recording_done = false; |
162 if (rec_mode()) { | 266 if (rec_mode()) { |
(...skipping 16 matching lines...) Expand all Loading... | |
179 } | 283 } |
180 | 284 |
181 bool rec_mode() const { | 285 bool rec_mode() const { |
182 return type_ == TransportType::kRecord || | 286 return type_ == TransportType::kRecord || |
183 type_ == TransportType::kPlayAndRecord; | 287 type_ == TransportType::kPlayAndRecord; |
184 } | 288 } |
185 | 289 |
186 private: | 290 private: |
187 TransportType type_ = TransportType::kInvalid; | 291 TransportType type_ = TransportType::kInvalid; |
188 rtc::Event* event_ = nullptr; | 292 rtc::Event* event_ = nullptr; |
293 AudioStream* audio_stream_ = nullptr; | |
189 size_t num_callbacks_ = 0; | 294 size_t num_callbacks_ = 0; |
190 size_t play_count_ = 0; | 295 size_t play_count_ = 0; |
191 size_t rec_count_ = 0; | 296 size_t rec_count_ = 0; |
192 AudioParameters playout_parameters_; | 297 AudioParameters playout_parameters_; |
193 AudioParameters record_parameters_; | 298 AudioParameters record_parameters_; |
194 }; | 299 }; |
195 | 300 |
196 // AudioDeviceTest test fixture. | 301 // AudioDeviceTest test fixture. |
197 class AudioDeviceTest : public ::testing::Test { | 302 class AudioDeviceTest : public ::testing::Test { |
198 protected: | 303 protected: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 } | 422 } |
318 | 423 |
319 // Start playout and verify that the native audio layer starts asking for real | 424 // Start playout and verify that the native audio layer starts asking for real |
320 // audio samples to play out using the NeedMorePlayData() callback. | 425 // audio samples to play out using the NeedMorePlayData() callback. |
321 // Note that we can't add expectations on audio parameters in EXPECT_CALL | 426 // Note that we can't add expectations on audio parameters in EXPECT_CALL |
322 // since parameter are not provided in the each callback. We therefore test and | 427 // since parameter are not provided in the each callback. We therefore test and |
323 // verify the parameters in the fake audio transport implementation instead. | 428 // verify the parameters in the fake audio transport implementation instead. |
324 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { | 429 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { |
325 SKIP_TEST_IF_NOT(requirements_satisfied()); | 430 SKIP_TEST_IF_NOT(requirements_satisfied()); |
326 MockAudioTransport mock(TransportType::kPlay); | 431 MockAudioTransport mock(TransportType::kPlay); |
327 mock.HandleCallbacks(event(), kNumCallbacks); | 432 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
328 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) | 433 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) |
329 .Times(AtLeast(kNumCallbacks)); | 434 .Times(AtLeast(kNumCallbacks)); |
330 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 435 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
331 StartPlayout(); | 436 StartPlayout(); |
332 event()->Wait(kTestTimeOutInMilliseconds); | 437 event()->Wait(kTestTimeOutInMilliseconds); |
333 StopPlayout(); | 438 StopPlayout(); |
334 } | 439 } |
335 | 440 |
336 // Start recording and verify that the native audio layer starts providing real | 441 // Start recording and verify that the native audio layer starts providing real |
337 // audio samples using the RecordedDataIsAvailable() callback. | 442 // audio samples using the RecordedDataIsAvailable() callback. |
338 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { | 443 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { |
339 SKIP_TEST_IF_NOT(requirements_satisfied()); | 444 SKIP_TEST_IF_NOT(requirements_satisfied()); |
340 MockAudioTransport mock(TransportType::kRecord); | 445 MockAudioTransport mock(TransportType::kRecord); |
341 mock.HandleCallbacks(event(), kNumCallbacks); | 446 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
342 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, | 447 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, |
343 false, _)) | 448 false, _)) |
344 .Times(AtLeast(kNumCallbacks)); | 449 .Times(AtLeast(kNumCallbacks)); |
345 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 450 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
346 StartRecording(); | 451 StartRecording(); |
347 event()->Wait(kTestTimeOutInMilliseconds); | 452 event()->Wait(kTestTimeOutInMilliseconds); |
348 StopRecording(); | 453 StopRecording(); |
349 } | 454 } |
350 | 455 |
351 // Start playout and recording (full-duplex audio) and verify that audio is | 456 // Start playout and recording (full-duplex audio) and verify that audio is |
352 // active in both directions. | 457 // active in both directions. |
353 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { | 458 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { |
354 SKIP_TEST_IF_NOT(requirements_satisfied()); | 459 SKIP_TEST_IF_NOT(requirements_satisfied()); |
355 MockAudioTransport mock(TransportType::kPlayAndRecord); | 460 MockAudioTransport mock(TransportType::kPlayAndRecord); |
356 mock.HandleCallbacks(event(), kNumCallbacks); | 461 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
357 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) | 462 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) |
358 .Times(AtLeast(kNumCallbacks)); | 463 .Times(AtLeast(kNumCallbacks)); |
359 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, | 464 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, |
360 false, _)) | 465 false, _)) |
361 .Times(AtLeast(kNumCallbacks)); | 466 .Times(AtLeast(kNumCallbacks)); |
362 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 467 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
363 StartPlayout(); | 468 StartPlayout(); |
364 StartRecording(); | 469 StartRecording(); |
365 event()->Wait(kTestTimeOutInMilliseconds); | 470 event()->Wait(kTestTimeOutInMilliseconds); |
366 StopRecording(); | 471 StopRecording(); |
367 StopPlayout(); | 472 StopPlayout(); |
368 } | 473 } |
369 | 474 |
475 // Start playout and recording and store recorded data in an intermediate FIFO | |
476 // buffer from which the playout side then reads its samples in the same order | |
477 // as they were stored. Under ideal circumstances, a callback sequence would | |
478 // look like: ...+-+-+-+-+-+-+-..., where '+' means 'packet recorded' and '-' | |
479 // means 'packet played'. Under such conditions, the FIFO would contain max 1, | |
480 // with an average somewhere in (0,1) depending on how long the packets are | |
481 // buffered. However, under more realistic conditions, the size | |
482 // of the FIFO will vary more due to an unbalance between the two sides. | |
483 // This test tries to verify that the device maintains a balanced callback- | |
484 // sequence by running in loopback for a few seconds while measuring the size | |
485 // (max and average) of the FIFO. The size of the FIFO is increased by the | |
486 // recording side and decreased by the playout side. | |
487 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { | |
488 SKIP_TEST_IF_NOT(requirements_satisfied()); | |
489 NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord); | |
490 FifoAudioStream audio_stream; | |
491 mock.HandleCallbacks(event(), &audio_stream, | |
492 kFullDuplexTimeInSec * kNumCallbacksPerSecond); | |
493 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | |
494 // Run both sides in mono to make the loopback packet handling less complex. | |
495 EXPECT_EQ(0, audio_device()->SetStereoPlayout(false)); | |
496 EXPECT_EQ(0, audio_device()->SetStereoRecording(false)); | |
497 StartPlayout(); | |
498 StartRecording(); | |
499 event()->Wait( | |
500 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); | |
501 StopRecording(); | |
502 StopPlayout(); | |
503 // This thresholds is set rather high to accomodate differences in hardware | |
504 // in several devices. The main idea is to capture cases where a very large | |
505 // latency is built up. | |
506 EXPECT_LE(audio_stream.average_size(), 5u); | |
507 } | |
508 | |
370 } // namespace webrtc | 509 } // namespace webrtc |
OLD | NEW |