| 235 | } |
| 236 | |
| 237 | int VolumeControl::getVolume() const |
| 238 | { |
| 239 | int volume = 0; |
| 240 | |
| 241 | #if defined (__APPLE__) |
| 242 | #error TODO: Not implemented for MacOS yet!!! |
| 243 | #elif defined(__linux__) |
| 244 | if (mixerElem != nullptr) |
| 245 | { |
| 246 | //get volume range |
| 247 | long minVolume; |
| 248 | long maxVolume; |
| 249 | if (snd_mixer_selem_get_playback_volume_range(mixerElem, &minVolume, &maxVolume) == 0) |
| 250 | { |
| 251 | //ok. now get volume |
| 252 | long rawVolume; |
| 253 | if (snd_mixer_selem_get_playback_volume(mixerElem, SND_MIXER_SCHN_MONO, &rawVolume) == 0) |
| 254 | { |
| 255 | //worked. bring into range 0-100 |
| 256 | rawVolume -= minVolume; |
| 257 | if (rawVolume > 0) |
| 258 | { |
| 259 | volume = (rawVolume * 100) / (maxVolume - minVolume); |
| 260 | } |
| 261 | //else volume = 0; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!"; |
| 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | LOG(LogError) << "VolumeControl::getVolume() - Failed to get volume range!"; |
| 271 | } |
| 272 | } |
| 273 | #elif defined(WIN32) || defined(_WIN32) |
| 274 | if (mixerHandle != nullptr) |
| 275 | { |
| 276 | //Windows older than Vista. use mixer API. get volume from line control |
| 277 | MIXERCONTROLDETAILS_UNSIGNED value; |
| 278 | MIXERCONTROLDETAILS mixerControlDetails; |
| 279 | mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS); |
| 280 | mixerControlDetails.dwControlID = mixerControl.dwControlID; |
| 281 | mixerControlDetails.cChannels = 1; //always 1 for a MIXERCONTROL_CONTROLF_UNIFORM control |
| 282 | mixerControlDetails.cMultipleItems = 0; //always 0 except for a MIXERCONTROL_CONTROLF_MULTIPLE control |
| 283 | mixerControlDetails.paDetails = &value; |
| 284 | mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); |
| 285 | if (mixerGetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR) |
| 286 | { |
| 287 | volume = (uint8_t)((value.dwValue * 100) / 65535); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!"; |
| 292 | } |
| 293 | } |
| 294 | else if (endpointVolume != nullptr) |
no outgoing calls
no test coverage detected