- Timestamp:
- May 12, 2021 12:41:56 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioCoreAudio.cpp
r89008 r89009 111 111 * Can be NULL if none assigned. */ 112 112 PCOREAUDIODEVICEDATA pDefaultDevOut; 113 #ifdef VBOX_WITH_AUDIO_CALLBACKS114 113 /** Upwards notification interface. */ 115 114 PPDMIHOSTAUDIOPORT pIHostAudioPort; 116 #endif117 115 /** Indicates whether we've registered default input device change listener. */ 118 116 bool fRegisteredDefaultInputListener; … … 207 205 } 208 206 209 #ifndef VBOX_WITH_AUDIO_CALLBACKS210 static int coreAudioASBDToStreamCfg(AudioStreamBasicDescription *pASBD, PPDMAUDIOSTREAMCFG pCfg)211 {212 AssertPtrReturn(pASBD, VERR_INVALID_PARAMETER);213 AssertPtrReturn(pCfg, VERR_INVALID_PARAMETER);214 215 AssertLogRelMsgReturn(pASBD->mChannelsPerFrame > 0, VERR_NOT_SUPPORTED);216 AssertLogRelMsgReturn(pASBD->mChannelsPerFrame < 16, VERR_NOT_SUPPORTED);217 AssertLogRelMsgReturn( pASBD->mBitsPerChannel == 8218 || pASBD->mBitsPerChannel == 16219 || pASBD->mBitsPerChannel == 32,220 ("%u\n", pASBD->mBitsPerChannel), VERR_NOT_SUPPORTED);221 AssertLogRelMsgReturn(!(pASBD->mFormatFlags & (kAudioFormatFlagIsFloat /** @todo more we don't like?*/)),222 ("%#x\n", pASBD->mFormatFlags), VERR_NOT_SUPPORTED);223 224 PDMAudioPropsInitEx(&pCfg->Props,225 pASBD->mBitsPerChannel / 8,226 RT_BOOL(pASBD->mFormatFlags & kAudioFormatFlagIsSignedInteger),227 pASBD->mChannelsPerFrame,228 (uint32_t)pASBD->mSampleRate,229 RT_BOOL(pASBD->mFormatFlags & kAudioFormatFlagIsBigEndian),230 false /*fRaw*/);231 return VINF_SUCCESS;232 }233 #endif /* !VBOX_WITH_AUDIO_CALLBACKS */234 207 235 208 #if 0 /* unused */ … … 308 281 /** The device is currently uninitializing. */ 309 282 COREAUDIOSTATUS_IN_UNINIT, 310 #ifndef VBOX_WITH_AUDIO_CALLBACKS311 /** The device has to be reinitialized.312 * @note Only needed if VBOX_WITH_AUDIO_CALLBACKS is not defined, as otherwise313 * the Audio Connector will take care of this as soon as this backend314 * tells it to do so via the provided audio callback. */315 COREAUDIOSTATUS_REINIT,316 #endif317 283 /** The usual 32-bit hack. */ 318 284 COREAUDIOSTATUS_32BIT_HACK = 0x7fffffff … … 425 391 * Internal Functions * 426 392 *********************************************************************************************************************************/ 427 #ifndef VBOX_WITH_AUDIO_CALLBACKS428 static int coreAudioStreamReinit(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream, PCOREAUDIODEVICEDATA pDev);429 #endif430 393 static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream); 431 394 … … 626 589 627 590 LogFlowFunc(("pDev=%p\n", pDev)); 628 629 #ifndef VBOX_WITH_AUDIO_CALLBACKS630 if (pDev)631 {632 /* This listener is called on every change of the hardware633 * device. So check if the default device has really changed. */634 UInt32 uSize = sizeof(AudioDeviceID);635 UInt32 uResp = 0;636 637 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, pProperty, 0, NULL, &uSize, &uResp);638 if (err == noErr)639 {640 if (pDev->deviceID != uResp) /* Has the device ID changed? */641 {642 rc2 = coreAudioDevicePropagateStatus(pDev, COREAUDIOSTATUS_REINIT);643 AssertRC(rc2);644 }645 }646 }647 #endif /* VBOX_WITH_AUDIO_CALLBACKS */648 591 } 649 592 … … 652 595 AssertRC(rc2); 653 596 654 #ifdef VBOX_WITH_AUDIO_CALLBACKS655 597 /* Notify the driver/device above us about possible changes in devices. */ 656 598 if (pThis->pIHostAudioPort) 657 599 pThis->pIHostAudioPort->pfnNotifyDevicesChanged(pThis->pIHostAudioPort); 658 #endif659 600 660 601 return noErr; 661 602 } 662 603 663 #ifndef VBOX_WITH_AUDIO_CALLBACKS664 665 /**666 * Re-initializes a Core Audio stream with a specific audio device and stream configuration.667 *668 * @return IPRT status code.669 * @param pThis Driver instance.670 * @param pCAStream Audio stream to re-initialize.671 * @param pDev Audio device to use for re-initialization.672 * @param pCfg Stream configuration to use for re-initialization.673 */674 static int coreAudioStreamReinitEx(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream,675 PCOREAUDIODEVICEDATA pDev, PPDMAUDIOSTREAMCFG pCfg)676 {677 LogFunc(("pCAStream=%p\n", pCAStream));678 679 int rc = coreAudioStreamUninit(pCAStream);680 if (RT_SUCCESS(rc))681 {682 rc = coreAudioStreamInit(pCAStream, pThis, pDev);683 if (RT_SUCCESS(rc))684 {685 rc = coreAudioStreamInitQueue(pCAStream, pCfg /* pCfgReq */, NULL /* pCfgAcq */);686 if (RT_SUCCESS(rc))687 rc = coreAudioStreamControl(pCAStream->pDrv, pCAStream, PDMAUDIOSTREAMCMD_ENABLE);688 689 if (RT_FAILURE(rc))690 {691 int rc2 = coreAudioStreamUninit(pCAStream);692 AssertRC(rc2);693 }694 }695 }696 697 if (RT_FAILURE(rc))698 LogRel(("CoreAudio: Unable to re-init stream: %Rrc\n", rc));699 700 return rc;701 }702 703 /**704 * Re-initializes a Core Audio stream with a specific audio device.705 *706 * @return IPRT status code.707 * @param pThis Driver instance.708 * @param pCAStream Audio stream to re-initialize.709 * @param pDev Audio device to use for re-initialization.710 */711 static int coreAudioStreamReinit(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream, PCOREAUDIODEVICEDATA pDev)712 {713 int rc = coreAudioStreamUninit(pCAStream);714 if (RT_SUCCESS(rc))715 {716 /* Use the acquired stream configuration from the former initialization to717 * re-initialize the stream. */718 PDMAUDIOSTREAMCFG CfgAcq;719 rc = coreAudioASBDToStreamCfg(&pCAStream->Unit.streamFmt, &CfgAcq);720 if (RT_SUCCESS(rc))721 rc = coreAudioStreamReinitEx(pThis, pCAStream, pDev, &CfgAcq);722 }723 724 return rc;725 }726 727 #endif /* !VBOX_WITH_AUDIO_CALLBACKS */728 604 729 605 #ifdef VBOX_WITH_AUDIO_CA_CONVERTER … … 1145 1021 case kAudioDevicePropertyNominalSampleRate: 1146 1022 { 1147 #ifndef VBOX_WITH_AUDIO_CALLBACKS1148 int rc2 = coreAudioDevicePropagateStatus(pDev, COREAUDIOSTATUS_REINIT);1149 AssertRC(rc2);1150 #else1151 1023 RT_NOREF(pDev); 1152 #endif1153 1024 break; 1154 1025 } … … 1984 1855 LogFlowFunc(("enmStreamCmd=%RU32, enmStatus=%RU32\n", enmStreamCmd, enmStatus)); 1985 1856 1986 if (!( enmStatus == COREAUDIOSTATUS_INIT 1987 #ifndef VBOX_WITH_AUDIO_CALLBACKS 1988 || enmStatus == COREAUDIOSTATUS_REINIT 1989 #endif 1990 )) 1857 if (enmStatus != COREAUDIOSTATUS_INIT) 1991 1858 { 1992 1859 return VINF_SUCCESS; … … 2126 1993 2127 1994 uint32_t status = ASMAtomicReadU32(&pCAStream->enmStatus); 2128 if (!( status == COREAUDIOSTATUS_INIT 2129 #ifndef VBOX_WITH_AUDIO_CALLBACKS 2130 || status == COREAUDIOSTATUS_REINIT 2131 #endif 2132 )) 1995 if (status != COREAUDIOSTATUS_INIT) 2133 1996 { 2134 1997 return VINF_SUCCESS; … … 2268 2131 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pStream; 2269 2132 2270 #ifndef VBOX_WITH_AUDIO_CALLBACKS2271 /* Check if the audio device should be reinitialized. If so do it. */2272 if (ASMAtomicReadU32(&pCAStream->enmStatus) == COREAUDIOSTATUS_REINIT)2273 {2274 if (pThis->pDefaultDevOut)2275 {2276 /* For now re just re-initialize with the current output device. */2277 int rc2 = coreAudioStreamReinit(pThis, pCAStream, pThis->pDefaultDevOut);2278 if (RT_FAILURE(rc2))2279 return VERR_NOT_AVAILABLE;2280 }2281 else2282 return VERR_NOT_AVAILABLE;2283 }2284 #else2285 2133 RT_NOREF(pThis); 2286 #endif2287 2134 2288 2135 if (ASMAtomicReadU32(&pCAStream->enmStatus) != COREAUDIOSTATUS_INIT) … … 2381 2228 PDRVHOSTCOREAUDIO pThis = PDMIHOSTAUDIO_2_DRVHOSTCOREAUDIO(pInterface); 2382 2229 2383 #ifndef VBOX_WITH_AUDIO_CALLBACKS2384 /* Check if the audio device should be reinitialized. If so do it. */2385 if (ASMAtomicReadU32(&pCAStream->enmStatus) == COREAUDIOSTATUS_REINIT)2386 {2387 /* For now re just re-initialize with the current input device. */2388 if (pThis->pDefaultDevIn)2389 {2390 int rc2 = coreAudioStreamReinit(pThis, pCAStream, pThis->pDefaultDevIn);2391 if (RT_FAILURE(rc2))2392 return VERR_NOT_AVAILABLE;2393 }2394 else2395 return VERR_NOT_AVAILABLE;2396 }2397 #else2398 2230 RT_NOREF(pThis); 2399 #endif2400 2231 2401 2232 if (ASMAtomicReadU32(&pCAStream->enmStatus) != COREAUDIOSTATUS_INIT) … … 2593 2424 LogRel(("CoreAudio: Failed to add the output default device changed listener: %d (%#x)\n", orc, orc)); 2594 2425 2595 #ifdef VBOX_WITH_AUDIO_CALLBACKS2596 2426 /* 2597 2427 * Query the notification interface from the driver/device above us. 2598 2428 */ 2599 2429 pThis->pIHostAudioPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHOSTAUDIOPORT); 2600 Assert(pThis->pIHostAudioPort); 2601 #endif 2430 AssertReturn(pThis->pIHostAudioPort, VERR_PDM_MISSING_INTERFACE_ABOVE); 2602 2431 2603 2432 #ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
Note:
See TracChangeset
for help on using the changeset viewer.