blob: c349b7ce0679c9e189aab894ceda6c0f7ddd075f [file] [log] [blame]
solenberg9a5f032222017-03-15 06:14:12 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/engine/adm_helpers.h"
solenberg9a5f032222017-03-15 06:14:12 -070012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_device/include/audio_device.h"
Yves Gerey3e707812018-11-28 16:47:49 +010014#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/logging.h"
solenberg9a5f032222017-03-15 06:14:12 -070016
17namespace webrtc {
18namespace 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 Gerey665174f2018-06-19 15:03:05 +020031 (AudioDeviceModule::WindowsDeviceType::kDefaultCommunicationDevice)
solenberg9a5f032222017-03-15 06:14:12 -070032#else
33#define AUDIO_DEVICE_ID (0u)
34#endif // defined(WEBRTC_WIN)
35
Fredrik Solenbergd3195342017-11-21 20:33:05 +010036void Init(AudioDeviceModule* adm) {
solenberg9a5f032222017-03-15 06:14:12 -070037 RTC_DCHECK(adm);
38
Fredrik Solenbergd3195342017-11-21 20:33:05 +010039 RTC_CHECK_EQ(0, adm->Init()) << "Failed to initialize the ADM.";
solenberg9a5f032222017-03-15 06:14:12 -070040
Fredrik Solenbergd3195342017-11-21 20:33:05 +010041 // Playout device.
42 {
43 if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) {
44 RTC_LOG(LS_ERROR) << "Unable to set playout device.";
solenberg9a5f032222017-03-15 06:14:12 -070045 return;
46 }
Fredrik Solenbergd3195342017-11-21 20:33:05 +010047 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.";
solenberg9a5f032222017-03-15 06:14:12 -070058 }
59 }
60
Fredrik Solenbergd3195342017-11-21 20:33:05 +010061 // 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 }
solenberg9a5f032222017-03-15 06:14:12 -070080}
solenberg9a5f032222017-03-15 06:14:12 -070081} // namespace adm_helpers
82} // namespace webrtc