This commit is contained in:
mofeng-git
2025-12-28 18:19:16 +08:00
commit d143d158e4
771 changed files with 220548 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2012-2019 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_CRITICAL_SECTION_H)
#define __MFX_CRITICAL_SECTION_H
#include <mfxdefs.h>
namespace MFX
{
// Just set "critical section" instance to zero for initialization.
typedef volatile mfxL32 mfxCriticalSection;
// Enter the global critical section.
void mfxEnterCriticalSection(mfxCriticalSection *pCSection);
// Leave the global critical section.
void mfxLeaveCriticalSection(mfxCriticalSection *pCSection);
class MFXAutomaticCriticalSection
{
public:
// Constructor
explicit MFXAutomaticCriticalSection(mfxCriticalSection *pCSection)
{
m_pCSection = pCSection;
mfxEnterCriticalSection(m_pCSection);
}
// Destructor
~MFXAutomaticCriticalSection()
{
mfxLeaveCriticalSection(m_pCSection);
}
protected:
// Pointer to a critical section
mfxCriticalSection *m_pCSection;
private:
// unimplemented by intent to make this class non-copyable
MFXAutomaticCriticalSection(const MFXAutomaticCriticalSection &);
void operator=(const MFXAutomaticCriticalSection &);
};
} // namespace MFX
#endif // __MFX_CRITICAL_SECTION_H

View File

@@ -0,0 +1,232 @@
// 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
// 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_DISPATCHER_H)
#define __MFX_DISPATCHER_H
#include <mfxvideo.h>
#include <mfxaudio.h>
#include <mfxplugin.h>
#include <stddef.h>
#include "mfx_dispatcher_defs.h"
#include "mfx_load_plugin.h"
#include "mfxenc.h"
#include "mfxpak.h"
#define INTEL_VENDOR_ID 0x8086
mfxStatus MFXQueryVersion(mfxSession session, mfxVersion *version);
enum
{
// to avoid code changing versions are just inherited
// from the API header file.
DEFAULT_API_VERSION_MAJOR = MFX_VERSION_MAJOR,
DEFAULT_API_VERSION_MINOR = MFX_VERSION_MINOR
};
//
// declare functions' integer identifiers.
//
#undef FUNCTION
#define FUNCTION(return_value, func_name, formal_param_list, actual_param_list) \
e##func_name,
enum eFunc
{
eMFXInit,
eMFXClose,
eMFXQueryIMPL,
eMFXQueryVersion,
eMFXJoinSession,
eMFXDisjoinSession,
eMFXCloneSession,
eMFXSetPriority,
eMFXGetPriority,
eMFXInitEx,
#include "mfx_exposed_functions_list.h"
eVideoFuncTotal
};
enum ePluginFunc
{
eMFXVideoUSER_Load,
eMFXVideoUSER_LoadByPath,
eMFXVideoUSER_UnLoad,
eMFXAudioUSER_Load,
eMFXAudioUSER_UnLoad,
ePluginFuncTotal
};
enum eAudioFunc
{
eFakeAudioEnum = eMFXGetPriority,
#include "mfxaudio_exposed_functions_list.h"
eAudioFuncTotal
};
// declare max buffer length for regsitry key name
enum
{
MFX_MAX_REGISTRY_KEY_NAME = 256
};
// declare the maximum DLL path
enum
{
MFX_MAX_DLL_PATH = 1024
};
// declare library's implementation types
enum eMfxImplType
{
MFX_LIB_HARDWARE = 0,
MFX_LIB_SOFTWARE = 1,
MFX_LIB_PSEUDO = 2,
MFX_LIB_IMPL_TYPES
};
// declare dispatcher's version
enum
{
MFX_DISPATCHER_VERSION_MAJOR = 1,
MFX_DISPATCHER_VERSION_MINOR = 3
};
struct _mfxSession
{
// A real handle from MFX engine passed to a called function
mfxSession session;
mfxFunctionPointer callTable[eVideoFuncTotal];
mfxFunctionPointer callPlugInsTable[ePluginFuncTotal];
mfxFunctionPointer callAudioTable[eAudioFuncTotal];
// Current library's implementation (exact implementation)
mfxIMPL impl;
};
// declare a dispatcher's handle
struct MFX_DISP_HANDLE : public _mfxSession
{
// Default constructor
MFX_DISP_HANDLE(const mfxVersion requiredVersion);
// Destructor
~MFX_DISP_HANDLE(void);
// Load the library's module
mfxStatus LoadSelectedDLL(const wchar_t *pPath, eMfxImplType implType, mfxIMPL impl, mfxIMPL implInterface, mfxInitParam &par);
// Unload the library's module
mfxStatus UnLoadSelectedDLL(void);
// Close the handle
mfxStatus Close(void);
// NOTE: changing order of struct's members can make different version of
// dispatchers incompatible. Think of different modules (e.g. MFT filters)
// within a single application.
// Library's implementation type (hardware or software)
eMfxImplType implType;
// Current library's VIA interface
mfxIMPL implInterface;
// Dispatcher's version. If version is 1.1 or lower, then old dispatcher's
// architecture is used. Otherwise it means current dispatcher's version.
mfxVersion dispVersion;
// Required API version of session initialized
const mfxVersion apiVersion;
// Actual library API version
mfxVersion actualApiVersion;
// Status of loaded dll
mfxStatus loadStatus;
// Resgistry subkey name for windows version
wchar_t subkeyName[MFX_MAX_REGISTRY_KEY_NAME];
// Storage ID for windows version
int storageID;
// Library's module handle
mfxModuleHandle hModule;
MFX::MFXPluginStorage pluginHive;
MFX::MFXPluginFactory pluginFactory;
private:
// Declare assignment operator and copy constructor to prevent occasional assignment
MFX_DISP_HANDLE(const MFX_DISP_HANDLE &);
MFX_DISP_HANDLE & operator = (const MFX_DISP_HANDLE &);
};
// 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);
}
inline
bool operator < (const mfxVersion &one, const mfxVersion &two)
{
return (one.Major < two.Major) || ((one.Major == two.Major) && (one.Minor < two.Minor));
}
inline
bool operator <= (const mfxVersion &one, const mfxVersion &two)
{
return (one == two) || (one < two);
}
//
// declare a table with functions descriptions
//
typedef
struct FUNCTION_DESCRIPTION
{
// Literal function's name
const char *pName;
// API version when function appeared first time
mfxVersion apiVersion;
} FUNCTION_DESCRIPTION;
extern const
FUNCTION_DESCRIPTION APIFunc[eVideoFuncTotal];
extern const
FUNCTION_DESCRIPTION APIAudioFunc[eAudioFuncTotal];
#endif // __MFX_DISPATCHER_H

View File

@@ -0,0 +1,47 @@
// 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
// 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.
#pragma once
#include "mfxdefs.h"
#include <cstring>
#include <cstdio>
#if defined(MFX_DISPATCHER_LOG)
#include <string>
#include <string.h>
#endif
#define MAX_PLUGIN_PATH MAX_PATH
#define MAX_PLUGIN_NAME MAX_PATH
#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
// 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

View File

@@ -0,0 +1,286 @@
// 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
// 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_DISPATCHER_LOG_H)
#define __MFX_DISPATCHER_LOG_H
//////////////////////////////////////////////////////////////////////////
//dispatcher log (DL) level
#define DL_INFO 1
#define DL_WRN 2
#define DL_ERROR 4
#define DL_LOADED_LIBRARY 8
//////////////////////////////////////////////////////////////////////////
//opcodes used only in events
enum
{
DL_EVENT_START = 1,
DL_EVENT_STOP,
DL_EVENT_MSG
};
//////////////////////////////////////////////////////////////////////////
#define DL_SINK_NULL 0
#define DL_SINK_PRINTF 1
#define DL_SINK_IMsgHandler 2
#define MFXFOURCCTYPE() "%c%c%c%c"
#define ZERO_OR_SPACE(value) ((0==(value)) ? '0' : (value))
#define MFXU32TOFOURCC(mfxu32)\
ZERO_OR_SPACE((char)(mfxu32 & 0xFF)), \
ZERO_OR_SPACE((char)((mfxu32 >> 8) & 0xFF)),\
ZERO_OR_SPACE((char)((mfxu32 >> 16) & 0xFF)),\
ZERO_OR_SPACE((char)((mfxu32 >> 24) & 0xFF))
#define MFXGUIDTYPE() "%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X"
#define MFXGUIDTOHEX(guid)\
(guid)->Data[0],\
(guid)->Data[1],\
(guid)->Data[2],\
(guid)->Data[3],\
(guid)->Data[4],\
(guid)->Data[5],\
(guid)->Data[6],\
(guid)->Data[7],\
(guid)->Data[8],\
(guid)->Data[9],\
(guid)->Data[10],\
(guid)->Data[11],\
(guid)->Data[12],\
(guid)->Data[13],\
(guid)->Data[14],\
(guid)->Data[15]
#if defined(MFX_DISPATCHER_LOG)
//---------------------------setup section------------------------
//using of formating instead of variadic macro with NULL end,
//leads to more flexibility in format, however constructing string
//with vsprintf_s is a time wasting
#define DISPATCHER_LOG_USE_FORMATING 1
//creates unique object, event guid registration, factories on heap
//heap reduce stack allocation and reduce reservation time at startup
//is a vital if mediasdk wont use
#define DISPATCHER_LOG_HEAP_SINGLETONES
// guid for all dispatcher events
#define DISPATCHER_LOG_EVENT_GUID L"{EB0538CC-4FEE-484d-ACEE-1182E9F37A57}"
//puts a sink into listeners list
//#define DISPATCHER_LOG_REGISTER_EVENT_PROVIDER
//puts a sink into listeners list
//#define DISPATCHER_LOG_REGISTER_FILE_WRITER
#define DISPACTHER_LOG_FW_PATH "c:\\dispatcher.log"
#include <stdio.h>
#include <stdarg.h>
//callback interface for intercept logging messages
class IMsgHandler
{
public:
virtual ~IMsgHandler(){}
virtual void Write(int level, int opcode, const char * msg, va_list argptr) = 0;
};
#if DISPATCHER_LOG_USE_FORMATING
#define DISPATCHER_LOG(lvl, opcode, str)\
{\
DispatcherLogBracketsHelper wrt(lvl,opcode);\
wrt.Write str;\
}
#else
#define DISPATCHER_LOG_VA_ARGS(...) wrt.Write(__VA_ARGS__, NULL)
//WARNING: don't use types that occupy more that 4 bytes in memory
//WARNING: don't use %s in format specifier
#define DISPATCHER_LOG(lvl, opcode, str) \
{\
DispatcherLogBracketsHelper wrt(lvl, opcode);\
DISPATCHER_LOG_VA_ARGS str;\
}
#endif//DISPATCHER_LOG_USE_FORMATING
#define DISPATCHER_LOG_OPERATION(operation) operation
#define __name_from_line( name, line ) name ## line
#define _name_from_line( name , line) __name_from_line( name, line )
#define name_from_line( name ) _name_from_line( name, __LINE__)
#define DISPATCHER_LOG_AUTO(lvl, msg)\
DispatchLogBlockHelper name_from_line(__auto_log_)(lvl); name_from_line(__auto_log_).Write msg;
#include <memory>
#include <map>
#include <list>
#include <string>
template <class T>
class DSSingleTone
{
public:
template <class TParam1>
inline static T & get(TParam1 par1)
{
T * pstored;
if (NULL == (pstored = store_or_load()))
{
return *store_or_load(new T(par1));
}
return *pstored;
}
inline static T & get()
{
T * pstored;
if (NULL == (pstored = store_or_load()))
{
return *store_or_load(new T());
}
return *pstored;
}
private:
//if obj == NULL, then it load
//if obj != NULL then it store obj
inline static T * store_or_load(T * obj = NULL)
{
static std::unique_ptr<T> instance;
if (NULL != obj)
{
instance.reset(obj);
}
return instance.get();
}
};
class DispatchLog
: public DSSingleTone<DispatchLog>
{
friend class DSSingleTone<DispatchLog>;
std::list<IMsgHandler*>m_Recepients;
int m_DispatcherLogSink;
public:
//sets current sink
void SetSink(int nsink, IMsgHandler *pHandler);
void AttachSink(int nsink, IMsgHandler *pHandler);
void DetachSink(int nsink, IMsgHandler *pHandler);
void ExchangeSink(int nsink, IMsgHandler *pOld, IMsgHandler *pNew);
void DetachAllSinks();
void Write(int level, int opcode, const char * msg, va_list argptr);
protected:
DispatchLog();
};
//allows to push arguments on the stack without declaring them as function parameters
struct DispatcherLogBracketsHelper
{
int m_level;
int m_opcode;
DispatcherLogBracketsHelper(int level, int opcode)
:m_level(level)
,m_opcode(opcode)
{
}
void Write(const char * str, ...);
} ;
//auto log on ctor dtor
struct DispatchLogBlockHelper
{
int m_level;
void Write(const char * str, ...);
DispatchLogBlockHelper (int level)
: m_level(level)
{
}
~DispatchLogBlockHelper();
};
//----utility sinks-----
#if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER)
class ETWHandlerFactory
: public DSSingleTone<ETWHandlerFactory>
{
friend class DSSingleTone<ETWHandlerFactory>;
typedef std::map<std::wstring, IMsgHandler*> _storage_type;
_storage_type m_storage;
public:
~ETWHandlerFactory();
IMsgHandler *GetSink(const wchar_t* sguid = DISPATCHER_LOG_EVENT_GUID);
protected:
ETWHandlerFactory(){}
};
#endif
#if defined(DISPATCHER_LOG_REGISTER_FILE_WRITER)
class FileSink
: public DSSingleTone<FileSink>
, public IMsgHandler
{
friend class DSSingleTone<FileSink>;
public:
virtual void Write(int level, int opcode, const char * msg, va_list argptr);
FileSink()
: m_hdl(NULL)
{
}
~FileSink()
{
if (NULL != m_hdl)
fclose(m_hdl);
}
private:
FILE * m_hdl;
FileSink(const std::string & log_file)
{
fopen_s(&m_hdl, log_file.c_str(), "a");
}
};
#endif
//-----utility functions
//since they are not called outside of macro we can define them here
std::string DispatcherLog_GetMFXImplString(int impl);
const char *DispatcherLog_GetMFXStatusString(int sts);
#else // !defined(MFX_DISPATCHER_LOG)
#define DISPATCHER_LOG(level, opcode, message)
#define DISPATCHER_LOG_AUTO(level, message)
#define DISPATCHER_LOG_OPERATION(operation)
#endif// !defined(MFX_DISPATCHER_LOG)
#define DISPATCHER_LOG_INFO(msg) DISPATCHER_LOG(DL_INFO, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_WRN(msg) DISPATCHER_LOG(DL_WRN, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_ERROR(msg) DISPATCHER_LOG(DL_ERROR, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_LIBRARY(msg) DISPATCHER_LOG(DL_LOADED_LIBRARY, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_BLOCK(msg) DISPATCHER_LOG_AUTO(DL_INFO, msg)
#endif // !defined(__MFX_DISPATCHER_LOG_H)

View File

@@ -0,0 +1,36 @@
// Copyright (c) 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_DISPATCHER_UWP_H)
#define __MFX_DISPATCHER_UWP_H
// Loads intel_gfx_api dll from DriverStore fro specified device and calls InitialiseMediaSession from it
mfxStatus GfxApiInit(mfxInitParam par, mfxU32 deviceID, mfxSession *session, mfxModuleHandle& hModule);
// Calls DisposeMediaSession from the intel_gfx_api dll and unloads it
mfxStatus GfxApiClose(mfxSession& session, mfxModuleHandle& hModule);
// Initializes intel_gfx_api for specified adapter number
mfxStatus GfxApiInitByAdapterNum(mfxInitParam par, mfxU32 adapterNum, mfxSession *session, mfxModuleHandle& hModule);
// Initializes intel_gfx_api for any Intel adapter, chooses integrated adapter with higher priority
mfxStatus GfxApiInitPriorityIntegrated(mfxInitParam par, mfxSession *session, mfxModuleHandle& hModule);
#endif // __MFX_DISPATCHER_UWP_H

View File

@@ -0,0 +1,65 @@
// 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 <windows.h>
#include <cfgmgr32.h>
#include <devguid.h>
#include "mfx_dispatcher_defs.h"
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

View File

@@ -0,0 +1,213 @@
// Copyright (c) 2012-2019 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_DXVA2_DEVICE_H)
#define __MFX_DXVA2_DEVICE_H
#include <windows.h>
#define TOSTRING(L) #L
#define STRINGIFY(L) TOSTRING(L)
#if defined(MEDIASDK_UWP_DISPATCHER)
#if defined(MFX_D3D9_ENABLED) && !defined(MFX_FORCE_D3D9_ENABLED)
#undef MFX_D3D9_ENABLED
#pragma message("\n\nATTENTION:\nin file\n\t" __FILE__ " (" STRINGIFY(__LINE__) "):\nUsing of D3D9 disabled for UWP!\n\n")
#endif
#if defined(MFX_FORCE_D3D9_ENABLED)
#define MFX_D3D9_ENABLED
#endif
#else
#define MFX_D3D9_ENABLED
#pragma message("\n\nATTENTION:\nin file\n\t" __FILE__ " (" STRINGIFY(__LINE__) "):\nUsing of D3D9 enabled!\n\n")
#endif
#include <mfxdefs.h>
#ifdef DXVA2DEVICE_LOG
#include <stdio.h>
#define DXVA2DEVICE_TRACE(expr) printf expr;
#define DXVA2DEVICE_TRACE_OPERATION(expr) expr;
#else
#define DXVA2DEVICE_TRACE(expr)
#define DXVA2DEVICE_TRACE_OPERATION(expr)
#endif
namespace MFX
{
class DXDevice
{
public:
// Default constructor
DXDevice(void);
// Destructor
virtual
~DXDevice(void) = 0;
// Initialize device using DXGI 1.1 or VAAPI interface
virtual
bool Init(const mfxU32 adapterNum) = 0;
// Obtain graphic card's parameter
mfxU32 GetVendorID(void) const;
mfxU32 GetDeviceID(void) const;
mfxU64 GetDriverVersion(void) const;
mfxU64 GetLUID(void) const;
// Provide the number of available adapters
mfxU32 GetAdapterCount(void) const;
// Close the object
virtual
void Close(void);
// Load the required DLL module
void LoadDLLModule(const wchar_t *pModuleName);
protected:
// Free DLL module
void UnloadDLLModule(void);
// Handle to the DLL library
HMODULE m_hModule;
// Number of adapters available
mfxU32 m_numAdapters;
// Vendor ID
mfxU32 m_vendorID;
// Device ID
mfxU32 m_deviceID;
// x.x.x.x each x of two bytes
mfxU64 m_driverVersion;
// LUID
mfxU64 m_luid;
private:
// unimplemented by intent to make this class and its descendants non-copyable
DXDevice(const DXDevice &);
void operator=(const DXDevice &);
};
#ifdef MFX_D3D9_ENABLED
class D3D9Device : public DXDevice
{
public:
// Default constructor
D3D9Device(void);
// Destructor
virtual
~D3D9Device(void);
// Initialize device using D3D v9 interface
virtual
bool Init(const mfxU32 adapterNum);
// Close the object
virtual
void Close(void);
protected:
// Pointer to the D3D v9 interface
void *m_pD3D9;
// Pointer to the D3D v9 extended interface
void *m_pD3D9Ex;
};
#endif // MFX_D3D9_ENABLED
class DXGI1Device : public DXDevice
{
public:
// Default constructor
DXGI1Device(void);
// Destructor
virtual
~DXGI1Device(void);
// Initialize device
virtual
bool Init(const mfxU32 adapterNum);
// Close the object
virtual
void Close(void);
protected:
// Pointer to the DXGI1 factory
void *m_pDXGIFactory1;
// Pointer to the current DXGI1 adapter
void *m_pDXGIAdapter1;
};
class DXVA2Device
{
public:
// Default constructor
DXVA2Device(void);
// Destructor
~DXVA2Device(void);
// Initialize device using D3D v9 interface
bool InitD3D9(const mfxU32 adapterNum);
// Initialize device using DXGI 1.1 interface
bool InitDXGI1(const mfxU32 adapterNum);
// Obtain graphic card's parameter
mfxU32 GetVendorID(void) const;
mfxU32 GetDeviceID(void) const;
mfxU64 GetDriverVersion(void) const;
// Provide the number of available adapters
mfxU32 GetAdapterCount(void) const;
void Close(void);
protected:
#ifdef MFX_D3D9_ENABLED
// Get vendor & device IDs by alternative way (D3D9 in Remote Desktop sessions)
void UseAlternativeWay(const D3D9Device *pD3D9Device);
#endif // MFX_D3D9_ENABLED
// Number of adapters available
mfxU32 m_numAdapters;
// Vendor ID
mfxU32 m_vendorID;
// Device ID
mfxU32 m_deviceID;
//x.x.x.x
mfxU64 m_driverVersion;
private:
// unimplemented by intent to make this class non-copyable
DXVA2Device(const DXVA2Device &);
void operator=(const DXVA2Device &);
};
} // namespace MFX
#endif // __MFX_DXVA2_DEVICE_H

