VirtualBox

Changeset 90830 in vbox


Ignore:
Timestamp:
Aug 24, 2021 10:47:52 AM (3 years ago)
Author:
vboxsync
Message:

Audio/ValKit: More work on ATS client destruction handling. bugref:10008

Location:
trunk/src/VBox
Files:
8 edited

Legend:

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

    r90745 r90830  
    471471    if (pPktHdr->cb == sizeof(ATSPKTHDR))
    472472    {
    473         rc = atsReplyAck(pThis, pInst, pPktHdr);
     473        if (pThis->Callbacks.pfnBye)
     474        {
     475            rc = pThis->Callbacks.pfnBye(pThis->Callbacks.pvUser);
     476        }
     477        else
     478            rc = VINF_SUCCESS;
     479
     480        if (RT_SUCCESS(rc))
     481        {
     482            rc = atsReplyAck(pThis, pInst, pPktHdr);
     483        }
     484        else
     485            rc = atsReplyRC(pThis, pInst, pPktHdr, rc, "Shutting down server failed");
     486
    474487        if (RT_SUCCESS(rc))
    475488            pThis->pTransport->pfnNotifyBye(pThis->pTransportInst, pInst->pTransportClient);
     
    512525    {
    513526        pThis->pTransport->pfnNotifyHowdy(pThis->pTransportInst, pInst->pTransportClient);
    514         pInst->enmState = ATSCLIENTSTATE_READY;
     527
     528        if (pThis->Callbacks.pfnHowdy)
     529            rc = pThis->Callbacks.pfnHowdy(pThis->Callbacks.pvUser);
     530
     531        if (RT_SUCCESS(rc))
     532            pInst->enmState = ATSCLIENTSTATE_READY;
    515533    }
    516534
     
    921939
    922940                        pThis->pTransport->pfnNotifyBye(pThis->pTransportInst, pInst->pTransportClient);
     941                        pInst->pTransportClient = NULL;
    923942                        papInsts[uId - 1] = NULL;
    924943                        cClientsCur--;
  • trunk/src/VBox/Devices/Audio/AudioTestService.h

    r90768 r90830  
    5252typedef struct ATSCALLBACKS
    5353{
     54    /**
     55     * Tells the implementation that a new client connected. Optional.
     56     *
     57     * @param   pvUser          User-supplied pointer to context data. Optional.
     58     */
     59    DECLR3CALLBACKMEMBER(int, pfnHowdy, (void const *pvUser));
     60
     61    /**
     62     * Tells the implementation that a client disconnected. Optional.
     63     *
     64     * @param   pvUser          User-supplied pointer to context data. Optional.
     65     */
     66    DECLR3CALLBACKMEMBER(int, pfnBye, (void const *pvUser));
     67
    5468    /**
    5569     * Begins a test set. Optional.
  • trunk/src/VBox/Devices/Audio/AudioTestServiceClient.cpp

    r90764 r90830  
    5757
    5858
     59/*********************************************************************************************************************************
     60*   Prototypes                                                                                                                   *
     61*********************************************************************************************************************************/
     62static int audioTestSvcClientCloseInternal(PATSCLIENT pClient);
     63
    5964/**
    6065 * Initializes an ATS client, internal version.
     
    230235
    231236/**
    232  * Tells the ATS server that we want disconnect.
     237 * Tells the ATS server that we want to disconnect.
    233238 *
    234239 * @returns VBox status code.
     
    237242static int audioTestSvcClientDoBye(PATSCLIENT pClient)
    238243{
    239     ATSPKTREQHOWDY Req;
    240     Req.uVersion = ATS_PROTOCOL_VS;
    241     audioTestSvcClientReqHdrInit(&Req.Hdr, sizeof(Req), ATSPKT_OPCODE_BYE, 0);
     244    ATSPKTHDR Req;
     245    audioTestSvcClientReqHdrInit(&Req, sizeof(Req), ATSPKT_OPCODE_BYE, 0);
    242246    int rc = audioTestSvcClientSendMsg(pClient, &Req, sizeof(Req));
    243247    if (RT_SUCCESS(rc))
     
    272276void AudioTestSvcClientDestroy(PATSCLIENT pClient)
    273277{
    274     /* ignore rc */ audioTestSvcClientDoBye(pClient);
     278    if (!pClient)
     279        return;
     280
     281    /* ignore rc */ audioTestSvcClientCloseInternal(pClient);
    275282
    276283    if (pClient->pTransport)
     284    {
    277285        pClient->pTransport->pfnTerm(pClient->pTransportInst);
     286        pClient->pTransport->pfnDestroy(pClient->pTransportInst);
     287        pClient->pTransport = NULL;
     288    }
    278289}
    279290
     
    495506
    496507/**
     508 * Disconnects from an ATS server, internal version.
     509 *
     510 * @returns VBox status code.
     511 * @param   pClient             Client to disconnect.
     512 */
     513static int audioTestSvcClientCloseInternal(PATSCLIENT pClient)
     514{
     515    int rc = audioTestSvcClientDoBye(pClient);
     516    if (RT_SUCCESS(rc))
     517    {
     518        if (pClient->pTransport->pfnNotifyBye)
     519            pClient->pTransport->pfnNotifyBye(pClient->pTransportInst, pClient->pTransportClient);
     520    }
     521
     522    return rc;
     523}
     524
     525/**
    497526 * Disconnects from an ATS server.
    498527 *
     
    502531int AudioTestSvcClientClose(PATSCLIENT pClient)
    503532{
    504     pClient->pTransport->pfnNotifyBye(pClient->pTransportInst, pClient->pTransportClient);
    505 
    506     return VINF_SUCCESS;
    507 }
    508 
     533    return audioTestSvcClientCloseInternal(pClient);
     534}
     535
  • trunk/src/VBox/Devices/Audio/AudioTestServiceClient.h

    r89962 r90830  
    3939typedef ATSCLIENT *PATSCLIENT;
    4040
     41/** @name Creation / destruction.
     42 * @{ */
    4143int AudioTestSvcClientCreate(PATSCLIENT pClient);
    4244void AudioTestSvcClientDestroy(PATSCLIENT pClient);
     45/** @} */
     46
     47/** @name Connection handling.
     48 * @{ */
    4349int AudioTestSvcClientConnect(PATSCLIENT pClient);
     50int AudioTestSvcClientClose(PATSCLIENT pClient);
     51/** @} */
     52
     53/** @name Option handling.
     54 * @{ */
    4455int AudioTestSvcClientHandleOption(PATSCLIENT pClient, int ch, PCRTGETOPTUNION pVal);
     56/** @} */
     57
     58/** @name Test set handling.
     59 * @{ */
    4560int AudioTestSvcClientTestSetBegin(PATSCLIENT pClient, const char *pszTag);
    4661int AudioTestSvcClientTestSetEnd(PATSCLIENT pClient, const char *pszTag);
     62int AudioTestSvcClientTestSetDownload(PATSCLIENT pClient, const char *pszTag, const char *pszPathOutAbs);
     63/** @} */
     64
     65/** @name Tone handling.
     66 * @{ */
    4767int AudioTestSvcClientTonePlay(PATSCLIENT pClient, PAUDIOTESTTONEPARMS pToneParms);
    4868int AudioTestSvcClientToneRecord(PATSCLIENT pClient, PAUDIOTESTTONEPARMS pToneParms);
    49 int AudioTestSvcClientTestSetDownload(PATSCLIENT pClient, const char *pszTag, const char *pszPathOutAbs);
    50 int AudioTestSvcClientClose(PATSCLIENT pClient);
     69/** @} */
    5170
    5271#endif /* !VBOX_INCLUDED_SRC_Audio_AudioTestServiceClient_h */
  • trunk/src/VBox/Devices/Audio/AudioTestServiceTcp.cpp

    r90554 r90830  
    426426    LogFunc(("atsTcpDisconnectClient %RTsock\n", pClient->hTcpClient));
    427427    atsTcpDisconnectClient(pThis, pClient);
    428     RTMemFree(pClient);
    429428}
    430429
     
    446445     * Try send the babble reply.
    447446     */
    448     NOREF(cMsSendTimeout); /** @todo implement the timeout here; non-blocking write + select-on-write. */
     447    RT_NOREF(cMsSendTimeout); /** @todo implement the timeout here; non-blocking write + select-on-write. */
    449448    int     rc;
    450449    size_t  cbToSend = RT_ALIGN_Z(pPktHdr->cb, ATSPKT_ALIGNMENT);
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r90788 r90830  
    257257    pTstParmsAcq->enmDir      = PDMAUDIODIR_OUT;
    258258#ifdef DEBUG
    259     pTstParmsAcq->cIterations = 4;
     259    pTstParmsAcq->cIterations = 1;
    260260#else
    261261    pTstParmsAcq->cIterations = RTRandU32Ex(1, 10);
     
    361361    pTstParmsAcq->enmDir      = PDMAUDIODIR_IN;
    362362#ifdef DEBUG
    363     pTstParmsAcq->cIterations = 4;
     363    pTstParmsAcq->cIterations = 1;
    364364#else
    365365    pTstParmsAcq->cIterations = RTRandU32Ex(1, 10);
  • trunk/src/VBox/ValidationKit/utils/audio/vkatCmdSelfTest.cpp

    r90769 r90830  
    162162    /* else Step 1a later. */
    163163
    164     RTThreadSleep(5000); /* Fudge: Wait until guest ATS is up. */
     164    RTThreadSleep(2000); /* Fudge: Wait until guest ATS is up. 2 seconds should be enough (tm). */
    165165
    166166    if (RT_SUCCESS(rc))
     
    192192    RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,  "Shutting down self test\n");
    193193
    194     ASMAtomicWriteBool(&g_fTerminate, true);
    195 
     194    /* If we started the guest ATS ourselves, wait for it to terminate properly. */
    196195    if (fStartGuestAts)
    197196    {
  • trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp

    r90767 r90830  
    6161    /** File handle to the (opened) test set archive for reading. */
    6262    RTFILE        hTestSetArchive;
     63    /** Number of currently connected clients. */
     64    uint8_t       cClients;
    6365} ATSCALLBACKCTX;
    6466typedef ATSCALLBACKCTX *PATSCALLBACKCTX;
     
    463465*********************************************************************************************************************************/
    464466
     467/** @copydoc ATSCALLBACKS::pfnHowdy
     468 *
     469 *  @note Runs as part of the guest ATS.
     470 */
     471static DECLCALLBACK(int) audioTestGstAtsHowdyCallback(void const *pvUser)
     472{
     473    PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
     474
     475    AssertReturn(pCtx->cClients <= UINT8_MAX, VERR_BUFFER_OVERFLOW);
     476
     477    pCtx->cClients++;
     478
     479    RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "New client connected, now %RU8 total\n", pCtx->cClients);
     480
     481    return VINF_SUCCESS;
     482}
     483
     484/** @copydoc ATSCALLBACKS::pfnBye
     485 *
     486 *  @note Runs as part of the guest ATS.
     487 */
     488static DECLCALLBACK(int) audioTestGstAtsByeCallback(void const *pvUser)
     489{
     490    PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser;
     491
     492    AssertReturn(pCtx->cClients, VERR_WRONG_ORDER);
     493    pCtx->cClients--;
     494
     495    RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Clients wants to disconnect, %RU8 remaining\n", pCtx->cClients);
     496
     497    if (0 == pCtx->cClients) /* All clients disconnected? Tear things down. */
     498    {
     499        RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Last client disconnected, terminating server ...\n");
     500        ASMAtomicWriteBool(&g_fTerminate, true);
     501    }
     502
     503    return VINF_SUCCESS;
     504}
     505
    465506/** @copydoc ATSCALLBACKS::pfnTestSetBegin
    466507 *
     
    870911        ATSCALLBACKS Callbacks;
    871912        RT_ZERO(Callbacks);
     913        Callbacks.pfnHowdy            = audioTestGstAtsHowdyCallback;
     914        Callbacks.pfnBye              = audioTestGstAtsByeCallback;
    872915        Callbacks.pfnTestSetBegin     = audioTestGstAtsTestSetBeginCallback;
    873916        Callbacks.pfnTestSetEnd       = audioTestGstAtsTestSetEndCallback;
     
    9651008        return;
    9661009
     1010    /* When in host mode, we need to destroy our ATS clients in order to also let
     1011     * the ATS server(s) know we're going to quit. */
     1012    if (pTstEnv->enmMode == AUDIOTESTMODE_HOST)
     1013    {
     1014        AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClValKit);
     1015        AudioTestSvcClientDestroy(&pTstEnv->u.Host.AtsClGuest);
     1016    }
     1017
    9671018    for (unsigned i = 0; i < RT_ELEMENTS(pTstEnv->aStreams); i++)
    9681019    {
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