- Timestamp:
- Dec 8, 2015 3:20:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r59029 r59059 461 461 } 462 462 463 static voiddirectSoundPlayClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)464 { 465 AssertPtrReturn Void(pThis);466 AssertPtrReturn Void(pDSoundStrmOut);463 static HRESULT directSoundPlayClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut) 464 { 465 AssertPtrReturn(pThis, E_POINTER); 466 AssertPtrReturn(pDSoundStrmOut, E_POINTER); 467 467 468 468 DSLOG(("DSound: Closing playback stream %p, buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB)); 469 469 470 HRESULT hr = S_OK; 471 470 472 if (pDSoundStrmOut->pDSB) 471 473 { 472 HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 473 if (FAILED(hr)) 474 hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB); 475 if (SUCCEEDED(hr)) 476 { 477 #ifdef VBOX_WITH_AUDIO_CALLBACKS 478 if (pThis->aEvents[DSOUNDEVENT_OUTPUT] != NULL) 479 { 480 CloseHandle(pThis->aEvents[DSOUNDEVENT_OUTPUT]); 481 pThis->aEvents[DSOUNDEVENT_OUTPUT] = NULL; 482 483 if (pThis->cEvents) 484 pThis->cEvents--; 485 486 pThis->pDSStrmOut = NULL; 487 } 488 489 int rc2 = dsoundNotifyThread(pThis, false /* fShutdown */); 490 AssertRC(rc2); 491 #endif 492 IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB); 493 pDSoundStrmOut->pDSB = NULL; 494 } 495 else 474 496 DSLOGREL(("DSound: Stop playback stream %p when closing %Rhrc\n", pDSoundStrmOut, hr)); 475 476 #ifdef VBOX_WITH_AUDIO_CALLBACKS 477 if (pThis->aEvents[DSOUNDEVENT_OUTPUT] != NULL) 478 { 479 CloseHandle(pThis->aEvents[DSOUNDEVENT_OUTPUT]); 480 pThis->aEvents[DSOUNDEVENT_OUTPUT] = NULL; 481 482 if (pThis->cEvents) 483 pThis->cEvents--; 484 485 pThis->pDSStrmOut = NULL; 486 } 487 488 int rc2 = dsoundNotifyThread(pThis, false /* fShutdown */); 489 AssertRC(rc2); 490 #endif 491 IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB); 492 pDSoundStrmOut->pDSB = NULL; 493 } 494 495 directSoundPlayInterfaceRelease(pDSoundStrmOut); 497 } 498 499 if (SUCCEEDED(hr)) 500 directSoundPlayInterfaceRelease(pDSoundStrmOut); 501 502 return hr; 496 503 } 497 504 … … 531 538 DSBUFFERDESC bd; 532 539 RT_ZERO(bd); 533 bd.dwSize 534 bd.lpwfxFormat 535 bd.dwFlags 540 bd.dwSize = sizeof(bd); 541 bd.lpwfxFormat = &wfx; 542 bd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2; 536 543 #ifdef VBOX_WITH_AUDIO_CALLBACKS 537 544 bd.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; … … 696 703 /* pdwStatus is optional. */ 697 704 705 bool fRestoreBuffer = false; 706 698 707 DWORD dwStatus = 0; 699 708 HRESULT hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus); 700 709 if (SUCCEEDED(hr)) 701 710 { 702 if ((dwStatus & DSBSTATUS_BUFFERLOST) != 0) 703 { 704 hr = directSoundPlayRestore(pDSB); 705 if (SUCCEEDED(hr)) 706 hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus); 707 } 711 fRestoreBuffer = RT_BOOL(dwStatus & DSBSTATUS_BUFFERLOST); 712 } 713 else if (hr == DSERR_BUFFERLOST) 714 fRestoreBuffer = true; 715 716 if (fRestoreBuffer) 717 { 718 hr = directSoundPlayRestore(pDSB); 719 if (SUCCEEDED(hr)) 720 hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus); 708 721 } 709 722 … … 876 889 } 877 890 878 static voiddirectSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)879 { 880 AssertPtrReturn Void(pDSoundStrmIn);891 static HRESULT directSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn) 892 { 893 AssertPtrReturn(pDSoundStrmIn, E_POINTER); 881 894 882 895 DSLOG(("DSound: pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB)); 883 896 897 HRESULT hr = S_OK; 898 884 899 if (pDSoundStrmIn->pDSCB) 885 900 { 886 HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 887 if (FAILED(hr)) 901 hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB); 902 if (SUCCEEDED(hr)) 903 { 904 IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB); 905 pDSoundStrmIn->pDSCB = NULL; 906 } 907 else 888 908 DSLOGREL(("DSound: Stop capture buffer %Rhrc\n", hr)); 889 890 IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB); 891 pDSoundStrmIn->pDSCB = NULL;892 }893 894 directSoundCaptureInterfaceRelease(pDSoundStrmIn);909 } 910 911 if (SUCCEEDED(hr)) 912 directSoundCaptureInterfaceRelease(pDSoundStrmIn); 913 914 return hr; 895 915 } 896 916 … … 1332 1352 DWORD cb1, cb2; 1333 1353 HRESULT hr = directSoundPlayLock(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive, 1334 1354 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */); 1335 1355 if (FAILED(hr)) 1336 1356 { … … 1405 1425 if (RT_SUCCESS(rc)) 1406 1426 { 1407 1408 1427 if (pcSamplesPlayed) 1428 *pcSamplesPlayed = cReadTotal; 1409 1429 } 1410 1430 … … 1419 1439 directSoundPlayClose(pThis, pDSoundStrmOut); 1420 1440 1421 pDSoundStrmOut->cbPlayWritePos 1422 pDSoundStrmOut->fRestartPlayback 1441 pDSoundStrmOut->cbPlayWritePos = 0; 1442 pDSoundStrmOut->fRestartPlayback = true; 1423 1443 pDSoundStrmOut->csPlaybackBufferSize = 0; 1424 1444 … … 1491 1511 if (FAILED(hr)) 1492 1512 { 1493 directSoundCaptureClose(pDSoundStrmIn); 1494 directSoundCaptureOpen(pThis, pDSoundStrmIn); 1495 1496 hr = directSoundCaptureStart(pThis, pDSoundStrmIn); 1513 hr = directSoundCaptureClose(pDSoundStrmIn); 1514 if (SUCCEEDED(hr)) 1515 { 1516 hr = directSoundCaptureOpen(pThis, pDSoundStrmIn); 1517 if (SUCCEEDED(hr)) 1518 hr = directSoundCaptureStart(pThis, pDSoundStrmIn); 1519 } 1497 1520 } 1498 1521 … … 1517 1540 rc = VERR_INVALID_PARAMETER; 1518 1541 break; 1519 1542 } 1520 1543 } 1521 1544 … … 1538 1561 if (pDSCB == NULL) 1539 1562 { 1540 pThis->fEnabledIn = false;1541 1542 rc = VERR_NOT_AVAILABLE;1543 break;1563 pThis->fEnabledIn = false; 1564 1565 rc = VERR_NOT_AVAILABLE; 1566 break; 1544 1567 } 1545 1568 … … 1555 1578 } 1556 1579 1557 rc = VERR_NOT_AVAILABLE;1558 break;1580 rc = VERR_NOT_AVAILABLE; 1581 break; 1559 1582 } 1560 1583 … … 1570 1593 DWORD csCaptured = dsoundRingDistance(csReadPos, pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize); 1571 1594 if (csCaptured == 0) 1572 break;1595 break; 1573 1596 1574 1597 /* Using as an intermediate not circular buffer. */ … … 1580 1603 { 1581 1604 DSLOGF(("DSound: Capture buffer full\n")); 1582 break;1605 break; 1583 1606 } 1584 1607 … … 1599 1622 if (FAILED(hr)) 1600 1623 { 1601 rc = VERR_ACCESS_DENIED;1602 break;1624 rc = VERR_ACCESS_DENIED; 1625 break; 1603 1626 } 1604 1627 … … 1628 1651 directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2); 1629 1652 1630 if (csWrittenTotal) /* Captured something? */1631 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal, &cCaptured);1653 if (csWrittenTotal) /* Captured something? */ 1654 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal, &cCaptured); 1632 1655 1633 1656 if (RT_SUCCESS(rc)) 1634 1657 { 1635 pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + cCaptured) % pDSoundStrmIn->csCaptureBufferSize;1658 pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + cCaptured) % pDSoundStrmIn->csCaptureBufferSize; 1636 1659 DSLOGF(("DSound: Capture %ld (%ld+%ld), processed %RU32/%RU32\n", 1637 csCaptured, len1, len2, cCaptured, csWrittenTotal));1660 csCaptured, len1, len2, cCaptured, csWrittenTotal)); 1638 1661 } 1639 1662 … … 1870 1893 CloseHandle(pThis->aEvents[DSOUNDEVENT_NOTIFY]); 1871 1894 pThis->aEvents[DSOUNDEVENT_NOTIFY] = NULL; 1872 1895 } 1873 1896 #endif 1874 1897 … … 1910 1933 DSLOGREL(("DSound: Waiting for thread to initialize failed with rc=%Rrc\n", rc)); 1911 1934 } 1912 1935 else 1913 1936 DSLOGREL(("DSound: Creating thread failed with rc=%Rrc\n", rc)); 1914 1937 #else … … 2037 2060 pThis->fEnabledOut = false; 2038 2061 #ifdef VBOX_WITH_AUDIO_CALLBACKS 2039 pThis->fStopped 2040 pThis->fShutdown 2062 pThis->fStopped = false; 2063 pThis->fShutdown = false; 2041 2064 2042 2065 RT_ZERO(pThis->aEvents); … … 2068 2091 "DirectSound Audio host driver", 2069 2092 /* fFlags */ 2070 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,2093 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT, 2071 2094 /* fClass. */ 2072 2095 PDM_DRVREG_CLASS_AUDIO,
Note:
See TracChangeset
for help on using the changeset viewer.