View File

@@ -0,0 +1,141 @@
// Copyright (c) 2012-2019 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.
//
// WARNING:
// this file doesn't contain an include guard by intension.
// The file may be included into a source file many times.
// That is why this header doesn't contain any include directive.
// Please, do no try to fix it.
//
// Use define API_VERSION to set the API of functions listed further
// When new functions are added new section with functions declarations must be started with updated define
//
// API version 1.0 functions
//
// API version where a function is added. Minor value should precedes the major value
#define API_VERSION {{0, 1}}
// CORE interface functions
FUNCTION(mfxStatus, MFXVideoCORE_SetBufferAllocator, (mfxSession session, mfxBufferAllocator *allocator), (session, allocator))
FUNCTION(mfxStatus, MFXVideoCORE_SetFrameAllocator, (mfxSession session, mfxFrameAllocator *allocator), (session, allocator))
FUNCTION(mfxStatus, MFXVideoCORE_SetHandle, (mfxSession session, mfxHandleType type, mfxHDL hdl), (session, type, hdl))
FUNCTION(mfxStatus, MFXVideoCORE_GetHandle, (mfxSession session, mfxHandleType type, mfxHDL *hdl), (session, type, hdl))
FUNCTION(mfxStatus, MFXVideoCORE_SyncOperation, (mfxSession session, mfxSyncPoint syncp, mfxU32 wait), (session, syncp, wait))
// ENCODE interface functions
FUNCTION(mfxStatus, MFXVideoENCODE_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoENCODE_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoENCODE_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoENCODE_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_GetEncodeStat, (mfxSession session, mfxEncodeStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoENCODE_EncodeFrameAsync, (mfxSession session, mfxEncodeCtrl *ctrl, mfxFrameSurface1 *surface, mfxBitstream *bs, mfxSyncPoint *syncp), (session, ctrl, surface, bs, syncp))
// DECODE interface functions
FUNCTION(mfxStatus, MFXVideoDECODE_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoDECODE_DecodeHeader, (mfxSession session, mfxBitstream *bs, mfxVideoParam *par), (session, bs, par))
FUNCTION(mfxStatus, MFXVideoDECODE_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoDECODE_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoDECODE_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_GetDecodeStat, (mfxSession session, mfxDecodeStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoDECODE_SetSkipMode, (mfxSession session, mfxSkipMode mode), (session, mode))
FUNCTION(mfxStatus, MFXVideoDECODE_GetPayload, (mfxSession session, mfxU64 *ts, mfxPayload *payload), (session, ts, payload))
FUNCTION(mfxStatus, MFXVideoDECODE_DecodeFrameAsync, (mfxSession session, mfxBitstream *bs, mfxFrameSurface1 *surface_work, mfxFrameSurface1 **surface_out, mfxSyncPoint *syncp), (session, bs, surface_work, surface_out, syncp))
// VPP interface functions
FUNCTION(mfxStatus, MFXVideoVPP_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoVPP_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoVPP_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoVPP_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_GetVPPStat, (mfxSession session, mfxVPPStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoVPP_RunFrameVPPAsync, (mfxSession session, mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux, mfxSyncPoint *syncp), (session, in, out, aux, syncp))
#undef API_VERSION
//
// API version 1.1 functions
//
#define API_VERSION {{1, 1}}
FUNCTION(mfxStatus, MFXVideoUSER_Register, (mfxSession session, mfxU32 type, const mfxPlugin *par), (session, type, par))
FUNCTION(mfxStatus, MFXVideoUSER_Unregister, (mfxSession session, mfxU32 type), (session, type))
FUNCTION(mfxStatus, MFXVideoUSER_ProcessFrameAsync, (mfxSession session, const mfxHDL *in, mfxU32 in_num, const mfxHDL *out, mfxU32 out_num, mfxSyncPoint *syncp), (session, in, in_num, out, out_num, syncp))
#undef API_VERSION
//
// API version 1.10 functions
//
#define API_VERSION {{10, 1}}
FUNCTION(mfxStatus, MFXVideoENC_Query,(mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session,in,out))
FUNCTION(mfxStatus, MFXVideoENC_QueryIOSurf,(mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session,par,request))
FUNCTION(mfxStatus, MFXVideoENC_Init,(mfxSession session, mfxVideoParam *par), (session,par))
FUNCTION(mfxStatus, MFXVideoENC_Reset,(mfxSession session, mfxVideoParam *par), (session,par))
FUNCTION(mfxStatus, MFXVideoENC_Close,(mfxSession session),(session))
FUNCTION(mfxStatus, MFXVideoENC_ProcessFrameAsync,(mfxSession session, mfxENCInput *in, mfxENCOutput *out, mfxSyncPoint *syncp),(session,in,out,syncp))
FUNCTION(mfxStatus, MFXVideoVPP_RunFrameVPPAsyncEx, (mfxSession session, mfxFrameSurface1 *in, mfxFrameSurface1 *work, mfxFrameSurface1 **out, mfxSyncPoint *syncp), (session, in, work, out, syncp))
#undef API_VERSION
#define API_VERSION {{13, 1}}
FUNCTION(mfxStatus, MFXVideoPAK_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoPAK_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoPAK_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoPAK_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoPAK_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoPAK_ProcessFrameAsync, (mfxSession session, mfxPAKInput *in, mfxPAKOutput *out, mfxSyncPoint *syncp), (session, in, out, syncp))
#undef API_VERSION
#define API_VERSION {{14, 1}}
// FUNCTION(mfxStatus, MFXInitEx, (mfxInitParam par, mfxSession session), (par, session))
FUNCTION(mfxStatus, MFXDoWork, (mfxSession session), (session))
#undef API_VERSION
#define API_VERSION {{19, 1}}
FUNCTION(mfxStatus, MFXVideoENC_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoPAK_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoCORE_QueryPlatform, (mfxSession session, mfxPlatform* platform), (session, platform))
FUNCTION(mfxStatus, MFXVideoUSER_GetPlugin, (mfxSession session, mfxU32 type, mfxPlugin *par), (session, type, par))
#undef API_VERSION

View File

@@ -0,0 +1,134 @@
// 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
// 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_LIBRARY_ITERATOR_H)
#define __MFX_LIBRARY_ITERATOR_H
#include <mfxvideo.h>
#if !defined(MEDIASDK_UWP_DISPATCHER)
#include "mfx_win_reg_key.h"
#endif
#include "mfx_driver_store_loader.h"
#include "mfx_dispatcher.h"
namespace MFX
{
// declare desired storage ID
enum
{
#if defined (MFX_TRACER_WA_FOR_DS)
MFX_UNKNOWN_KEY = -1,
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
#else
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
mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterface, mfxU32 *pVendorID, mfxU32 *pDeviceID);
const mfxU32 msdk_disp_path_len = 1024;
class MFXLibraryIterator
{
public:
// Default constructor
MFXLibraryIterator(void);
// Destructor
~MFXLibraryIterator(void);
// Initialize the iterator
mfxStatus Init(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID);
// Get the next library path
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(wchar_t *subKeyName, size_t length) const;
int GetStorageID() const { return m_StorageID; }
protected:
// Release the iterator
void Release(void);
// Initialize the registry iterator
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
mfxIMPL m_implInterface; // Required interface (D3D9, D3D11)
mfxU32 m_vendorID; // (mfxU32) property of used graphic card
mfxU32 m_deviceID; // (mfxU32) property of used graphic card
bool m_bIsSubKeyValid;
wchar_t m_SubKeyName[MFX_MAX_REGISTRY_KEY_NAME]; // registry subkey for selected module loaded
int m_StorageID;
#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
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
MFXLibraryIterator(const MFXLibraryIterator &);
void operator=(const MFXLibraryIterator &);
};
} // namespace MFX
#endif // __MFX_LIBRARY_ITERATOR_H

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2012-2019 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_LOAD_DLL_H)
#define __MFX_LOAD_DLL_H
#include "mfx_dispatcher.h"
namespace MFX
{
//
// declare DLL loading routines
//
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(wchar_t *pPath, size_t pathSize);
#endif
mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType);
mfxModuleHandle mfx_dll_load(const wchar_t *file_name);
//increments reference counter
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);
} // namespace MFX
#endif // __MFX_LOAD_DLL_H

View File

@@ -0,0 +1,85 @@
// Copyright (c) 2013-2019 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.
#pragma once
#include "mfxplugin.h"
#include "mfx_dispatcher_defs.h"
#include "mfx_plugin_hive.h"
namespace MFX
{
typedef mfxStatus (MFX_CDECL *CreatePluginPtr_t)(mfxPluginUID uid, mfxPlugin* plugin);
class PluginModule
{
mfxModuleHandle mHmodule;
CreatePluginPtr_t mCreatePluginPtr;
wchar_t mPath[MAX_PLUGIN_PATH];
public:
PluginModule();
PluginModule(const wchar_t * path);
PluginModule(const PluginModule & that) ;
PluginModule & operator = (const PluginModule & that);
bool Create(mfxPluginUID guid, mfxPlugin&);
~PluginModule(void);
private:
void Tidy();
};
class MFXPluginFactory {
struct FactoryRecord {
mfxPluginParam plgParams;
PluginModule module;
mfxPlugin plugin;
FactoryRecord ()
: plgParams(), plugin()
{}
FactoryRecord(const mfxPluginParam &plgParams,
PluginModule &module,
mfxPlugin plugin)
: plgParams(plgParams)
, module(module)
, plugin(plugin) {
}
};
MFXVector<FactoryRecord> mPlugins;
mfxU32 nPlugins;
mfxSession mSession;
public:
MFXPluginFactory(mfxSession session);
void Close();
mfxStatus Create(const PluginDescriptionRecord &);
bool Destroy(const mfxPluginUID &);
~MFXPluginFactory();
protected:
void DestroyPlugin( FactoryRecord & );
static bool RunVerification( const mfxPlugin & plg, const PluginDescriptionRecord &dsc, mfxPluginParam &pluginParams );
static bool VerifyEncoder( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyAudioEncoder( const mfxAudioCodecPlugin &audioCodec );
static bool VerifyEnc( const mfxVideoCodecPlugin &videoEnc );
static bool VerifyVpp( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyDecoder( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyAudioDecoder( const mfxAudioCodecPlugin &audioCodec );
static bool VerifyCodecCommon( const mfxVideoCodecPlugin & Video );
};
}

View File

@@ -0,0 +1,115 @@
// Copyright (c) 2013-2019 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.
#pragma once
#include "mfx_dispatcher_defs.h"
#include "mfxplugin.h"
#include "mfx_win_reg_key.h"
#include "mfx_vector.h"
#include <string.h>
#include <memory>
#include <stdio.h>
struct MFX_DISP_HANDLE;
namespace MFX {
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)
{
return !(lhs == rhs);
}
#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
{
public:
wchar_t sPath[MAX_PLUGIN_PATH];
char sName[MAX_PLUGIN_NAME];
//used for FS plugins that has poor description
bool onlyVersionRegistered;
bool Default;
PluginDescriptionRecord()
: mfxPluginParam()
, sPath()
, sName()
, onlyVersionRegistered()
, Default()
{
}
};
typedef MFXVector<PluginDescriptionRecord> MFXPluginStorage;
class MFXPluginStorageBase : public MFXPluginStorage
{
protected:
mfxVersion mCurrentAPIVersion;
protected:
MFXPluginStorageBase(mfxVersion currentAPIVersion)
: mCurrentAPIVersion(currentAPIVersion)
{
}
void ConvertAPIVersion( mfxU32 APIVersion, PluginDescriptionRecord &descriptionRecord) const
{
descriptionRecord.APIVersion.Minor = static_cast<mfxU16> (APIVersion & 0x0ff);
descriptionRecord.APIVersion.Major = static_cast<mfxU16> (APIVersion >> 8);
}
};
#if !defined(MEDIASDK_UWP_DISPATCHER)
//populated from registry
class MFXPluginsInHive : public MFXPluginStorageBase
{
public:
MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLibSubKey, mfxVersion currentAPIVersion);
};
//plugins are loaded from FS close to executable
class MFXPluginsInFS : public MFXPluginStorageBase
{
bool mIsVersionParsed;
bool mIsAPIVersionParsed;
public:
MFXPluginsInFS(mfxVersion currentAPIVersion);
private:
bool ParseFile(FILE * f, PluginDescriptionRecord & des);
bool ParseKVPair( wchar_t *key, wchar_t * value, PluginDescriptionRecord & des);
};
#endif //#if !defined(MEDIASDK_UWP_DISPATCHER)
//plugins are loaded from FS close to Runtime library
class MFXDefaultPlugins : public MFXPluginStorageBase
{
public:
MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP_HANDLE * hdl, int implType);
private:
};
}

View File

@@ -0,0 +1,217 @@
// Copyright (c) 2013-2019 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.
#pragma once
#include "mfxstructures.h"
#include <exception>
namespace MFX
{
template <class T>
class iterator_tmpl
{
template <class U> friend class MFXVector;
mfxU32 mIndex;
T* mRecords;
iterator_tmpl(mfxU32 index , T * records)
: mIndex (index)
, mRecords(records)
{}
public:
iterator_tmpl()
: mIndex ()
, mRecords()
{}
bool operator ==(const iterator_tmpl<T> & that )const
{
return mIndex == that.mIndex;
}
bool operator !=(const iterator_tmpl<T> & that )const
{
return mIndex != that.mIndex;
}
mfxU32 operator - (const iterator_tmpl<T> &that) const
{
return mIndex - that.mIndex;
}
iterator_tmpl<T> & operator ++()
{
mIndex++;
return * this;
}
iterator_tmpl<T> & operator ++(int)
{
mIndex++;
return * this;
}
T & operator *()
{
return mRecords[mIndex];
}
T * operator ->()
{
return mRecords + mIndex;
}
};
class MFXVectorRangeError : public std::exception
{
};
template <class T>
class MFXVector
{
T* mRecords;
mfxU32 mNrecords;
public:
MFXVector()
: mRecords()
, mNrecords()
{}
MFXVector(const MFXVector & rhs)
: mRecords()
, mNrecords()
{
insert(end(), rhs.begin(), rhs.end());
}
MFXVector & operator = (const MFXVector & rhs)
{
if (this != &rhs)
{
clear();
insert(end(), rhs.begin(), rhs.end());
}
return *this;
}
virtual ~MFXVector ()
{
clear();
}
typedef iterator_tmpl<T> iterator;
iterator begin() const
{
return iterator(0u, mRecords);
}
iterator end() const
{
return iterator(mNrecords, mRecords);
}
void insert(iterator where, iterator beg_iter, iterator end_iter)
{
mfxU32 elementsToInsert = (end_iter - beg_iter);
if (!elementsToInsert)
{
return;
}
if (where.mIndex > mNrecords)
{
throw MFXVectorRangeError();
}
T *newRecords = new T[mNrecords + elementsToInsert]();
mfxU32 i = 0;
// save left
for (; i < where.mIndex; i++)
{
newRecords[i] = mRecords[i];
}
// insert
for (; beg_iter != end_iter; beg_iter++, i++)
{
newRecords[i] = *beg_iter;
}
//save right
for (; i < mNrecords + elementsToInsert; i++)
{
newRecords[i] = mRecords[i - elementsToInsert];
}
delete [] mRecords;
mRecords = newRecords;
mNrecords = i;
}
T& operator [] (mfxU32 idx)
{
return mRecords[idx];
}
void push_back(const T& obj)
{
T *newRecords = new T[mNrecords + 1]();
mfxU32 i = 0;
for (; i <mNrecords; i++)
{
newRecords[i] = mRecords[i];
}
newRecords[i] = obj;
delete [] mRecords;
mRecords = newRecords;
mNrecords = i + 1;
}
void erase (iterator at)
{
if (at.mIndex >= mNrecords)
{
throw MFXVectorRangeError();
}
mNrecords--;
mfxU32 i = at.mIndex;
for (; i != mNrecords; i++)
{
mRecords[i] = mRecords[i+1];
}
//destroy last element
mRecords[i] = T();
}
void resize(mfxU32 nSize)
{
T * newRecords = new T[nSize]();
for (mfxU32 i = 0; i <mNrecords; i++)
{
newRecords[i] = mRecords[i];
}
delete [] mRecords;
mRecords = newRecords;
mNrecords = nSize;
}
mfxU32 size() const
{
return mNrecords;
}
void clear()
{
delete [] mRecords;
mRecords = 0;
mNrecords = 0;
}
bool empty()
{
return !mRecords;
}
T * data() const
{
return mRecords;
}
};
}

View File

@@ -0,0 +1,104 @@
// Copyright (c) 2012-2019 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_WIN_REG_KEY_H)
#define __MFX_WIN_REG_KEY_H
#include <windows.h>
#include "mfxplugin.h"
#include "mfx_dispatcher_log.h"
#if !defined(MEDIASDK_UWP_DISPATCHER)
namespace MFX {
template<class T> struct RegKey{};
template<> struct RegKey<bool>{enum {type = REG_DWORD};};
template<> struct RegKey<mfxU32>{enum {type = REG_DWORD};};
template<> struct RegKey<mfxPluginUID>{enum {type = REG_BINARY};};
template<> struct RegKey<mfxVersion>{enum {type = REG_DWORD};};
template<> struct RegKey<char*>{enum {type = REG_SZ};};
template<> struct RegKey<wchar_t*>{enum {type = REG_SZ};};
class WinRegKey
{
public:
// Default constructor
WinRegKey(void);
// Destructor
~WinRegKey(void);
// Open a registry key
bool Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired);
bool Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired);
// Query value
bool QueryInfo(LPDWORD lpcSubkeys);
bool QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData);
bool Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData);
bool Query(const wchar_t *pValueName, wchar_t *pData, mfxU32 &nData) {
DWORD dw = (DWORD)nData;
if (!Query(pValueName, RegKey<wchar_t*>::type, (LPBYTE)pData, &dw)){
return false;
}
nData = dw;
return true;
}
// Enumerate value names
bool EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType);
bool EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName);
protected:
// Release the object
void Release(void);
HKEY m_hKey; // (HKEY) handle to the opened key
private:
// unimplemented by intent to make this class non-copyable
WinRegKey(const WinRegKey &);
void operator=(const WinRegKey &);
};
template<class T>
inline bool QueryKey(WinRegKey & key, const wchar_t *pValueName, T &data ) {
DWORD size = sizeof(data);
return key.Query(pValueName, RegKey<T>::type, (LPBYTE) &data, &size);
}
template<>
inline bool QueryKey<bool>(WinRegKey & key, const wchar_t *pValueName, bool &data ) {
mfxU32 value = 0;
bool bRes = QueryKey(key, pValueName, value);
data = (1 == value);
return bRes;
}
} // namespace MFX
#endif // #if !defined(MEDIASDK_UWP_DISPATCHER)
#endif // __MFX_WIN_REG_KEY_H

View File

