Surface.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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_Surface_h
  33. #define AMF_Surface_h
  34. #pragma once
  35. #include "Data.h"
  36. #include "Plane.h"
  37. #if defined(_MSC_VER)
  38. #pragma warning( push )
  39. #pragma warning(disable : 4263)
  40. #pragma warning(disable : 4264)
  41. #endif
  42. #if defined(__cplusplus)
  43. namespace amf
  44. {
  45. #endif
  46. //----------------------------------------------------------------------------------------------
  47. typedef enum AMF_SURFACE_FORMAT
  48. {
  49. AMF_SURFACE_UNKNOWN = 0,
  50. AMF_SURFACE_NV12, ///< 1 - planar 4:2:0 Y width x height + packed UV width/2 x height/2 - 8 bit per component
  51. AMF_SURFACE_YV12, ///< 2 - planar 4:2:0 Y width x height + V width/2 x height/2 + U width/2 x height/2 - 8 bit per component
  52. AMF_SURFACE_BGRA, ///< 3 - packed 4:4:4 - 8 bit per component
  53. AMF_SURFACE_ARGB, ///< 4 - packed 4:4:4 - 8 bit per component
  54. AMF_SURFACE_RGBA, ///< 5 - packed 4:4:4 - 8 bit per component
  55. AMF_SURFACE_GRAY8, ///< 6 - single component - 8 bit
  56. AMF_SURFACE_YUV420P, ///< 7 - planar 4:2:0 Y width x height + U width/2 x height/2 + V width/2 x height/2 - 8 bit per component
  57. AMF_SURFACE_U8V8, ///< 8 - packed double component - 8 bit per component
  58. AMF_SURFACE_YUY2, ///< 9 - packed 4:2:2 Byte 0=8-bit Y'0; Byte 1=8-bit Cb; Byte 2=8-bit Y'1; Byte 3=8-bit Cr
  59. AMF_SURFACE_P010, ///< 10 - planar 4:2:0 Y width x height + packed UV width/2 x height/2 - 10 bit per component (16 allocated, upper 10 bits are used)
  60. AMF_SURFACE_RGBA_F16, ///< 11 - packed 4:4:4 - 16 bit per component float
  61. AMF_SURFACE_UYVY, ///< 12 - packed 4:2:2 the similar to YUY2 but Y and UV swapped: Byte 0=8-bit Cb; Byte 1=8-bit Y'0; Byte 2=8-bit Cr Byte 3=8-bit Y'1; (used the same DX/CL/Vulkan storage as YUY2)
  62. AMF_SURFACE_R10G10B10A2, ///< 13 - packed 4:4:4 to 4 bytes, 10 bit per RGB component, 2 bits per A
  63. AMF_SURFACE_Y210, ///< 14 - packed 4:2:2 - Word 0=10-bit Y'0; Word 1=10-bit Cb; Word 2=10-bit Y'1; Word 3=10-bit Cr
  64. AMF_SURFACE_AYUV, ///< 15 - packed 4:4:4 - 8 bit per component YUVA
  65. AMF_SURFACE_Y410, ///< 16 - packed 4:4:4 - 10 bit per YUV component, 2 bits per A, AVYU
  66. AMF_SURFACE_Y416, ///< 16 - packed 4:4:4 - 16 bit per component 4 bytes, AVYU
  67. AMF_SURFACE_GRAY32, ///< 17 - single component - 32 bit
  68. AMF_SURFACE_FIRST = AMF_SURFACE_NV12,
  69. AMF_SURFACE_LAST = AMF_SURFACE_GRAY32
  70. } AMF_SURFACE_FORMAT;
  71. //----------------------------------------------------------------------------------------------
  72. // AMF_SURFACE_USAGE translates to D3D11_BIND_FLAG or VkImageUsageFlags
  73. // bit mask
  74. //----------------------------------------------------------------------------------------------
  75. typedef enum AMF_SURFACE_USAGE_BITS
  76. { // D3D11 D3D12 Vulkan
  77. AMF_SURFACE_USAGE_DEFAULT = 0x80000000, // will apply default D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_TRANSFER_SRC_BIT| VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  78. AMF_SURFACE_USAGE_NONE = 0x00000000, // 0, D3D12_RESOURCE_FLAG_NONE, 0
  79. AMF_SURFACE_USAGE_SHADER_RESOURCE = 0x00000001, // D3D11_BIND_SHADER_RESOURCE, D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  80. AMF_SURFACE_USAGE_RENDER_TARGET = 0x00000002, // D3D11_BIND_RENDER_TARGET, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
  81. AMF_SURFACE_USAGE_UNORDERED_ACCESS = 0x00000004, // D3D11_BIND_UNORDERED_ACCESS, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  82. AMF_SURFACE_USAGE_TRANSFER_SRC = 0x00000008, // D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_TRANSFER_SRC_BIT
  83. AMF_SURFACE_USAGE_TRANSFER_DST = 0x00000010, // D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_TRANSFER_DST_BIT
  84. AMF_SURFACE_USAGE_LINEAR = 0x00000020
  85. } AMF_SURFACE_USAGE_BITS;
  86. typedef amf_flags AMF_SURFACE_USAGE;
  87. //----------------------------------------------------------------------------------------------
  88. #if defined(_WIN32)
  89. AMF_WEAK GUID AMFFormatGUID = { 0x8cd592d0, 0x8063, 0x4af8, {0xa7, 0xd0, 0x32, 0x5b, 0xc5, 0xf7, 0x48, 0xab}}; // UINT(AMF_SURFACE_FORMAT), default - AMF_SURFACE_UNKNOWN; to be set on ID3D11Texture2D objects when used natively (i.e. force UYVY on DXGI_FORMAT_YUY2 texture)
  90. #endif
  91. //----------------------------------------------------------------------------------------------
  92. // frame type
  93. //----------------------------------------------------------------------------------------------
  94. typedef enum AMF_FRAME_TYPE
  95. {
  96. // flags
  97. AMF_FRAME_STEREO_FLAG = 0x10000000,
  98. AMF_FRAME_LEFT_FLAG = AMF_FRAME_STEREO_FLAG | 0x20000000,
  99. AMF_FRAME_RIGHT_FLAG = AMF_FRAME_STEREO_FLAG | 0x40000000,
  100. AMF_FRAME_BOTH_FLAG = AMF_FRAME_LEFT_FLAG | AMF_FRAME_RIGHT_FLAG,
  101. AMF_FRAME_INTERLEAVED_FLAG = 0x01000000,
  102. AMF_FRAME_FIELD_FLAG = 0x02000000,
  103. AMF_FRAME_EVEN_FLAG = 0x04000000,
  104. AMF_FRAME_ODD_FLAG = 0x08000000,
  105. // values
  106. AMF_FRAME_UNKNOWN =-1,
  107. AMF_FRAME_PROGRESSIVE = 0,
  108. AMF_FRAME_INTERLEAVED_EVEN_FIRST = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG,
  109. AMF_FRAME_INTERLEAVED_ODD_FIRST = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG,
  110. AMF_FRAME_FIELD_SINGLE_EVEN = AMF_FRAME_FIELD_FLAG | AMF_FRAME_EVEN_FLAG,
  111. AMF_FRAME_FIELD_SINGLE_ODD = AMF_FRAME_FIELD_FLAG | AMF_FRAME_ODD_FLAG,
  112. AMF_FRAME_STEREO_LEFT = AMF_FRAME_LEFT_FLAG,
  113. AMF_FRAME_STEREO_RIGHT = AMF_FRAME_RIGHT_FLAG,
  114. AMF_FRAME_STEREO_BOTH = AMF_FRAME_BOTH_FLAG,
  115. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_LEFT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_LEFT_FLAG,
  116. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_RIGHT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_RIGHT_FLAG,
  117. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_BOTH = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_BOTH_FLAG,
  118. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_LEFT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_LEFT_FLAG,
  119. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_RIGHT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_RIGHT_FLAG,
  120. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_BOTH = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_BOTH_FLAG,
  121. } AMF_FRAME_TYPE;
  122. typedef enum AMF_ROTATION_ENUM
  123. {
  124. AMF_ROTATION_NONE = 0,
  125. AMF_ROTATION_90 = 1,
  126. AMF_ROTATION_180 = 2,
  127. AMF_ROTATION_270 = 3,
  128. } AMF_ROTATION_ENUM;
  129. #define AMF_SURFACE_ROTATION L"Rotation" // amf_int64(AMF_ROTATION_ENUM); default = AMF_ROTATION_NONE, can be set on surfaces
  130. //----------------------------------------------------------------------------------------------
  131. // AMFSurfaceObserver interface - callback; is called before internal release resources.
  132. //----------------------------------------------------------------------------------------------
  133. #if defined(__cplusplus)
  134. class AMFSurface;
  135. class AMF_NO_VTABLE AMFSurfaceObserver
  136. {
  137. public:
  138. virtual void AMF_STD_CALL OnSurfaceDataRelease(AMFSurface* pSurface) = 0;
  139. };
  140. #else // #if defined(__cplusplus)
  141. typedef struct AMFSurface AMFSurface;
  142. typedef struct AMFSurfaceObserver AMFSurfaceObserver;
  143. typedef struct AMFSurfaceObserverVtbl
  144. {
  145. void (AMF_STD_CALL *OnSurfaceDataRelease)(AMFSurfaceObserver* pThis, AMFSurface* pSurface);
  146. } AMFSurfaceObserverVtbl;
  147. struct AMFSurfaceObserver
  148. {
  149. const AMFSurfaceObserverVtbl *pVtbl;
  150. };
  151. #endif // #if defined(__cplusplus)
  152. //----------------------------------------------------------------------------------------------
  153. // AMFSurface interface
  154. //----------------------------------------------------------------------------------------------
  155. #if defined(__cplusplus)
  156. class AMF_NO_VTABLE AMFSurface : public AMFData
  157. {
  158. public:
  159. AMF_DECLARE_IID(0x3075dbe3, 0x8718, 0x4cfa, 0x86, 0xfb, 0x21, 0x14, 0xc0, 0xa5, 0xa4, 0x51)
  160. virtual AMF_SURFACE_FORMAT AMF_STD_CALL GetFormat() = 0;
  161. // do not store planes outside. should be used together with Surface
  162. virtual amf_size AMF_STD_CALL GetPlanesCount() = 0;
  163. virtual AMFPlane* AMF_STD_CALL GetPlaneAt(amf_size index) = 0;
  164. virtual AMFPlane* AMF_STD_CALL GetPlane(AMF_PLANE_TYPE type) = 0;
  165. virtual AMF_FRAME_TYPE AMF_STD_CALL GetFrameType() = 0;
  166. virtual void AMF_STD_CALL SetFrameType(AMF_FRAME_TYPE type) = 0;
  167. virtual AMF_RESULT AMF_STD_CALL SetCrop(amf_int32 x,amf_int32 y, amf_int32 width, amf_int32 height) = 0;
  168. virtual AMF_RESULT AMF_STD_CALL CopySurfaceRegion(AMFSurface* pDest, amf_int32 dstX, amf_int32 dstY, amf_int32 srcX, amf_int32 srcY, amf_int32 width, amf_int32 height) = 0;
  169. // Observer management
  170. #ifdef __clang__
  171. #pragma clang diagnostic push
  172. #pragma clang diagnostic ignored "-Woverloaded-virtual"
  173. #endif
  174. virtual void AMF_STD_CALL AddObserver(AMFSurfaceObserver* pObserver) = 0;
  175. virtual void AMF_STD_CALL RemoveObserver(AMFSurfaceObserver* pObserver) = 0;
  176. #ifdef __clang__
  177. #pragma clang diagnostic pop
  178. #endif
  179. };
  180. //----------------------------------------------------------------------------------------------
  181. // smart pointer
  182. //----------------------------------------------------------------------------------------------
  183. typedef AMFInterfacePtr_T<AMFSurface> AMFSurfacePtr;
  184. //----------------------------------------------------------------------------------------------
  185. #else // #if defined(__cplusplus)
  186. AMF_DECLARE_IID(AMFSurface, 0x3075dbe3, 0x8718, 0x4cfa, 0x86, 0xfb, 0x21, 0x14, 0xc0, 0xa5, 0xa4, 0x51)
  187. typedef struct AMFSurfaceVtbl
  188. {
  189. // AMFInterface interface
  190. amf_long (AMF_STD_CALL *Acquire)(AMFSurface* pThis);
  191. amf_long (AMF_STD_CALL *Release)(AMFSurface* pThis);
  192. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFSurface* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  193. // AMFPropertyStorage interface
  194. AMF_RESULT (AMF_STD_CALL *SetProperty)(AMFSurface* pThis, const wchar_t* name, AMFVariantStruct value);
  195. AMF_RESULT (AMF_STD_CALL *GetProperty)(AMFSurface* pThis, const wchar_t* name, AMFVariantStruct* pValue);
  196. amf_bool (AMF_STD_CALL *HasProperty)(AMFSurface* pThis, const wchar_t* name);
  197. amf_size (AMF_STD_CALL *GetPropertyCount)(AMFSurface* pThis);
  198. AMF_RESULT (AMF_STD_CALL *GetPropertyAt)(AMFSurface* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
  199. AMF_RESULT (AMF_STD_CALL *Clear)(AMFSurface* pThis);
  200. AMF_RESULT (AMF_STD_CALL *AddTo)(AMFSurface* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
  201. AMF_RESULT (AMF_STD_CALL *CopyTo)(AMFSurface* pThis, AMFPropertyStorage* pDest, amf_bool deep);
  202. void (AMF_STD_CALL *AddObserver)(AMFSurface* pThis, AMFPropertyStorageObserver* pObserver);
  203. void (AMF_STD_CALL *RemoveObserver)(AMFSurface* pThis, AMFPropertyStorageObserver* pObserver);
  204. // AMFData interface
  205. AMF_MEMORY_TYPE (AMF_STD_CALL *GetMemoryType)(AMFSurface* pThis);
  206. AMF_RESULT (AMF_STD_CALL *Duplicate)(AMFSurface* pThis, AMF_MEMORY_TYPE type, AMFData** ppData);
  207. AMF_RESULT (AMF_STD_CALL *Convert)(AMFSurface* pThis, AMF_MEMORY_TYPE type); // optimal interop if possilble. Copy through host memory if needed
  208. AMF_RESULT (AMF_STD_CALL *Interop)(AMFSurface* pThis, AMF_MEMORY_TYPE type); // only optimal interop if possilble. No copy through host memory for GPU objects
  209. AMF_DATA_TYPE (AMF_STD_CALL *GetDataType)(AMFSurface* pThis);
  210. amf_bool (AMF_STD_CALL *IsReusable)(AMFSurface* pThis);
  211. void (AMF_STD_CALL *SetPts)(AMFSurface* pThis, amf_pts pts);
  212. amf_pts (AMF_STD_CALL *GetPts)(AMFSurface* pThis);
  213. void (AMF_STD_CALL *SetDuration)(AMFSurface* pThis, amf_pts duration);
  214. amf_pts (AMF_STD_CALL *GetDuration)(AMFSurface* pThis);
  215. // AMFSurface interface
  216. AMF_SURFACE_FORMAT (AMF_STD_CALL *GetFormat)(AMFSurface* pThis);
  217. // do not store planes outside. should be used together with Surface
  218. amf_size (AMF_STD_CALL *GetPlanesCount)(AMFSurface* pThis);
  219. AMFPlane* (AMF_STD_CALL *GetPlaneAt)(AMFSurface* pThis, amf_size index);
  220. AMFPlane* (AMF_STD_CALL *GetPlane)(AMFSurface* pThis, AMF_PLANE_TYPE type);
  221. AMF_FRAME_TYPE (AMF_STD_CALL *GetFrameType)(AMFSurface* pThis);
  222. void (AMF_STD_CALL *SetFrameType)(AMFSurface* pThis, AMF_FRAME_TYPE type);
  223. AMF_RESULT (AMF_STD_CALL *SetCrop)(AMFSurface* pThis, amf_int32 x,amf_int32 y, amf_int32 width, amf_int32 height);
  224. AMF_RESULT (AMF_STD_CALL *CopySurfaceRegion)(AMFSurface* pThis, AMFSurface* pDest, amf_int32 dstX, amf_int32 dstY, amf_int32 srcX, amf_int32 srcY, amf_int32 width, amf_int32 height);
  225. // Observer management
  226. void (AMF_STD_CALL *AddObserver_Surface)(AMFSurface* pThis, AMFSurfaceObserver* pObserver);
  227. void (AMF_STD_CALL *RemoveObserver_Surface)(AMFSurface* pThis, AMFSurfaceObserver* pObserver);
  228. } AMFSurfaceVtbl;
  229. struct AMFSurface
  230. {
  231. const AMFSurfaceVtbl *pVtbl;
  232. };
  233. #endif // #if defined(__cplusplus)
  234. #if defined(__cplusplus)
  235. }
  236. #endif
  237. #if defined(_MSC_VER)
  238. #pragma warning( pop )
  239. #endif
  240. #endif //#ifndef AMF_Surface_h