VirtualBox

Changeset 89661 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Jun 13, 2021 11:08:07 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145106
Message:

DevIchAc97: Docs, TODOs, and some ichac97R3StreamUpdateDma refactoring preps. bugref:9890

File:
1 edited

Legend:

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

    r89640 r89661  
    304304/**
    305305 * Buffer Descriptor List Entry (BDLE).
     306 *
     307 * (See section 3.2.1 in Intel document number 252751-001, or section 1.2.2.1 in
     308 * Intel document number 302349-003.)
    306309 */
    307310typedef struct AC97BDLE
     
    319322/**
    320323 * Bus master register set for an audio stream.
     324 *
     325 * (See section 16.2 in Intel document 301473-002, or section 2.2 in Intel
     326 * document 302349-003.)
    321327 */
    322328typedef struct AC97BMREGS
     
    326332    uint8_t                 lvi;        /**< rw 0, Last valid index. */
    327333    uint16_t                sr;         /**< rw 1, Status register. */
    328     uint16_t                picb;       /**< ro 0, Position in current buffer (in samples). */
     334    uint16_t                picb;       /**< ro 0, Position in current buffer (samples left to process). */
    329335    uint8_t                 piv;        /**< ro 0, Prefetched index value. */
    330336    uint8_t                 cr;         /**< rw 0, Control register. */
     
    12651271                                     PAC97STREAM pStream, PAC97STREAMR3 pStreamCC)
    12661272{
    1267     int         rc2;
    1268     PAUDMIXSINK pSink = ichac97R3IndexToSink(pThisCC, pStream->u8SD);
     1273    /*
     1274     * Make sure we're running and got an active mixer sink.
     1275     */
     1276    PAUDMIXSINK pSink = ichac97R3IndexToSink(pThisCC, pStream->u8SD); /** @todo caller will need + check this too afterwards... */
    12691277    AssertPtr(pSink);
    1270     if (AudioMixerSinkIsActive(pSink))
    1271     {
    1272         if (pStreamCC->State.Cfg.enmDir == PDMAUDIODIR_OUT) /* Output (SDO). */
     1278    if (RT_LIKELY(AudioMixerSinkIsActive(pSink)))
     1279    { /* likely */ }
     1280    else
     1281        return;
     1282
     1283    int rc2;
     1284
     1285    /*
     1286     * Output streams (SDO).
     1287     */
     1288    if (pStreamCC->State.Cfg.enmDir == PDMAUDIODIR_OUT)
     1289    {
     1290        uint32_t cbStreamFree = ichac97R3StreamGetFree(pStreamCC);
     1291        if (cbStreamFree)
     1292        { /* likely */ }
     1293        else
    12731294        {
    1274             uint32_t cbStreamFree = ichac97R3StreamGetFree(pStreamCC);
    1275             if (cbStreamFree)
    1276             { /* likely */ }
    1277             else
    1278             {
    1279                 /** @todo Record this as a statistic. Try make some space available.    */
    1280             }
    1281             if (cbStreamFree)
    1282             {
    1283                 Log3Func(("[SD%RU8] PICB=%zu (%RU64ms), cbFree=%zu (%RU64ms), cbTransferChunk=%zu (%RU64ms)\n",
    1284                           pStream->u8SD,
    1285                           (pStream->Regs.picb << 1), PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, pStream->Regs.picb << 1),
    1286                           cbStreamFree, PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, cbStreamFree),
    1287                           pStreamCC->State.cbTransferChunk, PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, pStreamCC->State.cbTransferChunk)));
    1288 
    1289                 /* Do the DMA transfer. */
    1290                 rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC,
    1291                                               RT_MIN(pStreamCC->State.cbTransferChunk, cbStreamFree));
    1292                 AssertRC(rc2);
    1293 
    1294                 pStreamCC->State.tsLastUpdateNs = RTTimeNanoTS();
    1295             }
    1296 
     1295            /** @todo Record this as a statistic. Try make some space available.    */
     1296        }
     1297        if (cbStreamFree)
     1298        {
     1299            Log3Func(("[SD%RU8] PICB=%zu (%RU64ms), cbFree=%zu (%RU64ms), cbTransferChunk=%zu (%RU64ms)\n",
     1300                      pStream->u8SD,
     1301                      (pStream->Regs.picb << 1), PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, pStream->Regs.picb << 1),
     1302                      cbStreamFree, PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, cbStreamFree),
     1303                      pStreamCC->State.cbTransferChunk, PDMAudioPropsBytesToMilli(&pStreamCC->State.Cfg.Props, pStreamCC->State.cbTransferChunk)));
     1304
     1305            /* Do the DMA transfer. */
     1306            rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC,
     1307                                          RT_MIN(pStreamCC->State.cbTransferChunk, cbStreamFree));
     1308            AssertRC(rc2);
     1309
     1310            pStreamCC->State.tsLastUpdateNs = RTTimeNanoTS();
     1311        }
     1312
     1313        rc2 = AudioMixerSinkSignalUpdateJob(pSink);
     1314        AssertRC(rc2);
     1315    }
     1316    else /* Input (SDI). */
     1317    {
     1318#if 0 /* bird: I just love when crusial code like this with no explanation.  This just causing AIO
     1319   *       skipping a DMA timer cycle if the timer callback is a bit quicker than the 'hint' (see HDA/9890).   */
     1320        const uint64_t tsNowNs = RTTimeNanoTS();
     1321        if (tsNowNs - pStreamCC->State.tsLastUpdateNs >= pStreamCC->State.Cfg.Device.cMsSchedulingHint * RT_NS_1MS)
     1322        {
    12971323            rc2 = AudioMixerSinkSignalUpdateJob(pSink);
    12981324            AssertRC(rc2);
     1325
     1326            pStreamCC->State.tsLastUpdateNs = tsNowNs;
    12991327        }
    1300         else /* Input (SDI). */
     1328#endif
     1329
     1330        uint32_t cbStreamUsed = ichac97R3StreamGetUsed(pStreamCC);
     1331        if (cbStreamUsed)
     1332        { /* likey */ }
     1333        else
    13011334        {
    1302 #if 0 /* bird: I just love when crusial code like this with no explanation.  This just causing AIO
    1303        *       skipping a DMA timer cycle if the timer callback is a bit quicker than the 'hint' (see HDA/9890).   */
    1304             const uint64_t tsNowNs = RTTimeNanoTS();
    1305             if (tsNowNs - pStreamCC->State.tsLastUpdateNs >= pStreamCC->State.Cfg.Device.cMsSchedulingHint * RT_NS_1MS)
    1306             {
    1307                 rc2 = AudioMixerSinkSignalUpdateJob(pSink);
    1308                 AssertRC(rc2);
    1309 
    1310                 pStreamCC->State.tsLastUpdateNs = tsNowNs;
    1311             }
    1312 #endif
    1313 
    1314             uint32_t cbStreamUsed = ichac97R3StreamGetUsed(pStreamCC);
    1315             if (cbStreamUsed)
    1316             { /* likey */ }
    1317             else
    1318             {
    1319                 /** @todo Record this as a statistic. Try pull some data into the DMA buffer.*/
    1320             }
    1321 
    1322             if (cbStreamUsed)
    1323             {
    1324                 /* When running synchronously, do the DMA data transfers here.
    1325                  * Otherwise this will be done in the stream's async I/O thread. */
    1326                 rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, cbStreamUsed);
    1327                 AssertRC(rc2);
    1328             }
    1329 
    1330             /*
    1331              * We should always kick the AIO thread.
    1332              */
    1333             /** @todo This isn't entirely ideal.  If we get into an underrun situation,
    1334              *        we ideally want the AIO thread to run right before the DMA timer
    1335              *        rather than right after it ran. */
    1336             Log5Func(("Notifying AIO thread\n"));
    1337             rc2 = AudioMixerSinkSignalUpdateJob(pSink);
     1335            /** @todo Record this as a statistic. Try pull some data into the DMA buffer.*/
     1336        }
     1337
     1338        if (cbStreamUsed)
     1339        {
     1340            /* When running synchronously, do the DMA data transfers here.
     1341             * Otherwise this will be done in the stream's async I/O thread. */
     1342            rc2 = ichac97R3StreamTransfer(pDevIns, pThis, pStream, pStreamCC, cbStreamUsed);
    13381343            AssertRC(rc2);
    1339             pStreamCC->State.tsLastUpdateNs = RTTimeNanoTS();
    13401344        }
     1345
     1346        /*
     1347         * We should always kick the AIO thread.
     1348         */
     1349        /** @todo This isn't entirely ideal.  If we get into an underrun situation,
     1350         *        we ideally want the AIO thread to run right before the DMA timer
     1351         *        rather than right after it ran. */
     1352        Log5Func(("Notifying AIO thread\n"));
     1353        rc2 = AudioMixerSinkSignalUpdateJob(pSink);
     1354        AssertRC(rc2);
     1355        pStreamCC->State.tsLastUpdateNs = RTTimeNanoTS();
    13411356    }
    13421357}
     
    32683283                    {
    32693284                        ichac97MixerSet(pThis, AC97_PCM_Front_DAC_Rate, 0xbb80); /* Set default (48000 Hz). */
     3285                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3286                         *        actually used? */
    32703287                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PO_INDEX],
    32713288                                              &pThisCC->aStreams[AC97SOUNDSOURCE_PO_INDEX], true /* fForce */);
    32723289
    32733290                        ichac97MixerSet(pThis, AC97_PCM_LR_ADC_Rate, 0xbb80); /* Set default (48000 Hz). */
     3291                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3292                         *        actually used? */
    32743293                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PI_INDEX],
    32753294                                              &pThisCC->aStreams[AC97SOUNDSOURCE_PI_INDEX], true /* fForce */);
     
    32843303                    {
    32853304                        ichac97MixerSet(pThis, AC97_MIC_ADC_Rate, 0xbb80); /* Set default (48000 Hz). */
     3305                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3306                         *        actually used? */
    32863307                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_MC_INDEX],
    32873308                                              &pThisCC->aStreams[AC97SOUNDSOURCE_MC_INDEX], true /* fForce */);
     
    33023323                        LogRel2(("AC97: Setting front DAC rate to 0x%x\n", u32));
    33033324                        ichac97MixerSet(pThis, offPort, u32);
     3325                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3326                         *        actually used? */
    33043327                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PO_INDEX],
    33053328                                              &pThisCC->aStreams[AC97SOUNDSOURCE_PO_INDEX], true /* fForce */);
     
    33173340                        LogRel2(("AC97: Setting microphone ADC rate to 0x%x\n", u32));
    33183341                        ichac97MixerSet(pThis, offPort, u32);
     3342                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3343                         *        actually used? */
    33193344                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_MC_INDEX],
    33203345                                              &pThisCC->aStreams[AC97SOUNDSOURCE_MC_INDEX], true /* fForce */);
     
    33323357                        LogRel2(("AC97: Setting line-in ADC rate to 0x%x\n", u32));
    33333358                        ichac97MixerSet(pThis, offPort, u32);
     3359                        /** @todo r=bird: Why reopen it now?  Can't we put that off till it's
     3360                         *        actually used? */
    33343361                        ichac97R3StreamReOpen(pDevIns, pThis, pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PI_INDEX],
    33353362                                              &pThisCC->aStreams[AC97SOUNDSOURCE_PI_INDEX], true /* fForce */);
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