| 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 "media/engine/adm_helpers.h" |
| 12 |
| 13 | #include "modules/audio_device/include/audio_device.h" |
| 14 | #include "rtc_base/checks.h" |
| 15 | #include "rtc_base/logging.h" |
| 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 \ |
| 31 | (AudioDeviceModule::WindowsDeviceType::kDefaultCommunicationDevice) |
| 32 | #else |
| 33 | #define AUDIO_DEVICE_ID (0u) |
| 34 | #endif // defined(WEBRTC_WIN) |
| 35 |
| 36 | void Init(AudioDeviceModule* adm) { |
| 37 | RTC_DCHECK(adm); |
| 38 |
| 39 | RTC_CHECK_EQ(0, adm->Init()) << "Failed to initialize the ADM."; |
| 40 |
| 41 | // Playout device. |
| 42 | { |
| 43 | if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) { |
| 44 | RTC_LOG(LS_ERROR) << "Unable to set playout device."; |
| 45 | return; |
| 46 | } |
| 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."; |
| 58 | } |
| 59 | } |
| 60 |
| 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 | } |
| 80 | } |
| 81 | } // namespace adm_helpers |
| 82 | } // namespace webrtc |
| 83 |