@@ -0,0 +1,71 @@
// Copyright (c) 2013-2019 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.
//
// WARNING:
// this file doesn't contain an include guard by intension.
// The file may be included into a source file many times.
// That is why this header doesn't contain any include directive.
// Please, do no try to fix it.
//
//
// API version 1.8 functions
//
// Minor value should precedes the major value
#define API_VERSION {{8, 1}}
// CORE interface functions
FUNCTION(mfxStatus, MFXAudioCORE_SyncOperation, (mfxSession session, mfxSyncPoint syncp, mfxU32 wait), (session, syncp, wait))
// ENCODE interface functions
FUNCTION(mfxStatus, MFXAudioENCODE_Query, (mfxSession session, mfxAudioParam *in, mfxAudioParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXAudioENCODE_QueryIOSize, (mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXAudioENCODE_Init, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_Reset, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXAudioENCODE_GetAudioParam, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_EncodeFrameAsync, (mfxSession session, mfxAudioFrame *frame, mfxBitstream *buffer_out, mfxSyncPoint *syncp), (session, frame, buffer_out, syncp))
// DECODE interface functions
FUNCTION(mfxStatus, MFXAudioDECODE_Query, (mfxSession session, mfxAudioParam *in, mfxAudioParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXAudioDECODE_DecodeHeader, (mfxSession session, mfxBitstream *bs, mfxAudioParam *par), (session, bs, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Init, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Reset, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXAudioDECODE_QueryIOSize, (mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXAudioDECODE_GetAudioParam, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_DecodeFrameAsync, (mfxSession session, mfxBitstream *bs, mfxAudioFrame *frame_out, mfxSyncPoint *syncp), (session, bs, frame_out, syncp))
#undef API_VERSION
//
// API version 1.9 functions
//
#define API_VERSION {{9, 1}}
FUNCTION(mfxStatus, MFXAudioUSER_Register, (mfxSession session, mfxU32 type, const mfxPlugin *par), (session, type, par))
FUNCTION(mfxStatus, MFXAudioUSER_Unregister, (mfxSession session, mfxU32 type), (session, type))
FUNCTION(mfxStatus, MFXAudioUSER_ProcessFrameAsync, (mfxSession session, const mfxHDL *in, mfxU32 in_num, const mfxHDL *out, mfxU32 out_num, mfxSyncPoint *syncp), (session, in, in_num, out, out_num, syncp))
#undef API_VERSION

View File

@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{336AEFC3-987C-40AA-9678-E8BF1EC9C26F}</ProjectGuid>
<RootNamespace>libmfx_uwp</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>libmfx_uwp</ProjectName>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<ApplicationType>Windows Store</ApplicationType>
<AppContainerApplication>true</AppContainerApplication>
<DefaultLanguage>en-US</DefaultLanguage>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="$(Configuration.Contains('Release'))" Label="Configuration">
<WholeProgramOptimization>false</WholeProgramOptimization>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Debug'))" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
<TargetName>$(ProjectName)</TargetName>
<OutDir>..\..\..\..\build\win_$(Platform)\$(Configuration)\lib\</OutDir>
<IntDir>$(OutDir)..\objs\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(MINIDDK_ROOT)\Include\um;$(MINIDDK_ROOT)\Include\shared;$(IncludePath)</IncludePath>
<LibraryPath>$(MINIDDK_ROOT)\Lib\win8\um\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<!-- Global settings -->
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>false</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>Async</ExceptionHandling>
<PreprocessorDefinitions>_LIB;WINAPI_FAMILY=WINAPI_FAMILY_APP;MEDIASDK_UWP_DISPATCHER;MFX_D3D11_ENABLED;_UNICODE;UNICODE;MFX_VA;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions);WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAsWinRT>false</CompileAsWinRT>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<!-- End of Global settings -->
<!-- Configuration dependent settings -->
<ItemDefinitionGroup Condition="$(Configuration.Contains('Debug'))">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<Optimization>Disabled</Optimization>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnablePREfast>false</EnablePREfast>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.Contains('Release'))">
<ClCompile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>true</BufferSecurityCheck>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="!$(Platform.Contains('ARM'))">
<Lib>
<AdditionalLibraryDirectories>$(MfxBuildDir)..\build\win_$(Platform)\lib\</AdditionalLibraryDirectories>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Lib>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
</ItemDefinitionGroup>
<!-- End of Configuration dependent settings -->
<!-- Platform dependent settings -->
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PreprocessorDefinitions>WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Platform.Contains('ARM'))">
<ClCompile>
<PreprocessorDefinitions>MEDIASDK_ARM_LOADER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<!-- End of Platform dependent settings -->
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\mfx_dispatcher.cpp" />
<ClCompile Include="src\mfx_dispatcher_uwp.cpp" />
<ClCompile Include="src\mfx_dispatcher_log.cpp" />
<ClCompile Include="src\mfx_driver_store_loader.cpp" />
<ClCompile Include="src\mfx_function_table.cpp" />
<ClCompile Include="src\mfx_load_dll.cpp" />
<ClCompile Include="src\mfx_dxva2_device.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\mfxaudio_exposed_functions_list.h" />
<ClInclude Include="include\mfx_dispatcher.h" />
<ClInclude Include="include\mfx_dispatcher_uwp.h" />
<ClInclude Include="include\mfx_dispatcher_defs.h" />
<ClInclude Include="include\mfx_dispatcher_log.h" />
<ClInclude Include="include\mfx_driver_store_loader.h" />
<ClInclude Include="include\mfx_exposed_functions_list.h" />
<ClInclude Include="include\mfx_load_dll.h" />
<ClInclude Include="include\mfx_dxva2_device.h" />
<ClInclude Include="include\mfx_vector.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\mfx_dispatcher.cpp" />
<ClCompile Include="src\mfx_dispatcher_uwp.cpp" />
<ClCompile Include="src\mfx_dispatcher_log.cpp" />
<ClCompile Include="src\mfx_function_table.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\mfx_load_dll.cpp" />
<ClCompile Include="src\mfx_driver_store_loader.cpp" />
<ClCompile Include="src\mfx_dxva2_device.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\mfxaudio_exposed_functions_list.h" />
<ClInclude Include="include\mfx_dispatcher.h" />
<ClInclude Include="include\mfx_dispatcher_uwp.h" />
<ClInclude Include="include\mfx_dispatcher_defs.h" />
<ClInclude Include="include\mfx_dispatcher_log.h" />
<ClInclude Include="include\mfx_exposed_functions_list.h" />
<ClInclude Include="include\mfx_vector.h" />
<ClInclude Include="include\mfx_load_dll.h" />
<ClInclude Include="include\mfx_driver_store_loader.h" />
<ClInclude Include="include\mfx_dxva2_device.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="Documentation">
<UniqueIdentifier>{a76fc74b-469b-40f4-888b-abe6d364d3e2}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,248 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<Optimization>Disabled</Optimization>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A9F7AEFB-DC6C-49E8-8E71-5351ABDCE627}</ProjectGuid>
<RootNamespace>libmfx</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>libmfx_vs2015</ProjectName>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<WholeProgramOptimization>false</WholeProgramOptimization>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<WholeProgramOptimization>false</WholeProgramOptimization>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
<OutDir>..\..\..\..\build\win_$(Platform)\$(Configuration)\lib\</OutDir>
<IntDir>$(OutDir)..\objs\$(ProjectName)\</IntDir>
<IncludePath>$(MINIDDK_ROOT)\Include\um;$(MINIDDK_ROOT)\Include\shared;$(IncludePath)</IncludePath>
<LibraryPath>$(MINIDDK_ROOT)\Lib\win8\um\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>$(CPPFLAGS) %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>false</TreatWarningAsError>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>Async</ExceptionHandling>
<PreprocessorDefinitions>MFX_D3D11_ENABLED;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectName)</TargetName>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;MFX_VA;MFX_DEPRECATED_OFF;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<EnablePREfast>false</EnablePREfast>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;MFX_VA;MFX_DEPRECATED_OFF;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>true</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;NDEBUG;_LIB;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>true</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\mfx_dispatcher_main.cpp" />
<ClCompile Include="src\mfx_critical_section.cpp" />
<ClCompile Include="src\mfx_dispatcher.cpp" />
<ClCompile Include="src\mfx_dispatcher_log.cpp" />
<ClCompile Include="src\mfx_driver_store_loader.cpp" />
<ClCompile Include="src\mfx_dxva2_device.cpp" />
<ClCompile Include="src\mfx_function_table.cpp" />
<ClCompile Include="src\mfx_library_iterator.cpp" />
<ClCompile Include="src\mfx_load_dll.cpp" />
<ClCompile Include="src\mfx_load_plugin.cpp" />
<ClCompile Include="src\mfx_plugin_hive.cpp" />
<ClCompile Include="src\mfx_win_reg_key.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\mfxaudio_exposed_functions_list.h" />
<ClInclude Include="include\mfx_critical_section.h" />
<ClInclude Include="include\mfx_dispatcher.h" />
<ClInclude Include="include\mfx_dispatcher_defs.h" />
<ClInclude Include="include\mfx_dispatcher_log.h" />
<ClInclude Include="include\mfx_driver_store_loader.h" />
<ClInclude Include="include\mfx_dxva2_device.h" />
<ClInclude Include="include\mfx_exposed_functions_list.h" />
<ClInclude Include="include\mfx_library_iterator.h" />
<ClInclude Include="include\mfx_load_dll.h" />
<ClInclude Include="include\mfx_load_plugin.h" />
<ClInclude Include="include\mfx_plugin_hive.h" />
<ClInclude Include="include\mfx_win_reg_key.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>mfx_dispatch_trace_lib</ProjectName>
<ProjectGuid>{45806EE4-0256-4B1D-A730-EB70966E070A}</ProjectGuid>
<RootNamespace>mfx_dispatch_trace</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\build\win_$(Platform)\lib\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)..\objs\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\..\build\win_$(Platform)\lib\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)..\objs\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\build\win_$(Platform)\lib\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)..\objs\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\..\build\win_$(Platform)\lib\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)..\objs\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectName)_mbcs</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectName)_mbcs</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>$(ProjectName)_d_mbcs</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>$(ProjectName)_d_mbcs</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;../shared/include;../../include;$(MfxIppIncludeDir);../mfx_lib/shared/include;../shared/umc/core/umc/include;../shared/umc/core/vm/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;MFX_DISPATCHER_LOG;DXVA2DEVICE_LOG;MFX_DISPATCHER_EXPOSED_PREFIX;MFX_VA;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;../shared/include;../../include;$(MfxIppIncludeDir);../mfx_lib/shared/include;../shared/umc/core/umc/include;../shared/umc/core/vm/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;_DEBUG;_CONSOLE;MFX_DISPATCHER_LOG;DXVA2DEVICE_LOG;MFX_DISPATCHER_EXPOSED_PREFIX;MFX_VA;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;../shared/include;../../include;$(MfxIppIncludeDir);../mfx_lib/shared/include;../shared/umc/core/umc/include;../shared/umc/core/vm/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;MFX_DISPATCHER_LOG;DXVA2DEVICE_LOG;MFX_DISPATCHER_EXPOSED_PREFIX;MFX_VA;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
</ClCompile>
<Lib />
<Lib>
<OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>include;../shared/include;../../include;$(MfxIppIncludeDir);../mfx_lib/shared/include;../shared/umc/core/umc/include;../shared/umc/core/vm/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;NDEBUG;_CONSOLE;MFX_DISPATCHER_LOG;DXVA2DEVICE_LOG;MFX_DISPATCHER_EXPOSED_PREFIX;MFX_VA;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
</ClCompile>
<Lib />
<Lib>
<OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\mfx_critical_section.cpp" />
<ClCompile Include="src\mfx_dispatcher.cpp" />
<ClCompile Include="src\mfx_dispatcher_log.cpp" />
<ClCompile Include="src\mfx_driver_store_loader.cpp" />
<ClCompile Include="src\mfx_dxva2_device.cpp" />
<ClCompile Include="src\mfx_function_table.cpp" />
<ClCompile Include="src\mfx_library_iterator.cpp" />
<ClCompile Include="src\mfx_load_dll.cpp" />
<ClCompile Include="src\mfx_load_plugin.cpp" />
<ClCompile Include="src\mfx_plugin_hive.cpp" />
<ClCompile Include="src\mfx_win_reg_key.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\mfx_critical_section.h" />
<ClInclude Include="include\mfx_dispatcher.h" />
<ClInclude Include="include\mfx_dispatcher_defs.h" />
<ClInclude Include="include\mfx_dispatcher_log.h" />
<ClInclude Include="include\mfx_driver_store_loader.h" />
<ClInclude Include="include\mfx_dxva2_device.h" />
<ClInclude Include="include\mfx_exposed_functions_list.h" />
<ClInclude Include="include\mfx_library_iterator.h" />
<ClInclude Include="include\mfx_load_dll.h" />
<ClInclude Include="include\mfx_load_plugin.h" />
<ClInclude Include="include\mfx_plugin_hive.h" />
<ClInclude Include="include\mfx_win_reg_key.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,74 @@
// Copyright (c) 2012-2019 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 "mfx_critical_section.h"
#include <windows.h>
// SDK re-declares the following functions with different call declarator.
// We don't need them. Just redefine them to nothing.
#define _interlockedbittestandset fake_set
#define _interlockedbittestandreset fake_reset
#define _interlockedbittestandset64 fake_set64
#define _interlockedbittestandreset64 fake_reset64
#include <intrin.h>
#define MFX_WAIT() SwitchToThread()
// static section of the file
namespace
{
enum
{
MFX_SC_IS_FREE = 0,
MFX_SC_IS_TAKEN = 1
};
} // namespace
namespace MFX
{
mfxU32 mfxInterlockedCas32(mfxCriticalSection *pCSection, mfxU32 value_to_exchange, mfxU32 value_to_compare)
{
return _InterlockedCompareExchange(pCSection, value_to_exchange, value_to_compare);
}
mfxU32 mfxInterlockedXchg32(mfxCriticalSection *pCSection, mfxU32 value)
{
return _InterlockedExchange(pCSection, value);
}
void mfxEnterCriticalSection(mfxCriticalSection *pCSection)
{
while (MFX_SC_IS_TAKEN == mfxInterlockedCas32(pCSection,
MFX_SC_IS_TAKEN,
MFX_SC_IS_FREE))
{
MFX_WAIT();
}
} // void mfxEnterCriticalSection(mfxCriticalSection *pCSection)
void mfxLeaveCriticalSection(mfxCriticalSection *pCSection)
{
mfxInterlockedXchg32(pCSection, MFX_SC_IS_FREE);
} // void mfxLeaveCriticalSection(mfxCriticalSection *pCSection)
} // namespace MFX

View File

