summaryrefslogtreecommitdiff
path: root/libavcodec/mf_utils.h
diff options
context:
space:
mode:
authorTrystan Mata <trystan.mata@tytanium.xyz>2022-05-25 12:54:01 +0200
committerMartin Storsjö <martin@martin.st>2022-05-25 23:45:42 +0300
commit1cb601ad10313981209a5918fc36a968068fc0ec (patch)
tree3e72921c9fc9930807cb5f16e44960715f9aa948 /libavcodec/mf_utils.h
parent478e1a98a289bbc777bddc02fdcefeaa3c416a63 (diff)
downloadffmpeg-1cb601ad10313981209a5918fc36a968068fc0ec.tar.gz
avcodec/mfenc: Dynamically load MFPlat.DLL
Allows non-UWP builds of FFmpeg with MediaFoundation to work on N editions of Windows which are without MediaFoundation by default. On UWP target, FFmpeg is linked directly against MediaFoundation since LoadLibrary is not available. This commit adresses https://trac.ffmpeg.org/ticket/9788 Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavcodec/mf_utils.h')
-rw-r--r--libavcodec/mf_utils.h35
1 files changed, 23 insertions, 12 deletions
diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h
index d514723c3b..3b12344f3e 100644
--- a/libavcodec/mf_utils.h
+++ b/libavcodec/mf_utils.h
@@ -41,6 +41,25 @@
#include "avcodec.h"
+// Windows N editions does not provide MediaFoundation by default.
+// So to avoid DLL loading error, MediaFoundation will be dynamically loaded
+// except on UWP build since LoadLibrary is not available on it.
+typedef struct MFFunctions {
+ HRESULT (WINAPI *MFStartup) (ULONG Version, DWORD dwFlags);
+ HRESULT (WINAPI *MFShutdown) (void);
+ HRESULT (WINAPI *MFCreateAlignedMemoryBuffer) (DWORD cbMaxLength,
+ DWORD cbAligment,
+ IMFMediaBuffer **ppBuffer);
+ HRESULT (WINAPI *MFCreateSample) (IMFSample **ppIMFSample);
+ HRESULT (WINAPI *MFCreateMediaType) (IMFMediaType **ppMFType);
+ // MFTEnumEx is missing in Windows Vista's mfplat.dll.
+ HRESULT (WINAPI *MFTEnumEx)(GUID guidCategory, UINT32 Flags,
+ const MFT_REGISTER_TYPE_INFO *pInputType,
+ const MFT_REGISTER_TYPE_INFO *pOutputType,
+ IMFActivate ***pppMFTActivate,
+ UINT32 *pnumMFTActivate);
+} MFFunctions;
+
// These functions do exist in mfapi.h, but are only available within
// __cplusplus ifdefs.
HRESULT ff_MFGetAttributeSize(IMFAttributes *pattr, REFGUID guid,
@@ -50,15 +69,6 @@ HRESULT ff_MFSetAttributeSize(IMFAttributes *pattr, REFGUID guid,
#define ff_MFSetAttributeRatio ff_MFSetAttributeSize
#define ff_MFGetAttributeRatio ff_MFGetAttributeSize
-// MFTEnumEx was missing from mingw-w64's mfplat import library until
-// mingw-w64 v6.0.0, thus wrap it and load it using GetProcAddress.
-// It's also missing in Windows Vista's mfplat.dll.
-HRESULT ff_MFTEnumEx(GUID guidCategory, UINT32 Flags,
- const MFT_REGISTER_TYPE_INFO *pInputType,
- const MFT_REGISTER_TYPE_INFO *pOutputType,
- IMFActivate ***pppMFTActivate, UINT32 *pnumMFTActivate);
-
-
// These do exist in mingw-w64's codecapi.h, but they aren't properly defined
// by the header until after mingw-w64 v7.0.0.
DEFINE_GUID(ff_CODECAPI_AVDecVideoThumbnailGenerationMode, 0x2efd8eee,0x1150,0x4328,0x9c,0xf5,0x66,0xdc,0xe9,0x33,0xfc,0xf4);
@@ -150,7 +160,8 @@ char *ff_hr_str_buf(char *buf, size_t size, HRESULT hr);
#define FF_VAL_VT_UI4(v) FF_VARIANT_VALUE(VT_UI4, .ulVal = (v))
#define FF_VAL_VT_BOOL(v) FF_VARIANT_VALUE(VT_BOOL, .boolVal = (v))
-IMFSample *ff_create_memory_sample(void *fill_data, size_t size, size_t align);
+IMFSample *ff_create_memory_sample(MFFunctions *f, void *fill_data,
+ size_t size, size_t align);
enum AVSampleFormat ff_media_type_to_sample_fmt(IMFAttributes *type);
enum AVPixelFormat ff_media_type_to_pix_fmt(IMFAttributes *type);
const GUID *ff_pix_fmt_to_guid(enum AVPixelFormat pix_fmt);
@@ -160,10 +171,10 @@ char *ff_guid_str_buf(char *buf, size_t buf_size, const GUID *guid);
void ff_attributes_dump(void *log, IMFAttributes *attrs);
void ff_media_type_dump(void *log, IMFMediaType *type);
const CLSID *ff_codec_to_mf_subtype(enum AVCodecID codec);
-int ff_instantiate_mf(void *log, GUID category,
+int ff_instantiate_mf(void *log, MFFunctions *f, GUID category,
MFT_REGISTER_TYPE_INFO *in_type,
MFT_REGISTER_TYPE_INFO *out_type,
int use_hw, IMFTransform **res);
-void ff_free_mf(IMFTransform **mft);
+void ff_free_mf(MFFunctions *f, IMFTransform **mft);
#endif