VirtualBox

Changeset 73643 in vbox


Ignore:
Timestamp:
Aug 14, 2018 8:52:49 AM (6 years ago)
Author:
vboxsync
Message:

Audio/ALSA: Renamed alsaStreamSetThreshold() to alsaStreamSetSWParams() to emphasize its usage, and made sure that the current set starting threshold is retrieved again after setting it.

File:
1 edited

Legend:

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

    r73529 r73643  
    8484        struct
    8585        {
    86 
    8786        } In;
    8887        struct
    8988        {
    90             /** Minimum samples required for ALSA to play data. */
    91             uint32_t    cSamplesMin;
    9289        } Out;
    9390    };
     
    241238
    242239
    243 static int alsaStreamSetThreshold(snd_pcm_t *phPCM, snd_pcm_uframes_t threshold)
    244 {
     240static int alsaStreamSetSWParams(snd_pcm_t *phPCM, bool fIn, PALSAAUDIOSTREAMCFG pCfgReq, PALSAAUDIOSTREAMCFG pCfgObt)
     241{
     242    if (fIn) /* For input streams there's nothing to do in here right now. */
     243        return VINF_SUCCESS;
     244
    245245    snd_pcm_sw_params_t *pSWParms = NULL;
    246246    snd_pcm_sw_params_alloca(&pSWParms);
     
    254254        if (err < 0)
    255255        {
    256             LogRel(("ALSA: Failed to get current software parameters for threshold: %s\n",
    257                     snd_strerror(err)));
     256            LogRel(("ALSA: Failed to get current software parameters: %s\n", snd_strerror(err)));
    258257            rc = VERR_ACCESS_DENIED;
    259258            break;
    260259        }
    261260
    262         err = snd_pcm_sw_params_set_start_threshold(phPCM, pSWParms, threshold);
    263         if (err < 0)
    264         {
    265             LogRel(("ALSA: Failed to set software threshold to %ld: %s\n",
    266                     threshold, snd_strerror(err)));
     261        err = snd_pcm_sw_params_set_start_threshold(phPCM, pSWParms, pCfgReq->threshold);
     262        if (err < 0)
     263        {
     264            LogRel(("ALSA: Failed to set software threshold to %ld: %s\n", pCfgReq->threshold, snd_strerror(err)));
    267265            rc = VERR_ACCESS_DENIED;
    268266            break;
    269267        }
    270268
    271         err = snd_pcm_sw_params_set_avail_min(phPCM, pSWParms, 512);
    272         if (err < 0)
    273         {
    274             LogRel(("ALSA: Failed to set available minimum to %ld: %s\n",
    275                     threshold, snd_strerror(err)));
     269        err = snd_pcm_sw_params_set_avail_min(phPCM, pSWParms, pCfgReq->period_size);
     270        if (err < 0)
     271        {
     272            LogRel(("ALSA: Failed to set available minimum to %ld: %s\n", pCfgReq->threshold, snd_strerror(err)));
    276273            rc = VERR_ACCESS_DENIED;
    277274            break;
     
    281278        if (err < 0)
    282279        {
    283             LogRel(("ALSA: Failed to set new software parameters for threshold: %s\n",
    284                     snd_strerror(err)));
     280            LogRel(("ALSA: Failed to set new software parameters: %s\n", snd_strerror(err)));
    285281            rc = VERR_ACCESS_DENIED;
    286282            break;
    287283        }
    288284
    289         LogFlowFunc(("Setting threshold to %RU32\n", threshold));
     285        err = snd_pcm_sw_params_get_start_threshold(pSWParms, &pCfgObt->threshold);
     286        if (err < 0)
     287        {
     288            LogRel(("ALSA: Failed to get start threshold\n"));
     289            rc = VERR_ACCESS_DENIED;
     290            break;
     291        }
     292
     293        LogFunc(("Setting threshold to %RU32 frames\n", pCfgObt->threshold));
    290294        rc = VINF_SUCCESS;
    291295    }
     
    482486        }
    483487
    484         LogRel2(("ALSA: Frequency is %dHz, period size is %RU32 frames, buffer size is %RU32 fames\n",
     488        LogRel2(("ALSA: Frequency is %dHz, period size is %RU32 frames, buffer size is %RU32 frames\n",
    485489                 pCfgReq->freq, obt_period_size, obt_buffer_size));
    486490
     
    493497        }
    494498
    495         if (   !fIn
    496             && pCfgReq->threshold)
    497         {
    498             rc = alsaStreamSetThreshold(phPCM, pCfgReq->threshold);
    499             if (RT_FAILURE(rc))
    500                 break;
    501 
    502             LogRel2(("ALSA: Threshold for playback set to %RU32 frames\n", pCfgReq->threshold));
    503         }
     499        rc = alsaStreamSetSWParams(phPCM, fIn, pCfgReq, pCfgObt);
     500        if (RT_FAILURE(rc))
     501            break;
    504502
    505503        pCfgObt->fmt         = pCfgReq->fmt;
     
    508506        pCfgObt->period_size = obt_period_size;
    509507        pCfgObt->buffer_size = obt_buffer_size;
    510         pCfgObt->threshold   = pCfgReq->threshold;
    511 
    512         rc = VINF_SUCCESS;
    513508    }
    514509    while (0);
     
    13831378    snd_pcm_sframes_t cFramesAvail;
    13841379    int rc = alsaStreamGetAvail(pStreamALSA->phPCM, &cFramesAvail);
    1385     if (   RT_SUCCESS(rc)
    1386         && (uint32_t)cFramesAvail >= pStreamALSA->Out.cSamplesMin)
    1387     {
     1380    if (RT_SUCCESS(rc))
    13881381        cbAvail = PDMAUDIOSTREAMCFG_F2B(pStreamALSA->pCfg, cFramesAvail);
    1389     }
    13901382
    13911383    return cbAvail;
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