@@ -0,0 +1,661 @@
// 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
// 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 "mfx_dispatcher.h"
#include "mfx_dispatcher_log.h"
#include "mfx_load_dll.h"
#include <assert.h>
#include <string.h>
#include <windows.h>
#include "mfx_dxva2_device.h"
#include "mfxvideo++.h"
#include "mfx_vector.h"
#include "mfxadapter.h"
#include <algorithm>
#pragma warning(disable:4355)
MFX_DISP_HANDLE::MFX_DISP_HANDLE(const mfxVersion requiredVersion) :
_mfxSession()
,apiVersion(requiredVersion)
,pluginHive()
,pluginFactory((mfxSession)this)
{
actualApiVersion.Version = 0;
implType = MFX_LIB_SOFTWARE;
impl = MFX_IMPL_SOFTWARE;
loadStatus = MFX_ERR_NOT_FOUND;
dispVersion.Major = MFX_DISPATCHER_VERSION_MAJOR;
dispVersion.Minor = MFX_DISPATCHER_VERSION_MINOR;
storageID = 0;
implInterface = MFX_IMPL_HARDWARE_ANY;
hModule = (mfxModuleHandle) 0;
} // MFX_DISP_HANDLE::MFX_DISP_HANDLE(const mfxVersion requiredVersion)
MFX_DISP_HANDLE::~MFX_DISP_HANDLE(void)
{
Close();
} // MFX_DISP_HANDLE::~MFX_DISP_HANDLE(void)
mfxStatus MFX_DISP_HANDLE::Close(void)
{
mfxStatus mfxRes;
mfxRes = UnLoadSelectedDLL();
// need to reset dispatcher state after unloading dll
if (MFX_ERR_NONE == mfxRes)
{
implType = MFX_LIB_SOFTWARE;
impl = MFX_IMPL_SOFTWARE;
loadStatus = MFX_ERR_NOT_FOUND;
dispVersion.Major = MFX_DISPATCHER_VERSION_MAJOR;
dispVersion.Minor = MFX_DISPATCHER_VERSION_MINOR;
*static_cast<_mfxSession*>(this) = _mfxSession();
hModule = (mfxModuleHandle) 0;
}
return mfxRes;
} // mfxStatus MFX_DISP_HANDLE::Close(void)
mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const wchar_t *pPath, eMfxImplType reqImplType,
mfxIMPL reqImpl, mfxIMPL reqImplInterface, mfxInitParam &par)
{
mfxStatus mfxRes = MFX_ERR_NONE;
// check error(s)
if ((MFX_LIB_SOFTWARE != reqImplType) &&
(MFX_LIB_HARDWARE != reqImplType))
{
DISPATCHER_LOG_ERROR((("implType == %s, should be either MFX_LIB_SOFTWARE ot MFX_LIB_HARDWARE\n"), DispatcherLog_GetMFXImplString(reqImplType).c_str()));
loadStatus = MFX_ERR_ABORTED;
return loadStatus;
}
// only exact types of implementation is allowed
if (!(reqImpl & MFX_IMPL_AUDIO) &&
#if (MFX_VERSION >= MFX_VERSION_NEXT)
!(reqImpl & MFX_IMPL_EXTERNAL_THREADING) &&
#endif
(MFX_IMPL_SOFTWARE != reqImpl) &&
(MFX_IMPL_HARDWARE != reqImpl) &&
(MFX_IMPL_HARDWARE2 != reqImpl) &&
(MFX_IMPL_HARDWARE3 != reqImpl) &&
(MFX_IMPL_HARDWARE4 != reqImpl))
{
DISPATCHER_LOG_ERROR((("invalid implementation impl == %s\n"), DispatcherLog_GetMFXImplString(impl).c_str()));
loadStatus = MFX_ERR_ABORTED;
return loadStatus;
}
// only mfxExtThreadsParam is allowed
if (par.NumExtParam)
{
if ((par.NumExtParam > 1) || !par.ExtParam)
{
loadStatus = MFX_ERR_ABORTED;
return loadStatus;
}
if ((par.ExtParam[0]->BufferId != MFX_EXTBUFF_THREADS_PARAM) ||
(par.ExtParam[0]->BufferSz != sizeof(mfxExtThreadsParam)))
{
loadStatus = MFX_ERR_ABORTED;
return loadStatus;
}
}
// close the handle before initialization
Close();
// save the library's type
this->implType = reqImplType;
this->impl = reqImpl;
this->implInterface = reqImplInterface;
{
assert(hModule == (mfxModuleHandle)0);
DISPATCHER_LOG_BLOCK(("invoking LoadLibrary(%S)\n", pPath));
// load the DLL into the memory
hModule = MFX::mfx_dll_load(pPath);
if (hModule)
{
int i;
DISPATCHER_LOG_OPERATION({
wchar_t modulePath[1024];
GetModuleFileNameW((HMODULE)hModule, modulePath, sizeof(modulePath)/sizeof(modulePath[0]));
DISPATCHER_LOG_INFO((("loaded module %S\n"), modulePath))
});
if (impl & MFX_IMPL_AUDIO)
{
// load audio functions: pointers to exposed functions
for (i = 0; i < eAudioFuncTotal; i += 1)
{
// construct correct name of the function - remove "_a" postfix
mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIAudioFunc[i].pName);
if (pProc)
{
// function exists in the library,
// save the pointer.
callAudioTable[i] = pProc;
}
else
{
// The library doesn't contain the function
DISPATCHER_LOG_WRN((("Can't find API function \"%s\"\n"), APIAudioFunc[i].pName));
if (apiVersion.Version >= APIAudioFunc[i].apiVersion.Version)
{
DISPATCHER_LOG_ERROR((("\"%s\" is required for API %u.%u\n"), APIAudioFunc[i].pName, apiVersion.Major, apiVersion.Minor));
mfxRes = MFX_ERR_UNSUPPORTED;
break;
}
}
}
}
else
{
// load video functions: pointers to exposed functions
for (i = 0; i < eVideoFuncTotal; i += 1)
{
mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIFunc[i].pName);
if (pProc)
{
// function exists in the library,
// save the pointer.
callTable[i] = pProc;
}
else
{
// The library doesn't contain the function
DISPATCHER_LOG_WRN((("Can't find API function \"%s\"\n"), APIFunc[i].pName));
if (apiVersion.Version >= APIFunc[i].apiVersion.Version)
{
DISPATCHER_LOG_ERROR((("\"%s\" is required for API %u.%u\n"), APIFunc[i].pName, apiVersion.Major, apiVersion.Minor));
mfxRes = MFX_ERR_UNSUPPORTED;
break;
}
}
}
}
}
else
{
DISPATCHER_LOG_WRN((("can't find DLL: GetLastErr()=0x%x\n"), GetLastError()))
mfxRes = MFX_ERR_UNSUPPORTED;
}
}
// initialize the loaded DLL
if (MFX_ERR_NONE == mfxRes)
{
mfxVersion version(apiVersion);
/* check whether it is audio session or video */
mfxFunctionPointer *actualTable = (impl & MFX_IMPL_AUDIO) ? callAudioTable : callTable;
// Call old-style MFXInit init for older libraries and audio library
bool callOldInit = (impl & MFX_IMPL_AUDIO) || !actualTable[eMFXInitEx]; // if true call eMFXInit, if false - eMFXInitEx
int tableIndex = (callOldInit) ? eMFXInit : eMFXInitEx;
mfxFunctionPointer pFunc = actualTable[tableIndex];
{
if (callOldInit)
{
DISPATCHER_LOG_BLOCK(("MFXInit(%s,ver=%u.%u,session=0x%p)\n"
, DispatcherLog_GetMFXImplString(impl | implInterface).c_str()
, apiVersion.Major
, apiVersion.Minor
, &session));
mfxRes = (*(mfxStatus(MFX_CDECL *) (mfxIMPL, mfxVersion *, mfxSession *)) pFunc) (impl | implInterface, &version, &session);
}
else
{
DISPATCHER_LOG_BLOCK(("MFXInitEx(%s,ver=%u.%u,ExtThreads=%d,session=0x%p)\n"
, DispatcherLog_GetMFXImplString(impl | implInterface).c_str()
, apiVersion.Major
, apiVersion.Minor
, par.ExternalThreads
, &session));
mfxInitParam initPar = par;
// adjusting user parameters
initPar.Implementation = impl | implInterface;
initPar.Version = version;
mfxRes = (*(mfxStatus(MFX_CDECL *) (mfxInitParam, mfxSession *)) pFunc) (initPar, &session);
}
}
if (MFX_ERR_NONE != mfxRes)
{
DISPATCHER_LOG_WRN((("library can't be load. MFXInit returned %s \n"), DispatcherLog_GetMFXStatusString(mfxRes)))
}
else
{
mfxRes = MFXQueryVersion((mfxSession) this, &actualApiVersion);
if (MFX_ERR_NONE != mfxRes)
{
DISPATCHER_LOG_ERROR((("MFXQueryVersion returned: %d, skiped this library\n"), mfxRes))
}
else
{
DISPATCHER_LOG_INFO((("MFXQueryVersion returned API: %d.%d\n"), actualApiVersion.Major, actualApiVersion.Minor))
//special hook for applications that uses sink api to get loaded library path
DISPATCHER_LOG_LIBRARY(("%p" , hModule));
DISPATCHER_LOG_INFO(("library loaded succesfully\n"))
}
}
}
loadStatus = mfxRes;
return mfxRes;
} // mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const wchar_t *pPath, eMfxImplType implType, mfxIMPL impl)
mfxStatus MFX_DISP_HANDLE::UnLoadSelectedDLL(void)
{
mfxStatus mfxRes = MFX_ERR_NONE;
//unregistered plugins if any
pluginFactory.Close();
// close the loaded DLL
if (session)
{
/* check whether it is audio session or video */
int tableIndex = eMFXClose;
mfxFunctionPointer pFunc;
if (impl & MFX_IMPL_AUDIO)
{
pFunc = callAudioTable[tableIndex];
}
else
{
pFunc = callTable[tableIndex];
}
mfxRes = (*(mfxStatus (MFX_CDECL *) (mfxSession)) pFunc) (session);
if (MFX_ERR_NONE == mfxRes)
{
session = (mfxSession) 0;
}
DISPATCHER_LOG_INFO((("MFXClose(0x%x) returned %d\n"), session, mfxRes));
// actually, the return value is required to pass outside only.
}
// it is possible, that there is an active child session.
// can't unload library in that case.
if ((MFX_ERR_UNDEFINED_BEHAVIOR != mfxRes) &&
(hModule))
{
// unload the library.
if (!MFX::mfx_dll_free(hModule))
{
mfxRes = MFX_ERR_UNDEFINED_BEHAVIOR;
}
hModule = (mfxModuleHandle) 0;
}
return mfxRes;
} // 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)
{
mfxInitParam initPar;
memset(&initPar, 0, sizeof(initPar));
initPar.Version.Major = 1;
initPar.Version.Minor = 0;
switch (adapter_n)
{
case 0:
initPar.Implementation = MFX_IMPL_HARDWARE;
break;
case 1:
initPar.Implementation = MFX_IMPL_HARDWARE2;
break;
case 2:
initPar.Implementation = MFX_IMPL_HARDWARE3;
break;
case 3:
initPar.Implementation = MFX_IMPL_HARDWARE4;
break;
default:
// try searching on all display adapters
initPar.Implementation = MFX_IMPL_HARDWARE_ANY;
break;
}
initPar.Implementation |= MFX_IMPL_VIA_D3D11;
return dummy_session.InitEx(initPar);
}
static inline bool is_iGPU(const mfxAdapterInfo& adapter_info)
{
return adapter_info.Platform.MediaAdapterType == MFX_MEDIA_INTEGRATED;
}
static inline bool is_dGPU(const mfxAdapterInfo& adapter_info)
{
return adapter_info.Platform.MediaAdapterType == MFX_MEDIA_DISCRETE;
}
// This function implies that iGPU has higher priority
static inline mfxI32 iGPU_priority(const void* ll, const void* rr)
{
const mfxAdapterInfo& l = *(reinterpret_cast<const mfxAdapterInfo*>(ll));
const mfxAdapterInfo& r = *(reinterpret_cast<const mfxAdapterInfo*>(rr));
if (is_iGPU(l) && is_iGPU(r) || is_dGPU(l) && is_dGPU(r))
return 0;
if (is_iGPU(l) && is_dGPU(r))
return -1;
// The only combination left is_dGPU(l) && is_iGPU(r))
return 1;
}
static void RearrangeInPriorityOrder(const mfxComponentInfo & info, MFX::MFXVector<mfxAdapterInfo> & vec)
{
(void)info;
{
// Move iGPU to top priority
qsort(vec.data(), vec.size(), sizeof(mfxAdapterInfo), &iGPU_priority);
}
}
static mfxStatus PrepareAdaptersInfo(const mfxComponentInfo * info, MFX::MFXVector<mfxAdapterInfo> & vec, mfxAdaptersInfo& adapters)
{
// No suitable adapters on system to handle user's workload
if (vec.empty())
{
adapters.NumActual = 0;
return MFX_ERR_NOT_FOUND;
}
if (info)
{
RearrangeInPriorityOrder(*info, vec);
}
mfxU32 num_to_copy = (std::min)(mfxU32(vec.size()), adapters.NumAlloc);
for (mfxU32 i = 0; i < num_to_copy; ++i)
{
adapters.Adapters[i] = vec[i];
}
adapters.NumActual = num_to_copy;
if (vec.size() > adapters.NumAlloc)
{
return MFX_WRN_OUT_OF_RANGE;
}
return MFX_ERR_NONE;
}
static inline bool QueryAdapterInfo(mfxU32 adapter_n, mfxU32& VendorID, mfxU32& DeviceID)
{
MFX::DXVA2Device dxvaDevice;
if (!dxvaDevice.InitDXGI1(adapter_n))
return false;
VendorID = dxvaDevice.GetVendorID();
DeviceID = dxvaDevice.GetDeviceID();
return true;
}
static inline mfxU32 MakeVersion(mfxU16 major, mfxU16 minor)
{
return major * 1000 + minor;
}
mfxStatus MFXQueryAdaptersDecode(mfxBitstream* bitstream, mfxU32 codec_id, mfxAdaptersInfo* adapters)
{
if (!adapters || !bitstream)
return MFX_ERR_NULL_PTR;
MFX::MFXVector<mfxAdapterInfo> obtained_info;
mfxU32 adapter_n = 0, VendorID, DeviceID;
mfxComponentInfo input_info;
memset(&input_info, 0, sizeof(input_info));
input_info.Type = mfxComponentType::MFX_COMPONENT_DECODE;
input_info.Requirements.mfx.CodecId = codec_id;
for(;;)
{
if (!QueryAdapterInfo(adapter_n, VendorID, DeviceID))
break;
++adapter_n;
if (VendorID != INTEL_VENDOR_ID)
continue;
// Check if requested capabilities are supported
MFXVideoSession dummy_session;
mfxStatus sts = InitDummySession(adapter_n - 1, dummy_session);
if (sts != MFX_ERR_NONE)
{
continue;
}
mfxVideoParam stream_params, out;
memset(&out, 0, sizeof(out));
memset(&stream_params, 0, sizeof(stream_params));
out.mfx.CodecId = stream_params.mfx.CodecId = codec_id;
sts = MFXVideoDECODE_DecodeHeader(dummy_session.operator mfxSession(), bitstream, &stream_params);
if (sts != MFX_ERR_NONE)
{
continue;
}
sts = MFXVideoDECODE_Query(dummy_session.operator mfxSession(), &stream_params, &out);
if (sts != MFX_ERR_NONE) // skip MFX_ERR_UNSUPPORTED as well as MFX_WRN_INCOMPATIBLE_VIDEO_PARAM
continue;
mfxAdapterInfo info;
memset(&info, 0, sizeof(info));
//WA for initialization when application built w/ new API, but lib w/ old one.
mfxVersion apiVersion;
sts = dummy_session.QueryVersion(&apiVersion);
if (sts != MFX_ERR_NONE)
continue;
mfxU32 version = MakeVersion(apiVersion.Major, apiVersion.Minor);
if (version >= 1019)
{
sts = MFXVideoCORE_QueryPlatform(dummy_session.operator mfxSession(), &info.Platform);
if (sts != MFX_ERR_NONE)
{
continue;
}
}
else
{
// for API versions greater than 1.19 Device id is set inside QueryPlatform call
info.Platform.DeviceId = static_cast<mfxU16>(DeviceID);
}
info.Number = adapter_n - 1;
obtained_info.push_back(info);
}
return PrepareAdaptersInfo(&input_info, obtained_info, *adapters);
}
mfxStatus MFXQueryAdapters(mfxComponentInfo* input_info, mfxAdaptersInfo* adapters)
{
if (!adapters)
return MFX_ERR_NULL_PTR;
MFX::MFXVector<mfxAdapterInfo> obtained_info;
//obtained_info.reserve(adapters->NumAdaptersAlloc);
mfxU32 adapter_n = 0, VendorID, DeviceID;
for (;;)
{
if (!QueryAdapterInfo(adapter_n, VendorID, DeviceID))
break;
++adapter_n;
if (VendorID != INTEL_VENDOR_ID)
continue;
// Check if requested capabilities are supported
MFXVideoSession dummy_session;
mfxStatus sts = InitDummySession(adapter_n - 1, dummy_session);
if (sts != MFX_ERR_NONE)
{
continue;
}
// If input_info is NULL just return all Intel adapters and information about them
if (input_info)
{
mfxVideoParam out;
memset(&out, 0, sizeof(out));
switch (input_info->Type)
{
case mfxComponentType::MFX_COMPONENT_ENCODE:
{
out.mfx.CodecId = input_info->Requirements.mfx.CodecId;
sts = MFXVideoENCODE_Query(dummy_session.operator mfxSession(), &input_info->Requirements, &out);
}
break;
case mfxComponentType::MFX_COMPONENT_DECODE:
{
out.mfx.CodecId = input_info->Requirements.mfx.CodecId;
sts = MFXVideoDECODE_Query(dummy_session.operator mfxSession(), &input_info->Requirements, &out);
}
break;
case mfxComponentType::MFX_COMPONENT_VPP:
{
sts = MFXVideoVPP_Query(dummy_session.operator mfxSession(), &input_info->Requirements, &out);
}
break;
default:
sts = MFX_ERR_UNSUPPORTED;
}
}
if (sts != MFX_ERR_NONE) // skip MFX_ERR_UNSUPPORTED as well as MFX_WRN_INCOMPATIBLE_VIDEO_PARAM
continue;
mfxAdapterInfo info;
memset(&info, 0, sizeof(info));
//WA for initialization when application built w/ new API, but lib w/ old one.
mfxVersion apiVersion;
sts = dummy_session.QueryVersion(&apiVersion);
if (sts != MFX_ERR_NONE)
continue;
mfxU32 version = MakeVersion(apiVersion.Major, apiVersion.Minor);
if (version >= 1019)
{
sts = MFXVideoCORE_QueryPlatform(dummy_session.operator mfxSession(), &info.Platform);
if (sts != MFX_ERR_NONE)
{
continue;
}
}
else
{
// for API versions greater than 1.19 Device id is set inside QueryPlatform call
info.Platform.DeviceId = static_cast<mfxU16>(DeviceID);
}
info.Number = adapter_n - 1;
obtained_info.push_back(info);
}
return PrepareAdaptersInfo(input_info, obtained_info, *adapters);
}
mfxStatus MFXQueryAdaptersNumber(mfxU32* num_adapters)
{
if (!num_adapters)
return MFX_ERR_NULL_PTR;
mfxU32 intel_adapter_count = 0, VendorID, DeviceID;
for (mfxU32 cur_adapter = 0; ; ++cur_adapter)
{
if (!QueryAdapterInfo(cur_adapter, VendorID, DeviceID))
break;
if (VendorID == INTEL_VENDOR_ID)
++intel_adapter_count;
}
*num_adapters = intel_adapter_count;
return MFX_ERR_NONE;
}
#endif // (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031)

View File

