112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org/* 212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * 412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * Use of this source code is governed by a BSD-style license 512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * that can be found in the LICENSE file in the root of the source 612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * tree. An additional intellectual property rights grant can be found 712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * in the file PATENTS. All contributing project authors may 812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org * be found in the AUTHORS file in the root of the source tree. 912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org */ 1012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 11956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" 1212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 1308d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.orgnamespace { 1408d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org 1508d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.orgvoid ExpectVolumeNear(int expected, int actual) { 1608d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org // The hardware volume may be more coarsely quantized than [0, 255], so 1708d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org // it is not always reasonable to expect to get exactly what we set. This 1808d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org // allows for some error. 1908d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org const int kMaxVolumeError = 10; 2008d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org EXPECT_NEAR(expected, actual, kMaxVolumeError); 2108d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org EXPECT_GE(actual, 0); 2208d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org EXPECT_LE(actual, 255); 2308d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org} 2408d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org 2508d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org} // namespace 2608d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org 2712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgclass VolumeTest : public AfterStreamingFixture { 28f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org public: 29f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org void SetAndVerifyMicVolume(unsigned int volume) { 30f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org bool success = voe_volume_control_->SetMicVolume(volume) == 0; 31f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 32f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(success); 33f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 34f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (!success) { 35f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to set microphone volume to %u.\n", volume); 36f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org return; 37f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 38f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org 39f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org unsigned int test_volume = 1000; 40f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org success = voe_volume_control_->GetMicVolume(test_volume) == 0; 41f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 42f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(success); 43f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 44f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (success) { 45f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_EQ(volume, test_volume); 46f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } else { 47f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to get the microphone volume."); 48f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_EQ(1000u, test_volume); 49f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 50f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 51f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org 52f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org void SetAndVerifyInputMute(bool enable) { 53f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org bool success = voe_volume_control_->SetInputMute(channel_, enable) == 0; 54f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 55f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(success); 56f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 57f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (!success) { 58f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to %smute input.\n", enable ? "" : "un"); 59f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org return; 60f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 61f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org 62f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org bool is_muted = !enable; 63f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org success = voe_volume_control_->GetInputMute(channel_, is_muted) == 0; 64f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 65f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(success); 66f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 67f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (success) { 68f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_EQ(enable, is_muted); 69f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } else { 70f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to mute the input."); 71f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_NE(enable, is_muted); 72f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 73f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 7412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org}; 7512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 76f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org// Some tests are flaky on Linux (Pulse Audio), which boils down to some system 77f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org// values not being acquired in time. In Pulse Audio we make one retry if 78f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org// needed, but if we fail then, a -1 is returned propagating up through VoE. 79f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org// To avoid possible bugs slipping through on other platforms we make adequate 80f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org// changes on Linux only. 8106c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.orgTEST_F(VolumeTest, VerifyCorrectErrorReturns) { 8206c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // All tests run on correct initialization which eliminates one possible error 8306c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // return. In addition, we assume the audio_device returning values without 8406c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // error, which eliminates another potential error. 8506c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // Left to verify are sanity checks of set parameters. 8606c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org 8706c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // Valid volume range: [0, 255] 8806c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetSpeakerVolume(256)); 8906c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetMicVolume(256)); 9006c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org 9106c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org // Valid panning rage: [0, 1] 9206c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, -0.1f, 0.5f)); 9306c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 1.1f, 0.5f)); 9406c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 0.5f, -0.1f)); 9506c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 0.5f, 1.1f)); 9606c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org} 9706c1d6f3a1c38724901d436b59717d65235f5e65bjornv@webrtc.org 9816fcb247b24a924c5cad05ed320957cd8cb145c4andrew@webrtc.orgTEST_F(VolumeTest, DefaultSpeakerVolumeIsAtMost255) { 9912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int volume = 1000; 10012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 10112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_LE(volume, 255u); 10212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 10312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 104589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.orgTEST_F(VolumeTest, SetVolumeBeforePlayoutWorks) { 105589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org // This is a rather specialized test, intended to exercise some PulseAudio 106589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org // code. However, these conditions should be satisfied on any platform. 107589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org unsigned int original_volume = 0; 108589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(original_volume)); 109589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org Sleep(1000); 110589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org 111589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(200)); 112589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org unsigned int volume; 113589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 11408d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(200u, volume); 115589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org 116589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org PausePlaying(); 117589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org ResumePlaying(); 118589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 119589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org // Ensure the volume has not changed after resuming playout. 12008d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(200u, volume); 121589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org 122589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org PausePlaying(); 123589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100)); 124589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org ResumePlaying(); 125589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org // Ensure the volume set while paused is retained. 126589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 12708d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(100u, volume); 128589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org 129589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume)); 130589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org} 131589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org 13212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ManualSetVolumeWorks) { 13312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int original_volume = 0; 13412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(original_volume)); 13512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 13612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 13712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Setting speaker volume to 0 out of 255.\n"); 13812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(0)); 139589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org unsigned int volume; 140589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 14108d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(0u, volume); 14212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 14312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 14412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Setting speaker volume to 100 out of 255.\n"); 14512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100)); 146589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 14708d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(100u, volume); 14812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 14912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 15012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org // Set the volume to 255 very briefly so we don't blast the poor user 15112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org // listening to this. This is just to test the call succeeds. 15212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(255)); 153589673f1cbef93921900a835de52d05ad4f3a0e2andrew@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); 15408d660f08e7fb18c614729996da36b13b6f77bf3andrew@webrtc.org ExpectVolumeNear(255u, volume); 15512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 15612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Setting speaker volume to the original %d out of 255.\n", 15712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org original_volume); 15812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume)); 15912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 16012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 16112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 1628d63d0ee70d27439fd153af7093a6be390686efebjornv@webrtc.orgTEST_F(VolumeTest, DefaultMicrophoneVolumeIsAtMost255) { 16312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int volume = 1000; 164f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org bool could_get_mic_volume = voe_volume_control_->GetMicVolume(volume) == 0; 165f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 166f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(could_get_mic_volume); 167f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 168f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (could_get_mic_volume) { 1698d63d0ee70d27439fd153af7093a6be390686efebjornv@webrtc.org EXPECT_LE(volume, 255u); 170f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } else { 171f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to get the microphone volume."); 1728d63d0ee70d27439fd153af7093a6be390686efebjornv@webrtc.org EXPECT_EQ(1000u, volume); 173f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 17412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 17512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 176f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.orgTEST_F(VolumeTest, ManualRequiresMicrophoneCanSetMicrophoneVolumeWithAgcOff) { 17712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org SwitchToManualMicrophone(); 17812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_apm_->SetAgcStatus(false)); 17912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 18012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int original_volume = 0; 181f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org bool could_get_mic_volume = 182f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org (voe_volume_control_->GetMicVolume(original_volume) == 0); 183f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#if !defined(WEBRTC_LINUX) 184f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org EXPECT_TRUE(could_get_mic_volume); 185f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org#endif 186f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (could_get_mic_volume) 187f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Current microphone volume is %u.\n", original_volume); 188f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org else 189f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Failed to fetch current microphone volume.\n"); 19012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 19112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Setting microphone volume to 0.\n"); 192f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org SetAndVerifyMicVolume(0); 19312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 19412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Setting microphone volume to 255.\n"); 195f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org SetAndVerifyMicVolume(255); 19612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 197f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org if (could_get_mic_volume) { 198f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org TEST_LOG("Setting microphone volume back to %u.\n", original_volume); 199f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org SetAndVerifyMicVolume(original_volume); 200f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org Sleep(1000); 201f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org } 20212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 20312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 20412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ChannelScalingIsOneByDefault) { 20578088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org float scaling = -1.0f; 20612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 20712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling( 20812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org channel_, scaling)); 20978088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_FLOAT_EQ(1.0f, scaling); 21012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 21112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 21212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ManualCanSetChannelScaling) { 21312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetChannelOutputVolumeScaling( 21478088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org channel_, 0.1f)); 21512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 21678088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org float scaling = 1.0f; 21712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling( 21812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org channel_, scaling)); 21912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 22078088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_FLOAT_EQ(0.1f, scaling); 22112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 22212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Channel scaling set to 0.1: audio should be barely audible.\n"); 22312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(2000); 22412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 22512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 22612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, InputMutingIsNotEnabledByDefault) { 22712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org bool is_muted = true; 22812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetInputMute(channel_, is_muted)); 22912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_FALSE(is_muted); 23012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 23112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 232f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.orgTEST_F(VolumeTest, ManualInputMutingMutesMicrophone) { 23312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org SwitchToManualMicrophone(); 23412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org // Enable muting. 235f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org SetAndVerifyInputMute(true); 23612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Muted: talk into microphone and verify you can't hear yourself.\n"); 23712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(2000); 23812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 23912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org // Test that we can disable muting. 240f3e1341da73b45db817e9ba5b739141b6965784cbjornv@webrtc.org SetAndVerifyInputMute(false); 24112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Unmuted: talk into microphone and verify you can hear yourself.\n"); 24212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(2000); 24312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 24412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 24512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ManualTestInputAndOutputLevels) { 24612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org SwitchToManualMicrophone(); 24712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 24812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Speak and verify that the following levels look right:\n"); 24912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org for (int i = 0; i < 5; i++) { 25012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 25112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int input_level = 0; 25212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int output_level = 0; 25312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int input_level_full_range = 0; 25412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org unsigned int output_level_full_range = 0; 25512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 25612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevel( 25712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org input_level)); 25812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevel( 25912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org channel_, output_level)); 26012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevelFullRange( 26112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org input_level_full_range)); 26212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevelFullRange( 26312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org channel_, output_level_full_range)); 26412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 26512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG(" warped levels (0-9) : in=%5d, out=%5d\n", 26612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org input_level, output_level); 26712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG(" linear levels (0-32768): in=%5d, out=%5d\n", 26812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org input_level_full_range, output_level_full_range); 26912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org } 27012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 27112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 27212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ChannelsAreNotPannedByDefault) { 27312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org float left = -1.0; 27412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org float right = -1.0; 27512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 27612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right)); 27712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_FLOAT_EQ(1.0, left); 27812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_FLOAT_EQ(1.0, right); 27912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 28012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 28112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.orgTEST_F(VolumeTest, ManualTestChannelPanning) { 28212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Panning left.\n"); 28378088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.8f, 0.1f)); 28412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 28512dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 28612dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Back to center.\n"); 28778088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 1.0f, 1.0f)); 28812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 28912dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 29012dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org TEST_LOG("Panning right.\n"); 29178088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.1f, 0.8f)); 29212dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org Sleep(1000); 29312dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 29412dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org // To finish, verify that the getter works. 29578088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org float left = 0.0f; 29678088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org float right = 0.0f; 29712dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org 29812dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right)); 29978088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_FLOAT_EQ(0.1f, left); 30078088c2f3673dc104e2fc133c92583aa21d43e0ephoglund@webrtc.org EXPECT_FLOAT_EQ(0.8f, right); 30112dbc23851c95cbabdcafe9789465d8d91a59e81phoglund@webrtc.org} 302