hwcontext_d3d11va.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  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. #ifndef AVUTIL_HWCONTEXT_D3D11VA_H
  19. #define AVUTIL_HWCONTEXT_D3D11VA_H
  20. /**
  21. * @file
  22. * An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
  23. *
  24. * The default pool implementation will be fixed-size if initial_pool_size is
  25. * set (and allocate elements from an array texture). Otherwise it will allocate
  26. * individual textures. Be aware that decoding requires a single array texture.
  27. *
  28. * Using sw_format==AV_PIX_FMT_YUV420P has special semantics, and maps to
  29. * DXGI_FORMAT_420_OPAQUE. av_hwframe_transfer_data() is not supported for
  30. * this format. Refer to MSDN for details.
  31. *
  32. * av_hwdevice_ctx_create() for this device type supports a key named "debug"
  33. * for the AVDictionary entry. If this is set to any value, the device creation
  34. * code will try to load various supported D3D debugging layers.
  35. */
  36. #include <d3d11.h>
  37. #include <stdint.h>
  38. /**
  39. * This struct is allocated as AVHWDeviceContext.hwctx
  40. */
  41. typedef struct AVD3D11VADeviceContext {
  42. /**
  43. * Device used for texture creation and access. This can also be used to
  44. * set the libavcodec decoding device.
  45. *
  46. * Must be set by the user. This is the only mandatory field - the other
  47. * device context fields are set from this and are available for convenience.
  48. *
  49. * Deallocating the AVHWDeviceContext will always release this interface,
  50. * and it does not matter whether it was user-allocated.
  51. */
  52. ID3D11Device *device;
  53. /**
  54. * If unset, this will be set from the device field on init.
  55. *
  56. * Deallocating the AVHWDeviceContext will always release this interface,
  57. * and it does not matter whether it was user-allocated.
  58. */
  59. ID3D11DeviceContext *device_context;
  60. /**
  61. * If unset, this will be set from the device field on init.
  62. *
  63. * Deallocating the AVHWDeviceContext will always release this interface,
  64. * and it does not matter whether it was user-allocated.
  65. */
  66. ID3D11VideoDevice *video_device;
  67. /**
  68. * If unset, this will be set from the device_context field on init.
  69. *
  70. * Deallocating the AVHWDeviceContext will always release this interface,
  71. * and it does not matter whether it was user-allocated.
  72. */
  73. ID3D11VideoContext *video_context;
  74. /**
  75. * Callbacks for locking. They protect accesses to device_context and
  76. * video_context calls. They also protect access to the internal staging
  77. * texture (for av_hwframe_transfer_data() calls). They do NOT protect
  78. * access to hwcontext or decoder state in general.
  79. *
  80. * If unset on init, the hwcontext implementation will set them to use an
  81. * internal mutex.
  82. *
  83. * The underlying lock must be recursive. lock_ctx is for free use by the
  84. * locking implementation.
  85. */
  86. void (*lock)(void *lock_ctx);
  87. void (*unlock)(void *lock_ctx);
  88. void *lock_ctx;
  89. } AVD3D11VADeviceContext;
  90. /**
  91. * D3D11 frame descriptor for pool allocation.
  92. *
  93. * In user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
  94. * with the data pointer pointing at an object of this type describing the
  95. * planes of the frame.
  96. *
  97. * This has no use outside of custom allocation, and AVFrame AVBufferRef do not
  98. * necessarily point to an instance of this struct.
  99. */
  100. typedef struct AVD3D11FrameDescriptor {
  101. /**
  102. * The texture in which the frame is located. The reference count is
  103. * managed by the AVBufferRef, and destroying the reference will release
  104. * the interface.
  105. *
  106. * Normally stored in AVFrame.data[0].
  107. */
  108. ID3D11Texture2D *texture;
  109. /**
  110. * The index into the array texture element representing the frame, or 0
  111. * if the texture is not an array texture.
  112. *
  113. * Normally stored in AVFrame.data[1] (cast from intptr_t).
  114. */
  115. intptr_t index;
  116. } AVD3D11FrameDescriptor;
  117. /**
  118. * This struct is allocated as AVHWFramesContext.hwctx
  119. */
  120. typedef struct AVD3D11VAFramesContext {
  121. /**
  122. * The canonical texture used for pool allocation. If this is set to NULL
  123. * on init, the hwframes implementation will allocate and set an array
  124. * texture if initial_pool_size > 0.
  125. *
  126. * The only situation when the API user should set this is:
  127. * - the user wants to do manual pool allocation (setting
  128. * AVHWFramesContext.pool), instead of letting AVHWFramesContext
  129. * allocate the pool
  130. * - of an array texture
  131. * - and wants it to use it for decoding
  132. * - this has to be done before calling av_hwframe_ctx_init()
  133. *
  134. * Deallocating the AVHWFramesContext will always release this interface,
  135. * and it does not matter whether it was user-allocated.
  136. *
  137. * This is in particular used by the libavcodec D3D11VA hwaccel, which
  138. * requires a single array texture. It will create ID3D11VideoDecoderOutputView
  139. * objects for each array texture element on decoder initialization.
  140. */
  141. ID3D11Texture2D *texture;
  142. /**
  143. * D3D11_TEXTURE2D_DESC.BindFlags used for texture creation. The user must
  144. * at least set D3D11_BIND_DECODER if the frames context is to be used for
  145. * video decoding.
  146. * This field is ignored/invalid if a user-allocated texture is provided.
  147. */
  148. UINT BindFlags;
  149. /**
  150. * D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
  151. * This field is ignored/invalid if a user-allocated texture is provided.
  152. */
  153. UINT MiscFlags;
  154. } AVD3D11VAFramesContext;
  155. #endif /* AVUTIL_HWCONTEXT_D3D11VA_H */