@@ -0,0 +1,446 @@
// Copyright (c) 2012-2019 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_DISPATCHER_LOG)
#include "mfx_dispatcher_log.h"
#include "mfxstructures.h"
#include <windows.h>
#if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER)
#include <evntprov.h>
#include <winmeta.h>
#endif
#include <stdarg.h>
#include <algorithm>
#include <string>
#include <sstream>
struct CodeStringTable
{
int code;
const char *string;
} LevelStrings []=
{
{DL_INFO, "INFO: "},
{DL_WRN, "WARNING:"},
{DL_ERROR, "ERROR: "}
};
#define DEFINE_CODE(code)\
{code, #code}
static CodeStringTable StringsOfImpl[] = {
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_UNSUPPORTED)
};
static CodeStringTable StringsOfImplVIA[] = {
DEFINE_CODE(MFX_IMPL_VIA_ANY),
DEFINE_CODE(MFX_IMPL_VIA_D3D9),
DEFINE_CODE(MFX_IMPL_VIA_D3D11),
};
static CodeStringTable StringsOfStatus[] =
{
DEFINE_CODE(MFX_ERR_NONE ),
DEFINE_CODE(MFX_ERR_UNKNOWN ),
DEFINE_CODE(MFX_ERR_NULL_PTR ),
DEFINE_CODE(MFX_ERR_UNSUPPORTED ),
DEFINE_CODE(MFX_ERR_MEMORY_ALLOC ),
DEFINE_CODE(MFX_ERR_NOT_ENOUGH_BUFFER ),
DEFINE_CODE(MFX_ERR_INVALID_HANDLE ),
DEFINE_CODE(MFX_ERR_LOCK_MEMORY ),
DEFINE_CODE(MFX_ERR_NOT_INITIALIZED ),
DEFINE_CODE(MFX_ERR_NOT_FOUND ),
DEFINE_CODE(MFX_ERR_MORE_DATA ),
DEFINE_CODE(MFX_ERR_MORE_SURFACE ),
DEFINE_CODE(MFX_ERR_ABORTED ),
DEFINE_CODE(MFX_ERR_DEVICE_LOST ),
DEFINE_CODE(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM),
DEFINE_CODE(MFX_ERR_INVALID_VIDEO_PARAM ),
DEFINE_CODE(MFX_ERR_UNDEFINED_BEHAVIOR ),
DEFINE_CODE(MFX_ERR_DEVICE_FAILED ),
DEFINE_CODE(MFX_ERR_MORE_BITSTREAM ),
DEFINE_CODE(MFX_ERR_INVALID_AUDIO_PARAM ),
DEFINE_CODE(MFX_ERR_GPU_HANG ),
DEFINE_CODE(MFX_ERR_REALLOC_SURFACE ),
DEFINE_CODE(MFX_WRN_IN_EXECUTION ),
DEFINE_CODE(MFX_WRN_DEVICE_BUSY ),
DEFINE_CODE(MFX_WRN_VIDEO_PARAM_CHANGED ),
DEFINE_CODE(MFX_WRN_PARTIAL_ACCELERATION ),
DEFINE_CODE(MFX_WRN_INCOMPATIBLE_VIDEO_PARAM),
DEFINE_CODE(MFX_WRN_VALUE_NOT_CHANGED ),
DEFINE_CODE(MFX_WRN_OUT_OF_RANGE ),
DEFINE_CODE(MFX_WRN_FILTER_SKIPPED ),
DEFINE_CODE(MFX_WRN_INCOMPATIBLE_AUDIO_PARAM),
DEFINE_CODE(MFX_ERR_NONE_PARTIAL_OUTPUT ),
DEFINE_CODE(MFX_TASK_WORKING ),
DEFINE_CODE(MFX_TASK_BUSY ),
DEFINE_CODE(MFX_ERR_MORE_DATA_SUBMIT_TASK ),
};
#define CODE_TO_STRING(code, array)\
CodeToString(code, array, sizeof(array)/sizeof(array[0]))
const char* CodeToString(int code, CodeStringTable array[], int len )
{
for (int i = 0 ; i < len; i++)
{
if (array[i].code == code)
return array[i].string;
}
return "undef";
}
std::string DispatcherLog_GetMFXImplString(int impl)
{
std::string str1 = CODE_TO_STRING(impl & ~(-MFX_IMPL_VIA_ANY), StringsOfImpl);
std::string str2 = CODE_TO_STRING(impl & (-MFX_IMPL_VIA_ANY), StringsOfImplVIA);
return str1 + (str2 == "undef" ? "" : "|"+str2);
}
const char *DispatcherLog_GetMFXStatusString(int sts)
{
return CODE_TO_STRING(sts, StringsOfStatus);
}
//////////////////////////////////////////////////////////////////////////
void DispatcherLogBracketsHelper::Write(const char * str, ...)
{
va_list argsptr;
va_start(argsptr, str);
DispatchLog::get().Write(m_level, m_opcode, str, argsptr);
va_end(argsptr);
}
void DispatchLogBlockHelper::Write(const char * str, ...)
{
va_list argsptr;
va_start(argsptr, str);
DispatchLog::get().Write(m_level, DL_EVENT_START, str, argsptr);
va_end(argsptr);
}
DispatchLogBlockHelper::~DispatchLogBlockHelper()
{
DispatchLog::get().Write(m_level, DL_EVENT_STOP, NULL, NULL);
}
//////////////////////////////////////////////////////////////////////////
DispatchLog::DispatchLog()
: m_DispatcherLogSink(DL_SINK_PRINTF)
{
}
void DispatchLog::SetSink(int nSink, IMsgHandler * pHandler)
{
DetachAllSinks();
AttachSink(nSink, pHandler);
}
void DispatchLog::AttachSink(int nsink, IMsgHandler *pHandler)
{
m_DispatcherLogSink |= nsink;
if (NULL != pHandler)
m_Recepients.push_back(pHandler);
}
void DispatchLog::DetachSink(int nsink, IMsgHandler *pHandler)
{
if (nsink & DL_SINK_IMsgHandler)
{
m_Recepients.remove(pHandler);
}
m_DispatcherLogSink &= ~nsink;
}
void DispatchLog::ExchangeSink(int nsink, IMsgHandler *oldHdl, IMsgHandler *newHdl)
{
if (nsink & DL_SINK_IMsgHandler)
{
std::list<IMsgHandler*> :: iterator it = std::find(m_Recepients.begin(), m_Recepients.end(), oldHdl);
//cannot exchange in that case
if (m_Recepients.end() == it)
return;
*it = newHdl;
}
}
void DispatchLog::DetachAllSinks()
{
m_Recepients.clear();
m_DispatcherLogSink = DL_SINK_NULL;
}
void DispatchLog::Write(int level, int opcode, const char * msg, va_list argptr)
{
int sinkTable[] =
{
DL_SINK_PRINTF,
DL_SINK_IMsgHandler,
};
for (size_t i = 0; i < sizeof(sinkTable) / sizeof(sinkTable[0]); i++)
{
switch(m_DispatcherLogSink & sinkTable[i])
{
case DL_SINK_NULL:
break;
case DL_SINK_PRINTF:
{
char msg_formated[8048] = {0};
if (NULL != msg && level != DL_LOADED_LIBRARY)
{
#if _MSC_VER >= 1400
vsprintf_s(msg_formated, sizeof(msg_formated)/sizeof(msg_formated[0]), msg, argptr);
#else
vsnprintf(msg_formated, sizeof(msg_formated)/sizeof(msg_formated[0]), msg, argptr);
#endif
//TODO: improve this , add opcode handling
printf("%s %s", CODE_TO_STRING(level, LevelStrings), msg_formated);
}
break;
}
case DL_SINK_IMsgHandler:
{
std::list<IMsgHandler*>::iterator it;
for (it = m_Recepients.begin(); it != m_Recepients.end(); ++it)
{
(*it)->Write(level, opcode, msg, argptr);
}
break;
}
}
}
}
#if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER)
class ETWHandler : public IMsgHandler
{
public:
ETWHandler(const wchar_t * guid_str)
: m_bUseFormatter(DISPATCHER_LOG_USE_FORMATING)
, m_EventHandle()
, m_bProviderEnable()
{
GUID rguid = GUID_NULL;
if (FAILED(CLSIDFromString(guid_str, &rguid)))
{
return;
}
EventRegister(&rguid, NULL, NULL, &m_EventHandle);
m_bProviderEnable = 0 != EventProviderEnabled(m_EventHandle, 1,0);
}
~ETWHandler()
{
if (m_EventHandle)
{
EventUnregister(m_EventHandle);
}
}
virtual void Write(int level, int opcode, const char * msg, va_list argptr)
{
//event not registered
if (0==m_EventHandle)
{
return;
}
if (!m_bProviderEnable)
{
return;
}
if (level == DL_LOADED_LIBRARY)
{
return;
}
char msg_formated[1024];
EVENT_DESCRIPTOR descriptor;
EVENT_DATA_DESCRIPTOR data_descriptor;
EventDescZero(&descriptor);
descriptor.Opcode = (UCHAR)opcode;
descriptor.Level = (UCHAR)level;
if (m_bUseFormatter)
{
if (NULL != msg)
{
#if _MSC_VER >= 1400
vsprintf_s(msg_formated, sizeof (msg_formated) / sizeof (msg_formated[0]), msg, argptr);
#else
vsnprintf(msg_formated, sizeof (msg_formated) / sizeof (msg_formated[0]), msg, argptr);
#endif
EventDataDescCreate(&data_descriptor, msg_formated, (ULONG)(strlen(msg_formated) + 1));
}else
{
EventDataDescCreate(&data_descriptor, NULL, 0);
}
}else
{
//TODO: non formated events supports under zbb
}
EventWrite(m_EventHandle, &descriptor, 1, &data_descriptor);
}
protected:
//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
//submits event only if consumer attached
bool m_bProviderEnable;
REGHANDLE m_EventHandle;
};
//
IMsgHandler *ETWHandlerFactory::GetSink(const wchar_t* sguid)
{
_storage_type::iterator it;
it = m_storage.find(sguid);
if (it == m_storage.end())
{
ETWHandler * handler = new ETWHandler(sguid);
_storage_type::_Pairib it_bool = m_storage.insert(_storage_type::value_type(sguid, handler));
it = it_bool.first;
}
return it->second;
}
ETWHandlerFactory::~ETWHandlerFactory()
{
for each(_storage_type::value_type val in m_storage)
{
delete val.second;
}
}
class EventRegistrator : public IMsgHandler
{
const wchar_t * m_sguid;
public:
EventRegistrator(const wchar_t* sguid = DISPATCHER_LOG_EVENT_GUID)
:m_sguid(sguid)
{
DispatchLog::get().AttachSink( DL_SINK_IMsgHandler
, this);
}
virtual void Write(int level, int opcode, const char * msg, va_list argptr)
{
//we cannot call attach sink since we may have been called from iteration
//we axchanging preserve that placeholding
IMsgHandler * pSink = NULL;
DispatchLog::get().ExchangeSink(DL_SINK_IMsgHandler,
this,
pSink = ETWHandlerFactory::get().GetSink(m_sguid));
//need to call only once here all next calls will be done inside dispatcherlog
if (NULL != pSink)
{
pSink->Write(level, opcode, msg, argptr);
}
}
};
#endif
template <class TSink>
class SinkRegistrator
{
};
#if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER)
template <>
class SinkRegistrator<ETWHandlerFactory>
{
public:
SinkRegistrator(const wchar_t* sguid = DISPATCHER_LOG_EVENT_GUID)
{
DispatchLog::get().AttachSink( DL_SINK_IMsgHandler
, ETWHandlerFactory::get().GetSink(sguid));
}
};
#endif
#if defined(DISPATCHER_LOG_REGISTER_FILE_WRITER)
template <>
class SinkRegistrator<FileSink>
{
public:
SinkRegistrator()
{
DispatchLog::get().AttachSink( DL_SINK_IMsgHandler, &FileSink::get(DISPACTHER_LOG_FW_PATH));
}
};
void FileSink::Write(int level, int /*opcode*/, const char * msg, va_list argptr)
{
if (NULL != m_hdl && NULL != msg)
{
fprintf(m_hdl, "%s", CODE_TO_STRING(level, LevelStrings));
vfprintf(m_hdl, msg, argptr);
}
}
#endif
//////////////////////////////////////////////////////////////////////////
//singletons initialization section
#ifdef DISPATCHER_LOG_REGISTER_EVENT_PROVIDER
static SinkRegistrator<ETWHandlerFactory> g_registrator1;
#endif
#ifdef DISPATCHER_LOG_REGISTER_FILE_WRITER
static SinkRegistrator<FileSink> g_registrator2;
#endif
#endif//(MFX_DISPATCHER_LOG)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,288 @@
// Copyright (c) 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 "mfx_dispatcher.h"
#include "mfx_dispatcher_uwp.h"
#include "mfx_driver_store_loader.h"
#include "mfx_dxva2_device.h"
#include "mfx_load_dll.h"
mfxStatus GfxApiInit(mfxInitParam par, mfxU32 deviceID, mfxSession *session, mfxModuleHandle& hModule)
{
HRESULT hr = S_OK;
if (hModule == NULL)
{
wchar_t IntelGFXAPIdllName[MFX_MAX_DLL_PATH] = { 0 };
MFX::DriverStoreLoader dsLoader;
if (!dsLoader.GetDriverStorePath(IntelGFXAPIdllName, sizeof(IntelGFXAPIdllName), deviceID))
{
return MFX_ERR_UNSUPPORTED;
}
size_t pathLen = wcslen(IntelGFXAPIdllName);
MFX::mfx_get_default_intel_gfx_api_dll_name(IntelGFXAPIdllName + pathLen, sizeof(IntelGFXAPIdllName) / sizeof(IntelGFXAPIdllName[0]) - pathLen);
DISPATCHER_LOG_INFO((("loading %S\n"), IntelGFXAPIdllName));
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::mfx_dll_get_addr(hModule, "InitialiseMediaSession");
if (!pFunc)
{
DISPATCHER_LOG_ERROR("Can't find required API function: InitialiseMediaSession\n");
MFX::mfx_dll_free(hModule);
return MFX_ERR_UNSUPPORTED;
}
typedef HRESULT(APIENTRY *InitialiseMediaSessionPtr) (HANDLE*, LPVOID, LPVOID);
InitialiseMediaSessionPtr init = (InitialiseMediaSessionPtr)pFunc;
hr = init((HANDLE*)session, &par, NULL);
return (hr == S_OK) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
}
mfxStatus GfxApiClose(mfxSession& session, mfxModuleHandle& hModule)
{
HRESULT hr = S_OK;
if (!hModule)
{
return MFX_ERR_NULL_PTR;
}
mfxFunctionPointer pFunc = (mfxFunctionPointer)MFX::mfx_dll_get_addr(hModule, "DisposeMediaSession");
if (!pFunc)
{
DISPATCHER_LOG_ERROR("Can't find required API function: DisposeMediaSession\n");
return MFX_ERR_INVALID_HANDLE;
}
typedef HRESULT(APIENTRY *DisposeMediaSessionPtr) (HANDLE);
DisposeMediaSessionPtr dispose = (DisposeMediaSessionPtr)pFunc;
hr = dispose((HANDLE)session);
session = NULL;
MFX::mfx_dll_free(hModule);
hModule = NULL;
return (hr == S_OK) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
}
mfxStatus GfxApiInitByAdapterNum(mfxInitParam par, mfxU32 adapterNum, mfxSession *session, mfxModuleHandle& hModule)
{
MFX::DXVA2Device dxvaDevice;
if (!dxvaDevice.InitDXGI1(adapterNum))
{
DISPATCHER_LOG_ERROR((("dxvaDevice.InitDXGI1(%d) Failed\n"), adapterNum));
return MFX_ERR_UNSUPPORTED;
}
if (dxvaDevice.GetVendorID() != INTEL_VENDOR_ID)
{
DISPATCHER_LOG_ERROR("Specified adapter is not Intel\n");
return MFX_ERR_UNSUPPORTED;
}
return GfxApiInit(par, dxvaDevice.GetDeviceID(), session, hModule);
}
struct GfxApiHandle
{
mfxModuleHandle hModule;
mfxSession session;
mfxU16 mediaAdapterType;
};
static int GfxApiHandleSort(const void * plhs, const void * prhs)
{
const GfxApiHandle * lhs = *(const GfxApiHandle **)plhs;
const GfxApiHandle * rhs = *(const GfxApiHandle **)prhs;
// 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;
}
return 0;
}
mfxStatus GfxApiInitPriorityIntegrated(mfxInitParam par, mfxSession *session, mfxModuleHandle& hModule)
{
mfxStatus sts = MFX_ERR_UNSUPPORTED;
MFX::MFXVector<GfxApiHandle> gfxApiHandles;
for (int adapterNum = 0; adapterNum < 4; ++adapterNum)
{
MFX::DXVA2Device dxvaDevice;
if (!dxvaDevice.InitDXGI1(adapterNum) || dxvaDevice.GetVendorID() != INTEL_VENDOR_ID)
{
continue;
}
par.Implementation &= ~(0xf);
switch (adapterNum)
{
case 0:
par.Implementation |= MFX_IMPL_HARDWARE;
break;
case 1:
par.Implementation |= MFX_IMPL_HARDWARE2;
break;
case 2:
par.Implementation |= MFX_IMPL_HARDWARE3;
break;
case 3:
par.Implementation |= MFX_IMPL_HARDWARE4;
break;
}
mfxModuleHandle hModuleCur = NULL;
mfxSession sessionCur = NULL;
sts = GfxApiInit(par, dxvaDevice.GetDeviceID(), &sessionCur, hModuleCur);
if (sts != MFX_ERR_NONE)
continue;
mfxPlatform platform = { MFX_PLATFORM_UNKNOWN, 0, MFX_MEDIA_UNKNOWN };
sts = MFXVideoCORE_QueryPlatform(sessionCur, &platform);
if (sts != MFX_ERR_NONE)
{
sts = GfxApiClose(sessionCur, hModuleCur);
if (sts != MFX_ERR_NONE)
return sts;
continue;
}
GfxApiHandle handle = { hModuleCur, sessionCur, platform.MediaAdapterType };
gfxApiHandles.push_back(handle);
}
//Try to use fallback from System folder
mfxModuleHandle hFallback = NULL;
if (gfxApiHandles.size() == 0)
{
wchar_t IntelGFXAPIdllName[MFX_MAX_DLL_PATH] = { 0 };
MFX::mfx_get_default_intel_gfx_api_dll_name(IntelGFXAPIdllName, sizeof(IntelGFXAPIdllName) / sizeof(IntelGFXAPIdllName[0]));
DISPATCHER_LOG_INFO((("loading fallback %S\n"), IntelGFXAPIdllName));
hFallback = MFX::mfx_dll_load(IntelGFXAPIdllName);
if (!hFallback)
{
DISPATCHER_LOG_ERROR("Can't load intel_gfx_api\n");
return MFX_ERR_UNSUPPORTED;
}
for (int adapterNum = 0; adapterNum < 4; ++adapterNum)
{
MFX::DXVA2Device dxvaDevice;
if (!dxvaDevice.InitDXGI1(adapterNum) || dxvaDevice.GetVendorID() != INTEL_VENDOR_ID)
{
continue;
}
par.Implementation &= ~(0xf);
switch (adapterNum)
{
case 0:
par.Implementation |= MFX_IMPL_HARDWARE;
break;
case 1:
par.Implementation |= MFX_IMPL_HARDWARE2;
break;
case 2:
par.Implementation |= MFX_IMPL_HARDWARE3;
break;
case 3:
par.Implementation |= MFX_IMPL_HARDWARE4;
break;
}
mfxSession sessionCur = NULL;
sts = GfxApiInit(par, dxvaDevice.GetDeviceID(), &sessionCur, hFallback);
if (sts != MFX_ERR_NONE)
continue;
mfxPlatform platform = { MFX_PLATFORM_UNKNOWN, 0, MFX_MEDIA_UNKNOWN };
sts = MFXVideoCORE_QueryPlatform(sessionCur, &platform);
if (sts != MFX_ERR_NONE)
{
continue;
}
GfxApiHandle handle = { NULL, sessionCur, platform.MediaAdapterType };
gfxApiHandles.push_back(handle);
}
}
if (gfxApiHandles.size() == 0)
{
if (hFallback != NULL)
{
MFX::mfx_dll_free(hFallback);
hFallback = NULL;
}
return MFX_ERR_UNSUPPORTED;
}
qsort(&(*gfxApiHandles.begin()), gfxApiHandles.size(), sizeof(GfxApiHandle), &GfxApiHandleSort);
// When hModule == NULL and hFallback != NULL - it means dispatcher uses fallback library from System folder
hModule = ( gfxApiHandles.begin()->hModule == NULL && hFallback != NULL )? hFallback : gfxApiHandles.begin()->hModule;
*session = gfxApiHandles.begin()->session;
MFX::MFXVector<GfxApiHandle>::iterator it = gfxApiHandles.begin()++;
for (; it != gfxApiHandles.end(); ++it)
{
sts = GfxApiClose(it->session, it->hModule);
if (sts == MFX_ERR_NULL_PTR)
continue;
if (sts != MFX_ERR_NONE)
return sts;
}
//If dispatcher has tried a fallback, but returns something else - free loaded fallback
if (hFallback != NULL && hModule != hFallback)
{
MFX::mfx_dll_free(hFallback);
hFallback = NULL;
}
return sts;
}

View File

