VirtualBox

Changeset 88059 in vbox


Ignore:
Timestamp:
Mar 9, 2021 3:33:52 PM (4 years ago)
Author:
vboxsync
Message:

Audio: Adding a magic to PDMAUDIOSTREAM. bugref:9890

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r88057 r88059  
    12441244typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAMCTX;
    12451245
     1246/** @name PDMAUDIOSTREAM_WARN_FLAGS_XXX
     1247 * @{ */
    12461248/** No stream warning flags set. */
    12471249#define PDMAUDIOSTREAM_WARN_FLAGS_NONE          0
    12481250/** Warned about a disabled stream. */
    12491251#define PDMAUDIOSTREAM_WARN_FLAGS_DISABLED      RT_BIT(0)
     1252/** @} */
    12501253
    12511254/**
     
    12541257typedef struct PDMAUDIOSTREAM
    12551258{
    1256     /** List node.
    1257      * @todo s/Node/ListEntry/ */
    1258     RTLISTNODE              Node;
    1259     /** @todo add magic (some jazz pianist). */
     1259    /** Magic value (PDMAUDIOSTREAM_MAGIC). */
     1260    uint32_t                uMagic;
     1261    /** Size (in bytes) of the backend-specific stream data. */
     1262    uint32_t                cbBackend;
     1263    /** List entry (some DrvAudio internal list). */
     1264    RTLISTNODE              ListEntry;
    12601265    /** Number of references to this stream.
    12611266     *  Only can be destroyed when the reference count reaches 0. */
     
    12641269    uint32_t                cTriesReInit;
    12651270    /** Warnings shown already in the release log.
    1266      *  See PDMAUDIOSTREAM_WARN_FLAGS_XXX defines. */
     1271     *  See PDMAUDIOSTREAM_WARN_FLAGS_XXX. */
    12671272    uint32_t                fWarningsShown;
    12681273    /** Stream status flag. */
     
    12951300     *  That way the backends do not have access to the audio connector's data. */
    12961301    void                   *pvBackend;
    1297     /** Size (in bytes) of the backend-specific stream data. */
    1298     size_t                  cbBackend;
    12991302
    13001303    /** Name of this stream. */
     
    13081311    } RT_UNION_NM(u);
    13091312} PDMAUDIOSTREAM;
     1313
     1314/** Magic value for PDMAUDIOSTREAM. (Ahmad Jamal)   */
     1315#define PDMAUDIOSTREAM_MAGIC    UINT32_C(0x19300702)
    13101316
    13111317
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r88057 r88059  
    564564     * Init host stream.
    565565     */
     566    pStream->uMagic = PDMAUDIOSTREAM_MAGIC;
    566567
    567568    /* Set the host's default audio data layout. */
     
    762763static void drvAudioStreamFree(PPDMAUDIOSTREAM pStream)
    763764{
    764     if (!pStream)
    765         return;
    766 
    767     LogFunc(("[%s]\n", pStream->szName));
    768 
    769     if (pStream->pvBackend)
    770     {
    771         Assert(pStream->cbBackend);
    772         RTMemFree(pStream->pvBackend);
    773         pStream->pvBackend = NULL;
    774     }
    775 
    776     RTMemFree(pStream);
    777     pStream = NULL;
     765    if (pStream)
     766    {
     767        LogFunc(("[%s]\n", pStream->szName));
     768        Assert(pStream->uMagic == PDMAUDIOSTREAM_MAGIC);
     769        pStream->uMagic = ~PDMAUDIOSTREAM_MAGIC;
     770
     771        if (pStream->pvBackend)
     772        {
     773            Assert(pStream->cbBackend);
     774            RTMemFree(pStream->pvBackend);
     775            pStream->pvBackend = NULL;
     776        }
     777
     778        RTMemFree(pStream);
     779    }
    778780}
    779781
     
    794796    /* Mark all host streams to re-initialize. */
    795797    PPDMAUDIOSTREAM pStream;
    796     RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, Node)
     798    RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, ListEntry)
    797799    {
    798800        pStream->fStatus |= PDMAUDIOSTREAMSTS_FLAGS_PENDING_REINIT;
     
    22952297    {
    22962298        PPDMAUDIOSTREAM pStream;
    2297         RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, Node)
     2299        RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, ListEntry)
    22982300            drvAudioStreamControlInternal(pThis, pStream, enmCmd);
    22992301    }
     
    25372539 * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamCreate}
    25382540 */
    2539 static DECLCALLBACK(int) drvAudioStreamCreate(PPDMIAUDIOCONNECTOR pInterface,
    2540                                               PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest,
    2541                                               PPDMAUDIOSTREAM *ppStream)
     2541static DECLCALLBACK(int) drvAudioStreamCreate(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost,
     2542                                              PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream)
    25422543{
    25432544    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     
    25622563#define RC_BREAK(x) { rc = x; break; }
    25632564
    2564     do
     2565    do /* this is not a loop, just a construct to make the code more difficult to follow. */
    25652566    {
    25662567        if (   !DrvAudioHlpStreamCfgIsValid(pCfgHost)
     
    25992600            cbHstStrm = pThis->BackendCfg.cbStreamOut;
    26002601        }
     2602        AssertBreakStmt(cbHstStrm < _16M, rc = VERR_OUT_OF_RANGE);
    26012603
    26022604        /*
    26032605         * Allocate and initialize common state.
    26042606         */
    2605 
    26062607        pStream = (PPDMAUDIOSTREAM)RTMemAllocZ(sizeof(PDMAUDIOSTREAM));
    26072608        AssertPtrBreakStmt(pStream, rc = VERR_NO_MEMORY);
     
    26232624         * Allocate and init backend-specific data.
    26242625         */
    2625 
    26262626        if (cbHstStrm) /* High unlikely that backends do not have an own space for data, but better check. */
    26272627        {
    26282628            pStream->pvBackend = RTMemAllocZ(cbHstStrm);
    2629             AssertPtrBreakStmt(pStream->pvBackend, rc = VERR_NO_MEMORY);
    2630 
    2631             pStream->cbBackend = cbHstStrm;
     2629            AssertBreakStmt(pStream->pvBackend, rc = VERR_NO_MEMORY);
     2630
     2631            pStream->cbBackend = (uint32_t)cbHstStrm;
    26322632        }
    26332633
     
    26352635         * Try to init the rest.
    26362636         */
    2637 
    26382637        rc = drvAudioStreamInitInternal(pThis, pStream, pCfgHost, pCfgGuest);
    2639         if (RT_FAILURE(rc))
    2640             break;
    26412638
    26422639    } while (0);
     
    26602657    {
    26612658        /* Append the stream to our stream list. */
    2662         RTListAppend(&pThis->lstStreams, &pStream->Node);
     2659        RTListAppend(&pThis->lstStreams, &pStream->ListEntry);
    26632660
    26642661        /* Set initial reference counts. */
     
    27772774
    27782775        PPDMAUDIOSTREAM pStream;
    2779         RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, Node)
     2776        RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, ListEntry)
    27802777        {
    27812778            if (pStream->enmDir != enmDir) /* Skip unwanted streams. */
     
    30853082{
    30863083    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    3087     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    3088 
    30893084    PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
    30903085
     3086    if (!pStream)
     3087        return VINF_SUCCESS;
     3088    AssertPtrReturn(pStream, VERR_INVALID_POINTER);
     3089    Assert(pStream->uMagic == PDMAUDIOSTREAM_MAGIC);
     3090
    30913091    int rc = RTCritSectEnter(&pThis->CritSect);
    3092     AssertRC(rc);
     3092    AssertRCReturn(rc, rc);
    30933093
    30943094    LogRel2(("Audio: Destroying stream '%s'\n", pStream->szName));
    30953095
    30963096    LogFlowFunc(("[%s] cRefs=%RU32\n", pStream->szName, pStream->cRefs));
    3097     if (pStream->cRefs > 1)
     3097    if (pStream->cRefs < 1)
     3098    {
     3099        rc = drvAudioStreamUninitInternal(pThis, pStream);
     3100        if (RT_SUCCESS(rc))
     3101        {
     3102            if (pStream->enmDir == PDMAUDIODIR_IN)
     3103                pThis->In.cStreamsFree++;
     3104            else /* Out */
     3105                pThis->Out.cStreamsFree++;
     3106
     3107            RTListNodeRemove(&pStream->ListEntry);
     3108
     3109            drvAudioStreamFree(pStream);
     3110            pStream = NULL;
     3111        }
     3112        else
     3113            LogRel(("Audio: Uninitializing stream '%s' failed with %Rrc\n", pStream->szName, rc));
     3114    }
     3115    else
    30983116        rc = VERR_WRONG_ORDER;
    3099 
    3100     if (RT_SUCCESS(rc))
    3101     {
    3102         rc = drvAudioStreamUninitInternal(pThis, pStream);
    3103         if (RT_FAILURE(rc))
    3104             LogRel(("Audio: Uninitializing stream '%s' failed with %Rrc\n", pStream->szName, rc));
    3105     }
    3106 
    3107     if (RT_SUCCESS(rc))
    3108     {
    3109         if (pStream->enmDir == PDMAUDIODIR_IN)
    3110         {
    3111             pThis->In.cStreamsFree++;
    3112         }
    3113         else /* Out */
    3114         {
    3115             pThis->Out.cStreamsFree++;
    3116         }
    3117 
    3118         RTListNodeRemove(&pStream->Node);
    3119 
    3120         drvAudioStreamFree(pStream);
    3121         pStream = NULL;
    3122     }
    31233117
    31243118    int rc2 = RTCritSectLeave(&pThis->CritSect);
     
    35603554     * in drvAudioDestruct(). */
    35613555    PPDMAUDIOSTREAM pStream;
    3562     RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, Node)
     3556    RTListForEach(&pThis->lstStreams, pStream, PDMAUDIOSTREAM, ListEntry)
    35633557    {
    35643558        drvAudioStreamControlInternalBackend(pThis, pStream, PDMAUDIOSTREAMCMD_DISABLE);
     
    37053699
    37063700    PPDMAUDIOSTREAM pStream, pStreamNext;
    3707     RTListForEachSafe(&pThis->lstStreams, pStream, pStreamNext, PDMAUDIOSTREAM, Node)
     3701    RTListForEachSafe(&pThis->lstStreams, pStream, pStreamNext, PDMAUDIOSTREAM, ListEntry)
    37083702    {
    37093703        rc2 = drvAudioStreamUninitInternal(pThis, pStream);
    37103704        if (RT_SUCCESS(rc2))
    37113705        {
    3712             RTListNodeRemove(&pStream->Node);
     3706            RTListNodeRemove(&pStream->ListEntry);
    37133707
    37143708            drvAudioStreamFree(pStream);
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