Media Foundation学习笔记(三)Media Foundation的架构 基本对象类型

基本对象类型

 

 

Attributes

 

一个Attribute就是一个“键”-“值”对,其中“键”是一个GUID,“值”是一个PROPVARIANT。在Media Foundation中,Attributes被广泛地用于配置对象、描述媒体格式、查询对象属性和其他目的。

“值”只能是这7种类型:UINT32、UINT64、64-bits浮点数、GUID、null结尾的宽字符串、字节数组和IUnknown指针,被定义在MF_ATTRIBUTE_TYPE中:

typedefenum _MF_ATTRIBUTE_TYPE { 
  MF_ATTRIBUTE_UINT32    = VT_UI4,
  MF_ATTRIBUTE_UINT64    = VT_UI8,
  MF_ATTRIBUTE_DOUBLE    = VT_R8,
  MF_ATTRIBUTE_GUID      = VT_CLSID,
  MF_ATTRIBUTE_STRING    = VT_LPWSTR,
  MF_ATTRIBUTE_BLOB      = VT_VECTOR | VT_UI1,
  MF_ATTRIBUTE_IUNKNOWN  = VT_UNKNOWN
} MF_ATTRIBUTE_TYPE;

IMFAttributes口:设置和获取Attribute。例如:IMFAttributes::SetUINT32

MFCreateAttributes:创建一个空的Attribute

创建、设置和读取Attribute的例子:

externconst GUID MY_ATTRIBUTE;

HRESULT ShowCreateAttributeStore(IMFAttributes **ppAttributes)
{
    IMFAttributes *pAttributes = NULL;
const UINT32 cElements = 10;  // Starting size.

// Create the empty attribute store.
    HRESULT hr = MFCreateAttributes(&pAttributes, cElements);

// Set the MY_ATTRIBUTE attribute with a string value.
if (SUCCEEDED(hr))
    {
        hr = pAttributes->SetString(
            MY_ATTRIBUTE,
            L"This is a string value"
            );
    }

// Return the IMFAttributes pointer to the caller.
if (SUCCEEDED(hr))
    {
        *ppAttributes = pAttributes;
        (*ppAttributes)->AddRef();
    }

    SAFE_RELEASE(pAttributes);

return hr;
}

HRESULT ShowGetAttributes()
{
    IMFAttributes *pAttributes = NULL;
    WCHAR *pwszValue = NULL;
    UINT32 cchLength = 0;

// Create the attribute store.
    HRESULT hr = ShowCreateAttributeStore(&pAttributes);

// Get the attribute.
if (SUCCEEDED(hr))
    {
        hr = pAttributes->GetAllocatedString(
            MY_ATTRIBUTE,
&pwszValue,
&cchLength
            );
    }

    CoTaskMemFree(pwszValue);
    SAFE_RELEASE(pAttributes);

return hr;
}

 

序列化Attribute

序列化为字节数组:使用MFGetAttributesAsBlobMFInitAttributesFromBlob

序列化到一个实现了Istream接口的stream对象:使用MFSerializeAttributesToStreamMFDeserializeAttributesFromStream


 

Media Types

 

Media Type描述了媒体流的格式。类似DShow中的AM_MEDIA_TYPE

 

接口:IMFMediaType。这个接口从IMFAttributes继承而来。

 

MFCreateMediaType:创建一个新的MediaType。新的MediaType没有任何Attributes。

 

Media Type一些通用Attributes:

1.“键”MF_MT_MAJOR_TYPE:类似Dshow的AM_MEDIA_TYPE结构体中的majortype成员;“值”MFMediaType_Video类似Dshow的MEDIATYPE_Video

2. “键”MF_MT_SUBTYPE类似Dshow的AM_MEDIA_TYPE结构体中的subtype成员;“值”MFVideoFormat_RGB24类似Dshow的MEDIASUBTYPE_H264

 

Dshow中的媒体类型结构体和Media Foundation中的Media Type的转换:

 

AM_MEDIA_TYPE转MediaType互:MFInitMediaTypeFromAMMediaType

BITMAPINFOHEADER转Media Type:MFCreateVideoMediaTypeFromBitMapInfoHeaderEx

VIDEOINFOHEADER转Media Type:MFInitMediaTypeFromVideoInfoHeader

