Changeset 57375 in vbox for trunk/src/VBox
- Timestamp:
- Aug 17, 2015 11:16:04 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r57234 r57375 28 28 #include "VBoxDD.h" 29 29 30 #define DSLOG(a) do { LogRel2(a); } while(0)31 #define DSLOGF(a) do { LogRel3(a); } while(0)32 #define DSLOGREL(a) \33 do { \34 static int8_t scLogged = 0; \35 if (scLogged < 8) { \36 ++scLogged; \37 LogRel(a); \38 } \39 else { \40 DSLOG(a); \41 } \42 } while (0)43 44 30 typedef struct DSOUNDHOSTCFG 45 31 { … … 62 48 /** List of found host output devices. */ 63 49 RTLISTANCHOR lstDevOutput; 64 /** Configuration options. */50 /** DirectSound configuration options. */ 65 51 DSOUNDHOSTCFG cfg; 66 52 } DRVHOSTDSOUND, *PDRVHOSTDSOUND; … … 68 54 typedef struct DSOUNDSTREAMOUT 69 55 { 70 PDMAUDIOHSTSTRMOUT hw; /* Always must come first! */56 PDMAUDIOHSTSTRMOUT strmOut; /* Always must come first! */ 71 57 LPDIRECTSOUND8 pDS; 72 58 LPDIRECTSOUNDBUFFER8 pDSB; … … 79 65 typedef struct DSOUNDSTREAMIN 80 66 { 81 PDMAUDIOHSTSTRMIN hw; /* Always must come first! */67 PDMAUDIOHSTSTRMIN strmIn; /* Always must come first! */ 82 68 LPDIRECTSOUNDCAPTURE8 pDSC; 83 69 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB; … … 105 91 } DSOUNDDEV, *PDSOUNDDEV; 106 92 93 /** Maximum number of release logging entries. */ 94 static uint32_t s_cMaxRelLogEntries = 32; 95 107 96 /** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */ 108 97 #define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \ … … 157 146 static char *dsoundGUIDToUtf8StrA(LPCGUID lpGUID) 158 147 { 159 LPOLESTR lpOLEStr; 160 HRESULT hr = StringFromCLSID(*lpGUID, &lpOLEStr); 161 if (SUCCEEDED(hr)) 162 { 163 char *pszGUID; 164 int rc = RTUtf16ToUtf8(lpOLEStr, &pszGUID); 165 CoTaskMemFree(lpOLEStr); 166 167 return RT_SUCCESS(rc) ? pszGUID : NULL; 168 } 169 170 return NULL; 148 if (lpGUID) 149 { 150 LPOLESTR lpOLEStr; 151 HRESULT hr = StringFromCLSID(*lpGUID, &lpOLEStr); 152 if (SUCCEEDED(hr)) 153 { 154 char *pszGUID; 155 int rc = RTUtf16ToUtf8(lpOLEStr, &pszGUID); 156 CoTaskMemFree(lpOLEStr); 157 158 return RT_SUCCESS(rc) ? pszGUID : NULL; 159 } 160 } 161 162 return RTStrDup("<GUID not found>"); 171 163 } 172 164 … … 193 185 return VINF_SUCCESS; 194 186 195 DSLOGREL(("DSound: Restore playback buffer%Rhrc\n", hr));187 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error restoring playback buffer: %Rhrc\n", hr)); 196 188 return VERR_INVALID_STATE; 197 189 } … … 205 197 return VINF_SUCCESS; 206 198 207 DSLOG(("DSound: Unable to unlock output buffer, hr=%Rhrc\n", hr));199 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking output buffer: %Rhrc\n", hr)); 208 200 return VERR_ACCESS_DENIED; 209 201 } … … 217 209 return VINF_SUCCESS; 218 210 219 DSLOG(("DSound: Unable to unlock input buffer, hr=%Rhrc\n", hr));211 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking input buffer: %Rhrc\n", hr)); 220 212 return VERR_ACCESS_DENIED; 221 213 } … … 241 233 { 242 234 hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags); 243 } 244 } 245 246 if (FAILED(hr) || RT_FAILURE(rc)) 247 { 248 DSLOG(("DSound: Unable to lock output buffer, hr=%Rhrc\n", hr)); 249 return RT_SUCCESS(rc) ? VERR_ACCESS_DENIED: rc; 235 if (FAILED(hr)) 236 rc = VERR_ACCESS_DENIED; 237 } 238 } 239 240 if (RT_FAILURE(rc)) 241 { 242 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking output buffer: %Rhrc\n", hr)); 243 return rc; 250 244 } 251 245 … … 253 247 || (pv2 && (cb2 & pProps->uAlign))) 254 248 { 255 DSLOG(("DSound: lock output returned misaligned buffer: cb1=%d, cb2=%d\n", cb1, cb2)); 249 LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n", 250 cb1, cb2, pProps->uAlign)); 256 251 dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2); 257 252 return VERR_INVALID_STATE; … … 281 276 if (FAILED(hr)) 282 277 { 283 DSLOG(("DSound: Unable to lock capturing buffer, hr=%Rhrc\n", hr));278 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking capturing buffer: %Rhrc\n", hr)); 284 279 return VERR_ACCESS_DENIED; 285 280 } … … 288 283 || (pv2 && (cb2 & pProps->uAlign))) 289 284 { 290 DSLOG(("DSound: lock input returned misaligned buffer: cb1=%d, cb2=%d\n", cb1, cb2)); 285 LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n", 286 cb1, cb2, pProps->uAlign)); 291 287 dsoundUnlockInput(pDSCB, pv1, pv2, cb1, cb2); 292 288 return VERR_INVALID_PARAMETER; … … 319 315 if (pDSoundStrmOut->pDS != NULL) 320 316 { 321 DSLOG(("DSound:DirectSound instance already exists\n"));317 LogFlowFunc(("DirectSound instance already exists\n")); 322 318 return VINF_SUCCESS; 323 319 } … … 327 323 if (FAILED(hr)) 328 324 { 329 DSLOGREL(("DSound: DirectSound create instance%Rhrc\n", hr));325 LogRel(("DSound: Error creating DirectSound instance: %Rhrc\n", hr)); 330 326 } 331 327 else … … 334 330 if (SUCCEEDED(hr)) 335 331 { 336 HWND hwnd = GetDesktopWindow(); 337 hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hwnd, DSSCL_PRIORITY); 338 if (FAILED (hr)) 339 { 340 DSLOGREL(("DSound: Set cooperative level for window %p %Rhrc\n", hwnd, hr)); 341 } 332 HWND hWnd = GetDesktopWindow(); 333 hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hWnd, DSSCL_PRIORITY); 334 if (FAILED(hr)) 335 LogRel(("DSound: Error setting cooperative level for window %p: %Rhrc\n", hWnd, hr)); 342 336 } 343 337 if (FAILED(hr)) 344 338 { 345 339 if (hr == DSERR_NODRIVER) 346 { 347 DSLOGREL(("DSound: DirectSound playback is currently unavailable\n")); 348 } 340 LogRel(("DSound: DirectSound playback is currently unavailable\n")); 349 341 else 350 { 351 DSLOGREL(("DSound: DirectSound initialize %Rhrc\n", hr)); 352 } 342 LogRel(("DSound: Error initializing DirectSound: %Rhrc\n", hr)); 343 353 344 dsoundPlayInterfaceRelease(pDSoundStrmOut); 354 345 } … … 360 351 static void dsoundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut) 361 352 { 362 DSLOG(("DSound: playback close %p buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));353 LogFlowFunc(("Closing playback stream %p (buffer %p)\n", pDSoundStrmOut, pDSoundStrmOut->pDSB)); 363 354 364 355 if (pDSoundStrmOut->pDSB) … … 366 357 HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 367 358 if (FAILED(hr)) 368 { 369 DSLOGREL(("DSound: Playback close Stop %Rhrc\n", hr)); 370 } 359 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error closing playback stream %p: %Rhrc\n", pDSoundStrmOut, hr)); 371 360 372 361 IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB); … … 379 368 static int dsoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 380 369 { 381 DSLOG(("DSound: playback open %p size %u bytes, freq %u, chan %u, bits %u, sign %d\n", 382 pDSoundStrmOut, 383 pThis->cfg.cbBufferOut, 384 pDSoundStrmOut->hw.Props.uHz, 385 pDSoundStrmOut->hw.Props.cChannels, 386 pDSoundStrmOut->hw.Props.cBits, 387 pDSoundStrmOut->hw.Props.fSigned)); 370 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 371 AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER); 372 373 LogFlowFunc(("pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n", 374 pDSoundStrmOut, 375 pThis->cfg.cbBufferOut, 376 pDSoundStrmOut->strmOut.Props.uHz, 377 pDSoundStrmOut->strmOut.Props.cChannels, 378 pDSoundStrmOut->strmOut.Props.cBits, 379 pDSoundStrmOut->strmOut.Props.fSigned)); 388 380 389 381 if (pDSoundStrmOut->pDSB != NULL) 390 382 { 391 383 /* Should not happen but be forgiving. */ 392 DSLOGREL(("DSound:DirectSoundBuffer already exists\n"));384 LogFlowFunc(("DirectSoundBuffer already exists\n")); 393 385 dsoundPlayClose(pDSoundStrmOut); 394 386 } … … 418 410 if (FAILED(hr)) 419 411 { 420 DSLOGREL(("DSound: Playback CreateSoundBuffer%Rhrc\n", hr));412 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating playback stream: %Rhrc\n", hr)); 421 413 break; 422 414 } … … 426 418 if (FAILED(hr)) 427 419 { 428 DSLOGREL(("DSound: Playback QueryInterface%Rhrc\n", hr));420 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying interface for playback stream: %Rhrc\n", hr)); 429 421 break; 430 422 } 431 423 432 424 /* Query the actual parameters. */ 433 434 425 hr = IDirectSoundBuffer8_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL); 435 426 if (FAILED(hr)) 436 427 { 437 DSLOGREL(("DSound: Playback GetFormat%Rhrc\n", hr));428 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for playback stream: %Rhrc\n", hr)); 438 429 break; 439 430 } … … 445 436 if (FAILED(hr)) 446 437 { 447 DSLOGREL(("DSound: Playback GetCaps%Rhrc\n", hr));438 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for playback stream: %Rhrc\n", hr)); 448 439 break; 449 440 } 450 441 451 DSLOG(("DSound: playback format: size %d bytes\n" 452 " tag = %d\n" 453 " nChannels = %d\n" 454 " nSamplesPerSec = %d\n" 455 " nAvgBytesPerSec = %d\n" 456 " nBlockAlign = %d\n" 457 " wBitsPerSample = %d\n" 458 " cbSize = %d\n", 442 LogFunc(("Playback format:\n" 443 "\tdwBufferBytes = %RI32\n" 444 "\twFormatTag = %RI16\n" 445 "\tnChannels = %RI16\n" 446 "\tnSamplesPerSec = %RU32\n" 447 "\tnAvgBytesPerSec = %RU32\n" 448 "\tnBlockAlign = %RI16\n" 449 "\twBitsPerSample = %RI16\n" 450 "\tcbSize = %RI16\n", 459 451 bc.dwBufferBytes, 460 452 wfx.wFormatTag, … … 466 458 wfx.cbSize)); 467 459 468 if (bc.dwBufferBytes & pDSoundStrmOut->hw.Props.uAlign) 469 { 470 DSLOGREL(("DSound: Playback GetCaps returned misaligned buffer size %ld, alignment %d\n", 471 bc.dwBufferBytes, pDSoundStrmOut->hw.Props.uAlign + 1)); 472 } 460 if (bc.dwBufferBytes & pDSoundStrmOut->strmOut.Props.uAlign) 461 LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback capabilities returned misaligned buffer (size %ld, alignment %RU32)\n", 462 bc.dwBufferBytes, pDSoundStrmOut->strmOut.Props.uAlign + 1)); 473 463 474 464 if (bc.dwBufferBytes != pThis->cfg.cbBufferOut) 475 { 476 DSLOGREL(("DSound: Playback buffer size mismatch dsound %d, requested %d bytes\n", 477 bc.dwBufferBytes, pThis->cfg.cbBufferOut)); 478 } 479 480 /* Initial state. 465 LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback buffer size mismatched (DirectSound %ld, requested %ld bytes)\n", 466 bc.dwBufferBytes, pThis->cfg.cbBufferOut)); 467 468 /* 469 * Initial state. 481 470 * dsoundPlayStart initializes part of it to make sure that Stop/Start continues with a correct 482 471 * playback buffer position. 483 472 */ 484 pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->hw.Props.cShift; 485 DSLOG(("DSound: playback open csPlaybackBufferSize %d samples\n", pDSoundStrmOut->csPlaybackBufferSize)); 473 pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->strmOut.Props.cShift; 474 LogFlowFunc(("csPlaybackBufferSize=%ld\n", pDSoundStrmOut->csPlaybackBufferSize)); 475 486 476 } while (0); 487 477 … … 495 485 static void dsoundPlayClearSamples(PDSOUNDSTREAMOUT pDSoundStrmOut) 496 486 { 487 AssertPtrReturnVoid(pDSoundStrmOut); 488 497 489 LPVOID pv1, pv2; 498 490 DWORD cb1, cb2; 499 int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut-> hw.Props,500 0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut-> hw.Props.cShift,491 int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props, 492 0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift, 501 493 &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER); 502 494 if (RT_SUCCESS(rc)) 503 495 { 504 int len1 = cb1 >> pDSoundStrmOut-> hw.Props.cShift;505 int len2 = cb2 >> pDSoundStrmOut-> hw.Props.cShift;496 int len1 = cb1 >> pDSoundStrmOut->strmOut.Props.cShift; 497 int len2 = cb2 >> pDSoundStrmOut->strmOut.Props.cShift; 506 498 507 499 if (pv1 && len1) 508 audio_pcm_info_clear_buf(&pDSoundStrmOut-> hw.Props, pv1, len1);500 audio_pcm_info_clear_buf(&pDSoundStrmOut->strmOut.Props, pv1, len1); 509 501 510 502 if (pv2 && len2) 511 audio_pcm_info_clear_buf(&pDSoundStrmOut-> hw.Props, pv2, len2);503 audio_pcm_info_clear_buf(&pDSoundStrmOut->strmOut.Props, pv2, len2); 512 504 513 505 dsoundUnlockOutput(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2); … … 517 509 static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus) 518 510 { 511 AssertPtrReturn(pDSB, VERR_INVALID_POINTER); 512 /* pStatus is optional. */ 513 519 514 int rc = VINF_SUCCESS; 520 515 … … 527 522 rc = dsoundPlayRestore(pDSB); 528 523 if (RT_SUCCESS(rc)) 529 {530 524 hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus); 531 }532 525 } 533 526 } … … 535 528 if (FAILED(hr)) 536 529 { 537 DSLOG(("DSound: playback GetStatus%Rhrc\n", hr));530 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting playback status: %Rhrc\n", hr)); 538 531 if (RT_SUCCESS(rc)) 539 {540 532 rc = VERR_NOT_SUPPORTED; 541 }542 533 } 543 534 544 535 if (RT_SUCCESS(rc)) 545 536 { 546 *pStatus = dwStatus; 537 if (pStatus) 538 *pStatus = dwStatus; 547 539 } 548 540 … … 552 544 static void dsoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 553 545 { 546 AssertPtrReturnVoid(pThis); 547 AssertPtrReturnVoid(pDSoundStrmOut); 548 554 549 if (pDSoundStrmOut->pDSB != NULL) 555 550 { … … 558 553 dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus); 559 554 560 DSLOG(("DSound: playback stop\n"));555 LogFlowFunc(("Playback stopped\n")); 561 556 562 557 HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 563 558 if (FAILED(hr)) 564 { 565 DSLOG(("DSound: stop playback buffer %Rhrc\n", hr)); 566 } 559 LogRelMax(s_cMaxRelLogEntries, ("DSound: Errpor stopping playback buffer: %Rhrc\n", hr)); 567 560 } 568 561 } … … 570 563 static int dsoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut) 571 564 { 572 int rc = VINF_SUCCESS; 565 AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER); 566 567 int rc; 573 568 574 569 if (pDSoundStrmOut->pDSB != NULL) 575 570 { 576 571 DWORD dwStatus; 577 int rc2 = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus); 578 if (RT_FAILURE(rc2)) 579 { 580 DSLOG(("DSound: playback start GetStatus %Rrc\n", rc2)); 581 rc = rc2; /* Propagate error. */ 582 } 583 else 572 rc = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus); 573 if (RT_SUCCESS(rc)) 584 574 { 585 575 if (dwStatus & DSBSTATUS_PLAYING) 586 576 { 587 DSLOG(("DSound: already playing\n"));577 LogFlowFunc(("Already playing\n")); 588 578 } 589 579 else … … 593 583 pDSoundStrmOut->fReinitPlayPos = true; 594 584 595 DSLOG(("DSound: playback start\n"));585 LogFlowFunc(("Playback started\n")); 596 586 597 587 HRESULT hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING); 598 588 if (FAILED(hr)) 599 589 { 600 DSLOGREL(("DSound: Playback start%Rhrc\n", hr));590 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting playback: %Rhrc\n", hr)); 601 591 rc = VERR_NOT_SUPPORTED; 602 592 } … … 605 595 } 606 596 else 607 {608 597 rc = VERR_INVALID_STATE; 609 }610 598 611 599 return rc; … … 618 606 static LPCGUID dsoundCaptureSelectDevice(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 619 607 { 608 AssertPtrReturn(pThis, NULL); 609 AssertPtrReturn(pDSoundStrmIn, NULL); 610 620 611 LPCGUID pGUID = pThis->cfg.pGuidCapture; 621 612 … … 630 621 RTListForEach(&pThis->lstDevInput, pDev, DSOUNDDEV, Node) 631 622 { 632 if (RTStrIStr(pDev->pszName, "Mic")) 623 if (RTStrIStr(pDev->pszName, "Mic")) /** @todo what is with non en_us windows versions? */ 633 624 break; 634 625 } 635 626 if (RTListNodeIsDummy(&pThis->lstDevInput, pDev, DSOUNDDEV, Node)) 636 627 pDev = NULL; /* Found nothing. */ 637 } break; 628 629 break; 630 } 638 631 639 632 case PDMAUDIORECSOURCE_LINE_IN: … … 645 638 if (pDev) 646 639 { 647 DSLOG(("DSound: Guest \"%s\" is using host \"%s\"\n",648 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName));640 LogRel2(("DSound: Guest \"%s\" is using host \"%s\"\n", 641 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName)); 649 642 650 643 pGUID = &pDev->Guid; … … 653 646 654 647 char *pszGUID = dsoundGUIDToUtf8StrA(pGUID); 655 LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n", 656 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID ? pszGUID : "NULL")); 657 RTStrFree(pszGUID); 648 if (pszGUID) 649 { 650 LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n", 651 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID)); 652 RTStrFree(pszGUID); 653 } 658 654 659 655 return pGUID; … … 673 669 if (pDSoundStrmIn->pDSC != NULL) 674 670 { 675 DSLOG(("DSound: DirectSoundCapture instance already exists\n"));671 LogFunc(("DSound: DirectSoundCapture instance already exists\n")); 676 672 return VINF_SUCCESS; 677 673 } … … 681 677 if (FAILED(hr)) 682 678 { 683 DSLOGREL(("DSound: DirectSoundCapture create instance%Rhrc\n", hr));679 LogRel(("DSound: Error creating capture instance: %Rhrc\n", hr)); 684 680 } 685 681 else … … 690 686 { 691 687 if (hr == DSERR_NODRIVER) 692 { 693 DSLOGREL(("DSound: DirectSound capture is currently unavailable\n")); 694 } 688 LogRel(("DSound: DirectSound capture is currently unavailable\n")); 695 689 else 696 { 697 DSLOGREL(("DSound: DirectSoundCapture initialize %Rhrc\n", hr)); 698 } 690 LogRel(("DSound: Error initializing capture: %Rhrc\n", hr)); 699 691 dsoundCaptureInterfaceRelease(pDSoundStrmIn); 700 692 } … … 706 698 static void dsoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn) 707 699 { 708 DSLOG(("DSound: capture close %p buffer %p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB)); 700 AssertPtrReturnVoid(pDSoundStrmIn); 701 702 LogFlowFunc(("pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB)); 709 703 710 704 if (pDSoundStrmIn->pDSCB) … … 712 706 HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 713 707 if (FAILED (hr)) 714 { 715 DSLOG(("DSound: close capture buffer stop %Rhrc\n", hr)); 716 } 708 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr)); 717 709 718 710 IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB); … … 725 717 static int dsoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 726 718 { 727 DSLOG(("DSound: capture open %p size %u bytes freq %u, chan %u, bits %u, sign %d\n", 728 pDSoundStrmIn, 729 pThis->cfg.cbBufferIn, 730 pDSoundStrmIn->hw.Props.uHz, 731 pDSoundStrmIn->hw.Props.cChannels, 732 pDSoundStrmIn->hw.Props.cBits, 733 pDSoundStrmIn->hw.Props.fSigned)); 719 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 720 AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_PARAMETER); 721 722 LogFlowFunc(("pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n", 723 pDSoundStrmIn, 724 pThis->cfg.cbBufferIn, 725 pDSoundStrmIn->strmIn.Props.uHz, 726 pDSoundStrmIn->strmIn.Props.cChannels, 727 pDSoundStrmIn->strmIn.Props.cBits, 728 pDSoundStrmIn->strmIn.Props.fSigned)); 734 729 735 730 if (pDSoundStrmIn->pDSCB != NULL) 736 731 { 737 732 /* Should not happen but be forgiving. */ 738 DSLOGREL(("DSound: DirectSoundCaptureBuffer already exists\n"));733 LogFlowFunc(("Capture buffer already exists\n")); 739 734 dsoundCaptureClose(pDSoundStrmIn); 740 735 } … … 761 756 hr = IDirectSoundCapture_CreateCaptureBuffer(pDSoundStrmIn->pDSC, 762 757 &bd, &pDSCB, NULL); 763 764 758 if (FAILED(hr)) 765 759 { 766 DSLOGREL(("DSound: Create capture buffer%Rhrc\n", hr));760 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating capture buffer: %Rhrc\n", hr)); 767 761 pDSoundStrmIn->pDSCB = NULL; 768 762 break; … … 773 767 if (FAILED(hr)) 774 768 { 775 DSLOGREL(("DSound: Querying capture buffer%Rhrc\n", hr));769 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying for capture buffer interface: %Rhrc\n", hr)); 776 770 break; 777 771 } 778 772 779 773 /* Query the actual parameters. */ 780 781 774 DWORD cbReadPos = 0; 782 775 hr = IDirectSoundCaptureBuffer8_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos); … … 784 777 { 785 778 cbReadPos = 0; 786 DSLOG(("DSound: open GetCurrentPosition%Rhrc\n", hr));779 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current position for capture stream: %Rhrc\n", hr)); 787 780 } 788 781 … … 791 784 if (FAILED(hr)) 792 785 { 793 DSLOGREL(("DSound: Capture buffer GetFormat%Rhrc\n", hr));786 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for capture stream: %Rhrc\n", hr)); 794 787 break; 795 788 } … … 801 794 if (FAILED (hr)) 802 795 { 803 DSLOGREL(("DSound: Capture buffer GetCaps%Rhrc\n", hr));796 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for capture stream: %Rhrc\n", hr)); 804 797 break; 805 798 } 806 799 807 DSLOG(("DSound: capture buffer format: size %d bytes\n" 808 " tag = %d\n" 809 " nChannels = %d\n" 810 " nSamplesPerSec = %d\n" 811 " nAvgBytesPerSec = %d\n" 812 " nBlockAlign = %d\n" 813 " wBitsPerSample = %d\n" 814 " cbSize = %d\n", 800 LogFunc(("Capture format:\n" 801 "\tdwBufferBytes = %RI32\n" 802 "\twFormatTag = %RI16\n" 803 "\tnChannels = %RI16\n" 804 "\tnSamplesPerSec = %RU32\n" 805 "\tnAvgBytesPerSec = %RU32\n" 806 "\tnBlockAlign = %RI16\n" 807 "\twBitsPerSample = %RI16\n" 808 "\tcbSize = %RI16\n", 815 809 bc.dwBufferBytes, 816 810 wfx.wFormatTag, … … 822 816 wfx.cbSize)); 823 817 824 if (bc.dwBufferBytes & pDSoundStrmIn->hw.Props.uAlign) 825 { 826 DSLOGREL(("DSound: GetCaps returned misaligned buffer size %ld, alignment %d\n", 827 bc.dwBufferBytes, pDSoundStrmIn->hw.Props.uAlign + 1)); 828 } 818 if (bc.dwBufferBytes & pDSoundStrmIn->strmIn.Props.uAlign) 819 LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture capabilities returned misaligned buffer (size %ld, alignment %RU32)\n", 820 bc.dwBufferBytes, pDSoundStrmIn->strmIn.Props.uAlign + 1)); 829 821 830 822 if (bc.dwBufferBytes != pThis->cfg.cbBufferIn) 831 { 832 DSLOGREL(("DSound: Buffer size mismatch dsound %u, requested %u bytes\n", 823 LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer size mismatched (DirectSound %ld, requested %ld bytes)\n", 833 824 bc.dwBufferBytes, pThis->cfg.cbBufferIn)); 834 }835 825 836 826 /* Initial state: reading at the initial capture position. */ 837 pDSoundStrmIn->csCaptureReadPos = cbReadPos >> pDSoundStrmIn->hw.Props.cShift; 838 pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->hw.Props.cShift; 839 DSLOG(("DSound: capture open csCaptureReadPos %d, csCaptureBufferSize %d samples\n", 840 pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize)); 841 827 pDSoundStrmIn->csCaptureReadPos = cbReadPos >> pDSoundStrmIn->strmIn.Props.cShift; 828 pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->strmIn.Props.cShift; 829 830 LogFlowFunc(("csCaptureReadPos=%ld, csCaptureBufferSize=%ld\n", 831 pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize)); 832 833 /* Update status. */ 842 834 pDSoundStrmIn->hrLastCaptureIn = S_OK; 835 843 836 } while (0); 844 837 … … 852 845 static void dsoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn) 853 846 { 847 AssertPtrReturnVoid(pDSoundStrmIn); 848 854 849 if (pDSoundStrmIn->pDSCB) 855 850 { 856 DSLOG(("DSound: capture stop\n"));851 LogFlowFunc(("Capturing stopped\n")); 857 852 858 853 HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 859 854 if (FAILED(hr)) 860 { 861 DSLOG(("DSound: stop capture buffer %Rhrc\n", hr)); 862 } 855 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr)); 863 856 } 864 857 } … … 866 859 static int dsoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 867 860 { 861 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 862 AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_PARAMETER); 863 868 864 HRESULT hr; 869 865 … … 874 870 if (FAILED(hr)) 875 871 { 876 DSLOG(("DSound: start GetStatus%Rhrc\n", hr));872 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting capture buffer status: %Rhrc\n", hr)); 877 873 } 878 874 else … … 880 876 if (dwStatus & DSCBSTATUS_CAPTURING) 881 877 { 882 DSLOG(("DSound: already capturing\n"));878 LogFlowFunc(("Already capturing\n")); 883 879 } 884 880 else 885 881 { 886 DSLOG(("DSound: capture start\n")); 887 882 LogFlowFunc(("Capturig started\n")); 888 883 hr = IDirectSoundCaptureBuffer8_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING); 889 884 if (FAILED (hr)) 890 { 891 DSLOGREL(("DSound: Start %Rhrc\n", hr)); 892 } 885 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting capture: %Rhrc\n", hr)); 893 886 } 894 887 } … … 896 889 else 897 890 { 891 AssertMsgFailed(("No/invalid capture buffer\n")); 898 892 hr = E_FAIL; 899 893 } … … 941 935 static void dsoundLogDevice(const char *pszType, LPGUID lpGUID, LPCWSTR lpwstrDescription, LPCWSTR lpwstrModule) 942 936 { 937 AssertPtrReturnVoid(pszType); 938 AssertPtrReturnVoid(lpGUID); 939 AssertPtrReturnVoid(lpwstrDescription); 940 AssertPtrReturnVoid(lpwstrModule); 941 943 942 char *pszGUID = dsoundGUIDToUtf8StrA(lpGUID); 944 945 LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n", 946 pszType, pszGUID? pszGUID: "no GUID", lpwstrDescription, lpwstrModule)); 947 948 RTStrFree(pszGUID); 943 if (pszGUID) 944 { 945 LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n", 946 pszType, pszGUID, lpwstrDescription, lpwstrModule)); 947 948 RTStrFree(pszGUID); 949 } 949 950 } 950 951 … … 952 953 LPCWSTR lpwstrModule, LPVOID lpContext) 953 954 { 955 AssertPtrReturn(lpContext, FALSE); 956 954 957 PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext; 955 958 AssertPtrReturn(pCtx, FALSE); … … 960 963 return TRUE; 961 964 965 AssertPtrReturn(lpwstrDescription, FALSE); 966 AssertPtrReturn(lpwstrModule, FALSE); 967 962 968 dsoundLogDevice("Output", lpGUID, lpwstrDescription, lpwstrModule); 963 969 … … 986 992 987 993 int rc = dsoundDevAdd(&pCtx->pDrv->lstDevInput, 988 994 lpGUID, lpwstrDescription, NULL /* ppDev */); 989 995 if (RT_FAILURE(rc)) 990 996 return FALSE; /* Abort enumeration. */ … … 1004 1010 uint32_t *pcSamples) 1005 1011 { 1012 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1013 AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER); 1014 AssertPtrReturn(pCfg, VERR_INVALID_POINTER); 1015 /* pcSamples is optional. */ 1016 1006 1017 LogFlowFunc(("pHstStrmOut=%p, pCfg=%p\n", pHstStrmOut, pCfg)); 1007 1018 … … 1012 1023 pDSoundStrmOut->streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS; 1013 1024 1014 int rc = drvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut-> hw.Props);1025 int rc = drvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut->strmOut.Props); 1015 1026 if (RT_SUCCESS(rc)) 1016 1027 { … … 1061 1072 rc = dsoundPlayStart(pDSoundStrmOut); 1062 1073 } 1063 } break; 1074 1075 break; 1076 } 1064 1077 1065 1078 case PDMAUDIOSTREAMCMD_DISABLE: 1066 1079 { 1067 1080 dsoundPlayStop(pThis, pDSoundStrmOut); 1068 } break; 1081 break; 1082 } 1069 1083 1070 1084 default: … … 1072 1086 AssertMsgFailed(("Invalid command %ld\n", enmStreamCmd)); 1073 1087 rc = VERR_INVALID_PARAMETER; 1074 } break; 1088 break; 1089 } 1075 1090 } 1076 1091 … … 1083 1098 uint32_t *pcSamplesPlayed) 1084 1099 { 1100 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1101 AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER); 1102 /* pcSamplesPlayed is optional. */ 1103 1085 1104 PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface); 1086 1105 PDSOUNDSTREAMOUT pDSoundStrmOut = (PDSOUNDSTREAMOUT)pHstStrmOut; 1087 LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB;1088 1106 1089 1107 int rc = VINF_SUCCESS; 1090 1091 if (!pDSB) 1092 { 1093 if (pcSamplesPlayed) /** @todo single point of return */ 1094 *pcSamplesPlayed = 0; 1095 return VINF_SUCCESS; 1096 } 1097 1098 int cShift = pHstStrmOut->Props.cShift; 1099 DWORD cbBuffer = pDSoundStrmOut->csPlaybackBufferSize << cShift; 1100 1101 DWORD cbPlayPos, cbWritePos; 1102 HRESULT hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos); 1103 if (hr == DSERR_BUFFERLOST) 1104 { 1105 rc = dsoundPlayRestore(pDSB); 1108 uint32_t cReadTotal = 0; 1109 1110 do 1111 { 1112 LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB; 1113 if (!pDSB) 1114 break; 1115 1116 int cShift = pHstStrmOut->Props.cShift; 1117 DWORD cbBuffer = pDSoundStrmOut->csPlaybackBufferSize << cShift; 1118 1119 DWORD cbPlayPos, cbWritePos; 1120 HRESULT hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos); 1121 if (hr == DSERR_BUFFERLOST) 1122 { 1123 rc = dsoundPlayRestore(pDSB); 1124 if (RT_FAILURE(rc)) 1125 break; 1126 1127 hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos); 1128 if (hr == DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */ 1129 break; 1130 } 1131 1132 if (FAILED(hr)) 1133 { 1134 LogRelMax(s_cMaxRelLogEntries, ("Error retrieving current playback position: %Rhrc\n", hr)); 1135 break; 1136 } 1137 1138 DWORD cbFree; 1139 DWORD cbPlayWritePos; 1140 if (pDSoundStrmOut->fReinitPlayPos) 1141 { 1142 pDSoundStrmOut->fReinitPlayPos = false; 1143 1144 pDSoundStrmOut->cbPlayWritePos = cbWritePos; 1145 1146 cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos; 1147 cbFree = cbBuffer - dsoundRingDistance(cbWritePos, cbPlayPos, cbBuffer); 1148 } 1149 else 1150 { 1151 /* Full buffer? */ 1152 if (pDSoundStrmOut->cbPlayWritePos == cbPlayPos) 1153 break; 1154 1155 cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos; 1156 cbFree = dsoundRingDistance(cbPlayPos, cbPlayWritePos, cbBuffer); 1157 } 1158 1159 uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */); 1160 uint32_t cbLive = csLive << cShift; 1161 1162 /* Do not write more than available space in the DirectSound playback buffer. */ 1163 cbLive = RT_MIN(cbFree, cbLive); 1164 1165 cbLive &= ~pHstStrmOut->Props.uAlign; 1166 if (cbLive == 0 || cbLive > cbBuffer) 1167 { 1168 LogFlowFunc(("cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n", 1169 cbLive, cbBuffer, cbPlayWritePos, cbPlayPos)); 1170 break; 1171 } 1172 1173 LPVOID pv1, pv2; 1174 DWORD cb1, cb2; 1175 rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, cbPlayWritePos, cbLive, 1176 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */); 1106 1177 if (RT_FAILURE(rc)) 1107 { 1108 if (pcSamplesPlayed) 1109 *pcSamplesPlayed = 0; 1110 return VINF_SUCCESS; 1111 } 1112 1113 hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos); 1114 if (hr == DSERR_BUFFERLOST) 1115 { 1116 /* Avoid log flooding if the error is still there. */ 1117 if (pcSamplesPlayed) 1118 *pcSamplesPlayed = 0; 1119 return VINF_SUCCESS; 1120 } 1121 } 1122 if (FAILED (hr)) 1123 { 1124 DSLOG(("DSound: get playback buffer position %Rhrc\n", hr)); 1125 if (pcSamplesPlayed) 1126 *pcSamplesPlayed = 0; 1127 return VINF_SUCCESS; 1128 } 1129 1130 DWORD cbFree; 1131 DWORD cbPlayWritePos; 1132 if (pDSoundStrmOut->fReinitPlayPos) 1133 { 1134 pDSoundStrmOut->fReinitPlayPos = false; 1135 1136 pDSoundStrmOut->cbPlayWritePos = cbWritePos; 1137 1138 cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos; 1139 cbFree = cbBuffer - dsoundRingDistance(cbWritePos, cbPlayPos, cbBuffer); 1140 } 1141 else 1142 { 1143 if (pDSoundStrmOut->cbPlayWritePos == cbPlayPos) 1144 { 1145 /* Full buffer. */ 1146 if (pcSamplesPlayed) 1147 *pcSamplesPlayed = 0; 1148 return VINF_SUCCESS; 1149 } 1150 1151 cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos; 1152 cbFree = dsoundRingDistance(cbPlayPos, cbPlayWritePos, cbBuffer); 1153 } 1154 1155 uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */); 1156 uint32_t cbLive = csLive << cShift; 1157 1158 /* Do not write more than available space in the DirectSound playback buffer. */ 1159 cbLive = RT_MIN(cbFree, cbLive); 1160 1161 cbLive &= ~pHstStrmOut->Props.uAlign; 1162 if (cbLive == 0 || cbLive > cbBuffer) 1163 { 1164 DSLOG(("DSound: cbLive=%d cbBuffer=%d cbPlayWritePos=%d cbPlayPos=%d\n", 1165 cbLive, cbBuffer, cbPlayWritePos, cbPlayPos)); 1166 if (pcSamplesPlayed) 1167 *pcSamplesPlayed = 0; 1168 return VINF_SUCCESS; 1169 } 1170 1171 LPVOID pv1, pv2; 1172 DWORD cb1, cb2; 1173 rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, cbPlayWritePos, cbLive, 1174 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */); 1175 if (RT_FAILURE(rc)) 1176 { 1177 if (pcSamplesPlayed) 1178 *pcSamplesPlayed = 0; 1179 return VINF_SUCCESS; 1180 } 1181 1182 DWORD len1 = cb1 >> cShift; 1183 DWORD len2 = cb2 >> cShift; 1184 1185 uint32_t cReadTotal = 0; 1186 uint32_t cRead = 0; 1187 1188 if (pv1 && cb1) 1189 { 1190 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead); 1191 if (RT_SUCCESS(rc)) 1192 cReadTotal += cRead; 1193 } 1194 1195 if ( RT_SUCCESS(rc) 1196 && cReadTotal == len1 1197 && pv2 && cb2) 1198 { 1199 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead); 1200 if (RT_SUCCESS(rc)) 1201 cReadTotal += cRead; 1202 } 1203 1204 dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2); 1205 1206 pDSoundStrmOut->cbPlayWritePos = (cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer; 1207 1208 DSLOGF(("DSound: PlayOut %RU32 (%RU32 samples) out of %d%s, ds write pos %d -> %d, rc=%Rrc\n", 1209 AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive, 1210 cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "", 1211 cbPlayWritePos, pDSoundStrmOut->cbPlayWritePos, rc)); 1212 1213 if (cReadTotal) 1214 { 1215 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 1216 rc = VINF_SUCCESS; /* Played something. */ 1217 } 1178 break; 1179 1180 DWORD len1 = cb1 >> cShift; 1181 DWORD len2 = cb2 >> cShift; 1182 1183 uint32_t cRead = 0; 1184 1185 if (pv1 && cb1) 1186 { 1187 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead); 1188 if (RT_SUCCESS(rc)) 1189 cReadTotal += cRead; 1190 } 1191 1192 if ( RT_SUCCESS(rc) 1193 && cReadTotal == len1 1194 && pv2 && cb2) 1195 { 1196 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead); 1197 if (RT_SUCCESS(rc)) 1198 cReadTotal += cRead; 1199 } 1200 1201 dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2); 1202 1203 pDSoundStrmOut->cbPlayWritePos = (cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer; 1204 1205 LogFlowFunc(("%RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld -> %ld, rc=%Rrc\n", 1206 AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive, 1207 cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "", 1208 cbPlayWritePos, pDSoundStrmOut->cbPlayWritePos, rc)); 1209 1210 if (cReadTotal) 1211 { 1212 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 1213 rc = VINF_SUCCESS; /* Played something. */ 1214 } 1215 1216 } while (0); 1218 1217 1219 1218 if (pcSamplesPlayed) … … 1345 1344 if (hr != pDSoundStrmIn->hrLastCaptureIn) 1346 1345 { 1347 DSLOGREL(("DSound: CaptureIn GetCurrentPosition%Rhrc\n", hr));1346 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current capture position: %Rhrc\n", hr)); 1348 1347 pDSoundStrmIn->hrLastCaptureIn = hr; 1349 1348 } … … 1356 1355 1357 1356 if (cbReadPos & pHstStrmIn->Props.uAlign) 1358 { 1359 DSLOG(("DSound: CaptureIn misaligned read position %d(%d)\n", cbReadPos, pHstStrmIn->Props.uAlign)); 1360 } 1357 LogFunc(("Misaligned read position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign)); 1361 1358 1362 1359 /* Capture position in samples. */ 1363 intcsReadPos = cbReadPos >> pHstStrmIn->Props.cShift;1360 DWORD csReadPos = cbReadPos >> pHstStrmIn->Props.cShift; 1364 1361 1365 1362 /* Number of samples available in the DirectSound capture buffer. */ … … 1379 1376 if (csMixFree == 0) 1380 1377 { 1381 DSLOG(("DSound: capture mixbuffer full\n"));1378 LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer full\n")); 1382 1379 if (pcSamplesCaptured) 1383 1380 *pcSamplesCaptured = 0; … … 1385 1382 } 1386 1383 1387 DSLOGF(("DSound: CaptureIn csMixFree = %u, csReadPos = %d, csCaptureReadPos = %d, csCaptured = %u\n",1388 csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured));1384 LogFlowFunc(("csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n", 1385 csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured)); 1389 1386 1390 1387 /* No need to fetch more samples than mix buffer can receive. */ … … 1442 1439 { 1443 1440 pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + csProcessed) % pDSoundStrmIn->csCaptureBufferSize; 1444 DSLOGF(("DSound: CaptureIn %d (%d+%d), processed %d/%d\n",1445 csCaptured, len1, len2, csProcessed, csWrittenTotal));1441 LogFlowFunc(("%ld (%ld+%ld), processed %RU32/%RU32\n", 1442 csCaptured, len1, len2, csProcessed, csWrittenTotal)); 1446 1443 } 1447 1444 … … 1459 1456 dsoundCaptureClose(pDSoundStrmIn); 1460 1457 1461 pDSoundStrmIn->csCaptureReadPos = 0;1458 pDSoundStrmIn->csCaptureReadPos = 0; 1462 1459 pDSoundStrmIn->csCaptureBufferSize = 0; 1463 1460 RT_ZERO(pDSoundStrmIn->streamCfg); … … 1491 1488 HRESULT hr = DirectSoundEnumerateW(&dsoundEnumCallback, &ctx); 1492 1489 if (FAILED(hr)) 1493 DSLOG(("DSound: Enumerating host playback devices failed%Rhrc\n", hr));1494 1495 DSLOGREL(("DSound: Found %RU32 host playback devices\n", pCfg->cMaxHstStrmsOut));1490 LogRel(("DSound: Error enumerating host playback devices: %Rhrc\n", hr)); 1491 1492 LogRel(("DSound: Found %RU32 host playback devices\n", pCfg->cMaxHstStrmsOut)); 1496 1493 if (pCfg->cMaxHstStrmsOut == 0) 1497 1494 pCfg->cMaxHstStrmsOut = 1; /* Support at least one stream. */ … … 1499 1496 hr = DirectSoundCaptureEnumerateW(&dsoundCaptureEnumCallback, &ctx); 1500 1497 if (FAILED(hr)) 1501 DSLOG(("DSound: Enumerating host capturing devices failed%Rhrc\n", hr));1502 1503 DSLOGREL(("DSound: Found %RU32 host capturing devices\n", pCfg->cMaxHstStrmsIn));1498 LogRel(("DSound: Error nnumerating host capturing devices: %Rhrc\n", hr)); 1499 1500 LogRel(("DSound: Found %RU32 host capturing devices\n", pCfg->cMaxHstStrmsIn)); 1504 1501 if (pCfg->cMaxHstStrmsIn < 2) 1505 1502 { 1506 DSLOGREL(("DSound: Adjusting the number of host capturing devices from %RU32 to 2\n", pCfg->cMaxHstStrmsIn));1503 LogRel(("DSound: Adjusting the number of host capturing devices from %RU32 to 2\n", pCfg->cMaxHstStrmsIn)); 1507 1504 pCfg->cMaxHstStrmsIn = 2; /* Support at least two streams (line in + mic). */ 1508 1505 } … … 1529 1526 IDirectSound_Release(pDirectSound); 1530 1527 else 1531 DSLOGREL(("DSound: Not available%Rhrc\n", hr));1528 LogRel(("DSound: DirectSound not available: %Rhrc\n", hr)); 1532 1529 1533 1530 int rc = SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED; … … 1581 1578 pGuid = (LPCGUID)&pUuid; 1582 1579 else 1583 DSLOGREL(("DSound: Parse DirectSound %s%Rrc\n", pszName, rc));1580 LogRel(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc)); 1584 1581 1585 1582 RTStrFree(pszGuid); … … 1601 1598 pThis->cfg.pGuidCapture = dsoundConfigQueryGUID(pCfg, "DeviceGuidIn", &pThis->cfg.uuidCapture); 1602 1599 1603 DSLOG(("DSound:BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",1604 pThis->cfg.cbBufferOut,1605 pThis->cfg.cbBufferIn,1606 &pThis->cfg.uuidPlay,1607 &pThis->cfg.uuidCapture));1600 LogFlowFunc(("BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n", 1601 pThis->cfg.cbBufferOut, 1602 pThis->cfg.cbBufferIn, 1603 &pThis->cfg.uuidPlay, 1604 &pThis->cfg.uuidCapture)); 1608 1605 } 1609 1606 … … 1634 1631 if (FAILED(hr)) 1635 1632 { 1636 LogRel(("DSound: COM initialize%Rhrc\n", hr));1633 LogRel(("DSound: Error initializing COM: %Rhrc\n", hr)); 1637 1634 return VERR_NOT_SUPPORTED; 1638 1635 }
Note:
See TracChangeset
for help on using the changeset viewer.