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/tests (1 of 513 files). Show all

Unified · Split

libavcodec/tests/avcodec.c+18−17
@@ -37,14 +37,14 @@ do { \ · 36 unmodified lines
3737 #define ERR(msg) ERR_INTERNAL(msg, )
3838 #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
3939
40−static int priv_data_size_wrong(const AVCodec *codec)
40+static int priv_data_size_wrong(const FFCodec *codec)
4141 {
4242 if (codec->priv_data_size < 0 ||
43− codec->priv_class && codec->priv_data_size < sizeof(AVClass*))
43+ codec->p.priv_class && codec->priv_data_size < sizeof(AVClass*))
4444 return 1;
45− if (!codec->priv_class || !codec->priv_class->option)
45+ if (!codec->p.priv_class || !codec->p.priv_class->option)
4646 return 0;
47− for (const AVOption *opt = codec->priv_class->option; opt->name; opt++) {
47+ for (const AVOption *opt = codec->p.priv_class->option; opt->name; opt++) {
4848 if (opt->offset >= codec->priv_data_size ||
4949 opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 ||
5050 opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) {
@@ -62,6 +62,7 @@ int main(void){ · 11 unmodified lines
6262 int ret = 0;
6363
6464 while (codec = av_codec_iterate(&iter)) {
65+ const FFCodec *const codec2 = ffcodec(codec);
6566 const AVCodecDescriptor *desc;
6667 int is_decoder, is_encoder;
6768
@@ -88,14 +89,14 @@ int main(void){ · 20 unmodified lines
8889 if (codec->type != AVMEDIA_TYPE_VIDEO) {
8990 if (codec->pix_fmts || codec->supported_framerates)
9091 ERR("Non-video codec %s has video-only fields set\n");
91− if (codec->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)
92+ if (codec2->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)
9293 ERR("Non-video codec %s exports cropping\n");
9394 }
94− if (codec->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF &&
95+ if (codec2->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF &&
9596 !(codec->capabilities & AV_CODEC_CAP_SLICE_THREADS))
9697 ERR("Codec %s wants mainfunction despite not being "
9798 "slice-threading capable");
98− if (codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS &&
99+ if (codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS &&
99100 !(codec->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
100101 AV_CODEC_CAP_SLICE_THREADS |
101102 AV_CODEC_CAP_OTHER_THREADS)))
@@ -108,11 +109,11 @@ int main(void){ · 6 unmodified lines
108109 continue;
109110 }
110111 if (is_encoder) {
111− if (codec->type == AVMEDIA_TYPE_SUBTITLE ^ !!codec->encode_sub)
112+ if (codec->type == AVMEDIA_TYPE_SUBTITLE ^ !!codec2->encode_sub)
112113 ERR("Encoder %s is both subtitle encoder and not subtitle encoder.");
113− if (!!codec->encode_sub + !!codec->encode2 + !!codec->receive_packet != 1)
114+ if (!!codec2->encode_sub + !!codec2->encode2 + !!codec2->receive_packet != 1)
114115 ERR("Encoder %s does not implement exactly one encode API.\n");
115− if (codec->update_thread_context || codec->update_thread_context_for_user || codec->bsfs)
116+ if (codec2->update_thread_context || codec2->update_thread_context_for_user || codec2->bsfs)
116117 ERR("Encoder %s has decoder-only thread functions or bsf.\n");
117118 if (codec->type == AVMEDIA_TYPE_AUDIO) {
118119 if (!codec->sample_fmts) {
@@ -120,7 +121,7 @@ int main(void){ · 1 unmodified line
120121 ret = 1;
121122 }
122123 }
123− if (codec->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS |
124+ if (codec2->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS |
124125 FF_CODEC_CAP_SETS_PKT_DTS |
125126 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
126127 FF_CODEC_CAP_EXPORTS_CROPPING |
@@ -134,26 +135,26 @@ int main(void){ · 7 unmodified lines
134135 codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH)
135136 ERR("Frame-threaded encoder %s claims to support flushing\n");
136137 } else {
137− if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec->decode)
138+ if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec2->decode)
138139 ERR("Subtitle decoder %s does not implement decode callback\n");
139− if (codec->type == AVMEDIA_TYPE_SUBTITLE && codec->bsfs)
140+ if (codec->type == AVMEDIA_TYPE_SUBTITLE && codec2->bsfs)
140141 ERR("Automatic bitstream filtering unsupported for subtitles; "
141142 "yet decoder %s has it set\n");
142− if (!!codec->decode + !!codec->receive_frame != 1)
143+ if (!!codec2->decode + !!codec2->receive_frame != 1)
143144 ERR("Decoder %s does not implement exactly one decode API.\n");
144145 if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
145146 AV_CODEC_CAP_VARIABLE_FRAME_SIZE |
146147 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
147148 AV_CODEC_CAP_ENCODER_FLUSH))
148149 ERR("Decoder %s has encoder-only capabilities\n");
149− if (codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
150+ if (codec2->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
150151 !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
151152 ERR("Decoder %s wants allocated progress without supporting"
152153 "frame threads\n");
153154 }
154− if (priv_data_size_wrong(codec))
155+ if (priv_data_size_wrong(codec2))
155156 ERR_EXT("Private context of codec %s is impossibly-sized (size %d).",
156− codec->priv_data_size);
157+ codec2->priv_data_size);
157158 if (!(desc = avcodec_descriptor_get(codec->id))) {
158159 ERR("Codec %s lacks a corresponding descriptor\n");
159160 } else if (desc->type != codec->type)

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