VIDEOINFOHEADER2转Media Type:MFInitMediaTypeFromVideoInfoHeader2

WAVEFORMATEXWAVEFORMATEXTENSIBLE转Media Type:MFInitMediaTypeFromWaveFormatEx

 

MediaType转AM_MEDIA_TYPEIMFMediaType::GetRepresentationMFCreateAMMediaTypeFromMFMediaTypeMFInitAMMediaTypeFromMFMediaType

MediaType转VIDEOINFOHEADERVIDEOINFOHEADER2IMFMediaType::GetRepresentation

MediaType转WAVEFORMATEXWAVEFORMATEXTENSIBLEMFCreateWaveFormatExFromMFMediaType

 

Dshow中的媒体类型结构体成员和Media Foundation中的Attributes的对应关系:

 

AM_MEDIA_TYPE结构体:

Member

Attribute

bTemporalCompression

MF_MT_ALL_SAMPLES_INDEPENDENT

bFixedSizeSamples

MF_MT_FIXED_SIZE_SAMPLES

lSampleSize

MF_MT_SAMPLE_SIZE

WAVEFORMATEX, WAVEFORMATEXTENSIBLE结构体:

Member

Attribute

wFormatTag

MF_MT_SUBTYPE If wFormatTag is WAVE_FORMAT_EXTENSIBLE, the subtype is found in the SubFormat member.

nChannels

MF_MT_AUDIO_NUM_CHANNELS

nSamplesPerSec

MF_MT_AUDIO_SAMPLES_PER_SECOND

nAvgBytesPerSec

MF_MT_AUDIO_AVG_BYTES_PER_SECOND

nBlockAlign

MF_MT_AUDIO_BLOCK_ALIGNMENT

wBitsPerSample

MF_MT_AUDIO_BITS_PER_SAMPLE

wValidBitsPerSample

MF_MT_AUDIO_VALID_BITS_PER_SAMPLE

wSamplesPerBlock

MF_MT_AUDIO_SAMPLES_PER_BLOCK

dwChannelMask

MF_MT_AUDIO_CHANNEL_MASK

SubFormat

MF_MT_SUBTYPE

Extra data

MF_MT_USER_DATA


VIDEOINFOHEADER, VIDEOINFOHEADER2结构体:

Member

Attribute

dwBitRate

MF_MT_AVG_BITRATE

dwBitErrorRate

MF_MT_AVG_BIT_ERROR_RATE

AvgTimePerFrame

MF_MT_FRAME_RATE; useMFAverageTimePerFrameToFrameRate to calculate this value.

dwInterlaceFlags

MF_MT_INTERLACE_MODE

dwCopyProtectFlags

No defined equivalent

dwPictAspectRatioX, dwPictAspectRatioY

MF_MT_PIXEL_ASPECT_RATIO; must convert from picture aspect ratio to picture aspect ratio.

dwControlFlags

MF_MT_PAD_CONTROL_FLAGS. If the AMCONTROL_COLORINFO_PRESENT flag is present, set the extended color attributes described in Extended Color Information.

bmiHeader.biWidth, bmiHeader.biHeight

MF_MT_FRAME_SIZE

bmiHeader.biBitCount

Implicit in the subtype (MF_MT_SUBTYPE).

bmiHeader.biCompression

Implicit in the subtype.

bmiHeader.biSizeImage

MF_MT_SAMPLE_SIZE

Palette information

MF_MT_PALETTE

The following attributes can be inferred from theVIDEOINFOHEADER orVIDEOINFOHEADER2 structure but also require some knowledge of the format details. For example, different YUV formats have different stride requirements.

MF_MT_DEFAULT_STRIDE

MF_MT_MINIMUM_DISPLAY_APERTURE

MF_MT_PAN_SCAN_APERTURE

 

一些有用的针对Media Type对象的函数:

 

 

MFAverageTimePerFrameToFrameRate

Calculates the frame rate from the average duration of a video frame.

MFCalculateImageSize

Retrieves the image size for an uncompressed video format.

MFCompareFullToPartialMediaType

Compares a full media type to a partial media type.

MFCreateMediaType

Creates an empty media type.

MFFrameRateToAverageTimePerFrame

Converts a video frame rate into a frame duration.

MFGetStrideForBitmapInfoHeader

