Converting Between Format Tags and Subformat GUIDs

The guidelines for handling non-PCM WAVE_FORMAT_EXTENSIBLE formats are similar to those for non-PCM formats that are specified by wave-format tags. Specifically, a WAVE_FORMAT_EXTENSIBLE format should have a pin factory separate from the factory for PCM formats, and it requires its own data-range intersection handler.

The audio format for a WAVE_FORMAT_EXTENSIBLE format is specified by the GUID in the SubFormat member of the KSDATAFORMAT structure. Every registered wave-format tag has a corresponding subformat GUID, which is generated by the DEFINE_WAVEFORMATEX_GUID macro in Ksmedia.h. For example, the GUID corresponding to the WAVE_FORMAT_DOLBY_AC3_SPDIF tag is defined as DEFINE_WAVEFORMATEX_GUID(WAVE_FORMAT_DOLBY_AC3_SPDIF).

This code snippet from Ksmedia.h shows how to define a new GUID as an autoinitialized static variable:


#define STATIC_KSDATAFORMAT_SUBTYPE_WAVEFORMATEX \
 0x00000000L, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
DEFINE_GUIDSTRUCT("00000000-0000-0010-8000-00aa00389b71", KSDATAFORMAT_SUBTYPE_WAVEFORMATEX);
#define KSDATAFORMAT_SUBTYPE_WAVEFORMATEX DEFINE_GUIDNAMED(KSDATAFORMAT_SUBTYPE_WAVEFORMATEX)

These macros from Ksmedia.h convert between wave-format tags and their associated GUIDs:


#if !defined( DEFINE_WAVEFORMATEX_GUID )
#define DEFINE_WAVEFORMATEX_GUID(x) \
    (USHORT)(x), 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
#endif

#define INIT_WAVEFORMATEX_GUID(Guid, x) \
{ \
    *(Guid) = KSDATAFORMAT_SUBTYPE_WAVEFORMATEX; \
    (Guid)->Data1 = (USHORT)(x); \
}

#define IS_VALID_WAVEFORMATEX_GUID(Guid) \
    (!memcmp(((PUSHORT)&KSDATAFORMAT_SUBTYPE_WAVEFORMATEX) + 1, \
    ((PUSHORT)(Guid)) + 1, sizeof(GUID) - sizeof(USHORT)))

#define EXTRACT_WAVEFORMATEX_ID(Guid)(USHORT)((Guid)->Data1)

The sample code below combines these techniques to create a subformat GUID that is based on the wave-format tag WAVE_FORMAT_AC3_SPDIF, which has the value 0x0092:


#define STATIC_KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF \
    DEFINE_WAVEFORMATEX_GUID(WAVE_FORMAT_DOLBY_AC3_SPDIF)

DEFINE_GUIDSTRUCT("00000092-0000-0010-8000-00aa00389b71",
    KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF);

#define KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF \
    DEFINE_GUIDNAMED(KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF)
...
INIT_WAVEFORMATEX_GUID(pMyGuid,myWaveFormatTag);
...
if (IS_VALID_WAVEFORMATEX_GUID(aWaveFormatExGuidPtr)) {
    aWaveFormatTag = EXTRACT_WAVEFORMATEX_ID(aWaveFormatExGuidPtr);
}

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft