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