Retrieves the minimum surface stride for a video format.

MFIsFormatYUV

Queries whether a FOURCC code or D3DFORMAT value is a YUV format.

MFValidateMediaTypeSize

Validates the size of a buffer for a video format block.

MFWrapMediaType

Creates a media type that wraps another media type.

 

调试打印Media Type对象的函数:

#include 

LPCWSTR GetGUIDNameConst(const GUID& guid);
HRESULT GetGUIDName(const GUID& guid, WCHAR **ppwsz);

HRESULT LogAttributeValueByIndex(IMFAttributes *pAttr, DWORD index);
HRESULT SpecialCaseAttributeValue(GUID guid, const PROPVARIANT& var);

void DBGMSG(PCWSTR format, ...);

HRESULT LogMediaType(IMFMediaType *pType)
{
    UINT32 count = 0;

    HRESULT hr = pType->GetCount(&count);
if (FAILED(hr))
    {
return hr;
    }

if (count == 0)
    {
        DBGMSG(L"Empty media type.\n");
    }

for (UINT32 i = 0; i < count; i++)
    {
        hr = LogAttributeValueByIndex(pType, i);
if (FAILED(hr))
        {
break;
        }
    }
return hr;
}

HRESULT LogAttributeValueByIndex(IMFAttributes *pAttr, DWORD index)
{
    WCHAR *pGuidName = NULL;
    WCHAR *pGuidValName = NULL;

    GUID guid = { 0 };

    PROPVARIANT var;
    PropVariantInit(&var);

    HRESULT hr = pAttr->GetItemByIndex(index, &guid, &var);
if (FAILED(hr))
    {
goto done;
    }

    hr = GetGUIDName(guid, &pGuidName);
if (FAILED(hr))
    {
goto done;
    }

    DBGMSG(L"\t%s\t", pGuidName);

    hr = SpecialCaseAttributeValue(guid, var);
if (FAILED(hr))
    {
goto done;
    }
if (hr == S_FALSE)
    {
switch (var.vt)
        {
case VT_UI4:
            DBGMSG(L"%d", var.ulVal);
break;

case VT_UI8:
            DBGMSG(L"%I64d", var.uhVal);
break;

case VT_R8:
            DBGMSG(L"%f", var.dblVal);
break;

case VT_CLSID:
            hr = GetGUIDName(*var.puuid, &pGuidValName);
if (SUCCEEDED(hr))
            {
                DBGMSG(pGuidValName);
            }
break;

case VT_LPWSTR:
            DBGMSG(var.pwszVal);
break;

case VT_VECTOR | VT_UI1:
            DBGMSG(L"<>");
break;

case VT_UNKNOWN:
            DBGMSG(L"IUnknown");
break;

default:
            DBGMSG(L"Unexpected attribute type (vt = %d)", var.vt);
break;
        }
    }

done:
    DBGMSG(L"\n");
    CoTaskMemFree(pGuidName);
    CoTaskMemFree(pGuidValName);
    PropVariantClear(&var);
return hr;
}

HRESULT GetGUIDName(const GUID& guid, WCHAR **ppwsz)
{
    HRESULT hr = S_OK;
    WCHAR *pName = NULL;

    LPCWSTR pcwsz = GetGUIDNameConst(guid);
if (pcwsz)
    {
        size_t cchLength = 0;

        hr = StringCchLength(pcwsz, STRSAFE_MAX_CCH, &cchLength);
if (FAILED(hr))
        {
goto done;
        }

        pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR));

if (pName == NULL)
        {
            hr = E_OUTOFMEMORY;
goto done;
        }

        hr = StringCchCopy(pName, cchLength + 1, pcwsz);
if (FAILED(hr))
        {
goto done;
        }
    }
else
    {
        hr = StringFromCLSID(guid, &pName);
    }

done:
if (FAILED(hr))
    {
        *ppwsz = NULL;
        CoTaskMemFree(pName);
    }
else
    {
        *ppwsz = pName;
    }
return hr;
}

void LogUINT32AsUINT64(const PROPVARIANT& var)
{
    UINT32 uHigh = 0, uLow = 0;
    Unpack2UINT32AsUINT64(var.uhVal.QuadPart, &uHigh, &uLow);
    DBGMSG(L"%d x %d", uHigh, uLow);
}

