From fc433e65463e3a2e3cc43b3f8cb68849b00f381f Mon Sep 17 00:00:00 2001 From: solenberg Date: Fri, 9 Sep 2016 11:04:53 -0700 Subject: [PATCH] Don't use VoE legacy APIs in force_mic_volume_max tool. BUG=webrtc:4690 Committed: https://crrev.com/ae9f2bdcef7f3a338ece6f57744c8c8f74d15483 Review-Url: https://codereview.webrtc.org/2268183007 Cr-Original-Commit-Position: refs/heads/master@{#14135} Cr-Commit-Position: refs/heads/master@{#14169} --- webrtc/tools/BUILD.gn | 31 ++++++----- webrtc/tools/DEPS | 1 + .../force_mic_volume_max.cc | 54 +++++++++++-------- webrtc/tools/tools.gyp | 2 +- 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/webrtc/tools/BUILD.gn b/webrtc/tools/BUILD.gn index 37f015c1ea..eba0122338 100644 --- a/webrtc/tools/BUILD.gn +++ b/webrtc/tools/BUILD.gn @@ -117,22 +117,25 @@ rtc_executable("frame_editor") { ] } -rtc_executable("force_mic_volume_max") { - sources = [ - "force_mic_volume_max/force_mic_volume_max.cc", - ] +# It doesn't make sense to build this tool without the ADM enabled. +if (rtc_include_internal_audio_device) { + rtc_executable("force_mic_volume_max") { + sources = [ + "force_mic_volume_max/force_mic_volume_max.cc", + ] - if (is_clang) { - # Suppress warnings from the Chromium Clang plugin. - # See http://code.google.com/p/webrtc/issues/detail?id=163 for details. - suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] + if (is_clang) { + # Suppress warnings from the Chromium Clang plugin. + # See http://code.google.com/p/webrtc/issues/detail?id=163 for details. + suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] + } + + deps = [ + "../modules/audio_device:audio_device", + "../system_wrappers:system_wrappers_default", + "//build/win:default_exe_manifest", + ] } - - deps = [ - "../system_wrappers:system_wrappers_default", - "../voice_engine", - "//build/win:default_exe_manifest", - ] } if (rtc_enable_protobuf) { diff --git a/webrtc/tools/DEPS b/webrtc/tools/DEPS index 035245095c..cc33de1f96 100644 --- a/webrtc/tools/DEPS +++ b/webrtc/tools/DEPS @@ -2,6 +2,7 @@ include_rules = [ "+webrtc/base", "+webrtc/call", "+webrtc/common_video", + "+webrtc/modules/audio_device", "+webrtc/modules/audio_processing", "+webrtc/modules/congestion_controller", "+webrtc/modules/rtp_rtcp", diff --git a/webrtc/tools/force_mic_volume_max/force_mic_volume_max.cc b/webrtc/tools/force_mic_volume_max/force_mic_volume_max.cc index 2bab2881bb..0a2347d5ba 100644 --- a/webrtc/tools/force_mic_volume_max/force_mic_volume_max.cc +++ b/webrtc/tools/force_mic_volume_max/force_mic_volume_max.cc @@ -12,33 +12,45 @@ #include -#include "webrtc/test/channel_transport/channel_transport.h" -#include "webrtc/voice_engine/include/voe_audio_processing.h" -#include "webrtc/voice_engine/include/voe_base.h" -#include "webrtc/voice_engine/include/voe_volume_control.h" +#include "webrtc/modules/audio_device/include/audio_device.h" -int main(int argc, char** argv) { - webrtc::VoiceEngine* voe = webrtc::VoiceEngine::Create(); - if (voe == NULL) { - fprintf(stderr, "Failed to initialize voice engine.\n"); +using webrtc::AudioDeviceModule; + +#if defined(_WIN32) +#define DEFAULT_INPUT_DEVICE (AudioDeviceModule::kDefaultCommunicationDevice) +#else +#define DEFAULT_INPUT_DEVICE (0) +#endif + +int main(int /*argc*/, char** /*argv*/) { + // Create and initialize the ADM. + rtc::scoped_refptr adm( + AudioDeviceModule::Create(1, AudioDeviceModule::kPlatformDefaultAudio)); + if (!adm.get()) { + fprintf(stderr, "Failed to create Audio Device Module.\n"); + return 1; + } + if (adm->Init() != 0) { + fprintf(stderr, "Failed to initialize Audio Device Module.\n"); + return 1; + } + if (adm->SetRecordingDevice(DEFAULT_INPUT_DEVICE) != 0) { + fprintf(stderr, "Failed to set the default input device.\n"); + return 1; + } + if (adm->InitMicrophone() != 0) { + fprintf(stderr, "Failed to to initialize the microphone.\n"); return 1; } - webrtc::VoEBase* base = webrtc::VoEBase::GetInterface(voe); - webrtc::VoEVolumeControl* volume_control = - webrtc::VoEVolumeControl::GetInterface(voe); - - if (base->Init() != 0) { - fprintf(stderr, "Failed to initialize voice engine base.\n"); + // Set mic volume to max. + uint32_t max_vol = 0; + if (adm->MaxMicrophoneVolume(&max_vol) != 0) { + fprintf(stderr, "Failed to get max volume.\n"); return 1; } - // Set to 0 first in case the mic is above 100%. - if (volume_control->SetMicVolume(0) != 0) { - fprintf(stderr, "Failed set volume to 0.\n"); - return 1; - } - if (volume_control->SetMicVolume(255) != 0) { - fprintf(stderr, "Failed set volume to 255.\n"); + if (adm->SetMicrophoneVolume(max_vol) != 0) { + fprintf(stderr, "Failed to set mic volume.\n"); return 1; } diff --git a/webrtc/tools/tools.gyp b/webrtc/tools/tools.gyp index 12eff5de2a..d1ff42bcbe 100644 --- a/webrtc/tools/tools.gyp +++ b/webrtc/tools/tools.gyp @@ -90,7 +90,7 @@ 'target_name': 'force_mic_volume_max', 'type': 'executable', 'dependencies': [ - '<(webrtc_root)/voice_engine/voice_engine.gyp:voice_engine', + '<(webrtc_root)/modules/modules.gyp:audio_device', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers_default', ], 'sources': [