FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/hwcontext_internal.h
Date: 2026-11-01 05:14:56
Exec Total Coverage
Lines: 0 2 0.0%
Functions: 0 1 0.0%
Branches: 0 0 -%

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