VirtualBox

Changeset 89009 in vbox for trunk


Ignore:
Timestamp:
May 12, 2021 12:41:56 PM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioCoreAudio: Made VBOX_WITH_AUDIO_CALLBACKS non-optional. bugref:9890

File:
1 edited

Legend:

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

    r89008 r89009  
    111111     *  Can be NULL if none assigned. */
    112112    PCOREAUDIODEVICEDATA    pDefaultDevOut;
    113 #ifdef VBOX_WITH_AUDIO_CALLBACKS
    114113    /** Upwards notification interface. */
    115114    PPDMIHOSTAUDIOPORT      pIHostAudioPort;
    116 #endif
    117115    /** Indicates whether we've registered default input device change listener. */
    118116    bool                     fRegisteredDefaultInputListener;
     
    207205}
    208206
    209 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    210 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 == 8
    218                           || pASBD->mBitsPerChannel == 16
    219                           || 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 */
    234207
    235208#if 0 /* unused */
     
    308281    /** The device is currently uninitializing. */
    309282    COREAUDIOSTATUS_IN_UNINIT,
    310 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    311     /** The device has to be reinitialized.
    312      * @note Only needed if VBOX_WITH_AUDIO_CALLBACKS is not defined, as otherwise
    313      *       the Audio Connector will take care of this as soon as this backend
    314      *       tells it to do so via the provided audio callback. */
    315     COREAUDIOSTATUS_REINIT,
    316 #endif
    317283    /** The usual 32-bit hack. */
    318284    COREAUDIOSTATUS_32BIT_HACK = 0x7fffffff
     
    425391*   Internal Functions                                                                                                           *
    426392*********************************************************************************************************************************/
    427 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    428 static int coreAudioStreamReinit(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream, PCOREAUDIODEVICEDATA pDev);
    429 #endif
    430393static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream);
    431394
     
    626589
    627590        LogFlowFunc(("pDev=%p\n", pDev));
    628 
    629 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    630         if (pDev)
    631         {
    632             /* This listener is called on every change of the hardware
    633              * 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 */
    648591    }
    649592
     
    652595    AssertRC(rc2);
    653596
    654 #ifdef VBOX_WITH_AUDIO_CALLBACKS
    655597    /* Notify the driver/device above us about possible changes in devices. */
    656598    if (pThis->pIHostAudioPort)
    657599        pThis->pIHostAudioPort->pfnNotifyDevicesChanged(pThis->pIHostAudioPort);
    658 #endif
    659600
    660601    return noErr;
    661602}
    662603
    663 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    664 
    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 to
    717          * 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 */
    728604
    729605#ifdef VBOX_WITH_AUDIO_CA_CONVERTER
     
    11451021        case kAudioDevicePropertyNominalSampleRate:
    11461022        {
    1147 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    1148             int rc2 = coreAudioDevicePropagateStatus(pDev, COREAUDIOSTATUS_REINIT);
    1149             AssertRC(rc2);
    1150 #else
    11511023            RT_NOREF(pDev);
    1152 #endif
    11531024            break;
    11541025        }
     
    19841855    LogFlowFunc(("enmStreamCmd=%RU32, enmStatus=%RU32\n", enmStreamCmd, enmStatus));
    19851856
    1986     if (!(   enmStatus == COREAUDIOSTATUS_INIT
    1987 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    1988           || enmStatus == COREAUDIOSTATUS_REINIT
    1989 #endif
    1990           ))
     1857    if (enmStatus != COREAUDIOSTATUS_INIT)
    19911858    {
    19921859        return VINF_SUCCESS;
     
    21261993
    21271994    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)
    21331996    {
    21341997        return VINF_SUCCESS;
     
    22682131    PCOREAUDIOSTREAM  pCAStream = (PCOREAUDIOSTREAM)pStream;
    22692132
    2270 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    2271     /* 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         else
    2282             return VERR_NOT_AVAILABLE;
    2283     }
    2284 #else
    22852133    RT_NOREF(pThis);
    2286 #endif
    22872134
    22882135    if (ASMAtomicReadU32(&pCAStream->enmStatus) != COREAUDIOSTATUS_INIT)
     
    23812228    PDRVHOSTCOREAUDIO pThis     = PDMIHOSTAUDIO_2_DRVHOSTCOREAUDIO(pInterface);
    23822229
    2383 #ifndef VBOX_WITH_AUDIO_CALLBACKS
    2384     /* 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         else
    2395             return VERR_NOT_AVAILABLE;
    2396     }
    2397 #else
    23982230    RT_NOREF(pThis);
    2399 #endif
    24002231
    24012232    if (ASMAtomicReadU32(&pCAStream->enmStatus) != COREAUDIOSTATUS_INIT)
     
    25932424        LogRel(("CoreAudio: Failed to add the output default device changed listener: %d (%#x)\n", orc, orc));
    25942425
    2595 #ifdef VBOX_WITH_AUDIO_CALLBACKS
    25962426    /*
    25972427     * Query the notification interface from the driver/device above us.
    25982428     */
    25992429    pThis->pIHostAudioPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHOSTAUDIOPORT);
    2600     Assert(pThis->pIHostAudioPort);
    2601 #endif
     2430    AssertReturn(pThis->pIHostAudioPort, VERR_PDM_MISSING_INTERFACE_ABOVE);
    26022431
    26032432#ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
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