VirtualBox

Changeset 68468 in vbox


Ignore:
Timestamp:
Aug 18, 2017 1:57:08 PM (7 years ago)
Author:
vboxsync
Message:

Audio: Cleaned up callback stuff and got rid of the deprecated VBOX_WITH_AUDIO_DEVICE_CALLBACKS define. A bit of renaming and documentation to make things more clear.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r68402 r68468  
    933933
    934934/**
    935  * Audio callback types.
    936  * Those callbacks are being sent from the backends to the audio connector.
    937  */
    938 typedef enum PDMAUDIOCBTYPE
     935 * Enumeration for an audio callback source.
     936 */
     937typedef enum PDMAUDIOCBSOURCE
    939938{
    940939    /** Invalid, do not use. */
    941     PDMAUDIOCBTYPE_INVALID = 0,
    942     /** The backend's status has changed. */
    943     PDMAUDIOCBTYPE_STATUS,
    944     /** One or more host audio devices have changed. */
    945     PDMAUDIOCBTYPE_DEVICES_CHANGED,
     940    PDMAUDIOCBSOURCE_INVALID    = 0,
     941    /** Device emulation. */
     942    PDMAUDIOCBSOURCE_DEVICE     = 1,
     943    /** Audio connector interface. */
     944    PDMAUDIOCBSOURCE_CONNECTOR  = 2,
     945    /** Backend (lower). */
     946    PDMAUDIOCBSOURCE_BACKEND    = 3,
     947    /** Hack to blow the type up to 32-bit. */
     948    PDMAUDIOCBSOURCE_32BIT_HACK = 0x7fffffff
     949} PDMAUDIOCBSOURCE;
     950
     951/**
     952 * Audio device callback types.
     953 * Those callbacks are being sent from the audio connector ->  device emulation.
     954 */
     955typedef enum PDMAUDIODEVICECBTYPE
     956{
     957    /** Invalid, do not use. */
     958    PDMAUDIODEVICECBTYPE_INVALID = 0,
    946959    /** Data is availabe as input for passing to the device emulation. */
    947     PDMAUDIOCBTYPE_DATA_INPUT,
     960    PDMAUDIODEVICECBTYPE_DATA_INPUT,
    948961    /** Free data for the device emulation to write to the backend. */
    949     PDMAUDIOCBTYPE_DATA_OUTPUT
    950 } PDMAUDIOCBTYPE;
    951 
    952 /**
    953  * Callback data for audio input.
    954  */
    955 typedef struct PDMAUDIOCBDATA_DATA_INPUT
     962    PDMAUDIODEVICECBTYPE_DATA_OUTPUT,
     963    /** Hack to blow the type up to 32-bit. */
     964    PDMAUDIODEVICECBTYPE_32BIT_HACK = 0x7fffffff
     965} PDMAUDIODEVICECBTYPE;
     966
     967/**
     968 * Device callback data for audio input.
     969 */
     970typedef struct PDMAUDIODEVICECBDATA_DATA_INPUT
    956971{
    957972    /** Input: How many bytes are availabe as input for passing
     
    960975    /** Output: How many bytes have been read. */
    961976    uint32_t cbOutRead;
    962 } PDMAUDIOCBDATA_DATA_INPUT, *PPDMAUDIOCBDATA_DATA_INPUT;
    963 
    964 /**
    965  * Callback data for audio output.
    966  */
    967 typedef struct PDMAUDIOCBDATA_DATA_OUTPUT
     977} PDMAUDIODEVICECBDATA_DATA_INPUT, *PPDMAUDIODEVICECBDATA_DATA_INPUT;
     978
     979/**
     980 * Device callback data for audio output.
     981 */
     982typedef struct PDMAUDIODEVICECBDATA_DATA_OUTPUT
    968983{
    969984    /** Input:  How many bytes are free for the device emulation to write. */
     
    971986    /** Output: How many bytes were written by the device emulation. */
    972987    uint32_t cbOutWritten;
    973 } PDMAUDIOCBDATA_DATA_OUTPUT, *PPDMAUDIOCBDATA_DATA_OUTPUT;
     988} PDMAUDIODEVICECBDATA_DATA_OUTPUT, *PPDMAUDIODEVICECBDATA_DATA_OUTPUT;
     989
     990/**
     991 * Audio backend callback types.
     992 * Those callbacks are being sent from the backend -> audio connector.
     993 */
     994typedef enum PDMAUDIOBACKENDCBTYPE
     995{
     996    /** Invalid, do not use. */
     997    PDMAUDIOBACKENDCBTYPE_INVALID = 0,
     998    /** The backend's status has changed. */
     999    PDMAUDIOBACKENDCBTYPE_STATUS,
     1000    /** One or more host audio devices have changed. */
     1001    PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED,
     1002    /** Hack to blow the type up to 32-bit. */
     1003    PDMAUDIOBACKENDCBTYPE_32BIT_HACK = 0x7fffffff
     1004} PDMAUDIOBACKENDCBTYPE;
    9741005
    9751006/** Pointer to a host audio interface. */
     
    9771008
    9781009/**
    979  * Host audio (backend) callback function.
     1010 * Host audio callback function.
     1011 * This function will be called from a backend to communicate with the host audio interface.
    9801012 *
    9811013 * @returns IPRT status code.
     
    9851017 * @param   cbUser              Size (in bytes) of user argument.
    9861018 */
    987 typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser);
     1019typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOBACKENDCBTYPE enmType, void *pvUser, size_t cbUser);
    9881020/** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
    9891021typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
    9901022
    991 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
    992 /**
    993  * Structure for keeping a registered audio callback around.
    994  */
    995 typedef struct PDMAUDIOCALLBACK
     1023/**
     1024 * Audio callback registration record.
     1025 */
     1026typedef struct PDMAUDIOCBRECORD
    9961027{
    9971028    /** List node. */
    9981029    RTLISTANCHOR        Node;
    999     /** Callback type. */
    1000     PDMAUDIOCBTYPE      enmType;
     1030    /** Callback source. */
     1031    PDMAUDIOCBSOURCE    enmSource;
     1032    /** Callback type, based on the given source. */
     1033    union
     1034    {
     1035        /** Device callback stuff. */
     1036        struct
     1037        {
     1038            PDMAUDIODEVICECBTYPE enmType;
     1039        } Device;
     1040    };
    10011041    /** Pointer to context data. Optional. */
    10021042    void               *pvCtx;
     
    10041044     *  Must be 0 if pvCtx is NULL. */
    10051045    size_t              cbCtx;
    1006     /** Actual callback function to call. */
    1007     PFNPDMAUDIOCALLBACK pFn;
    1008 } PDMAUDIOCALLBACK, *PPDMAUDIOCALLBACK;
    1009 #endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */
     1046} PDMAUDIOCBRECORD, *PPDMAUDIOCBRECORD;
    10101047
    10111048#define PPDMAUDIOBACKENDSTREAM void *
     
    11711208    DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured));
    11721209
    1173 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
    1174     DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCALLBACK paCallbacks, size_t cCallbacks));
    1175     DECLR3CALLBACKMEMBER(int, pfnCallback, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser));
    1176 #endif
     1210    /**
     1211     * Registers (device) callbacks.
     1212     * This is handy for letting the device emulation know of certain events, e.g. processing input / output data
     1213     * or configuration changes.
     1214     *
     1215     * @returns VBox status code.
     1216     * @param   pInterface           Pointer to the interface structure containing the called function pointer.
     1217     * @param   paCallbacks          Pointer to array of callbacks to register.
     1218     * @param   cCallbacks           Number of callbacks to register.
     1219     */
     1220    DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCBRECORD paCallbacks, size_t cCallbacks));
    11771221
    11781222} PDMIAUDIOCONNECTOR;
    11791223
    11801224/** PDMIAUDIOCONNECTOR interface ID. */
    1181 #define PDMIAUDIOCONNECTOR_IID                  "FF2044D1-F8D9-4F42-BE9E-0E9AD14F4552"
     1225#define PDMIAUDIOCONNECTOR_IID                  "344ABC57-659E-4B21-8C25-69ED9FAD490D"
    11821226
    11831227/**
  • trunk/src/VBox/Devices/Audio/DevHDA.cpp

    r68389 r68468  
    26492649#else /* VBOX_WITH_AUDIO_HDA_CALLBACKS */
    26502650
    2651 static DECLCALLBACK(int) hdaCallbackInput(PDMAUDIOCBTYPE enmType, void *pvCtx, size_t cbCtx, void *pvUser, size_t cbUser)
     2651static DECLCALLBACK(int) hdaCallbackInput(PDMAUDIOBACKENDCBTYPE enmType, void *pvCtx, size_t cbCtx, void *pvUser, size_t cbUser)
    26522652{
    26532653    Assert(enmType == PDMAUDIOCALLBACKTYPE_INPUT);
     
    26662666}
    26672667
    2668 static DECLCALLBACK(int) hdaCallbackOutput(PDMAUDIOCBTYPE enmType, void *pvCtx, size_t cbCtx, void *pvUser, size_t cbUser)
     2668static DECLCALLBACK(int) hdaCallbackOutput(PDMAUDIOBACKENDCBTYPE enmType, void *pvCtx, size_t cbCtx, void *pvUser, size_t cbUser)
    26692669{
    26702670    Assert(enmType == PDMAUDIOCALLBACKTYPE_OUTPUT);
     
    47714771                continue;
    47724772
    4773             PDMAUDIOCALLBACK AudioCallbacks[2];
     4773            PDMAUDIOCBRECORD AudioCallbacks[2];
    47744774
    47754775            HDACALLBACKCTX Ctx = { pThis, pDrv };
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r68415 r68468  
    36963696                continue;
    36973697
    3698             PDMAUDIOCALLBACK AudioCallbacks[2];
     3698            PDMAUDIOCBRECORD AudioCallbacks[2];
    36993699
    37003700            AC97CALLBACKCTX Ctx = { pThis, pDrv };
  • trunk/src/VBox/Devices/Audio/DevSB16.cpp

    r68389 r68468  
    25242524                continue;
    25252525
    2526             PDMAUDIOCALLBACK AudioCallbacks[2];
     2526            PDMAUDIOCBRECORD AudioCallbacks[2];
    25272527
    25282528            SB16CALLBACKCTX Ctx = { pThis, pDrv };
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r68387 r68468  
    18591859}
    18601860
    1861 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
     1861#ifdef VBOX_WITH_AUDIO_CALLBACKS
    18621862/**
    18631863 * Duplicates an audio callback.
     
    18661866 * @param   pCB                 Callback to duplicate.
    18671867 */
    1868 static PPDMAUDIOCALLBACK drvAudioCallbackDuplicate(PPDMAUDIOCALLBACK pCB)
     1868static PPDMAUDIOCBRECORD drvAudioCallbackDuplicate(PPDMAUDIOCBRECORD pCB)
    18691869{
    18701870    AssertPtrReturn(pCB, NULL);
    18711871
    1872     PPDMAUDIOCALLBACK pCBCopy = (PPDMAUDIOCALLBACK)RTMemDup((void *)pCB, sizeof(PDMAUDIOCALLBACK));
     1872    PPDMAUDIOCBRECORD pCBCopy = (PPDMAUDIOCBRECORD)RTMemDup((void *)pCB, sizeof(PDMAUDIOCBRECORD));
    18731873    if (!pCBCopy)
    18741874        return NULL;
     
    18941894 * @param   pCB                 Callback to destroy.
    18951895 */
    1896 static void drvAudioCallbackDestroy(PPDMAUDIOCALLBACK pCB)
     1896static void drvAudioCallbackDestroy(PPDMAUDIOCBRECORD pCB)
    18971897{
    18981898    if (!pCB)
     
    19121912 */
    19131913static DECLCALLBACK(int) drvAudioRegisterCallbacks(PPDMIAUDIOCONNECTOR pInterface,
    1914                                                    PPDMAUDIOCALLBACK paCallbacks, size_t cCallbacks)
     1914                                                   PPDMAUDIOCBRECORD paCallbacks, size_t cCallbacks)
    19151915{
    19161916    AssertPtrReturn(pInterface,  VERR_INVALID_POINTER);
     
    19261926    for (size_t i = 0; i < cCallbacks; i++)
    19271927    {
    1928         PPDMAUDIOCALLBACK pCB = drvAudioCallbackDuplicate(&paCallbacks[i]);
     1928        PPDMAUDIOCBRECORD pCB = drvAudioCallbackDuplicate(&paCallbacks[i]);
    19291929        if (!pCB)
    19301930        {
     
    19331933        }
    19341934
    1935         switch (pCB->enmType)
    1936         {
    1937             case PDMAUDIOCBTYPE_DATA_INPUT:
    1938                 RTListAppend(&pThis->lstCBIn, &pCB->Node);
     1935        switch (pCB->enmSource)
     1936        {
     1937            case PDMAUDIOCBSOURCE_DEVICE:
     1938            {
     1939                switch (pCB->Device.enmType)
     1940                {
     1941                    case PDMAUDIODEVICECBTYPE_DATA_INPUT:
     1942                        RTListAppend(&pThis->lstCBIn, &pCB->Node);
     1943                        break;
     1944
     1945                    case PDMAUDIODEVICECBTYPE_DATA_OUTPUT:
     1946                        RTListAppend(&pThis->lstCBOut, &pCB->Node);
     1947                        break;
     1948
     1949                    default:
     1950                        AssertMsgFailed(("Not supported\n"));
     1951                        break;
     1952                }
     1953
    19391954                break;
    1940 
    1941             case PDMAUDIOCBTYPE_DATA_OUTPUT:
    1942                 RTListAppend(&pThis->lstCBOut, &pCB->Node);
    1943                 break;
     1955            }
    19441956
    19451957            default:
    1946                 AssertMsgFailed(("Not supported\n"));
    1947                 break;
     1958               AssertMsgFailed(("Not supported\n"));
     1959               break;
    19481960        }
    19491961    }
     
    19571969    return rc;
    19581970}
    1959 
    1960 /**
    1961  * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnCallback}
    1962  */
    1963 static DECLCALLBACK(int) drvAudioCallback(PPDMIAUDIOCONNECTOR pInterface, PDMAUDIOCBTYPE enmType,
    1964                                           void *pvUser, size_t cbUser)
    1965 {
    1966     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    1967     AssertPtrReturn(pvUser,     VERR_INVALID_POINTER);
    1968     AssertReturn(cbUser,        VERR_INVALID_PARAMETER);
    1969 
    1970     PDRVAUDIO     pThis       = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
    1971     PRTLISTANCHOR pListAnchor = NULL;
    1972 
    1973     switch (enmType)
    1974     {
    1975         case PDMAUDIOCBTYPE_DATA_INPUT:
    1976             pListAnchor = &pThis->lstCBIn;
    1977             break;
    1978 
    1979         case PDMAUDIOCBTYPE_DATA_OUTPUT:
    1980             pListAnchor = &pThis->lstCBOut;
    1981             break;
    1982 
    1983         default:
    1984             AssertMsgFailed(("Not supported\n"));
    1985             break;
    1986     }
    1987 
    1988     if (pListAnchor)
    1989     {
    1990         PPDMAUDIOCALLBACK pCB;
    1991         RTListForEach(pListAnchor, pCB, PDMAUDIOCALLBACK, Node)
    1992         {
    1993             Assert(pCB->enmType == enmType);
    1994             int rc2 = pCB->pfnCallback(enmType, pCB->pvCtx, pCB->cbCtx, pvUser, cbUser);
    1995             if (RT_FAILURE(rc2))
    1996                 LogFunc(("Failed with %Rrc\n", rc2));
    1997         }
    1998 
    1999         return VINF_SUCCESS;
    2000     }
    2001 
    2002     return VERR_NOT_SUPPORTED;
    2003 }
    2004 #endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */
     1971#endif /* VBOX_WITH_AUDIO_CALLBACKS */
    20051972
    20061973#ifdef VBOX_WITH_AUDIO_CALLBACKS
     
    20151982 */
    20161983static DECLCALLBACK(int) drvAudioBackendCallback(PPDMDRVINS pDrvIns,
    2017                                                  PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser)
     1984                                                 PDMAUDIOBACKENDCBTYPE enmType, void *pvUser, size_t cbUser)
    20181985{
    20191986    AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
     
    20342001    switch (enmType)
    20352002    {
    2036         case PDMAUDIOCBTYPE_DEVICES_CHANGED:
     2003        case PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED:
    20372004            LogRel(("Audio: Host audio device configuration has changed\n"));
    20382005            rc = drvAudioScheduleReInitInternal(pThis);
     
    31793146    RTListInit(&pThis->lstHstStreams);
    31803147    RTListInit(&pThis->lstGstStreams);
    3181 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
     3148#ifdef VBOX_WITH_AUDIO_CALLBACKS
    31823149    RTListInit(&pThis->lstCBIn);
    31833150    RTListInit(&pThis->lstCBOut);
     
    32073174    pThis->IAudioConnector.pfnStreamPlay        = drvAudioStreamPlay;
    32083175    pThis->IAudioConnector.pfnStreamCapture     = drvAudioStreamCapture;
    3209 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
     3176#ifdef VBOX_WITH_AUDIO_CALLBACKS
    32103177    pThis->IAudioConnector.pfnRegisterCallbacks = drvAudioRegisterCallbacks;
    3211     pThis->IAudioConnector.pfnCallback          = drvAudioCallback;
    32123178#endif
    32133179
     
    33393305    Assert(RTListIsEmpty(&pThis->lstGstStreams));
    33403306
    3341 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
     3307#ifdef VBOX_WITH_AUDIO_CALLBACKS
    33423308    /*
    3343      * Destroy device callbacks, if any.
     3309     * Destroy callbacks, if any.
    33443310     */
    3345     PPDMAUDIOCALLBACK pCB, pCBNext;
    3346     RTListForEachSafe(&pThis->lstCBIn, pCB, pCBNext, PDMAUDIOCALLBACK, Node)
     3311    PPDMAUDIOCBRECORD pCB, pCBNext;
     3312    RTListForEachSafe(&pThis->lstCBIn, pCB, pCBNext, PDMAUDIOCBRECORD, Node)
    33473313        drvAudioCallbackDestroy(pCB);
    33483314
    3349     RTListForEachSafe(&pThis->lstCBOut, pCB, pCBNext, PDMAUDIOCALLBACK, Node)
     3315    RTListForEachSafe(&pThis->lstCBOut, pCB, pCBNext, PDMAUDIOCBRECORD, Node)
    33503316        drvAudioCallbackDestroy(pCB);
    33513317#endif
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r68136 r68468  
    121121    /** Audio configuration settings retrieved from the backend. */
    122122    PDMAUDIOBACKENDCFG      BackendCfg;
    123 #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
     123#ifdef VBOX_WITH_AUDIO_CALLBACKS
    124124    /** @todo Use a map with primary key set to the callback type? */
    125125    RTLISTANCHOR            lstCBIn;
  • trunk/src/VBox/Devices/Makefile.kmk

    r68233 r68468  
    591591 #                  tell the emulation when and how to process data.
    592592 if 0
    593   VBOX_DEFS   += VBOX_WITH_AUDIO_DEVICE_CALLBACKS
    594593  VBOX_DEFS   += VBOX_WITH_AUDIO_SB16_CALLBACKS
    595594  VBOX_DEFS   += VBOX_WITH_AUDIO_AC97_CALLBACKS
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