IAudioProcessingObjectNotifications2::GetApoNotificationRegistrationInfo2 方法 (audioengineextensionapo.h)

由系统调用,以允许客户端注册以接收 APO 终结点和系统效果通知的通知回调。 此方法的行为与 IAudioProcessingObjectNotifications::GetApoNotificationRegistrationInfo 相同,并添加了一个参数,该参数可用于确定在当前设备上运行的 Windows 版本上支持的通知类型。

语法

HRESULT GetApoNotificationRegistrationInfo2(
        APO_NOTIFICATION_TYPE       maxApoNotificationTypeSupported,
  [out] APO_NOTIFICATION_DESCRIPTOR **apoNotifications,
  [out] DWORD                       *count
);

参数

maxApoNotificationTypeSupported

APO_NOTIFICATION_TYPE 枚举中的 值,指示当前设备上运行的 Windows 版本支持的最高枚举值。 客户端可以使用比较运算符来确定是否支持特定通知类型。

[out] apoNotifications

返回指向 APO_NOTIFICATION_DESCRIPTOR 数组的指针的输出参数,指定请求通知的 APO 更改集。

[out] count

指定 apoNotifications 中返回的项数的输出参数。

返回值

HRESULT。

注解

以下示例演示 GetAppNotificationRegistrationInfo2 的典型实现。 该示例检查 maxApoNotificationTypeSupported 参数的值,以确定当前设备上运行的 Windows 版本是否支持它感兴趣的通知。 如果是,则注册这些通知。

STDMETHODIMP SampleApo::GetApoNotificationRegistrationInfo2(
    UINT32 maxApoNotificationTypeSupported,
    APO_NOTIFICATION_DESCRIPTOR** apoNotificationDescriptorsReturned,
    DWORD* count)
{

    *apoNotificationDescriptorsReturned = nullptr;
    
    *count = 0;
    
    // Before this function can be called, our m_device member variable should already have been initialized.
    // This would typically be done in our implementation of IAudioProcessingObject::Initialize, by using
    // APOInitSystemEffects3::pDeviceCollection to obtain the last IMMDevice in the collection.
    
    RETURN_HR_IF_NULL(E_FAIL, m_device);
    
    if(maxApoNotificationTypeSupported >= APO_NOTIFICATION_TYPE_MICROPHONE_BOOST)
    {
    
        // Let the OS know what notifications we are interested in by returning an array of
        // APO_NOTIFICATION_DESCRIPTORs.
        constexpr DWORD numDescriptors = 3;
        wil::unique_cotaskmem_ptr<APO_NOTIFICATION_DESCRIPTOR[]> apoNotificationDescriptors;
        apoNotificationDescriptors.reset(static_cast<APO_NOTIFICATION_DESCRIPTOR*>(
        CoTaskMemAlloc(sizeof(APO_NOTIFICATION_DESCRIPTOR) * numDescriptors)));
        RETURN_IF_NULL_ALLOC(apoNotificationDescriptors);
        
        // Our APO wants to get notified when the volume level changes on the audio endpoint.
        // The APO_NOTIFICATION_DESCRIPTOR::audioEndpointVolume element is used to specify the audio
        // endpoint for both the APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME and the
        // APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME2 notifications.
        apoNotificationDescriptors[0].type = APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME2;
        (void)m_device.query_to(&apoNotificationDescriptors[0].audioEndpointVolume.device);
        
        // Our APO also wants to get notified when the orientation of the device changes.
        apoNotificationDescriptors[1].type = APO_NOTIFICATION_TYPE_DEVICE_ORIENTATION;
        
        // Our APO also wants to get notified when the microphone boost changes on the audio endpoint.
        apoNotificationDescriptors[2].type = APO_NOTIFICATION_TYPE_MICROPHONE_BOOST;
        (void)m_device.query_to(&apoNotificationDescriptors[2].audioMicrophoneBoost.device);
        
        // The OS will immediately fire a notification for the above notification types, so we do not
        // need to query the OS for the current values.
        
        *apoNotificationDescriptorsReturned = apoNotificationDescriptors.release();
        *count = numDescriptors;
    
    }
    else
    {
        // If we get here, the APO is running on an older version of Windows that does not support the
        // APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME2, APO_NOTIFICATION_TYPE_DEVICE_ORIENTATION, and
        // APO_NOTIFICATION_TYPE_MICROPHONE_BOOST notifications. What the APO does at this point is
        // implementation-specific. For example, the APO may choose to subscribe to the
        // APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME notification instead of
        // APO_NOTIFICATION_TYPE_ENDPOINT_VOLUME2.
    }
    
    return S_OK;

}

在 22621 之前的 Windows 版本中,Windows 将仅调用 IAudioProcessingObjectNotifications::GetApoNotificationRegistrationInfo,而不是 IAudioProcessingObjectNotifications2 上的 方法。 由于在 22621 之前的 Windows 版本上支持的最高通知类型 是APO_NOTIFICATION_TYPE_SYSTEM_EFFECTS_PROPERTY_CHANGE,因此需要在版本 22621 及更早版本上运行的 APO 可以选择通过使用 IAudioProcessingObjectNotifications::GetApoNotificationRegistrationInfo 的以下实现来简化其代码。

STDMETHODIMP SampleApo::GetApoNotificationRegistrationInfo(
    APO_NOTIFICATION_DESCRIPTOR** apoNotificationDescriptorsReturned,
    DWORD* count)
{
    // When the OS invokes GetApoNotificationRegistrationInfo, it implies that the maximum notification value
    // that is supported is APO_NOTIFICATION_TYPE_SYSTEM_EFFECTS_PROPERTY_CHANGE.
    GetApoNotificationRegistrationInfo2(APO_NOTIFICATION_TYPE_SYSTEM_EFFECTS_PROPERTY_CHANGE, apoNotificationDescriptorsReturned, count);
    
    return S_OK;
}

有关音频驱动程序随附的音频处理对象 (API) 的Windows 11 API 的详细信息,请参阅音频处理对象的Windows 11 API

要求

要求
最低受支持的客户端 Windows 内部版本 22621
标头 audioengineextensionapo.h