@@ -0,0 +1,225 @@
// 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 <tchar.h>
#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;
}
inline bool GetGuidString(const GUID guid, wchar_t * string, size_t size)
{
return swprintf_s(string, size,
L"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}
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<WCHAR> DeviceIDList;
wchar_t DisplayGUID[40];
DEVINST DeviceInst;
DISPATCHER_LOG_INFO(("Looking for MediaSDK in DriverStore\n"));
if (!LoadCfgMgr() || !LoadCmFuncs())
{
return false;
}
if (!GetGuidString(GUID_DEVCLASS_DISPLAY, DisplayGUID, sizeof(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 = RegGetValueW(hKey_sw, NULL, L"DriverStorePathForMediaSDK", RRF_RT_REG_SZ, NULL, (LPBYTE)path, &pathSize);
RegCloseKey(hKey_sw);
if (ERROR_SUCCESS == nError)
{
if (path[wcslen(path) - 1] != '/' && path[wcslen(path) - 1] != '\\')
{
wcscat_s(path, dwPathSize / sizeof(path[0]), 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

View File

@@ -0,0 +1,568 @@
// Copyright (c) 2012-2019 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.
#define INITGUID
#include <d3d9.h>
#include <dxgi.h>
#include "mfx_dxva2_device.h"
using namespace MFX;
DXDevice::DXDevice(void)
{
m_hModule = (HMODULE) 0;
m_numAdapters = 0;
m_vendorID = 0;
m_deviceID = 0;
m_driverVersion = 0;
m_luid = 0;
} // DXDevice::DXDevice(void)
DXDevice::~DXDevice(void)
{
Close();
// free DX library only when device is destroyed
UnloadDLLModule();
} // DXDevice::~DXDevice(void)
mfxU32 DXDevice::GetVendorID(void) const
{
return m_vendorID;
} // mfxU32 DXDevice::GetVendorID(void) const
mfxU32 DXDevice::GetDeviceID(void) const
{
return m_deviceID;
} // mfxU32 DXDevice::GetDeviceID(void) const
mfxU64 DXDevice::GetDriverVersion(void) const
{
return m_driverVersion;
}// mfxU64 DXDevice::GetDriverVersion(void) const
mfxU64 DXDevice::GetLUID(void) const
{
return m_luid;
} // mfxU64 DXDevice::GetLUID(void) const
mfxU32 DXDevice::GetAdapterCount(void) const
{
return m_numAdapters;
} // mfxU32 DXDevice::GetAdapterCount(void) const
void DXDevice::Close(void)
{
m_numAdapters = 0;
m_vendorID = 0;
m_deviceID = 0;
m_luid = 0;
} // void DXDevice::Close(void)
void DXDevice::LoadDLLModule(const wchar_t *pModuleName)
{
// unload the module if it is required
UnloadDLLModule();
#if !defined(MEDIASDK_UWP_DISPATCHER)
DWORD prevErrorMode = 0;
// set the silent error mode
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode);
#else
prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
#endif // !defined(MEDIASDK_UWP_DISPATCHER)
// load specified library
m_hModule = LoadLibraryExW(pModuleName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS);
#if !defined(MEDIASDK_UWP_DISPATCHER)
// set the previous error mode
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(prevErrorMode, NULL);
#else
SetErrorMode(prevErrorMode);
#endif
#endif // !defined(MEDIASDK_UWP_DISPATCHER)
} // void LoadDLLModule(const wchar_t *pModuleName)
void DXDevice::UnloadDLLModule(void)
{
if (m_hModule)
{
FreeLibrary(m_hModule);
m_hModule = (HMODULE) 0;
}
} // void DXDevice::UnloaDLLdModule(void)
#ifdef MFX_D3D9_ENABLED
D3D9Device::D3D9Device(void)
{
m_pD3D9 = (void *) 0;
m_pD3D9Ex = (void *) 0;
} // D3D9Device::D3D9Device(void)
D3D9Device::~D3D9Device(void)
{
Close();
} // D3D9Device::~D3D9Device(void)
void D3D9Device::Close(void)
{
// release the interfaces
if (m_pD3D9Ex)
{
((IDirect3D9Ex *) m_pD3D9Ex)->Release();
}
// release the interfaces
if (m_pD3D9)
{
((IDirect3D9 *) m_pD3D9)->Release();
}
m_pD3D9 = (void *) 0;
m_pD3D9Ex = (void *) 0;
} // void D3D9Device::Close(void)
typedef
IDirect3D9 * (WINAPI *D3DCreateFunctionPtr_t) (UINT);
typedef
HRESULT (WINAPI *D3DExCreateFunctionPtr_t) (UINT, IDirect3D9Ex **);
bool D3D9Device::Init(const mfxU32 adapterNum)
{
// close the device before initialization
Close();
// load the library
if (NULL == m_hModule)
{
LoadDLLModule(L"d3d9.dll");
}
if (m_hModule)
{
D3DCreateFunctionPtr_t pFunc;
// load address of procedure to create D3D device
pFunc = (D3DCreateFunctionPtr_t) GetProcAddress(m_hModule, "Direct3DCreate9");
if (pFunc)
{
D3DADAPTER_IDENTIFIER9 adapterIdent;
IDirect3D9 *pD3D9;
HRESULT hRes;
// create D3D object
m_pD3D9 = pFunc(D3D_SDK_VERSION);
if (NULL == m_pD3D9)
{
DXVA2DEVICE_TRACE(("FAIL: Direct3DCreate9(%d) : GetLastError()=0x%x", D3D_SDK_VERSION, GetLastError()));
return false;
}
// cast the interface
pD3D9 = (IDirect3D9 *) m_pD3D9;
m_numAdapters = pD3D9->GetAdapterCount();
if (adapterNum >= m_numAdapters)
{
return false;
}
// get the card's parameters
hRes = pD3D9->GetAdapterIdentifier(adapterNum, 0, &adapterIdent);
if (D3D_OK != hRes)
{
DXVA2DEVICE_TRACE(("FAIL: GetAdapterIdentifier(%d) = 0x%x \n", adapterNum, hRes));
return false;
}
m_vendorID = adapterIdent.VendorId;
m_deviceID = adapterIdent.DeviceId;
m_driverVersion = (mfxU64)adapterIdent.DriverVersion.QuadPart;
// load LUID
IDirect3D9Ex *pD3D9Ex;
D3DExCreateFunctionPtr_t pFuncEx;
LUID d3d9LUID;
// find the appropriate function
pFuncEx = (D3DExCreateFunctionPtr_t) GetProcAddress(m_hModule, "Direct3DCreate9Ex");
if (NULL == pFuncEx)
{
// the extended interface is not supported
return true;
}
// create extended interface
hRes = pFuncEx(D3D_SDK_VERSION, &pD3D9Ex);
if (FAILED(hRes))
{
// can't create extended interface
return true;
}
m_pD3D9Ex = pD3D9Ex;
// obtain D3D9 device LUID
hRes = pD3D9Ex->GetAdapterLUID(adapterNum, &d3d9LUID);
if (FAILED(hRes))
{
// can't get LUID
return true;
}
// copy the LUID
*((LUID *) &m_luid) = d3d9LUID;
}
else
{
DXVA2DEVICE_TRACE_OPERATION({
wchar_t path[1024];
DWORD lastErr = GetLastError();
GetModuleFileNameW(m_hModule, path, sizeof(path)/sizeof(path[0]));
DXVA2DEVICE_TRACE(("FAIL: invoking GetProcAddress(Direct3DCreate9) in %S : GetLastError()==0x%x\n", path, lastErr)); });
return false;
}
}
else
{
DXVA2DEVICE_TRACE(("FAIL: invoking LoadLibrary(\"d3d9.dll\") : GetLastError()==0x%x\n", GetLastError()));
return false;
}
return true;
} // bool D3D9Device::Init(const mfxU32 adapterNum)
#endif //MFX_D3D9_ENABLED
typedef
HRESULT (WINAPI *DXGICreateFactoryFunc) (REFIID riid, void **ppFactory);
DXGI1Device::DXGI1Device(void)
{
m_pDXGIFactory1 = (void *) 0;
m_pDXGIAdapter1 = (void *) 0;
} // DXGI1Device::DXGI1Device(void)
DXGI1Device::~DXGI1Device(void)
{
Close();
} // DXGI1Device::~DXGI1Device(void)
void DXGI1Device::Close(void)
{
// release the interfaces
if (m_pDXGIAdapter1)
{
((IDXGIAdapter1 *) m_pDXGIAdapter1)->Release();
}
if (m_pDXGIFactory1)
{
((IDXGIFactory1 *) m_pDXGIFactory1)->Release();
}
m_pDXGIFactory1 = (void *) 0;
m_pDXGIAdapter1 = (void *) 0;
} // void DXGI1Device::Close(void)
bool DXGI1Device::Init(const mfxU32 adapterNum)
{
// release the object before initialization
Close();
IDXGIFactory1 *pFactory = NULL;
IDXGIAdapter1 *pAdapter = NULL;
DXGI_ADAPTER_DESC1 desc = { 0 };
mfxU32 curAdapter = 0;
mfxU32 maxAdapters = 0;
HRESULT hRes = E_FAIL;
DXGICreateFactoryFunc pFunc = NULL;
// load up the library if it is not loaded
if (NULL == m_hModule)
{
LoadDLLModule(L"dxgi.dll");
}
if (m_hModule)
{
// load address of procedure to create DXGI 1.1 factory
pFunc = (DXGICreateFactoryFunc)GetProcAddress(m_hModule, "CreateDXGIFactory1");
}
if (NULL == pFunc)
{
return false;
}
// create the factory
#if _MSC_VER >= 1400
hRes = pFunc(__uuidof(IDXGIFactory1), (void**)(&pFactory));
#else
hRes = pFunc(IID_IDXGIFactory1, (void**)(&pFactory));
#endif
if (FAILED(hRes))
{
return false;
}
m_pDXGIFactory1 = pFactory;
// get the number of adapters
curAdapter = 0;
maxAdapters = 0;
do
{
// get the required adapted
hRes = pFactory->EnumAdapters1(curAdapter, &pAdapter);
if (FAILED(hRes))
{
break;
}
// if it is the required adapter, save the interface
if (curAdapter == adapterNum)
{
m_pDXGIAdapter1 = pAdapter;
}
else
{
pAdapter->Release();
}
// get the next adapter
curAdapter += 1;
} while (SUCCEEDED(hRes));
maxAdapters = curAdapter;
// there is no required adapter
if (adapterNum >= maxAdapters)
{
return false;
}
pAdapter = (IDXGIAdapter1 *) m_pDXGIAdapter1;
// get the adapter's parameters
hRes = pAdapter->GetDesc1(&desc);
if (FAILED(hRes))
{
return false;
}
// save the parameters
m_vendorID = desc.VendorId;
m_deviceID = desc.DeviceId;
*((LUID *) &m_luid) = desc.AdapterLuid;
return true;
} // bool DXGI1Device::Init(const mfxU32 adapterNum)
DXVA2Device::DXVA2Device(void)
{
m_numAdapters = 0;
m_vendorID = 0;
m_deviceID = 0;
m_driverVersion = 0;
} // DXVA2Device::DXVA2Device(void)
DXVA2Device::~DXVA2Device(void)
{
Close();
} // DXVA2Device::~DXVA2Device(void)
void DXVA2Device::Close(void)
{
m_numAdapters = 0;
m_vendorID = 0;
m_deviceID = 0;
m_driverVersion = 0;
} // void DXVA2Device::Close(void)
#ifdef MFX_D3D9_ENABLED
bool DXVA2Device::InitD3D9(const mfxU32 adapterNum)
{
D3D9Device d3d9Device;
bool bRes;
// release the object before initialization
Close();
// create 'old fashion' device
bRes = d3d9Device.Init(adapterNum);
if (false == bRes)
{
return false;
}
m_numAdapters = d3d9Device.GetAdapterCount();
// check if the application is under Remote Desktop
if ((0 == d3d9Device.GetVendorID()) || (0 == d3d9Device.GetDeviceID()))
{
// get the required parameters alternative way and ...
UseAlternativeWay(&d3d9Device);
}
else
{
// save the parameters and ...
m_vendorID = d3d9Device.GetVendorID();
m_deviceID = d3d9Device.GetDeviceID();
m_driverVersion = d3d9Device.GetDriverVersion();
}
// ... say goodbye
return true;
} // bool InitD3D9(const mfxU32 adapterNum)
#else // MFX_D3D9_ENABLED
bool DXVA2Device::InitD3D9(const mfxU32 adapterNum)
{
(void)adapterNum;
return false;
}
#endif // MFX_D3D9_ENABLED
bool DXVA2Device::InitDXGI1(const mfxU32 adapterNum)
{
DXGI1Device dxgi1Device;
bool bRes;
// release the object before initialization
Close();
// create modern DXGI device
bRes = dxgi1Device.Init(adapterNum);
if (false == bRes)
{
return false;
}
// save the parameters and ...
m_vendorID = dxgi1Device.GetVendorID();
m_deviceID = dxgi1Device.GetDeviceID();
m_numAdapters = dxgi1Device.GetAdapterCount();
// ... say goodbye
return true;
} // bool DXVA2Device::InitDXGI1(const mfxU32 adapterNum)
#ifdef MFX_D3D9_ENABLED
void DXVA2Device::UseAlternativeWay(const D3D9Device *pD3D9Device)
{
mfxU64 d3d9LUID = pD3D9Device->GetLUID();
// work only with valid LUIDs
if (0 == d3d9LUID)
{
return;
}
DXGI1Device dxgi1Device;
mfxU32 curDevice = 0;
bool bRes = false;
do
{
// initialize the next DXGI1 or DXGI device
bRes = dxgi1Device.Init(curDevice);
if (false == bRes)
{
// there is no more devices
break;
}
// is it required device ?
if (d3d9LUID == dxgi1Device.GetLUID())
{
m_vendorID = dxgi1Device.GetVendorID();
m_deviceID = dxgi1Device.GetDeviceID();
m_driverVersion = dxgi1Device.GetDriverVersion();
return ;
}
// get the next device
curDevice += 1;
} while (bRes);
dxgi1Device.Close();
// we need to match a DXGI(1) device to the D3D9 device
} // void DXVA2Device::UseAlternativeWay(const D3D9Device *pD3D9Device)
#endif // MFX_D3D9_ENABLED
mfxU32 DXVA2Device::GetVendorID(void) const
{
return m_vendorID;
} // mfxU32 DXVA2Device::GetVendorID(void) const
mfxU32 DXVA2Device::GetDeviceID(void) const
{
return m_deviceID;
} // mfxU32 DXVA2Device::GetDeviceID(void) const
mfxU64 DXVA2Device::GetDriverVersion(void) const
{
return m_driverVersion;
}// mfxU64 DXVA2Device::GetDriverVersion(void) const
mfxU32 DXVA2Device::GetAdapterCount(void) const
{
return m_numAdapters;
} // mfxU32 DXVA2Device::GetAdapterCount(void) const

View File

@@ -0,0 +1,133 @@
// Copyright (c) 2012-2019 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 "mfx_dispatcher.h"
//
// implement a table with functions names
//
#undef FUNCTION
#define FUNCTION(return_value, func_name, formal_param_list, actual_param_list) \
{#func_name, API_VERSION},
const
FUNCTION_DESCRIPTION APIFunc[eVideoFuncTotal] =
{
{"MFXInit", {{0, 1}}},
{"MFXClose", {{0, 1}}},
{"MFXQueryIMPL", {{0, 1}}},
{"MFXQueryVersion", {{0, 1}}},
{"MFXJoinSession", {{1, 1}}},
{"MFXDisjoinSession", {{1, 1}}},
{"MFXCloneSession", {{1, 1}}},
{"MFXSetPriority", {{1, 1}}},
{"MFXGetPriority", {{1, 1}}},
{"MFXInitEx", {{1, 14}}},
#include "mfx_exposed_functions_list.h"
};
const
FUNCTION_DESCRIPTION APIAudioFunc[eAudioFuncTotal] =
{
{"MFXInit", {{8, 1}}},
{"MFXClose", {{8, 1}}},
{"MFXQueryIMPL", {{8, 1}}},
{"MFXQueryVersion", {{8, 1}}},
{"MFXJoinSession", {{8, 1}}},
{"MFXDisjoinSession", {{8, 1}}},
{"MFXCloneSession", {{8, 1}}},
{"MFXSetPriority", {{8, 1}}},
{"MFXGetPriority", {{8, 1}}},
#include "mfxaudio_exposed_functions_list.h"
};
// static section of the file
namespace
{
//
// declare pseudo-functions.
// they are used as default values for call-tables.
//
mfxStatus pseudoMFXInit(mfxIMPL impl, mfxVersion *ver, mfxSession *session)
{
// touch unreferenced parameters
(void) impl;
(void) ver;
(void) session;
return MFX_ERR_UNKNOWN;
} // mfxStatus pseudoMFXInit(mfxIMPL impl, mfxVersion *ver, mfxSession *session)
mfxStatus pseudoMFXClose(mfxSession session)
{
// touch unreferenced parameters
(void) session;
return MFX_ERR_UNKNOWN;
} // mfxStatus pseudoMFXClose(mfxSession session)
mfxStatus pseudoMFXJoinSession(mfxSession session, mfxSession child_session)
{
// touch unreferenced parameters
(void) session;
(void) child_session;
return MFX_ERR_UNKNOWN;
} // mfxStatus pseudoMFXJoinSession(mfxSession session, mfxSession child_session)
mfxStatus pseudoMFXCloneSession(mfxSession session, mfxSession *clone)
{
// touch unreferenced parameters
(void) session;
(void) clone;
return MFX_ERR_UNKNOWN;
} // mfxStatus pseudoMFXCloneSession(mfxSession session, mfxSession *clone)
void SuppressWarnings(...)
{
// this functions is suppose to suppress warnings.
// Actually it does nothing.
} // void SuppressWarnings(...)
#undef FUNCTION
#define FUNCTION(return_value, func_name, formal_param_list, actual_param_list) \
return_value pseudo##func_name formal_param_list \
{ \
SuppressWarnings actual_param_list; \
return MFX_ERR_UNKNOWN; \
}
#include "mfx_exposed_functions_list.h"
} // namespace

View File

@@ -0,0 +1,592 @@
// 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
// 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 "mfx_library_iterator.h"
#include "mfx_dispatcher.h"
#include "mfx_dispatcher_log.h"
#include "mfx_dxva2_device.h"
#include "mfx_load_dll.h"
#include <tchar.h>
#include <windows.h>
namespace MFX
{
enum
{
MFX_MAX_MERIT = 0x7fffffff
};
//
// declare registry keys
//
const
wchar_t rootDispPath[] = L"Software\\Intel\\MediaSDK\\Dispatch";
const
wchar_t vendorIDKeyName[] = L"VendorID";
const
wchar_t deviceIDKeyName[] = L"DeviceID";
const
wchar_t meritKeyName[] = L"Merit";
const
wchar_t pathKeyName[] = L"Path";
const
wchar_t apiVersionName[] = L"APIVersion";
mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterface, mfxU32 *pVendorID, mfxU32 *pDeviceID)
{
if (NULL == pImplInterface)
{
return MFX_ERR_NULL_PTR;
}
#if (MFX_VERSION >= MFX_VERSION_NEXT)
mfxIMPL impl_via = (*pImplInterface & ~MFX_IMPL_EXTERNAL_THREADING);
#else
mfxIMPL impl_via = *pImplInterface;
#endif
DXVA2Device dxvaDevice;
if (MFX_IMPL_VIA_D3D9 == impl_via)
{
// try to create the Direct3D 9 device and find right adapter
if (!dxvaDevice.InitD3D9(adapterNum))
{
DISPATCHER_LOG_INFO((("dxvaDevice.InitD3D9(%d) Failed\n"), adapterNum ));
return MFX_ERR_UNSUPPORTED;
}
}
else if (MFX_IMPL_VIA_D3D11 == impl_via)
{
// try to open DXGI 1.1 device to get hardware ID
if (!dxvaDevice.InitDXGI1(adapterNum))
{
DISPATCHER_LOG_INFO((("dxvaDevice.InitDXGI1(%d) Failed\n"), adapterNum ));
return MFX_ERR_UNSUPPORTED;
}
}
else if (MFX_IMPL_VIA_ANY == impl_via)
{
// try the Direct3D 9 device
if (dxvaDevice.InitD3D9(adapterNum))
{
*pImplInterface = MFX_IMPL_VIA_D3D9; // store value for GetImplementationType() call
}
// else try to open DXGI 1.1 device to get hardware ID
else if (dxvaDevice.InitDXGI1(adapterNum))
{
*pImplInterface = MFX_IMPL_VIA_D3D11; // store value for GetImplementationType() call
}
else
{
DISPATCHER_LOG_INFO((("Unsupported adapter %d\n"), adapterNum ));
return MFX_ERR_UNSUPPORTED;
}
}
else
{
DISPATCHER_LOG_ERROR((("Unknown implementation type %d\n"), *pImplInterface ));
return MFX_ERR_UNSUPPORTED;
}
// obtain card's parameters
if (pVendorID && pDeviceID)
{
*pVendorID = dxvaDevice.GetVendorID();
*pDeviceID = dxvaDevice.GetDeviceID();
}
return MFX_ERR_NONE;
}
MFXLibraryIterator::MFXLibraryIterator(void)
#if !defined(MEDIASDK_UWP_DISPATCHER)
: m_baseRegKey()
#endif
{
m_implType = MFX_LIB_PSEUDO;
m_implInterface = MFX_IMPL_UNSUPPORTED;
m_vendorID = 0;
m_deviceID = 0;
m_lastLibIndex = 0;
m_lastLibMerit = MFX_MAX_MERIT;
m_bIsSubKeyValid = 0;
m_StorageID = 0;
m_SubKeyName[0] = 0;
} // MFXLibraryIterator::MFXLibraryIterator(void)
MFXLibraryIterator::~MFXLibraryIterator(void)
{
Release();
} // MFXLibraryIterator::~MFXLibraryIterator(void)
void MFXLibraryIterator::Release(void)
{
m_implType = MFX_LIB_PSEUDO;
m_implInterface = MFX_IMPL_UNSUPPORTED;
m_vendorID = 0;
m_deviceID = 0;
m_lastLibIndex = 0;
m_lastLibMerit = MFX_MAX_MERIT;
m_SubKeyName[0] = 0;
} // void MFXLibraryIterator::Release(void)
DECLSPEC_NOINLINE HMODULE GetThisDllModuleHandle()
{
HMODULE hDll = NULL;
GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(&GetThisDllModuleHandle), &hDll);
return hDll;
}
// 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;
sImplPath[0] = L'\0';
switch (storageID) {
case MFX_APP_FOLDER:
hModule = 0;
break;
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 || !exeModule || hModule == exeModule)
return false;
break;
}
DWORD nSize = 0;
DWORD allocSize = msdk_disp_path_len;
nSize = GetModuleFileNameW(hModule, &sImplPath[0], allocSize);
if (nSize == 0 || nSize == allocSize) {
// nSize == 0 meanse that system can't get this info for hModule
// nSize == allocSize buffer is too small
return false;
}
// for any case because WinXP implementation of GetModuleFileName does not add \0 to the end of string
sImplPath[nSize] = L'\0';
wchar_t * dirSeparator = wcsrchr(sImplPath, L'\\');
if (dirSeparator != NULL && dirSeparator < (sImplPath + msdk_disp_path_len))
{
*++dirSeparator = 0;
}
return true;
}
mfxStatus MFXLibraryIterator::Init(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID)
{
// check error(s)
if ((MFX_LIB_SOFTWARE != implType) &&
(MFX_LIB_HARDWARE != implType))
{
return MFX_ERR_UNSUPPORTED;
}
// release the object before initialization
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_UWP_DISPATCHER)
if (storageID == MFX_CURRENT_USER_KEY || storageID == MFX_LOCAL_MACHINE_KEY)
{
return InitRegistry(storageID);
}
#if defined(MFX_TRACER_WA_FOR_DS)
if (storageID == MFX_TRACER)
{
return InitRegistryTracer();
}
#endif
#endif
wchar_t sMediaSDKPath[msdk_disp_path_len] = {};
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, sMediaSDKPath, storageID);
} // mfxStatus MFXLibraryIterator::Init(eMfxImplType implType, const mfxU32 adapterNum, int storageID)
mfxStatus MFXLibraryIterator::InitRegistry(int storageID)
{
#if !defined(MEDIASDK_UWP_DISPATCHER)
HKEY rootHKey;
bool bRes;
// open required registry key
rootHKey = (MFX_LOCAL_MACHINE_KEY == storageID) ? (HKEY_LOCAL_MACHINE) : (HKEY_CURRENT_USER);
bRes = m_baseRegKey.Open(rootHKey, rootDispPath, KEY_READ);
if (false == bRes)
{
DISPATCHER_LOG_WRN((("Can't open %s\\%S : RegOpenKeyExA()==0x%x\n"),
(MFX_LOCAL_MACHINE_KEY == storageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
rootDispPath, GetLastError()))
return MFX_ERR_UNKNOWN;
}
DISPATCHER_LOG_INFO((("Inspecting %s\\%S\n"),
(MFX_LOCAL_MACHINE_KEY == storageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
rootDispPath))
return MFX_ERR_NONE;
#else
(void) storageID;
return MFX_ERR_UNSUPPORTED;
#endif // #if !defined(MEDIASDK_UWP_DISPATCHER)
} // 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, const wchar_t * path, const int storageID)
{
const int maxPathLen = sizeof(m_path)/sizeof(m_path[0]);
m_path[0] = 0;
wcscpy_s(m_path, maxPathLen, path);
size_t pathLen = wcslen(m_path);
if(storageID==MFX_APP_FOLDER)
{
// we looking for runtime in application folder, it should be named libmfxsw64 or libmfxsw32
mfx_get_default_dll_name(m_path + pathLen, msdk_disp_path_len - pathLen, MFX_LIB_SOFTWARE);
}
else
{
mfx_get_default_dll_name(m_path + pathLen, msdk_disp_path_len - pathLen, implType);
}
return MFX_ERR_NONE;
} // mfxStatus MFXLibraryIterator::InitFolder(eMfxImplType implType, const wchar_t * path, const int storageID)
mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath
, size_t pathSize
, eMfxImplType *pImplType, mfxVersion minVersion)
{
UNREFERENCED_PARAMETER(minVersion);
if (m_StorageID == MFX_APP_FOLDER)
{
if (m_lastLibIndex != 0)
return MFX_ERR_NOT_FOUND;
if (m_vendorID != INTEL_VENDOR_ID)
return MFX_ERR_UNKNOWN;
m_lastLibIndex = 1;
wcscpy_s(pPath, pathSize, m_path);
*pImplType = MFX_LIB_SOFTWARE;
return MFX_ERR_NONE;
}
if (m_StorageID == MFX_PATH_MSDK_FOLDER || m_StorageID == MFX_DRIVER_STORE)
{
if (m_lastLibIndex != 0)
return MFX_ERR_NOT_FOUND;
if (m_vendorID != INTEL_VENDOR_ID)
return MFX_ERR_UNKNOWN;
m_lastLibIndex = 1;
wcscpy_s(pPath, pathSize, m_path);
// do not change impl type
return MFX_ERR_NONE;
}
#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;
DWORD index;
bool enumRes;
// main query cycle
index = 0;
m_bIsSubKeyValid = false;
do
{
WinRegKey subKey;
wchar_t subKeyName[MFX_MAX_REGISTRY_KEY_NAME] = { 0 };
DWORD subKeyNameSize = sizeof(subKeyName) / sizeof(subKeyName[0]);
// query next value name
enumRes = m_baseRegKey.EnumKey(index, subKeyName, &subKeyNameSize);
if (!enumRes)
{
DISPATCHER_LOG_WRN((("no more subkeys : RegEnumKeyExA()==0x%x\n"), GetLastError()))
}
else
{
DISPATCHER_LOG_INFO((("found subkey: %S\n"), subKeyName))
bool bRes;
// open the sub key
bRes = subKey.Open(m_baseRegKey, subKeyName, KEY_READ);
if (!bRes)
{
DISPATCHER_LOG_WRN((("error opening key %S :RegOpenKeyExA()==0x%x\n"), subKeyName, GetLastError()));
}
else
{
DISPATCHER_LOG_INFO((("opened key: %S\n"), subKeyName));
mfxU32 vendorID = 0, deviceID = 0, merit = 0;
DWORD size;
// query vendor and device IDs
size = sizeof(vendorID);
bRes = subKey.Query(vendorIDKeyName, REG_DWORD, (LPBYTE) &vendorID, &size);
DISPATCHER_LOG_OPERATION({
if (bRes)
{
DISPATCHER_LOG_INFO((("loaded %S : 0x%x\n"), vendorIDKeyName, vendorID));
}
else
{
DISPATCHER_LOG_WRN((("querying %S : RegQueryValueExA()==0x%x\n"), vendorIDKeyName, GetLastError()));
}
})
if (bRes)
{
size = sizeof(deviceID);
bRes = subKey.Query(deviceIDKeyName, REG_DWORD, (LPBYTE) &deviceID, &size);
DISPATCHER_LOG_OPERATION({
if (bRes)
{
DISPATCHER_LOG_INFO((("loaded %S : 0x%x\n"), deviceIDKeyName, deviceID));
}
else
{
DISPATCHER_LOG_WRN((("querying %S : RegQueryValueExA()==0x%x\n"), deviceIDKeyName, GetLastError()));
}
})
}
// query merit value
if (bRes)
{
size = sizeof(merit);
bRes = subKey.Query(meritKeyName, REG_DWORD, (LPBYTE) &merit, &size);
DISPATCHER_LOG_OPERATION({
if (bRes)
{
DISPATCHER_LOG_INFO((("loaded %S : %d\n"), meritKeyName, merit));
}
else
{
DISPATCHER_LOG_WRN((("querying %S : RegQueryValueExA()==0x%x\n"), meritKeyName, GetLastError()));
}
})
}
// if the library fits required parameters,
// query the library's path
if (bRes)
{
// compare device's and library's IDs
if (MFX_LIB_HARDWARE == m_implType)
{
if (m_vendorID != vendorID)
{
bRes = false;
DISPATCHER_LOG_WRN((("%S conflict, actual = 0x%x : required = 0x%x\n"), vendorIDKeyName, m_vendorID, vendorID));
}
if (bRes && m_deviceID != deviceID)
{
bRes = false;
DISPATCHER_LOG_WRN((("%S conflict, actual = 0x%x : required = 0x%x\n"), deviceIDKeyName, m_deviceID, deviceID));
}
}
DISPATCHER_LOG_OPERATION({
if (bRes)
{
if (!(((m_lastLibMerit > merit) || ((m_lastLibMerit == merit) && (m_lastLibIndex < index))) &&
(libMerit < merit)))
{
DISPATCHER_LOG_WRN((("merit conflict: lastMerit = 0x%x, requiredMerit = 0x%x, libraryMerit = 0x%x, lastindex = %d, index = %d\n")
, m_lastLibMerit, merit, libMerit, m_lastLibIndex, index));
}
}})
if ((bRes) &&
((m_lastLibMerit > merit) || ((m_lastLibMerit == merit) && (m_lastLibIndex < index))) &&
(libMerit < merit))
{
wchar_t tmpPath[MFX_MAX_DLL_PATH];
DWORD tmpPathSize = sizeof(tmpPath);
bRes = subKey.Query(pathKeyName, REG_SZ, (LPBYTE) tmpPath, &tmpPathSize);
if (!bRes)
{
DISPATCHER_LOG_WRN((("error querying %S : RegQueryValueExA()==0x%x\n"), pathKeyName, GetLastError()));
}
else
{
DISPATCHER_LOG_INFO((("loaded %S : %S\n"), pathKeyName, tmpPath));
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;
// set the library's type
if ((0 == vendorID) || (0 == deviceID))
{
*pImplType = MFX_LIB_SOFTWARE;
DISPATCHER_LOG_INFO((("Library type is MFX_LIB_SOFTWARE\n")));
}
else
{
*pImplType = MFX_LIB_HARDWARE;
DISPATCHER_LOG_INFO((("Library type is MFX_LIB_HARDWARE\n")));
}
}
}
}
}
}
// advance key index
index += 1;
} while (enumRes);
// if the library's path was successfully read,
// the merit variable holds valid value
if (0 == libMerit)
{
return MFX_ERR_NOT_FOUND;
}
wcscpy_s(pPath, pathSize, libPath);
m_lastLibIndex = libIndex;
m_lastLibMerit = libMerit;
m_bIsSubKeyValid = true;
#endif
return MFX_ERR_NONE;
} // mfxStatus MFXLibraryIterator::SelectDLLVersion(wchar_t *pPath, size_t pathSize, eMfxImplType *pImplType, mfxVersion minVersion)
mfxIMPL MFXLibraryIterator::GetImplementationType()
{
return m_implInterface;
} // mfxIMPL MFXLibraryIterator::GetImplementationType()
bool MFXLibraryIterator::GetSubKeyName(wchar_t *subKeyName, size_t length) const
{
wcscpy_s(subKeyName, length, m_SubKeyName);
return m_bIsSubKeyValid;
}
} // namespace MFX

View File

@@ -0,0 +1,242 @@
// Copyright (c) 2012-2019 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 "mfx_dispatcher.h"
#include "mfx_load_dll.h"
#include <wchar.h>
#include <string.h>
#include <windows.h>
#if defined(_WIN64)
const
wchar_t * const defaultDLLName[2] = {L"libmfxhw64.dll",
L"libmfxsw64.dll"};
const
wchar_t * const defaultAudioDLLName[2] = {L"libmfxaudiosw64.dll",
L"libmfxaudiosw64.dll"};
const
wchar_t * const defaultPluginDLLName[2] = {L"mfxplugin64_hw.dll",
L"mfxplugin64_sw.dll"};
#if defined(MEDIASDK_UWP_DISPATCHER)
const
wchar_t * const IntelGFXAPIDLLName = {L"intel_gfx_api-x64.dll"};
#endif
#elif defined(_WIN32)
const
wchar_t * const defaultDLLName[2] = {L"libmfxhw32.dll",
L"libmfxsw32.dll"};
const
wchar_t * const defaultAudioDLLName[2] = {L"libmfxaudiosw32.dll",
L"libmfxaudiosw32.dll"};
const
wchar_t * const defaultPluginDLLName[2] = {L"mfxplugin32_hw.dll",
L"mfxplugin32_sw.dll"};
#if defined(MEDIASDK_UWP_DISPATCHER)
const
wchar_t * const IntelGFXAPIDLLName = {L"intel_gfx_api-x86.dll"};
#endif
#endif // (defined(_WIN64))
namespace MFX
{
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
wcscpy(pPath, defaultDLLName[implType & 1]);
return MFX_ERR_NONE;
#endif
} // 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(wchar_t *pPath, size_t pathSize)
{
if (!pPath)
{
return MFX_ERR_NULL_PTR;
}
#if _MSC_VER >= 1400
return 0 == wcscpy_s(pPath, pathSize, IntelGFXAPIDLLName)
? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
#else
wcscpy(pPath, IntelGFXAPIDLLName);
return MFX_ERR_NONE;
#endif
} // mfx_get_default_intel_gfx_api_dll_name(wchar_t *pPath, size_t pathSize)
#endif
mfxStatus mfx_get_default_plugin_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, defaultPluginDLLName[implType & 1])
? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
#else
wcscpy(pPath, defaultPluginDLLName[implType & 1]);
return MFX_ERR_NONE;
#endif
}
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
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)
// Force load library from system path to avoid DLL pre-loading attacks.
// We try to avoid loading DLLs from the application directory because we provide a portable version.
HMODULE load_library_system_path(const wchar_t *pFileName) {
const wchar_t * pDllName = wcsrchr(pFileName, L'\\');
if (pDllName == NULL) {
pDllName = pFileName;
} else {
pDllName++;
}
return LoadLibraryExW(pDllName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS);
}
mfxModuleHandle mfx_dll_load(const wchar_t *pFileName)
{
mfxModuleHandle hModule = (mfxModuleHandle) 0;
// check error(s)
if (NULL == pFileName)
{
return NULL;
}
#if !defined(MEDIASDK_UWP_DISPATCHER)
// set the silent error mode
DWORD prevErrorMode = 0;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode);
#else
prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
#endif // !defined(MEDIASDK_UWP_DISPATCHER)
// load the library's module
#if !defined(MEDIASDK_ARM_LOADER)
hModule = load_library_system_path(pFileName);
#endif
#if !defined(MEDIASDK_UWP_DISPATCHER)
// set the previous error mode
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(prevErrorMode, NULL);
#else
SetErrorMode(prevErrorMode);
#endif
#endif // !defined(MEDIASDK_UWP_DISPATCHER)
return hModule;
} // mfxModuleHandle mfx_dll_load(const wchar_t *pFileName)
mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *pFunctionName)
{
if (NULL == handle)
{
return NULL;
}
return (mfxFunctionPointer) GetProcAddress((HMODULE) handle, pFunctionName);
} // mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *pFunctionName)
bool mfx_dll_free(mfxModuleHandle handle)
{
if (NULL == handle)
{
return true;
}
BOOL bRes = FreeLibrary((HMODULE)handle);
return !!bRes;
} // bool mfx_dll_free(mfxModuleHandle handle)
#if !defined(MEDIASDK_UWP_DISPATCHER)
mfxModuleHandle mfx_get_dll_handle(const wchar_t *pFileName)
{
mfxModuleHandle hModule = (mfxModuleHandle) 0;
// check error(s)
if (NULL == pFileName)
{
return NULL;
}
// set the silent error mode
DWORD prevErrorMode = 0;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(SEM_FAILCRITICALERRORS, &prevErrorMode);
#else
prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
// load the library's module
GetModuleHandleExW(0, pFileName, (HMODULE*) &hModule);
// set the previous error mode
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
SetThreadErrorMode(prevErrorMode, NULL);
#else
SetErrorMode(prevErrorMode);
#endif
return hModule;
}
#endif //!defined(MEDIASDK_UWP_DISPATCHER)
} // namespace MFX

