hwcontext_internal.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_INTERNAL_H
  19. #define AVUTIL_HWCONTEXT_INTERNAL_H
  20. #include <stddef.h>
  21. #include "buffer.h"
  22. #include "hwcontext.h"
  23. #include "frame.h"
  24. #include "pixfmt.h"
  25. typedef struct HWContextType {
  26. enum AVHWDeviceType type;
  27. const char *name;
  28. /**
  29. * An array of pixel formats supported by the AVHWFramesContext instances
  30. * Terminated by AV_PIX_FMT_NONE.
  31. */
  32. const enum AVPixelFormat *pix_fmts;
  33. /**
  34. * size of the public hardware-specific context,
  35. * i.e. AVHWDeviceContext.hwctx
  36. */
  37. size_t device_hwctx_size;
  38. /**
  39. * size of the private data, i.e.
  40. * AVHWDeviceInternal.priv
  41. */
  42. size_t device_priv_size;
  43. /**
  44. * Size of the hardware-specific device configuration.
  45. * (Used to query hwframe constraints.)
  46. */
  47. size_t device_hwconfig_size;
  48. /**
  49. * size of the public frame pool hardware-specific context,
  50. * i.e. AVHWFramesContext.hwctx
  51. */
  52. size_t frames_hwctx_size;
  53. /**
  54. * size of the private data, i.e.
  55. * AVHWFramesInternal.priv
  56. */
  57. size_t frames_priv_size;
  58. int (*device_create)(AVHWDeviceContext *ctx, const char *device,
  59. AVDictionary *opts, int flags);
  60. int (*device_derive)(AVHWDeviceContext *dst_ctx,
  61. AVHWDeviceContext *src_ctx,
  62. AVDictionary *opts, int flags);
  63. int (*device_init)(AVHWDeviceContext *ctx);
  64. void (*device_uninit)(AVHWDeviceContext *ctx);
  65. int (*frames_get_constraints)(AVHWDeviceContext *ctx,
  66. const void *hwconfig,
  67. AVHWFramesConstraints *constraints);
  68. int (*frames_init)(AVHWFramesContext *ctx);
  69. void (*frames_uninit)(AVHWFramesContext *ctx);
  70. int (*frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame);
  71. int (*transfer_get_formats)(AVHWFramesContext *ctx,
  72. enum AVHWFrameTransferDirection dir,
  73. enum AVPixelFormat **formats);
  74. int (*transfer_data_to)(AVHWFramesContext *ctx, AVFrame *dst,
  75. const AVFrame *src);
  76. int (*transfer_data_from)(AVHWFramesContext *ctx, AVFrame *dst,
  77. const AVFrame *src);
  78. int (*map_to)(AVHWFramesContext *ctx, AVFrame *dst,
  79. const AVFrame *src, int flags);
  80. int (*map_from)(AVHWFramesContext *ctx, AVFrame *dst,
  81. const AVFrame *src, int flags);
  82. int (*frames_derive_to)(AVHWFramesContext *dst_ctx,
  83. AVHWFramesContext *src_ctx, int flags);
  84. int (*frames_derive_from)(AVHWFramesContext *dst_ctx,
  85. AVHWFramesContext *src_ctx, int flags);
  86. } HWContextType;
  87. struct AVHWDeviceInternal {
  88. const HWContextType *hw_type;
  89. void *priv;
  90. /**
  91. * For a derived device, a reference to the original device
  92. * context it was derived from.
  93. */
  94. AVBufferRef *source_device;
  95. };
  96. struct AVHWFramesInternal {
  97. const HWContextType *hw_type;
  98. void *priv;
  99. AVBufferPool *pool_internal;
  100. /**
  101. * For a derived context, a reference to the original frames
  102. * context it was derived from.
  103. */
  104. AVBufferRef *source_frames;
  105. /**
  106. * Flags to apply to the mapping from the source to the derived
  107. * frame context when trying to allocate in the derived context.
  108. */
  109. int source_allocation_map_flags;
  110. };
  111. typedef struct HWMapDescriptor {
  112. /**
  113. * A reference to the original source of the mapping.
  114. */
  115. AVFrame *source;
  116. /**
  117. * A reference to the hardware frames context in which this
  118. * mapping was made. May be the same as source->hw_frames_ctx,
  119. * but need not be.
  120. */
  121. AVBufferRef *hw_frames_ctx;
  122. /**
  123. * Unmap function.
  124. */
  125. void (*unmap)(AVHWFramesContext *ctx,
  126. struct HWMapDescriptor *hwmap);
  127. /**
  128. * Hardware-specific private data associated with the mapping.
  129. */
  130. void *priv;
  131. } HWMapDescriptor;
  132. int ff_hwframe_map_create(AVBufferRef *hwframe_ref,
  133. AVFrame *dst, const AVFrame *src,
  134. void (*unmap)(AVHWFramesContext *ctx,
  135. HWMapDescriptor *hwmap),
  136. void *priv);
  137. /**
  138. * Replace the current hwmap of dst with the one from src, used for indirect
  139. * mappings like VAAPI->(DRM)->OpenCL/Vulkan where a direct interop is missing
  140. */
  141. int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src);
  142. extern const HWContextType ff_hwcontext_type_cuda;
  143. extern const HWContextType ff_hwcontext_type_d3d11va;
  144. extern const HWContextType ff_hwcontext_type_drm;
  145. extern const HWContextType ff_hwcontext_type_dxva2;
  146. extern const HWContextType ff_hwcontext_type_opencl;
  147. extern const HWContextType ff_hwcontext_type_qsv;
  148. extern const HWContextType ff_hwcontext_type_vaapi;
  149. extern const HWContextType ff_hwcontext_type_vdpau;
  150. extern const HWContextType ff_hwcontext_type_videotoolbox;
  151. extern const HWContextType ff_hwcontext_type_mediacodec;
  152. extern const HWContextType ff_hwcontext_type_vulkan;
  153. #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */