VirtualBox

Changeset 73344 in vbox


Ignore:
Timestamp:
Jul 25, 2018 8:12:10 AM (7 years ago)
Author:
vboxsync
Message:

Audio/DebugAudio: Got rid of intermediate buffer; not needed.

File:
1 edited

Legend:

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

    r70013 r73344  
    77
    88/*
    9  * Copyright (C) 2016-2017 Oracle Corporation
     9 * Copyright (C) 2016-2018 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4545            uint64_t   tsLastCaptured;
    4646        } In;
    47         struct
    48         {
    49             uint8_t   *auPlayBuffer;
    50             uint32_t   cbPlayBuffer;
    51         } Out;
    5247    };
    5348} DEBUGAUDIOSTREAM, *PDEBUGAUDIOSTREAM;
     
    136131    RT_NOREF(pDrv);
    137132
    138     int rc = VINF_SUCCESS;
    139 
    140     pStreamDbg->Out.cbPlayBuffer  = _1K * PDMAUDIOSTREAMCFG_F2B(pCfgReq, 1); /** @todo Make this configurable? */
    141     pStreamDbg->Out.auPlayBuffer  = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer);
    142     if (!pStreamDbg->Out.auPlayBuffer)
    143         rc = VERR_NO_MEMORY;
    144 
     133    char szTemp[RTPATH_MAX];
     134    int rc = RTPathTemp(szTemp, sizeof(szTemp));
    145135    if (RT_SUCCESS(rc))
    146136    {
    147         char szTemp[RTPATH_MAX];
    148         rc = RTPathTemp(szTemp, sizeof(szTemp));
     137        char szFile[RTPATH_MAX];
     138        rc = DrvAudioHlpGetFileName(szFile, RT_ELEMENTS(szFile), szTemp, "DebugAudioOut",
     139                                    pDrv->pDrvIns->iInstance, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAG_NONE);
    149140        if (RT_SUCCESS(rc))
    150141        {
    151             char szFile[RTPATH_MAX];
    152             rc = DrvAudioHlpGetFileName(szFile, RT_ELEMENTS(szFile), szTemp, "DebugAudioOut",
    153                                         pDrv->pDrvIns->iInstance, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAG_NONE);
     142            rc = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAG_NONE, &pStreamDbg->pFile);
    154143            if (RT_SUCCESS(rc))
    155144            {
    156                 rc = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAG_NONE, &pStreamDbg->pFile);
    157                 if (RT_SUCCESS(rc))
    158                 {
    159                     rc = DrvAudioHlpFileOpen(pStreamDbg->pFile, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE,
    160                                              &pCfgReq->Props);
    161                 }
    162 
    163                 if (RT_FAILURE(rc))
    164                     LogRel(("DebugAudio: Creating output file '%s' failed with %Rrc\n", szFile, rc));
     145                rc = DrvAudioHlpFileOpen(pStreamDbg->pFile, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE,
     146                                         &pCfgReq->Props);
    165147            }
    166             else
    167                 LogRel(("DebugAudio: Unable to build file name for temp dir '%s': %Rrc\n", szTemp, rc));
     148
     149            if (RT_FAILURE(rc))
     150                LogRel(("DebugAudio: Creating output file '%s' failed with %Rrc\n", szFile, rc));
    168151        }
    169152        else
    170             LogRel(("DebugAudio: Unable to retrieve temp dir: %Rrc\n", rc));
     153            LogRel(("DebugAudio: Unable to build file name for temp dir '%s': %Rrc\n", szTemp, rc));
    171154    }
     155    else
     156        LogRel(("DebugAudio: Unable to retrieve temp dir: %Rrc\n", rc));
    172157
    173158    if (RT_SUCCESS(rc))
     
    223208    PDEBUGAUDIOSTREAM  pStreamDbg = (PDEBUGAUDIOSTREAM)pStream;
    224209
    225     uint32_t cbWrittenTotal = 0;
    226 
    227     uint32_t cbAvail = cxBuf;
    228     while (cbAvail)
    229     {
    230         uint32_t cbChunk = RT_MIN(cbAvail, pStreamDbg->Out.cbPlayBuffer);
    231 
    232         memcpy(pStreamDbg->Out.auPlayBuffer, (uint8_t *)pvBuf + cbWrittenTotal, cbChunk);
    233 
    234         int rc2 = DrvAudioHlpFileWrite(pStreamDbg->pFile, pStreamDbg->Out.auPlayBuffer, cbChunk, 0 /* fFlags */);
    235         if (RT_FAILURE(rc2))
    236         {
    237             LogRel(("DebugAudio: Writing output failed with %Rrc\n", rc2));
    238             break;
    239         }
    240 
    241         Assert(cbAvail >= cbChunk);
    242         cbAvail        -= cbChunk;
    243 
    244         cbWrittenTotal += cbChunk;
     210    int rc = DrvAudioHlpFileWrite(pStreamDbg->pFile, pvBuf, cxBuf, 0 /* fFlags */);
     211    if (RT_FAILURE(rc))
     212    {
     213        LogRel(("DebugAudio: Writing output failed with %Rrc\n", rc));
     214        return rc;
    245215    }
    246216
    247217    if (pcxWritten)
    248         *pcxWritten = cbWrittenTotal;
     218        *pcxWritten = cxBuf;
    249219
    250220    return VINF_SUCCESS;
     
    278248{
    279249    RT_NOREF(pDrv);
    280 
    281     if (pStreamDbg->Out.auPlayBuffer)
    282     {
    283         RTMemFree(pStreamDbg->Out.auPlayBuffer);
    284         pStreamDbg->Out.auPlayBuffer = NULL;
    285     }
    286250
    287251    DrvAudioHlpFileDestroy(pStreamDbg->pFile);
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