Interface.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // Notice Regarding Standards. AMD does not provide a license or sublicense to
  3. // any Intellectual Property Rights relating to any standards, including but not
  4. // limited to any audio and/or video codec technologies such as MPEG-2, MPEG-4;
  5. // AVC/H.264; HEVC/H.265; AAC decode/FFMPEG; AAC encode/FFMPEG; VC-1; and MP3
  6. // (collectively, the "Media Technologies"). For clarity, you will pay any
  7. // royalties due for such third party technologies, which may include the Media
  8. // Technologies that are owed as a result of AMD providing the Software to you.
  9. //
  10. // MIT license
  11. //
  12. // Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the "Software"), to deal
  16. // in the Software without restriction, including without limitation the rights
  17. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. // copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. // THE SOFTWARE.
  31. //
  32. #ifndef AMF_Interface_h
  33. #define AMF_Interface_h
  34. #pragma once
  35. #include "Result.h"
  36. #if defined(__cplusplus)
  37. namespace amf
  38. {
  39. #endif
  40. #if defined(__cplusplus)
  41. #define AMF_DECLARE_IID(_data1, _data2, _data3, _data41, _data42, _data43, _data44, _data45, _data46, _data47, _data48) \
  42. static AMF_INLINE const amf::AMFGuid IID() \
  43. { \
  44. amf::AMFGuid uid = {_data1, _data2, _data3, _data41, _data42, _data43, _data44, _data45, _data46, _data47, _data48}; \
  45. return uid; \
  46. }
  47. #else
  48. #define AMF_DECLARE_IID(name, _data1, _data2, _data3, _data41, _data42, _data43, _data44, _data45, _data46, _data47, _data48) \
  49. AMF_INLINE static const AMFGuid IID_##name(void) \
  50. { \
  51. AMFGuid uid = {_data1, _data2, _data3, _data41, _data42, _data43, _data44, _data45, _data46, _data47, _data48}; \
  52. return uid; \
  53. }
  54. #endif
  55. //------------------------------------------------------------------------
  56. // AMFInterface interface - base class for all AMF interfaces
  57. //------------------------------------------------------------------------
  58. #if defined(__cplusplus)
  59. class AMF_NO_VTABLE AMFInterface
  60. {
  61. public:
  62. AMF_DECLARE_IID(0x9d872f34, 0x90dc, 0x4b93, 0xb6, 0xb2, 0x6c, 0xa3, 0x7c, 0x85, 0x25, 0xdb)
  63. virtual amf_long AMF_STD_CALL Acquire() = 0;
  64. virtual amf_long AMF_STD_CALL Release() = 0;
  65. virtual AMF_RESULT AMF_STD_CALL QueryInterface(const AMFGuid& interfaceID, void** ppInterface) = 0;
  66. };
  67. #else
  68. AMF_DECLARE_IID(AMFInterface, 0x9d872f34, 0x90dc, 0x4b93, 0xb6, 0xb2, 0x6c, 0xa3, 0x7c, 0x85, 0x25, 0xdb)
  69. typedef struct AMFInterface AMFInterface;
  70. typedef struct AMFInterfaceVtbl
  71. {
  72. // AMFInterface interface
  73. amf_long (AMF_STD_CALL *Acquire)(AMFInterface* pThis);
  74. amf_long (AMF_STD_CALL *Release)(AMFInterface* pThis);
  75. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFInterface* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  76. } AMFInterfaceVtbl;
  77. struct AMFInterface
  78. {
  79. const AMFInterfaceVtbl *pVtbl;
  80. };
  81. #endif
  82. //------------------------------------------------------------------------
  83. // template for AMF smart pointer
  84. //------------------------------------------------------------------------
  85. #if defined(__cplusplus)
  86. template<class _Interf>
  87. class AMFInterfacePtr_T
  88. {
  89. private:
  90. _Interf* m_pInterf;
  91. void InternalAcquire()
  92. {
  93. if(m_pInterf != NULL)
  94. {
  95. m_pInterf->Acquire();
  96. }
  97. }
  98. void InternalRelease()
  99. {
  100. if(m_pInterf != NULL)
  101. {
  102. m_pInterf->Release();
  103. }
  104. }
  105. public:
  106. AMFInterfacePtr_T() : m_pInterf(NULL)
  107. {}
  108. AMFInterfacePtr_T(const AMFInterfacePtr_T<_Interf>& p) : m_pInterf(p.m_pInterf)
  109. {
  110. InternalAcquire();
  111. }
  112. AMFInterfacePtr_T(_Interf* pInterface) : m_pInterf(pInterface)
  113. {
  114. InternalAcquire();
  115. }
  116. template<class _OtherInterf>
  117. explicit AMFInterfacePtr_T(const AMFInterfacePtr_T<_OtherInterf>& cp) : m_pInterf(NULL)
  118. {
  119. void* pInterf = NULL;
  120. if((cp == NULL) || (cp->QueryInterface(_Interf::IID(), &pInterf) != AMF_OK))
  121. {
  122. pInterf = NULL;
  123. }
  124. m_pInterf = static_cast<_Interf*>(pInterf);
  125. }
  126. template<class _OtherInterf>
  127. explicit AMFInterfacePtr_T(_OtherInterf* cp) : m_pInterf(NULL)
  128. {
  129. void* pInterf = NULL;
  130. if((cp == NULL) || (cp->QueryInterface(_Interf::IID(), &pInterf) != AMF_OK))
  131. {
  132. pInterf = NULL;
  133. }
  134. m_pInterf = static_cast<_Interf*>(pInterf);
  135. }
  136. ~AMFInterfacePtr_T()
  137. {
  138. InternalRelease();
  139. }
  140. AMFInterfacePtr_T& operator=(_Interf* pInterface)
  141. {
  142. if(m_pInterf != pInterface)
  143. {
  144. _Interf* pOldInterface = m_pInterf;
  145. m_pInterf = pInterface;
  146. InternalAcquire();
  147. if(pOldInterface != NULL)
  148. {
  149. pOldInterface->Release();
  150. }
  151. }
  152. return *this;
  153. }
  154. AMFInterfacePtr_T& operator=(const AMFInterfacePtr_T<_Interf>& cp)
  155. {
  156. return operator=(cp.m_pInterf);
  157. }
  158. void Attach(_Interf* pInterface)
  159. {
  160. InternalRelease();
  161. m_pInterf = pInterface;
  162. }
  163. _Interf* Detach()
  164. {
  165. _Interf* const pOld = m_pInterf;
  166. m_pInterf = NULL;
  167. return pOld;
  168. }
  169. void Release()
  170. {
  171. InternalRelease();
  172. m_pInterf = NULL;
  173. }
  174. operator _Interf*() const
  175. {
  176. return m_pInterf;
  177. }
  178. _Interf& operator*() const
  179. {
  180. return *m_pInterf;
  181. }
  182. // Returns the address of the interface pointer contained in this
  183. // class. This is required for initializing from C-style factory function to
  184. // avoid getting an incorrect ref count at the beginning.
  185. _Interf** operator&()
  186. {
  187. InternalRelease();
  188. m_pInterf = 0;
  189. return &m_pInterf;
  190. }
  191. _Interf* operator->() const
  192. {
  193. return m_pInterf;
  194. }
  195. bool operator==(const AMFInterfacePtr_T<_Interf>& p)
  196. {
  197. return (m_pInterf == p.m_pInterf);
  198. }
  199. bool operator==(_Interf* p)
  200. {
  201. return (m_pInterf == p);
  202. }
  203. bool operator!=(const AMFInterfacePtr_T<_Interf>& p)
  204. {
  205. return !(operator==(p));
  206. }
  207. bool operator!=(_Interf* p)
  208. {
  209. return !(operator==(p));
  210. }
  211. _Interf* GetPtr()
  212. {
  213. return m_pInterf;
  214. }
  215. const _Interf* GetPtr() const
  216. {
  217. return m_pInterf;
  218. }
  219. };
  220. //----------------------------------------------------------------------------------------------
  221. // smart pointer
  222. //----------------------------------------------------------------------------------------------
  223. typedef AMFInterfacePtr_T<AMFInterface> AMFInterfacePtr;
  224. //----------------------------------------------------------------------------------------------
  225. #endif
  226. #if defined(__cplusplus)
  227. }
  228. #endif
  229. #endif //#ifndef AMF_Interface_h