FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hwaccel_internal.h
Go to the documentation of this file.
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 #include "libavutil/refstruct.h"
30 
31 #define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
32 #define HWACCEL_CAP_THREAD_SAFE (1 << 1)
33 
34 typedef struct FFHWAccel {
35  /**
36  * The public AVHWAccel. See avcodec.h for it.
37  */
39 
40  /**
41  * Allocate a custom buffer
42  */
44 
45  /**
46  * Called at the beginning of each frame or field picture.
47  *
48  * Meaningful frame information (codec specific) is guaranteed to
49  * be parsed at this point. This function is mandatory.
50  *
51  * Note that buf can be NULL along with buf_size set to 0.
52  * Otherwise, this means the whole frame is available at this point.
53  *
54  * @param avctx the codec context
55  * @param buf_ref the frame data buffer reference (optional)
56  * @param buf the frame data buffer base
57  * @param buf_size the size of the frame in bytes
58  * @return zero if successful, a negative value otherwise
59  */
60  int (*start_frame)(AVCodecContext *avctx, const AVBufferRef *buf_ref,
61  const uint8_t *buf, uint32_t buf_size);
62 
63  /**
64  * Callback for parameter data (SPS/PPS/VPS etc).
65  *
66  * Useful for hardware decoders which keep persistent state about the
67  * video parameters, and need to receive any changes to update that state.
68  *
69  * @param avctx the codec context
70  * @param type the nal unit type
71  * @param buf the nal unit data buffer
72  * @param buf_size the size of the nal unit in bytes
73  * @return zero if successful, a negative value otherwise
74  */
75  int (*decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size);
76 
77  /**
78  * Callback for each slice.
79  *
80  * Meaningful slice information (codec specific) is guaranteed to
81  * be parsed at this point. This function is mandatory.
82  *
83  * @param avctx the codec context
84  * @param buf the slice data buffer base
85  * @param buf_size the size of the slice in bytes
86  * @return zero if successful, a negative value otherwise
87  */
88  int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
89 
90  /**
91  * Called at the end of each frame or field picture.
92  *
93  * The whole picture is parsed at this point and can now be sent
94  * to the hardware accelerator. This function is mandatory.
95  *
96  * @param avctx the codec context
97  * @return zero if successful, a negative value otherwise
98  */
99  int (*end_frame)(AVCodecContext *avctx);
100 
101  /**
102  * Size of per-frame hardware accelerator private data.
103  *
104  * Private data is allocated with av_mallocz() before
105  * AVCodecContext.get_buffer() and deallocated after
106  * AVCodecContext.release_buffer().
107  */
109 
110  /**
111  * Size of the private data to allocate in
112  * AVCodecInternal.hwaccel_priv_data.
113  */
115 
116  /**
117  * Internal hwaccel capabilities.
118  */
120 
121  /**
122  * Initialize the hwaccel private data.
123  *
124  * This will be called from ff_get_format(), after hwaccel and
125  * hwaccel_context are set and the hwaccel private data in AVCodecInternal
126  * is allocated.
127  */
128  int (*init)(AVCodecContext *avctx);
129 
130  /**
131  * Uninitialize the hwaccel private data.
132  *
133  * This will be called from get_format() or ff_codec_close(), after hwaccel
134  * and hwaccel_context are already uninitialized.
135  */
136  int (*uninit)(AVCodecContext *avctx);
137 
138  /**
139  * Fill the given hw_frames context with current codec parameters. Called
140  * from get_format. Refer to avcodec_get_hw_frames_parameters() for
141  * details.
142  *
143  * This CAN be called before AVHWAccel.init is called, and you must assume
144  * that avctx->hwaccel_priv_data is invalid.
145  */
146  int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
147 
148  /**
149  * Copy necessary context variables from a previous thread context to the current one.
150  * For thread-safe hwaccels only.
151  */
153 
154  /**
155  * Callback to free the hwaccel-specific frame data.
156  *
157  * @param hwctx a pointer to an AVHWDeviceContext.
158  * @param data the per-frame hardware accelerator private data to be freed.
159  */
160  void (*free_frame_priv)(AVRefStructOpaque hwctx, void *data);
161 
162  /**
163  * Callback to flush the hwaccel state.
164  */
165  void (*flush)(AVCodecContext *avctx);
166 } FFHWAccel;
167 
168 static inline const FFHWAccel *ffhwaccel(const AVHWAccel *codec)
169 {
170  return (const FFHWAccel*)codec;
171 }
172 
173 #define FF_HW_CALL(avctx, function, ...) \
174  (ffhwaccel((avctx)->hwaccel)->function((avctx), __VA_ARGS__))
175 
176 #define FF_HW_SIMPLE_CALL(avctx, function) \
177  (ffhwaccel((avctx)->hwaccel)->function(avctx))
178 
179 #define FF_HW_HAS_CB(avctx, function) \
180  ((avctx)->hwaccel && ffhwaccel((avctx)->hwaccel)->function)
181 
182 #endif /* AVCODEC_HWACCEL_INTERNAL */
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
FFHWAccel::frame_params
int(* frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Fill the given hw_frames context with current codec parameters.
Definition: hwaccel_internal.h:146
data
const char data[16]
Definition: mxf.c:149
FFHWAccel::flush
void(* flush)(AVCodecContext *avctx)
Callback to flush the hwaccel state.
Definition: hwaccel_internal.h:165
FFHWAccel::free_frame_priv
void(* free_frame_priv)(AVRefStructOpaque hwctx, void *data)
Callback to free the hwaccel-specific frame data.
Definition: hwaccel_internal.h:160
FFHWAccel::start_frame
int(* start_frame)(AVCodecContext *avctx, const AVBufferRef *buf_ref, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: hwaccel_internal.h:60
AVHWAccel
Definition: avcodec.h:2118
FFHWAccel::alloc_frame
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: hwaccel_internal.h:43
FFHWAccel
Definition: hwaccel_internal.h:34
FFHWAccel::end_frame
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: hwaccel_internal.h:99
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
refstruct.h
FFHWAccel::frame_priv_data_size
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: hwaccel_internal.h:108
FFHWAccel::priv_data_size
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: hwaccel_internal.h:114
FFHWAccel::decode_params
int(* decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size)
Callback for parameter data (SPS/PPS/VPS etc).
Definition: hwaccel_internal.h:75
FFHWAccel::init
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: hwaccel_internal.h:128
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
FFHWAccel::uninit
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: hwaccel_internal.h:136
avcodec.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:451
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:168
FFHWAccel::decode_slice
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: hwaccel_internal.h:88
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
FFHWAccel::caps_internal
int caps_internal
Internal hwaccel capabilities.
Definition: hwaccel_internal.h:119
src
#define src
Definition: vp8dsp.c:248
FFHWAccel::update_thread_context
int(* update_thread_context)(AVCodecContext *dst, const AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
Definition: hwaccel_internal.h:152