1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * This file is part of FFmpeg.
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
5cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
6cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
7cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
8cabdff1aSopenharmony_ci *
9cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
10cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
11cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12cabdff1aSopenharmony_ci * Lesser General Public License for more details.
13cabdff1aSopenharmony_ci *
14cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
15cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
16cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17cabdff1aSopenharmony_ci */
18cabdff1aSopenharmony_ci
19cabdff1aSopenharmony_ci#ifndef AVCODEC_MF_UTILS_H
20cabdff1aSopenharmony_ci#define AVCODEC_MF_UTILS_H
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci#include <windows.h>
23cabdff1aSopenharmony_ci#include <initguid.h>
24cabdff1aSopenharmony_ci#ifdef _MSC_VER
25cabdff1aSopenharmony_ci// The official way of including codecapi (via dshow.h) makes the ICodecAPI
26cabdff1aSopenharmony_ci// interface unavailable in UWP mode, but including icodecapi.h + codecapi.h
27cabdff1aSopenharmony_ci// seems to be equivalent. (These headers conflict with the official way
28cabdff1aSopenharmony_ci// of including it though, through strmif.h via dshow.h. And on mingw, the
29cabdff1aSopenharmony_ci// mf*.h headers below indirectly include strmif.h.)
30cabdff1aSopenharmony_ci#include <icodecapi.h>
31cabdff1aSopenharmony_ci#else
32cabdff1aSopenharmony_ci#define NO_DSHOW_STRSAFE
33cabdff1aSopenharmony_ci#include <dshow.h>
34cabdff1aSopenharmony_ci// Older versions of mingw-w64 need codecapi.h explicitly included, while newer
35cabdff1aSopenharmony_ci// ones include it implicitly from dshow.h (via uuids.h).
36cabdff1aSopenharmony_ci#include <codecapi.h>
37cabdff1aSopenharmony_ci#endif
38cabdff1aSopenharmony_ci#include <mfapi.h>
39cabdff1aSopenharmony_ci#include <mferror.h>
40cabdff1aSopenharmony_ci#include <mfobjects.h>
41cabdff1aSopenharmony_ci#include <mftransform.h>
42cabdff1aSopenharmony_ci
43cabdff1aSopenharmony_ci#include "avcodec.h"
44cabdff1aSopenharmony_ci
45cabdff1aSopenharmony_ci// Windows N editions does not provide MediaFoundation by default.
46cabdff1aSopenharmony_ci// So to avoid DLL loading error, MediaFoundation will be dynamically loaded
47cabdff1aSopenharmony_ci// except on UWP build since LoadLibrary is not available on it.
48cabdff1aSopenharmony_citypedef struct MFFunctions {
49cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFStartup) (ULONG Version, DWORD dwFlags);
50cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFShutdown) (void);
51cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFCreateAlignedMemoryBuffer) (DWORD cbMaxLength,
52cabdff1aSopenharmony_ci                                                   DWORD cbAligment,
53cabdff1aSopenharmony_ci                                                   IMFMediaBuffer **ppBuffer);
54cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFCreateSample) (IMFSample **ppIMFSample);
55cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFCreateMediaType) (IMFMediaType **ppMFType);
56cabdff1aSopenharmony_ci    // MFTEnumEx is missing in Windows Vista's mfplat.dll.
57cabdff1aSopenharmony_ci    HRESULT (WINAPI *MFTEnumEx)(GUID guidCategory, UINT32 Flags,
58cabdff1aSopenharmony_ci                                const MFT_REGISTER_TYPE_INFO *pInputType,
59cabdff1aSopenharmony_ci                                const MFT_REGISTER_TYPE_INFO *pOutputType,
60cabdff1aSopenharmony_ci                                IMFActivate ***pppMFTActivate,
61cabdff1aSopenharmony_ci                                UINT32 *pnumMFTActivate);
62cabdff1aSopenharmony_ci} MFFunctions;
63cabdff1aSopenharmony_ci
64cabdff1aSopenharmony_ci// These functions do exist in mfapi.h, but are only available within
65cabdff1aSopenharmony_ci// __cplusplus ifdefs.
66cabdff1aSopenharmony_ciHRESULT ff_MFGetAttributeSize(IMFAttributes *pattr, REFGUID guid,
67cabdff1aSopenharmony_ci                              UINT32 *pw, UINT32 *ph);
68cabdff1aSopenharmony_ciHRESULT ff_MFSetAttributeSize(IMFAttributes *pattr, REFGUID guid,
69cabdff1aSopenharmony_ci                              UINT32 uw, UINT32 uh);
70cabdff1aSopenharmony_ci#define ff_MFSetAttributeRatio ff_MFSetAttributeSize
71cabdff1aSopenharmony_ci#define ff_MFGetAttributeRatio ff_MFGetAttributeSize
72cabdff1aSopenharmony_ci
73cabdff1aSopenharmony_ci// These do exist in mingw-w64's codecapi.h, but they aren't properly defined
74cabdff1aSopenharmony_ci// by the header until after mingw-w64 v7.0.0.
75cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoThumbnailGenerationMode, 0x2efd8eee,0x1150,0x4328,0x9c,0xf5,0x66,0xdc,0xe9,0x33,0xfc,0xf4);
76cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoDropPicWithMissingRef, 0xf8226383,0x14c2,0x4567,0x97,0x34,0x50,0x04,0xe9,0x6f,0xf8,0x87);
77cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoSoftwareDeinterlaceMode, 0x0c08d1ce,0x9ced,0x4540,0xba,0xe3,0xce,0xb3,0x80,0x14,0x11,0x09);
78cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoFastDecodeMode, 0x6b529f7d,0xd3b1,0x49c6,0xa9,0x99,0x9e,0xc6,0x91,0x1b,0xed,0xbf);
79cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVLowLatencyMode, 0x9c27891a,0xed7a,0x40e1,0x88,0xe8,0xb2,0x27,0x27,0xa0,0x24,0xee);
80cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoH264ErrorConcealment, 0xececace8,0x3436,0x462c,0x92,0x94,0xcd,0x7b,0xac,0xd7,0x58,0xa9);
81cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoMPEG2ErrorConcealment, 0x9d2bfe18,0x728d,0x48d2,0xb3,0x58,0xbc,0x7e,0x43,0x6c,0x66,0x74);
82cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoCodecType, 0x434528e5,0x21f0,0x46b6,0xb6,0x2c,0x9b,0x1b,0x6b,0x65,0x8c,0xd1);
83cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoDXVAMode, 0xf758f09e,0x7337,0x4ae7,0x83,0x87,0x73,0xdc,0x2d,0x54,0xe6,0x7d);
84cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoDXVABusEncryption, 0x42153c8b,0xfd0b,0x4765,0xa4,0x62,0xdd,0xd9,0xe8,0xbc,0xc3,0x88);
85cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoSWPowerLevel, 0xfb5d2347,0x4dd8,0x4509,0xae,0xd0,0xdb,0x5f,0xa9,0xaa,0x93,0xf4);
86cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoMaxCodedWidth, 0x5ae557b8,0x77af,0x41f5,0x9f,0xa6,0x4d,0xb2,0xfe,0x1d,0x4b,0xca);
87cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecVideoMaxCodedHeight, 0x7262a16a,0xd2dc,0x4e75,0x9b,0xa8,0x65,0xc0,0xc6,0xd3,0x2b,0x13);
88cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecNumWorkerThreads, 0x9561c3e8,0xea9e,0x4435,0x9b,0x1e,0xa9,0x3e,0x69,0x18,0x94,0xd8);
89cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecSoftwareDynamicFormatChange, 0x862e2f0a,0x507b,0x47ff,0xaf,0x47,0x01,0xe2,0x62,0x42,0x98,0xb7);
90cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVDecDisableVideoPostProcessing, 0xf8749193,0x667a,0x4f2c,0xa9,0xe8,0x5d,0x4a,0xf9,0x24,0xf0,0x8f);
91cabdff1aSopenharmony_ci
92cabdff1aSopenharmony_ci// These are missing from mingw-w64's headers until after mingw-w64 v7.0.0.
93cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncCommonRateControlMode,      0x1c0608e9, 0x370c, 0x4710, 0x8a, 0x58, 0xcb, 0x61, 0x81, 0xc4, 0x24, 0x23);
94cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncCommonQuality,       0xfcbf57a3, 0x7ea5, 0x4b0c, 0x96, 0x44, 0x69, 0xb4, 0x0c, 0x39, 0xc3, 0x91);
95cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncCommonMeanBitRate,   0xf7222374, 0x2144, 0x4815, 0xb5, 0x50, 0xa3, 0x7f, 0x8e, 0x12, 0xee, 0x52);
96cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncH264CABACEnable,    0xee6cad62, 0xd305, 0x4248, 0xa5, 0xe, 0xe1, 0xb2, 0x55, 0xf7, 0xca, 0xf8);
97cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncVideoForceKeyFrame, 0x398c1b98, 0x8353, 0x475a, 0x9e, 0xf2, 0x8f, 0x26, 0x5d, 0x26, 0x3, 0x45);
98cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVEncMPVDefaultBPictureCount, 0x8d390aac, 0xdc5c, 0x4200, 0xb5, 0x7f, 0x81, 0x4d, 0x04, 0xba, 0xba, 0xb2);
99cabdff1aSopenharmony_ciDEFINE_GUID(ff_CODECAPI_AVScenarioInfo, 0xb28a6e64,0x3ff9,0x446a,0x8a,0x4b,0x0d,0x7a,0x53,0x41,0x32,0x36);
100cabdff1aSopenharmony_ci
101cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_D3D11_BINDFLAGS, 0xeacf97ad, 0x065c, 0x4408, 0xbe, 0xe3, 0xfd, 0xcb, 0xfd, 0x12, 0x8b, 0xe2);
102cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_D3D11_USAGE, 0xe85fe442, 0x2ca3, 0x486e, 0xa9, 0xc7, 0x10, 0x9d, 0xda, 0x60, 0x98, 0x80);
103cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_D3D11_AWARE, 0x206b4fc8, 0xfcf9, 0x4c51, 0xaf, 0xe3, 0x97, 0x64, 0x36, 0x9e, 0x33, 0xa0);
104cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_D3D11_SHARED, 0x7b8f32c3, 0x6d96, 0x4b89, 0x92, 0x3, 0xdd, 0x38, 0xb6, 0x14, 0x14, 0xf3);
105cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_D3D11_SHARED_WITHOUT_MUTEX, 0x39dbd44d, 0x2e44, 0x4931, 0xa4, 0xc8, 0x35, 0x2d, 0x3d, 0xc4, 0x21, 0x15);
106cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT, 0x851745d5, 0xc3d6, 0x476d, 0x95, 0x27, 0x49, 0x8e, 0xf2, 0xd1, 0xd, 0x18);
107cabdff1aSopenharmony_ciDEFINE_GUID(ff_MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT_PROGRESSIVE, 0xf5523a5, 0x1cb2, 0x47c5, 0xa5, 0x50, 0x2e, 0xeb, 0x84, 0xb4, 0xd1, 0x4a);
108cabdff1aSopenharmony_ci
109cabdff1aSopenharmony_ciDEFINE_MEDIATYPE_GUID(ff_MFVideoFormat_HEVC, 0x43564548); // FCC('HEVC')
110cabdff1aSopenharmony_ciDEFINE_MEDIATYPE_GUID(ff_MFVideoFormat_HEVC_ES, 0x53564548); // FCC('HEVS')
111cabdff1aSopenharmony_ci
112cabdff1aSopenharmony_ci
113cabdff1aSopenharmony_ci// This enum is missing from mingw-w64's codecapi.h by v7.0.0.
114cabdff1aSopenharmony_cienum ff_eAVEncCommonRateControlMode {
115cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_CBR                 = 0,
116cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_PeakConstrainedVBR  = 1,
117cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_UnconstrainedVBR    = 2,
118cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_Quality             = 3,
119cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_LowDelayVBR         = 4,
120cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_GlobalVBR           = 5,
121cabdff1aSopenharmony_ci    ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR   = 6
122cabdff1aSopenharmony_ci};
123cabdff1aSopenharmony_ci
124cabdff1aSopenharmony_cienum ff_eAVScenarioInfo {
125cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_Unknown                         = 0,
126cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_DisplayRemoting                 = 1,
127cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_VideoConference                 = 2,
128cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_Archive                         = 3,
129cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_LiveStreaming                   = 4,
130cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_CameraRecord                    = 5,
131cabdff1aSopenharmony_ci    ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap   = 6
132cabdff1aSopenharmony_ci};
133cabdff1aSopenharmony_ci
134cabdff1aSopenharmony_ci// These do exist in mingw-w64's mfobjects.idl, but are missing from
135cabdff1aSopenharmony_ci// mfobjects.h that is generated from the former, due to incorrect use of
136cabdff1aSopenharmony_ci// ifdefs in the IDL file.
137cabdff1aSopenharmony_cienum {
138cabdff1aSopenharmony_ci    ff_METransformUnknown = 600,
139cabdff1aSopenharmony_ci    ff_METransformNeedInput,
140cabdff1aSopenharmony_ci    ff_METransformHaveOutput,
141cabdff1aSopenharmony_ci    ff_METransformDrainComplete,
142cabdff1aSopenharmony_ci    ff_METransformMarker,
143cabdff1aSopenharmony_ci};
144cabdff1aSopenharmony_ci
145cabdff1aSopenharmony_ci// These do exist in all supported headers, but are manually defined here
146cabdff1aSopenharmony_ci// to avoid having to include codecapi.h, as there's problems including that
147cabdff1aSopenharmony_ci// header when targeting UWP (where including it with MSVC seems to work,
148cabdff1aSopenharmony_ci// but fails when built with clang in MSVC mode).
149cabdff1aSopenharmony_cienum ff_eAVEncH264VProfile {
150cabdff1aSopenharmony_ci   ff_eAVEncH264VProfile_Base = 66,
151cabdff1aSopenharmony_ci   ff_eAVEncH264VProfile_Main = 77,
152cabdff1aSopenharmony_ci   ff_eAVEncH264VProfile_High = 100,
153cabdff1aSopenharmony_ci};
154cabdff1aSopenharmony_ci
155cabdff1aSopenharmony_cichar *ff_hr_str_buf(char *buf, size_t size, HRESULT hr);
156cabdff1aSopenharmony_ci#define ff_hr_str(hr) ff_hr_str_buf((char[80]){0}, 80, hr)
157cabdff1aSopenharmony_ci
158cabdff1aSopenharmony_ci// Possibly compiler-dependent; the MS/MinGW definition for this is just crazy.
159cabdff1aSopenharmony_ci#define FF_VARIANT_VALUE(type, contents) &(VARIANT){ .vt = (type), contents }
160cabdff1aSopenharmony_ci
161cabdff1aSopenharmony_ci#define FF_VAL_VT_UI4(v) FF_VARIANT_VALUE(VT_UI4, .ulVal = (v))
162cabdff1aSopenharmony_ci#define FF_VAL_VT_BOOL(v) FF_VARIANT_VALUE(VT_BOOL, .boolVal = (v))
163cabdff1aSopenharmony_ci
164cabdff1aSopenharmony_ciIMFSample *ff_create_memory_sample(MFFunctions *f, void *fill_data,
165cabdff1aSopenharmony_ci                                   size_t size, size_t align);
166cabdff1aSopenharmony_cienum AVSampleFormat ff_media_type_to_sample_fmt(IMFAttributes *type);
167cabdff1aSopenharmony_cienum AVPixelFormat ff_media_type_to_pix_fmt(IMFAttributes *type);
168cabdff1aSopenharmony_ciconst GUID *ff_pix_fmt_to_guid(enum AVPixelFormat pix_fmt);
169cabdff1aSopenharmony_ciint ff_fourcc_from_guid(const GUID *guid, uint32_t *out_fourcc);
170cabdff1aSopenharmony_cichar *ff_guid_str_buf(char *buf, size_t buf_size, const GUID *guid);
171cabdff1aSopenharmony_ci#define ff_guid_str(guid) ff_guid_str_buf((char[80]){0}, 80, guid)
172cabdff1aSopenharmony_civoid ff_attributes_dump(void *log, IMFAttributes *attrs);
173cabdff1aSopenharmony_civoid ff_media_type_dump(void *log, IMFMediaType *type);
174cabdff1aSopenharmony_ciconst CLSID *ff_codec_to_mf_subtype(enum AVCodecID codec);
175cabdff1aSopenharmony_ciint ff_instantiate_mf(void *log, MFFunctions *f, GUID category,
176cabdff1aSopenharmony_ci                      MFT_REGISTER_TYPE_INFO *in_type,
177cabdff1aSopenharmony_ci                      MFT_REGISTER_TYPE_INFO *out_type,
178cabdff1aSopenharmony_ci                      int use_hw, IMFTransform **res);
179cabdff1aSopenharmony_civoid ff_free_mf(MFFunctions *f, IMFTransform **mft);
180cabdff1aSopenharmony_ci
181cabdff1aSopenharmony_ci#endif
182