VirtualBox

Changeset 62910 in vbox for trunk


Ignore:
Timestamp:
Aug 3, 2016 12:28:51 PM (8 years ago)
Author:
vboxsync
Message:

DrvHostDSound.cpp: No need to verify parameters twice (there's more of this silliness) and don't pass pInterface when you can pass pThis to workers. Some documentation clean (much to be desired still) - cannot figure why this is so difficult to incorporate into the initial code writing, sigh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp

    r62909 r62910  
    263263                           PDSOUNDSTREAMOUT pDSoundStream, DWORD *pdwBuffer, DWORD *pdwFree, DWORD *pdwPlayPos)
    264264{
    265     AssertPtrReturn(pThis,         VERR_INVALID_POINTER);
     265    AssertPtr(pThis);
    266266    AssertPtrReturn(pDSoundStream, VERR_INVALID_POINTER);
    267267    AssertPtrNull(pdwBuffer);
     
    755755static HRESULT directSoundPlayGetStatus(PDRVHOSTDSOUND pThis, LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pdwStatus)
    756756{
    757     AssertPtrReturn(pThis, E_POINTER);
     757    AssertPtr(pThis);
    758758    AssertPtrReturn(pDSB,  E_POINTER);
    759759    AssertPtrNull(pdwStatus);
     
    14151415}
    14161416
    1417 static int dsoundCreateStreamOut(PPDMIHOSTAUDIO pInterface,
    1418                                  PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
    1419 {
    1420     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1421     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    1422     AssertPtrReturn(pCfg,       VERR_INVALID_POINTER);
    1423     /* pcSamples is optional. */
    1424 
     1417static int dsoundCreateStreamOut(PDRVHOSTDSOUND pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
     1418{
    14251419    LogFlowFunc(("pStream=%p, pCfg=%p\n", pStream, pCfg));
    1426 
    1427     PDRVHOSTDSOUND   pThis         = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    14281420    PDSOUNDSTREAMOUT pDSoundStream = (PDSOUNDSTREAMOUT)pStream;
    14291421
     
    14471439    }
    14481440    else
    1449     {
    14501441        RT_ZERO(pDSoundStream->streamCfg);
    1451     }
    14521442
    14531443    LogFlowFuncLeaveRC(rc);
     
    14551445}
    14561446
    1457 static int dsoundControlStreamOut(PPDMIHOSTAUDIO pInterface,
    1458                                   PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
    1459 {
    1460     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1461     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    1462 
     1447static int dsoundControlStreamOut(PDRVHOSTDSOUND pThis, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
     1448{
    14631449    LogFlowFunc(("pStream=%p, cmd=%d\n", pStream, enmStreamCmd));
    1464 
    1465     PDRVHOSTDSOUND   pThis          = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    14661450    PDSOUNDSTREAMOUT pDSoundStream = (PDSOUNDSTREAMOUT)pStream;
    14671451
     
    15131497}
    15141498
    1515 static DECLCALLBACK(int) drvHostDSoundStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
    1516                                                  uint32_t *pcSamplesPlayed)
     1499
     1500/**
     1501 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
     1502 */
     1503static DECLCALLBACK(int) drvHostDSoundStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesPlayed)
    15171504{
    15181505    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     
    16581645}
    16591646
    1660 static int dsoundDestroyStreamOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
    1661 {
    1662     PDRVHOSTDSOUND   pThis         = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
     1647static int dsoundDestroyStreamOut(PDRVHOSTDSOUND pThis, PPDMAUDIOSTREAM pStream)
     1648{
    16631649    PDSOUNDSTREAMOUT pDSoundStream = (PDSOUNDSTREAMOUT)pStream;
    16641650
     
    16741660}
    16751661
    1676 static int dsoundCreateStreamIn(PPDMIHOSTAUDIO pInterface,
    1677                                 PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
    1678 {
    1679     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1680     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    1681     AssertPtrReturn(pCfg,       VERR_INVALID_POINTER);
    1682 
    1683     PDRVHOSTDSOUND  pThis         = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
     1662static int dsoundCreateStreamIn(PDRVHOSTDSOUND pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
     1663{
    16841664    PDSOUNDSTREAMIN pDSoundStream = (PDSOUNDSTREAMIN)pStream;
    16851665
     
    17151695}
    17161696
    1717 static int dsoundControlStreamIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
    1718                                  PDMAUDIOSTREAMCMD enmStreamCmd)
    1719 {
    1720     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1721     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    1722 
     1697static int dsoundControlStreamIn(PDRVHOSTDSOUND pThis, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
     1698{
    17231699    LogFlowFunc(("pStream=%p, enmStreamCmd=%ld\n", pStream, enmStreamCmd));
    1724 
    1725     PDRVHOSTDSOUND  pThis         = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    17261700    PDSOUNDSTREAMIN pDSoundStream = (PDSOUNDSTREAMIN)pStream;
    17271701
     
    17721746}
    17731747
     1748
     1749/**
     1750 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
     1751 */
    17741752static DECLCALLBACK(int) drvHostDSoundStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
    17751753                                                    uint32_t *pcSamplesCaptured)
     
    18971875}
    18981876
    1899 static int dsoundDestroyStreamIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
    1900 {
    1901     RT_NOREF(pInterface);
     1877static int dsoundDestroyStreamIn(PPDMAUDIOSTREAM pStream)
     1878{
    19021879    PDSOUNDSTREAMIN pDSoundStream = (PDSOUNDSTREAMIN)pStream;
    19031880
     
    19111888}
    19121889
     1890
     1891/**
     1892 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetConfig}
     1893 */
    19131894static DECLCALLBACK(int) drvHostDSoundGetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
    19141895{
     
    19241905
    19251906#ifdef VBOX_WITH_AUDIO_CALLBACKS
     1907
    19261908static int dsoundNotifyThread(PDRVHOSTDSOUND pThis, bool fShutdown)
    19271909{
     
    19401922    return VINF_SUCCESS;
    19411923}
     1924
    19421925
    19431926static DECLCALLBACK(int) dsoundNotificationThread(RTTHREAD hThreadSelf, void *pvUser)
     
    20292012    return rc;
    20302013}
     2014
    20312015#endif /* VBOX_WITH_AUDIO_CALLBACKS */
    20322016
     2017
     2018/**
     2019 * @interface_method_impl{PDMIHOSTAUDIO,pfnShutdown}
     2020 */
    20332021static DECLCALLBACK(void) drvHostDSoundShutdown(PPDMIHOSTAUDIO pInterface)
    20342022{
     
    20592047}
    20602048
     2049
     2050/**
     2051 * @interface_method_impl{PDMIHOSTAUDIO,pfnInit}
     2052 */
    20612053static DECLCALLBACK(int) drvHostDSoundInit(PPDMIHOSTAUDIO pInterface)
    20622054{
    20632055    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    2064 
    20652056    LogFlowFuncEnter();
    20662057
     
    20692060    /* Verify that IDirectSound is available. */
    20702061    LPDIRECTSOUND pDirectSound = NULL;
    2071     HRESULT hr = CoCreateInstance(CLSID_DirectSound, NULL, CLSCTX_ALL,
    2072                                   IID_IDirectSound, (void **)&pDirectSound);
     2062    HRESULT hr = CoCreateInstance(CLSID_DirectSound, NULL, CLSCTX_ALL, IID_IDirectSound, (void **)&pDirectSound);
    20732063    if (SUCCEEDED(hr))
    20742064    {
     
    21112101}
    21122102
    2113 static DECLCALLBACK(void *) drvHostDSoundQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    2114 {
    2115     PPDMDRVINS     pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
    2116     PDRVHOSTDSOUND pThis   = PDMINS_2_DATA(pDrvIns, PDRVHOSTDSOUND);
    2117 
    2118     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    2119     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
    2120     return NULL;
    2121 }
    21222103
    21232104static LPCGUID dsoundConfigQueryGUID(PCFGMNODE pCfg, const char *pszName, RTUUID *pUuid)
     
    21412122}
    21422123
     2124
    21432125static void dsoundConfigInit(PDRVHOSTDSOUND pThis, PCFGMNODE pCfg)
    21442126{
     
    21602142}
    21612143
    2162 /*
    2163  * PDMIHOSTAUDIO
     2144
     2145/**
     2146 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
    21642147 */
    2165 
    21662148static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostDSoundGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
    21672149{
     
    21722154}
    21732155
    2174 static DECLCALLBACK(int) drvHostDSoundStreamCreate(PPDMIHOSTAUDIO pInterface,
    2175                                                    PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
     2156
     2157/**
     2158 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
     2159 */
     2160static DECLCALLBACK(int)
     2161drvHostDSoundStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
     2162{
     2163    AssertPtrReturn(pInterface,    VERR_INVALID_POINTER);
     2164    AssertPtrReturn(pStream,       VERR_INVALID_POINTER);
     2165    AssertPtrReturn(pCfg,          VERR_INVALID_POINTER);
     2166    AssertPtrNullReturn(pcSamples, VERR_INVALID_POINTER);
     2167    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
     2168
     2169    int rc;
     2170    if (pCfg->enmDir == PDMAUDIODIR_IN)
     2171        rc = dsoundCreateStreamIn(pThis,  pStream, pCfg, pcSamples);
     2172    else
     2173        rc = dsoundCreateStreamOut(pThis, pStream, pCfg, pcSamples);
     2174
     2175    LogFlowFunc(("%s: rc=%Rrc\n", pStream->szName, rc));
     2176    return rc;
     2177}
     2178
     2179
     2180/**
     2181 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
     2182 */
     2183static DECLCALLBACK(int) drvHostDSoundStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
    21762184{
    21772185    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    21782186    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    2179     AssertPtrReturn(pCfg,       VERR_INVALID_POINTER);
     2187    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    21802188
    21812189    int rc;
    2182     if (pCfg->enmDir == PDMAUDIODIR_IN)
    2183         rc = dsoundCreateStreamIn(pInterface,  pStream, pCfg, pcSamples);
     2190    if (pStream->enmDir == PDMAUDIODIR_IN)
     2191        rc = dsoundDestroyStreamIn(pStream);
    21842192    else
    2185         rc = dsoundCreateStreamOut(pInterface, pStream, pCfg, pcSamples);
    2186 
    2187     LogFlowFunc(("%s: rc=%Rrc\n", pStream->szName, rc));
     2193        rc = dsoundDestroyStreamOut(pThis, pStream);
     2194
    21882195    return rc;
    21892196}
    21902197
    2191 static DECLCALLBACK(int) drvHostDSoundStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
     2198
     2199/**
     2200 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
     2201 */
     2202static DECLCALLBACK(int)
     2203drvHostDSoundStreamControl(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
    21922204{
    21932205    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    21942206    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     2207    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
     2208
     2209    Assert(pStream->enmCtx == PDMAUDIOSTREAMCTX_HOST);
    21952210
    21962211    int rc;
    21972212    if (pStream->enmDir == PDMAUDIODIR_IN)
    2198         rc = dsoundDestroyStreamIn(pInterface,  pStream);
     2213        rc = dsoundControlStreamIn(pThis,  pStream, enmStreamCmd);
    21992214    else
    2200         rc = dsoundDestroyStreamOut(pInterface, pStream);
     2215        rc = dsoundControlStreamOut(pThis, pStream, enmStreamCmd);
    22012216
    22022217    return rc;
    22032218}
    22042219
    2205 static DECLCALLBACK(int) drvHostDSoundStreamControl(PPDMIHOSTAUDIO pInterface,
    2206                                                     PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
    2207 {
    2208     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    2209     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    2210 
    2211     Assert(pStream->enmCtx == PDMAUDIOSTREAMCTX_HOST);
    2212 
    2213     int rc;
    2214     if (pStream->enmDir == PDMAUDIODIR_IN)
    2215         rc = dsoundControlStreamIn(pInterface,  pStream, enmStreamCmd);
    2216     else
    2217         rc = dsoundControlStreamOut(pInterface, pStream, enmStreamCmd);
    2218 
    2219     return rc;
    2220 }
    2221 
     2220
     2221/**
     2222 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetStatus}
     2223 */
    22222224static DECLCALLBACK(PDMAUDIOSTRMSTS) drvHostDSoundStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
    22232225{
     
    22562258
    22572259
     2260/**
     2261 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
     2262 */
    22582263static DECLCALLBACK(int) drvHostDSoundStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
    22592264{
     
    22672272}
    22682273
     2274
     2275/*********************************************************************************************************************************
     2276*   PDMDRVINS::IBase Interface                                                                                                   *
     2277*********************************************************************************************************************************/
     2278
     2279/**
     2280 * @callback_method_impl{PDMIBASE,pfnQueryInterface}
     2281 */
     2282static DECLCALLBACK(void *) drvHostDSoundQueryInterface(PPDMIBASE pInterface, const char *pszIID)
     2283{
     2284    PPDMDRVINS     pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
     2285    PDRVHOSTDSOUND pThis   = PDMINS_2_DATA(pDrvIns, PDRVHOSTDSOUND);
     2286
     2287    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
     2288    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
     2289    return NULL;
     2290}
     2291
     2292
     2293/*********************************************************************************************************************************
     2294*   PDMDRVREG Interface                                                                                                          *
     2295*********************************************************************************************************************************/
    22692296
    22702297/**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette