VirtualBox

Changeset 89470 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 2, 2021 7:56:05 PM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioAlsa: Eliminated the ALSAAUDIOSTREAMCFG structure and associated config duplication. bugref:9890

File:
1 edited

Legend:

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

    r89450 r89470  
    7373*********************************************************************************************************************************/
    7474/**
    75  * ALSA audio stream configuration.
    76  */
    77 typedef struct ALSAAUDIOSTREAMCFG
    78 {
    79     unsigned int        freq;
    80     /** PCM sound format. */
    81     snd_pcm_format_t    fmt;
    82 #if 0 /* Unused. */
    83     /** PCM data access type. */
    84     snd_pcm_access_t    access;
    85     /** Whether resampling should be performed by alsalib or not. */
    86     int                 resample;
    87 #endif
    88     /** Number of audio channels. */
    89     int                 cChannels;
    90     /** Buffer size (in audio frames). */
    91     unsigned long       buffer_size;
    92     /** Periods (in audio frames). */
    93     unsigned long       period_size;
    94     /** For playback:  Starting to play threshold (in audio frames).
    95      *  For Capturing: ~~Starting to capture threshold (in audio frames)~~ !nothing! */
    96     unsigned long       threshold;
    97 
    98     /* latency = period_size * periods / (rate * bytes_per_frame) */
    99 } ALSAAUDIOSTREAMCFG;
    100 /** Pointer to an ALSA audio stream config. */
    101 typedef ALSAAUDIOSTREAMCFG *PALSAAUDIOSTREAMCFG;
    102 
    103 
    104 /**
    10575 * ALSA host audio specific stream data.
    10676 */
     
    11787    /** The stream's acquired configuration. */
    11888    PDMAUDIOSTREAMCFG       Cfg;
    119     /** The acquired ALSA stream config (same as Cfg). */
    120     ALSAAUDIOSTREAMCFG      AlsaCfg;
    12189} ALSAAUDIOSTREAM;
    12290/** Pointer to the ALSA host audio specific stream data. */
     
    386354
    387355        default:
    388             AssertMsgFailed(("%RU8 bytes not supported\n", PDMAudioPropsSampleSize(pProps)));
    389             return SND_PCM_FORMAT_U8;
    390     }
    391 }
    392 
    393 
    394 /**
    395  * Converts an ALSA PCM format to internal PCM properties.
    396  *
    397  * @returns VBox status code.
    398  * @param   pProps      Where to store the converted PCM properties on success.
    399  * @param   fmt         ALSA PCM format to convert.
    400  * @param   cChannels   Number of channels.
    401  * @param   uHz         Frequency.
    402  */
    403 static int alsaALSAToAudioProps(PPDMAUDIOPCMPROPS pProps, snd_pcm_format_t fmt, int cChannels, unsigned uHz)
    404 {
    405     AssertReturn(cChannels > 0, VERR_INVALID_PARAMETER);
    406     AssertReturn(cChannels < PDMAUDIO_MAX_CHANNELS, VERR_INVALID_PARAMETER);
    407     switch (fmt)
    408     {
    409         case SND_PCM_FORMAT_S8:
    410             PDMAudioPropsInit(pProps, 1 /*8-bit*/,  true /*signed*/, cChannels, uHz);
    411             break;
    412 
    413         case SND_PCM_FORMAT_U8:
    414             PDMAudioPropsInit(pProps, 1 /*8-bit*/, false /*signed*/, cChannels, uHz);
    415             break;
    416 
    417         case SND_PCM_FORMAT_S16_LE:
    418             PDMAudioPropsInitEx(pProps, 2 /*16-bit*/,  true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    419             break;
    420 
    421         case SND_PCM_FORMAT_U16_LE:
    422             PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    423             break;
    424 
    425         case SND_PCM_FORMAT_S16_BE:
    426             PDMAudioPropsInitEx(pProps, 2 /*16-bit*/,  true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    427             break;
    428 
    429         case SND_PCM_FORMAT_U16_BE:
    430             PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    431             break;
    432 
    433         case SND_PCM_FORMAT_S32_LE:
    434             PDMAudioPropsInitEx(pProps, 4 /*32-bit*/,  true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    435             break;
    436 
    437         case SND_PCM_FORMAT_U32_LE:
    438             PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    439             break;
    440 
    441         case SND_PCM_FORMAT_S32_BE:
    442             PDMAudioPropsInitEx(pProps, 4 /*32-bit*/,  true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    443             break;
    444 
    445         case SND_PCM_FORMAT_U32_BE:
    446             PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    447             break;
    448 
    449         default:
    450             AssertMsgFailedReturn(("Format %d not supported\n", fmt), VERR_NOT_SUPPORTED);
    451     }
    452     return VINF_SUCCESS;
     356            AssertLogRelMsgFailed(("%RU8 bytes not supported\n", PDMAudioPropsSampleSize(pProps)));
     357            return SND_PCM_FORMAT_UNKNOWN;
     358    }
    453359}
    454360
     
    458364 *
    459365 * @returns 0 on success, negative errno on failure.
    460  * @param   hPCM            ALSA stream to set software parameters for.
    461  * @param   fIn             Whether this is an input stream or not.
    462  * @param   pAlsaCfgReq     Requested configuration to set (ALSA).
    463  * @param   pAlsaCfgObt     Obtained configuration on success (ALSA).
    464  *                          Might differ from requested configuration.
    465  */
    466 static int alsaStreamSetSWParams(snd_pcm_t *hPCM, bool fIn, PALSAAUDIOSTREAMCFG pAlsaCfgReq, PALSAAUDIOSTREAMCFG pAlsaCfgObt)
    467 {
    468     if (fIn) /* For input streams there's nothing to do in here right now. */
    469         return VINF_SUCCESS;
     366 * @param   hPCM        ALSA stream to set software parameters for.
     367 * @param   pCfgReq     Requested stream configuration (PDM).
     368 * @param   pCfgAcq     The actual stream configuration (PDM). Updated as
     369 *                      needed.
     370 */
     371static int alsaStreamSetSWParams(snd_pcm_t *hPCM, PCPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     372{
     373    if (pCfgReq->enmDir == PDMAUDIODIR_IN) /* For input streams there's nothing to do in here right now. */
     374        return 0;
    470375
    471376    snd_pcm_sw_params_t *pSWParms = NULL;
     
    480385       one continuous chunk when we should start playing.  But since it is
    481386       configurable, we'll set a reasonable minimum of two DMA periods or
    482        max 64 milliseconds (the pAlsaCfgReq->threshold value).
     387       max 50 milliseconds (the pAlsaCfgReq->threshold value).
    483388
    484389       Of course we also have to make sure the threshold is below the buffer
    485390       size, or ALSA will never start playing. */
    486     unsigned long cFramesThreshold = RT_MIN(pAlsaCfgObt->period_size * 2, pAlsaCfgReq->threshold);
    487     if (cFramesThreshold >= pAlsaCfgObt->buffer_size - pAlsaCfgObt->buffer_size / 16)
    488         cFramesThreshold = pAlsaCfgObt->buffer_size - pAlsaCfgObt->buffer_size / 16;
     391    unsigned long const cFramesMax       = PDMAudioPropsMilliToFrames(&pCfgAcq->Props, 50);
     392    unsigned long       cFramesThreshold = RT_MIN(pCfgAcq->Backend.cFramesPeriod * 2, cFramesMax);
     393    if (cFramesThreshold >= pCfgAcq->Backend.cFramesBufferSize - pCfgAcq->Backend.cFramesBufferSize / 16)
     394        cFramesThreshold  = pCfgAcq->Backend.cFramesBufferSize - pCfgAcq->Backend.cFramesBufferSize / 16;
    489395
    490396    err = snd_pcm_sw_params_set_start_threshold(hPCM, pSWParms, cFramesThreshold);
    491397    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set software threshold to %lu: %s\n", cFramesThreshold, snd_strerror(err)), err);
    492398
    493     err = snd_pcm_sw_params_set_avail_min(hPCM, pSWParms, pAlsaCfgReq->period_size);
    494     AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set available minimum to %lu: %s\n",
    495                                      pAlsaCfgReq->period_size, snd_strerror(err)), err);
     399    err = snd_pcm_sw_params_set_avail_min(hPCM, pSWParms, pCfgReq->Backend.cFramesPeriod);
     400    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set available minimum to %u: %s\n",
     401                                     pCfgReq->Backend.cFramesPeriod, snd_strerror(err)), err);
    496402
    497403    /* Commit the software parameters: */
     
    500406
    501407    /* Get the actual parameters: */
    502     err = snd_pcm_sw_params_get_start_threshold(pSWParms, &pAlsaCfgObt->threshold);
    503     AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to get start threshold: %s\n", snd_strerror(err)), err);
    504 
    505     LogRel2(("ALSA: SW params: %lu frames threshold, %lu frame avail minimum\n",
    506              pAlsaCfgObt->threshold, pAlsaCfgReq->period_size));
     408    snd_pcm_uframes_t cFramesThresholdActual = cFramesThreshold;
     409    err = snd_pcm_sw_params_get_start_threshold(pSWParms, &cFramesThresholdActual);
     410    AssertLogRelMsgStmt(err >= 0, ("ALSA: Failed to get start threshold: %s\n", snd_strerror(err)),
     411                        cFramesThresholdActual = cFramesThreshold);
     412
     413    LogRel2(("ALSA: SW params: %lu frames threshold, %u frames avail minimum\n",
     414             cFramesThresholdActual, pCfgAcq->Backend.cFramesPeriod));
    507415    return 0;
    508416}
     
    514422 * @returns 0 on success, negative errno on failure.
    515423 * @param   hPCM        ALSA stream to set software parameters for.
    516  * @param   pAlsaCfgReq Requested configuration to set (ALSA).
    517  * @param   pAlsaCfgObt Obtained configuration on success (ALSA). Might differ
    518  *                      from requested configuration.
    519  */
    520 static int alsaStreamSetHwParams(snd_pcm_t *hPCM, PALSAAUDIOSTREAMCFG pAlsaCfgReq, PALSAAUDIOSTREAMCFG pAlsaCfgObt)
     424 * @param   enmAlsaFmt  The ALSA format to use.
     425 * @param   pCfgReq     Requested stream configuration (PDM).
     426 * @param   pCfgAcq     The actual stream configuration (PDM).  This is assumed
     427 *                      to be a copy of pCfgReq on input, at least for
     428 *                      properties handled here.  On output some of the
     429 *                      properties may be updated to match the actual stream
     430 *                      configuration.
     431 */
     432static int alsaStreamSetHwParams(snd_pcm_t *hPCM, snd_pcm_format_t enmAlsaFmt,
     433                                 PCPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    521434{
    522435    /*
     
    539452
    540453    /* Set the format, frequency and channel count. */
    541     err = snd_pcm_hw_params_set_format(hPCM, pHWParms, pAlsaCfgReq->fmt);
    542     AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set audio format to %d: %s\n", pAlsaCfgReq->fmt, snd_strerror(err)), err);
    543 
    544     unsigned int uFreq = pAlsaCfgReq->freq;
     454    err = snd_pcm_hw_params_set_format(hPCM, pHWParms, enmAlsaFmt);
     455    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set audio format to %d: %s\n", enmAlsaFmt, snd_strerror(err)), err);
     456
     457    unsigned int uFreq = PDMAudioPropsHz(&pCfgReq->Props);
    545458    err = snd_pcm_hw_params_set_rate_near(hPCM, pHWParms, &uFreq, NULL /*dir*/);
    546     AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set frequency to %uHz: %s\n", pAlsaCfgReq->freq, snd_strerror(err)), err);
    547     pAlsaCfgObt->freq = uFreq;
    548 
    549     unsigned int cChannels = pAlsaCfgReq->cChannels;
     459    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set frequency to %uHz: %s\n",
     460                                     PDMAudioPropsHz(&pCfgReq->Props), snd_strerror(err)), err);
     461    pCfgAcq->Props.uHz = uFreq;
     462
     463    unsigned int cChannels = PDMAudioPropsChannels(&pCfgReq->Props);
    550464    err = snd_pcm_hw_params_set_channels_near(hPCM, pHWParms, &cChannels);
    551     AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set number of channels to %d\n", pAlsaCfgReq->cChannels), err);
    552     pAlsaCfgObt->cChannels = cChannels;
     465    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set number of channels to %d\n", PDMAudioPropsChannels(&pCfgReq->Props)),
     466                          err);
     467    if (cChannels != PDMAudioPropsChannels(&pCfgReq->Props))
     468    {
     469        AssertLogRelMsgReturn(cChannels > 0 && cChannels <= PDMAUDIO_MAX_CHANNELS,
     470                              ("ALSA: Unsupported channel count: %u (requested %d)\n",
     471                               cChannels, PDMAudioPropsChannels(&pCfgReq->Props)), -ERANGE);
     472        PDMAudioPropsSetChannels(&pCfgAcq->Props, (uint8_t)cChannels);
     473        /** @todo Can we somehow guess channel IDs? */
     474    }
    553475
    554476    /* The period size (reportedly frame count per hw interrupt): */
    555477    int               dir    = 0;
    556     snd_pcm_uframes_t minval = pAlsaCfgReq->period_size;
     478    snd_pcm_uframes_t minval = pCfgReq->Backend.cFramesPeriod;
    557479    err = snd_pcm_hw_params_get_period_size_min(pHWParms, &minval, &dir);
    558480    AssertLogRelMsgReturn(err >= 0, ("ALSA: Could not determine minimal period size: %s\n", snd_strerror(err)), err);
    559481
    560     snd_pcm_uframes_t period_size_f = pAlsaCfgReq->period_size;
     482    snd_pcm_uframes_t period_size_f = pCfgReq->Backend.cFramesPeriod;
    561483    if (period_size_f < minval)
    562484        period_size_f = minval;
    563485    err = snd_pcm_hw_params_set_period_size_near(hPCM, pHWParms, &period_size_f, 0);
    564     LogRel2(("ALSA: Period size is: %lu frames (min %lu, requested %lu)\n", period_size_f, minval, pAlsaCfgReq->period_size));
     486    LogRel2(("ALSA: Period size is: %lu frames (min %lu, requested %u)\n", period_size_f, minval, pCfgReq->Backend.cFramesPeriod));
    565487    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set period size %d (%s)\n", period_size_f, snd_strerror(err)), err);
    566488
    567489    /* The buffer size: */
    568     minval = pAlsaCfgReq->buffer_size;
     490    minval = pCfgReq->Backend.cFramesBufferSize;
    569491    err = snd_pcm_hw_params_get_buffer_size_min(pHWParms, &minval);
    570492    AssertLogRelMsgReturn(err >= 0, ("ALSA: Could not retrieve minimal buffer size: %s\n", snd_strerror(err)), err);
    571493
    572     snd_pcm_uframes_t buffer_size_f = pAlsaCfgReq->buffer_size;
     494    snd_pcm_uframes_t buffer_size_f = pCfgReq->Backend.cFramesBufferSize;
    573495    if (buffer_size_f < minval)
    574496        buffer_size_f = minval;
    575497    err = snd_pcm_hw_params_set_buffer_size_near(hPCM, pHWParms, &buffer_size_f);
    576     LogRel2(("ALSA: Buffer size is: %lu frames (min %lu, requested %lu)\n", buffer_size_f, minval, pAlsaCfgReq->buffer_size));
     498    LogRel2(("ALSA: Buffer size is: %lu frames (min %lu, requested %u)\n", buffer_size_f, minval, pCfgReq->Backend.cFramesBufferSize));
    577499    AssertLogRelMsgReturn(err >= 0, ("ALSA: Failed to set near buffer size %RU32: %s\n", buffer_size_f, snd_strerror(err)), err);
    578500
     
    589511    err = snd_pcm_hw_params_get_buffer_size(pHWParms, &obt_buffer_size);
    590512    AssertLogRelMsgStmt(err >= 0, ("ALSA: Failed to get buffer size: %s\n", snd_strerror(err)), obt_buffer_size = buffer_size_f);
    591     pAlsaCfgObt->buffer_size = obt_buffer_size;
     513    pCfgAcq->Backend.cFramesBufferSize = obt_buffer_size;
    592514
    593515    snd_pcm_uframes_t obt_period_size = period_size_f;
    594516    err = snd_pcm_hw_params_get_period_size(pHWParms, &obt_period_size, &dir);
    595517    AssertLogRelMsgStmt(err >= 0, ("ALSA: Failed to get period size: %s\n", snd_strerror(err)), obt_period_size = period_size_f);
    596     pAlsaCfgObt->period_size = obt_period_size;
    597 
    598 //    pAlsaCfgObt->access  = pAlsaCfgReq->access;  - unused and uninitialized.
    599     pAlsaCfgObt->fmt     = pAlsaCfgReq->fmt;
    600 
    601     LogRel2(("ALSA: HW params: %u Hz, %lu frames period, %lu frames buffer, %u channel(s), fmt=%d, access=%d\n",
    602              pAlsaCfgObt->freq, pAlsaCfgObt->period_size, pAlsaCfgObt->buffer_size, pAlsaCfgObt->cChannels,
    603              pAlsaCfgObt->fmt, -1 /*pAlsaCfgObt->access*/));
     518    pCfgAcq->Backend.cFramesPeriod = obt_period_size;
     519
     520    LogRel2(("ALSA: HW params: %u Hz, %u frames period, %u frames buffer, %u channel(s), enmAlsaFmt=%d\n",
     521             PDMAudioPropsHz(&pCfgAcq->Props), pCfgAcq->Backend.cFramesPeriod, pCfgAcq->Backend.cFramesBufferSize,
     522             PDMAudioPropsChannels(&pCfgAcq->Props), enmAlsaFmt));
    604523    return 0;
    605524}
     
    610529 *
    611530 * @returns VBox status code.
    612  * @param   pszDev      The name of the device to open.
    613  * @param   fIn         Whether this is an input stream to create or not.
    614  * @param   pAlsaCfgReq Requested configuration to create stream with (ALSA).
     531 * @param   pThis       The alsa driver instance data.
     532 * @param   enmAlsaFmt  The ALSA format to use.
    615533 * @param   pCfgReq     Requested configuration to create stream with (PDM).
    616  * @param   pAlsaCfgObt Obtained configuration the stream got created on
    617  *                      success.
     534 * @param   pCfgAcq     The actual stream configuration (PDM).  This is assumed
     535 *                      to be a copy of pCfgReq on input, at least for
     536 *                      properties handled here.  On output some of the
     537 *                      properties may be updated to match the actual stream
     538 *                      configuration.
    618539 * @param   phPCM       Where to store the ALSA stream handle on success.
    619540 */
    620 static int alsaStreamOpen(const char *pszDev, bool fIn, PALSAAUDIOSTREAMCFG pAlsaCfgReq, PPDMAUDIOSTREAMCFG pCfgReq,
    621                           PALSAAUDIOSTREAMCFG pAlsaCfgObt,  snd_pcm_t **phPCM)
    622 {
    623     AssertLogRelMsgReturn(pszDev && *pszDev,
    624                           ("ALSA: Invalid or no %s device name set\n", fIn ? "input" : "output"),
    625                           VERR_INVALID_NAME);
    626     RT_NOREF(pCfgReq);
    627 
     541static int alsaStreamOpen(PDRVHOSTALSAAUDIO pThis, snd_pcm_format_t enmAlsaFmt, PCPDMAUDIOSTREAMCFG pCfgReq,
     542                          PPDMAUDIOSTREAMCFG pCfgAcq, snd_pcm_t **phPCM)
     543{
    628544    /*
    629545     * Open the stream.
    630546     */
    631     int rc = VERR_AUDIO_STREAM_COULD_NOT_CREATE;
     547    int                rc      = VERR_AUDIO_STREAM_COULD_NOT_CREATE;
     548    const char * const pszType = pCfgReq->enmDir == PDMAUDIODIR_IN ? "input" : "output";
     549    const char * const pszDev  = pCfgReq->enmDir == PDMAUDIODIR_IN ? pThis->szDefaultIn : pThis->szDefaultOut;
     550    snd_pcm_stream_t   enmType = pCfgReq->enmDir == PDMAUDIODIR_IN ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK;
     551
    632552    snd_pcm_t *hPCM = NULL;
    633     LogRel(("ALSA: Using %s device \"%s\"\n", fIn ? "input" : "output", pszDev));
    634     int err = snd_pcm_open(&hPCM, pszDev,
    635                            fIn ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
    636                            SND_PCM_NONBLOCK);
     553    LogRel(("ALSA: Using %s device \"%s\"\n", pszType, pszDev));
     554    int err = snd_pcm_open(&hPCM, pszDev, enmType, SND_PCM_NONBLOCK);
    637555    if (err >= 0)
    638556    {
     
    643561             * Configure hardware stream parameters.
    644562             */
    645             err = alsaStreamSetHwParams(hPCM, pAlsaCfgReq, pAlsaCfgObt);
     563            err = alsaStreamSetHwParams(hPCM, enmAlsaFmt, pCfgReq, pCfgAcq);
    646564            if (err >= 0)
    647565            {
     
    656574                     * Configure software stream parameters and we're done.
    657575                     */
    658                     rc = alsaStreamSetSWParams(hPCM, fIn, pAlsaCfgReq, pAlsaCfgObt);
     576                    rc = alsaStreamSetSWParams(hPCM, pCfgReq, pCfgAcq);
    659577                    if (RT_SUCCESS(rc))
    660578                    {
     
    668586        }
    669587        else
    670             LogRel(("ALSA: Error setting output non-blocking mode: %s\n", snd_strerror(err)));
     588            LogRel(("ALSA: Error setting non-blocking mode for %s stream: %s\n", pszType, snd_strerror(err)));
    671589        alsaStreamClose(&hPCM);
    672590    }
    673591    else
    674         LogRel(("ALSA: Failed to open \"%s\" as %s device: %s\n", pszDev, fIn ? "input" : "output", snd_strerror(err)));
     592        LogRel(("ALSA: Failed to open \"%s\" as %s device: %s\n", pszDev, pszType, snd_strerror(err)));
    675593    *phPCM = NULL;
    676594    return rc;
     
    693611    PDMAudioStrmCfgCopy(&pStreamALSA->Cfg, pCfgReq);
    694612
    695     ALSAAUDIOSTREAMCFG Req;
    696     Req.fmt         = alsaAudioPropsToALSA(&pCfgReq->Props);
    697     Req.freq        = PDMAudioPropsHz(&pCfgReq->Props);
    698     Req.cChannels   = PDMAudioPropsChannels(&pCfgReq->Props);
    699     Req.period_size = pCfgReq->Backend.cFramesPeriod;
    700     Req.buffer_size = pCfgReq->Backend.cFramesBufferSize;
    701     Req.threshold   = PDMAudioPropsMilliToFrames(&pCfgReq->Props, 50);
    702     int rc = alsaStreamOpen(pCfgReq->enmDir == PDMAUDIODIR_IN ? pThis->szDefaultIn : pThis->szDefaultOut,
    703                             pCfgReq->enmDir == PDMAUDIODIR_IN,
    704                             &Req, pCfgReq, &pStreamALSA->AlsaCfg, &pStreamALSA->hPCM);
    705     if (RT_SUCCESS(rc))
    706     {
    707         rc = alsaALSAToAudioProps(&pCfgAcq->Props, pStreamALSA->AlsaCfg.fmt,
    708                                   pStreamALSA->AlsaCfg.cChannels, pStreamALSA->AlsaCfg.freq);
     613    int                     rc;
     614    snd_pcm_format_t const  enmFmt = alsaAudioPropsToALSA(&pCfgReq->Props);
     615    if (enmFmt != SND_PCM_FORMAT_UNKNOWN)
     616    {
     617        rc = alsaStreamOpen(pThis, enmFmt, pCfgReq, pCfgAcq, &pStreamALSA->hPCM);
    709618        if (RT_SUCCESS(rc))
    710619        {
    711             pCfgAcq->Backend.cFramesPeriod          = pStreamALSA->AlsaCfg.period_size;
    712             pCfgAcq->Backend.cFramesBufferSize      = pStreamALSA->AlsaCfg.buffer_size;
    713 
    714620            /* We have no objections to the pre-buffering that DrvAudio applies,
    715621               only we need to adjust it relative to the actual buffer size. */
     
    722628            return rc;
    723629        }
    724         alsaStreamClose(&pStreamALSA->hPCM);
    725     }
     630    }
     631    else
     632        rc = VERR_AUDIO_STREAM_COULD_NOT_CREATE;
    726633    LogFunc(("returns %Rrc\n", rc));
    727634    return rc;
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