VirtualBox

Changeset 73653 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 14, 2018 12:57:20 PM (6 years ago)
Author:
vboxsync
Message:

Audio/DrvAudio: Bugfixes for drvAudioStreamPlay(); play (transfer) as much as possible /according to the backend) after buffering is complete; added debug logging.

File:
1 edited

Legend:

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

    r73652 r73653  
    898898
    899899        uint32_t cbToWrite = RT_MIN(cbBuf, cbFree);
    900         if (cbToWrite > cbBuf) /* Paranoia. */
    901             cbToWrite = cbBuf;
    902 
    903900        if (!cbToWrite)
    904901        {
     
    943940
    944941                pStream->tsLastReadWrittenNs = RTTimeNanoTS();
    945 
     942#ifdef DEBUG
     943                pStream->Out.Dbg.cfWrittenSinceLastPlay += AUDIOMIXBUF_F2F_RATIO(&pStream->Guest.MixBuf, cfGstMixed);
     944#endif
    946945                /* Keep going. */
    947946            }
     
    951950
    952951            cbWrittenTotal = AUDIOMIXBUF_F2B(&pStream->Guest.MixBuf, cfGstWritten);
    953 #ifdef DEBUG
    954             if (pStream->fThresholdReached)
    955                 pStream->Out.Dbg.cbJitterWrittenPlayed += cbWrittenTotal;
    956 #endif
    957952
    958953#ifdef VBOX_WITH_STATISTICS
     
    14081403        }
    14091404              uint32_t cfLive       = AudioMixBufLive(&pStream->Host.MixBuf);
     1405#ifdef LOG_ENABLED
    14101406        const uint8_t  uLivePercent = (100 * cfLive) / AudioMixBufSize(&pStream->Host.MixBuf);
    14111407
    14121408        const uint64_t tsDeltaPlayedCapturedNs = RTTimeNanoTS() - pStream->tsLastPlayedCapturedNs;
    14131409
    1414         pStream->tsLastPlayedCapturedNs = RTTimeNanoTS();
    1415 
    1416         Log3Func(("[%s] Last played %RU64ns (%RU64ms), filled with %RU64ms (%RU8%%) total, "
    1417                   "(cfLive=%RU32, fThresholdReached=%RTbool)\n",
     1410              uint32_t cfPassed     = DrvAudioHlpNanoToFrames(tsDeltaPlayedCapturedNs, &pStream->Host.Cfg.Props);
     1411#endif
     1412        const uint32_t cfPeriod     = pStream->Host.Cfg.Backend.cfPeriod;
     1413
     1414        Log3Func(("[%s] Last played %RU64ns (%RU64ms), filled with %RU64ms (%RU8%%) total (fThresholdReached=%RTbool)\n",
    14181415                  pStream->szName, tsDeltaPlayedCapturedNs, tsDeltaPlayedCapturedNs / RT_NS_1MS_64,
    1419                   DrvAudioHlpFramesToMilli(cfLive, &pStream->Host.Cfg.Props),
    1420                   uLivePercent, cfLive, pStream->fThresholdReached));
     1416                  DrvAudioHlpFramesToMilli(cfLive, &pStream->Host.Cfg.Props), uLivePercent, pStream->fThresholdReached));
    14211417
    14221418        bool fDoPlay      = pStream->fThresholdReached;
     
    14551451        if (fDoPlay)
    14561452        {
     1453            uint32_t cfWritable;
     1454            if (pThis->pHostDrvAudio->pfnStreamGetWritable)
     1455            {
     1456                cfWritable = PDMAUDIOPCMPROPS_B2F(&pStream->Host.Cfg.Props,
     1457                                                  pThis->pHostDrvAudio->pfnStreamGetWritable(pThis->pHostDrvAudio, pStream->pvBackend));
     1458            }
     1459            else
     1460                cfWritable = cfPeriod;
     1461
    14571462            uint32_t cfToPlay = 0;
    14581463            if (fJustStarted)
    1459                 cfToPlay = pStream->Host.Cfg.Backend.cfPeriod; /* cfPeriod can be 0. */
     1464                cfToPlay = RT_MIN(cfWritable, cfPeriod);
    14601465
    14611466            if (!cfToPlay)
    1462             {
    1463                 cfToPlay = DrvAudioHlpNanoToFrames(tsDeltaPlayedCapturedNs, &pStream->Host.Cfg.Props);
    1464                 if (pStream->Host.Cfg.Device.uSchedulingHintMs)
    1465                     cfToPlay = RT_MIN(cfToPlay, DrvAudioHlpMilliToFrames(pStream->Host.Cfg.Device.uSchedulingHintMs, &pStream->Host.Cfg.Props));
    1466             }
    1467 
    1468             Log3Func(("[%s] fJustStarted=%RTbool, cfLive=%RU32, cfToPlay=%RU32\n",
    1469                       pStream->szName, fJustStarted, cfLive, cfToPlay));
    1470 
    1471             /* Did we reach a buffer underrun? Do pre-buffering again.
    1472              * If we're in pending disabled mode, try to play (drain) the remaining audio data. */
    1473             if (   !(pStream->fStatus & PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE)
    1474                 && !fJustStarted)
    1475             {
    1476                 if (cfLive < cfToPlay)
    1477                 {
    1478                     pStream->fThresholdReached = false;
    1479                     Log3Func(("[%s] Warning: Buffer underrun (cfLive=%RU32, cfToPlay=%RU32)\n", pStream->szName, cfLive, cfToPlay));
    1480                     LogRel2(("Audio: Stream '%s' buffer underrun (total %RU8%%, which is %RU8%% of a period), buffering ...\n",
    1481                              pStream->szName, uLivePercent, (100 * cfLive) / pStream->Host.Cfg.Backend.cfPeriod));
    1482                     break;
    1483                 }
    1484             }
     1467                cfToPlay = cfWritable;
    14851468
    14861469            if (cfToPlay > cfLive) /* Don't try to play more than available. */
    14871470                cfToPlay = cfLive;
    1488 
    1489             if (!cfToPlay)
    1490                 break;
    14911471#ifdef DEBUG
    1492             if (!fJustStarted)
    1493                 pStream->Out.Dbg.cbJitterWrittenPlayed -= AUDIOMIXBUF_F2B(&pStream->Host.MixBuf, cfToPlay);
    14941472            Log3Func(("[%s] Playing %RU32 frames (%RU64ms), now filled with %RU64ms -- %RU8%% (cbJitterWrittenPlayed=%RI64)\n",
    14951473                      pStream->szName, cfToPlay, DrvAudioHlpFramesToMilli(cfToPlay, &pStream->Host.Cfg.Props),
    14961474                      DrvAudioHlpFramesToMilli(AudioMixBufUsed(&pStream->Host.MixBuf), &pStream->Host.Cfg.Props),
    1497                       AudioMixBufUsed(&pStream->Host.MixBuf) * 100 / AudioMixBufSize(&pStream->Host.MixBuf),
    1498                       pStream->Out.Dbg.cbJitterWrittenPlayed));
     1475                      AudioMixBufUsed(&pStream->Host.MixBuf) * 100 / AudioMixBufSize(&pStream->Host.MixBuf)));
    14991476#endif
    1500             if (pThis->pHostDrvAudio->pfnStreamPlayBegin)
    1501                 pThis->pHostDrvAudio->pfnStreamPlayBegin(pThis->pHostDrvAudio, pStream->pvBackend);
    1502 
    1503             if (RT_LIKELY(pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED))
     1477            if (cfToPlay)
    15041478            {
    1505                 rc = drvAudioStreamPlayNonInterleaved(pThis, pStream, cfToPlay, &cfPlayedTotal);
     1479                if (pThis->pHostDrvAudio->pfnStreamPlayBegin)
     1480                    pThis->pHostDrvAudio->pfnStreamPlayBegin(pThis->pHostDrvAudio, pStream->pvBackend);
     1481
     1482                if (RT_LIKELY(pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED))
     1483                {
     1484                    rc = drvAudioStreamPlayNonInterleaved(pThis, pStream, cfToPlay, &cfPlayedTotal);
     1485                }
     1486                else if (pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW)
     1487                {
     1488                    rc = drvAudioStreamPlayRaw(pThis, pStream, cfToPlay, &cfPlayedTotal);
     1489                }
     1490                else
     1491                    AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
     1492
     1493                if (pThis->pHostDrvAudio->pfnStreamPlayEnd)
     1494                    pThis->pHostDrvAudio->pfnStreamPlayEnd(pThis->pHostDrvAudio, pStream->pvBackend);
     1495
     1496                pStream->tsLastPlayedCapturedNs = RTTimeNanoTS();
     1497#ifdef DEBUG
     1498                Log3Func(("[%s] Dbg: cfWrittenSinceLastPlay=%RU64 (%RU64ms)\n",
     1499                          pStream->szName,
     1500                          pStream->Out.Dbg.cfWrittenSinceLastPlay, DrvAudioHlpFramesToMilli(pStream->Out.Dbg.cfWrittenSinceLastPlay, &pStream->Host.Cfg.Props)));
     1501                pStream->Out.Dbg.cfWrittenSinceLastPlay = 0;
     1502#endif
    15061503            }
    1507             else if (pStream->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW)
    1508             {
    1509                 rc = drvAudioStreamPlayRaw(pThis, pStream, cfToPlay, &cfPlayedTotal);
    1510             }
    1511             else
    1512                 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
    1513 
    1514             if (pThis->pHostDrvAudio->pfnStreamPlayEnd)
    1515                 pThis->pHostDrvAudio->pfnStreamPlayEnd(pThis->pHostDrvAudio, pStream->pvBackend);
     1504
     1505            Log3Func(("[%s] Dbg: fJustStarted=%RTbool, cfPassed=%RU32 (%RU64ms), cfLive=%RU32 (%RU64ms), cfPeriod=%RU32 (%RU64ms), "
     1506                      "cfWritable=%RU32 (%RU64ms), -> cfToPlay=%RU32 (%RU64ms), cfPlayed=%RU32 (%RU64ms)\n",
     1507                      pStream->szName, fJustStarted,
     1508                      cfPassed, DrvAudioHlpFramesToMilli(cfPassed, &pStream->Host.Cfg.Props),
     1509                      cfLive, DrvAudioHlpFramesToMilli(cfLive, &pStream->Host.Cfg.Props),
     1510                      cfPeriod, DrvAudioHlpFramesToMilli(cfPeriod, &pStream->Host.Cfg.Props),
     1511                      cfWritable, DrvAudioHlpFramesToMilli(cfWritable, &pStream->Host.Cfg.Props),
     1512                      cfToPlay, DrvAudioHlpFramesToMilli(cfToPlay, &pStream->Host.Cfg.Props),
     1513                      cfPlayedTotal, DrvAudioHlpFramesToMilli(cfPlayedTotal, &pStream->Host.Cfg.Props)));
    15161514        }
    15171515
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