Changeset 91601 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Oct 6, 2021 5:20:51 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r91598 r91601 38 38 # include <alsa/version.h> 39 39 # include "DrvHostAudioAlsaStubs.h" 40 #endif 41 #ifdef VBOX_WITH_AUDIO_OSS 42 # include <fcntl.h> 43 # include <sys/ioctl.h> 44 # include <sys/mman.h> 45 # include <sys/soundcard.h> 40 46 #endif 41 47 #ifdef RT_OS_WINDOWS … … 80 86 *********************************************************************************************************************************/ 81 87 88 #ifdef VBOX_WITH_AUDIO_ALSA 82 89 /** 83 * Sets the system's master volume , if available.84 * 85 * @returns VBox status code. VERR_NOT_SUPPORTED if not supported.90 * Sets the system's master volume via ALSA, if available. 91 * 92 * @returns VBox status code. 86 93 * @param uVolPercent Volume (in percent) to set. 87 94 */ 88 int audioTestSetMasterVolume(unsigned uVolPercent) 89 { 90 #ifdef VBOX_WITH_AUDIO_ALSA 95 static int audioTestSetMasterVolumeALSA(unsigned uVolPercent) 96 { 91 97 int rc = audioLoadAlsaLib(); 92 98 if (RT_FAILURE(rc)) … … 143 149 # undef ALSA_CHECK_RET 144 150 # undef ALSA_CHECK_ERR_RET 145 146 #elif defined(RT_OS_WINDOWS) 147 151 } 152 #endif /* VBOX_WITH_AUDIO_ALSA */ 153 154 #ifdef VBOX_WITH_AUDIO_OSS 155 /** 156 * Sets the system's master volume via OSS, if available. 157 * 158 * @returns VBox status code. 159 * @param uVolPercent Volume (in percent) to set. 160 */ 161 static int audioTestSetMasterVolumeOSS(unsigned uVolPercent) 162 { 163 int hFile = open("/dev/dsp", O_WRONLY | O_NONBLOCK, 0); 164 if (hFile == -1) 165 { 166 /* Try opening the mixing device instead. */ 167 hFile = open("/dev/mixer", O_RDONLY | O_NONBLOCK, 0); 168 } 169 170 if (hFile != -1) 171 { 172 /* OSS maps 0 (muted) - 100 (max), so just use uVolPercent unmodified here. */ 173 uint16_t uVol = RT_MAKE_U16(uVolPercent, uVolPercent); 174 AssertLogRelMsgReturnStmt(ioctl(hFile, SOUND_MIXER_PCM /* SNDCTL_DSP_SETPLAYVOL */, &uVol) >= 0, 175 ("OSS: Failed to set DSP playback volume: %s (%d)\n", 176 strerror(errno), errno), close(hFile), RTErrConvertFromErrno(errno)); 177 return VINF_SUCCESS; 178 } 179 180 return VERR_NOT_SUPPORTED; 181 } 182 #endif /* VBOX_WITH_AUDIO_OSS */ 183 184 #ifdef RT_OS_WINDOWS 185 static int audioTestSetMasterVolumeWASAPI(unsigned uVolPercent) 186 { 148 187 HRESULT hr; 149 188 … … 186 225 187 226 # undef WASAPI_CHECK_HR_RET 188 189 #else 190 191 RT_NOREF(uVolPercent); 227 } 228 #endif /* RT_OS_WINDOWS */ 229 230 /** 231 * Sets the system's master volume, if available. 232 * 233 * @returns VBox status code. VERR_NOT_SUPPORTED if not supported. 234 * @param uVolPercent Volume (in percent) to set. 235 */ 236 int audioTestSetMasterVolume(unsigned uVolPercent) 237 { 238 int rc = VINF_SUCCESS; 239 240 #ifdef VBOX_WITH_AUDIO_ALSA 241 rc = audioTestSetMasterVolumeALSA(uVolPercent); 242 if (RT_SUCCESS(rc)) 243 return rc; 244 /* else try OSS (if available) below. */ 245 #endif /* VBOX_WITH_AUDIO_ALSA */ 246 247 #ifdef VBOX_WITH_AUDIO_OSS 248 rc = audioTestSetMasterVolumeOSS(uVolPercent); 249 if (RT_SUCCESS(rc)) 250 return rc; 251 #endif /* VBOX_WITH_AUDIO_OSS */ 252 253 #ifdef RT_OS_WINDOWS 254 rc = audioTestSetMasterVolumeWASAPI(uVolPercent); 255 if (RT_SUCCESS(rc)) 256 return rc; 257 #endif 258 259 RT_NOREF(uVolPercent); 192 260 /** @todo Port other platforms. */ 193 261 return VERR_NOT_SUPPORTED; 194 #endif195 262 } 196 263
Note:
See TracChangeset
for help on using the changeset viewer.