View File

@@ -0,0 +1,454 @@
// Copyright (c) 2013-2019 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 "mfx_load_plugin.h"
#include "mfx_load_dll.h"
#include "mfx_dispatcher_log.h"
#define TRACE_PLUGIN_ERROR(str, ...) DISPATCHER_LOG_ERROR((("[PLUGIN]: " str), __VA_ARGS__))
#define TRACE_PLUGIN_INFO(str, ...) DISPATCHER_LOG_INFO((("[PLUGIN]: " str), __VA_ARGS__))
#define CREATE_PLUGIN_FNC "CreatePlugin"
MFX::PluginModule::PluginModule()
: mHmodule()
, mCreatePluginPtr()
, mPath()
{
}
MFX::PluginModule::PluginModule(const PluginModule & that)
: mHmodule(mfx_dll_load(that.mPath))
, mCreatePluginPtr(that.mCreatePluginPtr)
{
wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath);
}
MFX::PluginModule & MFX::PluginModule::operator = (const MFX::PluginModule & that)
{
if (this != &that)
{
Tidy();
mHmodule = mfx_dll_load(that.mPath);
mCreatePluginPtr = that.mCreatePluginPtr;
wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), that.mPath);
}
return *this;
}
MFX::PluginModule::PluginModule(const wchar_t * path)
: mCreatePluginPtr()
{
mHmodule = mfx_dll_load(path);
if (NULL == mHmodule) {
TRACE_PLUGIN_ERROR("Cannot load module: %S\n", path);
return ;
}
TRACE_PLUGIN_INFO("Plugin loaded at: %S\n", path);
mCreatePluginPtr = (CreatePluginPtr_t)mfx_dll_get_addr(mHmodule, CREATE_PLUGIN_FNC);
if (NULL == mCreatePluginPtr) {
TRACE_PLUGIN_ERROR("Cannot get procedure address: %s\n", CREATE_PLUGIN_FNC);
return ;
}
wcscpy_s(mPath, sizeof(mPath) / sizeof(*mPath), path);
}
bool MFX::PluginModule::Create( mfxPluginUID uid, mfxPlugin& plg)
{
bool result = false;
if (mCreatePluginPtr)
{
mfxStatus mfxResult = mCreatePluginPtr(uid, &plg);
result = (MFX_ERR_NONE == mfxResult);
if (!result) {
TRACE_PLUGIN_ERROR("\"%S::%s\" returned %d\n", mPath, CREATE_PLUGIN_FNC, mfxResult);
} else {
TRACE_PLUGIN_INFO("\"%S::%s\" SUCCEED\n", mPath, CREATE_PLUGIN_FNC);
}
}
return result;
}
void MFX::PluginModule::Tidy()
{
mfx_dll_free(mHmodule);
mCreatePluginPtr = NULL;
mHmodule = NULL;
}
MFX::PluginModule::~PluginModule(void)
{
Tidy();
}
#if !defined(MEDIASDK_UWP_DISPATCHER)
bool MFX::MFXPluginFactory::RunVerification( const mfxPlugin & plg, const PluginDescriptionRecord &dsc, mfxPluginParam &pluginParams)
{
if (plg.PluginInit == 0)
{
TRACE_PLUGIN_ERROR("plg->PluginInit = 0\n", 0);
return false;
}
if (plg.PluginClose == 0)
{
TRACE_PLUGIN_ERROR("plg->PluginClose = 0\n", 0);
return false;
}
if (plg.GetPluginParam == 0)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam = 0\n", 0);
return false;
}
if (plg.Execute == 0)
{
TRACE_PLUGIN_ERROR("plg->Execute = 0\n", 0);
return false;
}
if (plg.FreeResources == 0)
{
TRACE_PLUGIN_ERROR("plg->FreeResources = 0\n", 0);
return false;
}
mfxStatus sts = plg.GetPluginParam(plg.pthis, &pluginParams);
if (sts != MFX_ERR_NONE)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned %d\n", sts);
return false;
}
if (dsc.Default)
{
// for default plugins there is no description, dsc.APIVersion, dsc.PluginVersion and dsc.PluginUID were set by dispatcher
// dsc.PluginVersion == requested plugin version (parameter of MFXVideoUSER_Load); dsc.APIVersion == loaded library API
if (dsc.PluginVersion > pluginParams.PluginVersion)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned PluginVersion=%d, but it is smaller than requested : %d\n", pluginParams.PluginVersion, dsc.PluginVersion);
return false;
}
}
else
{
if (!dsc.onlyVersionRegistered && pluginParams.CodecId != dsc.CodecId)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned CodecId=" MFXFOURCCTYPE()", but registration has CodecId=" MFXFOURCCTYPE()"\n"
, MFXU32TOFOURCC(pluginParams.CodecId), MFXU32TOFOURCC(dsc.CodecId));
return false;
}
if (!dsc.onlyVersionRegistered && pluginParams.Type != dsc.Type)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned Type=%d, but registration has Type=%d\n", pluginParams.Type, dsc.Type);
return false;
}
if (pluginParams.PluginUID != dsc.PluginUID)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned UID=" MFXGUIDTYPE()", but registration has UID=" MFXGUIDTYPE()"\n"
, MFXGUIDTOHEX(&pluginParams.PluginUID), MFXGUIDTOHEX(&dsc.PluginUID));
return false;
}
if (pluginParams.PluginVersion != dsc.PluginVersion)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned PluginVersion=%d, but registration has PlgVer=%d\n", pluginParams.PluginVersion, dsc.PluginVersion);
return false;
}
if (pluginParams.APIVersion.Version != dsc.APIVersion.Version)
{
TRACE_PLUGIN_ERROR("plg->GetPluginParam() returned APIVersion=%d.%d, but registration has APIVer=%d.%d\n"
, pluginParams.APIVersion.Major, pluginParams.APIVersion.Minor
, dsc.APIVersion.Major, dsc.APIVersion.Minor);
return false;
}
}
switch(pluginParams.Type)
{
case MFX_PLUGINTYPE_VIDEO_DECODE:
case MFX_PLUGINTYPE_VIDEO_ENCODE:
case MFX_PLUGINTYPE_VIDEO_VPP:
{
TRACE_PLUGIN_INFO("plugin type= %d\n", pluginParams.Type);
if (plg.Video == 0)
{
TRACE_PLUGIN_ERROR("plg->Video = 0\n", 0);
return false;
}
if (!VerifyCodecCommon(*plg.Video))
return false;
break;
}
}
switch(pluginParams.Type)
{
case MFX_PLUGINTYPE_VIDEO_DECODE:
return VerifyDecoder(*plg.Video);
case MFX_PLUGINTYPE_AUDIO_DECODE:
return VerifyAudioDecoder(*plg.Audio);
case MFX_PLUGINTYPE_VIDEO_ENCODE:
return VerifyEncoder(*plg.Video);
case MFX_PLUGINTYPE_AUDIO_ENCODE:
return VerifyAudioEncoder(*plg.Audio);
case MFX_PLUGINTYPE_VIDEO_VPP:
return VerifyVpp(*plg.Video);
case MFX_PLUGINTYPE_VIDEO_ENC:
return VerifyEnc(*plg.Video);
default:
{
TRACE_PLUGIN_ERROR("unsupported plugin type: %d\n", pluginParams.Type);
return false;
}
}
}
bool MFX::MFXPluginFactory::VerifyVpp( const mfxVideoCodecPlugin &vpp )
{
if (vpp.VPPFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->VPPFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyEncoder( const mfxVideoCodecPlugin &encoder )
{
if (encoder.EncodeFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->EncodeFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyAudioEncoder( const mfxAudioCodecPlugin &encoder )
{
if (encoder.EncodeFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Audio->EncodeFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyEnc( const mfxVideoCodecPlugin &videoEnc )
{
if (videoEnc.ENCFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->EncodeFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyDecoder( const mfxVideoCodecPlugin &decoder )
{
if (decoder.DecodeHeader == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->DecodeHeader = 0\n", 0);
return false;
}
if (decoder.GetPayload == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->GetPayload = 0\n", 0);
return false;
}
if (decoder.DecodeFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->DecodeFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyAudioDecoder( const mfxAudioCodecPlugin &decoder )
{
if (decoder.DecodeHeader == 0)
{
TRACE_PLUGIN_ERROR("plg->Audio->DecodeHeader = 0\n", 0);
return false;
}
// if (decoder.GetPayload == 0)
{
// TRACE_PLUGIN_ERROR("plg->Audio->GetPayload = 0\n", 0);
// return false;
}
if (decoder.DecodeFrameSubmit == 0)
{
TRACE_PLUGIN_ERROR("plg->Audio->DecodeFrameSubmit = 0\n", 0);
return false;
}
return true;
}
bool MFX::MFXPluginFactory::VerifyCodecCommon( const mfxVideoCodecPlugin & videoCodec )
{
if (videoCodec.Query == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->Query = 0\n", 0);
return false;
}
//todo: remove
if (videoCodec.Query == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->Query = 0\n", 0);
return false;
}
if (videoCodec.QueryIOSurf == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->QueryIOSurf = 0\n", 0);
return false;
}
if (videoCodec.Init == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->Init = 0\n", 0);
return false;
}
if (videoCodec.Reset == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->Reset = 0\n", 0);
return false;
}
if (videoCodec.Close == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->Close = 0\n", 0);
return false;
}
if (videoCodec.GetVideoParam == 0)
{
TRACE_PLUGIN_ERROR("plg->Video->GetVideoParam = 0\n", 0);
return false;
}
return true;
}
mfxStatus MFX::MFXPluginFactory::Create(const PluginDescriptionRecord & rec)
{
PluginModule plgModule(rec.sPath);
mfxPlugin plg = {};
mfxPluginParam plgParams;
if (!plgModule.Create(rec.PluginUID, plg))
{
return MFX_ERR_UNKNOWN;
}
if (!RunVerification(plg, rec, plgParams))
{
//will do not call plugin close since it is not safe to do that until structure is corrected
return MFX_ERR_UNKNOWN;
}
if (rec.Type == MFX_PLUGINTYPE_AUDIO_DECODE ||
rec.Type == MFX_PLUGINTYPE_AUDIO_ENCODE)
{
mfxStatus sts = MFXAudioUSER_Register(mSession, plgParams.Type, &plg);
if (MFX_ERR_NONE != sts)
{
TRACE_PLUGIN_ERROR(" MFXAudioUSER_Register returned %d\n", sts);
return sts;
}
}
else
{
mfxStatus sts = MFXVideoUSER_Register(mSession, plgParams.Type, &plg);
if (MFX_ERR_NONE != sts)
{
TRACE_PLUGIN_ERROR(" MFXVideoUSER_Register returned %d\n", sts);
return sts;
}
}
mPlugins.push_back(FactoryRecord(plgParams, plgModule, plg));
return MFX_ERR_NONE;
}
MFX::MFXPluginFactory::~MFXPluginFactory()
{
Close();
}
MFX::MFXPluginFactory::MFXPluginFactory( mfxSession session ) :
mPlugins()
{
mSession = session;
nPlugins = 0;
}
bool MFX::MFXPluginFactory::Destroy( const mfxPluginUID & uidToDestroy)
{
for (MFXVector<FactoryRecord >::iterator i = mPlugins.begin(); i!= mPlugins.end(); i++)
{
if (i->plgParams.PluginUID == uidToDestroy)
{
DestroyPlugin(*i);
//dll unload should happen here
//todo: check that dll_free fail is traced
mPlugins.erase(i);
return true;
}
}
return false;
}
void MFX::MFXPluginFactory::Close()
{
for (MFXVector<FactoryRecord>::iterator i = mPlugins.begin(); i!= mPlugins.end(); i++)
{
DestroyPlugin(*i);
}
mPlugins.clear();
}
void MFX::MFXPluginFactory::DestroyPlugin( FactoryRecord & record)
{
mfxStatus sts;
if (record.plgParams.Type == MFX_PLUGINTYPE_AUDIO_DECODE ||
record.plgParams.Type == MFX_PLUGINTYPE_AUDIO_ENCODE)
{
sts = MFXAudioUSER_Unregister(mSession, record.plgParams.Type);
TRACE_PLUGIN_INFO(" MFXAudioUSER_Unregister for Type=%d, returned %d\n", record.plgParams.Type, sts);
}
else
{
sts = MFXVideoUSER_Unregister(mSession, record.plgParams.Type);
TRACE_PLUGIN_INFO(" MFXVideoUSER_Unregister for Type=%d, returned %d\n", record.plgParams.Type, sts);
}
}
#endif //!defined(MEDIASDK_UWP_DISPATCHER)

View File

@@ -0,0 +1,491 @@
// Copyright (c) 2013-2019 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 "mfx_plugin_hive.h"
#include "mfx_library_iterator.h"
#include "mfx_dispatcher.h"
#include "mfx_dispatcher_log.h"
#include "mfx_load_dll.h"
#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__))
namespace
{
const wchar_t rootPluginPath[] = L"Software\\Intel\\MediaSDK\\Plugin";
const wchar_t rootDispatchPath[] = L"Software\\Intel\\MediaSDK\\Dispatch";
const wchar_t pluginSubkey[] = L"Plugin";
const wchar_t TypeKeyName[] = L"Type";
const wchar_t CodecIDKeyName[] = L"CodecID";
const wchar_t GUIDKeyName[] = L"GUID";
const wchar_t PathKeyName[] = L"Path";
const wchar_t DefaultKeyName[] = L"Default";
const wchar_t PlgVerKeyName[] = L"PluginVersion";
const wchar_t APIVerKeyName[] = L"APIVersion";
}
namespace
{
#ifdef _WIN64
const wchar_t pluginFileName[] = L"FileName64";
#else
const wchar_t pluginFileName[] = L"FileName32";
#endif // _WIN64
//do not allow store plugin in different hierarchy
const wchar_t pluginFileNameRestrictedCharacters[] = L"\\/";
const wchar_t pluginCfgFileName[] = L"plugin.cfg";
const wchar_t pluginSearchPattern[] = L"????????????????????????????????";
const mfxU32 pluginCfgFileNameLen = 10;
const mfxU32 pluginDirNameLen = 32;
const mfxU32 defaultPluginNameLen = 25;
const mfxU32 charsPermfxU8 = 2;
const mfxU32 slashLen = 1;
enum
{
MAX_PLUGIN_FILE_LINE = 4096
};
#define alignStr() "%-14S"
}
#if !defined(MEDIASDK_UWP_DISPATCHER)
MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const wchar_t *msdkLibSubKey, mfxVersion currentAPIVersion)
: MFXPluginStorageBase(currentAPIVersion)
{
HKEY rootHKey;
bool bRes;
WinRegKey regKey;
if (MFX_LOCAL_MACHINE_KEY != mfxStorageID && MFX_CURRENT_USER_KEY != mfxStorageID)
return;
// open required registry key
rootHKey = (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? (HKEY_LOCAL_MACHINE) : (HKEY_CURRENT_USER);
if (msdkLibSubKey) {
//dispatch/subkey/plugin
bRes = regKey.Open(rootHKey, rootDispatchPath, KEY_READ);
if (bRes)
{
bRes = regKey.Open(regKey, msdkLibSubKey, KEY_READ);
}
if (bRes)
{
bRes = regKey.Open(regKey, pluginSubkey, KEY_READ);
}
}
else
{
bRes = regKey.Open(rootHKey, rootPluginPath, KEY_READ);
}
if (false == bRes) {
return;
}
DWORD index = 0;
if (!regKey.QueryInfo(&index)) {
return;
}
try
{
resize(index);
}
catch (...) {
TRACE_HIVE_ERROR("new PluginDescriptionRecord[%d] threw an exception: \n", index);
return;
}
for(index = 0; ; index++)
{
wchar_t subKeyName[MFX_MAX_REGISTRY_KEY_NAME];
DWORD subKeyNameSize = sizeof(subKeyName) / sizeof(subKeyName[0]);
WinRegKey subKey;
// query next value name
bool enumRes = regKey.EnumKey(index, subKeyName, &subKeyNameSize);
if (!enumRes) {
break;
}
// open the sub key
bRes = subKey.Open(regKey, subKeyName, KEY_READ);
if (!bRes) {
continue;
}
if (msdkLibSubKey)
{
TRACE_HIVE_INFO("Found Plugin: %s\\%S\\%S\\%S\\%S\n", (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
rootDispatchPath, msdkLibSubKey, pluginSubkey, subKeyName);
}
else
{
TRACE_HIVE_INFO("Found Plugin: %s\\%S\\%S\n", (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
rootPluginPath, subKeyName);
}
PluginDescriptionRecord descriptionRecord;
if (!QueryKey(subKey, TypeKeyName, descriptionRecord.Type))
{
continue;
}
TRACE_HIVE_INFO(alignStr()" : %d\n", TypeKeyName, descriptionRecord.Type);
if (QueryKey(subKey, CodecIDKeyName, descriptionRecord.CodecId))
{
TRACE_HIVE_INFO(alignStr()" : " MFXFOURCCTYPE()" \n", CodecIDKeyName, MFXU32TOFOURCC(descriptionRecord.CodecId));
}
else
{
TRACE_HIVE_INFO(alignStr()" : \n", CodecIDKeyName, "NOT REGISTERED");
}
if (!QueryKey(subKey, GUIDKeyName, descriptionRecord.PluginUID))
{
continue;
}
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))
{
TRACE_HIVE_WRN("no value for : %S\n", PathKeyName);
continue;
}
TRACE_HIVE_INFO(alignStr()" : %S\n", PathKeyName, descriptionRecord.sPath);
if (!QueryKey(subKey, DefaultKeyName, descriptionRecord.Default))
{
continue;
}
TRACE_HIVE_INFO(alignStr()" : %s\n", DefaultKeyName, descriptionRecord.Default ? "true" : "false");
mfxU32 version = 0;
if (!QueryKey(subKey, PlgVerKeyName, version))
{
continue;
}
descriptionRecord.PluginVersion = static_cast<mfxU16>(version);
if (0 == version)
{
TRACE_HIVE_ERROR(alignStr()" : %d, which is invalid\n", PlgVerKeyName, descriptionRecord.PluginVersion);
continue;
}
else
{
TRACE_HIVE_INFO(alignStr()" : %d\n", PlgVerKeyName, descriptionRecord.PluginVersion);
}
mfxU32 APIVersion = 0;
if (!QueryKey(subKey, APIVerKeyName, APIVersion))
{
continue;
}
ConvertAPIVersion(APIVersion, descriptionRecord);
TRACE_HIVE_INFO(alignStr()" : %d.%d \n", APIVerKeyName, descriptionRecord.APIVersion.Major, descriptionRecord.APIVersion.Minor);
try
{
operator[](index) = descriptionRecord;
}
catch (...) {
TRACE_HIVE_ERROR("operator[](%d) = descriptionRecord; - threw exception \n", index);
}
}
}
MFX::MFXPluginsInFS::MFXPluginsInFS( mfxVersion currentAPIVersion )
: MFXPluginStorageBase(currentAPIVersion)
, mIsVersionParsed()
, mIsAPIVersionParsed()
{
WIN32_FIND_DATAW find_data;
wchar_t currentModuleName[MAX_PLUGIN_PATH];
GetModuleFileNameW(NULL, currentModuleName, MAX_PLUGIN_PATH);
if (GetLastError() != 0)
{
TRACE_HIVE_ERROR("GetModuleFileName() reported an error: %d\n", GetLastError());
return;
}
wchar_t *lastSlashPos = wcsrchr(currentModuleName, L'\\');
if (!lastSlashPos) {
lastSlashPos = currentModuleName;
}
mfxU32 executableDirLen = (mfxU32)(lastSlashPos - currentModuleName) + slashLen;
if (executableDirLen + pluginDirNameLen + pluginCfgFileNameLen >= MAX_PLUGIN_PATH)
{
TRACE_HIVE_ERROR("MAX_PLUGIN_PATH which is %d, not enough to locate plugin path\n", MAX_PLUGIN_PATH);
return;
}
wcscpy_s(lastSlashPos + slashLen
, MAX_PLUGIN_PATH - executableDirLen, pluginSearchPattern);
HANDLE fileFirst = FindFirstFileW(currentModuleName, &find_data);
if (INVALID_HANDLE_VALUE == fileFirst)
{
TRACE_HIVE_ERROR("FindFirstFileW() unable to locate any plugins folders\n", 0);
return;
}
do
{
if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
continue;
}
if (pluginDirNameLen != wcslen(find_data.cFileName))
{
continue;
}
//converting dirname into guid
PluginDescriptionRecord descriptionRecord;
descriptionRecord.APIVersion = currentAPIVersion;
descriptionRecord.onlyVersionRegistered = true;
mfxU32 i = 0;
for(i = 0; i != pluginDirNameLen / charsPermfxU8; i++)
{
mfxU32 hexNum = 0;
if (1 != swscanf_s(find_data.cFileName + charsPermfxU8 * i, L"%2x", &hexNum))
{
// it is ok to have non-plugin subdirs with length 32
//TRACE_HIVE_INFO("folder name \"%S\" is not a valid GUID string\n", find_data.cFileName);
break;
}
if (hexNum == 0 && find_data.cFileName + charsPermfxU8 * i != wcsstr(find_data.cFileName + 2*i, L"00"))
{
// it is ok to have non-plugin subdirs with length 32
//TRACE_HIVE_INFO("folder name \"%S\" is not a valid GUID string\n", find_data.cFileName);
break;
}
descriptionRecord.PluginUID.Data[i] = (mfxU8)hexNum;
}
if (i != pluginDirNameLen / charsPermfxU8) {
continue;
}
wcscpy_s(currentModuleName + executableDirLen
, MAX_PLUGIN_PATH - executableDirLen, find_data.cFileName);
wcscpy_s(currentModuleName + executableDirLen + pluginDirNameLen
, MAX_PLUGIN_PATH - executableDirLen - pluginDirNameLen, L"\\");
//this is path to plugin directory
wcscpy_s(descriptionRecord.sPath
, sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath), currentModuleName);
wcscpy_s(currentModuleName + executableDirLen + pluginDirNameLen + slashLen
, MAX_PLUGIN_PATH - executableDirLen - pluginDirNameLen - slashLen, pluginCfgFileName);
FILE *pluginCfgFile = 0;
_wfopen_s(&pluginCfgFile, currentModuleName, L"r");
if (!pluginCfgFile)
{
TRACE_HIVE_INFO("in directory \"%S\" no mandatory \"%S\"\n"
, find_data.cFileName, pluginCfgFileName);
continue;
}
if (ParseFile(pluginCfgFile, descriptionRecord))
{
try
{
push_back(descriptionRecord);
}
catch (...) {
TRACE_HIVE_ERROR("mRecords.push_back(descriptionRecord); - threw exception \n", 0);
}
}
fclose(pluginCfgFile);
}while (FindNextFileW(fileFirst, &find_data));
FindClose(fileFirst);
}
bool MFX::MFXPluginsInFS::ParseFile(FILE * f, PluginDescriptionRecord & descriptionRecord)
{
wchar_t line[MAX_PLUGIN_FILE_LINE];
while(NULL != fgetws(line, sizeof(line) / sizeof(*line), f))
{
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);
continue;
}
*delimiter = 0;
if (!ParseKVPair(line, delimiter + 1, descriptionRecord))
{
return false;
}
}
if (!mIsVersionParsed)
{
TRACE_HIVE_ERROR("%S : Mandatory key %S not found\n", pluginCfgFileName, PlgVerKeyName);
return false;
}
if (!mIsAPIVersionParsed)
{
TRACE_HIVE_ERROR("%S : Mandatory key %S not found\n", pluginCfgFileName, APIVerKeyName);
return false;
}
if (!wcslen(descriptionRecord.sPath))
{
TRACE_HIVE_ERROR("%S : Mandatory key %S not found\n", pluginCfgFileName, pluginFileName);
return false;
}
return true;
}
bool MFX::MFXPluginsInFS::ParseKVPair( wchar_t * key, wchar_t* value, PluginDescriptionRecord & descriptionRecord)
{
if (0 != wcsstr(key, PlgVerKeyName))
{
mfxU32 version ;
if (0 == swscanf_s(value, L"%d", &version))
{
return false;
}
descriptionRecord.PluginVersion = (mfxU16)version;
if (0 == descriptionRecord.PluginVersion)
{
TRACE_HIVE_ERROR("%S: %S = %d, which is invalid\n", pluginCfgFileName, PlgVerKeyName, descriptionRecord.PluginVersion);
return false;
}
TRACE_HIVE_INFO("%S: %S = %d \n", pluginCfgFileName, PlgVerKeyName, descriptionRecord.PluginVersion);
mIsVersionParsed = true;
return true;
}
if (0 != wcsstr(key, APIVerKeyName))
{
mfxU32 APIversion;
if (0 == swscanf_s(value, L"%d", &APIversion))
{
return false;
}
ConvertAPIVersion(APIversion, descriptionRecord);
TRACE_HIVE_INFO("%S: %S = %d.%d \n", pluginCfgFileName, APIVerKeyName, descriptionRecord.APIVersion.Major, descriptionRecord.APIVersion.Minor);
mIsAPIVersionParsed = true;
return true;
}
if (0!=wcsstr(key, pluginFileName))
{
wchar_t *startQuoteMark = wcschr(value, L'\"');
if (!startQuoteMark)
{
TRACE_HIVE_ERROR("plugin filename not in quotes : %S\n", value);
return false;
}
wchar_t *endQuoteMark = wcschr(startQuoteMark + 1, L'\"');
if (!endQuoteMark)
{
TRACE_HIVE_ERROR("plugin filename not in quotes : %S\n", value);
return false;
}
*endQuoteMark = 0;
mfxU32 currentPathLen = (mfxU32)wcslen(descriptionRecord.sPath);
if (currentPathLen + wcslen(startQuoteMark + 1) > sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath))
{
TRACE_HIVE_ERROR("buffer of MAX_PLUGIN_PATH characters which is %d, not enough lo store plugin path: %S%S\n"
, MAX_PLUGIN_PATH, descriptionRecord.sPath, startQuoteMark + 1);
return false;
}
size_t restrictedCharIdx = wcscspn(startQuoteMark + 1, pluginFileNameRestrictedCharacters);
if (restrictedCharIdx != wcslen(startQuoteMark + 1))
{
TRACE_HIVE_ERROR("plugin filename :%S, contains one of restricted characters: %S\n", startQuoteMark + 1, pluginFileNameRestrictedCharacters);
return false;
}
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);
return true;
}
return true;
}
#endif //#if !defined(MEDIASDK_UWP_DISPATCHER)
MFX::MFXDefaultPlugins::MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP_HANDLE * hdl, int implType)
: MFXPluginStorageBase(currentAPIVersion)
{
wchar_t libModuleName[MAX_PLUGIN_PATH];
GetModuleFileNameW((HMODULE)hdl->hModule, libModuleName, MAX_PLUGIN_PATH);
if (GetLastError() != 0)
{
TRACE_HIVE_ERROR("GetModuleFileName() reported an error: %d\n", GetLastError());
return;
}
wchar_t *lastSlashPos = wcsrchr(libModuleName, L'\\');
if (!lastSlashPos) {
lastSlashPos = libModuleName;
}
mfxU32 executableDirLen = (mfxU32)(lastSlashPos - libModuleName) + slashLen;
if (executableDirLen + defaultPluginNameLen >= MAX_PLUGIN_PATH)
{
TRACE_HIVE_ERROR("MAX_PLUGIN_PATH which is %d, not enough to locate default plugin path\n", MAX_PLUGIN_PATH);
return;
}
mfx_get_default_plugin_name(lastSlashPos + slashLen, MAX_PLUGIN_PATH - executableDirLen, (eMfxImplType)implType);
if (-1 != GetFileAttributesW(libModuleName))
{
// add single default plugin description
PluginDescriptionRecord descriptionRecord;
descriptionRecord.APIVersion = currentAPIVersion;
descriptionRecord.Default = true;
wcscpy_s(descriptionRecord.sPath
, sizeof(descriptionRecord.sPath) / sizeof(*descriptionRecord.sPath), libModuleName);
push_back(descriptionRecord);
}
else
{
TRACE_HIVE_INFO("GetFileAttributesW() unable to locate default plugin dll named %S\n", libModuleName);
}
}

View File

@@ -0,0 +1,217 @@
// Copyright (c) 2012-2019 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(MEDIASDK_UWP_DISPATCHER)
#include "mfx_win_reg_key.h"
#include "mfx_dispatcher_log.h"
#define TRACE_WINREG_ERROR(str, ...) DISPATCHER_LOG_ERROR((("[WINREG]: " str), __VA_ARGS__))
namespace MFX
{
WinRegKey::WinRegKey(void)
{
m_hKey = (HKEY) 0;
} // WinRegKey::WinRegKey(void)
WinRegKey::~WinRegKey(void)
{
Release();
} // WinRegKey::~WinRegKey(void)
void WinRegKey::Release(void)
{
// close the opened key
if (m_hKey)
{
RegCloseKey(m_hKey);
}
m_hKey = (HKEY) 0;
} // void WinRegKey::Release(void)
bool WinRegKey::Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired)
{
LONG lRes;
HKEY hTemp;
//
// All operation are performed in this order by intention.
// It makes possible to reopen the keys, using itself as a base.
//
// try to the open registry key
lRes = RegOpenKeyExW(hRootKey, pSubKey, 0, samDesired, &hTemp);
if (ERROR_SUCCESS != lRes)
{
DISPATCHER_LOG_OPERATION(SetLastError(lRes));
TRACE_WINREG_ERROR("Opening key \"%s\\%S\" : RegOpenKeyExW()==0x%x\n"
, (HKEY_LOCAL_MACHINE == hRootKey) ? ("HKEY_LOCAL_MACHINE")
: (HKEY_CURRENT_USER == hRootKey) ? ("HKEY_CURRENT_USER")
: "UNSUPPORTED_KEY", pSubKey, GetLastError());
return false;
}
// release the object before initialization
Release();
// save the handle
m_hKey = hTemp;
return true;
} // bool WinRegKey::Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired)
bool WinRegKey::Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired)
{
return Open(rootKey.m_hKey, pSubKey, samDesired);
} // bool WinRegKey::Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired)
bool WinRegKey::QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData) {
DWORD keyType = type;
LONG lRes;
// query the value
lRes = RegQueryValueExW(m_hKey, pValueName, NULL, &keyType, 0, pcbData);
if (ERROR_SUCCESS != lRes)
{
DISPATCHER_LOG_OPERATION(SetLastError(lRes));
TRACE_WINREG_ERROR("Querying \"%S\" : RegQueryValueExA()==0x%x\n", pValueName, GetLastError());
return false;
}
return true;
}
bool WinRegKey::Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData)
{
DWORD keyType = type;
LONG lRes;
DWORD dstSize = (pcbData) ? (*pcbData) : (0);
// query the value
lRes = RegQueryValueExW(m_hKey, pValueName, NULL, &keyType, pData, pcbData);
if (ERROR_SUCCESS != lRes)
{
DISPATCHER_LOG_OPERATION(SetLastError(lRes));
TRACE_WINREG_ERROR("Querying \"%S\" : RegQueryValueExA()==0x%x\n", pValueName, GetLastError());
return false;
}
// check the type
if (keyType != type)
{
TRACE_WINREG_ERROR("Querying \"%S\" : expectedType=%d, returned=%d\n", pValueName, type, keyType);
return false;
}
// terminate the string only if pointers not NULL
if ((REG_SZ == type || REG_EXPAND_SZ == type) && NULL != pData && NULL != pcbData)
{
wchar_t *pString = (wchar_t *) pData;
size_t NullEndingSizeBytes = sizeof(wchar_t); // size of string termination null character
if (dstSize < NullEndingSizeBytes)
{
TRACE_WINREG_ERROR("Querying \"%S\" : buffer is too small for null-terminated string", pValueName);
return false;
}
size_t maxStringLengthBytes = dstSize - NullEndingSizeBytes;
size_t maxStringIndex = dstSize / sizeof(wchar_t) - 1;
size_t lastIndex = (maxStringLengthBytes < *pcbData) ? (maxStringIndex) : (*pcbData) / sizeof(wchar_t);
pString[lastIndex] = (wchar_t) 0;
}
else if(REG_MULTI_SZ == type && NULL != pData && NULL != pcbData)
{
wchar_t *pString = (wchar_t *) pData;
size_t NullEndingSizeBytes = sizeof(wchar_t)*2; // size of string termination null characters
if (dstSize < NullEndingSizeBytes)
{
TRACE_WINREG_ERROR("Querying \"%S\" : buffer is too small for multi-line null-terminated string", pValueName);
return false;
}
size_t maxStringLengthBytes = dstSize - NullEndingSizeBytes;
size_t maxStringIndex = dstSize / sizeof(wchar_t) - 1;
size_t lastIndex = (maxStringLengthBytes < *pcbData) ? (maxStringIndex) : (*pcbData) / sizeof(wchar_t) + 1;
// last 2 bytes should be 0 in case of REG_MULTI_SZ
pString[lastIndex] = pString[lastIndex - 1] = (wchar_t) 0;
}
return true;
} // 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)
{
LONG lRes;
// enum the values
lRes = RegEnumValueW(m_hKey, index, pValueName, pcchValueName, 0, pType, NULL, NULL);
if (ERROR_SUCCESS != lRes)
{
DISPATCHER_LOG_OPERATION(SetLastError(lRes));
return false;
}
return true;
} // bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType)
bool WinRegKey::EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName)
{
LONG lRes;
// enum the keys
lRes = RegEnumKeyExW(m_hKey, index, pValueName, pcchValueName, NULL, NULL, NULL, NULL);
if (ERROR_SUCCESS != lRes)
{
DISPATCHER_LOG_OPERATION(SetLastError(lRes));
TRACE_WINREG_ERROR("EnumKey with index=%d: RegEnumKeyExW()==0x%x\n", index, GetLastError());
return false;
}
return true;
} // bool WinRegKey::EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName)
bool WinRegKey::QueryInfo(LPDWORD lpcSubkeys)
{
LONG lRes;
lRes = RegQueryInfoKeyW(m_hKey, NULL, 0, 0, lpcSubkeys, 0, 0, 0, 0, 0, 0, 0);
if (ERROR_SUCCESS != lRes) {
TRACE_WINREG_ERROR("RegQueryInfoKeyW()==0x%x\n", lRes);
return false;
}
return true;
} //bool QueryInfo(LPDWORD lpcSubkeys);
} // namespace MFX
#endif // #if !defined(MEDIASDK_UWP_DISPATCHER)