History

avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec

Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean.

Andreas Rheinhardt committed 4 years ago

Commit 20f97271 parent a688f3c513 files · +5330 −5260Browse files

Showing the changes to libavcodec/codec_internal.h (1 of 513 files). Show all

Unified · Split

libavcodec/codec_internal.h+131−3
@@ -19,6 +19,11 @@ · 18 unmodified lines
19#ifndef AVCODEC_CODEC_INTERNAL_H19#ifndef AVCODEC_CODEC_INTERNAL_H
20#define AVCODEC_CODEC_INTERNAL_H20#define AVCODEC_CODEC_INTERNAL_H
21 21
22#include <stdint.h>
23
24#include "libavutil/attributes.h"
25#include "codec.h"
26
22/**27/**
23 * The codec does not modify any global variables in the init function,28 * The codec does not modify any global variables in the init function,
24 * allowing to call the init function without locking any global mutexes.29 * allowing to call the init function without locking any global mutexes.
@@ -70,13 +75,136 @@ · 45 unmodified lines
70#define FF_CODEC_CAP_SETS_FRAME_PROPS (1 << 8)75#define FF_CODEC_CAP_SETS_FRAME_PROPS (1 << 8)
71 76
72/**77/**
73 * AVCodec.codec_tags termination value78 * FFCodec.codec_tags termination value
74 */79 */
75#define FF_CODEC_TAGS_END -180#define FF_CODEC_TAGS_END -1
76 81
77struct AVCodecDefault {82typedef struct AVCodecDefault {
78 const char *key;83 const char *key;
79 const char *value;84 const char *value;
80};85} AVCodecDefault;
86
87struct AVCodecContext;
88struct AVSubtitle;
89struct AVPacket;
90
91typedef struct FFCodec {
92 /**
93 * The public AVCodec. See codec.h for it.
94 */
95 AVCodec p;
96
97 /**
98 * Internal codec capabilities FF_CODEC_CAP_*.
99 */
100 int caps_internal;
101
102 int priv_data_size;
103 /**
104 * @name Frame-level threading support functions
105 * @{
106 */
107 /**
108 * Copy necessary context variables from a previous thread context to the current one.
109 * If not defined, the next thread will start automatically; otherwise, the codec
110 * must call ff_thread_finish_setup().
111 *
112 * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
113 */
114 int (*update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src);
115
116 /**
117 * Copy variables back to the user-facing context
118 */
119 int (*update_thread_context_for_user)(struct AVCodecContext *dst, const struct AVCodecContext *src);
120 /** @} */
121
122 /**
123 * Private codec-specific defaults.
124 */
125 const AVCodecDefault *defaults;
126
127 /**
128 * Initialize codec static data, called from av_codec_iterate().
129 *
130 * This is not intended for time consuming operations as it is
131 * run for every codec regardless of that codec being used.
132 */
133 void (*init_static_data)(struct FFCodec *codec);
134
135 int (*init)(struct AVCodecContext *);
136 int (*encode_sub)(struct AVCodecContext *, uint8_t *buf, int buf_size,
137 const struct AVSubtitle *sub);
138 /**
139 * Encode data to an AVPacket.
140 *
141 * @param avctx codec context
142 * @param avpkt output AVPacket
143 * @param[in] frame AVFrame containing the raw data to be encoded
144 * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
145 * non-empty packet was returned in avpkt.
146 * @return 0 on success, negative error code on failure
147 */
148 int (*encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt,
149 const struct AVFrame *frame, int *got_packet_ptr);
150 /**
151 * Decode picture or subtitle data.
152 *
153 * @param avctx codec context
154 * @param outdata codec type dependent output struct
155 * @param[out] got_frame_ptr decoder sets to 0 or 1 to indicate that a
156 * non-empty frame or subtitle was returned in
157 * outdata.
158 * @param[in] avpkt AVPacket containing the data to be decoded
159 * @return amount of bytes read from the packet on success, negative error
160 * code on failure
161 */
162 int (*decode)(struct AVCodecContext *avctx, void *outdata,
163 int *got_frame_ptr, struct AVPacket *avpkt);
164 int (*close)(struct AVCodecContext *);
165 /**
166 * Encode API with decoupled frame/packet dataflow. This function is called
167 * to get one output packet. It should call ff_encode_get_frame() to obtain
168 * input data.
169 */
170 int (*receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt);
171
172 /**
173 * Decode API with decoupled packet/frame dataflow. This function is called
174 * to get one output frame. It should call ff_decode_get_packet() to obtain
175 * input data.
176 */
177 int (*receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame);
178 /**
179 * Flush buffers.
180 * Will be called when seeking
181 */
182 void (*flush)(struct AVCodecContext *);
183
184 /**
185 * Decoding only, a comma-separated list of bitstream filters to apply to
186 * packets before decoding.
187 */
188 const char *bsfs;
189
190 /**
191 * Array of pointers to hardware configurations supported by the codec,
192 * or NULL if no hardware supported. The array is terminated by a NULL
193 * pointer.
194 *
195 * The user can only access this field via avcodec_get_hw_config().
196 */
197 const struct AVCodecHWConfigInternal *const *hw_configs;
198
199 /**
200 * List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
201 */
202 const uint32_t *codec_tags;
203} FFCodec;
204
205static av_always_inline const FFCodec *ffcodec(const AVCodec *codec)
206{
207 return (const FFCodec*)codec;
208}
81 209
82#endif /* AVCODEC_CODEC_INTERNAL_H */210#endif /* AVCODEC_CODEC_INTERNAL_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t