共用方式為


PKEY_AudioEngine_OEMFormat

在 Windows Vista 和更新版本中, PKEY_AudioEngine_OEMFormat 屬性金鑰會識別音訊端點裝置的預設資料流程格式。 轉譯和擷取裝置都有預設格式。 全域音訊引擎會使用裝置的預設格式連線到裝置以進行共用模式作業。 安裝裝置的 INF 檔案會將裝置的預設格式載入登錄。 使用者可以透過 Windows 多媒體控制台 (Mmsys.cpl) 變更預設格式。 Windows XP 和舊版 Windows 不支援 PKEY_AudioEngine_OEMFormat 屬性索引鍵。

INF 檔案會在該裝置的 add-registry 區段中指定音訊端點裝置的預設格式。 下列 INF 範例顯示將端點裝置的預設格式載入登錄的 add-registry 區段。

;;
;; Identify endpoint device as a set of speakers.
;; Set default format to 48-kHz, 16-bit stereo.
;; Add endpoint extension property page.
;;
[OEMSettingsOverride.AddReg]
HKR,"EP\\0", %PKEY_AudioEndpoint_Association%,,%KSNODETYPE_SPEAKER%
HKR,"EP\\0", %PKEY_AudioEngine_OEMFormat%, %REG_BINARY%, 41,00,00,00,28,00,00,00,
 FE,FF,02,00,80,BB,00,00,00,EE,02,00,04,00,10,00,16,00,10,00,03,00,00,00,01,00,
 00,00,00,00,10,00,80,00,00,AA,00,38,9B,71
HKR,"EP\\0", %PKEY_AudioEndpoint_ControlPanelProvider%,,%AUDIOENDPOINT_EXT_UI_CLSID

上述範例取自 Windows 驅動程式套件中 Sysfx 音訊範例中的 Sysfx.inf 檔案。 此 INF 檔案的 Strings 區段包含下列定義。

PKEY_AudioEndpoint_ControlPanelProvider = "{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F0E},1"
PKEY_AudioEndpoint_Association          = "{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F0E},2"
PKEY_AudioEngine_OEMFormat              = "{E4870E26-3CC5-4CD2-BA46-CA0A9A70ED04},3"

在上述範例中,OEMSettingsOverride.AddReg 的 add-registry 區段名稱是由 Sysfx.inf 中介面安裝區段中的 AddReg 指示詞所定義。 上述範例會將字串 「EP\\\0 ) 」 所識別的端點號碼 0 (數個屬性新增至裝置介面的登錄專案。 (如果裝置介面代表具有多個端點的 波篩選器 ,則其他端點編號為 1、2 等等。) 如需介面安裝區段的詳細資訊,請參閱 INF AddInterface 指示詞。

在 INF 檔案建立三個屬性機碼並將其相關聯的值載入登錄之後,應用程式就可以取得端點裝置的 IPropertyStore 介面來存取屬性。 Windows SDK 中的標頭檔 Mmdeviceapi.h 包含三個屬性索引鍵的 C/C++ 定義。 如需取得 IPropertyStore 介面的詳細資訊,請參閱 Windows SDK 檔中 IMMDevice::OpenPropertyStore 方法的描述。

在上述 INF 範例中, PKEY_AudioEndpoint_Association 屬性金鑰會識別端點裝置的 KS 針腳類別 GUID。 PKEY_AudioEndpoint_ControlPanelProvider屬性索引鍵會識別 COM 介面物件的類別 GUID,該物件會將屬性值提供給端點裝置Mmsys.cpl中的屬性頁。 如需這些屬性索引鍵的詳細資訊,請參閱 Windows SDK 檔。 如需 KS 針腳類別 GUID 的詳細資訊,請參閱 Pin 類別屬性

在上述 INF 範例中,與PKEY_AudioEngine_OEMFormat屬性索引鍵相關聯的屬性值是 48 位元組的REG_BINARY值,其中包含描述格式之一的將IZATION 標記法為時時, 若要計算要與PKEY_AudioEngine_OEMFormat屬性索引鍵建立關聯的REG_BINARY資料值,請在PropVariant結構中內嵌一個 CALCULATEATEXWAVEFORMATEXTENSIBLE結構,並藉由呼叫StgSerializePropVariant函式來序列化PropVariant結構。 如需 PropVariant 結構和 StgSerializePropVariant 函式的詳細資訊,請參閱 Windows SDK 檔。

下列程式碼範例是一個主控台應用程式,可列印出現在上述 INF 範例中的REG_BINARY資料。

//
// Embed a WAVEFORMATEXTENSIBLE structure in a PropVariant
// container, and print the PropVariant structure as a
// serialized stream of bytes in REG_BINARY format.
//

#include <stdio.h>
#include <wtypes.h>
#include <propidl.h>
#include <propvarutil.h>
#include <mmreg.h>
#include <ks.h>
#include <ksmedia.h>

void PrintSerializedFormat(WAVEFORMATEX *pWfx)
{
    HRESULT hr;
    PROPVARIANT var;
    SERIALIZEDPROPERTYVALUE* pVal;
    ULONG cb;

    // Create a VT_BLOB from the WAVEFORMATEX structure.
    var.vt = VT_BLOB;
    var.blob.cbSize = sizeof(*pWfx) + pWfx->cbSize;
    var.blob.pBlobData = (BYTE*)pWfx;

    // Serialize the PROPVARIANT structure. The serialized byte stream
    // will eventually be written to the registry as REG_BINARY data.
    hr = StgSerializePropVariant(&var, &pVal, &cb);
    if (SUCCEEDED(hr))
    {
        // Write the binary data to stdout. Format the output so you can
        // copy and paste it directly into the INF file as REG_BINARY data.
        for (UINT i = 0; i < cb; i++)
        {
            BYTE b = ((BYTE*)pVal)[i];
            wprintf(L"%2.2X,", b);
        }

        wprintf(L"\n");
        CoTaskMemFree(pVal);
    }
}

//
// Use a WAVEFORMATEXTENSIBLE structure to specify the format
// for a 48-kHz, 16-bit, (2-channel) stereo audio stream.
//
void main()
{
    WAVEFORMATEXTENSIBLE wfx;

    wfx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
    wfx.Format.nChannels = 2;
    wfx.Format.nSamplesPerSec = 48000;
    wfx.Format.nAvgBytesPerSec = 4*48000;
    wfx.Format.nBlockAlign = 4;
    wfx.Format.wBitsPerSample = 16;
    wfx.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
    wfx.Samples.wValidBitsPerSample = 16;
    wfx.dwChannelMask = 3;
    wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;

    PrintSerializedFormat(&wfx.Format);
}

上述程式碼範例中的 main 函式會建立一個將預設格式描述為 的一個要描述的 WAVEFORMATEXTENSIBLE 結構。 您可以修改 main 函式來建立一個將端點裝置的預設格式設定為 要描述的一個將建立為一個其一 或二十六進位的 「波 狀結構」或「波狀結構」。

上述程式碼範例中的 PrintSerializedFormat 函式會序列化格式描述,並將序列化格式描述列印為REG_BINARY資料。 您可以複製函式所產生的列印輸出,並將其貼到 INF 檔案中。