Changeset 91571 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Oct 5, 2021 3:37:20 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 147280
- Location:
- trunk/src/VBox/ValidationKit/utils/audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/Makefile.kmk
r91454 r91571 77 77 vkat_INCS = \ 78 78 $(PATH_ROOT)/src/VBox/Devices/build \ 79 $(PATH_ROOT)/src/VBox/Devices 79 $(PATH_ROOT)/src/VBox/Devices \ 80 $(PATH_ROOT)/src/VBox/Devices/Audio 80 81 vkat_SOURCES = \ 81 82 vkat.cpp \ -
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r91570 r91571 32 32 #include <iprt/log.h> 33 33 34 #ifdef VBOX_WITH_AUDIO_ALSA 35 # include "DrvHostAudioAlsaStubsMangling.h" 36 # include <alsa/asoundlib.h> 37 # include <alsa/control.h> /* For device enumeration. */ 38 # include <alsa/version.h> 39 # include "DrvHostAudioAlsaStubs.h" 40 #endif 41 34 42 #include <iprt/ctype.h> 35 43 #include <iprt/dir.h> … … 59 67 static int audioTestStreamDestroy(PAUDIOTESTENV pTstEnv, PAUDIOTESTSTREAM pStream); 60 68 69 70 /********************************************************************************************************************************* 71 * Volume handling. * 72 *********************************************************************************************************************************/ 73 74 /** 75 * Sets the system's master volume, if available. 76 * 77 * @returns VBox status code. VERR_NOT_SUPPORTED if not supported. 78 * @param uPercentVol Volume (in percent) to set. 79 */ 80 int audioTestSetMasterVolume(unsigned uPercentVol) 81 { 82 #ifdef VBOX_WITH_AUDIO_ALSA 83 int rc = audioLoadAlsaLib(); 84 if (RT_FAILURE(rc)) 85 return rc; 86 87 int err; 88 snd_mixer_t *handle; 89 90 # define ALSA_CHECK_RET(a_Exp, a_Text) \ 91 if (!(a_Exp)) \ 92 { \ 93 AssertLogRelMsg(a_Exp, a_Text); \ 94 if (handle) \ 95 snd_mixer_close(handle); \ 96 return VERR_GENERAL_FAILURE; \ 97 } 98 99 # define ALSA_CHECK_ERR_RET(a_Text) \ 100 ALSA_CHECK_RET(err >= 0, a_Text) 101 102 err = snd_mixer_open(&handle, 0 /* Index */); 103 ALSA_CHECK_ERR_RET(("ALSA: Failed to open mixer: %s\n", snd_strerror(err))); 104 err = snd_mixer_attach(handle, "default"); 105 ALSA_CHECK_ERR_RET(("ALSA: Failed to attach to default sink: %s\n", snd_strerror(err))); 106 err = snd_mixer_selem_register(handle, NULL, NULL); 107 ALSA_CHECK_ERR_RET(("ALSA: Failed to attach to default sink: %s\n", snd_strerror(err))); 108 err = snd_mixer_load(handle); 109 ALSA_CHECK_ERR_RET(("ALSA: Failed to load mixer: %s\n", snd_strerror(err))); 110 111 snd_mixer_selem_id_t *sid = NULL; 112 snd_mixer_selem_id_alloca(&sid); 113 114 snd_mixer_selem_id_set_index(sid, 0 /* Index */); 115 snd_mixer_selem_id_set_name(sid, "Master"); 116 117 snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid); 118 ALSA_CHECK_RET(elem != NULL, ("ALSA: Failed to find mixer element: %s\n", snd_strerror(err))); 119 120 long uVolMin, uVolMax; 121 122 snd_mixer_selem_get_playback_volume_range(elem, &uVolMin, &uVolMax); 123 ALSA_CHECK_ERR_RET(("ALSA: Failed to get playback volume range: %s\n", snd_strerror(err))); 124 125 long const uVol = RT_MIN(uPercentVol, 100) * uVolMax / 100; 126 127 err = snd_mixer_selem_set_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, uVol); 128 ALSA_CHECK_ERR_RET(("ALSA: Failed to set playback volume left: %s\n", snd_strerror(err))); 129 err = snd_mixer_selem_set_playback_volume(elem, SND_MIXER_SCHN_FRONT_RIGHT, uVol); 130 ALSA_CHECK_ERR_RET(("ALSA: Failed to set playback volume right: %s\n", snd_strerror(err))); 131 132 snd_mixer_close(handle); 133 134 return VINF_SUCCESS; 135 136 # undef ALSA_CHECK_RET 137 # undef ALSA_CHECK_ERR_RET 138 139 #endif /* VBOX_WITH_AUDIO_ALSA */ 140 141 /** @todo Port other platforms. */ 142 return VERR_NOT_SUPPORTED; 143 } 61 144 62 145 /********************************************************************************************************************************* … … 256 339 AssertRCReturn(rc, rc); 257 340 } 341 342 /* Try to crank up the system's master volume up to 100% so that we (hopefully) play the test tone always at the same leve. 343 * Not supported on all platforms yet, therefore not critical for overall testing (yet). */ 344 unsigned const uVolPercent = 100; 345 int rc2 = audioTestSetMasterVolume(uVolPercent); 346 if (RT_FAILURE(rc2)) 347 { 348 if (rc2 == VERR_NOT_SUPPORTED) 349 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Setting system's master volume is not supported on this platform, skipping\n"); 350 else 351 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Setting system's master volume failed with %Rrc\n", rc2); 352 } 353 else 354 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Set system's master volume to %RU8%%\n", uVolPercent); 258 355 259 356 rc = AudioTestMixStreamEnable(&pStream->Mix); … … 426 523 if (pTstEnv) 427 524 { 428 intrc2 = AudioTestObjClose(Obj);525 rc2 = AudioTestObjClose(Obj); 429 526 if (RT_SUCCESS(rc)) 430 527 rc = rc2;
Note:
See TracChangeset
for help on using the changeset viewer.