VirtualBox

Ignore:
Timestamp:
Oct 6, 2021 5:20:51 PM (3 years ago)
Author:
vboxsync
Message:

Audio/Validation Kit: Implemented setting the system's master volume to 100% on OSS. Untested. ​​bugref:10008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp

    r91598 r91601  
    3838# include <alsa/version.h>
    3939# 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>
    4046#endif
    4147#ifdef RT_OS_WINDOWS
     
    8086*********************************************************************************************************************************/
    8187
     88#ifdef VBOX_WITH_AUDIO_ALSA
    8289/**
    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.
    8693 * @param   uVolPercent         Volume (in percent) to set.
    8794 */
    88 int audioTestSetMasterVolume(unsigned uVolPercent)
    89 {
    90 #ifdef VBOX_WITH_AUDIO_ALSA
     95static int audioTestSetMasterVolumeALSA(unsigned uVolPercent)
     96{
    9197    int rc = audioLoadAlsaLib();
    9298    if (RT_FAILURE(rc))
     
    143149# undef ALSA_CHECK_RET
    144150# 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 */
     161static 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
     185static int audioTestSetMasterVolumeWASAPI(unsigned uVolPercent)
     186{
    148187    HRESULT hr;
    149188
     
    186225
    187226# 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 */
     236int 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);
    192260    /** @todo Port other platforms. */
    193261   return VERR_NOT_SUPPORTED;
    194 #endif
    195262}
    196263
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette