solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/engine/adm_helpers.h" |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "modules/audio_device/include/audio_device.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/logging.h" |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace adm_helpers { |
| 19 | |
| 20 | // On Windows Vista and newer, Microsoft introduced the concept of "Default |
| 21 | // Communications Device". This means that there are two types of default |
| 22 | // devices (old Wave Audio style default and Default Communications Device). |
| 23 | // |
| 24 | // On Windows systems which only support Wave Audio style default, uses either |
| 25 | // -1 or 0 to select the default device. |
| 26 | // |
| 27 | // Using a #define for AUDIO_DEVICE since we will call *different* versions of |
| 28 | // the ADM functions, depending on the ID type. |
| 29 | #if defined(WEBRTC_WIN) |
| 30 | #define AUDIO_DEVICE_ID \ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 31 | (AudioDeviceModule::WindowsDeviceType::kDefaultCommunicationDevice) |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 32 | #else |
| 33 | #define AUDIO_DEVICE_ID (0u) |
| 34 | #endif // defined(WEBRTC_WIN) |
| 35 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 36 | void Init(AudioDeviceModule* adm) { |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 37 | RTC_DCHECK(adm); |
| 38 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 39 | RTC_CHECK_EQ(0, adm->Init()) << "Failed to initialize the ADM."; |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 40 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 41 | // Playout device. |
| 42 | { |
| 43 | if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) { |
| 44 | RTC_LOG(LS_ERROR) << "Unable to set playout device."; |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 47 | if (adm->InitSpeaker() != 0) { |
| 48 | RTC_LOG(LS_ERROR) << "Unable to access speaker."; |
| 49 | } |
| 50 | |
| 51 | // Set number of channels |
| 52 | bool available = false; |
| 53 | if (adm->StereoPlayoutIsAvailable(&available) != 0) { |
| 54 | RTC_LOG(LS_ERROR) << "Failed to query stereo playout."; |
| 55 | } |
| 56 | if (adm->SetStereoPlayout(available) != 0) { |
| 57 | RTC_LOG(LS_ERROR) << "Failed to set stereo playout mode."; |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 61 | // Recording device. |
| 62 | { |
| 63 | if (adm->SetRecordingDevice(AUDIO_DEVICE_ID) != 0) { |
| 64 | RTC_LOG(LS_ERROR) << "Unable to set recording device."; |
| 65 | return; |
| 66 | } |
| 67 | if (adm->InitMicrophone() != 0) { |
| 68 | RTC_LOG(LS_ERROR) << "Unable to access microphone."; |
| 69 | } |
| 70 | |
| 71 | // Set number of channels |
| 72 | bool available = false; |
| 73 | if (adm->StereoRecordingIsAvailable(&available) != 0) { |
| 74 | RTC_LOG(LS_ERROR) << "Failed to query stereo recording."; |
| 75 | } |
| 76 | if (adm->SetStereoRecording(available) != 0) { |
| 77 | RTC_LOG(LS_ERROR) << "Failed to set stereo recording mode."; |
| 78 | } |
| 79 | } |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 80 | } |
solenberg | 9a5f03222 | 2017-03-15 06:14:12 -0700 | [diff] [blame] | 81 | } // namespace adm_helpers |
| 82 | } // namespace webrtc |