Changeset 65095 in vbox
- Timestamp:
- Jan 4, 2017 9:10:27 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevHDA.cpp
r65070 r65095 642 642 /** Shutdown indicator. */ 643 643 volatile bool fShutdown; 644 /** Whether the thread should do any data processing or not. */ 645 volatile bool fEnabled; 644 646 uint32_t Padding1; 645 647 } HDASTREAMSTATEAIO, *PHDASTREAMSTATEAIO; … … 1005 1007 static int hdaStreamUpdate(PHDASTATE pThis, PHDASTREAM pStream); 1006 1008 DECLINLINE(uint32_t) hdaStreamUpdateLPIB(PHDASTATE pThis, PHDASTREAM pStream, uint32_t u32LPIB); 1009 static void hdaStreamLock(PHDASTREAM pStream); 1010 static void hdaStreamUnlock(PHDASTREAM pStream); 1007 1011 #endif /* IN_RING3 */ 1008 1012 /** @} */ … … 1019 1023 static void hdaStreamAsyncIOLock(PHDASTREAM pStream); 1020 1024 static void hdaStreamAsyncIOUnlock(PHDASTREAM pStream); 1025 static void hdaStreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable); 1021 1026 # endif 1022 1027 #endif … … 1306 1311 1307 1312 /** 1313 * Locks an HDA stream for serialized access. 1314 * 1315 * @returns IPRT status code. 1316 * @param pStream HDA stream to lock. 1317 */ 1318 static void hdaStreamLock(PHDASTREAM pStream) 1319 { 1320 AssertPtrReturnVoid(pStream); 1321 int rc2 = RTCritSectEnter(&pStream->State.CritSect); 1322 AssertRC(rc2); 1323 } 1324 1325 1326 /** 1327 * Unlocks a formerly locked HDA stream. 1328 * 1329 * @returns IPRT status code. 1330 * @param pStream HDA stream to unlock. 1331 */ 1332 static void hdaStreamUnlock(PHDASTREAM pStream) 1333 { 1334 AssertPtrReturnVoid(pStream); 1335 int rc2 = RTCritSectLeave(&pStream->State.CritSect); 1336 AssertRC(rc2); 1337 } 1338 1339 1340 /** 1308 1341 * Fetches the next BDLE to use for a stream. 1309 1342 * … … 1809 1842 LogFunc(("[SD%RU8]: Reset\n", uSD)); 1810 1843 1811 int rc2;1812 #ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO1813 /*1814 * Make sure to destroy the async I/O thread for this stream on reset, as we1815 * can't be sure that the same stream is being used in the next cycle1816 * (and therefore would leave unused threads around).1817 */1818 rc2 = hdaStreamAsyncIODestroy(pThis, pStream);1819 AssertRC(rc2);1820 #endif1821 1822 1844 /* 1823 1845 * First, reset the internal stream state. … … 1854 1876 HDA_STREAM_REG(pThis, BDPL, uSD) = 0; 1855 1877 1856 rc2 = hdaStreamInit(pThis, pStream, uSD);1878 int rc2 = hdaStreamInit(pThis, pStream, uSD); 1857 1879 AssertRC(rc2); 1858 1880 } … … 1863 1885 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1864 1886 1865 LogF lowFunc(("[SD%RU8]: fEnable=%RTbool, pMixSink=%p\n", pStream->u8SD, fEnable, pStream->pMixSink));1887 LogFunc(("[SD%RU8]: fEnable=%RTbool, pMixSink=%p\n", pStream->u8SD, fEnable, pStream->pMixSink)); 1866 1888 1867 1889 int rc = VINF_SUCCESS; 1890 1891 hdaStreamLock(pStream); 1868 1892 1869 1893 #ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO 1870 1894 hdaStreamAsyncIOLock(pStream); 1895 hdaStreamAsyncIOEnable(pStream, fEnable); 1871 1896 #endif 1872 1897 … … 1880 1905 rc = AudioMixerSinkCtl(pStream->pMixSink->pMixSink, enmCmd); 1881 1906 } 1882 else1883 rc = VINF_SUCCESS;1884 1907 1885 1908 #ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO … … 1887 1910 #endif 1888 1911 1889 if (RT_FAILURE(rc)) 1890 { 1891 LogFunc(("Failed with rc=%Rrc\n", rc)); 1892 return rc; 1893 } 1894 1912 /* Make sure to leave the lock before (eventually) starting the timer. */ 1913 hdaStreamUnlock(pStream); 1914 1915 #ifndef VBOX_WITH_AUDIO_HDA_CALLBACKS 1895 1916 /* Second, see if we need to start or stop the timer. */ 1896 1917 if (!fEnable) 1897 {1898 # ifndef VBOX_WITH_AUDIO_HDA_CALLBACKS1899 1918 hdaTimerMaybeStop(pThis); 1900 # endif1901 }1902 1919 else 1903 {1904 # ifndef VBOX_WITH_AUDIO_HDA_CALLBACKS1905 1920 hdaTimerMaybeStart(pThis); 1906 # endif 1907 } 1908 1909 LogFlowFunc(("u8Strm=%RU8, fEnable=%RTbool, cStreamsActive=%RU8\n", pStream->u8SD, fEnable, pThis->cStreamsActive)); 1910 return VINF_SUCCESS; 1911 } 1912 1913 static void hdaStreamAssignToSink(PHDASTREAM pStream, PHDAMIXERSINK pMixSink) 1914 { 1915 AssertPtrReturnVoid(pStream); 1916 1917 int rc2 = RTCritSectEnter(&pStream->State.CritSect); 1918 if (RT_SUCCESS(rc2)) 1919 { 1920 pStream->pMixSink = pMixSink; 1921 1922 rc2 = RTCritSectLeave(&pStream->State.CritSect); 1923 AssertRC(rc2); 1924 } 1921 #endif 1922 1923 LogFunc(("[SD%RU8]: cStreamsActive=%RU8, rc=%Rrc\n", pStream->u8SD, pThis->cStreamsActive, rc)); 1924 return rc; 1925 1925 } 1926 1926 … … 2371 2371 AssertPtr(pStream); 2372 2372 2373 /* Note: Do not use hdaRegWriteSDLock() here, as SDnCTL might change the RUN bit. */2374 int rc2 = RTCritSectEnter(&pStream->State.CritSect);2375 AssertRC(rc2);2376 2377 2373 if (fInReset) 2378 2374 { … … 2399 2395 ASMAtomicXchgBool(&pStream->State.fInReset, true); 2400 2396 2397 hdaStreamLock(pStream); 2398 2401 2399 hdaStreamReset(pThis, pStream); 2400 2401 hdaStreamUnlock(pStream); 2402 2402 } 2403 2403 else … … 2414 2414 { 2415 2415 /* Make sure to first fetch the current BDLE before enabling the stream below. */ 2416 rc2 = hdaBDLEFetch(pThis, &pStream->State.BDLE, pStream->u64BDLBase, pStream->State.uCurBDLE);2416 int rc2 = hdaBDLEFetch(pThis, &pStream->State.BDLE, pStream->u64BDLBase, pStream->State.uCurBDLE); 2417 2417 AssertRC(rc2); 2418 2418 } … … 2422 2422 } 2423 2423 2424 rc2 = hdaRegWriteU24(pThis, iReg, u32Value);2424 int rc2 = hdaRegWriteU24(pThis, iReg, u32Value); 2425 2425 AssertRC(rc2); 2426 2426 2427 2427 /* Make sure to handle interrupts here as well. */ 2428 2428 hdaProcessInterrupt(pThis); 2429 2430 rc2 = RTCritSectLeave(&pStream->State.CritSect);2431 AssertRC(rc2);2432 2429 2433 2430 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ … … 3658 3655 * @param pThis HDA state. 3659 3656 * @param enmMixerCtl Mixer control to remove. 3657 * 3658 * @remarks Can be called as a callback by the HDA codec. 3660 3659 */ 3661 3660 static DECLCALLBACK(int) hdaMixerRemoveStream(PHDASTATE pThis, PDMAUDIOMIXERCTL enmMixerCtl) … … 3736 3735 * @param uSD SD stream number (number + 1) to set. Set to 0 for unassign. 3737 3736 * @param uChannel Channel to set. Only valid if a valid SD stream number is specified. 3737 * 3738 * @remarks Can be called as a callback by the HDA codec. 3738 3739 */ 3739 3740 static DECLCALLBACK(int) hdaMixerSetStream(PHDASTATE pThis, PDMAUDIOMIXERCTL enmMixerCtl, uint8_t uSD, uint8_t uChannel) … … 3771 3772 if (pStream) 3772 3773 { 3773 pSink->uSD = uSD; 3774 pSink->uChannel = uChannel; 3775 3776 /* Make sure that the stream also has this sink set. */ 3777 hdaStreamAssignToSink(pStream, pSink); 3774 hdaStreamLock(pStream); 3775 3776 pSink->uSD = uSD; 3777 pSink->uChannel = uChannel; 3778 pStream->pMixSink = pSink; 3779 3780 hdaStreamUnlock(pStream); 3778 3781 3779 3782 rc = VINF_SUCCESS; … … 3800 3803 * @param enmMixerCtl Mixer control to set volume for. 3801 3804 * @param pVol Pointer to volume data to set. 3805 * 3806 * @remarks Can be called as a callback by the HDA codec. 3802 3807 */ 3803 3808 static DECLCALLBACK(int) hdaMixerSetVolume(PHDASTATE pThis, … … 4407 4412 if (RT_SUCCESS(rc2)) 4408 4413 { 4414 if (!pAIO->fEnabled) 4415 { 4416 RTCritSectLeave(&pAIO->CritSect); 4417 continue; 4418 } 4419 4409 4420 uint32_t cbToProcess; 4410 4421 uint32_t cbProcessed = 0; … … 4566 4577 AssertRC(rc2); 4567 4578 } 4579 4580 /** 4581 * Enables (resumes) or disables (pauses) the async I/O thread. 4582 * 4583 * @param pStream HDA stream to enable/disable async I/O thread for. 4584 * @param fEnable Whether to enable or disable the I/O thread. 4585 * 4586 * @remarks Does not do locking. 4587 */ 4588 static void hdaStreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable) 4589 { 4590 PHDASTREAMSTATEAIO pAIO = &pStream->State.AIO; 4591 ASMAtomicXchgBool(&pAIO->fEnabled, fEnable); 4592 } 4568 4593 #endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */ 4569 4594 … … 4586 4611 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 4587 4612 4613 hdaStreamLock(pStream); 4614 4588 4615 PHDAMIXERSINK pSink = pStream->pMixSink; 4589 4616 AssertPtr(pSink); … … 4593 4620 4594 4621 if (!AudioMixerSinkIsActive(pSink->pMixSink)) 4622 { 4623 hdaStreamUnlock(pStream); 4595 4624 return VINF_SUCCESS; 4625 } 4596 4626 4597 4627 Log2Func(("[SD%RU8]\n", pStream->u8SD)); 4598 4599 int rc = VINF_SUCCESS;4600 4628 4601 4629 bool fDone = false; … … 4735 4763 } /* while !fDone */ 4736 4764 4737 return rc; 4765 hdaStreamUnlock(pStream); 4766 4767 return VINF_SUCCESS; 4738 4768 } 4739 4769 #endif /* IN_RING3 */
Note:
See TracChangeset
for help on using the changeset viewer.