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

Side by Side Diff: webrtc/modules/audio_device/android/audio_device_unittest.cc

Issue 2119633004: Adds support for OpenSL ES based audio capture on Android (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing presubmit warnings Created 4 years, 3 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
OLDNEW
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
(...skipping 24 matching lines...) Expand all
35 35
36 using std::cout; 36 using std::cout;
37 using std::endl; 37 using std::endl;
38 using ::testing::_; 38 using ::testing::_;
39 using ::testing::AtLeast; 39 using ::testing::AtLeast;
40 using ::testing::Gt; 40 using ::testing::Gt;
41 using ::testing::Invoke; 41 using ::testing::Invoke;
42 using ::testing::NiceMock; 42 using ::testing::NiceMock;
43 using ::testing::NotNull; 43 using ::testing::NotNull;
44 using ::testing::Return; 44 using ::testing::Return;
45 using ::testing::TestWithParam;
46 45
47 // #define ENABLE_DEBUG_PRINTF 46 // #define ENABLE_DEBUG_PRINTF
48 #ifdef ENABLE_DEBUG_PRINTF 47 #ifdef ENABLE_DEBUG_PRINTF
49 #define PRINTD(...) fprintf(stderr, __VA_ARGS__); 48 #define PRINTD(...) fprintf(stderr, __VA_ARGS__);
50 #else 49 #else
51 #define PRINTD(...) ((void)0) 50 #define PRINTD(...) ((void)0)
52 #endif 51 #endif
53 #define PRINT(...) fprintf(stderr, __VA_ARGS__); 52 #define PRINT(...) fprintf(stderr, __VA_ARGS__);
54 53
55 namespace webrtc { 54 namespace webrtc {
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 AudioParameters record_parameters_; 711 AudioParameters record_parameters_;
713 std::unique_ptr<BuildInfo> build_info_; 712 std::unique_ptr<BuildInfo> build_info_;
714 }; 713 };
715 714
716 TEST_F(AudioDeviceTest, ConstructDestruct) { 715 TEST_F(AudioDeviceTest, ConstructDestruct) {
717 // Using the test fixture to create and destruct the audio device module. 716 // Using the test fixture to create and destruct the audio device module.
718 } 717 }
719 718
720 // We always ask for a default audio layer when the ADM is constructed. But the 719 // We always ask for a default audio layer when the ADM is constructed. But the
721 // ADM will then internally set the best suitable combination of audio layers, 720 // ADM will then internally set the best suitable combination of audio layers,
722 // for input and output based on if low-latency output audio in combination 721 // for input and output based on if low-latency output and/or input audio in
723 // with OpenSL ES is supported or not. This test ensures that the correct 722 // combination with OpenSL ES is supported or not. This test ensures that the
724 // selection is done. 723 // correct selection is done.
725 TEST_F(AudioDeviceTest, VerifyDefaultAudioLayer) { 724 TEST_F(AudioDeviceTest, VerifyDefaultAudioLayer) {
726 const AudioDeviceModule::AudioLayer audio_layer = GetActiveAudioLayer(); 725 const AudioDeviceModule::AudioLayer audio_layer = GetActiveAudioLayer();
727 bool low_latency_output = audio_manager()->IsLowLatencyPlayoutSupported(); 726 bool low_latency_output = audio_manager()->IsLowLatencyPlayoutSupported();
728 AudioDeviceModule::AudioLayer expected_audio_layer = low_latency_output ? 727 bool low_latency_input = audio_manager()->IsLowLatencyRecordSupported();
729 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio : 728 AudioDeviceModule::AudioLayer expected_audio_layer;
730 AudioDeviceModule::kAndroidJavaAudio; 729 if (low_latency_output && low_latency_input) {
730 expected_audio_layer = AudioDeviceModule::kAndroidOpenSLESAudio;
731 } else if (low_latency_output && !low_latency_input) {
732 expected_audio_layer =
733 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio;
734 } else {
735 expected_audio_layer = AudioDeviceModule::kAndroidJavaAudio;
736 }
731 EXPECT_EQ(expected_audio_layer, audio_layer); 737 EXPECT_EQ(expected_audio_layer, audio_layer);
732 } 738 }
733 739
734 // Verify that it is possible to explicitly create the two types of supported 740 // Verify that it is possible to explicitly create the two types of supported
735 // ADMs. These two tests overrides the default selection of native audio layer 741 // ADMs. These two tests overrides the default selection of native audio layer
736 // by ignoring if the device supports low-latency output or not. 742 // by ignoring if the device supports low-latency output or not.
737 TEST_F(AudioDeviceTest, CorrectAudioLayerIsUsedForCombinedJavaOpenSLCombo) { 743 TEST_F(AudioDeviceTest, CorrectAudioLayerIsUsedForCombinedJavaOpenSLCombo) {
738 AudioDeviceModule::AudioLayer expected_layer = 744 AudioDeviceModule::AudioLayer expected_layer =
739 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio; 745 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio;
740 AudioDeviceModule::AudioLayer active_layer = TestActiveAudioLayer( 746 AudioDeviceModule::AudioLayer active_layer = TestActiveAudioLayer(
741 expected_layer); 747 expected_layer);
742 EXPECT_EQ(expected_layer, active_layer); 748 EXPECT_EQ(expected_layer, active_layer);
743 } 749 }
744 750
745 TEST_F(AudioDeviceTest, CorrectAudioLayerIsUsedForJavaInBothDirections) { 751 TEST_F(AudioDeviceTest, CorrectAudioLayerIsUsedForJavaInBothDirections) {
746 AudioDeviceModule::AudioLayer expected_layer = 752 AudioDeviceModule::AudioLayer expected_layer =
747 AudioDeviceModule::kAndroidJavaAudio; 753 AudioDeviceModule::kAndroidJavaAudio;
748 AudioDeviceModule::AudioLayer active_layer = TestActiveAudioLayer( 754 AudioDeviceModule::AudioLayer active_layer = TestActiveAudioLayer(
749 expected_layer); 755 expected_layer);
750 EXPECT_EQ(expected_layer, active_layer); 756 EXPECT_EQ(expected_layer, active_layer);
751 } 757 }
752 758
759 TEST_F(AudioDeviceTest, CorrectAudioLayerIsUsedForOpenSLInBothDirections) {
760 AudioDeviceModule::AudioLayer expected_layer =
761 AudioDeviceModule::kAndroidOpenSLESAudio;
762 AudioDeviceModule::AudioLayer active_layer =
763 TestActiveAudioLayer(expected_layer);
764 EXPECT_EQ(expected_layer, active_layer);
765 }
766
753 // The Android ADM supports two different delay reporting modes. One for the 767 // The Android ADM supports two different delay reporting modes. One for the
754 // low-latency output path (in combination with OpenSL ES), and one for the 768 // low-latency output path (in combination with OpenSL ES), and one for the
755 // high-latency output path (Java backends in both directions). These two tests 769 // high-latency output path (Java backends in both directions). These two tests
756 // verifies that the audio manager reports correct delay estimate given the 770 // verifies that the audio manager reports correct delay estimate given the
757 // selected audio layer. Note that, this delay estimate will only be utilized 771 // selected audio layer. Note that, this delay estimate will only be utilized
758 // if the HW AEC is disabled. 772 // if the HW AEC is disabled.
759 TEST_F(AudioDeviceTest, UsesCorrectDelayEstimateForHighLatencyOutputPath) { 773 TEST_F(AudioDeviceTest, UsesCorrectDelayEstimateForHighLatencyOutputPath) {
760 EXPECT_EQ(kHighLatencyModeDelayEstimateInMilliseconds, 774 EXPECT_EQ(kHighLatencyModeDelayEstimateInMilliseconds,
761 TestDelayOnAudioLayer(AudioDeviceModule::kAndroidJavaAudio)); 775 TestDelayOnAudioLayer(AudioDeviceModule::kAndroidJavaAudio));
762 } 776 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 TEST_F(AudioDeviceTest, StartStopRecording) { 870 TEST_F(AudioDeviceTest, StartStopRecording) {
857 StartRecording(); 871 StartRecording();
858 StopRecording(); 872 StopRecording();
859 StartRecording(); 873 StartRecording();
860 StopRecording(); 874 StopRecording();
861 } 875 }
862 876
863 // Verify that calling StopPlayout() will leave us in an uninitialized state 877 // Verify that calling StopPlayout() will leave us in an uninitialized state
864 // which will require a new call to InitPlayout(). This test does not call 878 // which will require a new call to InitPlayout(). This test does not call
865 // StartPlayout() while being uninitialized since doing so will hit a 879 // StartPlayout() while being uninitialized since doing so will hit a
866 // RTC_DCHECK. 880 // RTC_DCHECK and death tests are not supported on Android.
867 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) { 881 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) {
868 EXPECT_EQ(0, audio_device()->InitPlayout()); 882 EXPECT_EQ(0, audio_device()->InitPlayout());
869 EXPECT_EQ(0, audio_device()->StartPlayout()); 883 EXPECT_EQ(0, audio_device()->StartPlayout());
870 EXPECT_EQ(0, audio_device()->StopPlayout()); 884 EXPECT_EQ(0, audio_device()->StopPlayout());
871 EXPECT_FALSE(audio_device()->PlayoutIsInitialized()); 885 EXPECT_FALSE(audio_device()->PlayoutIsInitialized());
872 } 886 }
873 887
888 // Verify that calling StopRecording() will leave us in an uninitialized state
889 // which will require a new call to InitRecording(). This test does not call
890 // StartRecording() while being uninitialized since doing so will hit a
891 // RTC_DCHECK and death tests are not supported on Android.
892 TEST_F(AudioDeviceTest, StopRecordingRequiresInitToRestart) {
893 EXPECT_EQ(0, audio_device()->InitRecording());
894 EXPECT_EQ(0, audio_device()->StartRecording());
895 EXPECT_EQ(0, audio_device()->StopRecording());
896 EXPECT_FALSE(audio_device()->RecordingIsInitialized());
897 }
898
874 // Start playout and verify that the native audio layer starts asking for real 899 // Start playout and verify that the native audio layer starts asking for real
875 // audio samples to play out using the NeedMorePlayData callback. 900 // audio samples to play out using the NeedMorePlayData callback.
876 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { 901 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) {
877 MockAudioTransport mock(kPlayout); 902 MockAudioTransport mock(kPlayout);
878 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); 903 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks);
879 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), 904 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(),
880 kBytesPerSample, 905 kBytesPerSample,
881 playout_channels(), 906 playout_channels(),
882 playout_sample_rate(), 907 playout_sample_rate(),
883 NotNull(), 908 NotNull(),
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 StopPlayout(); 1052 StopPlayout();
1028 StopRecording(); 1053 StopRecording();
1029 // Verify that the correct number of transmitted impulses are detected. 1054 // Verify that the correct number of transmitted impulses are detected.
1030 EXPECT_EQ(latency_audio_stream->num_latency_values(), 1055 EXPECT_EQ(latency_audio_stream->num_latency_values(),
1031 static_cast<size_t>( 1056 static_cast<size_t>(
1032 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); 1057 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1));
1033 latency_audio_stream->PrintResults(); 1058 latency_audio_stream->PrintResults();
1034 } 1059 }
1035 1060
1036 } // namespace webrtc 1061 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/audio_device_template.h ('k') | webrtc/modules/audio_device/android/audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698