float OffsetToFloat(const MFOffset& offset)
{
return offset.value + (static_cast(offset.fract) / 65536.0f);
}

HRESULT LogVideoArea(const PROPVARIANT& var)
{
if (var.caub.cElems OffsetX), OffsetToFloat(pArea->OffsetY), 
        pArea->Area.cx, pArea->Area.cy);
return S_OK;
}

// Handle certain known special cases.
HRESULT SpecialCaseAttributeValue(GUID guid, const PROPVARIANT& var)
{
if ((guid == MF_MT_FRAME_RATE) || (guid == MF_MT_FRAME_RATE_RANGE_MAX) ||
        (guid == MF_MT_FRAME_RATE_RANGE_MIN) || (guid == MF_MT_FRAME_SIZE) ||
        (guid == MF_MT_PIXEL_ASPECT_RATIO))
    {
// Attributes that contain two packed 32-bit values.
        LogUINT32AsUINT64(var);
    }
elseif ((guid == MF_MT_GEOMETRIC_APERTURE) || 
             (guid == MF_MT_MINIMUM_DISPLAY_APERTURE) || 
             (guid == MF_MT_PAN_SCAN_APERTURE))
    {
// Attributes that an MFVideoArea structure.
return LogVideoArea(var);
    }
else
    {
return S_FALSE;
    }
return S_OK;
}

void DBGMSG(PCWSTR format, ...)
{
    va_list args;
    va_start(args, format);

    WCHAR msg[MAX_PATH];

if (SUCCEEDED(StringCbVPrintf(msg, sizeof(msg), format, args)))
    {
        OutputDebugString(msg);
    }
}

#ifndef IF_EQUAL_RETURN
#define IF_EQUAL_RETURN(param, val) if(val == param) return L#val
#endif

LPCWSTR GetGUIDNameConst(const GUID& guid)
{
    IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
    IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
    IF_EQUAL_RETURN(guid, MF_MT_SUBTYPE);
    IF_EQUAL_RETURN(guid, MF_MT_ALL_SAMPLES_INDEPENDENT);
    IF_EQUAL_RETURN(guid, MF_MT_FIXED_SIZE_SAMPLES);
    IF_EQUAL_RETURN(guid, MF_MT_COMPRESSED);
    IF_EQUAL_RETURN(guid, MF_MT_SAMPLE_SIZE);
    IF_EQUAL_RETURN(guid, MF_MT_WRAPPED_TYPE);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_NUM_CHANNELS);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_SECOND);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FLOAT_SAMPLES_PER_SECOND);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_AVG_BYTES_PER_SECOND);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BLOCK_ALIGNMENT);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BITS_PER_SAMPLE);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_VALID_BITS_PER_SAMPLE);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_BLOCK);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_CHANNEL_MASK);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FOLDDOWN_MATRIX);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKREF);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKTARGET);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGREF);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGTARGET);
    IF_EQUAL_RETURN(guid, MF_MT_AUDIO_PREFER_WAVEFORMATEX);
    IF_EQUAL_RETURN(guid, MF_MT_AAC_PAYLOAD_TYPE);
    IF_EQUAL_RETURN(guid, MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION);
    IF_EQUAL_RETURN(guid, MF_MT_FRAME_SIZE);
    IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE);
    IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MAX);
    IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MIN);
    IF_EQUAL_RETURN(guid, MF_MT_PIXEL_ASPECT_RATIO);
    IF_EQUAL_RETURN(guid, MF_MT_DRM_FLAGS);
    IF_EQUAL_RETURN(guid, MF_MT_PAD_CONTROL_FLAGS);
    IF_EQUAL_RETURN(guid, MF_MT_SOURCE_CONTENT_HINT);
    IF_EQUAL_RETURN(guid, MF_MT_VIDEO_CHROMA_SITING);
    IF_EQUAL_RETURN(guid, MF_MT_INTERLACE_MODE);
    IF_EQUAL_RETURN(guid, MF_MT_TRANSFER_FUNCTION);
    IF_EQUAL_RETURN(guid, MF_MT_VIDEO_PRIMARIES);
    IF_EQUAL_RETURN(guid, MF_MT_CUSTOM_VIDEO_PRIMARIES);
    IF_EQUAL_RETURN(guid, MF_MT_YUV_MATRIX);
    IF_EQUAL_RETURN(guid, MF_MT_VIDEO_LIGHTING);
    IF_EQUAL_RETURN(guid, MF_MT_VIDEO_NOMINAL_RANGE);
    IF_EQUAL_RETURN(guid, MF_MT_GEOMETRIC_APERTURE);
    IF_EQUAL_RETURN(guid, MF_MT_MINIMUM_DISPLAY_APERTURE);
    IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_APERTURE);
    IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_ENABLED);
    IF_EQUAL_RETURN(guid, MF_MT_AVG_BITRATE);
    IF_EQUAL_RETURN(guid, MF_MT_AVG_BIT_ERROR_RATE);
    IF_EQUAL_RETURN(guid, MF_MT_MAX_KEYFRAME_SPACING);
    IF_EQUAL_RETURN(guid, MF_MT_DEFAULT_STRIDE);
    IF_EQUAL_RETURN(guid, MF_MT_PALETTE);
    IF_EQUAL_RETURN(guid, MF_MT_USER_DATA);
    IF_EQUAL_RETURN(guid, MF_MT_AM_FORMAT_TYPE);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG_START_TIME_CODE);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG2_PROFILE);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG2_LEVEL);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG2_FLAGS);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG_SEQUENCE_HEADER);
    IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_0);
    IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_0);
    IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_1);
    IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_1);
    IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_SRC_PACK);
    IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_PACK);
    IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER);
    IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_FORMAT);
    IF_EQUAL_RETURN(guid, MF_MT_IMAGE_LOSS_TOLERANT); 
    IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION);
    IF_EQUAL_RETURN(guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY);
    IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC); 
    IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG);

