1 /* 2 * GStreamer 3 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com> 4 * Copyright (C) 2020 Seungha Yang <seungha@centricular.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __GST_D3D11_MEMORY_H__ 23 #define __GST_D3D11_MEMORY_H__ 24 25 #include <gst/gst.h> 26 #include <gst/video/video.h> 27 #include <gst/d3d11/gstd3d11_fwd.h> 28 #include <gst/d3d11/gstd3d11format.h> 29 30 G_BEGIN_DECLS 31 32 #define GST_TYPE_D3D11_ALLOCATION_PARAMS (gst_d3d11_allocation_params_get_type()) 33 34 #define GST_TYPE_D3D11_MEMORY (gst_d3d11_memory_get_type()) 35 #define GST_D3D11_MEMORY_CAST(obj) ((GstD3D11Memory *)obj) 36 37 #define GST_TYPE_D3D11_ALLOCATOR (gst_d3d11_allocator_get_type()) 38 #define GST_D3D11_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_D3D11_ALLOCATOR, GstD3D11Allocator)) 39 #define GST_D3D11_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_D3D11_ALLOCATOR, GstD3D11AllocatorClass)) 40 #define GST_IS_D3D11_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_D3D11_ALLOCATOR)) 41 #define GST_IS_D3D11_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_ALLOCATOR)) 42 #define GST_D3D11_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_ALLOCATOR, GstD3D11AllocatorClass)) 43 #define GST_D3D11_ALLOCATOR_CAST(obj) ((GstD3D11Allocator *)obj) 44 45 #define GST_TYPE_D3D11_POOL_ALLOCATOR (gst_d3d11_pool_allocator_get_type()) 46 #define GST_D3D11_POOL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_D3D11_POOL_ALLOCATOR, GstD3D11PoolAllocator)) 47 #define GST_D3D11_POOL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_D3D11_POOL_ALLOCATOR, GstD3D11PoolAllocatorClass)) 48 #define GST_IS_D3D11_POOL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_D3D11_POOL_ALLOCATOR)) 49 #define GST_IS_D3D11_POOL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_POOL_ALLOCATOR)) 50 #define GST_D3D11_POOL_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_POOL_ALLOCATOR, GstD3D11PoolAllocatorClass)) 51 #define GST_D3D11_POOL_ALLOCATOR_CAST(obj) ((GstD3D11PoolAllocator *)obj) 52 53 /** 54 * GST_D3D11_MEMORY_NAME: 55 * 56 * The name of the Direct3D11 memory 57 * 58 * Since: 1.20 59 */ 60 #define GST_D3D11_MEMORY_NAME "D3D11Memory" 61 62 /** 63 * GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY: 64 * 65 * Name of the caps feature for indicating the use of #GstD3D11Memory 66 * 67 * Since: 1.20 68 */ 69 #define GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY "memory:D3D11Memory" 70 71 /** 72 * GST_MAP_D3D11: 73 * 74 * Flag indicating that we should map the D3D11 resource instead of to system memory. 75 * 76 * Since: 1.20 77 */ 78 #define GST_MAP_D3D11 (GST_MAP_FLAG_LAST << 1) 79 80 /** 81 * GstD3D11AllocationFlags: 82 * @GST_D3D11_ALLOCATION_FLAG_TEXTURE_ARRAY: Indicates each allocated texture 83 * should be array type. This type of 84 * is used for D3D11/DXVA decoders 85 * in general. 86 * 87 * Since: 1.20 88 */ 89 typedef enum 90 { 91 GST_D3D11_ALLOCATION_FLAG_TEXTURE_ARRAY = (1 << 0), 92 } GstD3D11AllocationFlags; 93 94 /** 95 * GstD3D11MemoryTransfer: 96 * @GST_D3D11_MEMORY_TRANSFER_NEED_DOWNLOAD: the texture needs downloading 97 * to the staging texture memory 98 * @GST_D3D11_MEMORY_TRANSFER_NEED_UPLOAD: the staging texture needs uploading 99 * to the texture 100 * 101 * Since: 1.20 102 */ 103 typedef enum 104 { 105 GST_D3D11_MEMORY_TRANSFER_NEED_DOWNLOAD = (GST_MEMORY_FLAG_LAST << 0), 106 GST_D3D11_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1) 107 } GstD3D11MemoryTransfer; 108 109 struct _GstD3D11AllocationParams 110 { 111 /* Texture description per plane */ 112 D3D11_TEXTURE2D_DESC desc[GST_VIDEO_MAX_PLANES]; 113 114 GstVideoInfo info; 115 GstVideoInfo aligned_info; 116 const GstD3D11Format *d3d11_format; 117 118 GstD3D11AllocationFlags flags; 119 120 /*< private >*/ 121 gpointer _gst_reserved[GST_PADDING_LARGE]; 122 }; 123 124 GST_D3D11_API 125 GType gst_d3d11_allocation_params_get_type (void); 126 127 GST_D3D11_API 128 GstD3D11AllocationParams * gst_d3d11_allocation_params_new (GstD3D11Device * device, 129 GstVideoInfo * info, 130 GstD3D11AllocationFlags flags, 131 guint bind_flags); 132 133 GST_D3D11_API 134 GstD3D11AllocationParams * gst_d3d11_allocation_params_copy (GstD3D11AllocationParams * src); 135 136 GST_D3D11_API 137 void gst_d3d11_allocation_params_free (GstD3D11AllocationParams * params); 138 139 GST_D3D11_API 140 gboolean gst_d3d11_allocation_params_alignment (GstD3D11AllocationParams * parms, 141 GstVideoAlignment * align); 142 143 struct _GstD3D11Memory 144 { 145 GstMemory mem; 146 147 /*< public >*/ 148 GstD3D11Device *device; 149 150 /*< private >*/ 151 GstD3D11MemoryPrivate *priv; 152 gpointer _gst_reserved[GST_PADDING]; 153 }; 154 155 GST_D3D11_API 156 GType gst_d3d11_memory_get_type (void); 157 158 GST_D3D11_API 159 void gst_d3d11_memory_init_once (void); 160 161 GST_D3D11_API 162 gboolean gst_is_d3d11_memory (GstMemory * mem); 163 164 GST_D3D11_API 165 ID3D11Texture2D * gst_d3d11_memory_get_texture_handle (GstD3D11Memory * mem); 166 167 GST_D3D11_API 168 gboolean gst_d3d11_memory_get_texture_desc (GstD3D11Memory * mem, 169 D3D11_TEXTURE2D_DESC * desc); 170 171 GST_D3D11_API 172 gboolean gst_d3d11_memory_get_texture_stride (GstD3D11Memory * mem, 173 guint * stride); 174 175 GST_D3D11_API 176 guint gst_d3d11_memory_get_subresource_index (GstD3D11Memory * mem); 177 178 GST_D3D11_API 179 guint gst_d3d11_memory_get_shader_resource_view_size (GstD3D11Memory * mem); 180 181 GST_D3D11_API 182 ID3D11ShaderResourceView * gst_d3d11_memory_get_shader_resource_view (GstD3D11Memory * mem, 183 guint index); 184 185 GST_D3D11_API 186 guint gst_d3d11_memory_get_render_target_view_size (GstD3D11Memory * mem); 187 188 GST_D3D11_API 189 ID3D11RenderTargetView * gst_d3d11_memory_get_render_target_view (GstD3D11Memory * mem, 190 guint index); 191 192 GST_D3D11_API 193 ID3D11VideoDecoderOutputView * gst_d3d11_memory_get_decoder_output_view (GstD3D11Memory * mem, 194 ID3D11VideoDevice * video_device, 195 ID3D11VideoDecoder * decoder, 196 const GUID * decoder_profile); 197 198 GST_D3D11_API 199 ID3D11VideoProcessorInputView * gst_d3d11_memory_get_processor_input_view (GstD3D11Memory * mem, 200 ID3D11VideoDevice * video_device, 201 ID3D11VideoProcessorEnumerator * enumerator); 202 203 GST_D3D11_API 204 ID3D11VideoProcessorOutputView * gst_d3d11_memory_get_processor_output_view (GstD3D11Memory * mem, 205 ID3D11VideoDevice * video_device, 206 ID3D11VideoProcessorEnumerator * enumerator); 207 208 struct _GstD3D11Allocator 209 { 210 GstAllocator allocator; 211 212 /*< private >*/ 213 GstD3D11AllocatorPrivate *priv; 214 215 gpointer _gst_reserved[GST_PADDING]; 216 }; 217 218 struct _GstD3D11AllocatorClass 219 { 220 GstAllocatorClass allocator_class; 221 222 gboolean (*set_actvie) (GstD3D11Allocator * allocator, 223 gboolean active); 224 225 /*< private >*/ 226 gpointer _gst_reserved[GST_PADDING_LARGE]; 227 }; 228 229 GST_D3D11_API 230 GType gst_d3d11_allocator_get_type (void); 231 232 GST_D3D11_API 233 GstMemory * gst_d3d11_allocator_alloc (GstD3D11Allocator * allocator, 234 GstD3D11Device * device, 235 const D3D11_TEXTURE2D_DESC * desc); 236 237 GST_D3D11_API 238 gboolean gst_d3d11_allocator_set_active (GstD3D11Allocator * allocator, 239 gboolean active); 240 241 struct _GstD3D11PoolAllocator 242 { 243 GstD3D11Allocator allocator; 244 245 /*< public >*/ 246 GstD3D11Device *device; 247 248 /*< private >*/ 249 GstD3D11PoolAllocatorPrivate *priv; 250 251 gpointer _gst_reserved[GST_PADDING]; 252 }; 253 254 struct _GstD3D11PoolAllocatorClass 255 { 256 GstD3D11AllocatorClass allocator_class; 257 258 /*< private >*/ 259 gpointer _gst_reserved[GST_PADDING]; 260 }; 261 262 GST_D3D11_API 263 GType gst_d3d11_pool_allocator_get_type (void); 264 265 GST_D3D11_API 266 GstD3D11PoolAllocator * gst_d3d11_pool_allocator_new (GstD3D11Device * device, 267 const D3D11_TEXTURE2D_DESC * desc); 268 269 GST_D3D11_API 270 GstFlowReturn gst_d3d11_pool_allocator_acquire_memory (GstD3D11PoolAllocator * allocator, 271 GstMemory ** memory); 272 273 GST_D3D11_API 274 gboolean gst_d3d11_pool_allocator_get_pool_size (GstD3D11PoolAllocator * allocator, 275 guint * max_size, 276 guint * outstanding_size); 277 278 G_END_DECLS 279 280 #endif /* __GST_D3D11_MEMORY_H__ */ 281