Changeset 58071 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Oct 7, 2015 6:23:04 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r57752 r58071 28 28 #include "VBoxDD.h" 29 29 30 /* 31 * IDirectSound* interface uses HRESULT status codes and the driver callbacks use 32 * the IPRT status codes. To minimize HRESULT->IPRT conversion most internal functions 33 * in the driver return HRESULT and conversion is done in the driver callbacks. 34 * 35 * Naming convention: 36 * 'dsound*' functions return IPRT status code; 37 * 'directSound*' - return HRESULT. 38 */ 39 40 /* 41 * Optional release logging, which a user can turn on with the 42 * 'VBoxManage debugvm' command. 43 * Debug logging still uses the common Log* macros from IPRT. 44 * Messages which always should go to the release log use LogRel. 45 */ 46 /* General code behavior. */ 47 #define DSLOG(a) do { LogRel2(a); } while(0) 48 /* Something which produce a lot of logging during playback/recording. */ 49 #define DSLOGF(a) do { LogRel3(a); } while(0) 50 /* Important messages like errors. Limited in the default release log to avoid log flood. */ 51 #define DSLOGREL(a) \ 52 do { \ 53 static int8_t scLogged = 0; \ 54 if (scLogged < 8) { \ 55 ++scLogged; \ 56 LogRel(a); \ 57 } \ 58 else { \ 59 DSLOG(a); \ 60 } \ 61 } while (0) 62 30 63 /* Dynamically load dsound.dll. */ 31 64 typedef HRESULT WINAPI FNDIRECTSOUNDENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext); … … 97 130 } DSOUNDDEV, *PDSOUNDDEV; 98 131 99 /** Maximum number of release logging entries. */100 static uint32_t s_cMaxRelLogEntries = 32;101 102 132 /** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */ 103 133 #define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \ … … 166 196 } 167 197 168 return RTStrDup(" <GUID not found>");198 return RTStrDup("{Default device}"); 169 199 } 170 200 … … 185 215 } 186 216 187 static int dsoundPlayRestore(LPDIRECTSOUNDBUFFER8 pDSB)217 static HRESULT directSoundPlayRestore(LPDIRECTSOUNDBUFFER8 pDSB) 188 218 { 189 219 HRESULT hr = IDirectSoundBuffer8_Restore(pDSB); 190 if (SUCCEEDED(hr)) 191 return VINF_SUCCESS; 192 193 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error restoring playback buffer: %Rhrc\n", hr)); 194 return VERR_INVALID_STATE; 195 } 196 197 static int dsoundUnlockOutput(LPDIRECTSOUNDBUFFER8 pDSB, 198 LPVOID pv1, LPVOID pv2, 199 DWORD cb1, DWORD cb2) 220 if (FAILED(hr)) 221 DSLOGREL(("DSound: Restore playback buffer %Rhrc\n", hr)); 222 return hr; 223 } 224 225 static HRESULT directSoundPlayUnlock(LPDIRECTSOUNDBUFFER8 pDSB, 226 LPVOID pv1, LPVOID pv2, 227 DWORD cb1, DWORD cb2) 200 228 { 201 229 HRESULT hr = IDirectSoundBuffer8_Unlock(pDSB, pv1, cb1, pv2, cb2); 202 if (SUCCEEDED(hr)) 203 return VINF_SUCCESS; 204 205 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking output buffer: %Rhrc\n", hr)); 206 return VERR_ACCESS_DENIED; 207 } 208 209 static int dsoundUnlockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, 210 LPVOID pv1, LPVOID pv2, 211 DWORD cb1, DWORD cb2) 230 if (FAILED(hr)) 231 DSLOGREL(("DSound: Unlock playback buffer %Rhrc\n", hr)); 232 return hr; 233 } 234 235 static HRESULT directSoundCaptureUnlock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, 236 LPVOID pv1, LPVOID pv2, 237 DWORD cb1, DWORD cb2) 212 238 { 213 239 HRESULT hr = IDirectSoundCaptureBuffer8_Unlock(pDSCB, pv1, cb1, pv2, cb2); 214 if (SUCCEEDED(hr)) 215 return VINF_SUCCESS; 216 217 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking input buffer: %Rhrc\n", hr)); 218 return VERR_ACCESS_DENIED; 219 } 220 221 static int dsoundLockOutput(LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps, 222 DWORD dwOffset, DWORD dwBytes, 223 LPVOID *ppv1, LPVOID *ppv2, 224 DWORD *pcb1, DWORD *pcb2, 225 DWORD dwFlags) 226 { 227 int rc = VINF_SUCCESS; 228 240 if (FAILED(hr)) 241 DSLOGREL(("DSound: Unlock capture buffer %Rhrc\n", hr)); 242 return hr; 243 } 244 245 static HRESULT directSoundPlayLock(LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps, 246 DWORD dwOffset, DWORD dwBytes, 247 LPVOID *ppv1, LPVOID *ppv2, 248 DWORD *pcb1, DWORD *pcb2, 249 DWORD dwFlags) 250 { 229 251 LPVOID pv1 = NULL; 230 252 LPVOID pv2 = NULL; … … 235 257 if (hr == DSERR_BUFFERLOST) 236 258 { 237 rc = dsoundPlayRestore(pDSB);238 if ( RT_SUCCESS(rc))259 hr = directSoundPlayRestore(pDSB); 260 if (SUCCEEDED(hr)) 239 261 { 240 262 hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags); 241 if (FAILED(hr)) 242 rc = VERR_ACCESS_DENIED; 243 } 244 } 245 246 if (RT_FAILURE(rc)) 247 { 248 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking output buffer: %Rhrc\n", hr)); 249 return rc; 263 } 264 } 265 266 if (FAILED(hr)) 267 { 268 DSLOGREL(("DSound: Lock playback buffer %Rhrc\n", hr)); 269 return hr; 250 270 } 251 271 … … 253 273 || (pv2 && (cb2 & pProps->uAlign))) 254 274 { 255 LogRelMax(s_cMaxRelLogEntries,("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",256 257 d soundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);258 return VERR_INVALID_STATE;275 DSLOGREL(("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n", 276 cb1, cb2, pProps->uAlign)); 277 directSoundPlayUnlock(pDSB, pv1, pv2, cb1, cb2); 278 return E_FAIL; 259 279 } 260 280 … … 264 284 *pcb2 = cb2; 265 285 266 return VINF_SUCCESS;267 } 268 269 static int dsoundLockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps,270 DWORD dwOffset, DWORD dwBytes,271 LPVOID *ppv1, LPVOID *ppv2,272 DWORD *pcb1, DWORD *pcb2,273 DWORD dwFlags)286 return S_OK; 287 } 288 289 static HRESULT directSoundCaptureLock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps, 290 DWORD dwOffset, DWORD dwBytes, 291 LPVOID *ppv1, LPVOID *ppv2, 292 DWORD *pcb1, DWORD *pcb2, 293 DWORD dwFlags) 274 294 { 275 295 LPVOID pv1 = NULL; … … 282 302 if (FAILED(hr)) 283 303 { 284 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking capturing buffer:%Rhrc\n", hr));285 return VERR_ACCESS_DENIED;304 DSLOGREL(("DSound: Lock capture buffer %Rhrc\n", hr)); 305 return hr; 286 306 } 287 307 … … 289 309 || (pv2 && (cb2 & pProps->uAlign))) 290 310 { 291 LogRelMax(s_cMaxRelLogEntries,("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",292 293 d soundUnlockInput(pDSCB, pv1, pv2, cb1, cb2);294 return VERR_INVALID_PARAMETER;311 DSLOGREL(("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n", 312 cb1, cb2, pProps->uAlign)); 313 directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2); 314 return E_FAIL; 295 315 } 296 316 … … 300 320 *pcb2 = cb2; 301 321 302 return VINF_SUCCESS;322 return S_OK; 303 323 } 304 324 … … 308 328 */ 309 329 310 static void d soundPlayInterfaceRelease(PDSOUNDSTREAMOUT pDSoundStrmOut)330 static void directSoundPlayInterfaceRelease(PDSOUNDSTREAMOUT pDSoundStrmOut) 311 331 { 312 332 if (pDSoundStrmOut->pDS) … … 317 337 } 318 338 319 static int dsoundPlayInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)339 static HRESULT directSoundPlayInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 320 340 { 321 341 if (pDSoundStrmOut->pDS != NULL) 322 342 { 323 LogFlowFunc(("DirectSound instance already exists\n"));324 return VINF_SUCCESS;343 DSLOG(("DSound: DirectSound instance already exists\n")); 344 return S_OK; 325 345 } 326 346 … … 329 349 if (FAILED(hr)) 330 350 { 331 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating DirectSound instance:%Rhrc\n", hr));351 DSLOGREL(("DSound: Create DirectSound instance %Rhrc\n", hr)); 332 352 } 333 353 else … … 339 359 hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hWnd, DSSCL_PRIORITY); 340 360 if (FAILED(hr)) 341 LogRel(("DSound: Error setting cooperative level for window %p: %Rhrc\n", hWnd, hr)); 342 } 361 DSLOGREL(("DSound: Set cooperative level for window %p %Rhrc\n", hWnd, hr)); 362 } 363 343 364 if (FAILED(hr)) 344 365 { 345 if (hr == DSERR_NODRIVER) 346 LogRel(("DSound: DirectSound playback is currently unavailable\n"));366 if (hr == DSERR_NODRIVER) /* Usually means that no playback devices are attached. */ 367 DSLOGREL(("DSound: DirectSound playback is currently unavailable\n")); 347 368 else 348 LogRel(("DSound: Error initializing DirectSound:%Rhrc\n", hr));349 350 d soundPlayInterfaceRelease(pDSoundStrmOut);351 } 352 } 353 354 return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;355 } 356 357 static void d soundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut)358 { 359 LogFlowFunc(("Closing playback stream %p (buffer %p)\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));369 DSLOGREL(("DSound: DirectSound playback initialize %Rhrc\n", hr)); 370 371 directSoundPlayInterfaceRelease(pDSoundStrmOut); 372 } 373 } 374 375 return hr; 376 } 377 378 static void directSoundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut) 379 { 380 DSLOG(("DSound: Closing playback stream %p, buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB)); 360 381 361 382 if (pDSoundStrmOut->pDSB) … … 363 384 HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 364 385 if (FAILED(hr)) 365 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error closing playback stream %p:%Rhrc\n", pDSoundStrmOut, hr));386 DSLOGREL(("DSound: Stop playback stream %p when closing %Rhrc\n", pDSoundStrmOut, hr)); 366 387 367 388 IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB); … … 369 390 } 370 391 371 d soundPlayInterfaceRelease(pDSoundStrmOut);372 } 373 374 static int dsoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)375 { 376 AssertPtrReturn(pThis, VERR_INVALID_POINTER);377 AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER);378 379 LogFlowFunc(("pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",380 381 382 383 384 385 392 directSoundPlayInterfaceRelease(pDSoundStrmOut); 393 } 394 395 static HRESULT directSoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 396 { 397 AssertPtrReturn(pThis, E_POINTER); 398 AssertPtrReturn(pDSoundStrmOut, E_POINTER); 399 400 DSLOG(("DSound: pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n", 401 pDSoundStrmOut, 402 pThis->cfg.cbBufferOut, 403 pDSoundStrmOut->strmOut.Props.uHz, 404 pDSoundStrmOut->strmOut.Props.cChannels, 405 pDSoundStrmOut->strmOut.Props.cBits, 406 pDSoundStrmOut->strmOut.Props.fSigned)); 386 407 387 408 if (pDSoundStrmOut->pDSB != NULL) 388 409 { 389 410 /* Should not happen but be forgiving. */ 390 LogFlowFunc(("DirectSoundBuffer already exists\n"));391 d soundPlayClose(pDSoundStrmOut);411 DSLOGREL(("DSound: DirectSoundBuffer already exists\n")); 412 directSoundPlayClose(pDSoundStrmOut); 392 413 } 393 414 … … 395 416 int rc = dsoundWaveFmtFromCfg(&pDSoundStrmOut->streamCfg, &wfx); 396 417 if (RT_FAILURE(rc)) 397 return rc; 398 399 rc = dsoundPlayInterfaceCreate(pThis, pDSoundStrmOut); 400 if (RT_FAILURE(rc)) 401 return rc; 402 403 HRESULT hr = S_OK; 418 return E_INVALIDARG; 419 420 HRESULT hr = directSoundPlayInterfaceCreate(pThis, pDSoundStrmOut); 421 if (FAILED(hr)) 422 return hr; 404 423 405 424 do /* To use breaks. */ 406 425 { 426 LPDIRECTSOUNDBUFFER pDSB = NULL; 407 427 DSBUFFERDESC bd; 408 LPDIRECTSOUNDBUFFER pDSB;409 428 RT_ZERO(bd); 410 429 bd.dwSize = sizeof(bd); … … 413 432 bd.dwBufferBytes = pThis->cfg.cbBufferOut; 414 433 hr = IDirectSound8_CreateSoundBuffer(pDSoundStrmOut->pDS, 415 &bd, &pDSB, NULL);434 &bd, &pDSB, NULL); 416 435 if (FAILED(hr)) 417 436 { 418 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating playback stream: %Rhrc\n", hr)); 419 break; 420 } 421 437 DSLOGREL(("DSound: CreateSoundBuffer %Rhrc\n", hr)); 438 break; 439 } 440 441 /* "Upgrade" to IDirectSoundBuffer8 intarface. */ 422 442 hr = IDirectSoundBuffer_QueryInterface(pDSB, IID_IDirectSoundBuffer8, (void **)&pDSoundStrmOut->pDSB); 423 443 pDSB->Release(); 424 444 if (FAILED(hr)) 425 445 { 426 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying interface for playback stream: %Rhrc\n", hr)); 427 break; 428 } 429 430 /* Query the actual parameters. */ 446 DSLOGREL(("DSound: Query IDirectSoundBuffer8 %Rhrc\n", hr)); 447 break; 448 } 449 450 /* 451 * Query the actual parameters. 452 */ 431 453 hr = IDirectSoundBuffer8_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL); 432 454 if (FAILED(hr)) 433 455 { 434 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for playback stream:%Rhrc\n", hr));456 DSLOGREL(("DSound: Playback GetFormat %Rhrc\n", hr)); 435 457 break; 436 458 } … … 442 464 if (FAILED(hr)) 443 465 { 444 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for playback stream:%Rhrc\n", hr));445 break; 446 } 447 448 LogFunc(("Playback format:\n"449 "\tdwBufferBytes = %RI32\n"450 "\twFormatTag = %RI16\n"451 "\tnChannels = %RI16\n"452 "\tnSamplesPerSec = %RU32\n"453 "\tnAvgBytesPerSec = %RU32\n"454 "\tnBlockAlign = %RI16\n"455 "\twBitsPerSample = %RI16\n"456 "\tcbSize = %RI16\n",457 458 459 460 461 462 463 464 466 DSLOGREL(("DSound: Playback GetCaps %Rhrc\n", hr)); 467 break; 468 } 469 470 DSLOG(("DSound: Playback format:\n" 471 " dwBufferBytes = %RI32\n" 472 " wFormatTag = %RI16\n" 473 " nChannels = %RI16\n" 474 " nSamplesPerSec = %RU32\n" 475 " nAvgBytesPerSec = %RU32\n" 476 " nBlockAlign = %RI16\n" 477 " wBitsPerSample = %RI16\n" 478 " cbSize = %RI16\n", 479 bc.dwBufferBytes, 480 wfx.wFormatTag, 481 wfx.nChannels, 482 wfx.nSamplesPerSec, 483 wfx.nAvgBytesPerSec, 484 wfx.nBlockAlign, 485 wfx.wBitsPerSample, 486 wfx.cbSize)); 465 487 466 488 if (bc.dwBufferBytes & pDSoundStrmOut->strmOut.Props.uAlign) 467 LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",468 489 DSLOGREL(("DSound: Playback GetCaps returned misaligned buffer: size %RU32, alignment %RU32\n", 490 bc.dwBufferBytes, pDSoundStrmOut->strmOut.Props.uAlign + 1)); 469 491 470 492 if (bc.dwBufferBytes != pThis->cfg.cbBufferOut) 471 LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",472 493 DSLOGREL(("DSound: Playback buffer size mismatched: DirectSound %RU32, requested %RU32 bytes\n", 494 bc.dwBufferBytes, pThis->cfg.cbBufferOut)); 473 495 474 496 /* … … 478 500 */ 479 501 pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->strmOut.Props.cShift; 480 LogFlowFunc(("csPlaybackBufferSize=%ld\n", pDSoundStrmOut->csPlaybackBufferSize));502 DSLOG(("DSound: csPlaybackBufferSize=%RU32\n", pDSoundStrmOut->csPlaybackBufferSize)); 481 503 482 504 } while (0); 483 505 484 if (SUCCEEDED(hr)) 485 return VINF_SUCCESS; 486 487 dsoundPlayClose(pDSoundStrmOut); 488 return VERR_NOT_SUPPORTED; 506 if (FAILED(hr)) 507 directSoundPlayClose(pDSoundStrmOut); 508 509 return hr; 489 510 } 490 511 … … 495 516 LPVOID pv1, pv2; 496 517 DWORD cb1, cb2; 497 int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props,498 0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift,499 &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);500 if ( RT_SUCCESS(rc))518 HRESULT hr = directSoundPlayLock(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props, 519 0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift, 520 &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER); 521 if (SUCCEEDED(hr)) 501 522 { 502 523 int len1 = cb1 >> pDSoundStrmOut->strmOut.Props.cShift; … … 509 530 drvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv2, len2); 510 531 511 d soundUnlockOutput(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2);512 } 513 } 514 515 static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)516 { 517 AssertPtrReturn(pDSB, VERR_INVALID_POINTER);532 directSoundPlayUnlock(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2); 533 } 534 } 535 536 static HRESULT directSoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus) 537 { 538 AssertPtrReturn(pDSB, E_POINTER); 518 539 /* pStatus is optional. */ 519 520 int rc = VINF_SUCCESS;521 540 522 541 DWORD dwStatus = 0; … … 526 545 if ((dwStatus & DSBSTATUS_BUFFERLOST) != 0) 527 546 { 528 rc = dsoundPlayRestore(pDSB);529 if ( RT_SUCCESS(rc))547 hr = directSoundPlayRestore(pDSB); 548 if (SUCCEEDED(hr)) 530 549 hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus); 531 550 } 532 551 } 533 552 534 if (FAILED(hr)) 535 { 536 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting playback status: %Rhrc\n", hr)); 537 if (RT_SUCCESS(rc)) 538 rc = VERR_NOT_SUPPORTED; 539 } 540 541 if (RT_SUCCESS(rc)) 553 if (SUCCEEDED(hr)) 542 554 { 543 555 if (pStatus) 544 556 *pStatus = dwStatus; 545 557 } 546 547 return rc; 548 } 549 550 static void dsoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 558 else 559 DSLOGREL(("DSound: Playback GetStatus %Rhrc\n", hr)); 560 561 return hr; 562 } 563 564 static void directSoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 551 565 { 552 566 AssertPtrReturnVoid(pThis); … … 556 570 { 557 571 /* This performs some restore, so call it anyway and ignore result. */ 558 d soundPlayGetStatus(pDSoundStrmOut->pDSB, NULL /* Status */);559 560 LogFlowFunc(("Playback stopped\n"));572 directSoundPlayGetStatus(pDSoundStrmOut->pDSB, NULL /* Status */); 573 574 DSLOG(("DSound: Stopping playback\n")); 561 575 562 576 /* @todo Wait until all data in the buffer has been played. */ 563 577 HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 564 578 if (SUCCEEDED(hr)) 565 {566 579 dsoundPlayClearSamples(pDSoundStrmOut); 567 }568 580 else 569 LogRelMax(s_cMaxRelLogEntries, ("DSound: Errpor stopping playback buffer: %Rhrc\n", hr)); 570 } 571 } 572 573 static int dsoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut) 574 { 575 AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER); 576 577 int rc; 578 581 DSLOGREL(("DSound: Stop playback %Rhrc\n", hr)); 582 } 583 } 584 585 static HRESULT directSoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut) 586 { 587 AssertPtrReturn(pDSoundStrmOut, E_POINTER); 588 589 HRESULT hr; 579 590 if (pDSoundStrmOut->pDSB != NULL) 580 591 { 581 592 DWORD dwStatus; 582 rc = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);583 if ( RT_SUCCESS(rc))593 hr = directSoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus); 594 if (SUCCEEDED(hr)) 584 595 { 585 596 if (dwStatus & DSBSTATUS_PLAYING) 586 597 { 587 LogFlowFunc(("Already playing\n"));598 DSLOG(("DSound: Already playing\n")); 588 599 } 589 600 else … … 593 604 pDSoundStrmOut->fRestartPlayback = true; 594 605 595 LogFlowFunc(("Playback started\n"));606 DSLOG(("DSound: Playback start\n")); 596 607 597 608 /* The actual IDirectSoundBuffer8_Play call will be made in drvHostDSoundPlayOut, … … 602 613 } 603 614 else 604 rc = VERR_INVALID_STATE;605 606 return rc;615 hr = E_UNEXPECTED; 616 617 return hr; 607 618 } 608 619 … … 645 656 if (pDev) 646 657 { 647 LogRel2(("DSound: Guest \"%s\" is using host \"%s\"\n",648 658 DSLOG(("DSound: Guest \"%s\" is using host \"%s\"\n", 659 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName)); 649 660 650 661 pGUID = &pDev->Guid; … … 653 664 654 665 char *pszGUID = dsoundGUIDToUtf8StrA(pGUID); 655 if (pszGUID) 656 { 657 LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n", 658 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID)); 659 RTStrFree(pszGUID); 660 } 666 /* This always has to be in the release log. */ 667 LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n", 668 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID? pszGUID: "{?}")); 669 RTStrFree(pszGUID); 661 670 662 671 return pGUID; 663 672 } 664 673 665 static void d soundCaptureInterfaceRelease(PDSOUNDSTREAMIN pDSoundStrmIn)674 static void directSoundCaptureInterfaceRelease(PDSOUNDSTREAMIN pDSoundStrmIn) 666 675 { 667 676 if (pDSoundStrmIn->pDSC) … … 672 681 } 673 682 674 static int dsoundCaptureInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)683 static HRESULT directSoundCaptureInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 675 684 { 676 685 if (pDSoundStrmIn->pDSC != NULL) 677 686 { 678 LogFunc(("DSound: DirectSoundCapture instance already exists\n"));679 return VINF_SUCCESS;687 DSLOG(("DSound: DirectSoundCapture instance already exists\n")); 688 return S_OK; 680 689 } 681 690 … … 684 693 if (FAILED(hr)) 685 694 { 686 LogRel(("DSound: Error creating capture instance:%Rhrc\n", hr));695 DSLOGREL(("DSound: DirectSoundCapture create %Rhrc\n", hr)); 687 696 } 688 697 else … … 692 701 if (FAILED(hr)) 693 702 { 694 if (hr == DSERR_NODRIVER) 695 LogRel(("DSound: DirectSound capture is currently unavailable\n"));703 if (hr == DSERR_NODRIVER) /* Usually means that no capture devices are attached. */ 704 DSLOGREL(("DSound: DirectSound capture is currently unavailable\n")); 696 705 else 697 LogRel(("DSound: Error initializing capture: %Rhrc\n", hr)); 698 dsoundCaptureInterfaceRelease(pDSoundStrmIn); 699 } 700 } 701 702 return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED; 703 } 704 705 static void dsoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn) 706 DSLOGREL(("DSound: DirectSoundCapture initialize %Rhrc\n", hr)); 707 708 directSoundCaptureInterfaceRelease(pDSoundStrmIn); 709 } 710 } 711 712 return hr; 713 } 714 715 static void directSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn) 706 716 { 707 717 AssertPtrReturnVoid(pDSoundStrmIn); 708 718 709 LogFlowFunc(("pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));719 DSLOG(("DSound: pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB)); 710 720 711 721 if (pDSoundStrmIn->pDSCB) 712 722 { 713 723 HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 714 if (FAILED 715 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer:%Rhrc\n", hr));724 if (FAILED(hr)) 725 DSLOGREL(("DSound: Stop capture buffer %Rhrc\n", hr)); 716 726 717 727 IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB); … … 719 729 } 720 730 721 d soundCaptureInterfaceRelease(pDSoundStrmIn);722 } 723 724 static int dsoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)725 { 726 AssertPtrReturn(pThis, VERR_INVALID_POINTER);727 AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_POINTER);728 729 LogFlowFunc(("pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",730 731 732 733 734 735 731 directSoundCaptureInterfaceRelease(pDSoundStrmIn); 732 } 733 734 static HRESULT directSoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 735 { 736 AssertPtrReturn(pThis, E_POINTER); 737 AssertPtrReturn(pDSoundStrmIn, E_POINTER); 738 739 DSLOG(("DSound: pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n", 740 pDSoundStrmIn, 741 pThis->cfg.cbBufferIn, 742 pDSoundStrmIn->strmIn.Props.uHz, 743 pDSoundStrmIn->strmIn.Props.cChannels, 744 pDSoundStrmIn->strmIn.Props.cBits, 745 pDSoundStrmIn->strmIn.Props.fSigned)); 736 746 737 747 if (pDSoundStrmIn->pDSCB != NULL) 738 748 { 739 749 /* Should not happen but be forgiving. */ 740 LogFlowFunc(("Capture buffer already exists\n"));741 d soundCaptureClose(pDSoundStrmIn);750 DSLOGREL(("DSound: DirectSoundCaptureBuffer already exists\n")); 751 directSoundCaptureClose(pDSoundStrmIn); 742 752 } 743 753 … … 745 755 int rc = dsoundWaveFmtFromCfg(&pDSoundStrmIn->streamCfg, &wfx); 746 756 if (RT_FAILURE(rc)) 747 return rc; 748 749 rc = dsoundCaptureInterfaceCreate(pThis, pDSoundStrmIn); 750 if (RT_FAILURE(rc)) 751 return rc; 752 753 HRESULT hr = S_OK; 757 return E_INVALIDARG; 758 759 HRESULT hr = directSoundCaptureInterfaceCreate(pThis, pDSoundStrmIn); 760 if (FAILED(hr)) 761 return hr; 754 762 755 763 do /* To use breaks. */ 756 764 { 765 LPDIRECTSOUNDCAPTUREBUFFER pDSCB = NULL; 757 766 DSCBUFFERDESC bd; 758 LPDIRECTSOUNDCAPTUREBUFFER pDSCB = NULL;759 767 RT_ZERO(bd); 760 768 bd.dwSize = sizeof(bd); … … 765 773 if (FAILED(hr)) 766 774 { 767 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating capture buffer: %Rhrc\n", hr)); 768 pDSoundStrmIn->pDSCB = NULL; 775 DSLOGREL(("DSound: CreateCaptureBuffer %Rhrc\n", hr)); 769 776 break; 770 777 } … … 774 781 if (FAILED(hr)) 775 782 { 776 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying for capture buffer interface: %Rhrc\n", hr)); 777 break; 778 } 779 780 /* Query the actual parameters. */ 783 DSLOGREL(("DSound: Query IDirectSoundCaptureBuffer8 %Rhrc\n", hr)); 784 break; 785 } 786 787 /* 788 * Query the actual parameters. 789 */ 781 790 DWORD cbReadPos = 0; 782 791 hr = IDirectSoundCaptureBuffer8_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos); … … 784 793 { 785 794 cbReadPos = 0; 786 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current position for capture stream:%Rhrc\n", hr));795 DSLOGREL(("DSound: Capture (open) GetCurrentPosition %Rhrc\n", hr)); 787 796 } 788 797 … … 791 800 if (FAILED(hr)) 792 801 { 793 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for capture stream:%Rhrc\n", hr));802 DSLOGREL(("DSound: Capture GetFormat %Rhrc\n", hr)); 794 803 break; 795 804 } … … 799 808 bc.dwSize = sizeof(bc); 800 809 hr = IDirectSoundCaptureBuffer8_GetCaps(pDSoundStrmIn->pDSCB, &bc); 801 if (FAILED 802 { 803 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for capture stream:%Rhrc\n", hr));804 break; 805 } 806 807 LogFunc(("Capture format:\n"808 "\tdwBufferBytes = %RI32\n"809 "\twFormatTag = %RI16\n"810 "\tnChannels = %RI16\n"811 "\tnSamplesPerSec = %RU32\n"812 "\tnAvgBytesPerSec = %RU32\n"813 "\tnBlockAlign = %RI16\n"814 "\twBitsPerSample = %RI16\n"815 "\tcbSize = %RI16\n",816 817 818 819 820 821 822 823 810 if (FAILED(hr)) 811 { 812 DSLOGREL(("DSound: Capture GetCaps %Rhrc\n", hr)); 813 break; 814 } 815 816 DSLOG(("DSound: Capture format:\n" 817 " dwBufferBytes = %RI32\n" 818 " wFormatTag = %RI16\n" 819 " nChannels = %RI16\n" 820 " nSamplesPerSec = %RU32\n" 821 " nAvgBytesPerSec = %RU32\n" 822 " nBlockAlign = %RI16\n" 823 " wBitsPerSample = %RI16\n" 824 " cbSize = %RI16\n", 825 bc.dwBufferBytes, 826 wfx.wFormatTag, 827 wfx.nChannels, 828 wfx.nSamplesPerSec, 829 wfx.nAvgBytesPerSec, 830 wfx.nBlockAlign, 831 wfx.wBitsPerSample, 832 wfx.cbSize)); 824 833 825 834 if (bc.dwBufferBytes & pDSoundStrmIn->strmIn.Props.uAlign) 826 LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",835 DSLOGREL(("DSound: Capture GetCaps returned misaligned buffer: size %RU32, alignment %RU32\n", 827 836 bc.dwBufferBytes, pDSoundStrmIn->strmIn.Props.uAlign + 1)); 828 837 829 838 if (bc.dwBufferBytes != pThis->cfg.cbBufferIn) 830 LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",839 DSLOGREL(("DSound: Capture buffer size mismatched: DirectSound %RU32, requested %RU32 bytes\n", 831 840 bc.dwBufferBytes, pThis->cfg.cbBufferIn)); 832 841 833 /* Initial state: reading at the initial capture position . */842 /* Initial state: reading at the initial capture position, no error. */ 834 843 pDSoundStrmIn->csCaptureReadPos = cbReadPos >> pDSoundStrmIn->strmIn.Props.cShift; 835 844 pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->strmIn.Props.cShift; 836 837 LogFlowFunc(("csCaptureReadPos=%ld, csCaptureBufferSize=%ld\n", 845 pDSoundStrmIn->hrLastCaptureIn = S_OK; 846 847 DSLOG(("DSound: csCaptureReadPos=%RU32, csCaptureBufferSize=%RU32\n", 838 848 pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize)); 839 849 840 /* Update status. */841 pDSoundStrmIn->hrLastCaptureIn = S_OK;842 843 850 } while (0); 844 851 845 if (SUCCEEDED(hr)) 846 return VINF_SUCCESS; 847 848 dsoundCaptureClose(pDSoundStrmIn); 849 return VERR_NOT_SUPPORTED; 850 } 851 852 static void dsoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn) 852 if (FAILED(hr)) 853 directSoundCaptureClose(pDSoundStrmIn); 854 855 return hr; 856 } 857 858 static void directSoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn) 853 859 { 854 860 AssertPtrReturnVoid(pDSoundStrmIn); … … 856 862 if (pDSoundStrmIn->pDSCB) 857 863 { 858 LogFlowFunc(("Capturing stopped\n"));864 DSLOG(("DSound: Stopping capture\n")); 859 865 860 866 HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 861 867 if (FAILED(hr)) 862 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer:%Rhrc\n", hr));863 } 864 } 865 866 static int dsoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)868 DSLOGREL(("DSound: Capture buffer stop %Rhrc\n", hr)); 869 } 870 } 871 872 static HRESULT directSoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn) 867 873 { 868 874 AssertPtrReturn(pThis, VERR_INVALID_POINTER); … … 870 876 871 877 HRESULT hr; 872 873 878 if (pDSoundStrmIn->pDSCB != NULL) 874 879 { … … 877 882 if (FAILED(hr)) 878 883 { 879 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting capture buffer status:%Rhrc\n", hr));884 DSLOGREL(("DSound: Capture start GetStatus %Rhrc\n", hr)); 880 885 } 881 886 else … … 883 888 if (dwStatus & DSCBSTATUS_CAPTURING) 884 889 { 885 LogFlowFunc(("Already capturing\n"));890 DSLOG(("DSound: Already capturing\n")); 886 891 } 887 892 else 888 893 { 889 LogFlowFunc(("Capturig started\n"));894 DSLOG(("DSound: Capture start\n")); 890 895 hr = IDirectSoundCaptureBuffer8_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING); 891 if (FAILED 892 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting capture:%Rhrc\n", hr));896 if (FAILED(hr)) 897 DSLOGREL(("DSound: Capture started %Rhrc\n", hr)); 893 898 } 894 899 } … … 896 901 else 897 902 { 898 AssertMsgFailed(("No/invalid capture buffer\n")); 899 hr = E_FAIL; 900 } 901 902 return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED; 903 hr = E_UNEXPECTED; 904 } 905 906 return hr; 903 907 } 904 908 … … 942 946 static void dsoundLogDevice(const char *pszType, LPGUID lpGUID, LPCWSTR lpwstrDescription, LPCWSTR lpwstrModule) 943 947 { 944 AssertPtrReturnVoid(pszType);945 AssertPtrReturnVoid(lpGUID);946 AssertPtrReturnVoid(lpwstrDescription);947 AssertPtrReturnVoid(lpwstrModule);948 949 948 char *pszGUID = dsoundGUIDToUtf8StrA(lpGUID); 950 if (pszGUID) 951 { 952 LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n", 953 pszType, pszGUID, lpwstrDescription, lpwstrModule)); 954 955 RTStrFree(pszGUID); 956 } 949 /* This always has to be in the release log. */ 950 LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n", 951 pszType, pszGUID? pszGUID: "{?}", lpwstrDescription, lpwstrModule)); 952 RTStrFree(pszGUID); 957 953 } 958 954 … … 960 956 LPCWSTR lpwstrModule, LPVOID lpContext) 961 957 { 962 AssertPtrReturn(lpContext, FALSE);963 964 958 PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext; 965 959 AssertPtrReturn(pCtx, FALSE); … … 971 965 972 966 AssertPtrReturn(lpwstrDescription, FALSE); 973 AssertPtrReturn(lpwstrModule, FALSE);967 /* Do not care about lpwstrModule */ 974 968 975 969 dsoundLogDevice("Output", lpGUID, lpwstrDescription, lpwstrModule); … … 1043 1037 1044 1038 /* Try to open playback in case the device is already there. */ 1045 d soundPlayOpen(pThis, pDSoundStrmOut);1039 directSoundPlayOpen(pThis, pDSoundStrmOut); 1046 1040 } 1047 1041 else … … 1071 1065 { 1072 1066 /* Try to start playback. If it fails, then reopen and try again. */ 1073 rc = dsoundPlayStart(pDSoundStrmOut);1074 if ( RT_FAILURE(rc))1067 HRESULT hr = directSoundPlayStart(pDSoundStrmOut); 1068 if (FAILED(hr)) 1075 1069 { 1076 d soundPlayClose(pDSoundStrmOut);1077 d soundPlayOpen(pThis, pDSoundStrmOut);1078 1079 rc = dsoundPlayStart(pDSoundStrmOut);1070 directSoundPlayClose(pDSoundStrmOut); 1071 directSoundPlayOpen(pThis, pDSoundStrmOut); 1072 1073 hr = directSoundPlayStart(pDSoundStrmOut); 1080 1074 } 1081 1075 1076 if (FAILED(hr)) 1077 rc = VERR_NOT_SUPPORTED; 1078 1082 1079 break; 1083 1080 } … … 1085 1082 case PDMAUDIOSTREAMCMD_DISABLE: 1086 1083 { 1087 d soundPlayStop(pThis, pDSoundStrmOut);1084 directSoundPlayStop(pThis, pDSoundStrmOut); 1088 1085 break; 1089 1086 } … … 1100 1097 return rc; 1101 1098 } 1102 1103 1099 1104 1100 static DECLCALLBACK(int) drvHostDSoundPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut, … … 1115 1111 uint32_t cReadTotal = 0; 1116 1112 1117 do 1113 do /* to use 'break' */ 1118 1114 { 1119 1115 LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB; … … 1129 1125 if (hr == DSERR_BUFFERLOST) 1130 1126 { 1131 rc = dsoundPlayRestore(pDSB); 1132 if (RT_FAILURE(rc)) 1133 break; 1134 1135 hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, NULL); 1136 if (hr == DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */ 1137 break; 1127 hr = directSoundPlayRestore(pDSB); 1128 if (SUCCEEDED(hr)) 1129 { 1130 hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, NULL); 1131 } 1138 1132 } 1139 1133 1140 1134 if (FAILED(hr)) 1141 1135 { 1142 LogRelMax(s_cMaxRelLogEntries, ("Error retrieving current playback position: %Rhrc\n", hr)); 1136 if (hr != DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */ 1137 DSLOGREL(("DSound: Playback GetCurrentPosition %Rhrc\n", hr)); 1143 1138 break; 1144 1139 } … … 1162 1157 if (cbLive == 0 || cbLive > cbBuffer) 1163 1158 { 1164 LogFlowFunc(("cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n",1165 1159 DSLOG(("DSound: cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n", 1160 cbLive, cbBuffer, pDSoundStrmOut->cbPlayWritePos, cbPlayPos)); 1166 1161 break; 1167 1162 } … … 1169 1164 LPVOID pv1, pv2; 1170 1165 DWORD cb1, cb2; 1171 rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive,1172 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);1173 if ( RT_FAILURE(rc))1166 hr = directSoundPlayLock(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive, 1167 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */); 1168 if (FAILED(hr)) 1174 1169 break; 1175 1170 … … 1195 1190 } 1196 1191 1197 d soundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);1192 directSoundPlayUnlock(pDSB, pv1, pv2, cb1, cb2); 1198 1193 1199 1194 pDSoundStrmOut->cbPlayWritePos = (pDSoundStrmOut->cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer; 1200 1195 1201 LogFlowFunc(("%RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n",1202 1203 1204 1196 DSLOGF(("DSound: %RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n", 1197 AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive, 1198 cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "", 1199 pDSoundStrmOut->cbPlayWritePos, rc)); 1205 1200 1206 1201 if (cReadTotal) … … 1209 1204 rc = VINF_SUCCESS; /* Played something. */ 1210 1205 } 1206 1207 if (RT_FAILURE(rc)) 1208 break; 1211 1209 1212 1210 if (pDSoundStrmOut->fRestartPlayback) … … 1217 1215 */ 1218 1216 pDSoundStrmOut->fRestartPlayback = false; 1219 HRESULThr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);1217 hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING); 1220 1218 if (FAILED(hr)) 1221 1219 { 1222 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting playback:%Rhrc\n", hr));1220 DSLOGREL(("DSound: Playback start %Rhrc\n", hr)); 1223 1221 rc = VERR_NOT_SUPPORTED; 1224 1222 } … … 1237 1235 PDSOUNDSTREAMOUT pDSoundStrmOut = (PDSOUNDSTREAMOUT)pHstStrmOut; 1238 1236 1239 d soundPlayClose(pDSoundStrmOut);1237 directSoundPlayClose(pDSoundStrmOut); 1240 1238 1241 1239 pDSoundStrmOut->cbPlayWritePos = 0; … … 1277 1275 1278 1276 /* Try to open capture in case the device is already there. */ 1279 d soundCaptureOpen(pThis, pDSoundStrmIn);1277 directSoundCaptureOpen(pThis, pDSoundStrmIn); 1280 1278 } 1281 1279 else … … 1306 1304 { 1307 1305 /* Try to start capture. If it fails, then reopen and try again. */ 1308 rc = dsoundCaptureStart(pThis, pDSoundStrmIn);1309 if ( RT_FAILURE(rc))1306 HRESULT hr = directSoundCaptureStart(pThis, pDSoundStrmIn); 1307 if (FAILED(hr)) 1310 1308 { 1311 d soundCaptureClose(pDSoundStrmIn);1312 d soundCaptureOpen(pThis, pDSoundStrmIn);1313 1314 rc = dsoundCaptureStart(pThis, pDSoundStrmIn);1309 directSoundCaptureClose(pDSoundStrmIn); 1310 directSoundCaptureOpen(pThis, pDSoundStrmIn); 1311 1312 hr = directSoundCaptureStart(pThis, pDSoundStrmIn); 1315 1313 } 1314 1315 if (FAILED(hr)) 1316 rc = VERR_NOT_SUPPORTED; 1316 1317 } break; 1317 1318 1318 1319 case PDMAUDIOSTREAMCMD_DISABLE: 1319 1320 { 1320 d soundCaptureStop(pDSoundStrmIn);1321 directSoundCaptureStop(pDSoundStrmIn); 1321 1322 } break; 1322 1323 … … 1338 1339 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB = pDSoundStrmIn->pDSCB; 1339 1340 1340 int rc ;1341 int rc = VINF_SUCCESS; 1341 1342 1342 1343 if (pDSCB == NULL) … … 1354 1355 if (hr != pDSoundStrmIn->hrLastCaptureIn) 1355 1356 { 1356 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current capture position:%Rhrc\n", hr));1357 DSLOGREL(("DSound: Capture GetCurrentPosition %Rhrc\n", hr)); 1357 1358 pDSoundStrmIn->hrLastCaptureIn = hr; 1358 1359 } … … 1365 1366 1366 1367 if (cbReadPos & pHstStrmIn->Props.uAlign) 1367 LogFunc(("Misalignedread position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign));1368 DSLOGF(("DSound: Misaligned capture read position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign)); 1368 1369 1369 1370 /* Capture position in samples. */ … … 1386 1387 if (csMixFree == 0) 1387 1388 { 1388 LogRelMax(s_cMaxRelLogEntries,("DSound: Capture buffer full\n"));1389 DSLOGF(("DSound: Capture buffer full\n")); 1389 1390 if (pcSamplesCaptured) 1390 1391 *pcSamplesCaptured = 0; … … 1392 1393 } 1393 1394 1394 LogFlowFunc(("csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n",1395 1395 DSLOGF(("DSound: Capture csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n", 1396 csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured)); 1396 1397 1397 1398 /* No need to fetch more samples than mix buffer can receive. */ … … 1401 1402 LPVOID pv1, pv2; 1402 1403 DWORD cb1, cb2; 1403 rc = dsoundLockInput(pDSCB, &pHstStrmIn->Props,1404 pDSoundStrmIn->csCaptureReadPos << pHstStrmIn->Props.cShift,1405 csCaptured << pHstStrmIn->Props.cShift,1406 &pv1, &pv2, &cb1, &cb2,1407 0 /* dwFlags */);1408 if ( RT_FAILURE(rc))1404 hr = directSoundCaptureLock(pDSCB, &pHstStrmIn->Props, 1405 pDSoundStrmIn->csCaptureReadPos << pHstStrmIn->Props.cShift, 1406 csCaptured << pHstStrmIn->Props.cShift, 1407 &pv1, &pv2, &cb1, &cb2, 1408 0 /* dwFlags */); 1409 if (FAILED(hr)) 1409 1410 { 1410 1411 if (pcSamplesCaptured) … … 1436 1437 } 1437 1438 1438 d soundUnlockInput(pDSCB, pv1, pv2, cb1, cb2);1439 directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2); 1439 1440 1440 1441 uint32_t csProcessed = 0; … … 1449 1450 { 1450 1451 pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + csProcessed) % pDSoundStrmIn->csCaptureBufferSize; 1451 LogFlowFunc(("%ld (%ld+%ld), processed %RU32/%RU32\n",1452 1452 DSLOGF(("DSound: Capture %ld (%ld+%ld), processed %RU32/%RU32\n", 1453 csCaptured, len1, len2, csProcessed, csWrittenTotal)); 1453 1454 } 1454 1455 … … 1464 1465 PDSOUNDSTREAMIN pDSoundStrmIn = (PDSOUNDSTREAMIN)pHstStrmIn; 1465 1466 1466 d soundCaptureClose(pDSoundStrmIn);1467 directSoundCaptureClose(pDSoundStrmIn); 1467 1468 1468 1469 pDSoundStrmIn->csCaptureReadPos = 0; … … 1529 1530 { 1530 1531 /* No dsound.dll on this system. */ 1531 LogRel(("DSound: could not load dsound.dll %Rrc\n", rc));1532 LogRel(("DSound: Could not load dsound.dll %Rrc\n", rc)); 1532 1533 } 1533 1534 … … 1566 1567 IDirectSound_Release(pDirectSound); 1567 1568 else 1568 LogRel(("DSound: DirectSound not available:%Rhrc\n", hr));1569 DSLOGREL(("DSound: DirectSound not available %Rhrc\n", hr)); 1569 1570 1570 1571 int rc = SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED; … … 1592 1593 if (RT_SUCCESS(rc)) 1593 1594 { 1594 intrc = RTUuidFromStr(pUuid, pszGuid);1595 rc = RTUuidFromStr(pUuid, pszGuid); 1595 1596 if (RT_SUCCESS(rc)) 1596 1597 pGuid = (LPCGUID)&pUuid; 1597 1598 else 1598 LogRel(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc));1599 DSLOGREL(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc)); 1599 1600 1600 1601 RTStrFree(pszGuid); … … 1616 1617 pThis->cfg.pGuidCapture = dsoundConfigQueryGUID(pCfg, "DeviceGuidIn", &pThis->cfg.uuidCapture); 1617 1618 1618 LogFlowFunc(("BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",1619 1620 1621 1622 1619 DSLOG(("DSound: BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n", 1620 pThis->cfg.cbBufferOut, 1621 pThis->cfg.cbBufferIn, 1622 &pThis->cfg.uuidPlay, 1623 &pThis->cfg.uuidCapture)); 1623 1624 } 1624 1625 … … 1643 1644 { 1644 1645 PDRVHOSTDSOUND pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTDSOUND); 1646 1645 1647 LogRel(("Audio: Initializing DirectSound audio driver\n")); 1648 1646 1649 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); 1647 1650 … … 1649 1652 if (FAILED(hr)) 1650 1653 { 1651 LogRel(("DSound: Error initializing COM:%Rhrc\n", hr));1654 DSLOGREL(("DSound: CoInitializeEx %Rhrc\n", hr)); 1652 1655 return VERR_NOT_SUPPORTED; 1653 1656 }
Note:
See TracChangeset
for help on using the changeset viewer.