mfx_library_iterator.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* ****************************************************************************** *\
  2. Copyright (C) 2012-2018 Intel Corporation. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. - Neither the name of Intel Corporation nor the names of its contributors
  11. may be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. File Name: mfx_library_iterator.h
  24. \* ****************************************************************************** */
  25. #if !defined(__MFX_LIBRARY_ITERATOR_H)
  26. #define __MFX_LIBRARY_ITERATOR_H
  27. #include <mfxvideo.h>
  28. #if !defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)
  29. #include "mfx_win_reg_key.h"
  30. #endif
  31. #include "mfx_dispatcher.h"
  32. #if !defined(_WIN32) && !defined(_WIN64)
  33. struct mfx_disp_adapters
  34. {
  35. mfxU32 vendor_id;
  36. mfxU32 device_id;
  37. };
  38. #ifndef __APPLE__
  39. #define MFX_SO_BASE_NAME_LEN 15 // sizeof("libmfxhw32-p.so") = 15
  40. #else
  41. #define MFX_SO_BASE_NAME_LEN 16 // sizeof("libmfxhw64.dylib") = 16
  42. #endif
  43. #define MFX_MIN_REAL_LIBNAME MFX_SO_BASE_NAME_LEN + 4 // sizeof("libmfxhw32-p.so.0.0") >= 19
  44. #define MFX_MAX_REAL_LIBNAME MFX_MIN_REAL_LIBNAME + 8 // sizeof("libmfxhw32-p.so.<mj>.<mn>") <= 27, max(sizeof(<mj>))=sizeof(0xFFFF) = sizeof(65535) = 5
  45. struct mfx_libs
  46. {
  47. char name[MFX_MAX_REAL_LIBNAME+1];
  48. mfxVersion version;
  49. };
  50. #endif
  51. namespace MFX
  52. {
  53. // declare desired storage ID
  54. #if defined(_WIN32) || defined(_WIN64)
  55. enum
  56. {
  57. MFX_UNKNOWN_KEY = -1,
  58. MFX_CURRENT_USER_KEY = 0,
  59. MFX_LOCAL_MACHINE_KEY = 1,
  60. MFX_APP_FOLDER = 2,
  61. #if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE))
  62. MFX_PATH_MSDK_FOLDER = 3,
  63. MFX_STORAGE_ID_FIRST = MFX_CURRENT_USER_KEY,
  64. MFX_STORAGE_ID_LAST = MFX_PATH_MSDK_FOLDER
  65. #else
  66. MFX_PATH_MSDK_FOLDER = 3,
  67. MFX_STORAGE_ID_FIRST = MFX_PATH_MSDK_FOLDER,
  68. MFX_STORAGE_ID_LAST = MFX_PATH_MSDK_FOLDER
  69. #endif // !defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)
  70. };
  71. #else
  72. enum
  73. {
  74. MFX_UNKNOWN_KEY = -1,
  75. MFX_STORAGE_ID_OPT = 0, // storage is: MFX_MODULES_DIR
  76. MFX_APP_FOLDER = 1,
  77. MFX_STORAGE_ID_FIRST = MFX_STORAGE_ID_OPT,
  78. MFX_STORAGE_ID_LAST = MFX_STORAGE_ID_OPT
  79. };
  80. #endif
  81. // Try to initialize using given implementation type. Select appropriate type automatically in case of MFX_IMPL_VIA_ANY.
  82. // Params: adapterNum - in, pImplInterface - in/out, pVendorID - out, pDeviceID - out
  83. mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterface, mfxU32 *pVendorID, mfxU32 *pDeviceID);
  84. const mfxU32 msdk_disp_path_len = 1024;
  85. class MFXLibraryIterator
  86. {
  87. public:
  88. // Default constructor
  89. MFXLibraryIterator(void);
  90. // Destructor
  91. ~MFXLibraryIterator(void);
  92. // Initialize the iterator
  93. mfxStatus Init(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID);
  94. // Get the next library path
  95. mfxStatus SelectDLLVersion(msdk_disp_char *pPath, size_t pathSize,
  96. eMfxImplType *pImplType, mfxVersion minVersion);
  97. // Return interface type on which Intel adapter was found (if any): D3D9 or D3D11
  98. mfxIMPL GetImplementationType();
  99. // Retrun registry subkey name on which dll was selected after sucesfull call to selectDllVesion
  100. bool GetSubKeyName(msdk_disp_char *subKeyName, size_t length) const;
  101. int GetStorageID() const { return m_StorageID; }
  102. protected:
  103. // Release the iterator
  104. void Release(void);
  105. // Initialize the registry iterator
  106. mfxStatus InitRegistry(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID);
  107. // Initialize the app folder iterator
  108. mfxStatus InitFolder(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, const msdk_disp_char * path);
  109. eMfxImplType m_implType; // Required library implementation
  110. mfxIMPL m_implInterface; // Required interface (D3D9, D3D11)
  111. mfxU32 m_vendorID; // (mfxU32) property of used graphic card
  112. mfxU32 m_deviceID; // (mfxU32) property of used graphic card
  113. bool m_bIsSubKeyValid;
  114. wchar_t m_SubKeyName[MFX_MAX_REGISTRY_KEY_NAME]; // registry subkey for selected module loaded
  115. int m_StorageID;
  116. #if defined(_WIN32) || defined(_WIN64)
  117. #if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE))
  118. WinRegKey m_baseRegKey; // (WinRegKey) main registry key
  119. #endif
  120. mfxU32 m_lastLibIndex; // (mfxU32) index of previously returned library
  121. mfxU32 m_lastLibMerit; // (mfxU32) merit of previously returned library
  122. #else
  123. int m_lastLibIndex; // (mfxU32) index of previously returned library
  124. mfxU32 m_adapters_num;
  125. struct mfx_disp_adapters* m_adapters;
  126. int m_selected_adapter;
  127. mfxU32 m_libs_num;
  128. struct mfx_libs* m_libs;
  129. #endif // #if defined(_WIN32) || defined(_WIN64)
  130. msdk_disp_char m_path[msdk_disp_path_len];
  131. private:
  132. // unimplemented by intent to make this class non-copyable
  133. MFXLibraryIterator(const MFXLibraryIterator &);
  134. void operator=(const MFXLibraryIterator &);
  135. };
  136. } // namespace MFX
  137. #endif // __MFX_LIBRARY_ITERATOR_H