UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MicrosoftCommon.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "VideoCommon.h"
7
8#if PLATFORM_MICROSOFT
9
10namespace AVEncoder
11{
12
13inline const FString GetComErrorDescription(HRESULT Res)
14{
15 const uint32 BufSize = 4096;
16 WIDECHAR buffer[4096];
18 nullptr,
19 Res,
21 buffer,
22 sizeof(buffer) / sizeof(*buffer),
23 nullptr))
24 {
25 return buffer;
26 }
27 else
28 {
29 return TEXT("[cannot find error description]");
30 }
31}
32
34
35// macro to deal with COM calls inside a function that returns `false` on error
36#define CHECK_HR(COM_call)\
37 {\
38 HRESULT Res = COM_call;\
39 if (FAILED(Res))\
40 {\
41 UE_LOG(LogAVEncoder, Error, TEXT("`" #COM_call "` failed: 0x%X - %s"), Res, *GetComErrorDescription(Res));\
42 return false;\
43 }\
44 }
45
46// macro to deal with COM calls inside a function that returns `{}` on error
47#define CHECK_HR_DEFAULT(COM_call)\
48 {\
49 HRESULT Res = COM_call;\
50 if (FAILED(Res))\
51 {\
52 UE_LOG(LogAVEncoder, Error, TEXT("`" #COM_call "` failed: 0x%X - %s"), Res, *GetComErrorDescription(Res));\
53 return {};\
54 }\
55 }
56
57// macro to deal with COM calls inside COM method (that returns HRESULT)
58#define CHECK_HR_COM(COM_call)\
59 {\
60 HRESULT Res = COM_call;\
61 if (FAILED(Res))\
62 {\
63 UE_LOG(LogAVEncoder, Error, TEXT("`" #COM_call "` failed: 0x%X - %s"), Res, *GetComErrorDescription(Res));\
64 return Res;\
65 }\
66 }
67
68// macro to deal with COM calls inside COM method (that simply returns)
69#define CHECK_HR_VOID(COM_call)\
70 {\
71 HRESULT Res = COM_call;\
72 if (FAILED(Res))\
73 {\
74 UE_LOG(LogAVEncoder, Error, TEXT("`" #COM_call "` failed: 0x%X - %s"), Res, *GetComErrorDescription(Res));\
75 return;\
76 }\
77 }
78
80
81// following commented include causes name clash between UE4 and Windows `IMediaEventSink`,
82// we just need a couple of GUIDs from there so the solution is to duplicate them below
83//#include "wmcodecdsp.h"
84
85const GUID CLSID_AACMFTEncoder = { 0x93AF0C51, 0x2275, 0x45d2, { 0xA3, 0x5B, 0xF2, 0xBA, 0x21, 0xCA, 0xED, 0x00 } };
86const GUID CLSID_MP3ACMCodecWrapper ={ 0x11103421, 0x354c, 0x4cca, { 0xa7, 0xa3, 0x1a, 0xff, 0x9a, 0x5b, 0x67, 0x01 } };
87const GUID CLSID_CMSH264EncoderMFT = { 0x6ca50344, 0x051a, 0x4ded, { 0x97, 0x79, 0xa4, 0x33, 0x05, 0x16, 0x5e, 0x35 } };
88const GUID CLSID_VideoProcessorMFT = { 0x88753b26, 0x5b24, 0x49bd, { 0xb2, 0xe7, 0xc, 0x44, 0x5c, 0x78, 0xc9, 0x82 } };
89
90// `MF_LOW_LATENCY` is defined in "mfapi.h" for >= WIN8
91// UE4 supports lower Windows versions at the moment and so `WINVER` is < `_WIN32_WINNT_WIN8`
92// to be able to use `MF_LOW_LATENCY` with default UE4 build we define it ourselves and check actual
93// Windows version in runtime
94#if (WINVER < _WIN32_WINNT_WIN8)
95 const GUID MF_LOW_LATENCY = { 0x9c27891a, 0xed7a, 0x40e1,{ 0x88, 0xe8, 0xb2, 0x27, 0x27, 0xa0, 0x24, 0xee } };
96#endif
97
98
99//#if PLATFORM_WINDOWS
100//
101//ID3D11Device* GetUE4DxDevice();
102//
103//#endif
104
106//#if PLATFORM_WINDOWS
107//class FScopeDisabledDxDebugErrors final
108//{
109//private:
110//
111//public:
112// FScopeDisabledDxDebugErrors(TArray<D3D11_MESSAGE_ID>&& ErrorsToDisable)
113// {
114// TRefCountPtr<ID3D11Debug> Debug;
115// HRESULT HRes = GetUE4DxDevice()->QueryInterface(__uuidof(ID3D11Debug), reinterpret_cast<void**>(Debug.GetInitReference()));
116//
117// if (HRes == E_NOINTERFACE)
118// {
119// // Debug Layer is not enabled, so no need to disable its errors
120// return;
121// }
122//
123// if (!SUCCEEDED(HRes) ||
124// !SUCCEEDED(HRes = Debug->QueryInterface(__uuidof(ID3D11InfoQueue), reinterpret_cast<void**>(InfoQueue.GetInitReference()))))
125// {
126// //UE_LOG(LogAVEncoder, VeryVerbose, TEXT("Failed to get ID3D11InfoQueue: 0x%X - %s"), HRes, *_GetComErrorDescription(HRes));
127// return;
128// }
129//
130// D3D11_INFO_QUEUE_FILTER filter = {};
131// filter.DenyList.NumIDs = ErrorsToDisable.Num();
132// filter.DenyList.pIDList = ErrorsToDisable.GetData();
133// bSucceeded = SUCCEEDED(InfoQueue->PushStorageFilter(&filter));
134// }
135//
136// ~FScopeDisabledDxDebugErrors()
137// {
138// if (bSucceeded)
139// {
140// InfoQueue->PopStorageFilter();
141// }
142// }
143//
144//private:
145// TRefCountPtr<ID3D11InfoQueue> InfoQueue;
146// bool bSucceeded = false;
147//};
148//#endif
149
150
151} // namespace AVEncoder
152
153
154#endif // PLATFORM_MICROSOFT
155
156
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::WIDECHAR WIDECHAR
A wide character. Normally a signed type.
Definition Platform.h:1133
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
THIRD_PARTY_INCLUDES_START THIRD_PARTY_INCLUDES_END const FString GetComErrorDescription(HRESULT Res)
Definition WmfPrivate.h:24
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioEncoder.cpp:7
COREUOBJECT_API const FGuid GUID