Changeset 91452 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Sep 29, 2021 9:31:46 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCmdGeneric.cpp
r91451 r91452 191 191 * Command: play * 192 192 *********************************************************************************************************************************/ 193 194 /** 195 * Structure holding additional playback options. 196 */ 197 typedef struct AUDIOTESTPLAYOPTS 198 { 199 /** Whether to use the audio connector or not. */ 200 bool fWithDrvAudio; 201 /** Whether to use a mixing buffer or not. */ 202 bool fWithMixer; 203 /** Buffer size (in ms). */ 204 uint32_t cMsBufferSize; 205 /** Pre-buffering size (in ms). */ 206 uint32_t cMsPreBuffer; 207 /** Scheduling (in ms). */ 208 uint32_t cMsSchedulingHint; 209 /** Audio vlume to use (in percent). */ 210 uint8_t uVolumePercent; 211 /** PCM audio properties to use. */ 212 PDMAUDIOPCMPROPS Props; 213 } AUDIOTESTPLAYOPTS; 214 /** Pointer to additional playback options. */ 215 typedef AUDIOTESTPLAYOPTS *PAUDIOTESTPLAYOPTS; 193 216 194 217 /** … … 277 300 } 278 301 279 280 302 /** 281 303 * Worker for audioTestCmdPlayHandler that plays one file. 282 304 */ 283 static RTEXITCODE audioTestPlayOne(const char *pszFile, PCPDMDRVREG pDrvReg, const char *pszDevId, uint32_t cMsBufferSize, 284 uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint, 285 uint8_t cChannels, uint8_t cbSample, uint32_t uHz, uint8_t uVolumePercent, 286 bool fWithDrvAudio, bool fWithMixer) 305 static RTEXITCODE audioTestPlayOne(const char *pszFile, PCPDMDRVREG pDrvReg, const char *pszDevId, 306 PAUDIOTESTPLAYOPTS pOpts) 287 307 { 288 308 char szTmp[128]; … … 312 332 RTEXITCODE rcExit = RTEXITCODE_FAILURE; 313 333 AUDIOTESTDRVSTACK DrvStack; 314 rc = audioTestDriverStackInit(&DrvStack, pDrvReg, fWithDrvAudio);334 rc = audioTestDriverStackInit(&DrvStack, pDrvReg, pOpts->fWithDrvAudio); 315 335 if (RT_SUCCESS(rc)) 316 336 { … … 324 344 * Open a stream for the output. 325 345 */ 346 uint8_t const cChannels = PDMAudioPropsChannels(&pOpts->Props); 347 326 348 PDMAUDIOPCMPROPS ReqProps = WaveFile.Props; 327 349 if (cChannels != 0 && PDMAudioPropsChannels(&ReqProps) != cChannels) 328 350 PDMAudioPropsSetChannels(&ReqProps, cChannels); 351 352 uint8_t const cbSample = PDMAudioPropsSampleSize(&pOpts->Props); 329 353 if (cbSample != 0) 330 354 PDMAudioPropsSetSampleSize(&ReqProps, cbSample); 355 356 uint32_t const uHz = PDMAudioPropsHz(&pOpts->Props); 331 357 if (uHz != 0) 332 358 ReqProps.uHz = uHz; … … 334 360 PDMAUDIOSTREAMCFG CfgAcq; 335 361 PPDMAUDIOSTREAM pStream = NULL; 336 rc = audioTestDriverStackStreamCreateOutput(&DrvStack, &ReqProps, cMsBufferSize,337 cMsPreBuffer,cMsSchedulingHint, &pStream, &CfgAcq);362 rc = audioTestDriverStackStreamCreateOutput(&DrvStack, &ReqProps, pOpts->cMsBufferSize, 363 pOpts->cMsPreBuffer, pOpts->cMsSchedulingHint, &pStream, &CfgAcq); 338 364 if (RT_SUCCESS(rc)) 339 365 { … … 342 368 * output parameters doesn't match. 343 369 */ 344 if ( ! fWithMixer370 if ( !pOpts->fWithMixer 345 371 && ( !PDMAudioPropsAreEqual(&WaveFile.Props, &pStream->Cfg.Props) 346 || uVolumePercent != 100)372 || pOpts->uVolumePercent != 100) 347 373 ) 348 374 { 349 375 RTMsgInfo("Enabling the mixer buffer.\n"); 350 fWithMixer = true;376 pOpts->fWithMixer = true; 351 377 } 352 378 … … 356 382 */ 357 383 AUDIOTESTDRVMIXSTREAM Mix; 358 rc = AudioTestMixStreamInit(&Mix, &DrvStack, pStream, fWithMixer ? &WaveFile.Props : NULL, 100 /*ms*/);384 rc = AudioTestMixStreamInit(&Mix, &DrvStack, pStream, pOpts->fWithMixer ? &WaveFile.Props : NULL, 100 /*ms*/); 359 385 if (RT_SUCCESS(rc)) 360 386 { … … 362 388 RTMsgInfo("Stream: %s cbBackend=%#RX32%s\n", 363 389 PDMAudioPropsToString(&pStream->Cfg.Props, szTmp, sizeof(szTmp)), 364 pStream->cbBackend, fWithMixer ? " mixed" : "");365 366 if ( fWithMixer)367 AudioTestMixStreamSetVolume(&Mix, uVolumePercent);390 pStream->cbBackend, pOpts->fWithMixer ? " mixed" : ""); 391 392 if (pOpts->fWithMixer) 393 AudioTestMixStreamSetVolume(&Mix, pOpts->uVolumePercent); 368 394 369 395 /* … … 400 426 */ 401 427 static RTEXITCODE audioTestPlayTestToneOne(PAUDIOTESTTONEPARMS pToneParms, 402 PCPDMDRVREG pDrvReg, const char *pszDevId, uint32_t cMsBufferSize, 403 uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint, 404 uint8_t cChannels, uint8_t cbSample, uint32_t uHz, 405 bool fWithDrvAudio, bool fWithMixer) 428 PCPDMDRVREG pDrvReg, const char *pszDevId, 429 PAUDIOTESTPLAYOPTS pOpts) 406 430 { 407 431 char szTmp[128]; … … 415 439 RTEXITCODE rcExit = RTEXITCODE_FAILURE; 416 440 AUDIOTESTDRVSTACK DrvStack; 417 int rc = audioTestDriverStackInit(&DrvStack, pDrvReg, fWithDrvAudio);441 int rc = audioTestDriverStackInit(&DrvStack, pDrvReg, pOpts->fWithDrvAudio); 418 442 if (RT_SUCCESS(rc)) 419 443 { … … 427 451 * Open a stream for the output. 428 452 */ 453 uint8_t const cChannels = PDMAudioPropsChannels(&pOpts->Props); 454 429 455 PDMAUDIOPCMPROPS ReqProps = pToneParms->Props; 430 456 if (cChannels != 0 && PDMAudioPropsChannels(&ReqProps) != cChannels) 431 457 PDMAudioPropsSetChannels(&ReqProps, cChannels); 458 459 uint8_t const cbSample = PDMAudioPropsSampleSize(&pOpts->Props); 432 460 if (cbSample != 0) 433 461 PDMAudioPropsSetSampleSize(&ReqProps, cbSample); 462 463 uint32_t const uHz = PDMAudioPropsHz(&pOpts->Props); 434 464 if (uHz != 0) 435 465 ReqProps.uHz = uHz; 436 466 437 rc = audioTestDriverStackStreamCreateOutput(&DrvStack, &ReqProps, cMsBufferSize,438 cMsPreBuffer,cMsSchedulingHint, &TstStream.pStream, &TstStream.Cfg);467 rc = audioTestDriverStackStreamCreateOutput(&DrvStack, &ReqProps, pOpts->cMsBufferSize, 468 pOpts->cMsPreBuffer, pOpts->cMsSchedulingHint, &TstStream.pStream, &TstStream.Cfg); 439 469 if (RT_SUCCESS(rc)) 440 470 { … … 443 473 * output parameters doesn't match. 444 474 */ 445 if ( ! fWithMixer475 if ( !pOpts->fWithMixer 446 476 && ( !PDMAudioPropsAreEqual(&pToneParms->Props, &TstStream.pStream->Cfg.Props) 447 477 || pToneParms->uVolumePercent != 100) … … 449 479 { 450 480 RTMsgInfo("Enabling the mixer buffer.\n"); 451 fWithMixer = true;481 pOpts->fWithMixer = true; 452 482 } 453 483 … … 456 486 * is false, otherwise it's doing mixing, resampling and recoding. 457 487 */ 458 rc = AudioTestMixStreamInit(&TstStream.Mix, &DrvStack, TstStream.pStream, fWithMixer ? &pToneParms->Props : NULL, 100 /*ms*/); 488 rc = AudioTestMixStreamInit(&TstStream.Mix, &DrvStack, TstStream.pStream, 489 pOpts->fWithMixer ? &pToneParms->Props : NULL, 100 /*ms*/); 459 490 if (RT_SUCCESS(rc)) 460 491 { … … 462 493 RTMsgInfo("Stream: %s cbBackend=%#RX32%s\n", 463 494 PDMAudioPropsToString(&TstStream.pStream->Cfg.Props, szTmp, sizeof(szTmp)), 464 TstStream.pStream->cbBackend, fWithMixer ? " mixed" : "");495 TstStream.pStream->cbBackend, pOpts->fWithMixer ? " mixed" : ""); 465 496 466 497 /* … … 470 501 if (RT_SUCCESS(rc)) 471 502 { 472 if ( fWithMixer)503 if (pOpts->fWithMixer) 473 504 AudioTestMixStreamSetVolume(&TstStream.Mix, pToneParms->uVolumePercent); 474 505 … … 556 587 /* Option values: */ 557 588 PCPDMDRVREG pDrvReg = AudioTestGetDefaultBackend(); 558 uint32_t cMsBufferSize = UINT32_MAX;559 uint32_t cMsPreBuffer = UINT32_MAX;560 uint32_t cMsSchedulingHint = UINT32_MAX;561 589 const char *pszDevId = NULL; 562 bool fWithDrvAudio = false;563 bool fWithMixer = false;564 590 uint32_t cTestTones = 0; 565 591 uint8_t cbSample = 0; 566 592 uint8_t cChannels = 0; 567 593 uint32_t uHz = 0; 568 uint8_t uVolumePercent = 100; /* Use maximum volume by default. */ 594 595 AUDIOTESTPLAYOPTS PlayOpts; 596 RT_ZERO(PlayOpts); 597 598 PlayOpts.uVolumePercent = 100; /* Use maximum volume by default. */ 569 599 570 600 /* Argument processing loop: */ … … 586 616 587 617 case 'd': 588 fWithDrvAudio = true;618 PlayOpts.fWithDrvAudio = true; 589 619 break; 590 620 … … 594 624 595 625 case 'm': 596 fWithMixer = true;626 PlayOpts.fWithMixer = true; 597 627 break; 598 628 … … 610 640 611 641 case VKAT_PLAY_OPT_VOL: 612 uVolumePercent = ValueUnion.u8;613 if ( uVolumePercent > 100)642 PlayOpts.uVolumePercent = ValueUnion.u8; 643 if (PlayOpts.uVolumePercent > 100) 614 644 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid volume (0-100)"); 615 645 break; … … 620 650 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Playing test tones (-t) cannot be combined with playing files"); 621 651 622 RTEXITCODE rcExit = audioTestPlayOne(ValueUnion.psz, pDrvReg, pszDevId, cMsBufferSize, cMsPreBuffer, 623 cMsSchedulingHint, cChannels, cbSample, uHz, uVolumePercent, 624 fWithDrvAudio, fWithMixer); 652 /* Use some sane defaults if no PCM props are set by the user. */ 653 PDMAudioPropsInit(&PlayOpts.Props, 654 cbSample ? cbSample : 2 /* 16-bit */, true /* fSigned */, 655 cChannels ? cChannels : 2 /* Stereo */, uHz ? uHz : 44100); 656 657 RTEXITCODE rcExit = audioTestPlayOne(ValueUnion.psz, pDrvReg, pszDevId, &PlayOpts); 625 658 if (rcExit != RTEXITCODE_SUCCESS) 626 659 return rcExit; … … 653 686 #endif 654 687 ToneParms.msSequel = 0; /** @todo Implement analyzing this first! */ 655 ToneParms.uVolumePercent = uVolumePercent; 656 657 RTEXITCODE rcExit = audioTestPlayTestToneOne(&ToneParms, pDrvReg, pszDevId, cMsBufferSize, cMsPreBuffer, 658 cMsSchedulingHint, cChannels, cbSample, uHz, fWithDrvAudio, fWithMixer); 688 ToneParms.uVolumePercent = PlayOpts.uVolumePercent; 689 690 RTEXITCODE rcExit = audioTestPlayTestToneOne(&ToneParms, pDrvReg, pszDevId, &PlayOpts); 659 691 if (rcExit != RTEXITCODE_SUCCESS) 660 692 return rcExit;
Note:
See TracChangeset
for help on using the changeset viewer.