• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      * size of the private data, i.e.
46      * AVHWDeviceInternal.priv
47      */
48     size_t             device_priv_size;
49 
50     /**
51      * Size of the hardware-specific device configuration.
52      * (Used to query hwframe constraints.)
53      */
54     size_t             device_hwconfig_size;
55 
56     /**
57      * size of the public frame pool hardware-specific context,
58      * i.e. AVHWFramesContext.hwctx
59      */
60     size_t             frames_hwctx_size;
61     /**
62      * size of the private data, i.e.
63      * AVHWFramesInternal.priv
64      */
65     size_t             frames_priv_size;
66 
67     int              (*device_create)(AVHWDeviceContext *ctx, const char *device,
68                                       AVDictionary *opts, int flags);
69     int              (*device_derive)(AVHWDeviceContext *dst_ctx,
70                                       AVHWDeviceContext *src_ctx,
71                                       AVDictionary *opts, int flags);
72 
73     int              (*device_init)(AVHWDeviceContext *ctx);
74     void             (*device_uninit)(AVHWDeviceContext *ctx);
75 
76     int              (*frames_get_constraints)(AVHWDeviceContext *ctx,
77                                                const void *hwconfig,
78                                                AVHWFramesConstraints *constraints);
79 
80     int              (*frames_init)(AVHWFramesContext *ctx);
81     void             (*frames_uninit)(AVHWFramesContext *ctx);
82 
83     int              (*frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame);
84     int              (*transfer_get_formats)(AVHWFramesContext *ctx,
85                                              enum AVHWFrameTransferDirection dir,
86                                              enum AVPixelFormat **formats);
87     int              (*transfer_data_to)(AVHWFramesContext *ctx, AVFrame *dst,
88                                          const AVFrame *src);
89     int              (*transfer_data_from)(AVHWFramesContext *ctx, AVFrame *dst,
90                                            const AVFrame *src);
91 
92     int              (*map_to)(AVHWFramesContext *ctx, AVFrame *dst,
93                                const AVFrame *src, int flags);
94     int              (*map_from)(AVHWFramesContext *ctx, AVFrame *dst,
95                                  const AVFrame *src, int flags);
96 
97     int              (*frames_derive_to)(AVHWFramesContext *dst_ctx,
98                                          AVHWFramesContext *src_ctx, int flags);
99     int              (*frames_derive_from)(AVHWFramesContext *dst_ctx,
100                                            AVHWFramesContext *src_ctx, int flags);
101 } HWContextType;
102 
103 struct AVHWDeviceInternal {
104     const HWContextType *hw_type;
105     void                *priv;
106 
107     /**
108      * For a derived device, a reference to the original device
109      * context it was derived from.
110      */
111     AVBufferRef *source_device;
112 };
113 
114 struct AVHWFramesInternal {
115     const HWContextType *hw_type;
116     void                *priv;
117 
118     AVBufferPool *pool_internal;
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 };
131 
132 typedef struct HWMapDescriptor {
133     /**
134      * A reference to the original source of the mapping.
135      */
136     AVFrame *source;
137     /**
138      * A reference to the hardware frames context in which this
139      * mapping was made.  May be the same as source->hw_frames_ctx,
140      * but need not be.
141      */
142     AVBufferRef *hw_frames_ctx;
143     /**
144      * Unmap function.
145      */
146     void (*unmap)(AVHWFramesContext *ctx,
147                   struct HWMapDescriptor *hwmap);
148     /**
149      * Hardware-specific private data associated with the mapping.
150      */
151     void          *priv;
152 } HWMapDescriptor;
153 
154 int ff_hwframe_map_create(AVBufferRef *hwframe_ref,
155                           AVFrame *dst, const AVFrame *src,
156                           void (*unmap)(AVHWFramesContext *ctx,
157                                         HWMapDescriptor *hwmap),
158                           void *priv);
159 
160 /**
161  * Replace the current hwmap of dst with the one from src, used for indirect
162  * mappings like VAAPI->(DRM)->OpenCL/Vulkan where a direct interop is missing
163  */
164 int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src);
165 
166 extern const HWContextType ff_hwcontext_type_cuda;
167 extern const HWContextType ff_hwcontext_type_d3d11va;
168 extern const HWContextType ff_hwcontext_type_drm;
169 extern const HWContextType ff_hwcontext_type_dxva2;
170 extern const HWContextType ff_hwcontext_type_opencl;
171 extern const HWContextType ff_hwcontext_type_qsv;
172 extern const HWContextType ff_hwcontext_type_vaapi;
173 extern const HWContextType ff_hwcontext_type_vdpau;
174 extern const HWContextType ff_hwcontext_type_videotoolbox;
175 extern const HWContextType ff_hwcontext_type_mediacodec;
176 extern const HWContextType ff_hwcontext_type_vulkan;
177 
178 #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */
179