OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 <algorithm> | 11 #include <algorithm> |
12 #include <limits> | 12 #include <limits> |
13 #include <list> | 13 #include <list> |
| 14 #include <memory> |
14 #include <numeric> | 15 #include <numeric> |
15 #include <string> | 16 #include <string> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "webrtc/base/arraysize.h" | 21 #include "webrtc/base/arraysize.h" |
21 #include "webrtc/base/criticalsection.h" | 22 #include "webrtc/base/criticalsection.h" |
22 #include "webrtc/base/format_macros.h" | 23 #include "webrtc/base/format_macros.h" |
23 #include "webrtc/base/logging.h" | 24 #include "webrtc/base/logging.h" |
24 #include "webrtc/base/scoped_ptr.h" | |
25 #include "webrtc/base/scoped_ref_ptr.h" | 25 #include "webrtc/base/scoped_ref_ptr.h" |
26 #include "webrtc/modules/audio_device/audio_device_impl.h" | 26 #include "webrtc/modules/audio_device/audio_device_impl.h" |
27 #include "webrtc/modules/audio_device/include/audio_device.h" | 27 #include "webrtc/modules/audio_device/include/audio_device.h" |
28 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" | 28 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" |
29 #include "webrtc/system_wrappers/include/clock.h" | 29 #include "webrtc/system_wrappers/include/clock.h" |
30 #include "webrtc/system_wrappers/include/event_wrapper.h" | 30 #include "webrtc/system_wrappers/include/event_wrapper.h" |
31 #include "webrtc/system_wrappers/include/sleep.h" | 31 #include "webrtc/system_wrappers/include/sleep.h" |
32 #include "webrtc/test/testsupport/fileutils.h" | 32 #include "webrtc/test/testsupport/fileutils.h" |
33 | 33 |
34 using std::cout; | 34 using std::cout; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return static_cast<int>( | 138 return static_cast<int>( |
139 file_size_in_bytes_ / (kBytesPerSample * sample_rate_)); | 139 file_size_in_bytes_ / (kBytesPerSample * sample_rate_)); |
140 } | 140 } |
141 size_t file_size_in_callbacks() const { | 141 size_t file_size_in_callbacks() const { |
142 return file_size_in_seconds() * kNumCallbacksPerSecond; | 142 return file_size_in_seconds() * kNumCallbacksPerSecond; |
143 } | 143 } |
144 | 144 |
145 private: | 145 private: |
146 size_t file_size_in_bytes_; | 146 size_t file_size_in_bytes_; |
147 int sample_rate_; | 147 int sample_rate_; |
148 rtc::scoped_ptr<int16_t[]> file_; | 148 std::unique_ptr<int16_t[]> file_; |
149 size_t file_pos_; | 149 size_t file_pos_; |
150 }; | 150 }; |
151 | 151 |
152 // Simple first in first out (FIFO) class that wraps a list of 16-bit audio | 152 // Simple first in first out (FIFO) class that wraps a list of 16-bit audio |
153 // buffers of fixed size and allows Write and Read operations. The idea is to | 153 // buffers of fixed size and allows Write and Read operations. The idea is to |
154 // store recorded audio buffers (using Write) and then read (using Read) these | 154 // store recorded audio buffers (using Write) and then read (using Read) these |
155 // stored buffers with as short delay as possible when the audio layer needs | 155 // stored buffers with as short delay as possible when the audio layer needs |
156 // data to play out. The number of buffers in the FIFO will stabilize under | 156 // data to play out. The number of buffers in the FIFO will stabilize under |
157 // normal conditions since there will be a balance between Write and Read calls. | 157 // normal conditions since there will be a balance between Write and Read calls. |
158 // The container is a std::list container and access is protected with a lock | 158 // The container is a std::list container and access is protected with a lock |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 for (auto it = fifo_->begin(); it != fifo_->end(); ++it) { | 226 for (auto it = fifo_->begin(); it != fifo_->end(); ++it) { |
227 delete *it; | 227 delete *it; |
228 } | 228 } |
229 fifo_->clear(); | 229 fifo_->clear(); |
230 } | 230 } |
231 | 231 |
232 using AudioBufferList = std::list<int16_t*>; | 232 using AudioBufferList = std::list<int16_t*>; |
233 rtc::CriticalSection lock_; | 233 rtc::CriticalSection lock_; |
234 const size_t frames_per_buffer_; | 234 const size_t frames_per_buffer_; |
235 const size_t bytes_per_buffer_; | 235 const size_t bytes_per_buffer_; |
236 rtc::scoped_ptr<AudioBufferList> fifo_; | 236 std::unique_ptr<AudioBufferList> fifo_; |
237 size_t largest_size_; | 237 size_t largest_size_; |
238 size_t total_written_elements_; | 238 size_t total_written_elements_; |
239 size_t write_count_; | 239 size_t write_count_; |
240 }; | 240 }; |
241 | 241 |
242 // Inserts periodic impulses and measures the latency between the time of | 242 // Inserts periodic impulses and measures the latency between the time of |
243 // transmission and time of receiving the same impulse. | 243 // transmission and time of receiving the same impulse. |
244 // Usage requires a special hardware called Audio Loopback Dongle. | 244 // Usage requires a special hardware called Audio Loopback Dongle. |
245 // See http://source.android.com/devices/audio/loopback.html for details. | 245 // See http://source.android.com/devices/audio/loopback.html for details. |
246 class LatencyMeasuringAudioStream : public AudioStreamInterface { | 246 class LatencyMeasuringAudioStream : public AudioStreamInterface { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 EXPECT_TRUE(audio_device()->RecordingIsInitialized()); | 586 EXPECT_TRUE(audio_device()->RecordingIsInitialized()); |
587 EXPECT_EQ(0, audio_device()->StartRecording()); | 587 EXPECT_EQ(0, audio_device()->StartRecording()); |
588 EXPECT_TRUE(audio_device()->Recording()); | 588 EXPECT_TRUE(audio_device()->Recording()); |
589 } | 589 } |
590 | 590 |
591 void StopRecording() { | 591 void StopRecording() { |
592 EXPECT_EQ(0, audio_device()->StopRecording()); | 592 EXPECT_EQ(0, audio_device()->StopRecording()); |
593 EXPECT_FALSE(audio_device()->Recording()); | 593 EXPECT_FALSE(audio_device()->Recording()); |
594 } | 594 } |
595 | 595 |
596 rtc::scoped_ptr<EventWrapper> test_is_done_; | 596 std::unique_ptr<EventWrapper> test_is_done_; |
597 rtc::scoped_refptr<AudioDeviceModule> audio_device_; | 597 rtc::scoped_refptr<AudioDeviceModule> audio_device_; |
598 AudioParameters playout_parameters_; | 598 AudioParameters playout_parameters_; |
599 AudioParameters record_parameters_; | 599 AudioParameters record_parameters_; |
600 rtc::LoggingSeverity old_sev_; | 600 rtc::LoggingSeverity old_sev_; |
601 }; | 601 }; |
602 | 602 |
603 TEST_F(AudioDeviceTest, ConstructDestruct) { | 603 TEST_F(AudioDeviceTest, ConstructDestruct) { |
604 // Using the test fixture to create and destruct the audio device module. | 604 // Using the test fixture to create and destruct the audio device module. |
605 } | 605 } |
606 | 606 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 | 754 |
755 // Start playout and read audio from an external PCM file when the audio layer | 755 // Start playout and read audio from an external PCM file when the audio layer |
756 // asks for data to play out. Real audio is played out in this test but it does | 756 // asks for data to play out. Real audio is played out in this test but it does |
757 // not contain any explicit verification that the audio quality is perfect. | 757 // not contain any explicit verification that the audio quality is perfect. |
758 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) { | 758 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) { |
759 // TODO(henrika): extend test when mono output is supported. | 759 // TODO(henrika): extend test when mono output is supported. |
760 EXPECT_EQ(1, playout_channels()); | 760 EXPECT_EQ(1, playout_channels()); |
761 NiceMock<MockAudioTransport> mock(kPlayout); | 761 NiceMock<MockAudioTransport> mock(kPlayout); |
762 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond; | 762 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond; |
763 std::string file_name = GetFileName(playout_sample_rate()); | 763 std::string file_name = GetFileName(playout_sample_rate()); |
764 rtc::scoped_ptr<FileAudioStream> file_audio_stream( | 764 std::unique_ptr<FileAudioStream> file_audio_stream( |
765 new FileAudioStream(num_callbacks, file_name, playout_sample_rate())); | 765 new FileAudioStream(num_callbacks, file_name, playout_sample_rate())); |
766 mock.HandleCallbacks(test_is_done_.get(), file_audio_stream.get(), | 766 mock.HandleCallbacks(test_is_done_.get(), file_audio_stream.get(), |
767 num_callbacks); | 767 num_callbacks); |
768 // SetMaxPlayoutVolume(); | 768 // SetMaxPlayoutVolume(); |
769 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 769 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
770 StartPlayout(); | 770 StartPlayout(); |
771 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 771 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
772 StopPlayout(); | 772 StopPlayout(); |
773 } | 773 } |
774 | 774 |
(...skipping 13 matching lines...) Expand all Loading... |
788 // This test tries to verify that the device maintains a balanced callback- | 788 // This test tries to verify that the device maintains a balanced callback- |
789 // sequence by running in loopback for ten seconds while measuring the size | 789 // sequence by running in loopback for ten seconds while measuring the size |
790 // (max and average) of the FIFO. The size of the FIFO is increased by the | 790 // (max and average) of the FIFO. The size of the FIFO is increased by the |
791 // recording side and decreased by the playout side. | 791 // recording side and decreased by the playout side. |
792 // TODO(henrika): tune the final test parameters after running tests on several | 792 // TODO(henrika): tune the final test parameters after running tests on several |
793 // different devices. | 793 // different devices. |
794 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { | 794 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { |
795 EXPECT_EQ(record_channels(), playout_channels()); | 795 EXPECT_EQ(record_channels(), playout_channels()); |
796 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); | 796 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); |
797 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); | 797 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); |
798 rtc::scoped_ptr<FifoAudioStream> fifo_audio_stream( | 798 std::unique_ptr<FifoAudioStream> fifo_audio_stream( |
799 new FifoAudioStream(playout_frames_per_10ms_buffer())); | 799 new FifoAudioStream(playout_frames_per_10ms_buffer())); |
800 mock.HandleCallbacks(test_is_done_.get(), fifo_audio_stream.get(), | 800 mock.HandleCallbacks(test_is_done_.get(), fifo_audio_stream.get(), |
801 kFullDuplexTimeInSec * kNumCallbacksPerSecond); | 801 kFullDuplexTimeInSec * kNumCallbacksPerSecond); |
802 // SetMaxPlayoutVolume(); | 802 // SetMaxPlayoutVolume(); |
803 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 803 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
804 StartRecording(); | 804 StartRecording(); |
805 StartPlayout(); | 805 StartPlayout(); |
806 test_is_done_->Wait( | 806 test_is_done_->Wait( |
807 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); | 807 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); |
808 StopPlayout(); | 808 StopPlayout(); |
809 StopRecording(); | 809 StopRecording(); |
810 EXPECT_LE(fifo_audio_stream->average_size(), 10u); | 810 EXPECT_LE(fifo_audio_stream->average_size(), 10u); |
811 EXPECT_LE(fifo_audio_stream->largest_size(), 20u); | 811 EXPECT_LE(fifo_audio_stream->largest_size(), 20u); |
812 } | 812 } |
813 | 813 |
814 // Measures loopback latency and reports the min, max and average values for | 814 // Measures loopback latency and reports the min, max and average values for |
815 // a full duplex audio session. | 815 // a full duplex audio session. |
816 // The latency is measured like so: | 816 // The latency is measured like so: |
817 // - Insert impulses periodically on the output side. | 817 // - Insert impulses periodically on the output side. |
818 // - Detect the impulses on the input side. | 818 // - Detect the impulses on the input side. |
819 // - Measure the time difference between the transmit time and receive time. | 819 // - Measure the time difference between the transmit time and receive time. |
820 // - Store time differences in a vector and calculate min, max and average. | 820 // - Store time differences in a vector and calculate min, max and average. |
821 // This test requires a special hardware called Audio Loopback Dongle. | 821 // This test requires a special hardware called Audio Loopback Dongle. |
822 // See http://source.android.com/devices/audio/loopback.html for details. | 822 // See http://source.android.com/devices/audio/loopback.html for details. |
823 TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) { | 823 TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) { |
824 EXPECT_EQ(record_channels(), playout_channels()); | 824 EXPECT_EQ(record_channels(), playout_channels()); |
825 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); | 825 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); |
826 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); | 826 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); |
827 rtc::scoped_ptr<LatencyMeasuringAudioStream> latency_audio_stream( | 827 std::unique_ptr<LatencyMeasuringAudioStream> latency_audio_stream( |
828 new LatencyMeasuringAudioStream(playout_frames_per_10ms_buffer())); | 828 new LatencyMeasuringAudioStream(playout_frames_per_10ms_buffer())); |
829 mock.HandleCallbacks(test_is_done_.get(), latency_audio_stream.get(), | 829 mock.HandleCallbacks(test_is_done_.get(), latency_audio_stream.get(), |
830 kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); | 830 kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); |
831 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 831 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
832 // SetMaxPlayoutVolume(); | 832 // SetMaxPlayoutVolume(); |
833 // DisableBuiltInAECIfAvailable(); | 833 // DisableBuiltInAECIfAvailable(); |
834 StartRecording(); | 834 StartRecording(); |
835 StartPlayout(); | 835 StartPlayout(); |
836 test_is_done_->Wait( | 836 test_is_done_->Wait( |
837 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); | 837 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); |
838 StopPlayout(); | 838 StopPlayout(); |
839 StopRecording(); | 839 StopRecording(); |
840 // Verify that the correct number of transmitted impulses are detected. | 840 // Verify that the correct number of transmitted impulses are detected. |
841 EXPECT_EQ(latency_audio_stream->num_latency_values(), | 841 EXPECT_EQ(latency_audio_stream->num_latency_values(), |
842 static_cast<size_t>( | 842 static_cast<size_t>( |
843 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); | 843 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); |
844 latency_audio_stream->PrintResults(); | 844 latency_audio_stream->PrintResults(); |
845 } | 845 } |
846 | 846 |
847 } // namespace webrtc | 847 } // namespace webrtc |
OLD | NEW |