VirtualBox

Changeset 89481 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 3, 2021 12:46:22 PM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioAlsaStubs.h: Cleaned up function prefix and struct names. bugref:9890

File:
1 edited

Legend:

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

    r89480 r89481  
    7575 * ALSA host audio specific stream data.
    7676 */
    77 typedef struct ALSAAUDIOSTREAM
     77typedef struct DRVHSTAUDALSASTREAM
    7878{
    7979    /** Common part. */
     
    8787    /** The stream's acquired configuration. */
    8888    PDMAUDIOSTREAMCFG       Cfg;
    89 } ALSAAUDIOSTREAM;
     89} DRVHSTAUDALSASTREAM;
    9090/** Pointer to the ALSA host audio specific stream data. */
    91 typedef ALSAAUDIOSTREAM *PALSAAUDIOSTREAM;
     91typedef DRVHSTAUDALSASTREAM *PDRVHSTAUDALSASTREAM;
    9292
    9393
     
    9696 * @implements PDMIAUDIOCONNECTOR
    9797 */
    98 typedef struct DRVHOSTALSAAUDIO
     98typedef struct DRVHSTAUDALSA
    9999{
    100100    /** Pointer to the driver instance structure. */
     
    109109    /** Default output device name. */
    110110    char                szDefaultOut[256];
    111 } DRVHOSTALSAAUDIO;
     111} DRVHSTAUDALSA;
    112112/** Pointer to the instance data of an ALSA host audio driver. */
    113 typedef DRVHOSTALSAAUDIO *PDRVHOSTALSAAUDIO;
     113typedef DRVHSTAUDALSA *PDRVHSTAUDALSA;
    114114
    115115
     
    122122 *                  NULL.
    123123 */
    124 static int alsaStreamClose(snd_pcm_t **phPCM)
     124static int drvHstAudAlsaStreamClose(snd_pcm_t **phPCM)
    125125{
    126126    if (!phPCM || !*phPCM)
     
    146146
    147147#ifdef DEBUG
    148 static void alsaDbgErrorHandler(const char *file, int line, const char *function,
    149                                 int err, const char *fmt, ...)
     148static void drvHstAudAlsaDbgErrorHandler(const char *file, int line, const char *function,
     149                                         int err, const char *fmt, ...)
    150150{
    151151    /** @todo Implement me! */
     
    161161 * @param   hPCM               ALSA stream handle.
    162162 */
    163 static int alsaStreamRecover(snd_pcm_t *hPCM)
     163static int drvHstAudAlsaStreamRecover(snd_pcm_t *hPCM)
    164164{
    165165    AssertPtrReturn(hPCM, VERR_INVALID_POINTER);
     
    179179 * Resumes an ALSA stream.
    180180 *
     181 * Used by drvHstAudAlsaHA_StreamPlay() and drvHstAudAlsaHA_StreamCapture().
     182 *
    181183 * @returns VBox status code.
    182184 * @param   hPCM               ALSA stream to resume.
    183185 */
    184 static int alsaStreamResume(snd_pcm_t *hPCM)
     186static int drvHstAudAlsaStreamResume(snd_pcm_t *hPCM)
    185187{
    186188    AssertPtrReturn(hPCM, VERR_INVALID_POINTER);
     
    200202 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetConfig}
    201203 */
    202 static DECLCALLBACK(int) drvHostAlsaAudioHA_GetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg)
     204static DECLCALLBACK(int) drvHstAudAlsaHA_GetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg)
    203205{
    204206    RT_NOREF(pInterface);
     
    209211     */
    210212    RTStrCopy(pBackendCfg->szName, sizeof(pBackendCfg->szName), "ALSA");
    211     pBackendCfg->cbStream       = sizeof(ALSAAUDIOSTREAM);
     213    pBackendCfg->cbStream       = sizeof(DRVHSTAUDALSASTREAM);
    212214    pBackendCfg->fFlags         = 0;
    213215    /* ALSA allows exactly one input and one output used at a time for the selected device(s). */
     
    222224 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetDevices}
    223225 */
    224 static DECLCALLBACK(int) drvHostAlsaAudioHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum)
     226static DECLCALLBACK(int) drvHstAudAlsaHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum)
    225227{
    226228    RT_NOREF(pInterface);
     
    321323 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
    322324 */
    323 static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostAlsaAudioHA_GetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
     325static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHstAudAlsaHA_GetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
    324326{
    325327    RT_NOREF(enmDir);
     
    617619 * @param   phPCM       Where to store the ALSA stream handle on success.
    618620 */
    619 static int alsaStreamOpen(PDRVHOSTALSAAUDIO pThis, snd_pcm_format_t enmAlsaFmt, PCPDMAUDIOSTREAMCFG pCfgReq,
     621static int alsaStreamOpen(PDRVHSTAUDALSA pThis, snd_pcm_format_t enmAlsaFmt, PCPDMAUDIOSTREAMCFG pCfgReq,
    620622                          PPDMAUDIOSTREAMCFG pCfgAcq, snd_pcm_t **phPCM)
    621623{
     
    665667        else
    666668            LogRel(("ALSA: Error setting non-blocking mode for %s stream: %s\n", pszType, snd_strerror(err)));
    667         alsaStreamClose(&hPCM);
     669        drvHstAudAlsaStreamClose(&hPCM);
    668670    }
    669671    else
     
    677679 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
    678680 */
    679 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
    680                                                          PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    681 {
    682     PDRVHOSTALSAAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVHOSTALSAAUDIO, IHostAudio);
     681static DECLCALLBACK(int) drvHstAudAlsaHA_StreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
     682                                                      PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     683{
     684    PDRVHSTAUDALSA pThis = RT_FROM_MEMBER(pInterface, DRVHSTAUDALSA, IHostAudio);
    683685    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    684686    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     
    686688    AssertPtrReturn(pCfgAcq,    VERR_INVALID_POINTER);
    687689
    688     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     690    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    689691    PDMAudioStrmCfgCopy(&pStreamALSA->Cfg, pCfgReq);
    690692
     
    717719 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
    718720 */
    719 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
    720                                                           bool fImmediate)
     721static DECLCALLBACK(int) drvHstAudAlsaHA_StreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, bool fImmediate)
    721722{
    722723    RT_NOREF(pInterface);
    723     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     724    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    724725    AssertPtrReturn(pStreamALSA, VERR_INVALID_POINTER);
    725726    RT_NOREF(fImmediate);
     
    727728    /** @todo r=bird: It's not like we can do much with a bad status... Check
    728729     *        what the caller does... */
    729     return alsaStreamClose(&pStreamALSA->hPCM);
     730    return drvHstAudAlsaStreamClose(&pStreamALSA->hPCM);
    730731}
    731732
     
    734735 * @ interface_method_impl{PDMIHOSTAUDIO,pfnStreamEnable}
    735736 */
    736 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamEnable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     737static DECLCALLBACK(int) drvHstAudAlsaHA_StreamEnable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    737738{
    738739    RT_NOREF(pInterface);
    739     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     740    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    740741
    741742    /*
     
    778779 * @ interface_method_impl{PDMIHOSTAUDIO,pfnStreamDisable}
    779780 */
    780 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamDisable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     781static DECLCALLBACK(int) drvHstAudAlsaHA_StreamDisable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    781782{
    782783    RT_NOREF(pInterface);
    783     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     784    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    784785
    785786    int rc = snd_pcm_drop(pStreamALSA->hPCM);
     
    799800 * @ interface_method_impl{PDMIHOSTAUDIO,pfnStreamPause}
    800801 */
    801 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamPause(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     802static DECLCALLBACK(int) drvHstAudAlsaHA_StreamPause(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    802803{
    803804    /* Same as disable. */
    804805    /** @todo r=bird: Try use pause and fallback on disable/enable if it isn't
    805806     *        supported or doesn't work. */
    806     return drvHostAlsaAudioHA_StreamDisable(pInterface, pStream);
     807    return drvHstAudAlsaHA_StreamDisable(pInterface, pStream);
    807808}
    808809
     
    811812 * @ interface_method_impl{PDMIHOSTAUDIO,pfnStreamResume}
    812813 */
    813 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamResume(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     814static DECLCALLBACK(int) drvHstAudAlsaHA_StreamResume(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    814815{
    815816    /* Same as enable. */
    816     return drvHostAlsaAudioHA_StreamEnable(pInterface, pStream);
     817    return drvHstAudAlsaHA_StreamEnable(pInterface, pStream);
    817818}
    818819
     
    821822 * @ interface_method_impl{PDMIHOSTAUDIO,pfnStreamDrain}
    822823 */
    823 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamDrain(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     824static DECLCALLBACK(int) drvHstAudAlsaHA_StreamDrain(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    824825{
    825826    RT_NOREF(pInterface);
    826     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     827    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    827828
    828829    snd_pcm_state_t const enmState = snd_pcm_state(pStreamALSA->hPCM);
     
    880881 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
    881882 */
    882 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamControl(PPDMIHOSTAUDIO pInterface,
    883                                                           PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
     883static DECLCALLBACK(int) drvHstAudAlsaHA_StreamControl(PPDMIHOSTAUDIO pInterface,
     884                                                       PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
    884885{
    885886    /** @todo r=bird: I'd like to get rid of this pfnStreamControl method,
     
    890891    {
    891892        case PDMAUDIOSTREAMCMD_ENABLE:
    892             return drvHostAlsaAudioHA_StreamEnable(pInterface, pStream);
     893            return drvHstAudAlsaHA_StreamEnable(pInterface, pStream);
    893894        case PDMAUDIOSTREAMCMD_DISABLE:
    894             return drvHostAlsaAudioHA_StreamDisable(pInterface, pStream);
     895            return drvHstAudAlsaHA_StreamDisable(pInterface, pStream);
    895896        case PDMAUDIOSTREAMCMD_PAUSE:
    896             return drvHostAlsaAudioHA_StreamPause(pInterface, pStream);
     897            return drvHstAudAlsaHA_StreamPause(pInterface, pStream);
    897898        case PDMAUDIOSTREAMCMD_RESUME:
    898             return drvHostAlsaAudioHA_StreamResume(pInterface, pStream);
     899            return drvHstAudAlsaHA_StreamResume(pInterface, pStream);
    899900        case PDMAUDIOSTREAMCMD_DRAIN:
    900             return drvHostAlsaAudioHA_StreamDrain(pInterface, pStream);
     901            return drvHstAudAlsaHA_StreamDrain(pInterface, pStream);
    901902
    902903        case PDMAUDIOSTREAMCMD_END:
     
    936937    if (cFramesAvail == -EPIPE)
    937938    {
    938         rc = alsaStreamRecover(hPCM);
     939        rc = drvHstAudAlsaStreamRecover(hPCM);
    939940        if (RT_SUCCESS(rc))
    940941        {
     
    964965 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable}
    965966 */
    966 static DECLCALLBACK(uint32_t) drvHostAlsaAudioHA_StreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     967static DECLCALLBACK(uint32_t) drvHstAudAlsaHA_StreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    967968{
    968969    RT_NOREF(pInterface);
    969     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     970    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    970971
    971972    uint32_t          cbAvail      = 0;
     
    982983 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable}
    983984 */
    984 static DECLCALLBACK(uint32_t) drvHostAlsaAudioHA_StreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     985static DECLCALLBACK(uint32_t) drvHstAudAlsaHA_StreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    985986{
    986987    RT_NOREF(pInterface);
    987     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     988    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    988989
    989990    uint32_t          cbAvail      = 0;
     
    10001001 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetPending}
    10011002 */
    1002 static DECLCALLBACK(uint32_t) drvHostAlsaAudioHA_StreamGetPending(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
     1003static DECLCALLBACK(uint32_t) drvHstAudAlsaHA_StreamGetPending(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
    10031004{
    10041005    RT_NOREF(pInterface);
    1005     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     1006    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    10061007    AssertPtrReturn(pStreamALSA, 0);
    10071008
     
    10581059 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetState}
    10591060 */
    1060 static DECLCALLBACK(PDMHOSTAUDIOSTREAMSTATE) drvHostAlsaAudioHA_StreamGetState(PPDMIHOSTAUDIO pInterface,
    1061                                                                                PPDMAUDIOBACKENDSTREAM pStream)
     1061static DECLCALLBACK(PDMHOSTAUDIOSTREAMSTATE) drvHstAudAlsaHA_StreamGetState(PPDMIHOSTAUDIO pInterface,
     1062                                                                            PPDMAUDIOBACKENDSTREAM pStream)
    10621063{
    10631064    RT_NOREF(pInterface);
    1064     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     1065    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    10651066    AssertPtrReturn(pStreamALSA, PDMHOSTAUDIOSTREAMSTATE_INVALID);
    10661067
     
    10911092
    10921093/**
     1094 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
     1095 */
     1096static DECLCALLBACK(int) drvHstAudAlsaHA_StreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
     1097                                                    const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
     1098{
     1099    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
     1100    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     1101    AssertPtrReturn(pStream, VERR_INVALID_POINTER);
     1102    AssertPtrReturn(pcbWritten, VERR_INVALID_POINTER);
     1103    Log4Func(("@%#RX64: pvBuf=%p cbBuf=%#x (%u) state=%s - %s\n", pStreamALSA->offInternal, pvBuf, cbBuf, cbBuf,
     1104              snd_pcm_state_name(snd_pcm_state(pStreamALSA->hPCM)), pStreamALSA->Cfg.szName));
     1105    if (cbBuf)
     1106        AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
     1107    else
     1108    {
     1109        /* Fend off draining calls. */
     1110        *pcbWritten = 0;
     1111        return VINF_SUCCESS;
     1112    }
     1113
     1114    /*
     1115     * Determine how much we can write (caller actually did this
     1116     * already, but we repeat it just to be sure or something).
     1117     */
     1118    snd_pcm_sframes_t cFramesAvail;
     1119    int rc = alsaStreamGetAvail(pStreamALSA->hPCM, &cFramesAvail);
     1120    if (RT_SUCCESS(rc))
     1121    {
     1122        Assert(cFramesAvail);
     1123        if (cFramesAvail)
     1124        {
     1125            PCPDMAUDIOPCMPROPS pProps    = &pStreamALSA->Cfg.Props;
     1126            uint32_t           cbToWrite = PDMAudioPropsFramesToBytes(pProps, (uint32_t)cFramesAvail);
     1127            if (cbToWrite)
     1128            {
     1129                if (cbToWrite > cbBuf)
     1130                    cbToWrite = cbBuf;
     1131
     1132                /*
     1133                 * Try write the data.
     1134                 */
     1135                uint32_t cFramesToWrite = PDMAudioPropsBytesToFrames(pProps, cbToWrite);
     1136                snd_pcm_sframes_t cFramesWritten = snd_pcm_writei(pStreamALSA->hPCM, pvBuf, cFramesToWrite);
     1137                if (cFramesWritten > 0)
     1138                {
     1139                    Log4Func(("snd_pcm_writei w/ cbToWrite=%u -> %ld (frames) [cFramesAvail=%ld]\n",
     1140                              cbToWrite, cFramesWritten, cFramesAvail));
     1141                    *pcbWritten = PDMAudioPropsFramesToBytes(pProps, cFramesWritten);
     1142                    pStreamALSA->offInternal += *pcbWritten;
     1143                    return VINF_SUCCESS;
     1144                }
     1145                LogFunc(("snd_pcm_writei w/ cbToWrite=%u -> %ld [cFramesAvail=%ld]\n", cbToWrite, cFramesWritten, cFramesAvail));
     1146
     1147
     1148                /*
     1149                 * There are a couple of error we can recover from, try to do so.
     1150                 * Only don't try too many times.
     1151                 */
     1152                for (unsigned iTry = 0;
     1153                     (cFramesWritten == -EPIPE || cFramesWritten == -ESTRPIPE) && iTry < ALSA_RECOVERY_TRIES_MAX;
     1154                     iTry++)
     1155                {
     1156                    if (cFramesWritten == -EPIPE)
     1157                    {
     1158                        /* Underrun occurred. */
     1159                        rc = drvHstAudAlsaStreamRecover(pStreamALSA->hPCM);
     1160                        if (RT_FAILURE(rc))
     1161                            break;
     1162                        LogFlowFunc(("Recovered from playback (iTry=%u)\n", iTry));
     1163                    }
     1164                    else
     1165                    {
     1166                        /* An suspended event occurred, needs resuming. */
     1167                        rc = drvHstAudAlsaStreamResume(pStreamALSA->hPCM);
     1168                        if (RT_FAILURE(rc))
     1169                        {
     1170                            LogRel(("ALSA: Failed to resume output stream (iTry=%u, rc=%Rrc)\n", iTry, rc));
     1171                            break;
     1172                        }
     1173                        LogFlowFunc(("Resumed suspended output stream (iTry=%u)\n", iTry));
     1174                    }
     1175
     1176                    cFramesWritten = snd_pcm_writei(pStreamALSA->hPCM, pvBuf, cFramesToWrite);
     1177                    if (cFramesWritten > 0)
     1178                    {
     1179                        Log4Func(("snd_pcm_writei w/ cbToWrite=%u -> %ld (frames) [cFramesAvail=%ld]\n",
     1180                                  cbToWrite, cFramesWritten, cFramesAvail));
     1181                        *pcbWritten = PDMAudioPropsFramesToBytes(pProps, cFramesWritten);
     1182                        pStreamALSA->offInternal += *pcbWritten;
     1183                        return VINF_SUCCESS;
     1184                    }
     1185                    LogFunc(("snd_pcm_writei w/ cbToWrite=%u -> %ld [cFramesAvail=%ld, iTry=%d]\n", cbToWrite, cFramesWritten, cFramesAvail, iTry));
     1186                }
     1187
     1188                /* Make sure we return with an error status. */
     1189                if (RT_SUCCESS_NP(rc))
     1190                {
     1191                    if (cFramesWritten == 0)
     1192                        rc = VERR_ACCESS_DENIED;
     1193                    else
     1194                    {
     1195                        rc = RTErrConvertFromErrno(-(int)cFramesWritten);
     1196                        LogFunc(("Failed to write %RU32 bytes: %ld (%Rrc)\n", cbToWrite, cFramesWritten, rc));
     1197                    }
     1198                }
     1199            }
     1200        }
     1201    }
     1202    else
     1203        LogFunc(("Error getting number of playback frames, rc=%Rrc\n", rc));
     1204    *pcbWritten = 0;
     1205    return rc;
     1206}
     1207
     1208
     1209/**
    10931210 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
    10941211 */
    1095 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
    1096                                                           void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
     1212static DECLCALLBACK(int) drvHstAudAlsaHA_StreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
     1213                                                       void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
    10971214{
    10981215    RT_NOREF_PV(pInterface);
    1099     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
     1216    PDRVHSTAUDALSASTREAM pStreamALSA = (PDRVHSTAUDALSASTREAM)pStream;
    11001217    AssertPtrReturn(pStreamALSA, VERR_INVALID_POINTER);
    11011218    AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
     
    11241241
    11251242                case SND_PCM_STATE_SUSPENDED:
    1126                     rc = alsaStreamResume(pStreamALSA->hPCM);
     1243                    rc = drvHstAudAlsaStreamResume(pStreamALSA->hPCM);
    11271244                    if (RT_SUCCESS(rc))
    11281245                    {
     
    11901307            if (cFramesRead == -EPIPE)
    11911308            {
    1192                 rc = alsaStreamRecover(pStreamALSA->hPCM);
     1309                rc = drvHstAudAlsaStreamRecover(pStreamALSA->hPCM);
    11931310                if (RT_SUCCESS(rc))
    11941311                {
     
    12241341}
    12251342
    1226 /**
    1227  * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
    1228  */
    1229 static DECLCALLBACK(int) drvHostAlsaAudioHA_StreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
    1230                                                        const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
    1231 {
    1232     PALSAAUDIOSTREAM pStreamALSA = (PALSAAUDIOSTREAM)pStream;
    1233     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1234     AssertPtrReturn(pStream, VERR_INVALID_POINTER);
    1235     AssertPtrReturn(pcbWritten, VERR_INVALID_POINTER);
    1236     Log4Func(("@%#RX64: pvBuf=%p cbBuf=%#x (%u) state=%s - %s\n", pStreamALSA->offInternal, pvBuf, cbBuf, cbBuf,
    1237               snd_pcm_state_name(snd_pcm_state(pStreamALSA->hPCM)), pStreamALSA->Cfg.szName));
    1238     if (cbBuf)
    1239         AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
    1240     else
    1241     {
    1242         /* Fend off draining calls. */
    1243         *pcbWritten = 0;
    1244         return VINF_SUCCESS;
    1245     }
    1246 
    1247     /*
    1248      * Determine how much we can write (caller actually did this
    1249      * already, but we repeat it just to be sure or something).
    1250      */
    1251     snd_pcm_sframes_t cFramesAvail;
    1252     int rc = alsaStreamGetAvail(pStreamALSA->hPCM, &cFramesAvail);
    1253     if (RT_SUCCESS(rc))
    1254     {
    1255         Assert(cFramesAvail);
    1256         if (cFramesAvail)
    1257         {
    1258             PCPDMAUDIOPCMPROPS pProps    = &pStreamALSA->Cfg.Props;
    1259             uint32_t           cbToWrite = PDMAudioPropsFramesToBytes(pProps, (uint32_t)cFramesAvail);
    1260             if (cbToWrite)
    1261             {
    1262                 if (cbToWrite > cbBuf)
    1263                     cbToWrite = cbBuf;
    1264 
    1265                 /*
    1266                  * Try write the data.
    1267                  */
    1268                 uint32_t cFramesToWrite = PDMAudioPropsBytesToFrames(pProps, cbToWrite);
    1269                 snd_pcm_sframes_t cFramesWritten = snd_pcm_writei(pStreamALSA->hPCM, pvBuf, cFramesToWrite);
    1270                 if (cFramesWritten > 0)
    1271                 {
    1272                     Log4Func(("snd_pcm_writei w/ cbToWrite=%u -> %ld (frames) [cFramesAvail=%ld]\n",
    1273                               cbToWrite, cFramesWritten, cFramesAvail));
    1274                     *pcbWritten = PDMAudioPropsFramesToBytes(pProps, cFramesWritten);
    1275                     pStreamALSA->offInternal += *pcbWritten;
    1276                     return VINF_SUCCESS;
    1277                 }
    1278                 LogFunc(("snd_pcm_writei w/ cbToWrite=%u -> %ld [cFramesAvail=%ld]\n", cbToWrite, cFramesWritten, cFramesAvail));
    1279 
    1280 
    1281                 /*
    1282                  * There are a couple of error we can recover from, try to do so.
    1283                  * Only don't try too many times.
    1284                  */
    1285                 for (unsigned iTry = 0;
    1286                      (cFramesWritten == -EPIPE || cFramesWritten == -ESTRPIPE) && iTry < ALSA_RECOVERY_TRIES_MAX;
    1287                      iTry++)
    1288                 {
    1289                     if (cFramesWritten == -EPIPE)
    1290                     {
    1291                         /* Underrun occurred. */
    1292                         rc = alsaStreamRecover(pStreamALSA->hPCM);
    1293                         if (RT_FAILURE(rc))
    1294                             break;
    1295                         LogFlowFunc(("Recovered from playback (iTry=%u)\n", iTry));
    1296                     }
    1297                     else
    1298                     {
    1299                         /* An suspended event occurred, needs resuming. */
    1300                         rc = alsaStreamResume(pStreamALSA->hPCM);
    1301                         if (RT_FAILURE(rc))
    1302                         {
    1303                             LogRel(("ALSA: Failed to resume output stream (iTry=%u, rc=%Rrc)\n", iTry, rc));
    1304                             break;
    1305                         }
    1306                         LogFlowFunc(("Resumed suspended output stream (iTry=%u)\n", iTry));
    1307                     }
    1308 
    1309                     cFramesWritten = snd_pcm_writei(pStreamALSA->hPCM, pvBuf, cFramesToWrite);
    1310                     if (cFramesWritten > 0)
    1311                     {
    1312                         Log4Func(("snd_pcm_writei w/ cbToWrite=%u -> %ld (frames) [cFramesAvail=%ld]\n",
    1313                                   cbToWrite, cFramesWritten, cFramesAvail));
    1314                         *pcbWritten = PDMAudioPropsFramesToBytes(pProps, cFramesWritten);
    1315                         pStreamALSA->offInternal += *pcbWritten;
    1316                         return VINF_SUCCESS;
    1317                     }
    1318                     LogFunc(("snd_pcm_writei w/ cbToWrite=%u -> %ld [cFramesAvail=%ld, iTry=%d]\n", cbToWrite, cFramesWritten, cFramesAvail, iTry));
    1319                 }
    1320 
    1321                 /* Make sure we return with an error status. */
    1322                 if (RT_SUCCESS_NP(rc))
    1323                 {
    1324                     if (cFramesWritten == 0)
    1325                         rc = VERR_ACCESS_DENIED;
    1326                     else
    1327                     {
    1328                         rc = RTErrConvertFromErrno(-(int)cFramesWritten);
    1329                         LogFunc(("Failed to write %RU32 bytes: %ld (%Rrc)\n", cbToWrite, cFramesWritten, rc));
    1330                     }
    1331                 }
    1332             }
    1333         }
    1334     }
    1335     else
    1336         LogFunc(("Error getting number of playback frames, rc=%Rrc\n", rc));
    1337     *pcbWritten = 0;
    1338     return rc;
    1339 }
    1340 
    13411343
    13421344/**
    13431345 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
    13441346 */
    1345 static DECLCALLBACK(void *) drvHostAlsaAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    1346 {
    1347     PPDMDRVINS        pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
    1348     PDRVHOSTALSAAUDIO pThis   = PDMINS_2_DATA(pDrvIns, PDRVHOSTALSAAUDIO);
     1347static DECLCALLBACK(void *) drvHstAudAlsaQueryInterface(PPDMIBASE pInterface, const char *pszIID)
     1348{
     1349    PPDMDRVINS     pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
     1350    PDRVHSTAUDALSA pThis   = PDMINS_2_DATA(pDrvIns, PDRVHSTAUDALSA);
    13491351    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    13501352    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
     
    13591361 * @copydoc FNPDMDRVCONSTRUCT
    13601362 */
    1361 static DECLCALLBACK(int) drvHostAlsaAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
     1363static DECLCALLBACK(int) drvHstAudAlsaConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
    13621364{
    13631365    RT_NOREF(fFlags);
    13641366    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
    1365     PDRVHOSTALSAAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTALSAAUDIO);
     1367    PDRVHSTAUDALSA pThis = PDMINS_2_DATA(pDrvIns, PDRVHSTAUDALSA);
    13661368    LogRel(("Audio: Initializing ALSA driver\n"));
    13671369
     
    13711373    pThis->pDrvIns                   = pDrvIns;
    13721374    /* IBase */
    1373     pDrvIns->IBase.pfnQueryInterface = drvHostAlsaAudioQueryInterface;
     1375    pDrvIns->IBase.pfnQueryInterface = drvHstAudAlsaQueryInterface;
    13741376    /* IHostAudio */
    1375     pThis->IHostAudio.pfnGetConfig                  = drvHostAlsaAudioHA_GetConfig;
    1376     pThis->IHostAudio.pfnGetDevices                 = drvHostAlsaAudioHA_GetDevices;
     1377    pThis->IHostAudio.pfnGetConfig                  = drvHstAudAlsaHA_GetConfig;
     1378    pThis->IHostAudio.pfnGetDevices                 = drvHstAudAlsaHA_GetDevices;
    13771379    pThis->IHostAudio.pfnSetDevice                  = NULL;
    1378     pThis->IHostAudio.pfnGetStatus                  = drvHostAlsaAudioHA_GetStatus;
     1380    pThis->IHostAudio.pfnGetStatus                  = drvHstAudAlsaHA_GetStatus;
    13791381    pThis->IHostAudio.pfnDoOnWorkerThread           = NULL;
    13801382    pThis->IHostAudio.pfnStreamConfigHint           = NULL;
    1381     pThis->IHostAudio.pfnStreamCreate               = drvHostAlsaAudioHA_StreamCreate;
     1383    pThis->IHostAudio.pfnStreamCreate               = drvHstAudAlsaHA_StreamCreate;
    13821384    pThis->IHostAudio.pfnStreamInitAsync            = NULL;
    1383     pThis->IHostAudio.pfnStreamDestroy              = drvHostAlsaAudioHA_StreamDestroy;
     1385    pThis->IHostAudio.pfnStreamDestroy              = drvHstAudAlsaHA_StreamDestroy;
    13841386    pThis->IHostAudio.pfnStreamNotifyDeviceChanged  = NULL;
    1385     pThis->IHostAudio.pfnStreamControl              = drvHostAlsaAudioHA_StreamControl;
    1386     pThis->IHostAudio.pfnStreamGetReadable          = drvHostAlsaAudioHA_StreamGetReadable;
    1387     pThis->IHostAudio.pfnStreamGetWritable          = drvHostAlsaAudioHA_StreamGetWritable;
    1388     pThis->IHostAudio.pfnStreamGetPending           = drvHostAlsaAudioHA_StreamGetPending;
    1389     pThis->IHostAudio.pfnStreamGetState             = drvHostAlsaAudioHA_StreamGetState;
    1390     pThis->IHostAudio.pfnStreamPlay                 = drvHostAlsaAudioHA_StreamPlay;
    1391     pThis->IHostAudio.pfnStreamCapture              = drvHostAlsaAudioHA_StreamCapture;
     1387    pThis->IHostAudio.pfnStreamControl              = drvHstAudAlsaHA_StreamControl;
     1388    pThis->IHostAudio.pfnStreamGetReadable          = drvHstAudAlsaHA_StreamGetReadable;
     1389    pThis->IHostAudio.pfnStreamGetWritable          = drvHstAudAlsaHA_StreamGetWritable;
     1390    pThis->IHostAudio.pfnStreamGetPending           = drvHstAudAlsaHA_StreamGetPending;
     1391    pThis->IHostAudio.pfnStreamGetState             = drvHstAudAlsaHA_StreamGetState;
     1392    pThis->IHostAudio.pfnStreamPlay                 = drvHstAudAlsaHA_StreamPlay;
     1393    pThis->IHostAudio.pfnStreamCapture              = drvHstAudAlsaHA_StreamCapture;
    13921394
    13931395    /*
     
    14111413    }
    14121414#ifdef DEBUG
    1413     snd_lib_error_set_handler(alsaDbgErrorHandler);
     1415    snd_lib_error_set_handler(drvHstAudAlsaDbgErrorHandler);
    14141416#endif
    14151417    return VINF_SUCCESS;
     
    14391441    ~0U,
    14401442    /* cbInstance */
    1441     sizeof(DRVHOSTALSAAUDIO),
     1443    sizeof(DRVHSTAUDALSA),
    14421444    /* pfnConstruct */
    1443     drvHostAlsaAudioConstruct,
     1445    drvHstAudAlsaConstruct,
    14441446    /* pfnDestruct */
    14451447    NULL,
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