2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVUTIL_HWCONTEXT_INTERNAL_H
20 #define AVUTIL_HWCONTEXT_INTERNAL_H
25 #include "hwcontext.h"
29 typedef struct HWContextType
{
30 enum AVHWDeviceType type
;
34 * An array of pixel formats supported by the AVHWFramesContext instances
35 * Terminated by AV_PIX_FMT_NONE.
37 const enum AVPixelFormat
*pix_fmts
;
40 * size of the public hardware-specific context,
41 * i.e. AVHWDeviceContext.hwctx
43 size_t device_hwctx_size
;
46 * Size of the hardware-specific device configuration.
47 * (Used to query hwframe constraints.)
49 size_t device_hwconfig_size
;
52 * size of the public frame pool hardware-specific context,
53 * i.e. AVHWFramesContext.hwctx
55 size_t frames_hwctx_size
;
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
);
63 int (*device_init
)(AVHWDeviceContext
*ctx
);
64 void (*device_uninit
)(AVHWDeviceContext
*ctx
);
66 int (*frames_get_constraints
)(AVHWDeviceContext
*ctx
,
68 AVHWFramesConstraints
*constraints
);
70 int (*frames_init
)(AVHWFramesContext
*ctx
);
71 void (*frames_uninit
)(AVHWFramesContext
*ctx
);
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
,
79 int (*transfer_data_from
)(AVHWFramesContext
*ctx
, AVFrame
*dst
,
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
);
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
);
93 typedef struct FFHWFramesContext
{
95 * The public AVHWFramesContext. See hwcontext.h for it.
99 const HWContextType
*hw_type
;
101 AVBufferPool
*pool_internal
;
104 * For a derived context, a reference to the original frames
105 * context it was derived from.
107 AVBufferRef
*source_frames
;
109 * Flags to apply to the mapping from the source to the derived
110 * frame context when trying to allocate in the derived context.
112 int source_allocation_map_flags
;
115 static inline FFHWFramesContext
*ffhwframesctx(AVHWFramesContext
*ctx
)
117 return (FFHWFramesContext
*)ctx
;
120 typedef struct HWMapDescriptor
{
122 * A reference to the original source of the mapping.
126 * A reference to the hardware frames context in which this
127 * mapping was made. May be the same as source->hw_frames_ctx,
130 AVBufferRef
*hw_frames_ctx
;
134 void (*unmap
)(AVHWFramesContext
*ctx
,
135 struct HWMapDescriptor
*hwmap
);
137 * Hardware-specific private data associated with the mapping.
142 int ff_hwframe_map_create(AVBufferRef
*hwframe_ref
,
143 AVFrame
*dst
, const AVFrame
*src
,
144 void (*unmap
)(AVHWFramesContext
*ctx
,
145 HWMapDescriptor
*hwmap
),
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
152 int ff_hwframe_map_replace(AVFrame
*dst
, const AVFrame
*src
);
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 extern const HWContextType ff_hwcontext_type_amf
;
167 extern const HWContextType ff_hwcontext_type_oh
;
169 #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */