VirtualBox

Changeset 89707 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 15, 2021 2:24:03 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145155
Message:

DevIchAc97: Added a input/output stream indicator to ichac97R3StreamTransfer to avoid needing to consider corrupt stream number/whatever and return errors. bugref:9890

File:
1 edited

Legend:

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

    r89706 r89707  
    688688static uint32_t           ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC);
    689689static int                ichac97R3StreamTransfer(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream,
    690                                                   PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax, bool fWriteSilence);
     690                                                  PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax,
     691                                                  bool fWriteSilence, bool fInput);
    691692static DECLCALLBACK(void) ichac97R3StreamUpdateAsyncIoJob(PPDMDEVINS pDevIns, PAUDMIXSINK pSink, void *pvUser);
    692693
     
    13981399                  cbPeriod, PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, cbPeriod)));
    13991400
    1400         rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, RT_MIN(cbStreamFree, cbPeriod), false /*fWriteSilence*/);
     1401        rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, RT_MIN(cbStreamFree, cbPeriod),
     1402                                      false /*fWriteSilence*/, false /*fInput*/);
    14011403        AssertRC(rc2);
    14021404
     
    15131515        if (cbStreamUsed)
    15141516        {
    1515             rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, RT_MIN(cbPeriod, cbStreamUsed), fWriteSilence);
     1517            rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, RT_MIN(cbPeriod, cbStreamUsed),
     1518                                          fWriteSilence, true /*fInput*/);
    15161519            AssertRC(rc2);
    15171520
     
    27462749 *                              stream (done while waiting for backend to get
    27472750 *                              going).
     2751 * @param   fInput              Set if input, clear if output.
    27482752 */
    27492753static int ichac97R3StreamTransfer(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream,
    2750                                    PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax, bool fWriteSilence)
     2754                                   PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax, bool fWriteSilence, bool fInput)
    27512755{
    27522756    if (!cbToProcessMax)
     
    28252829        uint32_t cbChunk = cbLeft;
    28262830
    2827         switch (pStream->u8SD)
     2831        /*
     2832         * Output.
     2833         */
     2834        if (!fInput)
    28282835        {
    2829             case AC97SOUNDSOURCE_PO_INDEX: /* Output */
     2836            void  *pvDst = NULL;
     2837            size_t cbDst = NULL;
     2838            RTCircBufAcquireWriteBlock(pCircBuf, cbChunk, &pvDst, &cbDst);
     2839
     2840            if (cbDst)
    28302841            {
    2831                 void  *pvDst = NULL;
    2832                 size_t cbDst = NULL;
    2833                 RTCircBufAcquireWriteBlock(pCircBuf, cbChunk, &pvDst, &cbDst);
    2834 
    2835                 if (cbDst)
     2842                int rc2 = PDMDevHlpPCIPhysRead(pDevIns, pRegs->bd.addr, pvDst, cbDst);
     2843                AssertRC(rc2);
     2844
     2845                if (RT_LIKELY(!pStreamCC->Dbg.Runtime.fEnabled))
     2846                { /* likely */ }
     2847                else
     2848                    AudioHlpFileWrite(pStreamCC->Dbg.Runtime.pFileDMA, pvDst, cbDst, 0 /* fFlags */);
     2849            }
     2850
     2851            RTCircBufReleaseWriteBlock(pCircBuf, cbDst);
     2852
     2853            cbChunk = (uint32_t)cbDst; /* Update the current chunk size to what really has been written. */
     2854        }
     2855        /*
     2856         * Input.
     2857         */
     2858        else
     2859        {
     2860            if (!fWriteSilence)
     2861            {
     2862                void  *pvSrc = NULL;
     2863                size_t cbSrc = NULL;
     2864                RTCircBufAcquireReadBlock(pCircBuf, cbChunk, &pvSrc, &cbSrc);
     2865
     2866                if (cbSrc)
    28362867                {
    2837                     int rc2 = PDMDevHlpPCIPhysRead(pDevIns, pRegs->bd.addr, pvDst, cbDst);
     2868                    int rc2 = PDMDevHlpPCIPhysWrite(pDevIns, pRegs->bd.addr, pvSrc, cbSrc);
    28382869                    AssertRC(rc2);
    28392870
     
    28412872                    { /* likely */ }
    28422873                    else
    2843                         AudioHlpFileWrite(pStreamCC->Dbg.Runtime.pFileDMA, pvDst, cbDst, 0 /* fFlags */);
     2874                        AudioHlpFileWrite(pStreamCC->Dbg.Runtime.pFileDMA, pvSrc, cbSrc, 0 /* fFlags */);
    28442875                }
    28452876
    2846                 RTCircBufReleaseWriteBlock(pCircBuf, cbDst);
    2847 
    2848                 cbChunk = (uint32_t)cbDst; /* Update the current chunk size to what really has been written. */
    2849                 break;
     2877                RTCircBufReleaseReadBlock(pCircBuf, cbSrc);
     2878
     2879                cbChunk = (uint32_t)cbSrc; /* Update the current chunk size to what really has been read. */
    28502880            }
    2851 
    2852             case AC97SOUNDSOURCE_PI_INDEX: /* Input */
    2853             case AC97SOUNDSOURCE_MC_INDEX: /* Input */
    2854                 if (!fWriteSilence)
    2855                 {
    2856                     void  *pvSrc = NULL;
    2857                     size_t cbSrc = NULL;
    2858                     RTCircBufAcquireReadBlock(pCircBuf, cbChunk, &pvSrc, &cbSrc);
    2859 
    2860                     if (cbSrc)
    2861                     {
    2862                         int rc2 = PDMDevHlpPCIPhysWrite(pDevIns, pRegs->bd.addr, pvSrc, cbSrc);
    2863                         AssertRC(rc2);
    2864 
    2865                         if (RT_LIKELY(!pStreamCC->Dbg.Runtime.fEnabled))
    2866                         { /* likely */ }
    2867                         else
    2868                             AudioHlpFileWrite(pStreamCC->Dbg.Runtime.pFileDMA, pvSrc, cbSrc, 0 /* fFlags */);
    2869                     }
    2870 
    2871                     RTCircBufReleaseReadBlock(pCircBuf, cbSrc);
    2872 
    2873                     cbChunk = (uint32_t)cbSrc; /* Update the current chunk size to what really has been read. */
    2874                 }
    2875                 else
    2876                 {
    2877                     /* Since the format is signed 16-bit or 32-bit integer samples, we can
    2878                        use g_abRTZero64K as source and avoid some unnecessary bzero() work. */
    2879                     cbChunk = RT_MIN(cbChunk, sizeof(g_abRTZero64K));
    2880                     cbChunk = PDMAudioPropsFloorBytesToFrame(&pStreamCC->State.Cfg.Props, cbChunk);
    2881 
    2882                     int rc2 = PDMDevHlpPCIPhysWrite(pDevIns, pRegs->bd.addr, g_abRTZero64K, cbChunk);
    2883                     AssertRC(rc2);
    2884                 }
    2885                 break;
    2886 
    2887             default:
    2888                 AssertMsgFailed(("Stream #%RU8 not supported\n", pStream->u8SD));
    2889                 rc = VERR_NOT_SUPPORTED;
    2890                 break;
     2881            else
     2882            {
     2883                /* Since the format is signed 16-bit or 32-bit integer samples, we can
     2884                   use g_abRTZero64K as source and avoid some unnecessary bzero() work. */
     2885                cbChunk = RT_MIN(cbChunk, sizeof(g_abRTZero64K));
     2886                cbChunk = PDMAudioPropsFloorBytesToFrame(&pStreamCC->State.Cfg.Props, cbChunk);
     2887
     2888                int rc2 = PDMDevHlpPCIPhysWrite(pDevIns, pRegs->bd.addr, g_abRTZero64K, cbChunk);
     2889                AssertRC(rc2);
     2890            }
    28912891        }
    2892 
    2893         if (RT_FAILURE(rc))
    2894             break;
    28952892
    28962893        if (cbChunk)
     
    29342931        }
    29352932
    2936         if (/* All data processed? */
    2937                rc == VINF_EOF
    2938             /* ... or an error occurred? */
    2939             || RT_FAILURE(rc))
    2940         {
     2933        /* All data processed? */
     2934        if (rc == VINF_EOF)
    29412935            break;
    2942         }
    29432936    }
    29442937
Note: See TracChangeset for help on using the changeset viewer.

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