实现 IAdapterPowerManagement

为驱动程序实现 IAdapterPowerManagement 接口时,请参阅 Microsoft Windows 驱动程序工具包 (WDK) 中示例音频驱动程序中的 CAdapterCommon 类的实现。 此类会处理设备中断并执行所有音频适配器驱动程序通用的其他功能。 适配器的 CAdapterCommon 类应继承自 IAdapterPowerManagement 接口,并在其 NonDelegatingQueryInterface 方法中支持此接口。 (有关非委派接口的详细信息,请参阅 INonDelegatingUnknown 接口的说明。)

可以使用头文件 Portcls.h 中的 IMP_IAdapterPowerManagement 定义将 IAdapterPowerManagement::PowerChangeStateIAdapterPowerManagement::QueryPowerChangeStateIAdapterPowerManagement::QueryDeviceCapabilities 方法的函数声明添加到驱动程序的 CAdapterCommon 类定义中。

在 PortCls 系统驱动程序调用适配器的设备启动例程(请参阅启动设备)期间,适配器应通过调用 PcRegisterAdapterPowerManagement 向 PortCls 注册其 IAdapterPowerManagement 接口。 有关代码示例,请参阅 Sysvad 示例驱动程序中的 StartDevice 函数,该函数在示例音频驱动程序中进行了讨论。 PcRegisterAdapterPowerManagement 函数的第一个参数是指向适配器驱动程序的 CAdapterCommon 对象的 IUnknown 指针。 PortCls 会查询此对象以获取其 IAdapterPowerManagement 接口。

当 PortCls 调用适配器驱动程序的 IAdapterPowerManagement::PowerChangeState 方法以更改设备的电源状态时,适配器驱动程序应在适配器的 CAdapterCommon 对象中缓存设备的新电源状态。 在 CAdapterCommon::Init 调用(请参阅 WDK 的示例适配器驱动程序中的实现)期间,驱动程序应在从成功的初始化返回之前将初始电源状态设置为 PowerDeviceD0(在 DeviceState 中介绍)。 仅当已知驱动程序处于适当电源状态时,它才应写入硬件。

在关闭电源以响应 PowerChangeState 调用之前,适配器驱动程序应将音频输出置于可防止在电源关闭时产生扬声器噪音的状态。 例如,关闭过程可能包括将 DAC 输出逐步降至零,关闭 DAC,并将 MIDI 线静音。