FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hwaccel_internal.h
Date: 2023-10-02 11:06:47
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.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 /**
20 * Header providing the internals of AVHWAccel.
21 */
22
23 #ifndef AVCODEC_HWACCEL_INTERNAL_H
24 #define AVCODEC_HWACCEL_INTERNAL_H
25
26 #include <stdint.h>
27
28 #include "avcodec.h"
29
30 #define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
31 #define HWACCEL_CAP_THREAD_SAFE (1 << 1)
32
33 typedef struct FFHWAccel {
34 /**
35 * The public AVHWAccel. See avcodec.h for it.
36 */
37 AVHWAccel p;
38
39 /**
40 * Allocate a custom buffer
41 */
42 int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
43
44 /**
45 * Called at the beginning of each frame or field picture.
46 *
47 * Meaningful frame information (codec specific) is guaranteed to
48 * be parsed at this point. This function is mandatory.
49 *
50 * Note that buf can be NULL along with buf_size set to 0.
51 * Otherwise, this means the whole frame is available at this point.
52 *
53 * @param avctx the codec context
54 * @param buf the frame data buffer base
55 * @param buf_size the size of the frame in bytes
56 * @return zero if successful, a negative value otherwise
57 */
58 int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
59
60 /**
61 * Callback for parameter data (SPS/PPS/VPS etc).
62 *
63 * Useful for hardware decoders which keep persistent state about the
64 * video parameters, and need to receive any changes to update that state.
65 *
66 * @param avctx the codec context
67 * @param type the nal unit type
68 * @param buf the nal unit data buffer
69 * @param buf_size the size of the nal unit in bytes
70 * @return zero if successful, a negative value otherwise
71 */
72 int (*decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size);
73
74 /**
75 * Callback for each slice.
76 *
77 * Meaningful slice information (codec specific) is guaranteed to
78 * be parsed at this point. This function is mandatory.
79 *
80 * @param avctx the codec context
81 * @param buf the slice data buffer base
82 * @param buf_size the size of the slice in bytes
83 * @return zero if successful, a negative value otherwise
84 */
85 int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
86
87 /**
88 * Called at the end of each frame or field picture.
89 *
90 * The whole picture is parsed at this point and can now be sent
91 * to the hardware accelerator. This function is mandatory.
92 *
93 * @param avctx the codec context
94 * @return zero if successful, a negative value otherwise
95 */
96 int (*end_frame)(AVCodecContext *avctx);
97
98 /**
99 * Size of per-frame hardware accelerator private data.
100 *
101 * Private data is allocated with av_mallocz() before
102 * AVCodecContext.get_buffer() and deallocated after
103 * AVCodecContext.release_buffer().
104 */
105 int frame_priv_data_size;
106
107 /**
108 * Size of the private data to allocate in
109 * AVCodecInternal.hwaccel_priv_data.
110 */
111 int priv_data_size;
112
113 /**
114 * Internal hwaccel capabilities.
115 */
116 int caps_internal;
117
118 /**
119 * Initialize the hwaccel private data.
120 *
121 * This will be called from ff_get_format(), after hwaccel and
122 * hwaccel_context are set and the hwaccel private data in AVCodecInternal
123 * is allocated.
124 */
125 int (*init)(AVCodecContext *avctx);
126
127 /**
128 * Uninitialize the hwaccel private data.
129 *
130 * This will be called from get_format() or avcodec_close(), after hwaccel
131 * and hwaccel_context are already uninitialized.
132 */
133 int (*uninit)(AVCodecContext *avctx);
134
135 /**
136 * Fill the given hw_frames context with current codec parameters. Called
137 * from get_format. Refer to avcodec_get_hw_frames_parameters() for
138 * details.
139 *
140 * This CAN be called before AVHWAccel.init is called, and you must assume
141 * that avctx->hwaccel_priv_data is invalid.
142 */
143 int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
144
145 /**
146 * Copy necessary context variables from a previous thread context to the current one.
147 * For thread-safe hwaccels only.
148 */
149 int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
150
151 /**
152 * Callback to free the hwaccel-specific frame data.
153 *
154 * @param hwctx a pointer to an AVHWDeviceContext.
155 * @param data the per-frame hardware accelerator private data to be freed.
156 */
157 void (*free_frame_priv)(void *hwctx, uint8_t *data);
158
159 /**
160 * Callback to flush the hwaccel state.
161 */
162 void (*flush)(AVCodecContext *avctx);
163 } FFHWAccel;
164
165 445691 static inline const FFHWAccel *ffhwaccel(const AVHWAccel *codec)
166 {
167 445691 return (const FFHWAccel*)codec;
168 }
169
170 #define FF_HW_CALL(avctx, function, ...) \
171 (ffhwaccel((avctx)->hwaccel)->function((avctx), __VA_ARGS__))
172
173 #define FF_HW_SIMPLE_CALL(avctx, function) \
174 (ffhwaccel((avctx)->hwaccel)->function(avctx))
175
176 #define FF_HW_HAS_CB(avctx, function) \
177 ((avctx)->hwaccel && ffhwaccel((avctx)->hwaccel)->function)
178
179 #endif /* AVCODEC_HWACCEL_INTERNAL */
180