1 /* 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "webrtc/base/format_macros.h" 13 #include "webrtc/base/scoped_ptr.h" 14 #include "webrtc/modules/audio_device/android/build_info.h" 15 #include "webrtc/modules/audio_device/android/audio_manager.h" 16 #include "webrtc/modules/audio_device/android/ensure_initialized.h" 17 18 #define PRINT(...) fprintf(stderr, __VA_ARGS__); 19 20 namespace webrtc { 21 22 static const char kTag[] = " "; 23 24 class AudioManagerTest : public ::testing::Test { 25 protected: 26 AudioManagerTest() { 27 // One-time initialization of JVM and application context. Ensures that we 28 // can do calls between C++ and Java. 29 webrtc::audiodevicemodule::EnsureInitialized(); 30 audio_manager_.reset(new AudioManager()); 31 SetActiveAudioLayer(); 32 playout_parameters_ = audio_manager()->GetPlayoutAudioParameters(); 33 record_parameters_ = audio_manager()->GetRecordAudioParameters(); 34 } 35 36 AudioManager* audio_manager() const { return audio_manager_.get(); } 37 38 // A valid audio layer must always be set before calling Init(), hence we 39 // might as well make it a part of the test fixture. 40 void SetActiveAudioLayer() { 41 EXPECT_EQ(0, audio_manager()->GetDelayEstimateInMilliseconds()); 42 audio_manager()->SetActiveAudioLayer(AudioDeviceModule::kAndroidJavaAudio); 43 EXPECT_NE(0, audio_manager()->GetDelayEstimateInMilliseconds()); 44 } 45 46 rtc::scoped_ptr<AudioManager> audio_manager_; 47 AudioParameters playout_parameters_; 48 AudioParameters record_parameters_; 49 }; 50 51 TEST_F(AudioManagerTest, ConstructDestruct) { 52 } 53 54 TEST_F(AudioManagerTest, InitClose) { 55 EXPECT_TRUE(audio_manager()->Init()); 56 EXPECT_TRUE(audio_manager()->Close()); 57 } 58 59 TEST_F(AudioManagerTest, IsAcousticEchoCancelerSupported) { 60 PRINT("%sAcoustic Echo Canceler support: %s\n", kTag, 61 audio_manager()->IsAcousticEchoCancelerSupported() ? "Yes" : "No"); 62 } 63 64 TEST_F(AudioManagerTest, IsAutomaticGainControlSupported) { 65 PRINT("%sAutomatic Gain Control support: %s\n", kTag, 66 audio_manager()->IsAutomaticGainControlSupported() ? "Yes" : "No"); 67 } 68 69 TEST_F(AudioManagerTest, IsNoiseSuppressorSupported) { 70 PRINT("%sNoise Suppressor support: %s\n", kTag, 71 audio_manager()->IsNoiseSuppressorSupported() ? "Yes" : "No"); 72 } 73 74 TEST_F(AudioManagerTest, IsLowLatencyPlayoutSupported) { 75 PRINT("%sLow latency output support: %s\n", kTag, 76 audio_manager()->IsLowLatencyPlayoutSupported() ? "Yes" : "No"); 77 } 78 79 TEST_F(AudioManagerTest, ShowAudioParameterInfo) { 80 const bool low_latency_out = audio_manager()->IsLowLatencyPlayoutSupported(); 81 PRINT("PLAYOUT:\n"); 82 PRINT("%saudio layer: %s\n", kTag, 83 low_latency_out ? "Low latency OpenSL" : "Java/JNI based AudioTrack"); 84 PRINT("%ssample rate: %d Hz\n", kTag, playout_parameters_.sample_rate()); 85 PRINT("%schannels: %" PRIuS "\n", kTag, playout_parameters_.channels()); 86 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, 87 playout_parameters_.frames_per_buffer(), 88 playout_parameters_.GetBufferSizeInMilliseconds()); 89 PRINT("RECORD: \n"); 90 PRINT("%saudio layer: %s\n", kTag, "Java/JNI based AudioRecord"); 91 PRINT("%ssample rate: %d Hz\n", kTag, record_parameters_.sample_rate()); 92 PRINT("%schannels: %" PRIuS "\n", kTag, record_parameters_.channels()); 93 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, 94 record_parameters_.frames_per_buffer(), 95 record_parameters_.GetBufferSizeInMilliseconds()); 96 } 97 98 // Add device-specific information to the test for logging purposes. 99 TEST_F(AudioManagerTest, ShowDeviceInfo) { 100 BuildInfo build_info; 101 PRINT("%smodel: %s\n", kTag, build_info.GetDeviceModel().c_str()); 102 PRINT("%sbrand: %s\n", kTag, build_info.GetBrand().c_str()); 103 PRINT("%smanufacturer: %s\n", 104 kTag, build_info.GetDeviceManufacturer().c_str()); 105 } 106 107 // Add Android build information to the test for logging purposes. 108 TEST_F(AudioManagerTest, ShowBuildInfo) { 109 BuildInfo build_info; 110 PRINT("%sbuild release: %s\n", kTag, build_info.GetBuildRelease().c_str()); 111 PRINT("%sbuild id: %s\n", kTag, build_info.GetAndroidBuildId().c_str()); 112 PRINT("%sbuild type: %s\n", kTag, build_info.GetBuildType().c_str()); 113 PRINT("%sSDK version: %s\n", kTag, build_info.GetSdkVersion().c_str()); 114 } 115 116 // Basic test of the AudioParameters class using default construction where 117 // all members are set to zero. 118 TEST_F(AudioManagerTest, AudioParametersWithDefaultConstruction) { 119 AudioParameters params; 120 EXPECT_FALSE(params.is_valid()); 121 EXPECT_EQ(0, params.sample_rate()); 122 EXPECT_EQ(0U, params.channels()); 123 EXPECT_EQ(0U, params.frames_per_buffer()); 124 EXPECT_EQ(0U, params.frames_per_10ms_buffer()); 125 EXPECT_EQ(0U, params.GetBytesPerFrame()); 126 EXPECT_EQ(0U, params.GetBytesPerBuffer()); 127 EXPECT_EQ(0U, params.GetBytesPer10msBuffer()); 128 EXPECT_EQ(0.0f, params.GetBufferSizeInMilliseconds()); 129 } 130 131 // Basic test of the AudioParameters class using non default construction. 132 TEST_F(AudioManagerTest, AudioParametersWithNonDefaultConstruction) { 133 const int kSampleRate = 48000; 134 const size_t kChannels = 1; 135 const size_t kFramesPerBuffer = 480; 136 const size_t kFramesPer10msBuffer = 480; 137 const size_t kBytesPerFrame = 2; 138 const float kBufferSizeInMs = 10.0f; 139 AudioParameters params(kSampleRate, kChannels, kFramesPerBuffer); 140 EXPECT_TRUE(params.is_valid()); 141 EXPECT_EQ(kSampleRate, params.sample_rate()); 142 EXPECT_EQ(kChannels, params.channels()); 143 EXPECT_EQ(kFramesPerBuffer, params.frames_per_buffer()); 144 EXPECT_EQ(static_cast<size_t>(kSampleRate / 100), 145 params.frames_per_10ms_buffer()); 146 EXPECT_EQ(kBytesPerFrame, params.GetBytesPerFrame()); 147 EXPECT_EQ(kBytesPerFrame * kFramesPerBuffer, params.GetBytesPerBuffer()); 148 EXPECT_EQ(kBytesPerFrame * kFramesPer10msBuffer, 149 params.GetBytesPer10msBuffer()); 150 EXPECT_EQ(kBufferSizeInMs, params.GetBufferSizeInMilliseconds()); 151 } 152 153 } // namespace webrtc 154 155