hwcontext_internal.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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, int flags);
  62. int (*device_init)(AVHWDeviceContext *ctx);
  63. void (*device_uninit)(AVHWDeviceContext *ctx);
  64. int (*frames_get_constraints)(AVHWDeviceContext *ctx,
  65. const void *hwconfig,
  66. AVHWFramesConstraints *constraints);
  67. int (*frames_init)(AVHWFramesContext *ctx);
  68. void (*frames_uninit)(AVHWFramesContext *ctx);
  69. int (*frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame);
  70. int (*transfer_get_formats)(AVHWFramesContext *ctx,
  71. enum AVHWFrameTransferDirection dir,
  72. enum AVPixelFormat **formats);
  73. int (*transfer_data_to)(AVHWFramesContext *ctx, AVFrame *dst,
  74. const AVFrame *src);
  75. int (*transfer_data_from)(AVHWFramesContext *ctx, AVFrame *dst,
  76. const AVFrame *src);
  77. int (*map_to)(AVHWFramesContext *ctx, AVFrame *dst,
  78. const AVFrame *src, int flags);
  79. int (*map_from)(AVHWFramesContext *ctx, AVFrame *dst,
  80. const AVFrame *src, int flags);
  81. int (*frames_derive_to)(AVHWFramesContext *dst_ctx,
  82. AVHWFramesContext *src_ctx, int flags);
  83. int (*frames_derive_from)(AVHWFramesContext *dst_ctx,
  84. AVHWFramesContext *src_ctx, int flags);
  85. } HWContextType;
  86. struct AVHWDeviceInternal {
  87. const HWContextType *hw_type;
  88. void *priv;
  89. /**
  90. * For a derived device, a reference to the original device
  91. * context it was derived from.
  92. */
  93. AVBufferRef *source_device;
  94. };
  95. struct AVHWFramesInternal {
  96. const HWContextType *hw_type;
  97. void *priv;
  98. AVBufferPool *pool_internal;
  99. /**
  100. * For a derived context, a reference to the original frames
  101. * context it was derived from.
  102. */
  103. AVBufferRef *source_frames;
  104. /**
  105. * Flags to apply to the mapping from the source to the derived
  106. * frame context when trying to allocate in the derived context.
  107. */
  108. int source_allocation_map_flags;
  109. };
  110. typedef struct HWMapDescriptor {
  111. /**
  112. * A reference to the original source of the mapping.
  113. */
  114. AVFrame *source;
  115. /**
  116. * A reference to the hardware frames context in which this
  117. * mapping was made. May be the same as source->hw_frames_ctx,
  118. * but need not be.
  119. */
  120. AVBufferRef *hw_frames_ctx;
  121. /**
  122. * Unmap function.
  123. */
  124. void (*unmap)(AVHWFramesContext *ctx,
  125. struct HWMapDescriptor *hwmap);
  126. /**
  127. * Hardware-specific private data associated with the mapping.
  128. */
  129. void *priv;
  130. } HWMapDescriptor;
  131. int ff_hwframe_map_create(AVBufferRef *hwframe_ref,
  132. AVFrame *dst, const AVFrame *src,
  133. void (*unmap)(AVHWFramesContext *ctx,
  134. HWMapDescriptor *hwmap),
  135. void *priv);
  136. extern const HWContextType ff_hwcontext_type_cuda;
  137. extern const HWContextType ff_hwcontext_type_d3d11va;
  138. extern const HWContextType ff_hwcontext_type_drm;
  139. extern const HWContextType ff_hwcontext_type_dxva2;
  140. extern const HWContextType ff_hwcontext_type_opencl;
  141. extern const HWContextType ff_hwcontext_type_qsv;
  142. extern const HWContextType ff_hwcontext_type_vaapi;
  143. extern const HWContextType ff_hwcontext_type_vdpau;
  144. extern const HWContextType ff_hwcontext_type_videotoolbox;
  145. extern const HWContextType ff_hwcontext_type_mediacodec;
  146. #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */