blob: 119cc644510b0feeacd1cc2cad268b44c0e51bfb [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"
14#include "rtc_base/logging.h"
solenberg9a5f032222017-03-15 06:14:12 -070015
16namespace webrtc {
17namespace 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 Solenbergd3195342017-11-21 20:33:05 +010035void Init(AudioDeviceModule* adm) {
solenberg9a5f032222017-03-15 06:14:12 -070036 RTC_DCHECK(adm);
37
Fredrik Solenbergd3195342017-11-21 20:33:05 +010038 RTC_CHECK_EQ(0, adm->Init()) << "Failed to initialize the ADM.";
solenberg9a5f032222017-03-15 06:14:12 -070039
Fredrik Solenbergd3195342017-11-21 20:33:05 +010040 // Playout device.
41 {
42 if (adm->SetPlayoutDevice(AUDIO_DEVICE_ID) != 0) {
43 RTC_LOG(LS_ERROR) << "Unable to set playout device.";
solenberg9a5f032222017-03-15 06:14:12 -070044 return;
45 }
Fredrik Solenbergd3195342017-11-21 20:33:05 +010046 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.";
solenberg9a5f032222017-03-15 06:14:12 -070057 }
58 }
59
Fredrik Solenbergd3195342017-11-21 20:33:05 +010060 // 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 }
solenberg9a5f032222017-03-15 06:14:12 -070079}
solenberg9a5f032222017-03-15 06:14:12 -070080} // namespace adm_helpers
81} // namespace webrtc