| 6 |
| * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * FFmpeg is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with FFmpeg; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #ifndef AVUTIL_HWCONTEXT_D3D11VA_H |
| 20 | #define AVUTIL_HWCONTEXT_D3D11VA_H |
| 21 |
| 22 | /** |
| 23 | * @file |
| 24 | * An API-specific header for AV_HWDEVICE_TYPE_D3D11VA. |
| 25 | * |
| 26 | * The default pool implementation will be fixed-size if initial_pool_size is |
| 27 | * set (and allocate elements from an array texture). Otherwise it will allocate |
| 28 | * individual textures. Be aware that decoding requires a single array texture. |
| 29 | * |
| 30 | * Using sw_format==AV_PIX_FMT_YUV420P has special semantics, and maps to |
| 31 | * DXGI_FORMAT_420_OPAQUE. av_hwframe_transfer_data() is not supported for |
| 32 | * this format. Refer to MSDN for details. |
| 33 | * |
| 34 | * av_hwdevice_ctx_create() for this device type supports a key named "debug" |
| 35 | * for the AVDictionary entry. If this is set to any value, the device creation |
| 36 | * code will try to load various supported D3D debugging layers. |
| 37 | */ |
| 38 |
| 39 | #include <d3d11.h> |
| 40 | #include <stdint.h> |
| 41 |
| 42 | /** |
| 43 | * This struct is allocated as AVHWDeviceContext.hwctx |
| 44 | */ |
| 45 | typedef struct AVD3D11VADeviceContext { |
| 46 | /** |
| 47 | * Device used for texture creation and access. This can also be used to |
| 48 | * set the libavcodec decoding device. |
| 49 | * |
| 50 | * Must be set by the user. This is the only mandatory field - the other |
| 51 | * device context fields are set from this and are available for convenience. |
| 52 | * |
| 53 | * Deallocating the AVHWDeviceContext will always release this interface, |
| 54 | * and it does not matter whether it was user-allocated. |
| 55 | */ |
| 56 | ID3D11Device *device; |
| 57 |
| 58 | /** |
| 59 | * If unset, this will be set from the device field on init. |
| 60 | * |
| 61 | * Deallocating the AVHWDeviceContext will always release this interface, |
| 62 | * and it does not matter whether it was user-allocated. |
| 63 | */ |
| 64 | ID3D11DeviceContext *device_context; |
| 65 |
| 66 | /** |
| 67 | * If unset, this will be set from the device field on init. |
| 68 | * |
| 69 | * Deallocating the AVHWDeviceContext will always release this interface, |
| 70 | * and it does not matter whether it was user-allocated. |
| 71 | */ |
| 72 | ID3D11VideoDevice *video_device; |
| 73 |
| 74 | /** |
| 75 | * If unset, this will be set from the device_context field on init. |
| 76 | * |
| 77 | * Deallocating the AVHWDeviceContext will always release this interface, |
| 78 | * and it does not matter whether it was user-allocated. |
| 79 | */ |
| 80 | ID3D11VideoContext *video_context; |
| 81 |
| 82 | /** |
| 83 | * Callbacks for locking. They protect accesses to device_context and |
| 84 | * video_context calls. They also protect access to the internal staging |
| 85 | * texture (for av_hwframe_transfer_data() calls). They do NOT protect |
| 86 | * access to hwcontext or decoder state in general. |
| 87 | * |
| 88 | * If unset on init, the hwcontext implementation will set them to use an |
| 89 | * internal mutex. |
| 90 | * |
| 91 | * The underlying lock must be recursive. lock_ctx is for free use by the |
| 92 | * locking implementation. |
| 93 | */ |
| 94 | void (*lock)(void *lock_ctx); |
| 95 | void (*unlock)(void *lock_ctx); |
| 96 | void *lock_ctx; |
| 97 | /** |
| 98 | * D3D11_TEXTURE2D_DESC.BindFlags to be applied to D3D11 resources allocated |
| 99 | * for frames using this device context. |
| 100 | * |
| 101 | * It applies globally to all AVD3D11VAFramesContext allocated from this device context. |
| 102 | */ |
| 103 | UINT BindFlags; |
| 104 | /** |
| 105 | * D3D11_TEXTURE2D_DESC.MiscFlags to be applied to D3D11 resources allocated |
| 106 | * for frames using this device context. |
| 107 | * |
| 108 | * It applies globally to all AVD3D11VAFramesContext allocated from this device context. |
| 109 | */ |
| 110 | UINT MiscFlags; |
| 111 | } AVD3D11VADeviceContext; |
| 112 |
| 113 | /** |
| 114 | * D3D11 frame descriptor for pool allocation. |
| 115 | * |
| 116 | * In user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs |
| 117 | * with the data pointer pointing at an object of this type describing the |
| 118 | * planes of the frame. |
| 119 | * |
| 120 | * This has no use outside of custom allocation, and AVFrame AVBufferRef do not |
| 121 | * necessarily point to an instance of this struct. |
| 122 | */ |
| 123 | typedef struct AVD3D11FrameDescriptor { |
| 124 | /** |
| 125 | * The texture in which the frame is located. The reference count is |
| 126 | * managed by the AVBufferRef, and destroying the reference will release |
| 127 | * the interface. |
| 128 | * |
| 129 | * Normally stored in AVFrame.data[0]. |
| 130 | */ |
| 131 | ID3D11Texture2D *texture; |
| 132 |
| 133 | /** |
| 134 | * The index into the array texture element representing the frame, or 0 |
| 135 | * if the texture is not an array texture. |
| 136 | * |
| 137 | * Normally stored in AVFrame.data[1] (cast from intptr_t). |
| 138 | */ |
| 139 | intptr_t index; |
| 140 | } AVD3D11FrameDescriptor; |
| 141 |
| 142 | /** |
| 143 | * This struct is allocated as AVHWFramesContext.hwctx |
| 144 | */ |
| 145 | typedef struct AVD3D11VAFramesContext { |
| 146 | /** |
| 147 | * The canonical texture used for pool allocation. If this is set to NULL |
| 148 | * on init, the hwframes implementation will allocate and set an array |
| 149 | * texture if initial_pool_size > 0. |
| 150 | * |
| 151 | * The only situation when the API user should set this is: |
| 152 | * - the user wants to do manual pool allocation (setting |
| 153 | * AVHWFramesContext.pool), instead of letting AVHWFramesContext |
| 154 | * allocate the pool |
| 155 | * - of an array texture |
| 156 | * - and wants it to use it for decoding |
| 157 | * - this has to be done before calling av_hwframe_ctx_init() |
| 158 | * |
| 159 | * Deallocating the AVHWFramesContext will always release this interface, |
| 160 | * and it does not matter whether it was user-allocated. |
| 161 | * |
| 162 | * This is in particular used by the libavcodec D3D11VA hwaccel, which |
| 163 | * requires a single array texture. It will create ID3D11VideoDecoderOutputView |
| 164 | * objects for each array texture element on decoder initialization. |
| 165 | */ |
| 166 | ID3D11Texture2D *texture; |
| 167 |
| 168 | /** |
| 169 | * D3D11_TEXTURE2D_DESC.BindFlags used for texture creation. The user must |
| 170 | * at least set D3D11_BIND_DECODER if the frames context is to be used for |
| 171 | * video decoding. |
| 172 | * This field is ignored/invalid if a user-allocated texture is provided. |
| 173 | */ |
| 174 | UINT BindFlags; |
| 175 |
| 176 | /** |
| 177 | * D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation. |
| 178 | * This field is ignored/invalid if a user-allocated texture is provided. |
| 179 | */ |
| 180 | UINT MiscFlags; |
| 181 |
| 182 | /** |
| 183 | * In case if texture structure member above is not NULL contains the same texture |
| 184 | * pointer for all elements and different indexes into the array texture. |
| 185 | * In case if texture structure member above is NULL, all elements contains |
| 186 | * pointers to separate non-array textures and 0 indexes. |
| 187 | * This field is ignored/invalid if a user-allocated texture is provided. |
| 188 | */ |
| 189 | AVD3D11FrameDescriptor *texture_infos; |
| 190 | } AVD3D11VAFramesContext; |
| 191 |
| 192 | #endif /* AVUTIL_HWCONTEXT_D3D11VA_H */ |
| 193 |