Changeset 88885 in vbox for trunk/src/VBox
- Timestamp:
- May 5, 2021 6:28:38 PM (4 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/DrvAudioVRDE.h
r88382 r88885 70 70 /** Pointer to the associated VRDE audio driver. */ 71 71 struct DRVAUDIOVRDE *mpDrv; 72 /** Protects accesses to mpDrv from racing driver destruction. */ 73 RTCRITSECT mCritSect; 72 74 }; 73 75 -
trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
r88819 r88885 75 75 /** Pointer to the VRDP's console object. */ 76 76 ConsoleVRDPServer *pConsoleVRDPServer; 77 /** Pointer to the DrvAudio port interface that is above us. */78 PPDMIAUDIOCONNECTOR pDrvAudio;79 77 /** Number of connected clients to this VRDE instance. */ 80 78 uint32_t cClients; 79 /** Interface to the driver above us (DrvAudio). */ 80 PDMIHOSTAUDIOPORT *pIHostAudioPort; 81 81 /** Pointer to host audio interface. */ 82 82 PDMIHOSTAUDIO IHostAudio; … … 98 98 , mpDrv(NULL) 99 99 { 100 RTCritSectInit(&mCritSect); 100 101 } 101 102 … … 103 104 AudioVRDE::~AudioVRDE(void) 104 105 { 106 RTCritSectEnter(&mCritSect); 105 107 if (mpDrv) 106 108 { … … 108 110 mpDrv = NULL; 109 111 } 112 RTCritSectLeave(&mCritSect); 113 RTCritSectDelete(&mCritSect); 110 114 } 111 115 … … 129 133 RT_NOREF(uClientID); 130 134 131 LogRel2(("Audio: VRDE client connected\n"));135 RTCritSectEnter(&mCritSect); 132 136 if (mpDrv) 137 { 133 138 mpDrv->cClients++; 139 LogRel2(("Audio: VRDE client connected (#%u)\n", mpDrv->cClients)); 140 141 #if 0 /* later, maybe */ 142 /* 143 * The first client triggers a device change event in both directions 144 * so that can start talking to the audio device. 145 * 146 * Note! Should be okay to stay in the critical section here, as it's only 147 * used at construction and destruction time. 148 */ 149 if (mpDrv->cClients == 1) 150 { 151 VMSTATE enmState = PDMDrvHlpVMState(mpDrv->pDrvIns); 152 if (enmState <= VMSTATE_POWERING_OFF) 153 { 154 PDMIHOSTAUDIOPORT *pIHostAudioPort = mpDrv->pIHostAudioPort; 155 AssertPtr(pIHostAudioPort); 156 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_OUT, NULL /*pvUser*/); 157 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_IN, NULL /*pvUser*/); 158 } 159 } 160 #endif 161 } 162 RTCritSectLeave(&mCritSect); 134 163 } 135 164 … … 139 168 RT_NOREF(uClientID); 140 169 141 LogRel2(("Audio: VRDE client disconnected\n")); 142 Assert(mpDrv->cClients); 170 RTCritSectEnter(&mCritSect); 143 171 if (mpDrv) 172 { 173 Assert(mpDrv->cClients > 0); 144 174 mpDrv->cClients--; 175 LogRel2(("Audio: VRDE client disconnected (%u left)\n", mpDrv->cClients)); 176 #if 0 /* later maybe */ 177 /* 178 * The last client leaving triggers a device change event in both 179 * directions so the audio devices can stop wasting time trying to 180 * talk to us. (There is an additional safeguard in 181 * drvAudioVrdeHA_StreamGetStatus.) 182 */ 183 if (mpDrv->cClients == 0) 184 { 185 VMSTATE enmState = PDMDrvHlpVMState(mpDrv->pDrvIns); 186 if (enmState <= VMSTATE_POWERING_OFF) 187 { 188 PDMIHOSTAUDIOPORT *pIHostAudioPort = mpDrv->pIHostAudioPort; 189 AssertPtr(pIHostAudioPort); 190 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_OUT, NULL /*pvUser*/); 191 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_IN, NULL /*pvUser*/); 192 } 193 } 194 #endif 195 } 196 RTCritSectLeave(&mCritSect); 145 197 } 146 198 … … 313 365 PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq) 314 366 { 315 RT_NOREF(pInterface);316 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;367 PDRVAUDIOVRDE pThis = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio); 368 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream; 317 369 AssertPtrReturn(pStreamVRDE, VERR_INVALID_POINTER); 318 370 AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER); 319 371 AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER); 320 372 373 /* 374 * Only create a stream if we have clients. 375 */ 321 376 int rc; 322 if (pCfgReq->enmDir == PDMAUDIODIR_IN) 323 rc = vrdeCreateStreamIn(pStreamVRDE, pCfgAcq); 377 NOREF(pThis); 378 #if 0 /* later maybe */ 379 if (pThis->cClients == 0) 380 { 381 LogFunc(("No clients, failing with VERR_AUDIO_STREAM_COULD_NOT_CREATE.\n")); 382 rc = VERR_AUDIO_STREAM_COULD_NOT_CREATE; 383 } 324 384 else 325 rc = vrdeCreateStreamOut(pCfgAcq); 326 PDMAudioStrmCfgCopy(&pStreamVRDE->Cfg, pCfgAcq); 385 #endif 386 { 387 if (pCfgReq->enmDir == PDMAUDIODIR_IN) 388 rc = vrdeCreateStreamIn(pStreamVRDE, pCfgAcq); 389 else 390 rc = vrdeCreateStreamOut(pCfgAcq); 391 PDMAudioStrmCfgCopy(&pStreamVRDE->Cfg, pCfgAcq); 392 } 327 393 return rc; 328 394 } … … 536 602 RT_NOREF(pStream); 537 603 538 uint32_t fStrmStatus = PDMAUDIOSTREAM_STS_INITIALIZED; 539 if (pDrv->cClients) /* If any clients are connected, flag the stream as enabled. */ 540 fStrmStatus |= PDMAUDIOSTREAM_STS_ENABLED; 541 542 return fStrmStatus; 604 return pDrv->cClients > 0 605 ? PDMAUDIOSTREAM_STS_INITIALIZED | PDMAUDIOSTREAM_STS_ENABLED 606 #if 0 /* later mabye */ /** @todo r=bird: Weird backend status mess. */ 607 : PDMAUDIOSTREAM_STS_NONE /* play possum if the clients all disappears. Re-init should be underways. */; 608 #else 609 : PDMAUDIOSTREAM_STS_INITIALIZED /* If any clients are connected, flag the stream as enabled. */; 610 #endif 543 611 } 544 612 … … 685 753 * us since we'll be invalid when we return from this method. 686 754 */ 687 if (pThis->pAudioVRDE) 688 { 689 pThis->pAudioVRDE->mpDrv = NULL; 755 AudioVRDE *pAudioVRDE = pThis->pAudioVRDE; 756 if (pAudioVRDE) 757 { 758 RTCritSectEnter(&pAudioVRDE->mCritSect); 759 pAudioVRDE->mpDrv = NULL; 690 760 pThis->pAudioVRDE = NULL; 761 RTCritSectLeave(&pAudioVRDE->mCritSect); 691 762 } 692 763 } … … 740 811 741 812 /* 813 * Resolve the interface to the driver above us. 814 */ 815 pThis->pIHostAudioPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHOSTAUDIOPORT); 816 AssertPtrReturn(pThis->pIHostAudioPort, VERR_PDM_MISSING_INTERFACE_ABOVE); 817 818 /* 742 819 * Get the ConsoleVRDPServer object pointer. 743 820 */ … … 761 838 pThis->pAudioVRDE = (AudioVRDE *)pvUser; 762 839 AssertLogRelMsgReturn(RT_VALID_PTR(pThis->pAudioVRDE), ("pAudioVRDE=%p\n", pThis->pAudioVRDE), VERR_INVALID_POINTER); 840 RTCritSectEnter(&pThis->pAudioVRDE->mCritSect); 763 841 pThis->pAudioVRDE->mpDrv = pThis; 764 765 /* 766 * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls. 767 * Described in CFGM tree. 768 */ 769 pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR); 770 AssertMsgReturn(pThis->pDrvAudio, ("Configuration error: No upper interface specified!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE); 842 RTCritSectLeave(&pThis->pAudioVRDE->mCritSect); 771 843 772 844 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.