niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
| 11 | #include "voe_volume_control_impl.h" |
| 12 | |
| 13 | #include "channel.h" |
| 14 | #include "critical_section_wrapper.h" |
| 15 | #include "output_mixer.h" |
| 16 | #include "trace.h" |
| 17 | #include "transmit_mixer.h" |
| 18 | #include "voe_errors.h" |
| 19 | #include "voice_engine_impl.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | VoEVolumeControl* VoEVolumeControl::GetInterface(VoiceEngine* voiceEngine) |
| 24 | { |
| 25 | #ifndef WEBRTC_VOICE_ENGINE_VOLUME_CONTROL_API |
| 26 | return NULL; |
| 27 | #else |
| 28 | if (NULL == voiceEngine) |
| 29 | { |
| 30 | return NULL; |
| 31 | } |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 32 | VoiceEngineImpl* s = reinterpret_cast<VoiceEngineImpl*>(voiceEngine); |
| 33 | s->AddRef(); |
| 34 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | #endif |
| 36 | } |
| 37 | |
| 38 | #ifdef WEBRTC_VOICE_ENGINE_VOLUME_CONTROL_API |
| 39 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 40 | VoEVolumeControlImpl::VoEVolumeControlImpl(voe::SharedData* shared) |
| 41 | : _shared(shared) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 43 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | "VoEVolumeControlImpl::VoEVolumeControlImpl() - ctor"); |
| 45 | } |
| 46 | |
| 47 | VoEVolumeControlImpl::~VoEVolumeControlImpl() |
| 48 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 49 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | "VoEVolumeControlImpl::~VoEVolumeControlImpl() - dtor"); |
| 51 | } |
| 52 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | int VoEVolumeControlImpl::SetSpeakerVolume(unsigned int volume) |
| 54 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 55 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | "SetSpeakerVolume(volume=%u)", volume); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 57 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 59 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 61 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | return -1; |
| 63 | } |
| 64 | if (volume > kMaxVolumeLevel) |
| 65 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 66 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | "SetSpeakerVolume() invalid argument"); |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | WebRtc_UWord32 maxVol(0); |
| 72 | WebRtc_UWord32 spkrVol(0); |
| 73 | |
| 74 | // scale: [0,kMaxVolumeLevel] -> [0,MaxSpeakerVolume] |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 75 | if (_shared->audio_device()->MaxSpeakerVolume(&maxVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 77 | _shared->SetLastError(VE_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | "SetSpeakerVolume() failed to get max volume"); |
| 79 | return -1; |
| 80 | } |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 81 | // Round the value and avoid floating computation. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | spkrVol = (WebRtc_UWord32)((volume * maxVol + |
| 83 | (int)(kMaxVolumeLevel / 2)) / (kMaxVolumeLevel)); |
| 84 | |
| 85 | // set the actual volume using the audio mixer |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 86 | if (_shared->audio_device()->SetSpeakerVolume(spkrVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 88 | _shared->SetLastError(VE_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | "SetSpeakerVolume() failed to set speaker volume"); |
| 90 | return -1; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | int VoEVolumeControlImpl::GetSpeakerVolume(unsigned int& volume) |
| 96 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 97 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | "GetSpeakerVolume()"); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 99 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 101 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 103 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | WebRtc_UWord32 spkrVol(0); |
| 108 | WebRtc_UWord32 maxVol(0); |
| 109 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 110 | if (_shared->audio_device()->SpeakerVolume(&spkrVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 112 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | "GetSpeakerVolume() unable to get speaker volume"); |
| 114 | return -1; |
| 115 | } |
| 116 | |
| 117 | // scale: [0, MaxSpeakerVolume] -> [0, kMaxVolumeLevel] |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 118 | if (_shared->audio_device()->MaxSpeakerVolume(&maxVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 120 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | "GetSpeakerVolume() unable to get max speaker volume"); |
| 122 | return -1; |
| 123 | } |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 124 | // Round the value and avoid floating computation. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | volume = (WebRtc_UWord32) ((spkrVol * kMaxVolumeLevel + |
| 126 | (int)(maxVol / 2)) / (maxVol)); |
| 127 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 128 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 129 | VoEId(_shared->instance_id(), -1), |
| 130 | "GetSpeakerVolume() => volume=%d", volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int VoEVolumeControlImpl::SetSystemOutputMute(bool enable) |
| 135 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 136 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | "GetSystemOutputMute(enabled=%d)", enable); |
| 138 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 139 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 141 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | return -1; |
| 143 | } |
| 144 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 145 | if (_shared->audio_device()->SetSpeakerMute(enable) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 147 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | "SpeakerMute() unable to Set speaker mute"); |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | int VoEVolumeControlImpl::GetSystemOutputMute(bool& enabled) |
| 156 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 157 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | "GetSystemOutputMute(enabled=?)"); |
| 159 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 160 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 162 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 163 | return -1; |
| 164 | } |
| 165 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 166 | if (_shared->audio_device()->SpeakerMute(&enabled) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 168 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | "SpeakerMute() unable to get speaker mute state"); |
| 170 | return -1; |
| 171 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 172 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 173 | VoEId(_shared->instance_id(), -1), |
| 174 | "GetSystemOutputMute() => %d", enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | int VoEVolumeControlImpl::SetMicVolume(unsigned int volume) |
| 179 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 180 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | "SetMicVolume(volume=%u)", volume); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 182 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 183 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 185 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 187 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | return -1; |
| 189 | } |
| 190 | if (volume > kMaxVolumeLevel) |
| 191 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 192 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 193 | "SetMicVolume() invalid argument"); |
| 194 | return -1; |
| 195 | } |
| 196 | |
| 197 | WebRtc_UWord32 maxVol(0); |
| 198 | WebRtc_UWord32 micVol(0); |
| 199 | |
| 200 | // scale: [0, kMaxVolumeLevel] -> [0,MaxMicrophoneVolume] |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 201 | if (_shared->audio_device()->MaxMicrophoneVolume(&maxVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 202 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 203 | _shared->SetLastError(VE_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | "SetMicVolume() failed to get max volume"); |
| 205 | return -1; |
| 206 | } |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 207 | |
| 208 | if (volume == kMaxVolumeLevel) { |
| 209 | // On Linux running pulse, users are able to set the volume above 100% |
| 210 | // through the volume control panel, where the +100% range is digital |
| 211 | // scaling. WebRTC does not support setting the volume above 100%, and |
| 212 | // simply ignores changing the volume if the user tries to set it to |
| 213 | // |kMaxVolumeLevel| while the current volume is higher than |maxVol|. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 214 | if (_shared->audio_device()->MicrophoneVolume(&micVol) != 0) { |
| 215 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 216 | "SetMicVolume() unable to get microphone volume"); |
| 217 | return -1; |
| 218 | } |
| 219 | if (micVol >= maxVol) |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | // Round the value and avoid floating point computation. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 224 | micVol = (WebRtc_UWord32) ((volume * maxVol + |
| 225 | (int)(kMaxVolumeLevel / 2)) / (kMaxVolumeLevel)); |
| 226 | |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 227 | // set the actual volume using the audio mixer |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 228 | if (_shared->audio_device()->SetMicrophoneVolume(micVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 230 | _shared->SetLastError(VE_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | "SetMicVolume() failed to set mic volume"); |
| 232 | return -1; |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | int VoEVolumeControlImpl::GetMicVolume(unsigned int& volume) |
| 238 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 239 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 240 | "GetMicVolume()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 241 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 242 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 243 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 244 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 245 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 246 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | WebRtc_UWord32 micVol(0); |
| 251 | WebRtc_UWord32 maxVol(0); |
| 252 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 253 | if (_shared->audio_device()->MicrophoneVolume(&micVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 255 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 256 | "GetMicVolume() unable to get microphone volume"); |
| 257 | return -1; |
| 258 | } |
| 259 | |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 260 | // scale: [0, MaxMicrophoneVolume] -> [0, kMaxVolumeLevel] |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 261 | if (_shared->audio_device()->MaxMicrophoneVolume(&maxVol) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 263 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | "GetMicVolume() unable to get max microphone volume"); |
| 265 | return -1; |
| 266 | } |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 267 | if (micVol < maxVol) { |
| 268 | // Round the value and avoid floating point calculation. |
| 269 | volume = (WebRtc_UWord32) ((micVol * kMaxVolumeLevel + |
| 270 | (int)(maxVol / 2)) / (maxVol)); |
| 271 | } else { |
| 272 | // Truncate the value to the kMaxVolumeLevel. |
| 273 | volume = kMaxVolumeLevel; |
| 274 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 275 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 276 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 277 | VoEId(_shared->instance_id(), -1), |
| 278 | "GetMicVolume() => volume=%d", volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | int VoEVolumeControlImpl::SetInputMute(int channel, bool enable) |
| 283 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 284 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 285 | "SetInputMute(channel=%d, enable=%d)", channel, enable); |
| 286 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 287 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 288 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 289 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 290 | return -1; |
| 291 | } |
| 292 | if (channel == -1) |
| 293 | { |
| 294 | // Mute before demultiplexing <=> affects all channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 295 | return _shared->transmit_mixer()->SetMute(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 296 | } |
| 297 | else |
| 298 | { |
| 299 | // Mute after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 300 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 302 | if (channelPtr == NULL) |
| 303 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 304 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | "SetInputMute() failed to locate channel"); |
| 306 | return -1; |
| 307 | } |
| 308 | return channelPtr->SetMute(enable); |
| 309 | } |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int VoEVolumeControlImpl::GetInputMute(int channel, bool& enabled) |
| 314 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 315 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | "GetInputMute(channel=%d)", channel); |
| 317 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 318 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 319 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 320 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | return -1; |
| 322 | } |
| 323 | if (channel == -1) |
| 324 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 325 | enabled = _shared->transmit_mixer()->Mute(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 329 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 331 | if (channelPtr == NULL) |
| 332 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 333 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | "SetInputMute() failed to locate channel"); |
| 335 | return -1; |
| 336 | } |
| 337 | enabled = channelPtr->Mute(); |
| 338 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 339 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 340 | VoEId(_shared->instance_id(), -1), |
| 341 | "GetInputMute() => enabled = %d", (int)enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | int VoEVolumeControlImpl::SetSystemInputMute(bool enable) |
| 346 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 347 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | "SetSystemInputMute(enabled=%d)", enable); |
| 349 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 350 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 352 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 353 | return -1; |
| 354 | } |
| 355 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 356 | if (_shared->audio_device()->SetMicrophoneMute(enable) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 357 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 358 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | "MicrophoneMute() unable to set microphone mute state"); |
| 360 | return -1; |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | int VoEVolumeControlImpl::GetSystemInputMute(bool& enabled) |
| 367 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 368 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | "GetSystemInputMute(enabled=?)"); |
| 370 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 371 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 372 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 373 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | return -1; |
| 375 | } |
| 376 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 377 | if (_shared->audio_device()->MicrophoneMute(&enabled) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 378 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 379 | _shared->SetLastError(VE_GET_MIC_VOL_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 380 | "MicrophoneMute() unable to get microphone mute state"); |
| 381 | return -1; |
| 382 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 383 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 384 | VoEId(_shared->instance_id(), -1), |
| 385 | "GetSystemInputMute() => %d", enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | int VoEVolumeControlImpl::GetSpeechInputLevel(unsigned int& level) |
| 390 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 391 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 392 | "GetSpeechInputLevel()"); |
zakkhoyt@google.com | 630504f | 2011-07-13 20:06:58 +0000 | [diff] [blame] | 393 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 394 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 396 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 397 | return -1; |
| 398 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 399 | WebRtc_Word8 currentLevel = _shared->transmit_mixer()->AudioLevel(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 400 | level = static_cast<unsigned int> (currentLevel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 401 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 402 | VoEId(_shared->instance_id(), -1), |
| 403 | "GetSpeechInputLevel() => %d", level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | int VoEVolumeControlImpl::GetSpeechOutputLevel(int channel, |
| 408 | unsigned int& level) |
| 409 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 410 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
zakkhoyt@google.com | 630504f | 2011-07-13 20:06:58 +0000 | [diff] [blame] | 411 | "GetSpeechOutputLevel(channel=%d, level=?)", channel); |
zakkhoyt@google.com | 630504f | 2011-07-13 20:06:58 +0000 | [diff] [blame] | 412 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 413 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 414 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 415 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 416 | return -1; |
| 417 | } |
| 418 | if (channel == -1) |
| 419 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 420 | return _shared->output_mixer()->GetSpeechOutputLevel( |
| 421 | (WebRtc_UWord32&)level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 425 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 427 | if (channelPtr == NULL) |
| 428 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 429 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 430 | "GetSpeechOutputLevel() failed to locate channel"); |
| 431 | return -1; |
| 432 | } |
| 433 | channelPtr->GetSpeechOutputLevel((WebRtc_UWord32&)level); |
| 434 | } |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | int VoEVolumeControlImpl::GetSpeechInputLevelFullRange(unsigned int& level) |
| 439 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 440 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | "GetSpeechInputLevelFullRange(level=?)"); |
zakkhoyt@google.com | 5e26663 | 2011-07-15 18:21:34 +0000 | [diff] [blame] | 442 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 443 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 444 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 445 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 446 | return -1; |
| 447 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 448 | WebRtc_Word16 currentLevel = _shared->transmit_mixer()-> |
| 449 | AudioLevelFullRange(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 450 | level = static_cast<unsigned int> (currentLevel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 451 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 452 | VoEId(_shared->instance_id(), -1), |
| 453 | "GetSpeechInputLevelFullRange() => %d", level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | int VoEVolumeControlImpl::GetSpeechOutputLevelFullRange(int channel, |
| 458 | unsigned int& level) |
| 459 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 460 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 461 | "GetSpeechOutputLevelFullRange(channel=%d, level=?)", channel); |
zakkhoyt@google.com | 5e26663 | 2011-07-15 18:21:34 +0000 | [diff] [blame] | 462 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 463 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 464 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 465 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 466 | return -1; |
| 467 | } |
| 468 | if (channel == -1) |
| 469 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 470 | return _shared->output_mixer()->GetSpeechOutputLevelFullRange( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 471 | (WebRtc_UWord32&)level); |
| 472 | } |
| 473 | else |
| 474 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 475 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 477 | if (channelPtr == NULL) |
| 478 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 479 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 480 | "GetSpeechOutputLevelFullRange() failed to locate channel"); |
| 481 | return -1; |
| 482 | } |
| 483 | channelPtr->GetSpeechOutputLevelFullRange((WebRtc_UWord32&)level); |
| 484 | } |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | int VoEVolumeControlImpl::SetChannelOutputVolumeScaling(int channel, |
| 489 | float scaling) |
| 490 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 491 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 492 | "SetChannelOutputVolumeScaling(channel=%d, scaling=%3.2f)", |
| 493 | channel, scaling); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 494 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 495 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 496 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 497 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | return -1; |
| 499 | } |
| 500 | if (scaling < kMinOutputVolumeScaling || |
| 501 | scaling > kMaxOutputVolumeScaling) |
| 502 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 503 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | "SetChannelOutputVolumeScaling() invalid parameter"); |
| 505 | return -1; |
| 506 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 507 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 508 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 509 | if (channelPtr == NULL) |
| 510 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 511 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 512 | "SetChannelOutputVolumeScaling() failed to locate channel"); |
| 513 | return -1; |
| 514 | } |
| 515 | return channelPtr->SetChannelOutputVolumeScaling(scaling); |
| 516 | } |
| 517 | |
| 518 | int VoEVolumeControlImpl::GetChannelOutputVolumeScaling(int channel, |
| 519 | float& scaling) |
| 520 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 521 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 522 | "GetChannelOutputVolumeScaling(channel=%d, scaling=?)", channel); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 523 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 524 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 525 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 526 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 527 | return -1; |
| 528 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 529 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 530 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 531 | if (channelPtr == NULL) |
| 532 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 533 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 534 | "GetChannelOutputVolumeScaling() failed to locate channel"); |
| 535 | return -1; |
| 536 | } |
| 537 | return channelPtr->GetChannelOutputVolumeScaling(scaling); |
| 538 | } |
| 539 | |
| 540 | int VoEVolumeControlImpl::SetOutputVolumePan(int channel, |
| 541 | float left, |
| 542 | float right) |
| 543 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 544 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 545 | "SetOutputVolumePan(channel=%d, left=%2.1f, right=%2.1f)", |
| 546 | channel, left, right); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 547 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 548 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 549 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 550 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 551 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 552 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 553 | return -1; |
| 554 | } |
| 555 | |
| 556 | bool available(false); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 557 | _shared->audio_device()->StereoPlayoutIsAvailable(&available); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 558 | if (!available) |
| 559 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 560 | _shared->SetLastError(VE_FUNC_NO_STEREO, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 561 | "SetOutputVolumePan() stereo playout not supported"); |
| 562 | return -1; |
| 563 | } |
| 564 | if ((left < kMinOutputVolumePanning) || |
| 565 | (left > kMaxOutputVolumePanning) || |
| 566 | (right < kMinOutputVolumePanning) || |
| 567 | (right > kMaxOutputVolumePanning)) |
| 568 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 569 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 570 | "SetOutputVolumePan() invalid parameter"); |
| 571 | return -1; |
| 572 | } |
| 573 | |
| 574 | if (channel == -1) |
| 575 | { |
| 576 | // Master balance (affectes the signal after output mixing) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 577 | return _shared->output_mixer()->SetOutputVolumePan(left, right); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 578 | } |
| 579 | else |
| 580 | { |
| 581 | // Per-channel balance (affects the signal before output mixing) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 582 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 583 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 584 | if (channelPtr == NULL) |
| 585 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 586 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 587 | "SetOutputVolumePan() failed to locate channel"); |
| 588 | return -1; |
| 589 | } |
| 590 | return channelPtr->SetOutputVolumePan(left, right); |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | int VoEVolumeControlImpl::GetOutputVolumePan(int channel, |
| 596 | float& left, |
| 597 | float& right) |
| 598 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 599 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 600 | "GetOutputVolumePan(channel=%d, left=?, right=?)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 601 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame^] | 602 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 603 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 604 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 605 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 606 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 607 | return -1; |
| 608 | } |
| 609 | |
| 610 | bool available(false); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 611 | _shared->audio_device()->StereoPlayoutIsAvailable(&available); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 612 | if (!available) |
| 613 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 614 | _shared->SetLastError(VE_FUNC_NO_STEREO, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 615 | "GetOutputVolumePan() stereo playout not supported"); |
| 616 | return -1; |
| 617 | } |
| 618 | |
| 619 | if (channel == -1) |
| 620 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 621 | return _shared->output_mixer()->GetOutputVolumePan(left, right); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 622 | } |
| 623 | else |
| 624 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 625 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 626 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 627 | if (channelPtr == NULL) |
| 628 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 629 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 630 | "GetOutputVolumePan() failed to locate channel"); |
| 631 | return -1; |
| 632 | } |
| 633 | return channelPtr->GetOutputVolumePan(left, right); |
| 634 | } |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | #endif // #ifdef WEBRTC_VOICE_ENGINE_VOLUME_CONTROL_API |
| 639 | |
| 640 | } // namespace webrtc |