VirtualBox

Changeset 89541 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 7, 2021 9:26:07 AM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: More code for completely self-contained (self) testing. bugref:10008

Location:
trunk/src/VBox/Devices/Audio
Files:
8 edited

Legend:

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

    r89468 r89541  
    292292}
    293293
    294 
    295294/**
    296295 * Return the tag to use in the given buffer, generating one if needed.
     
    302301 * @param   pszTagUser          User specified tag, optional.
    303302 */
    304 int AudioTestCopyOrGenTag(char *pszTag, size_t cbTag, const char *pszTagUser)
     303static int audioTestCopyOrGenTag(char *pszTag, size_t cbTag, const char *pszTagUser)
    305304{
    306305    if (pszTagUser && *pszTagUser)
     
    325324{
    326325    char szTag[AUDIOTEST_TAG_MAX];
    327     int rc = AudioTestCopyOrGenTag(szTag, sizeof(szTag), pszTag);
     326    int rc = audioTestCopyOrGenTag(szTag, sizeof(szTag), pszTag);
    328327    AssertRCReturn(rc, rc);
    329328
     
    674673    audioTestSetInitInternal(pSet);
    675674
    676     int rc = AudioTestCopyOrGenTag(pSet->szTag, sizeof(pSet->szTag), pszTag);
     675    int rc = audioTestCopyOrGenTag(pSet->szTag, sizeof(pSet->szTag), pszTag);
    677676    AssertRCReturn(rc, rc);
    678677
  • trunk/src/VBox/Devices/Audio/AudioTest.h

    r89468 r89541  
    342342int    AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps);
    343343
     344int    AudioTestGenTag(char *pszTag, size_t cbTag);
     345
    344346int    AudioTestPathGetTemp(char *pszPath, size_t cbPath);
    345347int    AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszUUID);
  • trunk/src/VBox/Devices/Audio/AudioTestService.cpp

    r89458 r89541  
    143143    Log(("atsSendPkt: cb=%#x opcode=%.8s\n", pPkt->cb, pPkt->achOpcode));
    144144    Log2(("%.*Rhxd\n", RT_MIN(pPkt->cb, 256), pPkt));
    145     int rc = pThis->pTransport->pfnSendPkt(pClient->pTransportClient, pPkt);
     145    int rc = pThis->pTransport->pfnSendPkt(&pThis->TransportInst, pClient->pTransportClient, pPkt);
    146146    while (RT_UNLIKELY(rc == VERR_INTERRUPTED) && !pThis->fTerminate)
    147         rc = pThis->pTransport->pfnSendPkt(pClient->pTransportClient, pPkt);
     147        rc = pThis->pTransport->pfnSendPkt(&pThis->TransportInst, pClient->pTransportClient, pPkt);
    148148    if (RT_FAILURE(rc))
    149149        Log(("atsSendPkt: rc=%Rrc\n", rc));
     
    166166    memcpy(Reply.achOpcode, pszOpcode, sizeof(Reply.achOpcode));
    167167
    168     pThis->pTransport->pfnBabble(pClient->pTransportClient, &Reply, 20*1000);
     168    pThis->pTransport->pfnBabble(&pThis->TransportInst, pClient->pTransportClient, &Reply, 20*1000);
    169169}
    170170
     
    187187    {
    188188        PATSPKTHDR pPktHdr;
    189         int rc = pThis->pTransport->pfnRecvPkt(pClient->pTransportClient, &pPktHdr);
     189        int rc = pThis->pTransport->pfnRecvPkt(&pThis->TransportInst, pClient->pTransportClient, &pPktHdr);
    190190        if (RT_SUCCESS(rc))
    191191        {
     
    513513    if (RT_SUCCESS(rc))
    514514    {
    515         pThis->pTransport->pfnNotifyHowdy(pClient->pTransportClient);
     515        pThis->pTransport->pfnNotifyHowdy(&pThis->TransportInst, pClient->pTransportClient);
    516516        pClient->enmState = ATSCLIENTSTATE_READY;
    517517    }
     
    769769                                idxSlt++;
    770770
    771                             rc = pThis->pTransport->pfnPollSetAdd(pThis->hPollSet, pIt->pTransportClient, idxSlt + 1);
     771                            rc = pThis->pTransport->pfnPollSetAdd(&pThis->TransportInst, pThis->hPollSet, pIt->pTransportClient, idxSlt + 1);
    772772                            if (RT_SUCCESS(rc))
    773773                            {
     
    777777                            else
    778778                            {
    779                                 pThis->pTransport->pfnNotifyBye(pIt->pTransportClient);
     779                                pThis->pTransport->pfnNotifyBye(&pThis->TransportInst, pIt->pTransportClient);
    780780                                atsClientDestroy(pIt);
    781781                            }
     
    783783                        else
    784784                        {
    785                             pThis->pTransport->pfnNotifyBye(pIt->pTransportClient);
     785                            pThis->pTransport->pfnNotifyBye(&pThis->TransportInst, pIt->pTransportClient);
    786786                            atsClientDestroy(pIt);
    787787                        }
     
    801801                    {
    802802                        /* Close connection and remove client from array. */
    803                         rc = pThis->pTransport->pfnPollSetRemove(pThis->hPollSet, pClient->pTransportClient, uId);
     803                        rc = pThis->pTransport->pfnPollSetRemove(&pThis->TransportInst, pThis->hPollSet, pClient->pTransportClient, uId);
    804804                        AssertRC(rc);
    805805
    806                         pThis->pTransport->pfnNotifyBye(pClient->pTransportClient);
     806                        pThis->pTransport->pfnNotifyBye(&pThis->TransportInst, pClient->pTransportClient);
    807807                        papClients[uId - 1] = NULL;
    808808                        cClientsCur--;
     
    829829    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    830830
    831     int rc = VINF_SUCCESS;
     831    int rc = RTThreadUserSignal(hThread);
     832    AssertRCReturn(rc, rc);
    832833
    833834    while (!pThis->fTerminate)
     
    838839         */
    839840        PATSTRANSPORTCLIENT pTransportClient;
    840         rc = pThis->pTransport->pfnWaitForConnect(&pTransportClient);
     841        rc = pThis->pTransport->pfnWaitForConnect(&pThis->TransportInst, &pTransportClient);
    841842        if (RT_FAILURE(rc))
    842843            continue;
     
    866867        {
    867868            RTMsgError("Creating new client structure failed with out of memory error\n");
    868             pThis->pTransport->pfnNotifyBye(pTransportClient);
     869            pThis->pTransport->pfnNotifyBye(&pThis->TransportInst, pTransportClient);
    869870        }
    870871    }
     
    878879 * @returns VBox status code.
    879880 * @param   pThis               The ATS instance.
     881 * @param   pszBindAddr         Bind address. Empty means any address.
     882 *                              If set to NULL, "127.0.0.1" will be used.
     883 * @param   uBindPort           Bind port. If set to 0, ATS_DEFAULT_PORT is being used.
    880884 * @param   pCallbacks          The callbacks table to use.
    881885 *  */
    882 int AudioTestSvcInit(PATSSERVER pThis, PCATSCALLBACKS pCallbacks)
     886int AudioTestSvcInit(PATSSERVER pThis,
     887                     const char *pszBindAddr, uint32_t uBindPort, PCATSCALLBACKS pCallbacks)
    883888{
    884889    memcpy(&pThis->Callbacks, pCallbacks, sizeof(ATSCALLBACKS));
     
    896901     * Initialize the transport layer.
    897902     */
    898     int rc = pThis->pTransport->pfnInit();
     903    int rc = pThis->pTransport->pfnInit(&pThis->TransportInst, pszBindAddr ? pszBindAddr : "127.0.0.1",
     904                                         uBindPort ? uBindPort : ATS_TCP_DEFAULT_PORT);
    899905    if (RT_SUCCESS(rc))
    900906    {
     
    950956                            "AUDTSTSRVM");
    951957    if (RT_SUCCESS(rc))
    952         pThis->fStarted = true;
     958    {
     959        rc = RTThreadUserWait(pThis->hThreadMain, RT_MS_30SEC);
     960        if (RT_SUCCESS(rc))
     961            pThis->fStarted = true;
     962    }
    953963
    954964    return rc;
     
    969979
    970980    if (pThis->pTransport)
    971         pThis->pTransport->pfnTerm();
     981        pThis->pTransport->pfnTerm(&pThis->TransportInst);
    972982
    973983    size_t cbWritten;
  • trunk/src/VBox/Devices/Audio/AudioTestService.h

    r89458 r89541  
    2626
    2727/** Default TCP/IP port the ATS (Audio Test Service) is running on. */
    28 #define ATS_DEFAULT_PORT        6052
     28#define ATS_TCP_DEFAULT_PORT        6052
     29/** Alternative TCP/IP port the ATS (Audio Test Service) is running on. */
     30#define ATS_TCP_ALT_PORT            6042
    2931
    3032/**
     
    7678
    7779/**
     80 * Structure for keeping Audio Test Service (ATS) transport instance-specific data.
     81 *
     82 * Currently only TCP/IP is supported.
     83 */
     84typedef struct ATSTRANSPORTINST
     85{
     86    /** The addresses to bind to.  Empty string means any. */
     87    char                 szTcpBindAddr[256];
     88    /** The TCP port to listen to. */
     89    uint32_t             uTcpBindPort;
     90    /** Pointer to the TCP server instance. */
     91    PRTTCPSERVER         pTcpServer;
     92} ATSTRANSPORTINST;
     93/** Pointer to an Audio Test Service (ATS) TCP/IP transport instance. */
     94typedef ATSTRANSPORTINST *PATSTRANSPORTINSTTCP;
     95
     96/**
    7897 * Structure for keeping an Audio Test Service (ATS) instance.
    7998 */
     
    82101    /** The selected transport layer. */
    83102    PCATSTRANSPORT       pTransport;
     103    /** The transport instance. */
     104    ATSTRANSPORTINST     TransportInst;
    84105    /** The callbacks table. */
    85106    ATSCALLBACKS         Callbacks;
     
    106127typedef ATSSERVER *PATSSERVER;
    107128
    108 int AudioTestSvcInit(PATSSERVER pThis, PCATSCALLBACKS pCallbacks);
     129int AudioTestSvcInit(PATSSERVER pThis, const char *pszBindAddr, uint32_t uBindPort, PCATSCALLBACKS pCallbacks);
    109130int AudioTestSvcDestroy(PATSSERVER pThis);
    110131int AudioTestSvcStart(PATSSERVER pThis);
  • trunk/src/VBox/Devices/Audio/AudioTestServiceClient.cpp

    r89458 r89541  
    295295
    296296    /* For simplicity we always run on the same port, localhost only. */
    297     int rc = RTTcpClientConnect(pszAddr ? pszAddr : "127.0.0.1", uPort == 0 ? ATS_DEFAULT_PORT : uPort, &pClient->hSock);
     297    int rc = RTTcpClientConnect(pszAddr ? pszAddr : "127.0.0.1", uPort == 0 ? ATS_TCP_DEFAULT_PORT : uPort, &pClient->hSock);
    298298    if (RT_SUCCESS(rc))
    299299    {
  • trunk/src/VBox/Devices/Audio/AudioTestServiceInternal.h

    r89182 r89541  
    3333typedef PATSTRANSPORTCLIENT *PPATSTRANSPORTCLIENT;
    3434
     35/** Opaque ATS transport specific instance data. */
     36typedef struct ATSTRANSPORTINST *PATSTRANSPORTINST;
     37typedef PATSTRANSPORTINST *PPATSTRANSPORTINST;
     38
    3539/**
    3640 * Transport layer descriptor.
     
    4246    /** The description. */
    4347    const char     *pszDesc;
    44     /** Pointer to an array of options. */
    45     PCRTGETOPTDEF   paOpts;
    46     /** The number of options in the array. */
    47     size_t          cOpts;
    48 
    49     /**
    50      * Print the usage information for this transport layer.
    51      *
    52      * @param   pStream             The stream to print the usage info to.
    53      *
    54      * @remarks This is only required if TXSTRANSPORT::cOpts is greater than 0.
    55      */
    56     DECLR3CALLBACKMEMBER(void, pfnUsage, (PRTSTREAM pStream));
    57 
    58     /**
    59      * Handle an option.
    60      *
    61      * When encountering an options that is not part of the base options, we'll call
    62      * this method for each transport layer until one handles it.
    63      *
    64      * @retval  VINF_SUCCESS if handled.
    65      * @retval  VERR_TRY_AGAIN if not handled.
    66      * @retval  VERR_INVALID_PARAMETER if we should exit with a non-zero status.
    67      *
    68      * @param   ch                  The short option value.
    69      * @param   pVal                Pointer to the value union.
    70      *
    71      * @remarks This is only required if TXSTRANSPORT::cOpts is greater than 0.
    72      */
    73     DECLR3CALLBACKMEMBER(int, pfnOption, (int ch, PCRTGETOPTUNION pVal));
    7448
    7549    /**
     
    7852     * @returns IPRT status code.  On errors, the transport layer shall call
    7953     *          RTMsgError to display the error details to the user.
     54     * @param   pThis               The transport instance.
     55     * @param   pszBindAddr         Bind address. Empty means any address.
     56     * @param   uBindPort           Bind port. If set to 0, ATS_DEFAULT_PORT is being used.
    8057     */
    81     DECLR3CALLBACKMEMBER(int, pfnInit, (void));
     58    DECLR3CALLBACKMEMBER(int, pfnInit, (PATSTRANSPORTINST pThis, const char *pszBindAddr, uint32_t uBindPort));
    8259
    8360    /**
     
    8663     * On errors, the transport layer shall call RTMsgError to display the error
    8764     * details to the user.
     65     *
     66     * @param   pThis               The transport instance.
    8867     */
    89     DECLR3CALLBACKMEMBER(void, pfnTerm, (void));
     68    DECLR3CALLBACKMEMBER(void, pfnTerm, (PATSTRANSPORTINST pThis));
    9069
    9170    /**
     
    9372     * success.
    9473     */
    95     DECLR3CALLBACKMEMBER(int, pfnWaitForConnect, (PPATSTRANSPORTCLIENT ppClientNew));
     74    DECLR3CALLBACKMEMBER(int, pfnWaitForConnect, (PATSTRANSPORTINST pThis, PPATSTRANSPORTCLIENT ppClientNew));
    9675
    9776    /**
     
    9978     *
    10079     * @returns true if there are pending packets, false if there isn't.
     80     * @param   pThis               The transport instance.
    10181     * @param   pClient             The client to poll for data.
    10282     */
    103     DECLR3CALLBACKMEMBER(bool, pfnPollIn, (PATSTRANSPORTCLIENT pClient));
     83    DECLR3CALLBACKMEMBER(bool, pfnPollIn, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient));
    10484
    10585    /**
     
    10787     *
    10888     * @returns IPRT status code.
     89     * @param   pThis               The transport instance.
    10990     * @param   hPollSet            The poll set to add them to.
    11091     * @param   pClient             The transport client structure.
    11192     * @param   idStart             The handle ID to start at.
    11293     */
    113     DECLR3CALLBACKMEMBER(int, pfnPollSetAdd, (RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart));
     94    DECLR3CALLBACKMEMBER(int, pfnPollSetAdd, (PATSTRANSPORTINST pThis, RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart));
    11495
    11596    /**
     
    11798     *
    11899     * @returns IPRT status code.
     100     * @param   pThis               The transport instance.
    119101     * @param   hPollSet            The poll set to remove from.
    120102     * @param   pClient             The transport client structure.
    121103     * @param   idStart             The handle ID to remove.
    122104     */
    123     DECLR3CALLBACKMEMBER(int, pfnPollSetRemove, (RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart));
     105    DECLR3CALLBACKMEMBER(int, pfnPollSetRemove, (PATSTRANSPORTINST pThis, RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart));
    124106
    125107    /**
     
    134116     *          receive call.
    135117     *
     118     * @param   pThis               The transport instance.
    136119     * @param   pClient             The transport client structure.
    137120     * @param   ppPktHdr            Where to return the pointer to the packet we've
     
    140123     *                              free by calling RTMemFree.
    141124     */
    142     DECLR3CALLBACKMEMBER(int, pfnRecvPkt, (PATSTRANSPORTCLIENT pClient, PPATSPKTHDR ppPktHdr));
     125    DECLR3CALLBACKMEMBER(int, pfnRecvPkt, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PPATSPKTHDR ppPktHdr));
    143126
    144127    /**
     
    150133     * @retval  VERR_INTERRUPTED if interrupted before anything was sent.
    151134     *
     135     * @param   pThis               The transport instance.
    152136     * @param   pClient             The transport client structure.
    153137     * @param   pPktHdr             The packet to send.  The size is given by
     
    155139     *                              ATSPKT_ALIGNMENT.
    156140     */
    157     DECLR3CALLBACKMEMBER(int, pfnSendPkt, (PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr));
     141    DECLR3CALLBACKMEMBER(int, pfnSendPkt, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr));
    158142
    159143    /**
    160144     * Sends a babble packet and disconnects the client (if applicable).
    161145     *
     146     * @param   pThis               The transport instance.
    162147     * @param   pClient             The transport client structure.
    163148     * @param   pPktHdr             The packet to send.  The size is given by
     
    166151     * @param   cMsSendTimeout      The send timeout measured in milliseconds.
    167152     */
    168     DECLR3CALLBACKMEMBER(void, pfnBabble, (PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr, RTMSINTERVAL cMsSendTimeout));
     153    DECLR3CALLBACKMEMBER(void, pfnBabble, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr, RTMSINTERVAL cMsSendTimeout));
    169154
    170155    /**
    171156     * Notification about a client HOWDY.
    172157     *
     158     * @param   pThis               The transport instance.
    173159     * @param   pClient             The transport client structure.
    174160     */
    175     DECLR3CALLBACKMEMBER(void, pfnNotifyHowdy, (PATSTRANSPORTCLIENT pClient));
     161    DECLR3CALLBACKMEMBER(void, pfnNotifyHowdy, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient));
    176162
    177163    /**
     
    181167     * client at this point.
    182168     *
     169     * @param   pThis               The transport instance.
    183170     * @param   pClient             The transport client structure.
    184171     */
    185     DECLR3CALLBACKMEMBER(void, pfnNotifyBye, (PATSTRANSPORTCLIENT pClient));
     172    DECLR3CALLBACKMEMBER(void, pfnNotifyBye, (PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient));
    186173
    187174    /**
     
    190177     * For connection oriented transport layers, stop listening for and
    191178     * accepting at this point.
     179     *
     180     * @param   pThis               The transport instance.
    192181     */
    193     DECLR3CALLBACKMEMBER(void, pfnNotifyReboot, (void));
     182    DECLR3CALLBACKMEMBER(void, pfnNotifyReboot, (PATSTRANSPORTINST pThis));
    194183
    195184    /** Non-zero end marker. */
  • trunk/src/VBox/Devices/Audio/AudioTestServiceTcp.cpp

    r89204 r89541  
    3434#include <iprt/time.h>
    3535
     36#include "AudioTestService.h"
    3637#include "AudioTestServiceInternal.h"
    3738
     
    4041*   Defined Constants And Macros                                                                                                 *
    4142*********************************************************************************************************************************/
    42 /** The default server port.
    43  *  Note: Do not choose/use 6042, as the Validation Kit TxsService already might use that port. */
    44 #define ATS_TCP_DEF_BIND_PORT                   6052
    45 /** The default server bind address. */
    46 #define ATS_TCP_DEF_BIND_ADDRESS                ""
    4743
    4844
     
    7066*   Global Variables                                                                                                             *
    7167*********************************************************************************************************************************/
    72 /** @name TCP Parameters
    73  * @{ */
    74 /** The addresses to bind to.  Empty string means any.  */
    75 static char                 g_szTcpBindAddr[256]    = ATS_TCP_DEF_BIND_ADDRESS;
    76 /** The TCP port to listen to. */
    77 static uint32_t             g_uTcpBindPort          = ATS_TCP_DEF_BIND_PORT;
    78 /** @} */
    79 
    80 /** Pointer to the TCP server instance. */
    81 static PRTTCPSERVER         g_pTcpServer            = NULL;
    82 #if 0 /* unused */
    83 /** Stop connecting attempts when set. */
    84 static bool                 g_fTcpStopConnecting    = false;
    85 #endif
    86 
    87 
    8868
    8969/**
    9070 * Disconnects the current client and frees all stashed data.
    9171 */
    92 static void atsTcpDisconnectClient(PATSTRANSPORTCLIENT pClient)
    93 {
     72static void atsTcpDisconnectClient(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient)
     73{
     74    RT_NOREF(pThis);
     75
    9476    if (pClient->hTcpClient != NIL_RTSOCKET)
    9577    {
     
    10991 * @interface_method_impl{ATSTRANSPORT,pfnWaitForConnect}
    11092 */
    111 static DECLCALLBACK(int) atsTcpWaitForConnect(PPATSTRANSPORTCLIENT ppClientNew)
     93static DECLCALLBACK(int) atsTcpWaitForConnect(PATSTRANSPORTINST pThis, PPATSTRANSPORTCLIENT ppClientNew)
    11294{
    11395    int rc;
    11496    RTSOCKET hClientNew;
    11597
    116     rc = RTTcpServerListen2(g_pTcpServer, &hClientNew);
     98    rc = RTTcpServerListen2(pThis->pTcpServer, &hClientNew);
    11799    Log(("atsTcpWaitForConnect: RTTcpServerListen2 -> %Rrc\n", rc));
    118100
     
    141123 * @interface_method_impl{ATSTRANSPORT,pfnNotifyReboot}
    142124 */
    143 static DECLCALLBACK(void) atsTcpNotifyReboot(void)
    144 {
    145     Log(("atsTcpNotifyReboot: RTTcpServerDestroy(%p)\n", g_pTcpServer));
    146     if (g_pTcpServer)
    147     {
    148         int rc = RTTcpServerDestroy(g_pTcpServer);
     125static DECLCALLBACK(void) atsTcpNotifyReboot(PATSTRANSPORTINST pThis)
     126{
     127    Log(("atsTcpNotifyReboot: RTTcpServerDestroy(%p)\n", pThis->pTcpServer));
     128    if (pThis->pTcpServer)
     129    {
     130        int rc = RTTcpServerDestroy(pThis->pTcpServer);
    149131        if (RT_FAILURE(rc))
    150132            RTMsgInfo("RTTcpServerDestroy failed in atsTcpNotifyReboot: %Rrc", rc);
    151         g_pTcpServer = NULL;
     133        pThis->pTcpServer = NULL;
    152134    }
    153135}
     
    156138 * @interface_method_impl{ATSTRANSPORT,pfnNotifyBye}
    157139 */
    158 static DECLCALLBACK(void) atsTcpNotifyBye(PATSTRANSPORTCLIENT pClient)
     140static DECLCALLBACK(void) atsTcpNotifyBye(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient)
    159141{
    160142    Log(("atsTcpNotifyBye: atsTcpDisconnectClient %RTsock\n", pClient->hTcpClient));
    161     atsTcpDisconnectClient(pClient);
     143    atsTcpDisconnectClient(pThis, pClient);
    162144    RTMemFree(pClient);
    163145}
     
    166148 * @interface_method_impl{ATSTRANSPORT,pfnNotifyHowdy}
    167149 */
    168 static DECLCALLBACK(void) atsTcpNotifyHowdy(PATSTRANSPORTCLIENT pClient)
     150static DECLCALLBACK(void) atsTcpNotifyHowdy(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient)
    169151{
    170152    /* nothing to do here */
    171     RT_NOREF1(pClient);
     153    RT_NOREF(pThis, pClient);
    172154}
    173155
     
    175157 * @interface_method_impl{ATSTRANSPORT,pfnBabble}
    176158 */
    177 static DECLCALLBACK(void) atsTcpBabble(PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr, RTMSINTERVAL cMsSendTimeout)
     159static DECLCALLBACK(void) atsTcpBabble(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr, RTMSINTERVAL cMsSendTimeout)
    178160{
    179161    /*
     
    190172     */
    191173    Log(("atsTcpBabble: atsTcpDisconnectClient(%RTsock) (RTTcpWrite rc=%Rrc)\n", pClient->hTcpClient, rc));
    192     atsTcpDisconnectClient(pClient);
     174    atsTcpDisconnectClient(pThis, pClient);
    193175}
    194176
     
    196178 * @interface_method_impl{ATSTRANSPORT,pfnSendPkt}
    197179 */
    198 static DECLCALLBACK(int) atsTcpSendPkt(PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr)
     180static DECLCALLBACK(int) atsTcpSendPkt(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PCATSPKTHDR pPktHdr)
    199181{
    200182    Assert(pPktHdr->cb >= sizeof(ATSPKTHDR));
     
    210192        /* assume fatal connection error. */
    211193        Log(("RTTcpWrite -> %Rrc -> atsTcpDisconnectClient(%RTsock)\n", rc, pClient->hTcpClient));
    212         atsTcpDisconnectClient(pClient);
     194        atsTcpDisconnectClient(pThis, pClient);
    213195    }
    214196
     
    219201 * @interface_method_impl{ATSTRANSPORT,pfnRecvPkt}
    220202 */
    221 static DECLCALLBACK(int) atsTcpRecvPkt(PATSTRANSPORTCLIENT pClient, PPATSPKTHDR ppPktHdr)
     203static DECLCALLBACK(int) atsTcpRecvPkt(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient, PPATSPKTHDR ppPktHdr)
    222204{
    223205    int rc = VINF_SUCCESS;
     
    335317            /* assume fatal connection error. */
    336318            Log(("atsTcpRecvPkt: RTTcpRead -> %Rrc -> atsTcpDisconnectClient(%RTsock)\n", rc, pClient->hTcpClient));
    337             atsTcpDisconnectClient(pClient);
     319            atsTcpDisconnectClient(pThis, pClient);
    338320        }
    339321    }
     
    345327 * @interface_method_impl{ATSTRANSPORT,pfnPollSetAdd}
    346328 */
    347 static DECLCALLBACK(int) atsTcpPollSetAdd(RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart)
    348 {
     329static DECLCALLBACK(int) atsTcpPollSetAdd(PATSTRANSPORTINST pThis, RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart)
     330{
     331    RT_NOREF(pThis);
    349332    return RTPollSetAddSocket(hPollSet, pClient->hTcpClient, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, idStart);
    350333}
     
    353336 * @interface_method_impl{ATSTRANSPORT,pfnPollSetRemove}
    354337 */
    355 static DECLCALLBACK(int) atsTcpPollSetRemove(RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart)
    356 {
    357     RT_NOREF1(pClient);
     338static DECLCALLBACK(int) atsTcpPollSetRemove(PATSTRANSPORTINST pThis, RTPOLLSET hPollSet, PATSTRANSPORTCLIENT pClient, uint32_t idStart)
     339{
     340    RT_NOREF(pThis, pClient);
    358341    return RTPollSetRemove(hPollSet, idStart);
    359342}
     
    362345 * @interface_method_impl{ATSTRANSPORT,pfnPollIn}
    363346 */
    364 static DECLCALLBACK(bool) atsTcpPollIn(PATSTRANSPORTCLIENT pClient)
    365 {
     347static DECLCALLBACK(bool) atsTcpPollIn(PATSTRANSPORTINST pThis, PATSTRANSPORTCLIENT pClient)
     348{
     349    RT_NOREF(pThis);
    366350    int rc = RTTcpSelectOne(pClient->hTcpClient, 0/*cMillies*/);
    367351    return RT_SUCCESS(rc);
     
    371355 * @interface_method_impl{ATSTRANSPORT,pfnTerm}
    372356 */
    373 static DECLCALLBACK(void) atsTcpTerm(void)
     357static DECLCALLBACK(void) atsTcpTerm(PATSTRANSPORTINST pThis)
    374358{
    375359    /* Shut down the server (will wake up thread). */
    376     if (g_pTcpServer)
     360    if (pThis->pTcpServer)
    377361    {
    378362        Log(("atsTcpTerm: Destroying server...\n"));
    379         int rc = RTTcpServerDestroy(g_pTcpServer);
     363        int rc = RTTcpServerDestroy(pThis->pTcpServer);
    380364        if (RT_FAILURE(rc))
    381365            RTMsgInfo("RTTcpServerDestroy failed in atsTcpTerm: %Rrc", rc);
    382         g_pTcpServer        = NULL;
     366        pThis->pTcpServer        = NULL;
    383367    }
    384368
     
    389373 * @interface_method_impl{ATSTRANSPORT,pfnInit}
    390374 */
    391 static DECLCALLBACK(int) atsTcpInit(void)
    392 {
    393     int rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer);
     375static DECLCALLBACK(int) atsTcpInit(PATSTRANSPORTINST pThis, const char *pszBindAddr, uint32_t uBindPort)
     376{
     377    int rc = RTTcpServerCreateEx(pszBindAddr[0] ? pszBindAddr : NULL, uBindPort, &pThis->pTcpServer);
    394378    if (RT_FAILURE(rc))
    395379    {
     
    397381        {
    398382            RTMsgInfo("RTTcpServerCreateEx(%s, %u,) failed: %Rrc, retrying for 20 seconds...\n",
    399                       g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc);
     383                      pszBindAddr[0] ? pszBindAddr : NULL, uBindPort, rc);
    400384            uint64_t StartMs = RTTimeMilliTS();
    401385            do
    402386            {
    403387                RTThreadSleep(1000);
    404                 rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer);
     388                rc = RTTcpServerCreateEx(pszBindAddr[0] ? pszBindAddr : NULL, uBindPort, &pThis->pTcpServer);
    405389            } while (   rc == VERR_NET_DOWN
    406390                     && RTTimeMilliTS() - StartMs < 20000);
     
    410394        if (RT_FAILURE(rc))
    411395        {
    412             g_pTcpServer = NULL;
     396            pThis->pTcpServer = NULL;
    413397            RTMsgError("RTTcpServerCreateEx(%s, %u,) failed: %Rrc\n",
    414                        g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc);
     398                       pszBindAddr[0] ? pszBindAddr : NULL, uBindPort, rc);
    415399        }
    416400    }
     
    418402    return rc;
    419403}
    420 
    421 /** Options  */
    422 enum ATSTCPOPT
    423 {
    424     ATSTCPOPT_BIND_ADDRESS = 1000,
    425     ATSTCPOPT_BIND_PORT
    426 };
    427 
    428 /**
    429  * @interface_method_impl{ATSTRANSPORT,pfnOption}
    430  */
    431 static DECLCALLBACK(int) atsTcpOption(int ch, PCRTGETOPTUNION pVal)
    432 {
    433     int rc;
    434 
    435     switch (ch)
    436     {
    437         case ATSTCPOPT_BIND_ADDRESS:
    438             rc = RTStrCopy(g_szTcpBindAddr, sizeof(g_szTcpBindAddr), pVal->psz);
    439             if (RT_FAILURE(rc))
    440                 return RTMsgErrorRc(VERR_INVALID_PARAMETER, "TCP bind address is too long (%Rrc)", rc);
    441             return VINF_SUCCESS;
    442 
    443         case ATSTCPOPT_BIND_PORT:
    444             g_uTcpBindPort = pVal->u16 == 0 ? ATS_TCP_DEF_BIND_PORT : pVal->u16;
    445             return VINF_SUCCESS;
    446     }
    447     return VERR_TRY_AGAIN;
    448 }
    449 
    450 /**
    451  * @interface_method_impl{ATSTRANSPORT,pfnUsage}
    452  */
    453 DECLCALLBACK(void) atsTcpUsage(PRTSTREAM pStream)
    454 {
    455     RTStrmPrintf(pStream,
    456                  "  --tcp-bind-address <address>\n"
    457                  "       The address(es) to listen to TCP connection on.  Empty string\n"
    458                  "       means any address, this is the default.\n"
    459                  "  --tcp-bind-port <port>\n"
    460                  "       The port to listen to TCP connections on.\n"
    461                  "       Default: %u\n"
    462                  , ATS_TCP_DEF_BIND_PORT);
    463 }
    464 
    465 /** Command line options for the TCP/IP transport layer. */
    466 static const RTGETOPTDEF  g_TcpOpts[] =
    467 {
    468     { "--tcp-bind-address",     ATSTCPOPT_BIND_ADDRESS,     RTGETOPT_REQ_STRING },
    469     { "--tcp-bind-port",        ATSTCPOPT_BIND_PORT,        RTGETOPT_REQ_UINT16 }
    470 };
    471404
    472405/** TCP/IP transport layer. */
     
    475408    /* .szName            = */ "tcp",
    476409    /* .pszDesc           = */ "TCP/IP",
    477     /* .cOpts             = */ &g_TcpOpts[0],
    478     /* .paOpts            = */ RT_ELEMENTS(g_TcpOpts),
    479     /* .pfnUsage          = */ atsTcpUsage,
    480     /* .pfnOption         = */ atsTcpOption,
    481410    /* .pfnInit           = */ atsTcpInit,
    482411    /* .pfnTerm           = */ atsTcpTerm,
     
    493422    /* .u32EndMarker      = */ UINT32_C(0x12345678)
    494423};
     424
  • trunk/src/VBox/Devices/Audio/DrvHostAudioValidationKit.cpp

    r89510 r89541  
    155155    pTst->pObj = NULL;
    156156
    157     AssertPtrReturnVoid(pTst->pEntry);
    158     AudioTestSetTestDone(pTst->pEntry);
    159     pTst->pEntry = NULL;
     157    if (pTst->pEntry) /* Set set entry assign? Mark as done. */
     158    {
     159        AssertPtrReturnVoid(pTst->pEntry);
     160        AudioTestSetTestDone(pTst->pEntry);
     161        pTst->pEntry = NULL;
     162    }
    160163
    161164    RTMemFree(pTst);
     
    235238/** @copydoc ATSCALLBACKS::pfnTonePlay
    236239 *
    237  * Creates and registers a new test tone recording test
    238  * which later then gets recorded by the guest side.
     240 * Creates and registers a new test tone guest recording test.
    239241 */
    240242static DECLCALLBACK(int) drvHostValKitRegisterGuestRecTest(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
     
    270272/** @copydoc ATSCALLBACKS::pfnToneRecord
    271273 *
    272  * Creates and registers a new test tone playback test
    273  * which later then records audio played back by the guest side.
     274 * Creates and registers a new test tone guest playback test.
    274275 */
    275276static DECLCALLBACK(int) drvHostValKitRegisterGuestPlayTest(void const *pvUser, PAUDIOTESTTONEPARMS pToneParms)
     
    283284
    284285    pTestData->t.TestTone.u.Rec.cbToWrite = PDMAudioPropsMilliToBytes(&pToneParms->Props,
    285                                                                 pTestData->t.TestTone.Parms.msDuration);
     286                                                                      pTestData->t.TestTone.Parms.msDuration);
    286287    int rc = RTCritSectEnter(&pThis->CritSect);
    287288    if (RT_SUCCESS(rc))
     
    714715    Callbacks.pvUser          = pThis;
    715716
    716     LogRel(("Audio: Validation Kit: Starting Audio Test Service (ATS) ...\n"));
    717 
    718     int rc = AudioTestSvcInit(&pThis->Srv, &Callbacks);
     717    /** @todo Make this configurable via CFGM. */
     718    const char *pszTcpAddr = "127.0.0.1";
     719       uint32_t uTcpPort   = ATS_TCP_DEFAULT_PORT;
     720
     721    LogRel(("Audio: Validation Kit: Starting Audio Test Service (ATS) at %s:%RU32...\n",
     722            pszTcpAddr, uTcpPort));
     723
     724    int rc = AudioTestSvcInit(&pThis->Srv,
     725                              /* We only allow connections from localhost for now. */
     726                              pszTcpAddr, uTcpPort, &Callbacks);
    719727    if (RT_SUCCESS(rc))
    720728        rc = AudioTestSvcStart(&pThis->Srv);
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