Changeset 82597 in vbox
- Timestamp:
- Dec 16, 2019 6:42:38 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135483
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixer.cpp
r82588 r82597 90 90 * Internal Functions * 91 91 *********************************************************************************************************************************/ 92 static int audioMixerAddSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink); 92 93 static int audioMixerRemoveSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink); 93 94 95 static int audioMixerSinkInit(PAUDMIXSINK pSink, PAUDIOMIXER pMixer, const char *pcszName, AUDMIXSINKDIR enmDir); 94 96 static void audioMixerSinkDestroyInternal(PAUDMIXSINK pSink); 95 97 static int audioMixerSinkUpdateVolume(PAUDMIXSINK pSink, const PPDMAUDIOVOLUME pVolMaster); … … 184 186 if (pSink) 185 187 { 186 pSink->pszName = RTStrDup(pszName); 187 if (!pSink->pszName) 188 rc = VERR_NO_MEMORY; 189 188 rc = audioMixerSinkInit(pSink, pMixer, pszName, enmDir); 190 189 if (RT_SUCCESS(rc)) 191 rc = RTCritSectInit(&pSink->CritSect); 192 193 if (RT_SUCCESS(rc)) 194 { 195 pSink->pParent = pMixer; 196 pSink->enmDir = enmDir; 197 RTListInit(&pSink->lstStreams); 198 199 /* Set initial volume to max. */ 200 pSink->Volume.fMuted = false; 201 pSink->Volume.uLeft = PDMAUDIO_VOLUME_MAX; 202 pSink->Volume.uRight = PDMAUDIO_VOLUME_MAX; 203 204 /* Ditto for the combined volume. */ 205 pSink->VolumeCombined.fMuted = false; 206 pSink->VolumeCombined.uLeft = PDMAUDIO_VOLUME_MAX; 207 pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX; 208 209 RTListAppend(&pMixer->lstSinks, &pSink->Node); 210 pMixer->cSinks++; 211 212 LogFlowFunc(("pMixer=%p, pSink=%p, cSinks=%RU8\n", 213 pMixer, pSink, pMixer->cSinks)); 214 215 if (ppSink) 216 *ppSink = pSink; 190 { 191 rc = audioMixerAddSinkInternal(pMixer, pSink); 192 if (RT_SUCCESS(rc)) 193 { 194 if (ppSink) 195 *ppSink = pSink; 196 } 217 197 } 218 198 219 199 if (RT_FAILURE(rc)) 220 200 { 221 RTCritSectDelete(&pSink->CritSect); 222 223 if (pSink) 224 { 225 RTMemFree(pSink); 226 pSink = NULL; 227 } 201 audioMixerSinkDestroyInternal(pSink); 202 203 RTMemFree(pSink); 204 pSink = NULL; 228 205 } 229 206 } … … 245 222 * @param ppMixer Pointer which returns the created mixer object. 246 223 */ 247 int AudioMixerCreate(const char *p szName, uint32_t fFlags, PAUDIOMIXER *ppMixer)224 int AudioMixerCreate(const char *pcszName, uint32_t fFlags, PAUDIOMIXER *ppMixer) 248 225 { 249 226 RT_NOREF(fFlags); 250 AssertPtrReturn(p szName, VERR_INVALID_POINTER);227 AssertPtrReturn(pcszName, VERR_INVALID_POINTER); 251 228 /** @todo Add fFlags validation. */ 252 229 AssertPtrReturn(ppMixer, VERR_INVALID_POINTER); … … 257 234 if (pMixer) 258 235 { 259 pMixer->pszName = RTStrDup(p szName);236 pMixer->pszName = RTStrDup(pcszName); 260 237 if (!pMixer->pszName) 261 238 rc = VERR_NO_MEMORY; … … 343 320 344 321 audioMixerRemoveSinkInternal(pMixer, pSinkToRemove); 322 345 323 audioMixerSinkDestroyInternal(pSinkToRemove); 324 325 RTMemFree(pSinkToRemove); 346 326 } 347 327 … … 409 389 410 390 /** 391 * Adds sink to an existing mixer. 392 * 393 * @returns VBox status code. 394 * @param pMixer Mixer to add sink to. 395 * @param pSink Sink to add. 396 */ 397 static int audioMixerAddSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink) 398 { 399 AssertPtrReturn(pMixer, VERR_INVALID_POINTER); 400 AssertPtrReturn(pSink, VERR_INVALID_POINTER); 401 402 /** @todo Check upper sink limit? */ 403 /** @todo Check for double-inserted sinks? */ 404 405 RTListAppend(&pMixer->lstSinks, &pSink->Node); 406 pMixer->cSinks++; 407 408 LogFlowFunc(("pMixer=%p, pSink=%p, cSinks=%RU8\n", 409 pMixer, pSink, pMixer->cSinks)); 410 411 return VINF_SUCCESS; 412 } 413 414 /** 411 415 * Removes a formerly attached audio sink for an audio mixer, internal version. 412 416 * … … 429 433 /* Remove sink from mixer. */ 430 434 RTListNodeRemove(&pSink->Node); 435 431 436 Assert(pMixer->cSinks); 437 pMixer->cSinks--; 432 438 433 439 /* Set mixer to NULL so that we know we're not part of any mixer anymore. */ … … 810 816 811 817 /** 818 * Initializes a sink. 819 * 820 * @returns VBox status code. 821 * @param pSink Sink to initialize. 822 * @param pMixer Mixer the sink is assigned to. 823 * @param pcszName Name of the sink. 824 * @param enmDir Direction of the sink. 825 */ 826 static int audioMixerSinkInit(PAUDMIXSINK pSink, PAUDIOMIXER pMixer, const char *pcszName, AUDMIXSINKDIR enmDir) 827 { 828 pSink->pszName = RTStrDup(pcszName); 829 if (!pSink->pszName) 830 return VERR_NO_MEMORY; 831 832 int rc = RTCritSectInit(&pSink->CritSect); 833 if (RT_SUCCESS(rc)) 834 { 835 pSink->pParent = pMixer; 836 pSink->enmDir = enmDir; 837 838 RTListInit(&pSink->lstStreams); 839 840 /* Set initial volume to max. */ 841 pSink->Volume.fMuted = false; 842 pSink->Volume.uLeft = PDMAUDIO_VOLUME_MAX; 843 pSink->Volume.uRight = PDMAUDIO_VOLUME_MAX; 844 845 /* Ditto for the combined volume. */ 846 pSink->VolumeCombined.fMuted = false; 847 pSink->VolumeCombined.uLeft = PDMAUDIO_VOLUME_MAX; 848 pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX; 849 } 850 851 LogFlowFuncLeaveRC(rc); 852 return rc; 853 } 854 855 /** 812 856 * Destroys a mixer sink and removes it from the attached mixer (if any). 813 857 * … … 830 874 831 875 audioMixerRemoveSinkInternal(pMixer, pSink); 832 833 Assert(pMixer->cSinks);834 pMixer->cSinks--;835 876 } 836 877 … … 839 880 840 881 audioMixerSinkDestroyInternal(pSink); 882 883 RTMemFree(pSink); 884 pSink = NULL; 841 885 } 842 886 … … 876 920 AudioMixBufDestroy(&pSink->MixBuf); 877 921 RTCritSectDelete(&pSink->CritSect); 878 879 RTMemFree(pSink);880 pSink = NULL;881 922 } 882 923 … … 996 1037 return AUDMIXSINKDIR_UNKNOWN; 997 1038 998 AUDMIXSINKDIR enmDir = pSink->enmDir;1039 const AUDMIXSINKDIR enmDir = pSink->enmDir; 999 1040 1000 1041 int rc2 = RTCritSectLeave(&pSink->CritSect); … … 1090 1131 return 0; 1091 1132 1092 uint8_t cStreams = pSink->cStreams;1133 const uint8_t cStreams = pSink->cStreams; 1093 1134 1094 1135 rc2 = RTCritSectLeave(&pSink->CritSect); … … 1114 1155 return false; 1115 1156 1116 bool fIsActive = pSink->fStatus & AUDMIXSINK_STS_RUNNING;1157 const bool fIsActive = pSink->fStatus & AUDMIXSINK_STS_RUNNING; 1117 1158 /* Note: AUDMIXSINK_STS_PENDING_DISABLE implies AUDMIXSINK_STS_RUNNING. */ 1118 1159 … … 1509 1550 rc = pStream->pConn->pfnEnable(pStream->pConn, PDMAUDIODIR_IN, true /* Enable */); 1510 1551 if (RT_SUCCESS(rc)) 1552 { 1511 1553 pSink->In.pStreamRecSource = pStream; 1554 } 1512 1555 else if (pSink->In.pStreamRecSource->pConn) /* Stay with the current recording source (if any) and re-enable it. */ 1513 1556 { … … 2307 2350 return fIsValid; 2308 2351 } 2309
Note:
See TracChangeset
for help on using the changeset viewer.