// Media types

    IF_EQUAL_RETURN(guid, MFMediaType_Audio);
    IF_EQUAL_RETURN(guid, MFMediaType_Video);
    IF_EQUAL_RETURN(guid, MFMediaType_Protected);
    IF_EQUAL_RETURN(guid, MFMediaType_SAMI);
    IF_EQUAL_RETURN(guid, MFMediaType_Script);
    IF_EQUAL_RETURN(guid, MFMediaType_Image);
    IF_EQUAL_RETURN(guid, MFMediaType_HTML);
    IF_EQUAL_RETURN(guid, MFMediaType_Binary);
    IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer);

    IF_EQUAL_RETURN(guid, MFVideoFormat_AI44); //     FCC('AI44')
    IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32); //   D3DFMT_A8R8G8B8 
    IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV); //     FCC('AYUV')
    IF_EQUAL_RETURN(guid, MFVideoFormat_DV25); //     FCC('dv25')
    IF_EQUAL_RETURN(guid, MFVideoFormat_DV50); //     FCC('dv50')
    IF_EQUAL_RETURN(guid, MFVideoFormat_DVH1); //     FCC('dvh1')
    IF_EQUAL_RETURN(guid, MFVideoFormat_DVSD); //     FCC('dvsd')
    IF_EQUAL_RETURN(guid, MFVideoFormat_DVSL); //     FCC('dvsl')
    IF_EQUAL_RETURN(guid, MFVideoFormat_H264); //     FCC('H264')
    IF_EQUAL_RETURN(guid, MFVideoFormat_I420); //     FCC('I420')
    IF_EQUAL_RETURN(guid, MFVideoFormat_IYUV); //     FCC('IYUV')
    IF_EQUAL_RETURN(guid, MFVideoFormat_M4S2); //     FCC('M4S2')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MJPG);
    IF_EQUAL_RETURN(guid, MFVideoFormat_MP43); //     FCC('MP43')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MP4S); //     FCC('MP4S')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MP4V); //     FCC('MP4V')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MPG1); //     FCC('MPG1')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MSS1); //     FCC('MSS1')
    IF_EQUAL_RETURN(guid, MFVideoFormat_MSS2); //     FCC('MSS2')
    IF_EQUAL_RETURN(guid, MFVideoFormat_NV11); //     FCC('NV11')
    IF_EQUAL_RETURN(guid, MFVideoFormat_NV12); //     FCC('NV12')
    IF_EQUAL_RETURN(guid, MFVideoFormat_P010); //     FCC('P010')
    IF_EQUAL_RETURN(guid, MFVideoFormat_P016); //     FCC('P016')
    IF_EQUAL_RETURN(guid, MFVideoFormat_P210); //     FCC('P210')
    IF_EQUAL_RETURN(guid, MFVideoFormat_P216); //     FCC('P216')
    IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24); //    D3DFMT_R8G8B8 
    IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32); //    D3DFMT_X8R8G8B8 
    IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555); //   D3DFMT_X1R5G5B5 
    IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565); //   D3DFMT_R5G6B5 
    IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8);
    IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY); //     FCC('UYVY')
    IF_EQUAL_RETURN(guid, MFVideoFormat_v210); //     FCC('v210')
    IF_EQUAL_RETURN(guid, MFVideoFormat_v410); //     FCC('v410')
    IF_EQUAL_RETURN(guid, MFVideoFormat_WMV1); //     FCC('WMV1')
    IF_EQUAL_RETURN(guid, MFVideoFormat_WMV2); //     FCC('WMV2')
    IF_EQUAL_RETURN(guid, MFVideoFormat_WMV3); //     FCC('WMV3')
    IF_EQUAL_RETURN(guid, MFVideoFormat_WVC1); //     FCC('WVC1')
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y210); //     FCC('Y210')
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y216); //     FCC('Y216')
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y410); //     FCC('Y410')
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y416); //     FCC('Y416')
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y41P);
    IF_EQUAL_RETURN(guid, MFVideoFormat_Y41T);
    IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2); //     FCC('YUY2')
    IF_EQUAL_RETURN(guid, MFVideoFormat_YV12); //     FCC('YV12')
    IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU);

    IF_EQUAL_RETURN(guid, MFAudioFormat_PCM); //              WAVE_FORMAT_PCM 
    IF_EQUAL_RETURN(guid, MFAudioFormat_Float); //            WAVE_FORMAT_IEEE_FLOAT 
    IF_EQUAL_RETURN(guid, MFAudioFormat_DTS); //              WAVE_FORMAT_DTS 
    IF_EQUAL_RETURN(guid, MFAudioFormat_Dolby_AC3_SPDIF); //  WAVE_FORMAT_DOLBY_AC3_SPDIF 
    IF_EQUAL_RETURN(guid, MFAudioFormat_DRM); //              WAVE_FORMAT_DRM 
    IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8); //        WAVE_FORMAT_WMAUDIO2 
    IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9); //        WAVE_FORMAT_WMAUDIO3 
    IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudio_Lossless); // WAVE_FORMAT_WMAUDIO_LOSSLESS 
    IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF); //         WAVE_FORMAT_WMASPDIF 
    IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1); //             WAVE_FORMAT_WMAVOICE9 
    IF_EQUAL_RETURN(guid, MFAudioFormat_MP3); //              WAVE_FORMAT_MPEGLAYER3 
    IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG); //             WAVE_FORMAT_MPEG 
    IF_EQUAL_RETURN(guid, MFAudioFormat_AAC); //              WAVE_FORMAT_MPEG_HEAAC 
    IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); //             WAVE_FORMAT_MPEG_ADTS_AAC 

return NULL;
}


 

Media Buffers

Media Buffer对象用于管理内存块,用于Pipeline组件之间移动数据。应用程序只有在开发pipeline组件和不通过Media Session直接使用Pipeline组件这2种情况下,才需要使用Media Buffer对象。

 

接口:IMFMediaBuffer

 

创建对象:MFCreateMemoryBuffer或者MFCreateAlignedMemoryBuffer

 

非压缩图像的缓冲区:对于Direct3D表面这样的非压缩图像,可以使用IMF2DBuffer接口。MFCreateDXSurfaceBuffer可以创建DirectX表面对象,该对象实现了IMFMediaBuffer和IMF2DBuffer接口。

 

 

Media Samples

 

一个MediaSample对象存储了一个视频帧或者一个音频帧。一个Media Sample包含了0个或者多个Buffer,例如:在.asf文件中,一个视频帧通常就是由多个asf包组成。

 

接口:IMFSample。

 

创建对象:MFCreateSample;

添加Buffer:IMFSample::AddBuffer。

 

 

 

 

你可能感兴趣的:(MediaFundation)