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/buffer.h" |
| 15 #include "webrtc/base/criticalsection.h" |
13 #include "webrtc/base/event.h" | 16 #include "webrtc/base/event.h" |
14 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/race_checker.h" |
15 #include "webrtc/base/scoped_ref_ptr.h" | 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/base/thread_annotations.h" |
16 #include "webrtc/modules/audio_device/audio_device_impl.h" | 21 #include "webrtc/modules/audio_device/audio_device_impl.h" |
17 #include "webrtc/modules/audio_device/include/audio_device.h" | 22 #include "webrtc/modules/audio_device/include/audio_device.h" |
18 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" | 23 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" |
19 #include "webrtc/system_wrappers/include/sleep.h" | 24 #include "webrtc/system_wrappers/include/sleep.h" |
20 #include "webrtc/test/gmock.h" | 25 #include "webrtc/test/gmock.h" |
21 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
22 | 27 |
23 using ::testing::_; | 28 using ::testing::_; |
24 using ::testing::AtLeast; | 29 using ::testing::AtLeast; |
25 using ::testing::Ge; | 30 using ::testing::Ge; |
26 using ::testing::Invoke; | 31 using ::testing::Invoke; |
27 using ::testing::NiceMock; | 32 using ::testing::NiceMock; |
28 using ::testing::NotNull; | 33 using ::testing::NotNull; |
29 | 34 |
30 namespace webrtc { | 35 namespace webrtc { |
31 namespace { | 36 namespace { |
32 | 37 |
| 38 // #define ENABLE_DEBUG_PRINTF |
| 39 #ifdef ENABLE_DEBUG_PRINTF |
| 40 #define PRINTD(...) fprintf(stderr, __VA_ARGS__); |
| 41 #else |
| 42 #define PRINTD(...) ((void)0) |
| 43 #endif |
| 44 #define PRINT(...) fprintf(stderr, __VA_ARGS__); |
| 45 |
33 // Don't run these tests in combination with sanitizers. | 46 // Don't run these tests in combination with sanitizers. |
34 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) | 47 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) |
35 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ | 48 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ |
36 do { \ | 49 do { \ |
37 if (!requirements_satisfied) { \ | 50 if (!requirements_satisfied) { \ |
38 return; \ | 51 return; \ |
39 } \ | 52 } \ |
40 } while (false) | 53 } while (false) |
41 #else | 54 #else |
42 // Or if other audio-related requirements are not met. | 55 // Or if other audio-related requirements are not met. |
43 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ | 56 #define SKIP_TEST_IF_NOT(requirements_satisfied) \ |
44 do { \ | 57 do { \ |
45 return; \ | 58 return; \ |
46 } while (false) | 59 } while (false) |
47 #endif | 60 #endif |
48 | 61 |
49 // Number of callbacks (input or output) the tests waits for before we set | 62 // Number of callbacks (input or output) the tests waits for before we set |
50 // an event indicating that the test was OK. | 63 // an event indicating that the test was OK. |
51 static const size_t kNumCallbacks = 10; | 64 static constexpr size_t kNumCallbacks = 10; |
52 // Max amount of time we wait for an event to be set while counting callbacks. | 65 // Max amount of time we wait for an event to be set while counting callbacks. |
53 static const int kTestTimeOutInMilliseconds = 10 * 1000; | 66 static constexpr int kTestTimeOutInMilliseconds = 10 * 1000; |
| 67 // Average number of audio callbacks per second assuming 10ms packet size. |
| 68 static constexpr size_t kNumCallbacksPerSecond = 100; |
| 69 // Run the full-duplex test during this time (unit is in seconds). |
| 70 static constexpr int kFullDuplexTimeInSec = 5; |
54 | 71 |
55 enum class TransportType { | 72 enum class TransportType { |
56 kInvalid, | 73 kInvalid, |
57 kPlay, | 74 kPlay, |
58 kRecord, | 75 kRecord, |
59 kPlayAndRecord, | 76 kPlayAndRecord, |
60 }; | 77 }; |
| 78 |
| 79 // Interface for processing the audio stream. Real implementations can e.g. |
| 80 // run audio in loopback, read audio from a file or perform latency |
| 81 // measurements. |
| 82 class AudioStream { |
| 83 public: |
| 84 virtual void Write(rtc::ArrayView<const int16_t> source, size_t channels) = 0; |
| 85 virtual void Read(rtc::ArrayView<int16_t> destination, size_t channels) = 0; |
| 86 |
| 87 virtual ~AudioStream() = default; |
| 88 }; |
| 89 |
61 } // namespace | 90 } // namespace |
62 | 91 |
| 92 // Simple first in first out (FIFO) class that wraps a list of 16-bit audio |
| 93 // buffers of fixed size and allows Write and Read operations. The idea is to |
| 94 // store recorded audio buffers (using Write) and then read (using Read) these |
| 95 // stored buffers with as short delay as possible when the audio layer needs |
| 96 // data to play out. The number of buffers in the FIFO will stabilize under |
| 97 // normal conditions since there will be a balance between Write and Read calls. |
| 98 // The container is a std::list container and access is protected with a lock |
| 99 // since both sides (playout and recording) are driven by its own thread. |
| 100 // Note that, we know by design that the size of the audio buffer will not |
| 101 // change over time and that both sides will use the same size. |
| 102 class FifoAudioStream : public AudioStream { |
| 103 public: |
| 104 void Write(rtc::ArrayView<const int16_t> source, size_t channels) override { |
| 105 EXPECT_EQ(channels, 1u); |
| 106 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 107 const size_t size = [&] { |
| 108 rtc::CritScope lock(&lock_); |
| 109 fifo_.push_back(Buffer16(source.data(), source.size())); |
| 110 return fifo_.size(); |
| 111 }(); |
| 112 if (size > max_size_) { |
| 113 max_size_ = size; |
| 114 } |
| 115 // Add marker once per second to signal that audio is active. |
| 116 if (write_count_++ % 100 == 0) { |
| 117 PRINT("."); |
| 118 } |
| 119 written_elements_ += size; |
| 120 } |
| 121 |
| 122 void Read(rtc::ArrayView<int16_t> destination, size_t channels) override { |
| 123 EXPECT_EQ(channels, 1u); |
| 124 rtc::CritScope lock(&lock_); |
| 125 if (fifo_.empty()) { |
| 126 std::fill(destination.begin(), destination.end(), 0); |
| 127 } else { |
| 128 const Buffer16& buffer = fifo_.front(); |
| 129 RTC_CHECK_EQ(buffer.size(), destination.size()); |
| 130 std::copy(buffer.begin(), buffer.end(), destination.begin()); |
| 131 fifo_.pop_front(); |
| 132 } |
| 133 } |
| 134 |
| 135 size_t size() const { |
| 136 rtc::CritScope lock(&lock_); |
| 137 return fifo_.size(); |
| 138 } |
| 139 |
| 140 size_t max_size() const { |
| 141 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 142 return max_size_; |
| 143 } |
| 144 |
| 145 size_t average_size() const { |
| 146 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 147 return 0.5 + static_cast<float>(written_elements_ / write_count_); |
| 148 } |
| 149 |
| 150 using Buffer16 = rtc::BufferT<int16_t>; |
| 151 |
| 152 rtc::CriticalSection lock_; |
| 153 rtc::RaceChecker race_checker_; |
| 154 |
| 155 std::list<Buffer16> fifo_ GUARDED_BY(lock_); |
| 156 size_t write_count_ GUARDED_BY(race_checker_) = 0; |
| 157 size_t max_size_ GUARDED_BY(race_checker_) = 0; |
| 158 size_t written_elements_ GUARDED_BY(race_checker_) = 0; |
| 159 }; |
| 160 |
63 // Mocks the AudioTransport object and proxies actions for the two callbacks | 161 // Mocks the AudioTransport object and proxies actions for the two callbacks |
64 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations | 162 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations |
65 // of AudioStreamInterface. | 163 // of AudioStreamInterface. |
66 class MockAudioTransport : public test::MockAudioTransport { | 164 class MockAudioTransport : public test::MockAudioTransport { |
67 public: | 165 public: |
68 explicit MockAudioTransport(TransportType type) : type_(type) {} | 166 explicit MockAudioTransport(TransportType type) : type_(type) {} |
69 ~MockAudioTransport() {} | 167 ~MockAudioTransport() {} |
70 | 168 |
71 // Set default actions of the mock object. We are delegating to fake | 169 // Set default actions of the mock object. We are delegating to fake |
72 // implementation where the number of callbacks is counted and an event | 170 // implementation where the number of callbacks is counted and an event |
73 // is set after a certain number of callbacks. Audio parameters are also | 171 // is set after a certain number of callbacks. Audio parameters are also |
74 // checked. | 172 // checked. |
75 void HandleCallbacks(rtc::Event* event, int num_callbacks) { | 173 void HandleCallbacks(rtc::Event* event, |
| 174 AudioStream* audio_stream, |
| 175 int num_callbacks) { |
76 event_ = event; | 176 event_ = event; |
| 177 audio_stream_ = audio_stream; |
77 num_callbacks_ = num_callbacks; | 178 num_callbacks_ = num_callbacks; |
78 if (play_mode()) { | 179 if (play_mode()) { |
79 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) | 180 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) |
80 .WillByDefault( | 181 .WillByDefault( |
81 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); | 182 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); |
82 } | 183 } |
83 if (rec_mode()) { | 184 if (rec_mode()) { |
84 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) | 185 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) |
85 .WillByDefault( | 186 .WillByDefault( |
86 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); | 187 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); |
(...skipping 20 matching lines...) Expand all Loading... |
107 } else { | 208 } else { |
108 EXPECT_EQ(samples_per_channel, record_parameters_.frames_per_buffer()); | 209 EXPECT_EQ(samples_per_channel, record_parameters_.frames_per_buffer()); |
109 EXPECT_EQ(bytes_per_frame, record_parameters_.GetBytesPerFrame()); | 210 EXPECT_EQ(bytes_per_frame, record_parameters_.GetBytesPerFrame()); |
110 EXPECT_EQ(channels, record_parameters_.channels()); | 211 EXPECT_EQ(channels, record_parameters_.channels()); |
111 EXPECT_EQ(static_cast<int>(sample_rate), | 212 EXPECT_EQ(static_cast<int>(sample_rate), |
112 record_parameters_.sample_rate()); | 213 record_parameters_.sample_rate()); |
113 EXPECT_EQ(samples_per_channel, | 214 EXPECT_EQ(samples_per_channel, |
114 record_parameters_.frames_per_10ms_buffer()); | 215 record_parameters_.frames_per_10ms_buffer()); |
115 } | 216 } |
116 rec_count_++; | 217 rec_count_++; |
| 218 // Write audio data to audio stream object if one has been injected. |
| 219 if (audio_stream_) { |
| 220 audio_stream_->Write( |
| 221 rtc::MakeArrayView(static_cast<const int16_t*>(audio_buffer), |
| 222 samples_per_channel * channels), |
| 223 channels); |
| 224 } |
117 // Signal the event after given amount of callbacks. | 225 // Signal the event after given amount of callbacks. |
118 if (ReceivedEnoughCallbacks()) { | 226 if (ReceivedEnoughCallbacks()) { |
119 event_->Set(); | 227 event_->Set(); |
120 } | 228 } |
121 return 0; | 229 return 0; |
122 } | 230 } |
123 | 231 |
124 int32_t RealNeedMorePlayData(const size_t samples_per_channel, | 232 int32_t RealNeedMorePlayData(const size_t samples_per_channel, |
125 const size_t bytes_per_frame, | 233 const size_t bytes_per_frame, |
126 const size_t channels, | 234 const size_t channels, |
(...skipping 13 matching lines...) Expand all Loading... |
140 EXPECT_EQ(samples_per_channel, playout_parameters_.frames_per_buffer()); | 248 EXPECT_EQ(samples_per_channel, playout_parameters_.frames_per_buffer()); |
141 EXPECT_EQ(bytes_per_frame, playout_parameters_.GetBytesPerFrame()); | 249 EXPECT_EQ(bytes_per_frame, playout_parameters_.GetBytesPerFrame()); |
142 EXPECT_EQ(channels, playout_parameters_.channels()); | 250 EXPECT_EQ(channels, playout_parameters_.channels()); |
143 EXPECT_EQ(static_cast<int>(sample_rate), | 251 EXPECT_EQ(static_cast<int>(sample_rate), |
144 playout_parameters_.sample_rate()); | 252 playout_parameters_.sample_rate()); |
145 EXPECT_EQ(samples_per_channel, | 253 EXPECT_EQ(samples_per_channel, |
146 playout_parameters_.frames_per_10ms_buffer()); | 254 playout_parameters_.frames_per_10ms_buffer()); |
147 } | 255 } |
148 play_count_++; | 256 play_count_++; |
149 samples_per_channel_out = samples_per_channel; | 257 samples_per_channel_out = samples_per_channel; |
150 // Fill the audio buffer with zeros to avoid disturbing audio. | 258 // Read audio data from audio stream object if one has been injected. |
151 const size_t num_bytes = samples_per_channel * bytes_per_frame; | 259 if (audio_stream_) { |
152 std::memset(audio_buffer, 0, num_bytes); | 260 audio_stream_->Read( |
| 261 rtc::MakeArrayView(static_cast<int16_t*>(audio_buffer), |
| 262 samples_per_channel * channels), |
| 263 channels); |
| 264 } else { |
| 265 // Fill the audio buffer with zeros to avoid disturbing audio. |
| 266 const size_t num_bytes = samples_per_channel * bytes_per_frame; |
| 267 std::memset(audio_buffer, 0, num_bytes); |
| 268 } |
153 // Signal the event after given amount of callbacks. | 269 // Signal the event after given amount of callbacks. |
154 if (ReceivedEnoughCallbacks()) { | 270 if (ReceivedEnoughCallbacks()) { |
155 event_->Set(); | 271 event_->Set(); |
156 } | 272 } |
157 return 0; | 273 return 0; |
158 } | 274 } |
159 | 275 |
160 bool ReceivedEnoughCallbacks() { | 276 bool ReceivedEnoughCallbacks() { |
161 bool recording_done = false; | 277 bool recording_done = false; |
162 if (rec_mode()) { | 278 if (rec_mode()) { |
(...skipping 16 matching lines...) Expand all Loading... |
179 } | 295 } |
180 | 296 |
181 bool rec_mode() const { | 297 bool rec_mode() const { |
182 return type_ == TransportType::kRecord || | 298 return type_ == TransportType::kRecord || |
183 type_ == TransportType::kPlayAndRecord; | 299 type_ == TransportType::kPlayAndRecord; |
184 } | 300 } |
185 | 301 |
186 private: | 302 private: |
187 TransportType type_ = TransportType::kInvalid; | 303 TransportType type_ = TransportType::kInvalid; |
188 rtc::Event* event_ = nullptr; | 304 rtc::Event* event_ = nullptr; |
| 305 AudioStream* audio_stream_ = nullptr; |
189 size_t num_callbacks_ = 0; | 306 size_t num_callbacks_ = 0; |
190 size_t play_count_ = 0; | 307 size_t play_count_ = 0; |
191 size_t rec_count_ = 0; | 308 size_t rec_count_ = 0; |
192 AudioParameters playout_parameters_; | 309 AudioParameters playout_parameters_; |
193 AudioParameters record_parameters_; | 310 AudioParameters record_parameters_; |
194 }; | 311 }; |
195 | 312 |
196 // AudioDeviceTest test fixture. | 313 // AudioDeviceTest test fixture. |
197 class AudioDeviceTest : public ::testing::Test { | 314 class AudioDeviceTest : public ::testing::Test { |
198 protected: | 315 protected: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 434 } |
318 | 435 |
319 // Start playout and verify that the native audio layer starts asking for real | 436 // Start playout and verify that the native audio layer starts asking for real |
320 // audio samples to play out using the NeedMorePlayData() callback. | 437 // audio samples to play out using the NeedMorePlayData() callback. |
321 // Note that we can't add expectations on audio parameters in EXPECT_CALL | 438 // 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 | 439 // since parameter are not provided in the each callback. We therefore test and |
323 // verify the parameters in the fake audio transport implementation instead. | 440 // verify the parameters in the fake audio transport implementation instead. |
324 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { | 441 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { |
325 SKIP_TEST_IF_NOT(requirements_satisfied()); | 442 SKIP_TEST_IF_NOT(requirements_satisfied()); |
326 MockAudioTransport mock(TransportType::kPlay); | 443 MockAudioTransport mock(TransportType::kPlay); |
327 mock.HandleCallbacks(event(), kNumCallbacks); | 444 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
328 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) | 445 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) |
329 .Times(AtLeast(kNumCallbacks)); | 446 .Times(AtLeast(kNumCallbacks)); |
330 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 447 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
331 StartPlayout(); | 448 StartPlayout(); |
332 event()->Wait(kTestTimeOutInMilliseconds); | 449 event()->Wait(kTestTimeOutInMilliseconds); |
333 StopPlayout(); | 450 StopPlayout(); |
334 } | 451 } |
335 | 452 |
336 // Start recording and verify that the native audio layer starts providing real | 453 // Start recording and verify that the native audio layer starts providing real |
337 // audio samples using the RecordedDataIsAvailable() callback. | 454 // audio samples using the RecordedDataIsAvailable() callback. |
338 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { | 455 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { |
339 SKIP_TEST_IF_NOT(requirements_satisfied()); | 456 SKIP_TEST_IF_NOT(requirements_satisfied()); |
340 MockAudioTransport mock(TransportType::kRecord); | 457 MockAudioTransport mock(TransportType::kRecord); |
341 mock.HandleCallbacks(event(), kNumCallbacks); | 458 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
342 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, | 459 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, |
343 false, _)) | 460 false, _)) |
344 .Times(AtLeast(kNumCallbacks)); | 461 .Times(AtLeast(kNumCallbacks)); |
345 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 462 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
346 StartRecording(); | 463 StartRecording(); |
347 event()->Wait(kTestTimeOutInMilliseconds); | 464 event()->Wait(kTestTimeOutInMilliseconds); |
348 StopRecording(); | 465 StopRecording(); |
349 } | 466 } |
350 | 467 |
351 // Start playout and recording (full-duplex audio) and verify that audio is | 468 // Start playout and recording (full-duplex audio) and verify that audio is |
352 // active in both directions. | 469 // active in both directions. |
353 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { | 470 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { |
354 SKIP_TEST_IF_NOT(requirements_satisfied()); | 471 SKIP_TEST_IF_NOT(requirements_satisfied()); |
355 MockAudioTransport mock(TransportType::kPlayAndRecord); | 472 MockAudioTransport mock(TransportType::kPlayAndRecord); |
356 mock.HandleCallbacks(event(), kNumCallbacks); | 473 mock.HandleCallbacks(event(), nullptr, kNumCallbacks); |
357 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) | 474 EXPECT_CALL(mock, NeedMorePlayData(_, _, _, _, NotNull(), _, _, _)) |
358 .Times(AtLeast(kNumCallbacks)); | 475 .Times(AtLeast(kNumCallbacks)); |
359 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, | 476 EXPECT_CALL(mock, RecordedDataIsAvailable(NotNull(), _, _, _, _, Ge(0u), 0, _, |
360 false, _)) | 477 false, _)) |
361 .Times(AtLeast(kNumCallbacks)); | 478 .Times(AtLeast(kNumCallbacks)); |
362 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 479 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
363 StartPlayout(); | 480 StartPlayout(); |
364 StartRecording(); | 481 StartRecording(); |
365 event()->Wait(kTestTimeOutInMilliseconds); | 482 event()->Wait(kTestTimeOutInMilliseconds); |
366 StopRecording(); | 483 StopRecording(); |
367 StopPlayout(); | 484 StopPlayout(); |
368 } | 485 } |
369 | 486 |
| 487 // Start playout and recording and store recorded data in an intermediate FIFO |
| 488 // buffer from which the playout side then reads its samples in the same order |
| 489 // as they were stored. Under ideal circumstances, a callback sequence would |
| 490 // look like: ...+-+-+-+-+-+-+-..., where '+' means 'packet recorded' and '-' |
| 491 // means 'packet played'. Under such conditions, the FIFO would contain max 1, |
| 492 // with an average somewhere in (0,1) depending on how long the packets are |
| 493 // buffered. However, under more realistic conditions, the size |
| 494 // of the FIFO will vary more due to an unbalance between the two sides. |
| 495 // This test tries to verify that the device maintains a balanced callback- |
| 496 // sequence by running in loopback for a few seconds while measuring the size |
| 497 // (max and average) of the FIFO. The size of the FIFO is increased by the |
| 498 // recording side and decreased by the playout side. |
| 499 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { |
| 500 SKIP_TEST_IF_NOT(requirements_satisfied()); |
| 501 NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord); |
| 502 FifoAudioStream audio_stream; |
| 503 mock.HandleCallbacks(event(), &audio_stream, |
| 504 kFullDuplexTimeInSec * kNumCallbacksPerSecond); |
| 505 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
| 506 // Run both sides in mono to make the loopback packet handling less complex. |
| 507 // The test works for stereo as well; the only requirement is that both sides |
| 508 // use the same configuration. |
| 509 EXPECT_EQ(0, audio_device()->SetStereoPlayout(false)); |
| 510 EXPECT_EQ(0, audio_device()->SetStereoRecording(false)); |
| 511 StartPlayout(); |
| 512 StartRecording(); |
| 513 event()->Wait( |
| 514 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); |
| 515 StopRecording(); |
| 516 StopPlayout(); |
| 517 // This thresholds is set rather high to accommodate differences in hardware |
| 518 // in several devices. The main idea is to capture cases where a very large |
| 519 // latency is built up. |
| 520 EXPECT_LE(audio_stream.average_size(), 5u); |
| 521 PRINT("\n"); |
| 522 } |
| 523 |
370 } // namespace webrtc | 524 } // namespace webrtc |
OLD | NEW |