Surface.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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_P012, ///< 18 - planar 4:2:0 Y width x height + packed UV width/2 x height/2 - 12 bit per component (16 allocated, upper 12 bits are used)
  69. AMF_SURFACE_P016, ///< 19 - planar 4:2:0 Y width x height + packed UV width/2 x height/2 - 16 bit per component (16 allocated, all bits are used)
  70. AMF_SURFACE_FIRST = AMF_SURFACE_NV12,
  71. AMF_SURFACE_LAST = AMF_SURFACE_P016
  72. } AMF_SURFACE_FORMAT;
  73. //----------------------------------------------------------------------------------------------
  74. // AMF_SURFACE_USAGE translates to D3D11_BIND_FLAG or VkImageUsageFlags
  75. // bit mask
  76. //----------------------------------------------------------------------------------------------
  77. typedef enum AMF_SURFACE_USAGE_BITS
  78. { // D3D11 D3D12 Vulkan
  79. 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
  80. AMF_SURFACE_USAGE_NONE = 0x00000000, // 0, D3D12_RESOURCE_FLAG_NONE, 0
  81. 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
  82. AMF_SURFACE_USAGE_RENDER_TARGET = 0x00000002, // D3D11_BIND_RENDER_TARGET, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
  83. 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
  84. AMF_SURFACE_USAGE_TRANSFER_SRC = 0x00000008, // D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_TRANSFER_SRC_BIT
  85. AMF_SURFACE_USAGE_TRANSFER_DST = 0x00000010, // D3D12_RESOURCE_FLAG_NONE VK_IMAGE_USAGE_TRANSFER_DST_BIT
  86. AMF_SURFACE_USAGE_LINEAR = 0x00000020
  87. } AMF_SURFACE_USAGE_BITS;
  88. typedef amf_flags AMF_SURFACE_USAGE;
  89. //----------------------------------------------------------------------------------------------
  90. #if defined(_WIN32)
  91. 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)
  92. #endif
  93. //----------------------------------------------------------------------------------------------
  94. // frame type
  95. //----------------------------------------------------------------------------------------------
  96. typedef enum AMF_FRAME_TYPE
  97. {
  98. // flags
  99. AMF_FRAME_STEREO_FLAG = 0x10000000,
  100. AMF_FRAME_LEFT_FLAG = AMF_FRAME_STEREO_FLAG | 0x20000000,
  101. AMF_FRAME_RIGHT_FLAG = AMF_FRAME_STEREO_FLAG | 0x40000000,
  102. AMF_FRAME_BOTH_FLAG = AMF_FRAME_LEFT_FLAG | AMF_FRAME_RIGHT_FLAG,
  103. AMF_FRAME_INTERLEAVED_FLAG = 0x01000000,
  104. AMF_FRAME_FIELD_FLAG = 0x02000000,
  105. AMF_FRAME_EVEN_FLAG = 0x04000000,
  106. AMF_FRAME_ODD_FLAG = 0x08000000,
  107. // values
  108. AMF_FRAME_UNKNOWN =-1,
  109. AMF_FRAME_PROGRESSIVE = 0,
  110. AMF_FRAME_INTERLEAVED_EVEN_FIRST = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG,
  111. AMF_FRAME_INTERLEAVED_ODD_FIRST = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG,
  112. AMF_FRAME_FIELD_SINGLE_EVEN = AMF_FRAME_FIELD_FLAG | AMF_FRAME_EVEN_FLAG,
  113. AMF_FRAME_FIELD_SINGLE_ODD = AMF_FRAME_FIELD_FLAG | AMF_FRAME_ODD_FLAG,
  114. AMF_FRAME_STEREO_LEFT = AMF_FRAME_LEFT_FLAG,
  115. AMF_FRAME_STEREO_RIGHT = AMF_FRAME_RIGHT_FLAG,
  116. AMF_FRAME_STEREO_BOTH = AMF_FRAME_BOTH_FLAG,
  117. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_LEFT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_LEFT_FLAG,
  118. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_RIGHT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_RIGHT_FLAG,
  119. AMF_FRAME_INTERLEAVED_EVEN_FIRST_STEREO_BOTH = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_EVEN_FLAG | AMF_FRAME_BOTH_FLAG,
  120. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_LEFT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_LEFT_FLAG,
  121. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_RIGHT = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_RIGHT_FLAG,
  122. AMF_FRAME_INTERLEAVED_ODD_FIRST_STEREO_BOTH = AMF_FRAME_INTERLEAVED_FLAG | AMF_FRAME_ODD_FLAG | AMF_FRAME_BOTH_FLAG,
  123. } AMF_FRAME_TYPE;
  124. typedef enum AMF_ROTATION_ENUM
  125. {
  126. AMF_ROTATION_NONE = 0,
  127. AMF_ROTATION_90 = 1,
  128. AMF_ROTATION_180 = 2,
  129. AMF_ROTATION_270 = 3,
  130. } AMF_ROTATION_ENUM;
  131. #define AMF_SURFACE_ROTATION L"Rotation" // amf_int64(AMF_ROTATION_ENUM); default = AMF_ROTATION_NONE, can be set on surfaces
  132. //----------------------------------------------------------------------------------------------
  133. // AMFSurfaceObserver interface - callback; is called before internal release resources.
  134. //----------------------------------------------------------------------------------------------
  135. #if defined(__cplusplus)
  136. class AMFSurface;
  137. class AMF_NO_VTABLE AMFSurfaceObserver
  138. {
  139. public:
  140. virtual void AMF_STD_CALL OnSurfaceDataRelease(AMFSurface* pSurface) = 0;
  141. };
  142. #else // #if defined(__cplusplus)
  143. typedef struct AMFSurface AMFSurface;
  144. typedef struct AMFSurfaceObserver AMFSurfaceObserver;
  145. typedef struct AMFSurfaceObserverVtbl
  146. {
  147. void (AMF_STD_CALL *OnSurfaceDataRelease)(AMFSurfaceObserver* pThis, AMFSurface* pSurface);
  148. } AMFSurfaceObserverVtbl;
  149. struct AMFSurfaceObserver
  150. {
  151. const AMFSurfaceObserverVtbl *pVtbl;
  152. };
  153. #endif // #if defined(__cplusplus)
  154. //----------------------------------------------------------------------------------------------
  155. // AMFSurface interface
  156. //----------------------------------------------------------------------------------------------
  157. #if defined(__cplusplus)
  158. class AMF_NO_VTABLE AMFSurface : public AMFData
  159. {
  160. public:
  161. AMF_DECLARE_IID(0x3075dbe3, 0x8718, 0x4cfa, 0x86, 0xfb, 0x21, 0x14, 0xc0, 0xa5, 0xa4, 0x51)
  162. virtual AMF_SURFACE_FORMAT AMF_STD_CALL GetFormat() = 0;
  163. // do not store planes outside. should be used together with Surface
  164. virtual amf_size AMF_STD_CALL GetPlanesCount() = 0;
  165. virtual AMFPlane* AMF_STD_CALL GetPlaneAt(amf_size index) = 0;
  166. virtual AMFPlane* AMF_STD_CALL GetPlane(AMF_PLANE_TYPE type) = 0;
  167. virtual AMF_FRAME_TYPE AMF_STD_CALL GetFrameType() = 0;
  168. virtual void AMF_STD_CALL SetFrameType(AMF_FRAME_TYPE type) = 0;
  169. virtual AMF_RESULT AMF_STD_CALL SetCrop(amf_int32 x,amf_int32 y, amf_int32 width, amf_int32 height) = 0;
  170. 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;
  171. // Observer management
  172. #ifdef __clang__
  173. #pragma clang diagnostic push
  174. #pragma clang diagnostic ignored "-Woverloaded-virtual"
  175. #endif
  176. virtual void AMF_STD_CALL AddObserver(AMFSurfaceObserver* pObserver) = 0;
  177. virtual void AMF_STD_CALL RemoveObserver(AMFSurfaceObserver* pObserver) = 0;
  178. #ifdef __clang__
  179. #pragma clang diagnostic pop
  180. #endif
  181. };
  182. //----------------------------------------------------------------------------------------------
  183. // smart pointer
  184. //----------------------------------------------------------------------------------------------
  185. typedef AMFInterfacePtr_T<AMFSurface> AMFSurfacePtr;
  186. //----------------------------------------------------------------------------------------------
  187. #else // #if defined(__cplusplus)
  188. AMF_DECLARE_IID(AMFSurface, 0x3075dbe3, 0x8718, 0x4cfa, 0x86, 0xfb, 0x21, 0x14, 0xc0, 0xa5, 0xa4, 0x51)
  189. typedef struct AMFSurfaceVtbl
  190. {
  191. // AMFInterface interface
  192. amf_long (AMF_STD_CALL *Acquire)(AMFSurface* pThis);
  193. amf_long (AMF_STD_CALL *Release)(AMFSurface* pThis);
  194. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFSurface* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  195. // AMFPropertyStorage interface
  196. AMF_RESULT (AMF_STD_CALL *SetProperty)(AMFSurface* pThis, const wchar_t* name, AMFVariantStruct value);
  197. AMF_RESULT (AMF_STD_CALL *GetProperty)(AMFSurface* pThis, const wchar_t* name, AMFVariantStruct* pValue);
  198. amf_bool (AMF_STD_CALL *HasProperty)(AMFSurface* pThis, const wchar_t* name);
  199. amf_size (AMF_STD_CALL *GetPropertyCount)(AMFSurface* pThis);
  200. AMF_RESULT (AMF_STD_CALL *GetPropertyAt)(AMFSurface* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
  201. AMF_RESULT (AMF_STD_CALL *Clear)(AMFSurface* pThis);
  202. AMF_RESULT (AMF_STD_CALL *AddTo)(AMFSurface* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
  203. AMF_RESULT (AMF_STD_CALL *CopyTo)(AMFSurface* pThis, AMFPropertyStorage* pDest, amf_bool deep);
  204. void (AMF_STD_CALL *AddObserver)(AMFSurface* pThis, AMFPropertyStorageObserver* pObserver);
  205. void (AMF_STD_CALL *RemoveObserver)(AMFSurface* pThis, AMFPropertyStorageObserver* pObserver);
  206. // AMFData interface
  207. AMF_MEMORY_TYPE (AMF_STD_CALL *GetMemoryType)(AMFSurface* pThis);
  208. AMF_RESULT (AMF_STD_CALL *Duplicate)(AMFSurface* pThis, AMF_MEMORY_TYPE type, AMFData** ppData);
  209. AMF_RESULT (AMF_STD_CALL *Convert)(AMFSurface* pThis, AMF_MEMORY_TYPE type); // optimal interop if possilble. Copy through host memory if needed
  210. 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
  211. AMF_DATA_TYPE (AMF_STD_CALL *GetDataType)(AMFSurface* pThis);
  212. amf_bool (AMF_STD_CALL *IsReusable)(AMFSurface* pThis);
  213. void (AMF_STD_CALL *SetPts)(AMFSurface* pThis, amf_pts pts);
  214. amf_pts (AMF_STD_CALL *GetPts)(AMFSurface* pThis);
  215. void (AMF_STD_CALL *SetDuration)(AMFSurface* pThis, amf_pts duration);
  216. amf_pts (AMF_STD_CALL *GetDuration)(AMFSurface* pThis);
  217. // AMFSurface interface
  218. AMF_SURFACE_FORMAT (AMF_STD_CALL *GetFormat)(AMFSurface* pThis);
  219. // do not store planes outside. should be used together with Surface
  220. amf_size (AMF_STD_CALL *GetPlanesCount)(AMFSurface* pThis);
  221. AMFPlane* (AMF_STD_CALL *GetPlaneAt)(AMFSurface* pThis, amf_size index);
  222. AMFPlane* (AMF_STD_CALL *GetPlane)(AMFSurface* pThis, AMF_PLANE_TYPE type);
  223. AMF_FRAME_TYPE (AMF_STD_CALL *GetFrameType)(AMFSurface* pThis);
  224. void (AMF_STD_CALL *SetFrameType)(AMFSurface* pThis, AMF_FRAME_TYPE type);
  225. AMF_RESULT (AMF_STD_CALL *SetCrop)(AMFSurface* pThis, amf_int32 x,amf_int32 y, amf_int32 width, amf_int32 height);
  226. 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);
  227. // Observer management
  228. void (AMF_STD_CALL *AddObserver_Surface)(AMFSurface* pThis, AMFSurfaceObserver* pObserver);
  229. void (AMF_STD_CALL *RemoveObserver_Surface)(AMFSurface* pThis, AMFSurfaceObserver* pObserver);
  230. } AMFSurfaceVtbl;
  231. struct AMFSurface
  232. {
  233. const AMFSurfaceVtbl *pVtbl;
  234. };
  235. #endif // #if defined(__cplusplus)
  236. #if defined(__cplusplus)
  237. }
  238. #endif
  239. #if defined(_MSC_VER)
  240. #pragma warning( pop )
  241. #endif
  242. #endif //#ifndef AMF_Surface_h