diff --git a/Makefile.am b/Makefile.am index 0e3fd01..e9cb100 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,7 +26,9 @@ libmfx_la_SOURCES = \ src/mfx_library_iterator.cpp \ src/mfx_load_dll.cpp \ src/mfx_win_reg_key.cpp \ - src/mfx_plugin_hive.cpp + src/mfx_plugin_hive.cpp \ + src/mfx_driver_store_loader.h \ + src/mfx_driver_store_loader.cpp else libmfx_la_SOURCES = \ src/mfxloader.cpp \ diff --git a/configure.ac b/configure.ac index f675420..8d3110d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.53]) -AC_INIT([libmfx], [1.32]) +AC_INIT([libmfx], [1.34]) AC_CONFIG_SRCDIR([src/mfx_dispatcher.cpp]) AM_INIT_AUTOMAKE([foreign subdir-objects]) @@ -15,13 +15,13 @@ AS_CASE([${host_os}], [*mingw*], [ AC_DEFINE([MFX_HAVE_WINDOWS]) AM_CONDITIONAL([WINDOWS], [true]) - DLLIB="" + DLLIB="-lole32 -luuid" ], [*cygwin*], [ AC_DEFINE([MFX_HAVE_WINDOWS]) AC_DEFINE([_MAX_PATH], [MAX_PATH]) AM_CONDITIONAL([WINDOWS], [true]) - DLLIB="" + DLLIB="-lole32 -luuid" ], [AC_MSG_ERROR([${host_os} not supported.])] ) diff --git a/libmfx.sln b/libmfx.sln deleted file mode 100644 index e693417..0000000 --- a/libmfx.sln +++ /dev/null @@ -1,35 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmfx", "libmfx.vcproj", "{9E7B3527-11AA-46BA-A82F-C58761F9B56F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release_MD|Win32 = Release_MD|Win32 - Release_MD|x64 = Release_MD|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Debug|Win32.ActiveCfg = Debug|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Debug|Win32.Build.0 = Debug|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Debug|x64.ActiveCfg = Debug|x64 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Debug|x64.Build.0 = Debug|x64 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release_MD|Win32.ActiveCfg = Release_MD|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release_MD|Win32.Build.0 = Release_MD|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release_MD|x64.ActiveCfg = Release_MD|x64 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release_MD|x64.Build.0 = Release_MD|x64 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release|Win32.ActiveCfg = Release|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release|Win32.Build.0 = Release|Win32 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release|x64.ActiveCfg = Release|x64 - {9E7B3527-11AA-46BA-A82F-C58761F9B56F}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal diff --git a/libmfx.vcproj b/libmfx.vcproj deleted file mode 100644 index a34a514..0000000 --- a/libmfx.vcproj +++ /dev/null @@ -1,494 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mfx/mfxadapter.h b/mfx/mfxadapter.h index 9bcbc73..30c4fb3 100644 --- a/mfx/mfxadapter.h +++ b/mfx/mfxadapter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Intel Corporation +// Copyright (c) 2019-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -29,9 +29,9 @@ extern "C" { #endif -mfxStatus MFXQueryAdapters(mfxComponentInfo* input_info, mfxAdaptersInfo* adapters); -mfxStatus MFXQueryAdaptersDecode(mfxBitstream* bitstream, mfxU32 codec_id, mfxAdaptersInfo* adapters); -mfxStatus MFXQueryAdaptersNumber(mfxU32* num_adapters); +mfxStatus MFX_CDECL MFXQueryAdapters(mfxComponentInfo* input_info, mfxAdaptersInfo* adapters); +mfxStatus MFX_CDECL MFXQueryAdaptersDecode(mfxBitstream* bitstream, mfxU32 codec_id, mfxAdaptersInfo* adapters); +mfxStatus MFX_CDECL MFXQueryAdaptersNumber(mfxU32* num_adapters); #ifdef __cplusplus } // extern "C" #endif diff --git a/mfx/mfxastructures.h b/mfx/mfxastructures.h index 97e420b..679132f 100644 --- a/mfx/mfxastructures.h +++ b/mfx/mfxastructures.h @@ -48,7 +48,7 @@ enum { MFX_PROFILE_AAC_PS =29, /*MPEG AUDIO*/ - MFX_AUDIO_MPEG1_LAYER1 =0x00000110, + MFX_AUDIO_MPEG1_LAYER1 =0x00000110, MFX_AUDIO_MPEG1_LAYER2 =0x00000120, MFX_AUDIO_MPEG1_LAYER3 =0x00000140, MFX_AUDIO_MPEG2_LAYER1 =0x00000210, @@ -85,7 +85,7 @@ enum{ }; /*AAC encoder stereo mode*/ -enum +enum { MFX_AUDIO_AAC_MONO= 0, MFX_AUDIO_AAC_LR_STEREO= 1, @@ -104,9 +104,9 @@ typedef struct { mfxU16 NumChannel; mfxU16 BitPerSample; - mfxU16 reserved1[22]; + mfxU16 reserved1[22]; - union { + union { struct { /* AAC Decoding Options */ mfxU16 FlagPSSupportLev; mfxU16 Layer; @@ -116,7 +116,7 @@ typedef struct { struct { /* AAC Encoding Options */ mfxU16 OutputFormat; mfxU16 StereoMode; - mfxU16 reserved2[61]; + mfxU16 reserved2[61]; }; }; } mfxAudioInfoMFX; @@ -126,7 +126,7 @@ MFX_PACK_BEGIN_STRUCT_W_PTR() typedef struct { mfxU16 AsyncDepth; mfxU16 Protected; - mfxU16 reserved[14]; + mfxU16 reserved[14]; mfxAudioInfoMFX mfx; mfxExtBuffer** ExtParam; @@ -149,7 +149,7 @@ typedef struct { mfxU16 NumChannels; mfxU32 SampleFrequency; mfxU16 BitPerSample; - mfxU16 reserved1[7]; + mfxU16 reserved1[7]; mfxU8* Data; mfxU32 reserved2; diff --git a/mfx/mfxbrc.h b/mfx/mfxbrc.h index 6e4ed83..80516c3 100644 --- a/mfx/mfxbrc.h +++ b/mfx/mfxbrc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Intel Corporation +// Copyright (c) 2019-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -81,7 +81,7 @@ enum { MFX_BRC_PANIC_SMALL_FRAME = 4 // Coded frame is too small, no further recoding possible - required padding to MinFrameSize }; -MFX_PACK_BEGIN_USUAL_STRUCT() +MFX_PACK_BEGIN_STRUCT_W_PTR() typedef struct { mfxU32 MinFrameSize; // Size in bytes, coded frame must be padded to when Status = MFX_BRC_PANIC_SMALL_FRAME mfxU16 BRCStatus; // See BRCStatus enumerator diff --git a/mfx/mfxcommon.h b/mfx/mfxcommon.h index a8b8758..875b47f 100644 --- a/mfx/mfxcommon.h +++ b/mfx/mfxcommon.h @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2019 Intel Corporation +// Copyright (c) 2018-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -62,7 +62,7 @@ enum { MFX_IMPL_VIA_D3D11 = 0x0300, MFX_IMPL_VIA_VAAPI = 0x0400, - MFX_IMPL_AUDIO = 0x8000, + MFX_IMPL_AUDIO = 0x8000, #if (MFX_VERSION >= MFX_VERSION_NEXT) MFX_IMPL_EXTERNAL_THREADING = 0x10000, #endif @@ -179,6 +179,7 @@ enum { MFX_PLATFORM_JASPERLAKE = 32, MFX_PLATFORM_ELKHARTLAKE = 33, MFX_PLATFORM_TIGERLAKE = 40, + MFX_PLATFORM_KEEMBAY = 50, }; #if (MFX_VERSION >= 1031) diff --git a/mfx/mfxdefs.h b/mfx/mfxdefs.h index cbb75aa..07acf55 100644 --- a/mfx/mfxdefs.h +++ b/mfx/mfxdefs.h @@ -21,7 +21,7 @@ #define __MFXDEFS_H__ #define MFX_VERSION_MAJOR 1 -#define MFX_VERSION_MINOR 32 +#define MFX_VERSION_MINOR 34 // MFX_VERSION_NEXT is always +1 from last public release // may be enforced by MFX_VERSION_USE_LATEST define @@ -94,11 +94,11 @@ extern "C" #define __UINT64 unsigned long long #ifdef _WIN32 - #define MFX_CDECL __cdecl - #define MFX_STDCALL __stdcall + #define MFX_CDECL __cdecl + #define MFX_STDCALL __stdcall #else - #define MFX_CDECL - #define MFX_STDCALL + #define MFX_CDECL + #define MFX_STDCALL #endif /* _WIN32 */ #define MFX_INFINITE 0xFFFFFFFF @@ -197,7 +197,7 @@ typedef enum } mfxStatus; -// Application +// Application #if defined(MFX_DISPATCHER_EXPOSED_PREFIX) #include "mfxdispatcherprefixedfunctions.h" diff --git a/mfx/mfxfei.h b/mfx/mfxfei.h index 4f009ef..55e61ca 100644 --- a/mfx/mfxfei.h +++ b/mfx/mfxfei.h @@ -6,10 +6,10 @@ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -207,7 +207,6 @@ typedef struct { } mfxExtFeiEncMBCtrl; MFX_PACK_END() - /* 1 ENC_PAK output */ /* Buffer holds 32 MVs per MB. MVs are located in zigzag scan order. Number in diagram below shows location of MV in memory. @@ -533,7 +532,6 @@ typedef struct { } mfxExtFeiCodingOption; MFX_PACK_END() - /* 1 functions */ typedef enum { MFX_FEI_FUNCTION_PREENC =1, @@ -577,7 +575,6 @@ typedef struct { } mfxExtFeiParam; MFX_PACK_END() - #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ diff --git a/mfx/mfxfeihevc.h b/mfx/mfxfeihevc.h index 82560c6..8827892 100644 --- a/mfx/mfxfeihevc.h +++ b/mfx/mfxfeihevc.h @@ -6,10 +6,10 @@ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/mfx/mfxmvc.h b/mfx/mfxmvc.h index c987a1a..4ec71dc 100644 --- a/mfx/mfxmvc.h +++ b/mfx/mfxmvc.h @@ -98,7 +98,6 @@ typedef struct { } mfxExtMVCTargetViews ; MFX_PACK_END() - #ifdef __cplusplus } // extern "C" #endif diff --git a/mfx/mfxplugin++.h b/mfx/mfxplugin++.h index 0e2d818..9fe7ce5 100644 --- a/mfx/mfxplugin++.h +++ b/mfx/mfxplugin++.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Intel Corporation +// Copyright (c) 2017-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,7 @@ class MFXBaseUSER { explicit MFXBaseUSER(mfxSession session = NULL) : m_session(session){} - virtual ~MFXBaseUSER() {}; + virtual ~MFXBaseUSER() {} virtual mfxStatus Register(mfxU32 type, const mfxPlugin *par) = 0; virtual mfxStatus Unregister(mfxU32 type) = 0; @@ -563,15 +563,11 @@ namespace detail private: void SetupCallbacks() { m_codecPlg.DecodeHeader = _DecodeHeader; -// m_codecPlg.GetPayload = _GetPayload; m_codecPlg.DecodeFrameSubmit = _DecodeFrameSubmit; } static mfxStatus _DecodeHeader(mfxHDL pthis, mfxBitstream *bs, mfxAudioParam *par) { return reinterpret_cast(pthis)->DecodeHeader(bs, par); } -// static mfxStatus _GetPayload(mfxHDL pthis, mfxU64 *ts, mfxPayload *payload) { - // return reinterpret_cast(pthis)->GetPayload(ts, payload); - // } static mfxStatus _DecodeFrameSubmit(mfxHDL pthis, mfxBitstream *in, mfxAudioFrame *out, mfxThreadTask *task) { return reinterpret_cast(pthis)->DecodeFrameSubmit(in, out, task); } diff --git a/mfx/mfxplugin.h b/mfx/mfxplugin.h index 4037c33..58ddd6f 100644 --- a/mfx/mfxplugin.h +++ b/mfx/mfxplugin.h @@ -193,7 +193,6 @@ typedef struct mfxPlugin{ MFX_PACK_END() - mfxStatus MFX_CDECL MFXVideoUSER_Register(mfxSession session, mfxU32 type, const mfxPlugin *par); mfxStatus MFX_CDECL MFXVideoUSER_Unregister(mfxSession session, mfxU32 type); mfxStatus MFX_CDECL MFXVideoUSER_GetPlugin(mfxSession session, mfxU32 type, mfxPlugin *par); diff --git a/mfx/mfxsc.h b/mfx/mfxsc.h index d7e47fe..d6bc063 100644 --- a/mfx/mfxsc.h +++ b/mfx/mfxsc.h @@ -28,7 +28,7 @@ extern "C" #endif /* __cplusplus */ /* Extended Buffer Ids */ -enum +enum { MFX_EXTBUFF_SCREEN_CAPTURE_PARAM = MFX_MAKEFOURCC('S','C','P','A') }; diff --git a/mfx/mfxstructures.h b/mfx/mfxstructures.h index a9eb8e4..65e7de9 100644 --- a/mfx/mfxstructures.h +++ b/mfx/mfxstructures.h @@ -124,6 +124,9 @@ enum { MFX_FOURCC_Y216 = MFX_MAKEFOURCC('Y','2','1','6'), MFX_FOURCC_Y416 = MFX_MAKEFOURCC('Y','4','1','6'), #endif + MFX_FOURCC_NV21 = MFX_MAKEFOURCC('N', 'V', '2', '1'), /* Same as NV12 but with weaved V and U values. */ + MFX_FOURCC_IYUV = MFX_MAKEFOURCC('I', 'Y', 'U', 'V'), /* Same as YV12 except that the U and V plane order is reversed. */ + MFX_FOURCC_I010 = MFX_MAKEFOURCC('I', '0', '1', '0'), /* 10-bit YUV 4:2:0, each component has its own plane. */ }; /* PicStruct */ @@ -204,7 +207,6 @@ typedef struct MFX_PACK_END() #endif - /* Frame Data Info */ MFX_PACK_BEGIN_STRUCT_W_L_TYPE() typedef struct { @@ -329,7 +331,13 @@ typedef struct { mfxU16 SliceGroupsPresent; mfxU16 MaxDecFrameBuffering; mfxU16 EnableReallocRequest; +#if (MFX_VERSION >= 1034) + mfxU16 FilmGrain; + mfxU16 IgnoreLevelConstrain; + mfxU16 reserved2[5]; +#else mfxU16 reserved2[7]; +#endif }; struct { /* JPEG Decoding Options */ mfxU16 JPEGChromaFormat; @@ -415,6 +423,7 @@ enum { MFX_PROFILE_AVC_MAIN =77, MFX_PROFILE_AVC_EXTENDED =88, MFX_PROFILE_AVC_HIGH =100, + MFX_PROFILE_AVC_HIGH10 =110, MFX_PROFILE_AVC_HIGH_422 =122, MFX_PROFILE_AVC_CONSTRAINED_BASELINE =MFX_PROFILE_AVC_BASELINE + MFX_PROFILE_AVC_CONSTRAINT_SET1, MFX_PROFILE_AVC_CONSTRAINED_HIGH =MFX_PROFILE_AVC_HIGH + MFX_PROFILE_AVC_CONSTRAINT_SET4 @@ -438,6 +447,11 @@ enum { MFX_LEVEL_AVC_5 =50, MFX_LEVEL_AVC_51 =51, MFX_LEVEL_AVC_52 =52, +#if (MFX_VERSION >= MFX_VERSION_NEXT) + MFX_LEVEL_AVC_6 =60, + MFX_LEVEL_AVC_61 =61, + MFX_LEVEL_AVC_62 =62, +#endif /* MPEG-2 Profiles & Levels */ MFX_PROFILE_MPEG2_SIMPLE =0x50, @@ -498,6 +512,33 @@ enum { MFX_PROFILE_VP9_2 = 3, MFX_PROFILE_VP9_3 = 4, +#if (MFX_VERSION >= 1034) + /* AV1 Profiles */ + MFX_PROFILE_AV1_MAIN = 1, + MFX_PROFILE_AV1_HIGH = 2, + MFX_PROFILE_AV1_PRO = 3, + + MFX_LEVEL_AV1_2 = 20, + MFX_LEVEL_AV1_21 = 21, + MFX_LEVEL_AV1_22 = 22, + MFX_LEVEL_AV1_23 = 23, + MFX_LEVEL_AV1_3 = 30, + MFX_LEVEL_AV1_31 = 31, + MFX_LEVEL_AV1_32 = 32, + MFX_LEVEL_AV1_33 = 33, + MFX_LEVEL_AV1_4 = 40, + MFX_LEVEL_AV1_41 = 41, + MFX_LEVEL_AV1_42 = 42, + MFX_LEVEL_AV1_43 = 43, + MFX_LEVEL_AV1_5 = 50, + MFX_LEVEL_AV1_51 = 51, + MFX_LEVEL_AV1_52 = 52, + MFX_LEVEL_AV1_53 = 53, + MFX_LEVEL_AV1_6 = 60, + MFX_LEVEL_AV1_61 = 61, + MFX_LEVEL_AV1_62 = 62, + MFX_LEVEL_AV1_63 = 63, +#endif }; /* GopOptFlag */ @@ -933,6 +974,16 @@ enum { #endif #if (MFX_VERSION >= 1031) MFX_EXTBUFF_PARTIAL_BITSTREAM_PARAM = MFX_MAKEFOURCC('P','B','O','P'), +#endif + MFX_EXTBUFF_ENCODER_IPCM_AREA = MFX_MAKEFOURCC('P', 'C', 'M', 'R'), + MFX_EXTBUFF_INSERT_HEADERS = MFX_MAKEFOURCC('S', 'P', 'R', 'E'), +#if (MFX_VERSION >= 1034) + MFX_EXTBUFF_AV1_FILM_GRAIN_PARAM = MFX_MAKEFOURCC('A','1','F','G'), + MFX_EXTBUFF_AV1_LST_PARAM = MFX_MAKEFOURCC('A', '1', 'L', 'S'), + MFX_EXTBUFF_AV1_SEGMENTATION = MFX_MAKEFOURCC('1', 'S', 'E', 'G'), + MFX_EXTBUFF_AV1_PARAM = MFX_MAKEFOURCC('1', 'P', 'A', 'R'), + MFX_EXTBUFF_AV1_AUXDATA = MFX_MAKEFOURCC('1', 'A', 'U', 'X'), + MFX_EXTBUFF_AV1_TEMPORAL_LAYERS = MFX_MAKEFOURCC('1', 'T', 'M', 'L') #endif }; @@ -1489,7 +1540,8 @@ MFX_PACK_END() /* ROI encoding mode */ enum { MFX_ROI_MODE_PRIORITY = 0, - MFX_ROI_MODE_QP_DELTA = 1 + MFX_ROI_MODE_QP_DELTA = 1, + MFX_ROI_MODE_QP_VALUE = 2 }; MFX_PACK_BEGIN_USUAL_STRUCT() @@ -1636,9 +1688,20 @@ MFX_PACK_END() /* MBQPMode */ enum { MFX_MBQP_MODE_QP_VALUE = 0, // supported in CQP mode only - MFX_MBQP_MODE_QP_DELTA = 1 + MFX_MBQP_MODE_QP_DELTA = 1, + MFX_MBQP_MODE_QP_ADAPTIVE = 2 }; +MFX_PACK_BEGIN_USUAL_STRUCT() +typedef struct{ + union { + mfxU8 QP; + mfxI8 DeltaQP; + }; + mfxU16 Mode; +} mfxQPandMode; +MFX_PACK_END() + MFX_PACK_BEGIN_STRUCT_W_L_TYPE() typedef struct { mfxExtBuffer Header; @@ -1650,11 +1713,40 @@ typedef struct { union { mfxU8 *QP; // Block QP value. Valid when Mode = MFX_MBQP_MODE_QP_VALUE mfxI8 *DeltaQP; // For block i: QP[i] = BrcQP[i] + DeltaQP[i]. Valid when Mode = MFX_MBQP_MODE_QP_DELTA +#if (MFX_VERSION >= 1034) + mfxQPandMode *QPmode; // Block-granularity modes when MFX_MBQP_MODE_QP_ADAPTIVE is set +#endif mfxU64 reserved2; }; } mfxExtMBQP; MFX_PACK_END() +MFX_PACK_BEGIN_USUAL_STRUCT() +typedef struct { + mfxExtBuffer Header; /* Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_INSERT_HEADERS. */ + mfxU16 SPS; /* tri-state option to insert SPS */ + mfxU16 PPS; /* tri-state option to insert PPS */ + mfxU16 reserved[8]; +} mfxExtInsertHeaders; +MFX_PACK_END() + +MFX_PACK_BEGIN_STRUCT_W_PTR() +typedef struct { + mfxExtBuffer Header; /* Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_ENCODER_IPCM_AREA. */ + mfxU16 reserve1[10]; + + mfxU16 NumArea; /* Number of Area's */ + struct area { + mfxU32 Left; /* Left Area's coordinate. */ + mfxU32 Top; /* Top Area's coordinate. */ + mfxU32 Right; /* Right Area's coordinate. */ + mfxU32 Bottom; /* Bottom Area's coordinate. */ + + mfxU16 reserved2[8]; + } * Areas; /* Array of areas. */ +} mfxExtEncoderIPCMArea; +MFX_PACK_END() + MFX_PACK_BEGIN_STRUCT_W_L_TYPE() typedef struct { mfxExtBuffer Header; @@ -1993,12 +2085,27 @@ enum { MFX_SCALING_MODE_QUALITY = 2 }; +#if (MFX_VERSION >= 1033) +/* Interpolation Method */ +enum { + MFX_INTERPOLATION_DEFAULT = 0, + MFX_INTERPOLATION_NEAREST_NEIGHBOR = 1, + MFX_INTERPOLATION_BILINEAR = 2, + MFX_INTERPOLATION_ADVANCED = 3 +}; +#endif + MFX_PACK_BEGIN_USUAL_STRUCT() typedef struct { mfxExtBuffer Header; mfxU16 ScalingMode; +#if (MFX_VERSION >= 1033) + mfxU16 InterpolationMethod; + mfxU16 reserved[10]; +#else mfxU16 reserved[11]; +#endif } mfxExtVPPScaling; MFX_PACK_END() @@ -2319,6 +2426,63 @@ MFX_PACK_END() #endif +#if (MFX_VERSION >= 1034) +/* FilmGrainFlags */ +enum { + MFX_FILM_GRAIN_APPLY = (1 << 0), + MFX_FILM_GRAIN_UPDATE = (1 << 1), + MFX_FILM_GRAIN_CHROMA_SCALING_FROM_LUMA = (1 << 2), + MFX_FILM_GRAIN_OVERLAP = (1 << 3), + MFX_FILM_GRAIN_CLIP_TO_RESTRICTED_RANGE = (1 << 4) +}; + +MFX_PACK_BEGIN_USUAL_STRUCT() +typedef struct { + mfxU8 Value; + mfxU8 Scaling; +} mfxAV1FilmGrainPoint; +MFX_PACK_END() + +MFX_PACK_BEGIN_USUAL_STRUCT() +typedef struct { + mfxExtBuffer Header; + + mfxU16 FilmGrainFlags; /* FilmGrainFlags */ + mfxU16 GrainSeed; /* 0..65535 */ + + mfxU8 RefIdx; /* 0..6 */ + mfxU8 NumYPoints; /* 0..14 */ + mfxU8 NumCbPoints; /* 0..10 */ + mfxU8 NumCrPoints; /* 0..10 */ + + mfxAV1FilmGrainPoint PointY[14]; + mfxAV1FilmGrainPoint PointCb[10]; + mfxAV1FilmGrainPoint PointCr[10]; + + mfxU8 GrainScalingMinus8; /* 0..3 */ + mfxU8 ArCoeffLag; /* 0..3 */ + + mfxU8 ArCoeffsYPlus128[24]; /* 0..255 */ + mfxU8 ArCoeffsCbPlus128[25]; /* 0..255 */ + mfxU8 ArCoeffsCrPlus128[25]; /* 0..255 */ + + mfxU8 ArCoeffShiftMinus6; /* 0..3 */ + mfxU8 GrainScaleShift; /* 0..3 */ + + mfxU8 CbMult; /* 0..255 */ + mfxU8 CbLumaMult; /* 0..255 */ + mfxU16 CbOffset; /* 0..511 */ + + mfxU8 CrMult; /* 0..255 */ + mfxU8 CrLumaMult; /* 0..255 */ + mfxU16 CrOffset; /* 0..511 */ + + mfxU16 reserved[43]; +} mfxExtAV1FilmGrainParam; +MFX_PACK_END() + +#endif + #if (MFX_VERSION >= 1031) /* PartialBitstreamOutput */ enum { diff --git a/src/main.cpp b/src/main.cpp index d2c84b9..7b8a107 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,17 +30,8 @@ #include "mfx_library_iterator.h" #include "mfx_critical_section.h" -#include -#include - -#ifdef MFX_HAVE_LINUX -extern "C" { -#include "mfx_va_glue.h" -} -#endif - #if defined(MEDIASDK_UWP_DISPATCHER) -#include "mfx_driver_store_loader.h" +#include "mfx_dispatcher_uwp.h" #endif #include /* for memset on Linux */ @@ -78,10 +69,10 @@ namespace {MFX_LIB_SOFTWARE, MFX_IMPL_SOFTWARE | MFX_IMPL_AUDIO, 0}, #if (MFX_VERSION >= MFX_VERSION_NEXT) //MFX_SINGLE_THREAD case - {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE|MFX_IMPL_EXTERNAL_THREADING, 0}, - {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE2|MFX_IMPL_EXTERNAL_THREADING, 1}, - {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE3|MFX_IMPL_EXTERNAL_THREADING, 2}, - {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE4|MFX_IMPL_EXTERNAL_THREADING, 3}, + {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE | MFX_IMPL_EXTERNAL_THREADING, 0}, + {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE2 | MFX_IMPL_EXTERNAL_THREADING, 1}, + {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE3 | MFX_IMPL_EXTERNAL_THREADING, 2}, + {MFX_LIB_HARDWARE, MFX_IMPL_HARDWARE4 | MFX_IMPL_EXTERNAL_THREADING, 3}, #endif }; @@ -116,34 +107,6 @@ namespace using namespace MFX; -#if defined(MEDIASDK_UWP_LOADER) - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - // - // intel_gfx_api-*.dll calls these functions to do not mix MFXInitEx exposed - // from dispatcher_proc_table.lib with the libmfx[hw/sw] engines' call MFXInitEx - // - - mfxStatus InitMediaSDKSession(mfxInitParam par, mfxSession* session) - { - return MFXInitEx(par, session); - } - - mfxStatus DisposeMediaSDKSession(mfxSession session) - { - return MFXClose(session); - } - -#ifdef __cplusplus -}; //extern "C" -#endif /* __cplusplus */ - -#endif // defined(MEDIASDK_UWP_LOADER) - - #if !defined(MEDIASDK_UWP_DISPATCHER) // @@ -152,7 +115,7 @@ extern "C" { // All other functions are implemented implicitly. // -typedef MFXVector HandleVector; +typedef MFXVector HandleVector; typedef MFXVector StatusVector; struct VectorHandleGuard @@ -174,11 +137,32 @@ struct VectorHandleGuard }; -int HandleSort (const void * plhs, const void * prhs) +static int HandleSort (const void * plhs, const void * prhs) { - const MFX_DISP_HANDLE * lhs = *(const MFX_DISP_HANDLE **)plhs; - const MFX_DISP_HANDLE * rhs = *(const MFX_DISP_HANDLE **)prhs; + const MFX_DISP_HANDLE_EX * lhs = *(const MFX_DISP_HANDLE_EX **)plhs; + const MFX_DISP_HANDLE_EX * rhs = *(const MFX_DISP_HANDLE_EX **)prhs; + // prefer HW implementation + if (lhs->implType != MFX_LIB_HARDWARE && rhs->implType == MFX_LIB_HARDWARE) + { + return 1; + } + if (lhs->implType == MFX_LIB_HARDWARE && rhs->implType != MFX_LIB_HARDWARE) + { + return -1; + } + + // prefer integrated GPU + if (lhs->mediaAdapterType != MFX_MEDIA_INTEGRATED && rhs->mediaAdapterType == MFX_MEDIA_INTEGRATED) + { + return 1; + } + if (lhs->mediaAdapterType == MFX_MEDIA_INTEGRATED && rhs->mediaAdapterType != MFX_MEDIA_INTEGRATED) + { + return -1; + } + + // prefer dll with lower API version if (lhs->actualApiVersion < rhs->actualApiVersion) { return -1; @@ -201,9 +185,6 @@ int HandleSort (const void * plhs, const void * prhs) return 0; } -// for LEGACY and UWP_LOADER purposes implementation of MFXinitEx is traditionally loading -// required libmfx*.dll and fill the array of API functions' with corresponded pointers to instantiated libmfx*.dll - mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) { MFX::MFXAutomaticCriticalSection guard(&dispGuard); @@ -219,8 +200,8 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) HandleVector allocatedHandle; VectorHandleGuard handleGuard(allocatedHandle); - MFX_DISP_HANDLE *pHandle; - msdk_disp_char dllName[MFX_MAX_DLL_PATH] = { 0 }; + MFX_DISP_HANDLE_EX *pHandle; + wchar_t dllName[MFX_MAX_DLL_PATH] = { 0 }; MFX::MFXLibraryIterator libIterator; // there iterators are used only if the caller specified implicit type like AUTO @@ -231,6 +212,10 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) // implementation interface masked from the input parameter mfxIMPL implInterface = par.Implementation & -MFX_IMPL_VIA_ANY; +#if (MFX_VERSION >= MFX_VERSION_NEXT) + bool isSingleThread = (implInterface & MFX_IMPL_EXTERNAL_THREADING) > 0; + implInterface &= ~MFX_IMPL_EXTERNAL_THREADING; +#endif mfxIMPL implInterfaceOrig = implInterface; mfxVersion requiredVersion = {{MFX_VERSION_MINOR, MFX_VERSION_MAJOR}}; @@ -258,7 +243,7 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) *session = 0; // allocate the dispatching handle and call-table - pHandle = new MFX_DISP_HANDLE(requiredVersion); + pHandle = new MFX_DISP_HANDLE_EX(requiredVersion); } catch(...) { @@ -274,6 +259,11 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) maxImplIdx = implTypesRange[implMethod].maxIndex; do { +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread && implTypes[curImplIdx].implType != MFX_LIB_HARDWARE) + continue; +#endif + int currentStorage = MFX::MFX_STORAGE_ID_FIRST; implInterface = implInterfaceOrig; do @@ -317,22 +307,39 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) { break; } - DISPATCHER_LOG_INFO((("loading library %S\n"), MSDK2WIDE(dllName))); + DISPATCHER_LOG_INFO((("loading library %S\n"), dllName)); // try to load the selected DLL curImpl = implTypes[curImplIdx].impl; +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread) + curImpl |= MFX_IMPL_EXTERNAL_THREADING; +#endif mfxRes = pHandle->LoadSelectedDLL(dllName, implType, curImpl, implInterface, par); // unload the failed DLL if (MFX_ERR_NONE != mfxRes) { pHandle->Close(); + continue; } - else + + mfxPlatform platform = { MFX_PLATFORM_UNKNOWN, 0, MFX_MEDIA_UNKNOWN }; + if (pHandle->callTable[eMFXVideoCORE_QueryPlatform]) { - libIterator.GetSubKeyName(pHandle->subkeyName, sizeof(pHandle->subkeyName) / sizeof(pHandle->subkeyName[0])); - pHandle->storageID = libIterator.GetStorageID(); - allocatedHandle.push_back(pHandle); - pHandle = new MFX_DISP_HANDLE(requiredVersion); + mfxRes = MFXVideoCORE_QueryPlatform((mfxSession)pHandle, &platform); + if (MFX_ERR_NONE != mfxRes) + { + DISPATCHER_LOG_WRN(("MFXVideoCORE_QueryPlatform failed, rejecting loaded library\n")); + pHandle->Close(); + continue; + } } + pHandle->mediaAdapterType = platform.MediaAdapterType; + DISPATCHER_LOG_INFO((("media adapter type is %d\n"), pHandle->mediaAdapterType)); + + libIterator.GetSubKeyName(pHandle->subkeyName, sizeof(pHandle->subkeyName) / sizeof(pHandle->subkeyName[0])); + pHandle->storageID = libIterator.GetStorageID(); + allocatedHandle.push_back(pHandle); + pHandle = new MFX_DISP_HANDLE_EX(requiredVersion); } while (MFX_ERR_NONE != mfxRes); } @@ -342,18 +349,19 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) } while ((MFX_ERR_NONE != mfxRes) && (MFX::MFX_STORAGE_ID_LAST >= currentStorage)); - } while ((MFX_ERR_NONE != mfxRes) && (++curImplIdx <= maxImplIdx)); - + } while (++curImplIdx <= maxImplIdx); curImplIdx = implTypesRange[implMethod].minIndex; maxImplIdx = implTypesRange[implMethod].maxIndex; - // SOLID dispatcher checks if there are other available media sdk engines implementations in working dir - // UWP dispatcher does not use libraries other than in System32 folder -#if !defined(MEDIASDK_UWP_DISPATCHER) // Load RT from app folder (libmfxsw64 with API >= 1.10) do { +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread && implTypes[curImplIdx].implType != MFX_LIB_HARDWARE) + continue; +#endif + implInterface = implInterfaceOrig; // initialize the library iterator mfxRes = libIterator.Init(implTypes[curImplIdx].implType, @@ -385,10 +393,14 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) { break; } - DISPATCHER_LOG_INFO((("loading library %S\n"), MSDK2WIDE(dllName))); + DISPATCHER_LOG_INFO((("loading library %S\n"), dllName)); // try to load the selected DLL curImpl = implTypes[curImplIdx].impl; +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread) + curImpl |= MFX_IMPL_EXTERNAL_THREADING; +#endif mfxRes = pHandle->LoadSelectedDLL(dllName, implType, curImpl, implInterface, par); // unload the failed DLL if (MFX_ERR_NONE != mfxRes) @@ -405,20 +417,23 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) } pHandle->storageID = MFX::MFX_UNKNOWN_KEY; allocatedHandle.push_back(pHandle); - pHandle = new MFX_DISP_HANDLE(requiredVersion); + pHandle = new MFX_DISP_HANDLE_EX(requiredVersion); } } while (MFX_ERR_NONE != mfxRes); } } while ((MFX_ERR_NONE != mfxRes) && (++curImplIdx <= maxImplIdx)); -#endif // !defined(MEDIASDK_UWP_DISPATCHER) - // Load HW and SW libraries using legacy default DLL search mechanism // set current library index again curImplIdx = implTypesRange[implMethod].minIndex; do { +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread && implTypes[curImplIdx].implType != MFX_LIB_HARDWARE) + continue; +#endif + implInterface = implInterfaceOrig; if (par.Implementation & MFX_IMPL_AUDIO) @@ -436,7 +451,7 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) if (MFX_ERR_NONE == mfxRes) { - DISPATCHER_LOG_INFO((("loading default library %S\n"), MSDK2WIDE(dllName))) + DISPATCHER_LOG_INFO((("loading default library %S\n"), dllName)) // try to load the selected DLL using default DLL search mechanism if (MFX_LIB_HARDWARE == implTypes[curImplIdx].implType) @@ -452,10 +467,15 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) } if (MFX_ERR_NONE == mfxRes) { + curImpl = implTypes[curImplIdx].impl; +#if (MFX_VERSION >= MFX_VERSION_NEXT) + if (isSingleThread) + curImpl |= MFX_IMPL_EXTERNAL_THREADING; +#endif // try to load the selected DLL using default DLL search mechanism mfxRes = pHandle->LoadSelectedDLL(dllName, implTypes[curImplIdx].implType, - implTypes[curImplIdx].impl, + curImpl, implInterface, par); } @@ -469,7 +489,7 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) { pHandle->storageID = MFX::MFX_UNKNOWN_KEY; allocatedHandle.push_back(pHandle); - pHandle = new MFX_DISP_HANDLE(requiredVersion); + pHandle = new MFX_DISP_HANDLE_EX(requiredVersion); } } } @@ -488,9 +508,9 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) if (HandleSort(&(*first), &(*it)) != 0) NeedSort = true; - // select dll with version with lowest version number still greater or equal to requested + // sort allocatedHandle so that the most preferred dll is at the beginning if (NeedSort) - qsort(&(*allocatedHandle.begin()), allocatedHandle.size(), sizeof(MFX_DISP_HANDLE*), &HandleSort); + qsort(&(*allocatedHandle.begin()), allocatedHandle.size(), sizeof(MFX_DISP_HANDLE_EX*), &HandleSort); } HandleVector::iterator candidate = allocatedHandle.begin(); // check the final result of loading @@ -532,14 +552,11 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) hive.insert(hive.end(), plgsInHive.begin(), plgsInHive.end()); } -#if defined(MEDIASDK_USE_CFGFILES) || !defined(MEDIASDK_UWP_LOADER) // SOLID dispatcher also loads plug-ins from file system MFX::MFXPluginsInFS plgsInFS(apiVerActual); hive.insert(hive.end(), plgsInFS.begin(), plgsInFS.end()); -#endif // defined(MEDIASDK_USE_CFGFILES) || !defined(MEDIASDK_UWP_LOADER) } - // UWP dispatcher uses stubs pHandle->callPlugInsTable[eMFXVideoUSER_Load] = (mfxFunctionPointer)MFXVideoUSER_Load; pHandle->callPlugInsTable[eMFXVideoUSER_LoadByPath] = (mfxFunctionPointer)MFXVideoUSER_LoadByPath; pHandle->callPlugInsTable[eMFXVideoUSER_UnLoad] = (mfxFunctionPointer)MFXVideoUSER_UnLoad; @@ -554,7 +571,41 @@ mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) // everything is OK. Save pointers to the output variable *candidate = 0; // keep this one safe from guard destructor - *((MFX_DISP_HANDLE **) session) = pHandle; + + + //=================================== + + // MFXVideoCORE_QueryPlatform call creates d3d device handle, so we have handle right after MFXInit and can't accept external handle + // This is a workaround which calls close-init to remove that handle + + mfxFunctionPointer *actualTable = (pHandle->impl & MFX_IMPL_AUDIO) ? pHandle->callAudioTable : pHandle->callTable; + mfxFunctionPointer pFunc; + + pFunc = actualTable[eMFXClose]; + mfxRes = (*(mfxStatus(MFX_CDECL *) (mfxSession)) pFunc) (pHandle->session); + if (mfxRes != MFX_ERR_NONE) + return mfxRes; + + pHandle->session = 0; + bool callOldInit = (pHandle->impl & MFX_IMPL_AUDIO) || !actualTable[eMFXInitEx]; + pFunc = actualTable[(callOldInit) ? eMFXInit : eMFXInitEx]; + + mfxVersion version(pHandle->apiVersion); + if (callOldInit) + { + pHandle->loadStatus = (*(mfxStatus(MFX_CDECL *) (mfxIMPL, mfxVersion *, mfxSession *)) pFunc) (pHandle->impl | pHandle->implInterface, &version, &pHandle->session); + } + else + { + mfxInitParam initPar = par; + initPar.Implementation = pHandle->impl | pHandle->implInterface; + initPar.Version = version; + pHandle->loadStatus = (*(mfxStatus(MFX_CDECL *) (mfxInitParam, mfxSession *)) pFunc) (initPar, &pHandle->session); + } + + //=================================== + + *((MFX_DISP_HANDLE_EX **) session) = pHandle; return pHandle->loadStatus; @@ -690,15 +741,14 @@ mfxStatus MFXVideoUSER_LoadByPath(mfxSession session, const mfxPluginUID *uid, m } DISPATCHER_LOG_INFO((("MFXVideoUSER_LoadByPath: %S uid=" MFXGUIDTYPE()" version=%d\n") - , MSDK2WIDE(path) + , path , MFXGUIDTOHEX(uid) , version)) PluginDescriptionRecord record; record.sName[0] = 0; -#if defined(_WIN32) || defined(__CYGWIN__) - msdk_disp_char wPath[MAX_PLUGIN_PATH]; + wchar_t wPath[MAX_PLUGIN_PATH]; int res = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, len, wPath, MAX_PLUGIN_PATH-1); if (!res) @@ -708,10 +758,8 @@ mfxStatus MFXVideoUSER_LoadByPath(mfxSession session, const mfxPluginUID *uid, m } wPath[res]=0; - msdk_disp_char_cpy_s(record.sPath, MAX_PLUGIN_PATH, wPath); -#else // Linux/Android - msdk_disp_char_cpy_s(record.sPath, MAX_PLUGIN_PATH, path); -#endif + wcscpy_s(record.sPath, MAX_PLUGIN_PATH, wPath); + record.PluginUID = *uid; record.PluginVersion = (mfxU16)version; record.Default = true; @@ -848,40 +896,42 @@ static mfxModuleHandle hModule; // InitialiseMediaSession() implemented in intel_gfx_api.dll mfxStatus MFXInitEx(mfxInitParam par, mfxSession *session) { - HRESULT hr = S_OK; - #if defined(MEDIASDK_ARM_LOADER) - hr = E_NOTIMPL; + + return MFX_ERR_UNSUPPORTED; + #else + wchar_t IntelGFXAPIdllName[MFX_MAX_DLL_PATH] = { 0 }; + mfxI32 adapterNum = -1; - DriverStoreLoader dsLoader; - if (!dsLoader.GetDriverStorePath(IntelGFXAPIdllName, sizeof(IntelGFXAPIdllName))) + switch (par.Implementation & 0xf) { + case MFX_IMPL_SOFTWARE: +#if (MFX_VERSION >= MFX_VERSION_NEXT) + case MFX_IMPL_SINGLE_THREAD: +#endif return MFX_ERR_UNSUPPORTED; + case MFX_IMPL_AUTO: + case MFX_IMPL_HARDWARE: + adapterNum = 0; + break; + case MFX_IMPL_HARDWARE2: + adapterNum = 1; + break; + case MFX_IMPL_HARDWARE3: + adapterNum = 2; + break; + case MFX_IMPL_HARDWARE4: + adapterNum = 3; + break; + default: + return GfxApiInitPriorityIntegrated(par, session, hModule); } - size_t pathLen = wcslen(IntelGFXAPIdllName); - mfx_get_default_intel_gfx_api_dll_name(IntelGFXAPIdllName + pathLen, sizeof(IntelGFXAPIdllName) / sizeof(IntelGFXAPIdllName[0]) - pathLen); - DISPATCHER_LOG_INFO((("loading %S\n"), IntelGFXAPIdllName)); + return GfxApiInitByAdapterNum(par, adapterNum, session, hModule); - hModule = MFX::mfx_dll_load(IntelGFXAPIdllName); - if (!hModule) - { - DISPATCHER_LOG_ERROR("Can't load intel_gfx_api\n"); - return MFX_ERR_UNSUPPORTED; - } - - mfxFunctionPointer pFunc = (mfxFunctionPointer)mfx_dll_get_addr(hModule, "InitialiseMediaSession"); - if (!pFunc) - { - DISPATCHER_LOG_ERROR("Can't find required API function: InitialiseMediaSession\n"); - return MFX_ERR_UNSUPPORTED; - } - hr = (*(HRESULT(APIENTRY *) (HANDLE*, LPVOID, LPVOID)) pFunc) ((HANDLE*)session, &par, NULL); #endif - - return (hr == S_OK) ? MFX_ERR_NONE : (mfxStatus)hr; } // for the UWP_DISPATCHER purposes implementation of MFXClose is calling @@ -892,27 +942,20 @@ mfxStatus MFXClose(mfxSession session) return MFX_ERR_INVALID_HANDLE; } - HRESULT hr = S_OK; + mfxStatus sts = MFX_ERR_NONE; #if defined(MEDIASDK_ARM_LOADER) - hr = E_NOTIMPL; + + sts = MFX_ERR_UNSUPPORTED; + #else - if (hModule) - { - mfxFunctionPointer pFunc = (mfxFunctionPointer)mfx_dll_get_addr(hModule, "DisposeMediaSession"); - if (!pFunc) - { - DISPATCHER_LOG_ERROR("Can't find required API function: DisposeMediaSession\n"); - return MFX_ERR_INVALID_HANDLE; - } - hr = (*(HRESULT(APIENTRY *) (HANDLE)) pFunc) ((HANDLE)session); - } - else - return MFX_ERR_INVALID_HANDLE; + + sts = GfxApiClose(session, hModule); + #endif session = (mfxSession)NULL; - return (hr == S_OK) ? MFX_ERR_NONE : mfxStatus(hr); + return sts; } #undef FUNCTION diff --git a/src/mfx_critical_section.cpp b/src/mfx_critical_section.cpp index 23ba18c..3920f42 100644 --- a/src/mfx_critical_section.cpp +++ b/src/mfx_critical_section.cpp @@ -20,8 +20,6 @@ #include "mfx_critical_section.h" -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include // SDK re-declares the following functions with different call declarator. // We don't need them. Just redefine them to nothing. @@ -74,5 +72,3 @@ void mfxLeaveCriticalSection(mfxCriticalSection *pCSection) } // void mfxLeaveCriticalSection(mfxCriticalSection *pCSection) } // namespace MFX - -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) diff --git a/src/mfx_dispatcher.cpp b/src/mfx_dispatcher.cpp index 163f53e..ebe8143 100644 --- a/src/mfx_dispatcher.cpp +++ b/src/mfx_dispatcher.cpp @@ -25,13 +25,7 @@ #include #include -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include - #pragma warning(disable:4355) -#else - #include - #include -#endif // defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) +#include #include "mfx_dxva2_device.h" #include "mfx/mfxvideo++.h" @@ -39,6 +33,8 @@ #include "mfx/mfxadapter.h" #include +#pragma warning(disable:4355) + MFX_DISP_HANDLE::MFX_DISP_HANDLE(const mfxVersion requiredVersion) : _mfxSession() ,apiVersion(requiredVersion) @@ -86,7 +82,7 @@ mfxStatus MFX_DISP_HANDLE::Close(void) } // mfxStatus MFX_DISP_HANDLE::Close(void) -mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImplType reqImplType, +mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const wchar_t *pPath, eMfxImplType reqImplType, mfxIMPL reqImpl, mfxIMPL reqImplInterface, mfxInitParam &par) { mfxStatus mfxRes = MFX_ERR_NONE; @@ -140,7 +136,7 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl { assert(hModule == (mfxModuleHandle)0); - DISPATCHER_LOG_BLOCK(("invoking LoadLibrary(%S)\n", MSDK2WIDE(pPath))); + DISPATCHER_LOG_BLOCK(("invoking LoadLibrary(%S)\n", pPath)); // load the DLL into the memory hModule = MFX::mfx_dll_load(pPath); @@ -150,9 +146,9 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl int i; DISPATCHER_LOG_OPERATION({ - msdk_disp_char modulePath[1024]; + wchar_t modulePath[1024]; GetModuleFileNameW((HMODULE)hModule, modulePath, sizeof(modulePath)/sizeof(modulePath[0])); - DISPATCHER_LOG_INFO((("loaded module %S\n"), MSDK2WIDE(modulePath))) + DISPATCHER_LOG_INFO((("loaded module %S\n"), modulePath)) }); if (impl & MFX_IMPL_AUDIO) @@ -163,10 +159,6 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl // construct correct name of the function - remove "_a" postfix mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIAudioFunc[i].pName); - #ifdef ANDROID - // on Android very first call to dlsym may fail - if (!pProc) pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIAudioFunc[i].pName); - #endif if (pProc) { // function exists in the library, @@ -192,10 +184,6 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl for (i = 0; i < eVideoFuncTotal; i += 1) { mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIFunc[i].pName); - #ifdef ANDROID - // on Android very first call to dlsym may fail - if (!pProc) pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIFunc[i].pName); - #endif if (pProc) { // function exists in the library, @@ -218,11 +206,7 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl } else { -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) DISPATCHER_LOG_WRN((("can't find DLL: GetLastErr()=0x%x\n"), GetLastError())) -#else - DISPATCHER_LOG_WRN((("can't find DLL: dlerror() = \"%s\"\n"), dlerror())); -#endif mfxRes = MFX_ERR_UNSUPPORTED; } } @@ -294,7 +278,7 @@ mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImpl loadStatus = mfxRes; return mfxRes; -} // mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImplType implType, mfxIMPL impl) +} // mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const wchar_t *pPath, eMfxImplType implType, mfxIMPL impl) mfxStatus MFX_DISP_HANDLE::UnLoadSelectedDLL(void) { @@ -345,6 +329,13 @@ mfxStatus MFX_DISP_HANDLE::UnLoadSelectedDLL(void) } // mfxStatus MFX_DISP_HANDLE::UnLoadSelectedDLL(void) + +MFX_DISP_HANDLE_EX::MFX_DISP_HANDLE_EX(const mfxVersion requiredVersion) + : MFX_DISP_HANDLE(requiredVersion) + , mediaAdapterType(MFX_MEDIA_UNKNOWN) +{} + + #if (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031) static mfxStatus InitDummySession(mfxU32 adapter_n, MFXVideoSession & dummy_session) { @@ -409,6 +400,7 @@ static inline mfxI32 iGPU_priority(const void* ll, const void* rr) static void RearrangeInPriorityOrder(const mfxComponentInfo & info, MFX::MFXVector & vec) { + (void)info; { // Move iGPU to top priority qsort(vec.data(), vec.size(), sizeof(mfxAdapterInfo), &iGPU_priority); diff --git a/src/mfx_dispatcher.h b/src/mfx_dispatcher.h index cfccaeb..278e05f 100644 --- a/src/mfx_dispatcher.h +++ b/src/mfx_dispatcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2019 Intel Corporation +// Copyright (c) 2012-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,6 +34,8 @@ mfxStatus MFXQueryVersion(mfxSession session, mfxVersion *version); + + enum { // to avoid code changing versions are just inherited @@ -109,7 +111,7 @@ enum eMfxImplType enum { MFX_DISPATCHER_VERSION_MAJOR = 1, - MFX_DISPATCHER_VERSION_MINOR = 2 + MFX_DISPATCHER_VERSION_MINOR = 3 }; struct _mfxSession @@ -134,7 +136,7 @@ struct MFX_DISP_HANDLE : public _mfxSession ~MFX_DISP_HANDLE(void); // Load the library's module - mfxStatus LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImplType implType, mfxIMPL impl, mfxIMPL implInterface, mfxInitParam &par); + mfxStatus LoadSelectedDLL(const wchar_t *pPath, eMfxImplType implType, mfxIMPL impl, mfxIMPL implInterface, mfxInitParam &par); // Unload the library's module mfxStatus UnLoadSelectedDLL(void); @@ -159,7 +161,7 @@ struct MFX_DISP_HANDLE : public _mfxSession // Status of loaded dll mfxStatus loadStatus; // Resgistry subkey name for windows version - msdk_disp_char subkeyName[MFX_MAX_REGISTRY_KEY_NAME]; + wchar_t subkeyName[MFX_MAX_REGISTRY_KEY_NAME]; // Storage ID for windows version int storageID; @@ -176,26 +178,37 @@ struct MFX_DISP_HANDLE : public _mfxSession }; +// This struct extends MFX_DISP_HANDLE, we cannot extend MFX_DISP_HANDLE itself due to possible compatibility issues +// This struct was added in dispatcher version 1.3 +// Check dispatcher handle's version when you cast session struct which came from outside of MSDK API function to this +struct MFX_DISP_HANDLE_EX : public MFX_DISP_HANDLE +{ + MFX_DISP_HANDLE_EX(const mfxVersion requiredVersion); + + mfxU16 mediaAdapterType; + mfxU16 reserved[10]; +}; + // declare comparison operator inline bool operator == (const mfxVersion &one, const mfxVersion &two) { return (one.Version == two.Version); -} // bool operator == (const mfxVersion &one, const mfxVersion &two) +} inline bool operator < (const mfxVersion &one, const mfxVersion &two) { return (one.Major < two.Major) || ((one.Major == two.Major) && (one.Minor < two.Minor)); -} // bool operator < (const mfxVersion &one, const mfxVersion &two) +} inline bool operator <= (const mfxVersion &one, const mfxVersion &two) { return (one == two) || (one < two); -} // bool operator <= (const mfxVersion &one, const mfxVersion &two) +} // diff --git a/src/mfx_dispatcher_defs.h b/src/mfx_dispatcher_defs.h index 9a6eed9..bb61a58 100644 --- a/src/mfx_dispatcher_defs.h +++ b/src/mfx_dispatcher_defs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2019 Intel Corporation +// Copyright (c) 2013-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -31,54 +31,17 @@ #define MAX_PLUGIN_PATH 4096 #define MAX_PLUGIN_NAME 4096 -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) -typedef wchar_t msdk_disp_char; -#define MSDK2WIDE(x) x - -#if _MSC_VER >= 1400 - #define msdk_disp_char_cpy_s(to, to_size, from) wcscpy_s(to,to_size, from) -#else - #define msdk_disp_char_cpy_s(to, to_size, from) wcscpy(to, from) -#endif - #if _MSC_VER < 1400 #define wcscpy_s(to,to_size, from) wcscpy(to, from) #define wcscat_s(to,to_size, from) wcscat(to, from) #endif -#else -typedef char msdk_disp_char; -//#define msdk_disp_char_cpy_s(to, to_size, from) strcpy(to, from) - -inline void msdk_disp_char_cpy_s(char * to, size_t to_size, const char * from) -{ - size_t source_len = strlen(from); - size_t num_chars = (to_size - 1) < source_len ? (to_size - 1) : source_len; - strncpy(to, from, num_chars); - to[num_chars] = 0; -} - -#if defined(MFX_DISPATCHER_LOG) -#define MSDK2WIDE(x) getWideString(x).c_str() - -inline std::wstring getWideString(const char * string) -{ - size_t len = strlen(string); - return std::wstring(string, string + len); -} -#else - #define MSDK2WIDE(x) x -#endif - -#endif - -#if defined(__GNUC__) && !defined(_WIN32) && !defined(_WIN64) -#define sscanf_s sscanf -#define swscanf_s swscanf -#endif - - // declare library module's handle typedef void * mfxModuleHandle; typedef void (MFX_CDECL * mfxFunctionPointer)(void); + +// Tracer uses lib loading from Program Files logic (via Dispatch reg key) to make dispatcher load tracer dll. +// With DriverStore loading put at 1st place, dispatcher loads real lib before it finds tracer dll. +// This workaround explicitly checks tracer presence in Dispatch reg key and loads tracer dll before the search for lib in all other places. +#define MFX_TRACER_WA_FOR_DS 1 diff --git a/src/mfx_dispatcher_log.cpp b/src/mfx_dispatcher_log.cpp index d0c7323..b96306b 100644 --- a/src/mfx_dispatcher_log.cpp +++ b/src/mfx_dispatcher_log.cpp @@ -22,13 +22,11 @@ #include "mfx_dispatcher_log.h" #include "mfxstructures.h" -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #include #if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER) #include #include #endif -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #include #include #include @@ -49,14 +47,14 @@ struct CodeStringTable {code, #code} static CodeStringTable StringsOfImpl[] = { - DEFINE_CODE(MFX_IMPL_AUTO), + DEFINE_CODE(MFX_IMPL_AUTO), DEFINE_CODE(MFX_IMPL_SOFTWARE), - DEFINE_CODE(MFX_IMPL_HARDWARE), - DEFINE_CODE(MFX_IMPL_AUTO_ANY), - DEFINE_CODE(MFX_IMPL_HARDWARE_ANY), - DEFINE_CODE(MFX_IMPL_HARDWARE2), - DEFINE_CODE(MFX_IMPL_HARDWARE3), - DEFINE_CODE(MFX_IMPL_HARDWARE4), + DEFINE_CODE(MFX_IMPL_HARDWARE), + DEFINE_CODE(MFX_IMPL_AUTO_ANY), + DEFINE_CODE(MFX_IMPL_HARDWARE_ANY), + DEFINE_CODE(MFX_IMPL_HARDWARE2), + DEFINE_CODE(MFX_IMPL_HARDWARE3), + DEFINE_CODE(MFX_IMPL_HARDWARE4), DEFINE_CODE(MFX_IMPL_UNSUPPORTED) }; @@ -94,7 +92,7 @@ static CodeStringTable StringsOfStatus[] = DEFINE_CODE(MFX_WRN_INCOMPATIBLE_VIDEO_PARAM), DEFINE_CODE(MFX_WRN_VALUE_NOT_CHANGED ), DEFINE_CODE(MFX_WRN_OUT_OF_RANGE ), - + }; #define CODE_TO_STRING(code, array)\ @@ -183,7 +181,7 @@ void DispatchLog::ExchangeSink(int nsink, IMsgHandler *oldHdl, IMsgHandler *ne if (nsink & DL_SINK_IMsgHandler) { std::list :: iterator it = std::find(m_Recepients.begin(), m_Recepients.end(), oldHdl); - + //cannot exchange in that case if (m_Recepients.end() == it) return; @@ -213,7 +211,7 @@ void DispatchLog::Write(int level, int opcode, const char * msg, va_list argpt { case DL_SINK_NULL: break; - + case DL_SINK_PRINTF: { char msg_formated[8048] = {0}; @@ -259,7 +257,7 @@ class ETWHandler : public IMsgHandler { return; } - + EventRegister(&rguid, NULL, NULL, &m_EventHandle); m_bProviderEnable = 0 != EventProviderEnabled(m_EventHandle, 1,0); @@ -294,10 +292,10 @@ class ETWHandler : public IMsgHandler EVENT_DATA_DESCRIPTOR data_descriptor; EventDescZero(&descriptor); - - descriptor.Opcode = (UCHAR)opcode; + + descriptor.Opcode = (UCHAR)opcode; descriptor.Level = (UCHAR)level; - + if (m_bUseFormatter) { if (NULL != msg) @@ -314,7 +312,7 @@ class ETWHandler : public IMsgHandler } }else { - //TODO: non formated events supports under zbb + //TODO: non formated events supports under zbb } EventWrite(m_EventHandle, &descriptor, 1, &data_descriptor); @@ -325,7 +323,7 @@ class ETWHandler : public IMsgHandler //we may not use formatter in some cases described in dispatch_log macro //it significantly increases performance by eliminating any vsprintf operations bool m_bUseFormatter; - //consumer is attached, dispatcher trace to reduce formating overhead + //consumer is attached, dispatcher trace to reduce formating overhead //submits event only if consumer attached bool m_bProviderEnable; REGHANDLE m_EventHandle; diff --git a/src/mfx_dispatcher_log.h b/src/mfx_dispatcher_log.h index 5052a97..a958972 100644 --- a/src/mfx_dispatcher_log.h +++ b/src/mfx_dispatcher_log.h @@ -81,7 +81,6 @@ enum //is a vital if mediasdk wont use #define DISPATCHER_LOG_HEAP_SINGLETONES -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) // guid for all dispatcher events #define DISPATCHER_LOG_EVENT_GUID L"{EB0538CC-4FEE-484d-ACEE-1182E9F37A57}" @@ -92,8 +91,6 @@ enum //#define DISPATCHER_LOG_REGISTER_FILE_WRITER #define DISPACTHER_LOG_FW_PATH "c:\\dispatcher.log" -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include #include @@ -105,7 +102,6 @@ class IMsgHandler virtual void Write(int level, int opcode, const char * msg, va_list argptr) = 0; }; -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if DISPATCHER_LOG_USE_FORMATING #define DISPATCHER_LOG(lvl, opcode, str)\ @@ -125,10 +121,6 @@ class IMsgHandler #endif//DISPATCHER_LOG_USE_FORMATING #define DISPATCHER_LOG_OPERATION(operation) operation -#else -#define DISPATCHER_LOG(lvl, opcode, str) -#define DISPATCHER_LOG_OPERATION(operation) -#endif #define __name_from_line( name, line ) name ## line #define _name_from_line( name , line) __name_from_line( name, line ) @@ -227,7 +219,6 @@ struct DispatchLogBlockHelper }; //----utility sinks----- -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER) class ETWHandlerFactory : public DSSingleTone @@ -244,7 +235,6 @@ class ETWHandlerFactory ETWHandlerFactory(){} }; #endif -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(DISPATCHER_LOG_REGISTER_FILE_WRITER) class FileSink @@ -267,11 +257,7 @@ class FileSink FILE * m_hdl; FileSink(const std::string & log_file) { -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) fopen_s(&m_hdl, log_file.c_str(), "a"); -#else - m_hdl = fopen(log_file.c_str(), "a"); -#endif } }; diff --git a/src/mfx_driver_store_loader.cpp b/src/mfx_driver_store_loader.cpp new file mode 100644 index 0000000..17f0078 --- /dev/null +++ b/src/mfx_driver_store_loader.cpp @@ -0,0 +1,218 @@ +// Copyright (c) 2019-2020 Intel Corporation +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include + +#include "mfx_driver_store_loader.h" +#include "mfx_dispatcher_log.h" +#include "mfx_load_dll.h" + +namespace MFX +{ + + +inline bool IsIntelDeviceInstanceID(const wchar_t * DeviceID) +{ + return wcsstr(DeviceID, L"VEN_8086") || wcsstr(DeviceID, L"ven_8086"); +} + +inline bool ExctractDeviceID(const wchar_t* descrString, mfxU32& deviceID) +{ + const wchar_t *begin = wcsstr(descrString, L"DEV_"); + + if (!begin) + { + begin = wcsstr(descrString, L"dev_"); + if (!begin) + { + DISPATCHER_LOG_WRN(("exctracting device id: failed to find device id substring\n")); + return false; + } + } + + begin += wcslen(L"DEV_"); + deviceID = wcstoul(begin, NULL, 16); + if (!deviceID) + { + DISPATCHER_LOG_WRN(("exctracting device id: failed to convert device id str to int\n")); + return false; + } + + return true; +} + + + +DriverStoreLoader::DriverStoreLoader(void) + : m_moduleCfgMgr(NULL) + , m_pCM_Get_Device_ID_List_Size(NULL) + , m_pCM_Get_Device_ID_List(NULL) + , m_pCM_Locate_DevNode(NULL) + , m_pCM_Open_DevNode_Key(NULL) +{ +} + +DriverStoreLoader::~DriverStoreLoader(void) +{ +} + +bool DriverStoreLoader::GetDriverStorePath(wchar_t * path, DWORD dwPathSize, mfxU32 deviceID) +{ + if (path == NULL || dwPathSize == 0) + { + return false; + } + + // Obtain a PnP handle to the Intel graphics adapter + CONFIGRET result = CR_SUCCESS; + ULONG DeviceIDListSize = 0; + MFXVector DeviceIDList; + wchar_t DisplayGUID[40]; + DEVINST DeviceInst; + + DISPATCHER_LOG_INFO(("Looking for MediaSDK in DriverStore\n")); + + if (!LoadCfgMgr() || !LoadCmFuncs()) + { + return false; + } + + if (StringFromGUID2(GUID_DEVCLASS_DISPLAY, DisplayGUID, sizeof(DisplayGUID)) == 0) + { + DISPATCHER_LOG_WRN(("Couldn't prepare string from GUID\n")); + return false; + } + + do + { + result = m_pCM_Get_Device_ID_List_Size(&DeviceIDListSize, DisplayGUID, CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT); + if (result != CR_SUCCESS) + { + break; + } + + try + { + DeviceIDList.resize(DeviceIDListSize); + } + catch (...) + { + return false; + } + result = m_pCM_Get_Device_ID_List(DisplayGUID, DeviceIDList.data(), DeviceIDListSize, CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT); + + } while (result == CR_BUFFER_SMALL); + + if (result != CR_SUCCESS) + { + return false; + } + + //Look for MediaSDK record + wchar_t *begin = DeviceIDList.data(); + wchar_t *end = begin + DeviceIDList.size(); + size_t len = 0; + + for (; (begin < end) && (len = wcslen(begin)) > 0; begin += len + 1) + { + if (IsIntelDeviceInstanceID(begin)) + { + mfxU32 curDeviceID = 0; + if (!ExctractDeviceID(begin, curDeviceID) || curDeviceID != deviceID) + { + continue; + } + + result = m_pCM_Locate_DevNode(&DeviceInst, begin, CM_LOCATE_DEVNODE_NORMAL); + if (result != CR_SUCCESS) + { + continue; + } + + HKEY hKey_sw; + result = m_pCM_Open_DevNode_Key(DeviceInst, KEY_READ, 0, RegDisposition_OpenExisting, &hKey_sw, CM_REGISTRY_SOFTWARE); + if (result != CR_SUCCESS) + { + continue; + } + + ULONG nError; + + DWORD pathSize = dwPathSize; + + nError = RegQueryValueExW(hKey_sw, L"DriverStorePathForMediaSDK", 0, NULL, (LPBYTE)path, &pathSize); + + RegCloseKey(hKey_sw); + + if (ERROR_SUCCESS == nError) + { + if (path[wcslen(path) - 1] != '/' && path[wcslen(path) - 1] != '\\') + { + wcscat_s(path, MFX_MAX_DLL_PATH, L"\\"); + } + DISPATCHER_LOG_INFO(("DriverStore path is found\n")); + return true; + } + } + } + + DISPATCHER_LOG_INFO(("DriverStore path isn't found\n")); + return false; + +} // bool DriverStoreLoader::GetDriverStorePath(wchar_t * path, DWORD dwPathSize) + +bool DriverStoreLoader::LoadCfgMgr() +{ + if (!m_moduleCfgMgr) + { + m_moduleCfgMgr = mfx_dll_load(L"cfgmgr32.dll"); + + if (!m_moduleCfgMgr) + { + DISPATCHER_LOG_WRN(("cfgmgr32.dll couldn't be loaded\n")); + return false; + } + } + + return true; + +} // bool DriverStoreLoader::LoadCfgMgr() + +bool DriverStoreLoader::LoadCmFuncs() +{ + if (!m_pCM_Get_Device_ID_List || !m_pCM_Get_Device_ID_List_Size || !m_pCM_Locate_DevNode || !m_pCM_Open_DevNode_Key) + { + m_pCM_Get_Device_ID_List = (Func_CM_Get_Device_ID_ListW) mfx_dll_get_addr((HMODULE)m_moduleCfgMgr, "CM_Get_Device_ID_ListW"); + m_pCM_Get_Device_ID_List_Size = (Func_CM_Get_Device_ID_List_SizeW) mfx_dll_get_addr((HMODULE)m_moduleCfgMgr, "CM_Get_Device_ID_List_SizeW"); + m_pCM_Locate_DevNode = (Func_CM_Locate_DevNodeW) mfx_dll_get_addr((HMODULE)m_moduleCfgMgr, "CM_Locate_DevNodeW"); + m_pCM_Open_DevNode_Key = (Func_CM_Open_DevNode_Key) mfx_dll_get_addr((HMODULE)m_moduleCfgMgr, "CM_Open_DevNode_Key"); + + if (!m_pCM_Get_Device_ID_List || !m_pCM_Get_Device_ID_List_Size || !m_pCM_Locate_DevNode || !m_pCM_Open_DevNode_Key) + { + DISPATCHER_LOG_WRN(("One of cfgmgr32.dll function isn't found\n")); + return false; + } + } + + return true; + +} // bool DriverStoreLoader::LoadCmFuncs() + +} // namespace MFX diff --git a/src/mfx_driver_store_loader.h b/src/mfx_driver_store_loader.h new file mode 100644 index 0000000..372794f --- /dev/null +++ b/src/mfx_driver_store_loader.h @@ -0,0 +1,73 @@ +// Copyright (c) 2019-2020 Intel Corporation +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#if !defined(__MFX_DRIVER_STORE_LOADER_H) +#define __MFX_DRIVER_STORE_LOADER_H + +#include +#include +#include + +#include "mfx_dispatcher_defs.h" +#ifdef __MINGW32__ +#ifndef CM_GETIDLIST_FILTER_PRESENT +#define CM_GETIDLIST_FILTER_PRESENT (0x00000100) +#endif +#ifndef CM_GETIDLIST_FILTER_CLASS +#define CM_GETIDLIST_FILTER_CLASS (0x00000200) +#endif +#endif + +namespace MFX +{ + +typedef CONFIGRET(WINAPI *Func_CM_Get_Device_ID_List_SizeW)(PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags); +typedef CONFIGRET(WINAPI *Func_CM_Get_Device_ID_ListW)(PCWSTR pszFilter, PZZWSTR Buffer, ULONG BufferLen, ULONG ulFlags); +typedef CONFIGRET(WINAPI *Func_CM_Locate_DevNodeW)(PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags); +typedef CONFIGRET(WINAPI *Func_CM_Open_DevNode_Key)(DEVINST dnDevNode, REGSAM samDesired, ULONG ulHardwareProfile, REGDISPOSITION Disposition, PHKEY phkDevice, ULONG ulFlags); + +class DriverStoreLoader +{ +public: + DriverStoreLoader(void); + ~DriverStoreLoader(void); + + bool GetDriverStorePath(wchar_t *path, DWORD dwPathSize, mfxU32 deviceID); + +protected: + bool LoadCfgMgr(); + bool LoadCmFuncs(); + + mfxModuleHandle m_moduleCfgMgr; + Func_CM_Get_Device_ID_List_SizeW m_pCM_Get_Device_ID_List_Size; + Func_CM_Get_Device_ID_ListW m_pCM_Get_Device_ID_List; + Func_CM_Locate_DevNodeW m_pCM_Locate_DevNode; + Func_CM_Open_DevNode_Key m_pCM_Open_DevNode_Key; + +private: + // unimplemented by intent to make this class non-copyable + DriverStoreLoader(const DriverStoreLoader &); + void operator=(const DriverStoreLoader &); + +}; + +} // namespace MFX + +#endif // __MFX_DRIVER_STORE_LOADER_H diff --git a/src/mfx_dxva2_device.cpp b/src/mfx_dxva2_device.cpp index 9935574..ad69528 100644 --- a/src/mfx_dxva2_device.cpp +++ b/src/mfx_dxva2_device.cpp @@ -18,7 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #define INITGUID #include #include @@ -99,23 +98,19 @@ void DXDevice::LoadDLLModule(const wchar_t *pModuleName) #if !defined(MEDIASDK_UWP_DISPATCHER) DWORD prevErrorMode = 0; // set the silent error mode -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode); #else prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); #endif #endif // !defined(MEDIASDK_UWP_DISPATCHER) -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // load specified library m_hModule = LoadLibraryExW(pModuleName, NULL, 0); -#else - m_hModule = (HMODULE)(intptr_t) 0x1234; // fake value, we can't load system DLLs -#endif #if !defined(MEDIASDK_UWP_DISPATCHER) // set the previous error mode -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(prevErrorMode, NULL); #else SetErrorMode(prevErrorMode); @@ -128,9 +123,7 @@ void DXDevice::UnloadDLLModule(void) { if (m_hModule) { -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) FreeLibrary(m_hModule); -#endif m_hModule = (HMODULE) 0; } @@ -452,6 +445,7 @@ bool DXVA2Device::InitD3D9(const mfxU32 adapterNum) return false; } + m_numAdapters = d3d9Device.GetAdapterCount(); // check if the application is under Remote Desktop @@ -571,4 +565,4 @@ mfxU32 DXVA2Device::GetAdapterCount(void) const return m_numAdapters; } // mfxU32 DXVA2Device::GetAdapterCount(void) const -#endif + diff --git a/src/mfx_dxva2_device.h b/src/mfx_dxva2_device.h index f35e76c..839351f 100644 --- a/src/mfx_dxva2_device.h +++ b/src/mfx_dxva2_device.h @@ -21,7 +21,6 @@ #if !defined(__MFX_DXVA2_DEVICE_H) #define __MFX_DXVA2_DEVICE_H -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #include #define TOSTRING(L) #L @@ -40,8 +39,6 @@ #pragma message("\n\nATTENTION:\nin file\n\t" __FILE__ " (" STRINGIFY(__LINE__) "):\nUsing of D3D9 enabled!\n\n") #endif -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include #ifdef DXVA2DEVICE_LOG @@ -90,10 +87,8 @@ class DXDevice // Free DLL module void UnloadDLLModule(void); -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) // Handle to the DLL library HMODULE m_hModule; -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) // Number of adapters available mfxU32 m_numAdapters; @@ -113,9 +108,6 @@ class DXDevice void operator=(const DXDevice &); }; - -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #ifdef MFX_D3D9_ENABLED class D3D9Device : public DXDevice { @@ -169,7 +161,6 @@ class DXGI1Device : public DXDevice void *m_pDXGIAdapter1; }; -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) class DXVA2Device { diff --git a/src/mfx_library_iterator.cpp b/src/mfx_library_iterator.cpp index 808960a..9a2cfe2 100644 --- a/src/mfx_library_iterator.cpp +++ b/src/mfx_library_iterator.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2019 Intel Corporation +// Copyright (c) 2012-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -18,7 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #include "mfx_library_iterator.h" #include "mfx_dispatcher.h" @@ -30,8 +29,6 @@ #include #include -#include - namespace MFX { @@ -75,7 +72,7 @@ mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterf // try to create the Direct3D 9 device and find right adapter if (!dxvaDevice.InitD3D9(adapterNum)) { - DISPATCHER_LOG_INFO((("dxvaDevice.InitD3D9(%d) Failed "), adapterNum )); + DISPATCHER_LOG_INFO((("dxvaDevice.InitD3D9(%d) Failed\n"), adapterNum )); return MFX_ERR_UNSUPPORTED; } } @@ -84,7 +81,7 @@ mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterf // try to open DXGI 1.1 device to get hardware ID if (!dxvaDevice.InitDXGI1(adapterNum)) { - DISPATCHER_LOG_INFO((("dxvaDevice.InitDXGI1(%d) Failed "), adapterNum )); + DISPATCHER_LOG_INFO((("dxvaDevice.InitDXGI1(%d) Failed\n"), adapterNum )); return MFX_ERR_UNSUPPORTED; } } @@ -102,13 +99,13 @@ mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterf } else { - DISPATCHER_LOG_INFO((("Unsupported adapter %d "), adapterNum )); + DISPATCHER_LOG_INFO((("Unsupported adapter %d\n"), adapterNum )); return MFX_ERR_UNSUPPORTED; } } else { - DISPATCHER_LOG_ERROR((("Unknown implementation type %d "), *pImplInterface )); + DISPATCHER_LOG_ERROR((("Unknown implementation type %d\n"), *pImplInterface )); return MFX_ERR_UNSUPPORTED; } @@ -164,21 +161,16 @@ void MFXLibraryIterator::Release(void) DECLSPEC_NOINLINE HMODULE GetThisDllModuleHandle() { -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HMODULE hDll = HMODULE(-1); + HMODULE hDll = NULL; GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(&GetThisDllModuleHandle), &hDll); return hDll; -#else - // this should never be called with MEDIASDK_UWP_LOADER set - return NULL; -#endif } -// msdk_disp_char* sImplPath must be allocated with size not less then msdk_disp_path_len -bool GetImplPath(int storageID, msdk_disp_char* sImplPath) +// wchar_t* sImplPath must be allocated with size not less then msdk_disp_path_len +bool GetImplPath(int storageID, wchar_t* sImplPath) { HMODULE hModule = NULL; @@ -188,20 +180,13 @@ bool GetImplPath(int storageID, msdk_disp_char* sImplPath) case MFX_APP_FOLDER: hModule = 0; break; - -#if defined(MEDIASDK_UWP_LOADER) || defined(MEDIASDK_UWP_PROCTABLE) case MFX_PATH_MSDK_FOLDER: hModule = GetThisDllModuleHandle(); + HMODULE exeModule = GetModuleHandleW(NULL); //It should works only if Dispatcher is linked with Dynamic Linked Library - if (hModule != HMODULE(-1) && GetProcAddress(hModule, "DllMain") == NULL) + if (!hModule || !exeModule || hModule == exeModule) return false; break; -#endif - - } - - if(hModule == HMODULE(-1)) { - return false; } DWORD nSize = 0; @@ -218,7 +203,7 @@ bool GetImplPath(int storageID, msdk_disp_char* sImplPath) // for any case because WinXP implementation of GetModuleFileName does not add \0 to the end of string sImplPath[nSize] = L'\0'; - msdk_disp_char * dirSeparator = wcsrchr(sImplPath, L'\\'); + wchar_t * dirSeparator = wcsrchr(sImplPath, L'\\'); if (dirSeparator != NULL && dirSeparator < (sImplPath + msdk_disp_path_len)) { *++dirSeparator = 0; @@ -239,25 +224,55 @@ mfxStatus MFXLibraryIterator::Init(eMfxImplType implType, mfxIMPL implInterface, Release(); m_StorageID = storageID; m_lastLibIndex = 0; + m_implType = implType; + m_implInterface = implInterface != 0 + ? implInterface + : MFX_IMPL_VIA_ANY; + + // for HW impl check impl interface, check adapter, obtain deviceID and vendorID + if (m_implType != MFX_LIB_SOFTWARE) + { + mfxStatus mfxRes = MFX::SelectImplementationType(adapterNum, &m_implInterface, &m_vendorID, &m_deviceID); + if (MFX_ERR_NONE != mfxRes) + { + return mfxRes; + } + } -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) +#if !defined(MEDIASDK_UWP_DISPATCHER) if (storageID == MFX_CURRENT_USER_KEY || storageID == MFX_LOCAL_MACHINE_KEY) { - return InitRegistry(implType, implInterface, adapterNum, storageID); + return InitRegistry(storageID); + } + +#if defined(MFX_TRACER_WA_FOR_DS) + if (storageID == MFX_TRACER) + { + return InitRegistryTracer(); } #endif - msdk_disp_char sCurrentModulePath[msdk_disp_path_len]; +#endif + + wchar_t sMediaSDKPath[msdk_disp_path_len] = {}; - if(!GetImplPath(storageID, sCurrentModulePath)) { + if (storageID == MFX_DRIVER_STORE) + { + if (!m_driverStoreLoader.GetDriverStorePath(sMediaSDKPath, sizeof(sMediaSDKPath), m_deviceID)) + { + return MFX_ERR_UNSUPPORTED; + } + } + else if(!GetImplPath(storageID, sMediaSDKPath)) + { return MFX_ERR_UNSUPPORTED; } - return InitFolder(implType, implInterface, adapterNum, sCurrentModulePath, storageID); + return InitFolder(implType, sMediaSDKPath, storageID); } // mfxStatus MFXLibraryIterator::Init(eMfxImplType implType, const mfxU32 adapterNum, int storageID) -mfxStatus MFXLibraryIterator::InitRegistry(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID) +mfxStatus MFXLibraryIterator::InitRegistry(int storageID) { #if !defined(MEDIASDK_UWP_DISPATCHER) HKEY rootHKey; @@ -274,22 +289,6 @@ mfxStatus MFXLibraryIterator::InitRegistry(eMfxImplType implType, mfxIMPL implIn return MFX_ERR_UNKNOWN; } - // set the required library's implementation type - m_implType = implType; - m_implInterface = implInterface != 0 - ? implInterface - : MFX_IMPL_VIA_ANY; - - //deviceID and vendorID are not actual for SW library loading - if (m_implType != MFX_LIB_SOFTWARE) - { - mfxStatus mfxRes = MFX::SelectImplementationType(adapterNum, &m_implInterface, &m_vendorID, &m_deviceID); - if (MFX_ERR_NONE != mfxRes) - { - return mfxRes; - } - } - DISPATCHER_LOG_INFO((("Inspecting %s\\%S\n"), (MFX_LOCAL_MACHINE_KEY == storageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"), rootDispPath)) @@ -297,19 +296,39 @@ mfxStatus MFXLibraryIterator::InitRegistry(eMfxImplType implType, mfxIMPL implIn return MFX_ERR_NONE; #else (void) storageID; - (void) adapterNum; - (void) implInterface; - (void) implType; return MFX_ERR_UNSUPPORTED; #endif // #if !defined(MEDIASDK_UWP_DISPATCHER) -} // mfxStatus MFXLibraryIterator::InitRegistry(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID) +} // mfxStatus MFXLibraryIterator::InitRegistry(int storageID) + +#if defined(MFX_TRACER_WA_FOR_DS) +mfxStatus MFXLibraryIterator::InitRegistryTracer() +{ +#if !defined(MEDIASDK_UWP_DISPATCHER) + + const wchar_t tracerRegKeyPath[] = L"Software\\Intel\\MediaSDK\\Dispatch\\tracer"; + + if (!m_baseRegKey.Open(HKEY_LOCAL_MACHINE, tracerRegKeyPath, KEY_READ) && !m_baseRegKey.Open(HKEY_CURRENT_USER, tracerRegKeyPath, KEY_READ)) + { + DISPATCHER_LOG_WRN(("can't find tracer registry key\n")) + return MFX_ERR_UNKNOWN; + } + + DISPATCHER_LOG_INFO(("found tracer registry key\n")) + return MFX_ERR_NONE; + +#else + return MFX_ERR_UNSUPPORTED; +#endif // #if !defined(MEDIASDK_UWP_DISPATCHER) + +} // mfxStatus MFXLibraryIterator::InitRegistryTracer() +#endif -mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, const msdk_disp_char * path, const int storageID) +mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, const wchar_t * path, const int storageID) { const int maxPathLen = sizeof(m_path)/sizeof(m_path[0]); m_path[0] = 0; - msdk_disp_char_cpy_s(m_path, maxPathLen, path); + wcscpy_s(m_path, maxPathLen, path); size_t pathLen = wcslen(m_path); if(storageID==MFX_APP_FOLDER) @@ -322,23 +341,8 @@ mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, mfxIMPL implInte mfx_get_default_dll_name(m_path + pathLen, msdk_disp_path_len - pathLen, implType); } - // set the required library's implementation type - m_implType = implType; - m_implInterface = implInterface != 0 - ? implInterface - : MFX_IMPL_VIA_ANY; - - //deviceID and vendorID are not actual for SW library loading - if (m_implType != MFX_LIB_SOFTWARE) - { - mfxStatus mfxRes = MFX::SelectImplementationType(adapterNum, &m_implInterface, &m_vendorID, &m_deviceID); - if (MFX_ERR_NONE != mfxRes) - { - return mfxRes; - } - } return MFX_ERR_NONE; -} // mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, const msdk_disp_char * path, const int storageID) +} // mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, const wchar_t * path, const int storageID) mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath , size_t pathSize @@ -354,14 +358,12 @@ mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath return MFX_ERR_UNKNOWN; m_lastLibIndex = 1; - msdk_disp_char_cpy_s(pPath, pathSize, m_path); + wcscpy_s(pPath, pathSize, m_path); *pImplType = MFX_LIB_SOFTWARE; return MFX_ERR_NONE; } -#if defined(MEDIASDK_UWP_LOADER) || defined(MEDIASDK_UWP_PROCTABLE) - - if (m_StorageID == MFX_PATH_MSDK_FOLDER) + if (m_StorageID == MFX_PATH_MSDK_FOLDER || m_StorageID == MFX_DRIVER_STORE) { if (m_lastLibIndex != 0) return MFX_ERR_NOT_FOUND; @@ -369,13 +371,35 @@ mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath return MFX_ERR_UNKNOWN; m_lastLibIndex = 1; - msdk_disp_char_cpy_s(pPath, pathSize, m_path); + wcscpy_s(pPath, pathSize, m_path); // do not change impl type return MFX_ERR_NONE; } -#endif #if !defined(MEDIASDK_UWP_DISPATCHER) + +#if defined(MFX_TRACER_WA_FOR_DS) + if (m_StorageID == MFX_TRACER) + { + if (m_lastLibIndex != 0) + return MFX_ERR_NOT_FOUND; + if (m_vendorID != INTEL_VENDOR_ID) + return MFX_ERR_UNKNOWN; + + m_lastLibIndex = 1; + + if (m_baseRegKey.Query(pathKeyName, REG_SZ, (LPBYTE)pPath, (DWORD*)&pathSize)) + { + DISPATCHER_LOG_INFO((("loaded %S : %S\n"), pathKeyName, pPath)); + } + else + { + DISPATCHER_LOG_WRN((("error querying %S : RegQueryValueExA()==0x%x\n"), pathKeyName, GetLastError())); + } + return MFX_ERR_NONE; + } +#endif + wchar_t libPath[MFX_MAX_DLL_PATH] = L""; DWORD libIndex = 0; DWORD libMerit = 0; @@ -508,8 +532,8 @@ mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath { DISPATCHER_LOG_INFO((("loaded %S : %S\n"), pathKeyName, tmpPath)); - msdk_disp_char_cpy_s(libPath, sizeof(libPath) / sizeof(libPath[0]), tmpPath); - msdk_disp_char_cpy_s(m_SubKeyName, sizeof(m_SubKeyName) / sizeof(m_SubKeyName[0]), subKeyName); + wcscpy_s(libPath, sizeof(libPath) / sizeof(libPath[0]), tmpPath); + wcscpy_s(m_SubKeyName, sizeof(m_SubKeyName) / sizeof(m_SubKeyName[0]), subKeyName); libMerit = merit; libIndex = index; @@ -543,7 +567,7 @@ mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath return MFX_ERR_NOT_FOUND; } - msdk_disp_char_cpy_s(pPath, pathSize, libPath); + wcscpy_s(pPath, pathSize, libPath); m_lastLibIndex = libIndex; m_lastLibMerit = libMerit; @@ -560,11 +584,9 @@ mfxIMPL MFXLibraryIterator::GetImplementationType() return m_implInterface; } // mfxIMPL MFXLibraryIterator::GetImplementationType() -bool MFXLibraryIterator::GetSubKeyName(msdk_disp_char *subKeyName, size_t length) const +bool MFXLibraryIterator::GetSubKeyName(wchar_t *subKeyName, size_t length) const { - msdk_disp_char_cpy_s(subKeyName, length, m_SubKeyName); + wcscpy_s(subKeyName, length, m_SubKeyName); return m_bIsSubKeyValid; } } // namespace MFX -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - diff --git a/src/mfx_library_iterator.h b/src/mfx_library_iterator.h index eafa207..db77f2f 100644 --- a/src/mfx_library_iterator.h +++ b/src/mfx_library_iterator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2019 Intel Corporation +// Copyright (c) 2012-2020 Intel Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -28,64 +28,37 @@ #include "mfx_win_reg_key.h" #endif -#include "mfx_dispatcher.h" - -#if !defined(_WIN32) && !defined(_WIN64) && !defined(__CYGWIN__) -struct mfx_disp_adapters -{ - mfxU32 vendor_id; - mfxU32 device_id; -}; +#include "mfx_driver_store_loader.h" -#ifndef __APPLE__ -#define MFX_SO_BASE_NAME_LEN 15 // sizeof("libmfxhw32-p.so") = 15 -#else - -#define MFX_SO_BASE_NAME_LEN 16 // sizeof("libmfxhw64.dylib") = 16 -#endif - -#define MFX_MIN_REAL_LIBNAME MFX_SO_BASE_NAME_LEN + 4 // sizeof("libmfxhw32-p.so.0.0") >= 19 -#define MFX_MAX_REAL_LIBNAME MFX_MIN_REAL_LIBNAME + 8 // sizeof("libmfxhw32-p.so..") <= 27, max(sizeof())=sizeof(0xFFFF) = sizeof(65535) = 5 - -struct mfx_libs -{ - char name[MFX_MAX_REAL_LIBNAME+1]; - mfxVersion version; -}; -#endif +#include "mfx_dispatcher.h" namespace MFX { // declare desired storage ID -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) enum { +#if defined (MFX_TRACER_WA_FOR_DS) MFX_UNKNOWN_KEY = -1, - MFX_CURRENT_USER_KEY = 0, - MFX_LOCAL_MACHINE_KEY = 1, - MFX_APP_FOLDER = 2, -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) - MFX_PATH_MSDK_FOLDER = 3, - MFX_STORAGE_ID_FIRST = MFX_CURRENT_USER_KEY, - MFX_STORAGE_ID_LAST = MFX_PATH_MSDK_FOLDER -#else - MFX_PATH_MSDK_FOLDER = 3, - MFX_STORAGE_ID_FIRST = MFX_PATH_MSDK_FOLDER, + MFX_TRACER = 0, + MFX_DRIVER_STORE = 1, + MFX_CURRENT_USER_KEY = 2, + MFX_LOCAL_MACHINE_KEY = 3, + MFX_APP_FOLDER = 4, + MFX_PATH_MSDK_FOLDER = 5, + MFX_STORAGE_ID_FIRST = MFX_TRACER, MFX_STORAGE_ID_LAST = MFX_PATH_MSDK_FOLDER -#endif // !defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE) -}; #else -enum -{ - MFX_UNKNOWN_KEY = -1, - MFX_STORAGE_ID_OPT = 0, // storage is: MFX_MODULES_DIR - MFX_APP_FOLDER = 1, - - MFX_STORAGE_ID_FIRST = MFX_STORAGE_ID_OPT, - MFX_STORAGE_ID_LAST = MFX_STORAGE_ID_OPT -}; + MFX_UNKNOWN_KEY = -1, + MFX_DRIVER_STORE = 0, + MFX_CURRENT_USER_KEY = 1, + MFX_LOCAL_MACHINE_KEY = 2, + MFX_APP_FOLDER = 3, + MFX_PATH_MSDK_FOLDER = 4, + MFX_STORAGE_ID_FIRST = MFX_DRIVER_STORE, + MFX_STORAGE_ID_LAST = MFX_PATH_MSDK_FOLDER #endif +}; // Try to initialize using given implementation type. Select appropriate type automatically in case of MFX_IMPL_VIA_ANY. // Params: adapterNum - in, pImplInterface - in/out, pVendorID - out, pDeviceID - out @@ -105,14 +78,14 @@ class MFXLibraryIterator mfxStatus Init(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID); // Get the next library path - mfxStatus SelectDLLVersion(msdk_disp_char *pPath, size_t pathSize, + mfxStatus SelectDLLVersion(wchar_t *pPath, size_t pathSize, eMfxImplType *pImplType, mfxVersion minVersion); // Return interface type on which Intel adapter was found (if any): D3D9 or D3D11 mfxIMPL GetImplementationType(); // Retrun registry subkey name on which dll was selected after sucesfull call to selectDllVesion - bool GetSubKeyName(msdk_disp_char *subKeyName, size_t length) const; + bool GetSubKeyName(wchar_t *subKeyName, size_t length) const; int GetStorageID() const { return m_StorageID; } protected: @@ -121,9 +94,13 @@ class MFXLibraryIterator void Release(void); // Initialize the registry iterator - mfxStatus InitRegistry(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID); - // Initialize the app folder iterator - mfxStatus InitFolder(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, const msdk_disp_char * path, const int storageID); + mfxStatus InitRegistry(int storageID); +#if defined(MFX_TRACER_WA_FOR_DS) + // Initialize the registry iterator for searching for tracer + mfxStatus InitRegistryTracer(); +#endif + // Initialize the app/module folder iterator + mfxStatus InitFolder(eMfxImplType implType, const wchar_t * path, const int storageID); eMfxImplType m_implType; // Required library implementation @@ -135,17 +112,16 @@ class MFXLibraryIterator wchar_t m_SubKeyName[MFX_MAX_REGISTRY_KEY_NAME]; // registry subkey for selected module loaded int m_StorageID; -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #if !defined(MEDIASDK_UWP_DISPATCHER) WinRegKey m_baseRegKey; // (WinRegKey) main registry key #endif mfxU32 m_lastLibIndex; // (mfxU32) index of previously returned library mfxU32 m_lastLibMerit; // (mfxU32) merit of previously returned library -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - msdk_disp_char m_path[msdk_disp_path_len]; + wchar_t m_path[msdk_disp_path_len]; + + DriverStoreLoader m_driverStoreLoader; // for loading MediaSDK from DriverStore private: // unimplemented by intent to make this class non-copyable diff --git a/src/mfx_load_dll.cpp b/src/mfx_load_dll.cpp index b3bf3d6..c472675 100644 --- a/src/mfx_load_dll.cpp +++ b/src/mfx_load_dll.cpp @@ -18,8 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include "mfx_dispatcher.h" #include "mfx_load_dll.h" @@ -27,8 +25,7 @@ #include #include - -#if defined(_WIN64) || defined(__CYGWIN64__) +#if defined(_WIN64) const wchar_t * const defaultDLLName[2] = {L"libmfxhw64.dll", L"libmfxsw64.dll"}; @@ -36,7 +33,7 @@ const wchar_t * const defaultAudioDLLName[2] = {L"libmfxaudiosw64.dll", L"libmfxaudiosw64.dll"}; -const +const wchar_t * const defaultPluginDLLName[2] = {L"mfxplugin64_hw.dll", L"mfxplugin64_sw.dll"}; @@ -45,7 +42,7 @@ const wchar_t * const IntelGFXAPIDLLName = {L"intel_gfx_api-x64.dll"}; #endif -#elif defined(_WIN32) || defined(__CYGWIN__) +#elif defined(_WIN32) const wchar_t * const defaultDLLName[2] = {L"libmfxhw32.dll", L"libmfxsw32.dll"}; @@ -54,7 +51,7 @@ const wchar_t * const defaultAudioDLLName[2] = {L"libmfxaudiosw32.dll", L"libmfxaudiosw32.dll"}; -const +const wchar_t * const defaultPluginDLLName[2] = {L"mfxplugin32_hw.dll", L"mfxplugin32_sw.dll"}; @@ -69,26 +66,26 @@ namespace MFX { -mfxStatus mfx_get_default_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType) +mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) { if (!pPath) { return MFX_ERR_NULL_PTR; } - + // there are only 2 implementation with default DLL names #if _MSC_VER >= 1400 return 0 == wcscpy_s(pPath, pathSize, defaultDLLName[implType & 1]) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN; -#else +#else wcscpy(pPath, defaultDLLName[implType & 1]); return MFX_ERR_NONE; #endif -} // mfxStatus mfx_get_default_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType) +} // mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) #if defined(MEDIASDK_UWP_DISPATCHER) -mfxStatus mfx_get_default_intel_gfx_api_dll_name(msdk_disp_char *pPath, size_t pathSize) +mfxStatus mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize) { if (!pPath) { @@ -102,10 +99,10 @@ mfxStatus mfx_get_default_intel_gfx_api_dll_name(msdk_disp_char *pPath, size_t p wcscpy(pPath, IntelGFXAPIDLLName); return MFX_ERR_NONE; #endif -} // mfx_get_default_intel_gfx_api_dll_name(msdk_disp_char *pPath, size_t pathSize) +} // mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize) #endif -mfxStatus mfx_get_default_plugin_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType) +mfxStatus mfx_get_default_plugin_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) { if (!pPath) { @@ -117,30 +114,30 @@ mfxStatus mfx_get_default_plugin_name(msdk_disp_char *pPath, size_t pathSize, eM #if _MSC_VER >= 1400 return 0 == wcscpy_s(pPath, pathSize, defaultPluginDLLName[implType & 1]) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN; -#else +#else wcscpy(pPath, defaultPluginDLLName[implType & 1]); return MFX_ERR_NONE; #endif } -mfxStatus mfx_get_default_audio_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType) +mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) { if (!pPath) { return MFX_ERR_NULL_PTR; } - + // there are only 2 implementation with default DLL names #if _MSC_VER >= 1400 return 0 == wcscpy_s(pPath, pathSize, defaultAudioDLLName[implType & 1]) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN; -#else +#else wcscpy(pPath, defaultAudioDLLName[implType & 1]); return MFX_ERR_NONE; #endif } // mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType) -mfxModuleHandle mfx_dll_load(const msdk_disp_char *pFileName) +mfxModuleHandle mfx_dll_load(const wchar_t *pFileName) { mfxModuleHandle hModule = (mfxModuleHandle) 0; @@ -152,7 +149,7 @@ mfxModuleHandle mfx_dll_load(const msdk_disp_char *pFileName) #if !defined(MEDIASDK_UWP_DISPATCHER) // set the silent error mode DWORD prevErrorMode = 0; -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode); #else prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); @@ -166,7 +163,7 @@ mfxModuleHandle mfx_dll_load(const msdk_disp_char *pFileName) #if !defined(MEDIASDK_UWP_DISPATCHER) // set the previous error mode -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(prevErrorMode, NULL); #else SetErrorMode(prevErrorMode); @@ -200,7 +197,7 @@ bool mfx_dll_free(mfxModuleHandle handle) } // bool mfx_dll_free(mfxModuleHandle handle) #if !defined(MEDIASDK_UWP_DISPATCHER) -mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *pFileName) +mfxModuleHandle mfx_get_dll_handle(const wchar_t *pFileName) { mfxModuleHandle hModule = (mfxModuleHandle) 0; @@ -212,7 +209,7 @@ mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *pFileName) // set the silent error mode DWORD prevErrorMode = 0; -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode); #else prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); @@ -220,7 +217,7 @@ mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *pFileName) // load the library's module GetModuleHandleExW(0, pFileName, (HMODULE*) &hModule); // set the previous error mode -#if (_WIN32_WINNT >= 0x0600) && !(__GNUC__) +#if (_WIN32_WINNT >= 0x0600) SetThreadErrorMode(prevErrorMode, NULL); #else SetErrorMode(prevErrorMode); @@ -229,7 +226,5 @@ mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *pFileName) } #endif //!defined(MEDIASDK_UWP_DISPATCHER) - } // namespace MFX -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) diff --git a/src/mfx_load_dll.h b/src/mfx_load_dll.h index b1e9c39..7348af7 100644 --- a/src/mfx_load_dll.h +++ b/src/mfx_load_dll.h @@ -31,19 +31,19 @@ namespace MFX // declare DLL loading routines // - mfxStatus mfx_get_rt_dll_name(msdk_disp_char *pPath, size_t pathSize); - mfxStatus mfx_get_default_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType); - mfxStatus mfx_get_default_plugin_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType); + mfxStatus mfx_get_rt_dll_name(wchar_t *pPath, size_t pathSize); + mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType); + mfxStatus mfx_get_default_plugin_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType); #if defined(MEDIASDK_UWP_DISPATCHER) - mfxStatus mfx_get_default_intel_gfx_api_dll_name(msdk_disp_char *pPath, size_t pathSize); + mfxStatus mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize); #endif - mfxStatus mfx_get_default_audio_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType); + mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType); - mfxModuleHandle mfx_dll_load(const msdk_disp_char *file_name); + mfxModuleHandle mfx_dll_load(const wchar_t *file_name); //increments reference counter - mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *file_name); + mfxModuleHandle mfx_get_dll_handle(const wchar_t *file_name); mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *func_name); bool mfx_dll_free(mfxModuleHandle handle); diff --git a/src/mfx_load_plugin.cpp b/src/mfx_load_plugin.cpp index 3a6cd0c..8b84f4c 100644 --- a/src/mfx_load_plugin.cpp +++ b/src/mfx_load_plugin.cpp @@ -38,7 +38,7 @@ MFX::PluginModule::PluginModule(const PluginModule & that) : mHmodule(mfx_dll_load(that.mPath)) , mCreatePluginPtr(that.mCreatePluginPtr) { - msdk_disp_char_cpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath); + wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath); } MFX::PluginModule & MFX::PluginModule::operator = (const MFX::PluginModule & that) @@ -48,20 +48,20 @@ MFX::PluginModule & MFX::PluginModule::operator = (const MFX::PluginModule & tha Tidy(); mHmodule = mfx_dll_load(that.mPath); mCreatePluginPtr = that.mCreatePluginPtr; - msdk_disp_char_cpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath); + wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath); } return *this; } -MFX::PluginModule::PluginModule(const msdk_disp_char * path) +MFX::PluginModule::PluginModule(const wchar_t * path) : mCreatePluginPtr() { mHmodule = mfx_dll_load(path); if (NULL == mHmodule) { - TRACE_PLUGIN_ERROR("Cannot load module: %S\n", MSDK2WIDE(path)); + TRACE_PLUGIN_ERROR("Cannot load module: %S\n", path); return ; } - TRACE_PLUGIN_INFO("Plugin loaded at: %S\n", MSDK2WIDE(path)); + TRACE_PLUGIN_INFO("Plugin loaded at: %S\n", path); mCreatePluginPtr = (CreatePluginPtr_t)mfx_dll_get_addr(mHmodule, CREATE_PLUGIN_FNC); if (NULL == mCreatePluginPtr) { @@ -69,7 +69,7 @@ MFX::PluginModule::PluginModule(const msdk_disp_char * path) return ; } - msdk_disp_char_cpy_s(mPath, sizeof(mPath) / sizeof(*mPath), path); + wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), path); } bool MFX::PluginModule::Create( mfxPluginUID uid, mfxPlugin& plg) @@ -80,9 +80,9 @@ bool MFX::PluginModule::Create( mfxPluginUID uid, mfxPlugin& plg) mfxStatus mfxResult = mCreatePluginPtr(uid, &plg); result = (MFX_ERR_NONE == mfxResult); if (!result) { - TRACE_PLUGIN_ERROR("\"%S::%s\" returned %d\n", MSDK2WIDE(mPath), CREATE_PLUGIN_FNC, mfxResult); + TRACE_PLUGIN_ERROR("\"%S::%s\" returned %d\n", mPath, CREATE_PLUGIN_FNC, mfxResult); } else { - TRACE_PLUGIN_INFO("\"%S::%s\" SUCCEED\n", MSDK2WIDE(mPath), CREATE_PLUGIN_FNC); + TRACE_PLUGIN_INFO("\"%S::%s\" SUCCEED\n", mPath, CREATE_PLUGIN_FNC); } } return result; diff --git a/src/mfx_load_plugin.h b/src/mfx_load_plugin.h index 43e1ea4..ef249a4 100644 --- a/src/mfx_load_plugin.h +++ b/src/mfx_load_plugin.h @@ -31,11 +31,11 @@ namespace MFX { mfxModuleHandle mHmodule; CreatePluginPtr_t mCreatePluginPtr; - msdk_disp_char mPath[MAX_PLUGIN_PATH]; - + wchar_t mPath[MAX_PLUGIN_PATH]; + public: PluginModule(); - PluginModule(const msdk_disp_char * path); + PluginModule(const wchar_t * path); PluginModule(const PluginModule & that) ; PluginModule & operator = (const PluginModule & that); bool Create(mfxPluginUID guid, mfxPlugin&); @@ -55,8 +55,8 @@ namespace MFX {} FactoryRecord(const mfxPluginParam &plgParams, PluginModule &module, - mfxPlugin plugin) - : plgParams(plgParams) + mfxPlugin plugin) + : plgParams(plgParams) , module(module) , plugin(plugin) { } @@ -69,7 +69,7 @@ namespace MFX void Close(); mfxStatus Create(const PluginDescriptionRecord &); bool Destroy(const mfxPluginUID &); - + ~MFXPluginFactory(); protected: void DestroyPlugin( FactoryRecord & ); diff --git a/src/mfx_plugin_hive.cpp b/src/mfx_plugin_hive.cpp index 4067e9f..e7b47d4 100644 --- a/src/mfx_plugin_hive.cpp +++ b/src/mfx_plugin_hive.cpp @@ -18,19 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include "mfx_plugin_hive.h" #include "mfx_library_iterator.h" #include "mfx_dispatcher.h" #include "mfx_dispatcher_log.h" #include "mfx_load_dll.h" -#if defined(__CYGWIN__) -#include -#include -#endif - #define TRACE_HIVE_ERROR(str, ...) DISPATCHER_LOG_ERROR((("[HIVE]: " str), __VA_ARGS__)) #define TRACE_HIVE_INFO(str, ...) DISPATCHER_LOG_INFO((("[HIVE]: " str), __VA_ARGS__)) #define TRACE_HIVE_WRN(str, ...) DISPATCHER_LOG_WRN((("[HIVE]: " str), __VA_ARGS__)) @@ -51,7 +44,7 @@ namespace namespace { -#if defined(_WIN64) || defined(__CYGWIN64__) +#ifdef _WIN64 const wchar_t pluginFileName[] = L"FileName64"; #else const wchar_t pluginFileName[] = L"FileName32"; @@ -79,7 +72,6 @@ namespace MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLibSubKey, mfxVersion currentAPIVersion) : MFXPluginStorageBase(currentAPIVersion) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) HKEY rootHKey; bool bRes; WinRegKey regKey; @@ -161,7 +153,7 @@ MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLib if (QueryKey(subKey, CodecIDKeyName, descriptionRecord.CodecId)) { - TRACE_HIVE_INFO(alignStr()" : " MFXFOURCCTYPE() " \n", CodecIDKeyName, MFXU32TOFOURCC(descriptionRecord.CodecId)); + TRACE_HIVE_INFO(alignStr()" : " MFXFOURCCTYPE()" \n", CodecIDKeyName, MFXU32TOFOURCC(descriptionRecord.CodecId)); } else { @@ -172,7 +164,7 @@ MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLib { continue; } - TRACE_HIVE_INFO(alignStr()" : " MFXGUIDTYPE() "\n", GUIDKeyName, MFXGUIDTOHEX(&descriptionRecord.PluginUID)); + TRACE_HIVE_INFO(alignStr()" : " MFXGUIDTYPE()"\n", GUIDKeyName, MFXGUIDTOHEX(&descriptionRecord.PluginUID)); mfxU32 nSize = sizeof(descriptionRecord.sPath)/sizeof(*descriptionRecord.sPath); if (!subKey.Query(PathKeyName, descriptionRecord.sPath, nSize)) @@ -220,23 +212,15 @@ MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLib TRACE_HIVE_ERROR("operator[](%d) = descriptionRecord; - threw exception \n", index); } } -#else - - (void)mfxStorageID; - (void)msdkLibSubKey; - (void)currentAPIVersion; - -#endif //#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) } -#if defined(MEDIASDK_USE_CFGFILES) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion ) : MFXPluginStorageBase(currentAPIVersion) , mIsVersionParsed() , mIsAPIVersionParsed() { WIN32_FIND_DATAW find_data; - msdk_disp_char currentModuleName[MAX_PLUGIN_PATH]; + wchar_t currentModuleName[MAX_PLUGIN_PATH]; GetModuleFileNameW(NULL, currentModuleName, MAX_PLUGIN_PATH); if (GetLastError() != 0) @@ -244,7 +228,7 @@ MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion ) TRACE_HIVE_ERROR("GetModuleFileName() reported an error: %d\n", GetLastError()); return; } - msdk_disp_char *lastSlashPos = wcsrchr(currentModuleName, L'\\'); + wchar_t *lastSlashPos = wcsrchr(currentModuleName, L'\\'); if (!lastSlashPos) { lastSlashPos = currentModuleName; } @@ -254,7 +238,7 @@ MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion ) TRACE_HIVE_ERROR("MAX_PLUGIN_PATH which is %d, not enough to locate plugin path\n", MAX_PLUGIN_PATH); return; } - msdk_disp_char_cpy_s(lastSlashPos + slashLen + wcscpy_s(lastSlashPos + slashLen , MAX_PLUGIN_PATH - executableDirLen, pluginSearchPattern); HANDLE fileFirst = FindFirstFileW(currentModuleName, &find_data); @@ -300,26 +284,21 @@ MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion ) continue; } - msdk_disp_char_cpy_s(currentModuleName + executableDirLen + wcscpy_s(currentModuleName + executableDirLen , MAX_PLUGIN_PATH - executableDirLen, find_data.cFileName); - msdk_disp_char_cpy_s(currentModuleName + executableDirLen + pluginDirNameLen + wcscpy_s(currentModuleName + executableDirLen + pluginDirNameLen , MAX_PLUGIN_PATH - executableDirLen - pluginDirNameLen, L"\\"); //this is path to plugin directory - msdk_disp_char_cpy_s(descriptionRecord.sPath + wcscpy_s(descriptionRecord.sPath , sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath), currentModuleName); - msdk_disp_char_cpy_s(currentModuleName + executableDirLen + pluginDirNameLen + slashLen + wcscpy_s(currentModuleName + executableDirLen + pluginDirNameLen + slashLen , MAX_PLUGIN_PATH - executableDirLen - pluginDirNameLen - slashLen, pluginCfgFileName); FILE *pluginCfgFile = 0; -#ifdef __CYGWIN__ - std::string cmn_str = std::wstring_convert>().to_bytes(std::wstring(currentModuleName)); - pluginCfgFile = fopen(cmn_str.c_str(), "r"); -#else _wfopen_s(&pluginCfgFile, currentModuleName, L"r"); -#endif if (!pluginCfgFile) { TRACE_HIVE_INFO("in directory \"%S\" no mandatory \"%S\"\n" @@ -343,13 +322,13 @@ MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion ) FindClose(fileFirst); } -bool MFX::MFXPluginsInFS::ParseFile(FILE * f, PluginDescriptionRecord & descriptionRecord) +bool MFX::MFXPluginsInFS::ParseFile(FILE * f, PluginDescriptionRecord & descriptionRecord) { - msdk_disp_char line[MAX_PLUGIN_FILE_LINE]; + wchar_t line[MAX_PLUGIN_FILE_LINE]; while(NULL != fgetws(line, sizeof(line) / sizeof(*line), f)) { - msdk_disp_char *delimiter = wcschr(line, L'='); + wchar_t *delimiter = wcschr(line, L'='); if (0 == delimiter) { TRACE_HIVE_INFO("plugin.cfg contains line \"%S\" which is not in K=V format, skipping \n", line); @@ -383,7 +362,7 @@ bool MFX::MFXPluginsInFS::ParseFile(FILE * f, PluginDescriptionRecord & descript return true; } -bool MFX::MFXPluginsInFS::ParseKVPair( msdk_disp_char * key, msdk_disp_char* value, PluginDescriptionRecord & descriptionRecord) +bool MFX::MFXPluginsInFS::ParseKVPair( wchar_t * key, wchar_t* value, PluginDescriptionRecord & descriptionRecord) { if (0 != wcsstr(key, PlgVerKeyName)) { @@ -423,13 +402,13 @@ bool MFX::MFXPluginsInFS::ParseKVPair( msdk_disp_char * key, msdk_disp_char* val if (0!=wcsstr(key, pluginFileName)) { - msdk_disp_char *startQuoteMark = wcschr(value, L'\"'); + wchar_t *startQuoteMark = wcschr(value, L'\"'); if (!startQuoteMark) { TRACE_HIVE_ERROR("plugin filename not in quotes : %S\n", value); return false; } - msdk_disp_char *endQuoteMark = wcschr(startQuoteMark + 1, L'\"'); + wchar_t *endQuoteMark = wcschr(startQuoteMark + 1, L'\"'); if (!endQuoteMark) { @@ -453,7 +432,7 @@ bool MFX::MFXPluginsInFS::ParseKVPair( msdk_disp_char * key, msdk_disp_char* val return false; } - msdk_disp_char_cpy_s(descriptionRecord.sPath + currentPathLen + wcscpy_s(descriptionRecord.sPath + currentPathLen , sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath) - currentPathLen, startQuoteMark + 1); TRACE_HIVE_INFO("%S: %S = \"%S\" \n", pluginCfgFileName, pluginFileName, startQuoteMark + 1); @@ -464,14 +443,13 @@ bool MFX::MFXPluginsInFS::ParseKVPair( msdk_disp_char * key, msdk_disp_char* val return true; } -#endif //#if defined(MEDIASDK_USE_CFGFILES) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) #endif //#if !defined(MEDIASDK_UWP_DISPATCHER) MFX::MFXDefaultPlugins::MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP_HANDLE * hdl, int implType) : MFXPluginStorageBase(currentAPIVersion) { - msdk_disp_char libModuleName[MAX_PLUGIN_PATH]; + wchar_t libModuleName[MAX_PLUGIN_PATH]; GetModuleFileNameW((HMODULE)hdl->hModule, libModuleName, MAX_PLUGIN_PATH); if (GetLastError() != 0) @@ -479,7 +457,7 @@ MFX::MFXDefaultPlugins::MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP TRACE_HIVE_ERROR("GetModuleFileName() reported an error: %d\n", GetLastError()); return; } - msdk_disp_char *lastSlashPos = wcsrchr(libModuleName, L'\\'); + wchar_t *lastSlashPos = wcsrchr(libModuleName, L'\\'); if (!lastSlashPos) { lastSlashPos = libModuleName; } @@ -499,7 +477,7 @@ MFX::MFXDefaultPlugins::MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP descriptionRecord.APIVersion = currentAPIVersion; descriptionRecord.Default = true; - msdk_disp_char_cpy_s(descriptionRecord.sPath + wcscpy_s(descriptionRecord.sPath , sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath), libModuleName); push_back(descriptionRecord); @@ -511,4 +489,3 @@ MFX::MFXDefaultPlugins::MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP } -#endif diff --git a/src/mfx_plugin_hive.h b/src/mfx_plugin_hive.h index 8be85ab..aa41f4e 100644 --- a/src/mfx_plugin_hive.h +++ b/src/mfx_plugin_hive.h @@ -32,23 +32,23 @@ struct MFX_DISP_HANDLE; namespace MFX { - inline bool operator == (const mfxPluginUID &lhs, const mfxPluginUID & rhs) + inline bool operator == (const mfxPluginUID &lhs, const mfxPluginUID & rhs) { return !memcmp(lhs.Data, rhs.Data, sizeof(mfxPluginUID)); } - - inline bool operator != (const mfxPluginUID &lhs, const mfxPluginUID & rhs) + + inline bool operator != (const mfxPluginUID &lhs, const mfxPluginUID & rhs) { return !(lhs == rhs); } -#if defined(_WIN32) || defined(__CYGWIN__) +#ifdef _WIN32 //warning C4351: new behavior: elements of array 'MFX::PluginDescriptionRecord::sName' will be default initialized #pragma warning (disable: 4351) #endif - class PluginDescriptionRecord : public mfxPluginParam + class PluginDescriptionRecord : public mfxPluginParam { public: - msdk_disp_char sPath[MAX_PLUGIN_PATH]; + wchar_t sPath[MAX_PLUGIN_PATH]; char sName[MAX_PLUGIN_NAME]; //used for FS plugins that has poor description bool onlyVersionRegistered; @@ -65,12 +65,12 @@ namespace MFX { typedef MFXVector MFXPluginStorage; - class MFXPluginStorageBase : public MFXPluginStorage + class MFXPluginStorageBase : public MFXPluginStorage { protected: mfxVersion mCurrentAPIVersion; protected: - MFXPluginStorageBase(mfxVersion currentAPIVersion) + MFXPluginStorageBase(mfxVersion currentAPIVersion) : mCurrentAPIVersion(currentAPIVersion) { } @@ -87,10 +87,9 @@ namespace MFX { class MFXPluginsInHive : public MFXPluginStorageBase { public: - MFXPluginsInHive(int mfxStorageID, const msdk_disp_char *msdkLibSubKey, mfxVersion currentAPIVersion); + MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLibSubKey, mfxVersion currentAPIVersion); }; -#if defined(MEDIASDK_USE_CFGFILES) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) //plugins are loaded from FS close to executable class MFXPluginsInFS : public MFXPluginStorageBase { @@ -100,9 +99,8 @@ namespace MFX { MFXPluginsInFS(mfxVersion currentAPIVersion); private: bool ParseFile(FILE * f, PluginDescriptionRecord & des); - bool ParseKVPair( msdk_disp_char *key, msdk_disp_char * value, PluginDescriptionRecord & des); + bool ParseKVPair( wchar_t *key, wchar_t * value, PluginDescriptionRecord & des); }; -#endif //#if defined(MEDIASDK_USE_CFGFILES) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) #endif //#if !defined(MEDIASDK_UWP_DISPATCHER) diff --git a/src/mfx_vector.h b/src/mfx_vector.h index 0cf8364..c7c2c49 100644 --- a/src/mfx_vector.h +++ b/src/mfx_vector.h @@ -168,7 +168,6 @@ namespace MFX mRecords = newRecords; mNrecords = i + 1; - } void erase (iterator at) { diff --git a/src/mfx_win_reg_key.cpp b/src/mfx_win_reg_key.cpp index d3f8b0b..b9df889 100644 --- a/src/mfx_win_reg_key.cpp +++ b/src/mfx_win_reg_key.cpp @@ -17,7 +17,6 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if !defined(MEDIASDK_UWP_DISPATCHER) #include "mfx_win_reg_key.h" @@ -45,9 +44,7 @@ void WinRegKey::Release(void) // close the opened key if (m_hKey) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) RegCloseKey(m_hKey); -#endif } m_hKey = (HKEY) 0; @@ -56,7 +53,6 @@ void WinRegKey::Release(void) bool WinRegKey::Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) LONG lRes; HKEY hTemp; @@ -84,9 +80,6 @@ bool WinRegKey::Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired) m_hKey = hTemp; return true; -#else - return false; -#endif } // bool WinRegKey::Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired) @@ -97,7 +90,6 @@ bool WinRegKey::Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesir } // bool WinRegKey::Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired) bool WinRegKey::QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) DWORD keyType = type; LONG lRes; @@ -111,14 +103,10 @@ bool WinRegKey::QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pc } return true; -#else - return false; -#endif } bool WinRegKey::Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) DWORD keyType = type; LONG lRes; DWORD dstSize = (pcbData) ? (*pcbData) : (0); @@ -175,15 +163,11 @@ bool WinRegKey::Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWO } return true; -#else - return false; -#endif } // bool WinRegKey::Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData) bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) LONG lRes; // enum the values @@ -195,15 +179,11 @@ bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueNam } return true; -#else - return false; -#endif } // bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType) bool WinRegKey::EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) LONG lRes; // enum the keys @@ -216,15 +196,11 @@ bool WinRegKey::EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName) } return true; -#else - return false; -#endif } // bool WinRegKey::EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName) bool WinRegKey::QueryInfo(LPDWORD lpcSubkeys) { -#if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) LONG lRes; lRes = RegQueryInfoKeyW(m_hKey, NULL, 0, 0, lpcSubkeys, 0, 0, 0, 0, 0, 0, 0); @@ -233,13 +209,9 @@ bool WinRegKey::QueryInfo(LPDWORD lpcSubkeys) return false; } return true; -#else - return false; -#endif } //bool QueryInfo(LPDWORD lpcSubkeys); } // namespace MFX -#endif // #if !defined(MEDIASDK_UWP_DISPATCHER) -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) \ No newline at end of file +#endif // #if !defined(MEDIASDK_UWP_DISPATCHER) \ No newline at end of file diff --git a/src/mfx_win_reg_key.h b/src/mfx_win_reg_key.h index f2ea94e..6c9ca4a 100644 --- a/src/mfx_win_reg_key.h +++ b/src/mfx_win_reg_key.h @@ -21,8 +21,6 @@ #if !defined(__MFX_WIN_REG_KEY_H) #define __MFX_WIN_REG_KEY_H -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #include #include "mfx/mfxplugin.h" #include "mfx_dispatcher_log.h" @@ -103,6 +101,4 @@ inline bool QueryKey(WinRegKey & key, const wchar_t *pValueName, bool &dat } // namespace MFX #endif // #if !defined(MEDIASDK_UWP_DISPATCHER) -#endif // #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - #endif // __MFX_WIN_REG_KEY_H