Quantcast
Channel: Windows API – Fooling Around
Viewing all 49 articles
Browse latest View live

Did you know that: LVN_GETINFOTIP?

$
0
0

Did you know that when you handle LVN_GETINFOTIP notification message and you are provided with NMLVGETINFOTIP structure, you cannot just supply your own pszText string for the tooltip text? Instead you have to copy your string into supplied buffer, such as using _tcsncpy function. Otherwise things would not work.

BEGIN_MSG_MAP_EX(CFooPropertyPage)
	CHAIN_MSG_MAP(CPropertyPageT)
	...
	MSG_LVN_GETINFOTIP(IDC_FOOLISTVIEW, OnFooListViewGetInfoTip) 
	REFLECT_NOTIFICATIONS()
END_MSG_MAP()
...
LRESULT OnFooListViewGetInfoTip(NMLVGETINFOTIP* pHeader)
{
	ATLASSERT(!pHeader->lParam);
	CFoo* pFoo = m_FooListView.GetItemData(pHeader->iItem);
	CString& sTextBuffer = m_ModelListView.GetTextBufferString(TRUE);
	...
	sTextBuffer.TrimRight(_T("\t\n\r "));
	_tcsncpy(pHeader->pszText, sTextBuffer, pHeader->cchTextMax - 1);
	pHeader->pszText[pHeader->cchTextMax - 1] = 0;
	return 0;
}

Enumerating Binary Resource Languages

$
0
0

The small application is a goos sample and useful tool in the same time. It enumerates PE binary resources and counts languages used. Why? Normally you want single language of resources, however Visual Studio IDE does not show you languages in a convenient way and it is so easy to make a language mess which does not bite you immediately but might bring you troubles later. Apart from this there was a suspicion that language mess might cause runtime bugs on UpdateResource API.

The application gets you a summary of languages used and returns with exit code (checkable using e.g. errorlevel) indicating number of languages.

Output is TSV: LANGID, Language Name, Resource Count:

C:\>ListResourceLanguages.exe C:\Windows\syswow64\shell32.dll
1049    Russian 545
1033    English 3318

Download links:

Enumerating Media Foundation Transforms (MFTs)

$
0
0

Matthew van Eerde already made a similar wrapper over MFTEnumEx in How to enumerate Media Foundation transforms on your system, and this one extends it with enumeration of attributes, also listing them in human friendly way.
This sort of code should perhaps have been in Media Foundation SDK Samples, however we have what we have.

Media Foundation Transforms (MFTs) – they are registered and accessed through the registry, being available for enumeration with and without qualifying criteria. Some of the transforms are dual, DMO/MFT, some are MFT only which make their useful functionality not available directly for DirectShow pipeline. Luckily, the interface is similar to those of DMOs and making it reasonably possible to wrap one into another. Comparison of MFTs and DMOs shows how the two form factors compare one to the other.

Enumeration tool/utility shows availability of registered MFTs in the system. In Windows 7. For example, the output in Windows 7 workstation in provided below.

The output is a good cheat sheet for seeing support of media types in Windows components.

Download links:

