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