共用方式為


與 HD 音訊編解碼器通訊動詞

當您定義音訊配接器的音效拓撲時,Hdau.exe針腳組態工具會使用IOCTL_AZALIABUS_SENDVERBS IOCTL。 請勿將此 IOCTL 用於其他用途。 提供IOCTL_AZALIABUS_SENDVERBS的相關資訊,只記載其設計和實作。 Windows 7 Hdaudio.sys音訊類別驅動程式支援此 IOCTL。

高畫質 (HD) 音訊編解碼器能夠接收和回應動詞。 這些動詞和這些動詞的編解碼器回應記載為 HD 音訊規格的一部分。

在 Windows 7 和更新版本的 Windows 作業系統中,HD 音訊類別驅動程式會使用 IOCTL_AZALIABUS_SENDVERBS IOCTL 與音訊編解碼器通訊動詞。 IOCTL_AZALIABUS_SENDVERBS的定義如下列範例所示:

#define IOCTL_AZALIABUS_SENDVERBS CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)

如需FILE_DEVICE_UNKNOWN、METHOD_BUFFERED和FILE_ANY_ACCESS的詳細資訊,請參閱 Windows SDK 中的 Devioctl.h 標頭檔。

若要起始與音訊編解碼器的通訊,類別驅動程式會使用下列參數呼叫 DeviceIoControl 函 式。

BOOL DeviceIoControl(
  (HANDLE) hDevice,                      // handle to device
  IOCTL_AZALIABUS_SENDVERBS,             // dwIoControlCode
  NULL,                                  // lpInBuffer
  0,                                     // nInBufferSize
  (LPVOID) lpOutBuffer,                  // output buffer
  (DWORD) nOutBufferSize,                // size of output buffer
  (LPDWORD) lpBytesReturned,             // number of bytes returned
  (LPOVERLAPPED) lpOverlapped            // OVERLAPPED structure
);

如果 呼叫 DeviceIoControl 成功,則會傳回非零值。 如果呼叫失敗或擱置 (未立即處理) , DeviceIoControl 會傳回零值。 類別驅動程式可以呼叫 GetLastError 以取得更詳細的錯誤訊息。

當音訊驅動程式必須變更釘選組態預設值時,可以使用 IOCTL_AZALIABUS_SENDVERBS,從音訊編解碼器傳送和接收 Set 和 Get 動詞命令。 如果與音訊編解碼器的通訊不是關於釘選組態,音訊編解碼器只會回應 Get 動詞命令。

下列範例示範採用 AzCorbeEntry 結構和 HANDLE 作為參數的函式,並從編解碼器傳回 AzRirbResponse。

AzRirbEntry SendVerb(HANDLE handle, AzCorbEntry verb)
{
  UserModeCodecCommandPacket c;
  UserModeCodecResponsePacket r;
  c.NumCommands = 1;
  c.Command[0] = verb;
  DWORD BytesReturned;

//A nonzero value is returned for a successful call and it is interpreted as TRUE  
BOOL rc = DeviceIoControl(handle, IOCTL_AZALIABUS_SENDVERBS, &c, sizeof(c), &r, sizeof(r), &BytesReturned, 0);

  if(!rc)
  {
    printf("Failed to communicate with the device!\n");
    return 0;
  }

  if(BytesReturned != sizeof(r))
  {
    printf("Wrong number of bytes returned!\n");
    return 0;
  }

  return r.Response[0];
}

先前程式碼範例中使用的資料類型和結構定義于下列範例中:

AzCorbEntry

struct AzCorbEntry
{
  ULONG Verb        : 20; // 0:19
  ULONG NodeId      : 7;  // 20:26
  ULONG IndirectNID : 1;  // 27
  ULONG LinkId      : 4;  // 28:31
  enum {Invalid = 0xffffffff};
  AzCorbEntry(ULONG x = 0)
  :
    Verb(x),
    NodeId(x >> 20),
    IndirectNID(x >> 27),
    LinkId(x >> 28) {}
  operator ULONG()
  {
    return Verb | NodeId << 20 | IndirectNID << 27 | LinkId << 28;
  }
};

AzRirbEntry

struct AzRirbEntry
{
  union
  {
    struct 
    {
      ULONG Response  : 21; // 0 : 20
      ULONG SubTag    : 5; // 21 : 25
      ULONG Tag       : 6; // 26 : 31
    } UnsolicitedForm;

    ULONG Response    : 32; // 0:31
  };
  ULONG Sdi         : 4;  // 32:35
  ULONG Unsolicited : 1;  // 36
  ULONG Reserved0   : 26; // 37:62
  ULONG Valid       : 1;  // 63 note this bit only exists
                          // on the "link". The fact that the response
                          // got into memory assures that it is valid
  AzRirbEntry (ULONGLONG x = 0)
  {
    Response = x & 0xffffffff;
    Sdi = x >> 32;
    Unsolicited = x >> 36;
    Reserved0 = x >> 37;
    Valid = x >> 63;
  }
  operator ULONGLONG()
  {
    return (ULONGLONG)Response | (ULONGLONG)Sdi << 32 | (ULONGLONG)Unsolicited << 36 | (ULONGLONG)Reserved0 << 37 | (ULONGLONG)Valid << 63;
  }
};

下列兩個結構會與動詞傳輸 IOCTL 搭配使用,以啟用音訊驅動程式與 HD 音訊編解碼器之間的命令和回應傳輸。

UserModeCodecCommandPacket

typedef struct _UserModeCodecCommandPacket
{
  ULONG NumCommands;      // number of commands in this packet
  AzCorbEntry Command[1]; // variable length array of verbs
} UserModeCodecCommandPacket;

UserModeCodecResponsePacket

typedef struct _UserModeCodecResponsePacket
{
  ULONG NumResponses;       // on successful IOCTL, this will be updated with the number of responses.
  AzRirbEntry Response[1];  // Variable length array of responses. lpOutBuffer param to DeviceIoControl
                            // must point to sufficient space to hold this IOCTL with all its responses 
} UserModeCodecResponsePacket;