Category: MFT_CATEGORY_VIDEO_DECODER {D6C02D4B-6833-45B4-971A-05A4B04BAB91}

    DV Decoder MFT #0
        MFT_TRANSFORM_CLSID_Attribute: {404A6DE5-D4D6-4260-9BC7-5A6CBD882432} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC dvc 
            MEDIATYPE_Video FourCC dvhd
            MEDIATYPE_Video FourCC dvsd
            MEDIATYPE_Video FourCC dvsl
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YUY2
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Mpeg4s Decoder MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {5686A0D9-FE39-409F-9DFF-3FDBC849F9F5} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC mp4s
            MEDIATYPE_Video FourCC MP4S
            MEDIATYPE_Video FourCC m4s2
            MEDIATYPE_Video FourCC M4S2
            MEDIATYPE_Video FourCC MP4V
            MEDIATYPE_Video FourCC mp4v
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video FourCC YV12
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Microsoft H264 Video Decoder MFT #2
        MFT_TRANSFORM_CLSID_Attribute: {62CE7E72-4C71-4D20-B15D-452831A87D9D} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC H264
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YUY2
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMV Screen decoder MFT #3
        MFT_TRANSFORM_CLSID_Attribute: {7BAFB3B1-D8F4-4279-9253-27DA423108DE} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC MSS1
            MEDIATYPE_Video FourCC MSS2
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000015-3274-11D0-B724-00AA006C1A01}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMVideo Decoder MFT #4
        MFT_TRANSFORM_CLSID_Attribute: {82D353DF-90BD-4382-8BC2-3F6192B76E34} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC WMV1
            MEDIATYPE_Video FourCC WMV2
            MEDIATYPE_Video FourCC WMV3
            MEDIATYPE_Video FourCC WMVP
            MEDIATYPE_Video FourCC WVP2
            MEDIATYPE_Video FourCC WMVR
            MEDIATYPE_Video FourCC WMVA
            MEDIATYPE_Video FourCC WVC1
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    MJPEG Decoder MFT #5
        MFT_TRANSFORM_CLSID_Attribute: {CB17E772-E1CC-4633-8450-5617AF577905} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC MJPG
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YUY2
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Mpeg43 Decoder MFT #6
        MFT_TRANSFORM_CLSID_Attribute: {CBA9E78B-49A3-49EA-93D4-6BCBA8C4DE07} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC mp43
            MEDIATYPE_Video FourCC MP43
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Mpeg4 Decoder MFT #7
        MFT_TRANSFORM_CLSID_Attribute: {F371728A-6052-4D47-827C-D039335DFE0A} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC MPG4
            MEDIATYPE_Video FourCC mpg4
            MEDIATYPE_Video FourCC mp42
            MEDIATYPE_Video FourCC MP42
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_VIDEO_ENCODER {F79EAC7D-E545-4387-BDEE-D647D7BDE42A}

    H264 Encoder MFT #0
        MFT_TRANSFORM_CLSID_Attribute: {6CA50344-051A-4DED-9779-A43305165E35} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video FourCC YUY2
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC H264
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMVideo8 Encoder MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {7E320092-596A-41B2-BBEB-175D10504EB6} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC YVU9
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC WMV1
            MEDIATYPE_Video FourCC WMV2
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMVideo9 Encoder MFT #2
        MFT_TRANSFORM_CLSID_Attribute: {D23B90D0-144F-46BD-841D-59E4EB19DC59} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC YVU9
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {1D4A45F2-E5F6-4B44-8388-F0AE5C0E0C37}
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC WMV3
            MEDIATYPE_Video FourCC WMVP
            MEDIATYPE_Video FourCC WVP2
            MEDIATYPE_Video FourCC WMVA
            MEDIATYPE_Video FourCC WVC1
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_VIDEO_EFFECT {12E17C21-532C-4A6E-8A1C-40825A736397}

    Frame Rate Converter #0
        MFT_TRANSFORM_CLSID_Attribute: {01F36CE2-0907-4D8B-979D-F151BE91C883} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC YUYV
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC Y411
            MEDIATYPE_Video FourCC Y41P
            MEDIATYPE_Video FourCC Y211
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video {00000015-3274-11D0-B724-00AA006C1A01}
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC YUYV
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC Y411
            MEDIATYPE_Video FourCC Y41P
            MEDIATYPE_Video FourCC Y211
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video {00000015-3274-11D0-B724-00AA006C1A01}
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Resizer MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {1EA1EA14-48F4-4054-AD1A-E8AEE10AC805} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC V216
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC YVU9
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC V216
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC YVU9
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Color Control #2
        MFT_TRANSFORM_CLSID_Attribute: {798059F0-89CA-4160-B325-AEB48EFE4F9A} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC Y41P
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC Y41P
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Color Converter MFT #3
        MFT_TRANSFORM_CLSID_Attribute: {98230571-0087-4204-B020-3282538E57D3} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC V216
            MEDIATYPE_Video FourCC V410
            MEDIATYPE_Video FourCC NV11
            MEDIATYPE_Video FourCC Y41P
            MEDIATYPE_Video FourCC Y41T
            MEDIATYPE_Video FourCC Y42T
            MEDIATYPE_Video FourCC YVU9
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Video FourCC YV12
            MEDIATYPE_Video FourCC YUY2
            MEDIATYPE_Video FourCC UYVY
            MEDIATYPE_Video FourCC AYUV
            MEDIATYPE_Video FourCC NV12
            MEDIATYPE_Video {00000016-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000017-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC I420
            MEDIATYPE_Video FourCC IYUV
            MEDIATYPE_Video FourCC YVYU
            MEDIATYPE_Video {00000014-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000018-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video {00000029-524F-11CE-9F53-0020AF0BA770}
            MEDIATYPE_Video FourCC V216
            MEDIATYPE_Video FourCC V410
            MEDIATYPE_Video FourCC NV11
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_MULTIPLEXER {059C561E-05AE-4B61-B69D-55B61EE54A7B}

Category: MFT_CATEGORY_DEMULTIPLEXER {A8700A7A-939B-44C5-99D7-76226B23B3F1}

Category: MFT_CATEGORY_AUDIO_DECODER {9EA73FB4-EF7A-4559-8D5D-719D8F0426C7}

    WMAudio Decoder MFT #0
        MFT_TRANSFORM_CLSID_Attribute: {2EEB4ADF-4578-4D10-BCA7-BB955F56320A} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000160
            MEDIATYPE_Audio FourCC 0x00000161
            MEDIATYPE_Audio FourCC 0x00000162
            MEDIATYPE_Audio FourCC 0x00000163
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Microsoft AAC Audio Decoder MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {32D186A7-218F-4C75-8876-DD77273A8999} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00001610
            MEDIATYPE_Audio FourCC 0x000000ff
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000003
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    GSM ACM Wrapper MFT #2
        MFT_TRANSFORM_CLSID_Attribute: {4A76B469-7B66-4DD4-BA2D-DDF244C766DC} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000031
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMAPro over S/PDIF MFT #3
        MFT_TRANSFORM_CLSID_Attribute: {5210F8E4-B0BB-47C3-A8D9-7B2282CC79ED} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000162
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000164
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMSpeech Decoder DMO #4
        MFT_TRANSFORM_CLSID_Attribute: {874131CB-4ECC-443B-8948-746B89595D20} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x0000000a
            MEDIATYPE_Audio FourCC 0x0000000b
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    G711 Wrapper MFT #5
        MFT_TRANSFORM_CLSID_Attribute: {92B66080-5E2D-449E-90C4-C41F268E5514} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000007
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    IMA ADPCM ACM Wrapper MFT #6
        MFT_TRANSFORM_CLSID_Attribute: {A16E1BFF-A80D-48AD-AECD-A35C005685FE} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000011
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    MP3 Decoder MFT #7
        MFT_TRANSFORM_CLSID_Attribute: {BBEEA841-0A63-4F52-A7AB-A9B3A84ED38A} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000055
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    ADPCM ACM Wrapper MFT #8
        MFT_TRANSFORM_CLSID_Attribute: {CA34FE0A-5722-43AD-AF23-05F7650257DD} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000002
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_AUDIO_ENCODER {91C64BD0-F91E-4D8C-9276-DB248279D975}

    WM Speech Encoder DMO #0
        MFT_TRANSFORM_CLSID_Attribute: {1F1F4E1A-2252-4063-84BB-EEE75F8856D5} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x0000000a
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    WMAudio Encoder MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {70F598E9-F4AB-495A-99E2-A7C4D3D89ABF} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000161
            MEDIATYPE_Audio FourCC 0x00000162
            MEDIATYPE_Audio FourCC 0x00000163
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Microsoft AAC Audio Encoder MFT #2
        MFT_TRANSFORM_CLSID_Attribute: {93AF0C51-2275-45D2-A35B-F2BA21CAED00} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00001610
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_AUDIO_EFFECT {11064C48-3648-4ED0-932E-05CE8AC811B7}

    AEC #0
        MFT_TRANSFORM_CLSID_Attribute: {745057C7-F353-4F2D-A7EE-58434477730E} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

    Resampler MFT #1
        MFT_TRANSFORM_CLSID_Attribute: {F447B69E-1884-4A7E-8055-346F74D6EDB3} (0x48)
        MFT_INPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MFT_OUTPUT_TYPES_Attributes: 
            MEDIATYPE_Audio FourCC 0x00000001
            MEDIATYPE_Audio FourCC 0x00000003
             (0x1011)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_SYNCMFT (0x13)

Category: MFT_CATEGORY_VIDEO_PROCESSOR {302EA3FC-AA5F-47F9-9F7A-C2188BB16302}

Category: MFT_CATEGORY_OTHER {90175D57-B7EA-4901-AEB3-933A8747756F}

Continuous realloc()

$
0
0

A colleague raised a question that realloc does better than free + malloc because allocated memory block is never being actually shrunk and reallocations to smaller size following by reallocations to larger (but still not larger than one of the previous) do not lead to heap locks and actual underlying heap memory block reallocations.

While this is technically possible within the contract declared by the API, it does not seem to be likely that the runtime will stay reluctant to release unused memory. And what is also highly probable, that heap managers implement advanced tricks to decrease impact of heap locks while doing memory allocations. In the same time, realloc must move the payload data in full to the new memory location in case the reallocated block is moved itself. If this is not required and the block is large, there is an unwanted performance impact to take place.

The details of the API operation are likely to be described somewhere, and another related question might be how to do the measurement programmatically and get a hint of what is going on internally.

PSAPI offers GetProcessMemoryInfo function to obtain process memory metrics, and returned PROCESS_MEMORY_COUNTERS_EX::PrivateUsage field is showing private memory in use. malloc allocated memory is eventually mapped onto process private memory, so the API is good for seeing approximate (because of fragmentation, process memory use is always higher than sum of actually allocated block sizes) memory usage.

If we are going to allocate 1 MB blocks, then reallocate to 1 KB, then allocate additional memory, observing the process private memory usage we will be able to see if realloc does release unused memory.

The code is as simple as:

PrintPrivateUsage();
VOID* ppvItemsA[256];
static const SIZE_T g_nSizeA1 = 1 << 20; // 1 MB
_tprintf(_T("Allocating %d MB\n"), (_countof(ppvItemsA) * g_nSizeA1) >> 20);
for(SIZE_T nIndex = 0; nIndex < _countof(ppvItemsA); nIndex++)
    ppvItemsA[nIndex] = malloc(g_nSizeA1);
PrintPrivateUsage();
static const SIZE_T g_nSizeA2 = 4 << 10; // 4 KB
_tprintf(_T("Reallocating to %d MB\n"), (_countof(ppvItemsA) * g_nSizeA2) >> 20);
for(SIZE_T nIndex = 0; nIndex < _countof(ppvItemsA); nIndex++)
    ppvItemsA[nIndex] = realloc(ppvItemsA[nIndex], g_nSizeA2);
PrintPrivateUsage();
VOID* ppvItemsB[256];
static const SIZE_T g_nSizeB1 = 16 << 10; // 16 MB
_tprintf(_T("Allocating %d MB more\n"), (_countof(ppvItemsB) * g_nSizeB1) >> 20);
for(SIZE_T nIndex = 0; nIndex < _countof(ppvItemsB); nIndex++)
    ppvItemsB[nIndex] = malloc(g_nSizeB1);
PrintPrivateUsage();

And the output is:

PrivateUsage: 0 MB
Allocating 256 MB
PrivateUsage: 258 MB
Reallocating to 1 MB
PrivateUsage: 3 MB // <<--- (*)
Allocating 4 MB more
PrivateUsage: 7 MB

Which shows that reallocating to smaller size involves freeing unused space.

Download links:

PolyTextOut API – Does It Work?

$
0
0

As MSDN says,

The PolyTextOut function draws several strings using the font and text colors currently selected in the specified device context.

The article also mentions ExtTextOut as a simpler sister function:

To draw a single string of text, the application should call the ExtTextOut function.

It looks like the API is not so Unicode friendly. Code as simple as

PolyTextOut(L"Мама мыла раму");
PolyTextOut(L"Mother washed window");
PolyTextOut(L"ママソープフレーム");
PolyTextOut(L"დედა საპნის კარკასი");

ExtTextOut(L"Мама мыла раму");
ExtTextOut(L"Mother washed window");
ExtTextOut(L"ママソープフレーム");
ExtTextOut(L"დედა საპნის კარკასი");

Outputs correctly in case of ExtTextOut, while PolyTextOut stumbles on strings in Japanese, Georgian. All right, so why did it do Russian?

PolyTextOut Sample

Enumeration of DirectShow Capture Capabilities (Video and Audio)

$
0
0

The tool appears to be unmentioned here, and this is to fix the problem.

DirectShowCaptureCapabilities application enumerates video and audio capture devices and lists their typical DirectShow properties, specifically:

  • Moniker names (including USB identification)
  • Pins and property pages
  • Supported interfaces
  • Formats and capabilities available through IAMStreamConfig interface
  • Video and audio devices

DirectShowCaptureCapabilities Screenshot

The utility allows to save output and post it over Internet, what some users already did and here is capabilities of some hardware.

Some of the files might be useful to provide sample data for AM_MEDIA_TYPE structures for typical YUY2, UYVY, MJPG, H264 formats.

Download:

A few direct links to user-submitted output:

 

Registration-Free COM dependencies and COM reference isolation

$
0
0

Visual Studio offers COM reference isolation to applications so that COM dependency is used in a usual way, and in the same time there is no need in its registration or another copy of the COM server might be registered system wide, or using per-user registration, and the application would still prefer a local copy of COM server.

Isolated Property

The advantage is obvious: no more COM registration hell, and the application can be distributed with lowered risk of conflicts with other installed software, without a risk to affect other applications by registering an unwanted piece of software. Also, with an option to use COM dependency without need of elevated privileges to perform COM registration.

The feature is using reg-free COM and is not new. Articles on internet on using the feature date back to 2007 and earlier (e.g. Isolated COM), reg-free COM existed earlier. The feature is cool and offers a one click access to an incredibly powerful option with complicated technology underneath.

Problem 1: It is 2015 fall today and Visual Studio 2013 still does not have this – as complicated as Enabled/Disabled option – working right.

Once enabled, the option has the following effect on the project:

  1. the manifest file is detached from the binary and is written to external file (Client.exe + Client.exe.manifest as opposed to Client.exe with manifest embedded as resource)
  2. the manifest receives assembly/file elements that establish a registration-free link to COM dependency; the content of the element is repeating registration of the COM dependency normally written into registry system wide
  3. the compiler uses RegOverridePredefKey and friends API to check COM dependency registration keys and update the manifest file (see previous item) respectively

Apparently the COM server has to be registered at compile time, so that compiler could convert the registration into manifest file. For whatever reason, Visual Studio 2013 looks for 32-bit COM server when it is doing 64-bit build. That is, building x64 configuration with x64 COM server registered and supposed to be used further fails if you don’t have a similar Win32 COM server registered. Bummer.

This simple solution ComIsolation01 (Trac, SVN) has two projects: C++ COM server with 32 and 64 bit configurations, and C# client consumer. A build of Debug/Release x64 configuration successfully builds Server.dll, registers it, then attempts to build Client.exe and fails:

2>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3284: Cannot get the file path for type library “ae2714e3-e8be-44c7-b737-5510e5f8abed” version 1.0. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
2>D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\ComIsolation01\Client\Program.cs(14,13,14,22): error CS0246: The type or namespace name ‘ServerLib’ could not be found (are you missing a using directive or an assembly reference?)
2>D:\Projects\Alax.Info\Repository-Public\Utilities\Miscellaneous\ComIsolation01\Client\Program.cs(14,51,14,60): error CS0246: The type or namespace name ‘ServerLib’ could not be found (are you missing a using directive or an assembly reference?)

TYPE_E_LIBNOTREGISTERED, really? Because it looks for 32-bit type library and there is only 64-bit one registered. Build Win32 configuration once, and x64 builds are fixed. In other aspects, x64 build of Server.dll is correctly picked up.

Problem 2: Inflexible. The only COM reference isolation offered is a link with size and hash specification of the dependency.

Strict dependency check in manifest file

Why on earth? Okay it might be good for some people, perhaps. The only scenario I want to ever use is a link without checks for whether dependency is exactly as at build time. It is already isolated and the isolated file will be picked up. I would like to retain an option to patch it quickly by simply substituting a new file there, without an annoying need to patch manifest respectively. I don’t have an option like this.

Another post soon will show a solution for the problem, as well as easy way to apply isolation to C++ clients as well.

Logitech C930e camera and Media Foundation

$
0
0

Logitech’s C930e camera is the first one to be compliant with UVC 1.5 specification:

First 1080p HD webcam to support H.264 with Scalable Video Coding and UVC 1.5 encoding technology. […] The result is a smoother video stream in applications like Skype for Business and Microsoft® Lync® 2013.

More marketing information there at Logitech. More interesting is what the new capabilities look from API side programmatically. Additionally to well known Motion JPEG (FourCC MJPG) and YUY2 video, the camera delivers H.264 (FourCC H264) video.

Logitech C930e Webcam

Lync (Skype for Business) is presumably modified to accept that and it communicates to the camera using Media Foundation API.

The camera’s H.264 capabilities are accessible using both APIs, DirectShow and Media Foundation, and there is apparently a mess with driver versions and operating system versions as well. The best results are achieved with stock driver from Microsoft (without installing Logitech driver, this information is in good standing: “The only way I was able to get that stream under Windows 8.x was by NOT USING LOGITECH DRIVERS. This is a UVC 1.5 compatible camera and it will be configured automatically by the OS. With that driver (from Microsoft), use pin 1 (not 0) and you will get a ton of H264 formats.”).

A printout of DirectShow capabilities using DirectShowCaptureCapabilities is available here (note KS_H264VIDEOINFO structure). This time it is about what it looks when one’s doing Media Foundation.

As a Media Source, exposed are a few attributes and a great deal of media types (216 + 476), greater amount compared to DirectShow as it seems:

    • MF_DEVSOURCE_ATTRIBUTE_MEDIA_TYPE: 76 69 64 73 00 00 10 00 80 00 00 AA 00 38 9B 71 59 55 59 32 00 00 10 00 80 00 00 AA 00 38 9B 71
    • MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK: \\?\usb#vid_046d&pid_0843&mi_00#6&2314864d&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global (Type `VT_LPWSTR`)
    • MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME: Logitech Webcam C930e (Type `VT_LPWSTR`)
    • MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY: KSCATEGORY_VIDEO_CAMERA
    • MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE: MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
    • MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_HW_SOURCE: 4 (Type `VT_UI4`)
  • Characteristics: MFMEDIASOURCE_IS_LIVE | MFMEDIASOURCE_CAN_PAUSE
  • Stream 0: Default Selected, Identifier 0x0, Major Type MFMediaType_Video, 216 Media Types
  • Stream 1: Identifier 0x1, Major Type MFMediaType_Video, 476 Media Types

The H.264 formats are marked with subtypes of MFVideoFormat_H264 and MFVideoFormat_H264_ES. A raw print out is downloadable:

Specifically, it is interesting what are the attributes there since with Media Foundation it is tricky thing to find out quickly. The keys/identifiers are listed below.

Common

  • MF_MT_ALL_SAMPLES_INDEPENDENT
  • MF_MT_AM_FORMAT_TYPE
  • MF_MT_AVG_BITRATE
  • MF_MT_FIXED_SIZE_SAMPLES
  • MF_MT_FRAME_RATE
  • MF_MT_FRAME_RATE_RANGE_MAX
  • MF_MT_FRAME_RATE_RANGE_MIN
  • MF_MT_FRAME_SIZE
  • MF_MT_INTERLACE_MODE
  • MF_MT_MAJOR_TYPE
  • MF_MT_PIXEL_ASPECT_RATIO
  • MF_MT_SUBTYPE

MFVideoFormat_H264, MFVideoFormat_H264_ES

  • MF_MT_COMPRESSED
  • MF_MT_H264_CAPABILITIES
  • MF_MT_H264_MAX_CODEC_CONFIG_DELAY
  • MF_MT_H264_MAX_MB_PER_SEC
  • MF_MT_H264_RESOLUTION_SCALING
  • MF_MT_H264_SIMULCAST_SUPPORT
  • MF_MT_H264_SUPPORTED_RATE_CONTROL_MODES
  • MF_MT_H264_SUPPORTED_SLICE_MODES
  • MF_MT_H264_SUPPORTED_SYNC_FRAME_TYPES
  • MF_MT_H264_SUPPORTED_USAGES
  • MF_MT_H264_SVC_CAPABILITIES
  • MF_MT_VIDEO_LEVEL
  • MF_MT_VIDEO_PROFILE

MFVideoFormat_MJPG

  • MF_MT_SAMPLE_SIZE
  • MF_MT_VIDEO_CHROMA_SITING
  • MF_MT_VIDEO_LIGHTING
  • MF_MT_VIDEO_NOMINAL_RANGE
  • MF_MT_VIDEO_PRIMARIES
  • MF_MT_YUV_MATRIX

MFVideoFormat_YUY2

  • MF_MT_DEFAULT_STRIDE
  • MF_MT_SAMPLE_SIZE
  • MF_MT_VIDEO_CHROMA_SITING
  • MF_MT_VIDEO_LIGHTING
  • MF_MT_VIDEO_NOMINAL_RANGE
  • MF_MT_VIDEO_PRIMARIES
  • MF_MT_YUV_MATRIX

Blackmagic Design’s “Decklink Video Capture” filters

$
0
0

Pulling this out from Blackmagic Design Forum thread:

Generally, the recommended interface to the capture cards is the DeckLink API.

A DirectShow interface is available, but provides a subset of the functionality available from the complete DeckLink API.

Please note that the older, user-space DirectShow filters (DeckLink Video Capture) are deprecated in favour of the WDM filters (Blackmagic WDM Capture).

The WDM filters added support for 4K modes in Desktop Video 10.5+.

So the “Decklink Video Capture” filters that wrap the DeckLink SDK and provide convenient DirectShow interface are at their end of life.

Certainly, the most efficient and flexible way to interface Blackmagic Design hardware is to use their SDK (which is good and easy to use), however it does not give the immediate connectivity to Windows APIs. User mode filters were a good wrapper and provided typical functionality for capture and playback. They had their own issues (e.g. no VideoInfo2 support – interlaced formats treated as progressive and no support for progressive formats that collide with interlaces), also some reported 64-bit versions to be not quite stable.

WDM filters are around for some time, specifically they do offer 32-bit audio capture option which the other filters did not have. From what I remember they are lacking other capabilities availalble through SDK (update – e.g. no timecode support).

Apparently WMD filters do not offer playback option via DirectShow. This is not even mentioning the unfortunate Media Foundation – even though “Blackmagic WDM Render” is somehow around and with a certain luck is listed through MFTEnum:

    Blackmagic WDM Render #3
        MFT_ENUM_HARDWARE_URL_Attribute: \\?\decklink#avstream#5&2db0fd5&1&0000#{65e8773e-8f56-11d0-a3b9-00a0c9223196}\decklinkrender1 (Type VT_LPWSTR)
        MFT_INPUT_TYPES_Attributes: 
            MFMediaType_Video MFVideoFormat_UYVY
            MFMediaType_Video MFVideoFormat_v210
            MFMediaType_Video MFVideoFormat_UYVY
            MFMediaType_Video MFVideoFormat_v210
            MFMediaType_Video MFVideoFormat_UYVY
            MFMediaType_Video MFVideoFormat_v210
            MFMediaType_Video MFVideoFormat_UYVY
            MFMediaType_Video MFVideoFormat_v210
            MFMediaType_Video MFVideoFormat_UYVY
            MFMediaType_Video MFVideoFormat_v210
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Video FourCC HDYC
            MFMediaType_Audio MFAudioFormat_PCM
            MFMediaType_Audio MFAudioFormat_PCM
            
        MFT_TRANSFORM_CLSID_Attribute: {8AC3587A-4AE7-42D8-99E0-0A6013EEF90F} (Type VT_CLSID)
        MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_HARDWARE

For more or less serious DirectShow development the best way was and is to wrap the DeckLink SDK with a custom filter and have all options that SDK provides.

CLSID_VideoInputDeviceCategory and Media Foundation

$
0
0

Media Foundation as video capture API is inflexible. At Microsoft – besides standard Media Foundation problems of backward compatibility, availability of developer tools and overall awkwardness – they decided to no longer offer video capture extensibility with Media Foundation. Be happy with MFEnumDeviceSources and don’t go anywhere else. They explain that they already provided support for devices backed by kernel streaming drivers:

Starting in Windows 7, Media Foundation automatically supports audio and video capture devices. For video, the device must provide a kernel streaming (KS) minidriver in the video capture category. Media Foundation uses the PnP path to enumerate the device. For audio, Media Foundation uses the Windows Multimedia Device (MMDevice) API to enumerate audio endpoint devices. If the device meets these criteria, there is no need to implement a custom media source.

The next paragraph there is slyness:

However, you might want to implement a custom media source for some other type of device or other live data source. There are only a few differences between a live source and other media sources.

Indeed, you can implement a custom media source, however you cannot implement a backing object (Media Foundation Transform – see below) that standard media source would use, and you cannot make your own video source discoverable by applications so that a custom video source is a new option for video capture enabled applications using Media Foundation.

Over years developers were eagerly interested in various aspects of video capture om Windows platform using VFW and then DirectShow. Including specifically implementing a virtual camera device, for which Microsoft provided Push Source Filters Sample, which then was extended to popular VCam sample that “publishes” video source device and makes it available to applications enumerating video capture hardware. The latest API, Media Foundation, blocked the opportunity to provide a custom video source.

The interesting thing though is that there is no fundamental problem in allowing such extensibility: just a few pieces are missing.

For starters, MFTEnum enumerates objects in, well, DirectShow’s CLSID_VideoInputDeviceCategory category. This is not documented, but this shows how tightly Media Foundation and DirectShow (and related kernel drivers) are connected.

Category: CLSID_VideoInputDeviceCategory {860BB310-5D01-11D0-BD3B-00A0C911CE86}

Logitech Webcam C930e #0
    MFT_ENUM_HARDWARE_URL_Attribute: \\?\usb#vid_046d&pid_0843&mi_00#6&2314864d&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global (Type VT_LPWSTR)
    MFT_TRANSFORM_CLSID_Attribute: {8AC3587A-4AE7-42D8-99E0-0A6013EEF90F} (Type VT_CLSID)
    MFT_OUTPUT_TYPES_Attributes: 
        MFMediaType_Video MFVideoFormat_YUY2
        MFMediaType_Video MFVideoFormat_MJPG
    MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_HARDWARE

Blackmagic WDM Capture #1
    MFT_ENUM_HARDWARE_URL_Attribute: \\?\decklink#avstream#5&2db0fd5&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\decklinkcapture1 (Type VT_LPWSTR)
    MFT_TRANSFORM_CLSID_Attribute: {8AC3587A-4AE7-42D8-99E0-0A6013EEF90F} (Type VT_CLSID)
    MFT_OUTPUT_TYPES_Attributes: 
        MFMediaType_Video MFVideoFormat_UYVY
        MFMediaType_Video MFVideoFormat_v210
        MFMediaType_Video FourCC HDYC
        MFMediaType_Audio MFAudioFormat_PCM
    MF_TRANSFORM_FLAGS_Attribute: MFT_ENUM_FLAG_HARDWARE

Any questions? What MFEnumDeviceSources API does is enumeration in this category, and building device COM objects on top of existing MFTs. Using MFT for video source is actually a smart move. This should have been of course done in DirectShow many years ago, and with DMOs instead of MFTs.

DirectX Media Objects (DMOs) got a compact and powerful form factor. Video and audio source implementation can be nicely put in “zero input one output” DMO and then used by standard objects on top of that. Similarly to DirectShow DMO Wrapper Filter but for source filters. This was never done in DirectShow, unfortunately. In Media Foundation DMOs got their obese brother class: Media Foundation Transform, which is pretty much the same, just bloated.

This time Media Foundation guys implemented their base block, MFT, over video capture hardware items, which APIs like MFEnumDeviceSources and MFCreateDeviceSource picks up and uses on their backyard.

Frontend code activating media source goes inside to enumerate formats right there to the inner MFT, its IMFTransform::GetOutputAvailableType through standard Media Foundation implementation for video device source, mfcore‘s CDeviceSource class.

MyTransform::GetOutputAvailableType(unsigned long nOutputStreamIdentifier, unsigned long nTypeIndex, IMFMediaType * * ppMediaType) Line 1033 C++
mfcore.dll!CDeviceSource::GetDeviceStreamType(unsigned long) Unknown
mfcore.dll!CDeviceSource::CreateStreams(void) Unknown
mfcore.dll!CDeviceSource::CDeviceSource(struct IMFTransform *,struct _GUID,struct IMFAttributes *,long *) Unknown
mfcore.dll!CDeviceSource::CreateInstance(struct IMFTransform *,struct _GUID,struct IMFAttributes *,struct IMFMediaSource * *) Unknown
mfcore.dll!MFCreateDeviceSource() Unknown

Capture of frames takes place on WinRT worker thread via IMFTransform::ProcessOutput:

MyTransform::ProcessOutput(unsigned long nFlags, unsigned long nBufferCount, MFTOUTPUTDATABUFFER * pBuffers, unsigned long * pnStatus) Line 1281 C++
mfcore.dll!CDeviceSource::OnMFTEventReceived(struct IMFAsyncResult *) Unknown
mfcore.dll!CDeviceSource::OnMFTEventReceivedAsyncCallback::Invoke(struct IMFAsyncResult *) Unknown
RTWorkQ.dll!CSerialWorkQueue::QueueItem::ExecuteWorkItem(struct IMFAsyncResult *) Unknown
RTWorkQ.dll!CBaseWorkQueue::HandleConcurrentMMCSSEnter(class CRealTimeState *) Unknown
ntdll.dll!TppWorkpExecuteCallback() Unknown
ntdll.dll!TppWorkerThread() Unknown
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown

That is, the base building block for video capture in Media Foundation is MFT. Excellent! So do they allow registering your own MFT to provide the applications with a custom video device? Not really. The operation of CDeviceSource and Microsoft’s implementation for the MFT (“Device Proxy MFT”) is based on intimate assumptions between the two, and is not documented. When/if this goes public, we will start implementing virtual cameras the same way we did with good old DirectShow.

Media Foundation Video/Audio Capture Capabilities

$
0
0

Just like with DirectShow video capture capability information, it is helpful to unerstand what Medfia Foudnation video capture offering is exactly. Specifically:

H.264 realated attributes in media types might be not so obvious and device might report too many types.

  • Major Type: MFMediaType_Video
  • Compressed: 1
  • 25 Attributes
    • MF_MT_MAJOR_TYPE: MFMediaTypeVideo
    • MF_MT_SUBTYPE: MFVideoFormatH264ES
    • MF_MT_COMPRESSED: 1 (Type VTUI4)
    • MF_MT_ALL_SAMPLES_INDEPENDENT: 0 (Type VTUI4)
    • MF_MT_FIXED_SIZE_SAMPLES: 0 (Type VTUI4)
    • MF_MT_FRAME_SIZE: 755914244240 (Type VTUI8) // Width 176, Height 144
    • MF_MT_PIXEL_ASPECT_RATIO: 4294967297 (Type VTUI8) // Numerator 1, Denominator 1
    • MF_MT_INTERLACE_MODE: 2 (Type VTUI4) // MFVideoInterlaceProgressive
    • MF_MT_FRAME_RATE: 128849018881 (Type VTUI8) // Numerator 30, Denominator 1
    • MF_MT_FRAME_RATE_RANGE_MIN: 128849018881 (Type VTUI8) // Numerator 30, Denominator 1
    • MF_MT_FRAME_RATE_RANGE_MAX: 128849018881 (Type VTUI8) // Numerator 30, Denominator 1
    • MF_MT_AVG_BITRATE: 6003500 (Type VTUI4)
    • MF_MT_AM_FORMAT_TYPE: {2017BE05-6629-4248-AAED-7E1A47BC9B9C}
    • MF_MT_VIDEO_PROFILE: 257 (Type VTUI4) // eAVEncH264VProfileUCConstrainedHigh
    • MF_MT_VIDEO_LEVEL: 40 (Type VTUI4) // eAVEncH264VLevel4
    • MF_MT_H264_MAX_MB_PER_SEC: F5 00 00 00 00 00 00 00 F5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    • MF_MT_H264_SUPPORTED_USAGES: 3 (Type VTUI4)
    • MF_MT_H264_SUPPORTED_RATE_CONTROL_MODES: 15 (Type VTUI4)
    • MF_MT_H264_SUPPORTED_SYNC_FRAME_TYPES: 10 (Type VTUI4)
    • MF_MT_H264_SIMULCAST_SUPPORT: 0 (Type VTUI4)
    • MF_MT_H264_CAPABILITIES: 40 (Type VTUI4)
    • MF_MT_H264_SUPPORTED_SLICE_MODES: 14 (Type VTUI4)
    • MF_MT_H264_RESOLUTION_SCALING: 3 (Type VTUI4)
    • MF_MT_H264_MAX_CODEC_CONFIG_DELAY: 1 (Type VTUI4)
    • MF_MT_H264_SVC_CAPABILITIES: 1 (Type VTUI4)

MediaFoundationCaptureCapabilities

Download:

Sample Data:

See Also:

Fragile MFEnumDeviceSources

$
0
0

As I mentioned in earlier post, Media Foundation video capture capability is internally using undocumented categories with pretty much the same transforms and enumeration applicable to categories documented.

Without documenting it as public contract, MFEnumDeviceSources enumerates transforms, builds standard implementation for IMFMediaSource on top of available transform and… voila! Media Foundation offers “lightweight” API for video/audio capture. Lightweight presumably stands for “of substandard quality” here. It would be lightweight, if they documented the transforms, the enumeration API, make it extensible, decoupled their media source implementation from the transform, documented the internal communication between the two. However, it seems that there has been no progress in this direction since Windows 7.

The implementation is good in terms that it is implementing the documented promises, however if earlier APIs were developer friendly and well-extensible, here it is just minimal implementation without offering too much to people. Even though it could be extensible, it looks like Microsoft simply decided to not spend effort on pushing it to feature rich state, clean and open to developers.

A simple example: it is still possible to register your own transform into undocumented category. MFEnumDeviceSources implementation does see it, picks it up. Not a hardware transform? No go – we only offer media source functionality for hardware transform (actually for no apparent reason, other than possibly to put a stop to custom extensions). Hardware transform? No go – we cannot accept it for another reason, we only offer media source implementation for hardware transforms we “like”. The most confusing part is that rejection of unsupported transform might cause fatal failure in the enumeration loop: the rejection will make other, supported transforms and devices unavailable to applications. I suppose that once the loop encounters unsupported device, it simply forwards the failure upwards invalidating devices already found and yet to be enumerated. It is not the way the API should be developed, but it is okay – the category remains internal and undocumented.

MediaFoundationVideoEncoderTransforms: Detecting support for hardware H.264 video encoders

$
0
0

H.264 (MPEG-4 Part 10 also known as MPEG-4 AVC) video encoding was never packaged into DirectShow filter by Microsoft and instead they offered Media Foundation Transform (MFT) for the job: H.264 Video Encoder. Further development gave us third party video encoders also packaged as MFTs. Hardware backed MFTs became a part of video hardware drivers and nevertheless are part of Media Foundation API, can also be very well used standalone.

Detection of H.264 encoding capabilities? MediaFoundationVideoEncoderTransforms is here to help.

MediaFoundationVideoEncoderTransforms UI

H.264 options include:

  • H264 Encoder MFT
  • Intel® Quick Sync Video H.264 Encoder MFT
  • NVIDIA H.264 Encoder MFT
  • AMDh264Encoder

H.265 encoding will apparently be (already is) using the same encoder packaging.

The tools enumerates the transforms and provides details, similar to Enumerating Media Foundation Transforms (MFTs) application (source code available).

# System

[…]

# Display Devices <<– Same as in Device Manager

* AMD Radeon R7 200 Series
* Instance: PCI\VEN_1002&DEV_6610&SUBSYS_22BF1458&REV_00\4&2DB3ECDA&0&0008
* DEVPKEY_Device_Manufacturer: Advanced Micro Devices, Inc.
* DEVPKEY_Device_DriverVersion: 15.201.1151.1008
* Intel(R) HD Graphics 530 <<– Video adapter Intel QSV is available through (if you don’t see Intel video, then maybe it needs to be turned on in BIOS)
* Instance: PCI\VEN_8086&DEV_1912&SUBSYS_D0001458&REV_06\3&11583659&0&10
* DEVPKEY_Device_Manufacturer: Intel Corporation
* DEVPKEY_Device_DriverVersion: 20.19.15.4331

# Category `MFT_CATEGORY_VIDEO_ENCODER`

NOTE: Detail is limited to H.264 video encoders.

## Intel® Quick Sync Video H.264 Encoder MFT <<– The guy that does Intel QSV encoding

[…]

## H264 Encoder MFT <<– Stock Microsoft software H.264 implementation, available since Windows 7

[…]

(Other encoders like those from AMD, Nvidia will also be listed)

## Intel® Hardware H265 Encoder MFT <<– Intel also provides now H.265 hardware encoding option

[…]

## H265 Encoder MFT

[…]

Download links

ManifestComDependency: Adding/Removing Registration-Free COM dependencies

$
0
0

In one of the earlier posts I mentioned a problem with registration-free COM dependency setup up by Visual Studio as a part of build process. This post is about the tool that offers an alternate solution for the problems, and also gives more:

  • standalone, independent from build, addition/removal registration-free COM links
  • automation of registration-free COM links for native code builds

Unless one deals with ACTCTX activation contexts programmatically, taking advantage of registration-free COM is essentially a setup of respective side-by-side manifests, either standalone or embedded into executable. The manifests override standard global COM object lookup procedure and point to COM servers directly, in some way similar to the way static links to exported DLL functions work.

To enable, registration-free COM reference COM client needs to prepare respective manifest file (declare an assembly) and list its COM dependencies. The COM dependency list is not just COM server files but rather their COM classes and type libraries. That is, when it comes to automation, the tool needs to go over the COM servers and extract respective identifiers, so that it could properly shape this information and include into manifest XML.

To deal with the challenge, I am using ManifestComDependency tool (no better came to mind when it was created). The command line tool syntax is the following:

 ManifestComDependency <path> [options]
 
 Options:
  * /i[:<assembly-name>] - updates <assemblyIdentity> element replacing it with automatically generated
  * /a[:tc] <dependency-path>[|LIBID[;X.Y]] - adds file <dependency-path> dependency, optionally without type library and COM classes reference
  * /r <dependency-path> - removes dependency from file <dependency-path>
  * /e <export-path> - exports manifest to file <export-path>

The tool opens a file <path> for manifest modification. The file can be a binary file, such as .exe or .dll, in which case the tool will be working with embedded manifest resource. Or, if the path extension is .manifest or .xml, then the file is treated as standalone XML manifest file. Both options are good for manifests associated with .NET builds as well, even though this surely does not need to be managed code development – native COM consumers are okay.

/i option updates <assemblyIdentity> element in the manifest data because it is mandatory and in the same time it might so happen that it is missing or incomplete, which ends up in painful troubleshooting. The tool will name file name, architecture and version information from the binary resource information (product version; the VERSIONINFO resource has to be present).

ManifestComDependency Output

/a option adds a dependency, defined by either path or registered type library identifier the tool would use to resolve the path. t and c modifiers exclude type library and COM server information respectively. The tool created a file element for the dependency and populates it with COM servers discovered there. Type library is obtained using LoadTypeLib API and COM servers are picked up by a trick with RegOverridePredefKey and friends (e.g. see example in regsvr42 source or GraphStudioNext source – both are excellent sources of code snippets for the curious).

The task of COM server discovery assumes load of the library into process (LoadLibrary API call), which assumes bitness match between the tool and the loaded module. This is where you need both Win32 and x64 builds of the tool: if wrong bitness is detected, the tool restarts its sister build passing respective command line arguments, just like regsvr32 does with the only difference that regsvr32 uses binaries in system32 and syswow64 directories, and my tool looks for -Win32 and -x64 suffixes and the files in the same directory.

/r option removes dependencies by name. It is safe to remove certain dependency before adding it back because addition does not check if dependency already exists.

/e option writes the current version of the manifest in external file, esp. for review and troubleshooting if the actual manifest is embedded.

The order of options is important because they are executed one by one in the order of appearance. Then the result is saved/re-embedded once all tasks are done.

Command line example of re-adding registration-free COM dependencies:

ManifestComDependency-x64.exe BatchExport-x64.exe /i /r Player.dll /r mp4demux.dll /a Player.dll /a mp4demux.dll

This can be set as post-build event in the project settings, or put into batch file or run on-demand.

Download links

Making development fun


Certificate Enrollment API Adventures

$
0
0

IX509PrivateKey::Export exports key data from COM object, MSDN:

strExportType [in]

A BSTR value that specifies how the private key is exported.

If the key was created by using a CNG KSP (Key Storage Provider), you can specify one of the values allowed by the pszBlobType parameter in the NCryptExportKey function.

If the key was created by using a CryptoAPI CSP (Cryptographic Service Provider), you can specify one of the following values from the Bcrypt.h header file included with Wincrypt.h.
BCRYPT_PUBLIC_KEY_BLOB – Exports only the public portion of the private key.
BCRYPT_
PRIVATE_KEY_BLOB – Exports the entire private key.

Well this is actually accurate, however trying to make it…

CComPtr<IX509PrivateKey> pPrivateKey;
// ...
CComBSTR sPublicKeyBlob, sPrivateKeyBlob;
ATLENSURE_SUCCEEDED(pPrivateKey->Export(BCRYPT_PUBLIC_KEY_BLOB, XCN_CRYPT_STRING_BASE64, &sPublicKeyBlob));
ATLENSURE_SUCCEEDED(pPrivateKey->Export(BCRYPT_PRIVATE_KEY_BLOB, XCN_CRYPT_STRING_BASE64, &sPrivateKeyBlob));

… the both calls result in E_POINTER (0x80004003). The first argument is not just LPCWSTR. It has to be BSTR and the API is checking the length of the value using SysStringLen. One has to wrap the argument to provide it as BSTR:

CComPtr<IX509PrivateKey> pPrivateKey;
// ...
CComBSTR sPublicKeyBlob, sPrivateKeyBlob;
ATLENSURE_SUCCEEDED(pPrivateKey->Export(CComBSTR(BCRYPT_PUBLIC_KEY_BLOB), XCN_CRYPT_STRING_BASE64, &sPublicKeyBlob));
ATLENSURE_SUCCEEDED(pPrivateKey->Export(CComBSTR(BCRYPT_PRIVATE_KEY_BLOB), XCN_CRYPT_STRING_BASE64, &sPrivateKeyBlob));

Another problem is related to IObjectId::InitializeFromAlgorithmName.

strAlgorithmName [in]

A BSTR variable that contains the name. You can specify a name, or an OID in dotted decimal format. The method verifies that the format is consistent with the ASN.1 X.208 standard. For more information about CNG algorithm names, see CNG Algorithm Identifiers.

MSDN offers choices to provide a string or OID. Unfortunately, OID does not work and fails on internal argument validation with E_INVALIDARG (0x80070057).

ATLENSURE_SUCCEEDED(pObjectId->InitializeFromAlgorithmName(XCN_CRYPT_HASH_ALG_OID_GROUP_ID, 
    XCN_CRYPT_OID_INFO_PUBKEY_ANY, AlgorithmFlagsNone, 
        CComBSTR(L"SHA256"))); //CComBSTR(szOID_RSA_SHA256RSA)));

How to create Virtual Webcam in Windows 10?

$
0
0

(this is a re-post from StackOverflow)

Virtual webcam is typically a software only implementation that application discover as if it is a device with physical representation. The mentioned applications use APIs to work with web cameras and ability to extend the APIs and add your own video source is the way to create a virtual web camera.

In Windows there are a few APIs to consume video sources: Video for Windows, DirectShow, Media Foundation (in chronological order).

Video for Windows is not really extensible and limited in capabilities overall. It will see a virtual device if you provide a kernel mode driver for a virtual camera.

DirectShow is the API used by most video capture enabled Windows applications and it is present in all Windows versions including Windows 10 (except just Windows RT). Then it’s perfectly extensible and in most cases the term “virtual webcam” refers to DirectShow virtual webcam. Methods to create DirectShow virtual webcam discussed in many StackOverflow questions remain perfectly valid for Windows 10, for applications that implement video capture using DirectShow:

DirectShow samples were removed from Windows SDK but you can still find them in older releases:

If you provide a kernel mode driver for video camera device (your virtual webcam through custom kernel driver), DirectShow would also see it just like other video APIs.

Media Foundation is a supposed successor of DirectShow but its video capture capabilities in the part of extensibility simply do not exist. Microsoft decided to not allow custom video sources application would be able to discover the same way as web cameras. Due to Media Foundation complexity, and overhead and overall unfriendliness it is used by modest amount of applications. To implement a virtual webcam for Media Foundation application you again, like in case of Video for Windows, have to implement a kernel mode driver.

Signing with CryptoAPI using Certificate and Detached Private Key

$
0
0

Use of separated certificate and private key might be confusing without understanding how parts or CryptoAPI are related one to another. Apparently, CryptSignMessage and friends require private key in order to create a digital signature.

It is not a problem when private key resides right in the signing certificate (such as, for example, imported with PFXImportCertStore):

CRYPT_SIGN_MESSAGE_PARA Parameters;
ZeroMemory(&Parameters, sizeof Parameters);
Parameters.cbSize = sizeof Parameters;
Parameters.dwMsgEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
Parameters.pSigningCert = CertificateContext; // <<--- Certificate with Private Key
// ...

Things get more complicated when the certificate does not contain the private key. API’s error is CRYPT_E_NO_KEY_PROPERTY which is described as follows:

“The pSigningCert in *pSignPara does not have a CERT_KEY_PROV_INFO_PROP_ID or CERT_KEY_CONTEXT_PROP_ID property.”

CERT_KEY_PROV_INFO_PROP_ID is a property to be defined with certificate context and it expects a structure of type CRYPT_KEY_PROV_INFO. The other one, CERT_KEY_CONTEXT_PROP_ID takes a CERT_KEY_CONTEXT structure.

Even though described as “The CRYPT_KEY_PROV_INFO structure contains information about a key container within a cryptographic service provider (CSP).” and “The CERT_KEY_CONTEXT structure contains data associated with a CERT_KEY_CONTEXT_PROP_ID property.” respectively, it is not well clear to see where the key is attached exactly.

The missing part is that the private key is not something to be provided explicitly. Instead, the key is to be pre-loaded into provider and then this provider is associated with CERT_KEY_CONTEXT structure, which goes as a property value, which in turn is added to signing certificate context, whcih finally gets used for creating a digital signature.

__E(CryptStringToBinary(sPrivateKeyBlob, (DWORD) wcslen(sPrivateKeyBlob), CRYPT_STRING_BASE64_ANY, pnData, &nDataSize, NULL, NULL));
// ...
CCryptProvider Provider;
__E(Provider.AcquireContext(NULL, NULL, PROV_RSA_FULL, 0));
CCryptKey Key;
Key.Attach(Provider.ImportKey(pnData, nDataSize));
__E(Key);
// ...
CERT_KEY_CONTEXT KeyContext;
ZeroMemory(&KeyContext, sizeof KeyContext);
KeyContext.cbSize = sizeof KeyContext;
KeyContext.hCryptProv = Provider; // <<--- Here we go, ooh
KeyContext.dwKeySpec = AT_SIGNATURE;
CertificateContext.SetProperty(CERT_KEY_CONTEXT_PROP_ID, &KeyContext);

“… you will never get the same high quality video experience that you find with DirectShow”

$
0
0

Microsoft’s James Daily wrote back in 2011 (and it’s an incredible response in the public forum from MS guy – provided that DirectShow branch of the same forum did not see anything close for 10+ years) about how technologies relate one to another:

Hey, I’m the team’s DShow expert. Trevor asked me to take a look at your post and give my two cents. From looking at the DShow code that you are using in your winforms application I just want you to be aware that by including quartz.dll as a dependency you are using the DirectShow 8 OLE automation objects. These objects have been deprecated for years and are certainly not recommended [this might perhaps be not accurate enough because generally stuff in quartz.dll is not deprecated, it’s rather orphaned and yet waits it deprecation like related stuff from qedit.dll; however the overall attitude is about right – RR]. At this time Microsoft does not have a supported solution for calling DirectShow code from C# (or any managed language). Please see the “note” at the top of the page at the link below for documented confirmation of this. Because the technology is not supported from the winforms environment it is not possible for us to suggest a supported workaround from managed code.

That said it should be possible to facilitate the functionality that you are looking for by creating a custom EVR presenter. By using a custom presenter you can get direct access to the D3D surface. You can then use the standard D3D constructs to draw directly to the same D3D surface that the EVR is using to blit the video. There are two things to keep in mind about this solution. First you must code this solution in unmanaged C++. Again this is due to the fact that DirectShow is not supported from managed code. Second, this solution is extremely complex and difficult to implement even for the most experienced DirectShow / D3D expert. Because of these two factors it is recommended that you take a serious look at the MediaElement in WPF.

As you know the WPF environment is constructed from the ground up to offer developers a very rich “graphics first” environment. The MediaElement in particular was designed to allow you to mix video with various other UI components seamlessly. This solution will give you the flicker free, “draw over video” solution that you are looking for. The best part is you can do all of this in C#. The bad part of this solution is that the MediaElement is not designed for displaying time sensitive media content. In other words, the MediaElement is notorious for dropping and delaying the display of video frames. There are ways to minimize this such as using SD rather than HD content, use a video accelerated codec, etc. However, you will never get the same high quality video experience that you find with DirectShow.

I hope this will help you understand the current shortcomings of the technologies that you have chosen and help you to focus your efforts on a fully supported and viable solution. If you need any additional clarification please let us know.

and then also:

Unfortunately you can’t really tell the WPF MediaElement to never drop frames. The term we use for this class of issues is “disparate clocks”. In this case WPF is updating the screen at a certain rate (clock 1). The MediaElement (based on WMP) is cranking out video frames at a slightly different rate (clock 2). Given the underlying technologies there is currently no way to synchronize the two clocks and force them to “tick” at the same rate. Since the display will only be updated according to the WPF clock, multiple frames of video may be sent from the MediaElement to WPF between clock ticks. Because of this the MediaElement may appear to drop frames. This is a very common problem in multimedia development and there is no simple solution.

So if you absolutely need frame accuracy in your application then using the MediaElement probably won’t work for you. That said, there are some things that you can do to improve the chances of your content dropping as few frames as possible. Modify your content so that it uses either the h.264 or VC1 codec. Require your users to have modern video HW capable of advanced video acceleration. Use the MPEG 4 or ASF file container. When encoding your content set your frame rate at or below 25 frames per second. Set the resolution of your content to something like 720×480. Set the bitrate to VBR constrained and set an upper limit of between 500 Kbps and 2.5 Mbps.

If you use the guidelines above you will minimize the number of frames that get dropped but you will never be able to completely eliminate them. Also keep in mind that the same frames may not be dropped. For example: if you play video1.asf the first time you might drop frames 200 and 375. On the next run of the same file you may drop frames 143, 678 and 901. This is due to the relatively nondeterministic nature of the Windows OS.

I hope this helps.

Another commenter responded rather angrily:

…fail to include any mention of the DirectShow.NET library. Why? And shame on them for failing to do so. This library helps you use DirectShow in a managed context. There are plenty of code samples to be found….

The answer to this, however, was given in the same thread above a couple of times and explains that the responses are limited by existing policy:

I cannot comment on 3rd party libraries.

Because the technology is not supported from the winforms environment it is not possible for us to suggest a supported workaround…

Video for Windows API and Multiple Cameras

$
0
0

A StackOverflow question (already deleted) asked about use of indices when referencing Video for Windows (VFW) capture devices such as in capGetDriverDescription API and other. Video capture with Video for Windows allowed use of up to 10 devices (did anyone have that many at that time?). The numbering was API specific and at the latest stage the documentation described it as:

Plug-and-Play capture drivers are enumerated first, followed by capture drivers listed in the registry, which are then followed by capture drivers listed in SYSTEM.INI.

Even though it is a legacy API, and the API was really really simple and limited in capabilities, it still exists in all Windows versions, there is still some code running, and due to complexity of modern APIs some people still use it in VB.NET and C# projects.

There is, however, a trap involved if someone attempts to use multiple cameras using VFW. VFW drivers are no longer developed since… Let us see what VirtualDub says about dates and how ancient they are:

The newer type of video capture driver in Windows uses the Windows Driver Model (WDM), which was introduced in Windows 98 and 2000. The Microsoft DirectShow API is the primary API to use these drivers. Because the DirectShow API supports a larger variety of commands and settings than VFW, the functionality set of a WDM driver is significantly improved.

DirectShow is a much more complex API than VFW, however, and WDM-model drivers historically have been a lot less stable than their VFW counterparts. It is not unusual to see problems such as capture applications that cannot be closed, because their program execution is stuck in the capture driver. WDM is the proscribed driver model going forward, however, so the situation should improve over time.

All new drivers were WDM drivers for 15+ years. In order to provide backward compatibility later between VFW and WDM, Microsoft came out with Microsoft WDM Image Capture (Win32) driver. Windows versions up to Windows 10 include it, and it is the only VFW driver in the system. In turn, it manages one of existing WDM-driver devices of choice and exposes video capture functionality to VFW applications. If there are two or more WDM drivers, the VFW driver offers to choose between the devices.

VFW Capture Source Dialog

The screenshot displays a long standing bug with this driver: it offers choices of all registered DirectShow video capture devices (it enumerates CLSID_VideoInputDeviceCategory category) and reality is that it can only work with WDM devices and not other (more on this below).

VirtualDub has a mention of this driver as well:

If you have a Windows Driver Model (WDM) driver installed, you may also have an entry in the device list called Microsoft WDM Image Capture (Win32) (VFW). This entry comes from a Microsoft driver called VFWWDM32 and is a wrapper that allows WDM-model drivers to be used through the older Video for Windows (VFW) API. The WDM driver that is adapted can be selected through the Video Source driver dialog.

There are unfortunately some quirks in the way this adapter works, and some video capture devices will work erratically or not at all through this wrapper. Device settings not accessible through VFW will also still not be available when using it. If possible, use the capture device directly in DirectShow mode rather than using the VFWWDM32 driver.

This is works pretty nice with VFW API and applications. Even though the are all ancient and deprecated years ago, the system still has bridge to newer devices and applications can leverage their functionality. The problem is that there is only one VFW driver, and its index is zero. If you need two cameras you’re busted.

VFWWDM32 itself does not use any system exclusive resources and there is no reason why its different instances could not be configured with different WDM devices. However, VFWWDM32 is a simple old wrapper, either thread unsafe or such as implemented as singleton. People complain the operation with two cameras is impossible or unstable. It is still possible to run two different processes (such as, for example, VirtualDub) with two completely different VFWWDM32’s which do not interfere because of process boundary and run fine. WDM device is selected using capDlgVideoSource interactively, developers had hard time to do selection programmatically.

The interesting part is how VFWWDM32 does video capture using WDM. It is a cut corner in development: instead of doing simple DriectShow graph with Source –> Renderer, or Source –> Sample Grabber -> Renderer topology, where the wrapper would easily support all DriectShow video devices, including virtual, they decided to implement it this way:

VFWWDM Filter Graph

One filter graph, where the filter is the WDM Video Capture Filter for device in question.

  • the graph is CLSID_FilterGraphPrivateThread type, FINALLY it is found what this undocumented flavor of DirectShow fitler graph is used for
  • source filter output pins are not terminated, not connected to anything else
  • the graph is never run

Instead, VFWWDM32 uses some private undocumented communication to the WDM filter internals to run the device and receive frames.

Bottom line: VFW is a backward compatibility layer now on top DirectShow. DirectShow and Media Foundation both use WDM drivers to access video capture devices. Artificial constrain caused by simplistic implementation of VFWWDM driver is a limit of one video camera per process at a time.

Viewing all 49 articles
Browse latest View live