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