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.
Showing the changes to libavcodec/tests (1 of 513 files). Show all
Unified · Split
| @@ -37,14 +37,14 @@ do { \ · 36 unmodified lines | |||
| 37 | #define ERR(msg) ERR_INTERNAL(msg, ) | 37 | #define ERR(msg) ERR_INTERNAL(msg, ) |
| 38 | #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__) | 38 | #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__) |
| 39 | 39 | ||
| 40 | static int priv_data_size_wrong(const AVCodec *codec) | 40 | static int priv_data_size_wrong(const FFCodec *codec) |
| 41 | { | 41 | { |
| 42 | if (codec->priv_data_size < 0 || | 42 | 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*)) |
| 44 | return 1; | 44 | return 1; |
| 45 | if (!codec->priv_class || !codec->priv_class->option) | 45 | if (!codec->p.priv_class || !codec->p.priv_class->option) |
| 46 | return 0; | 46 | 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++) { |
| 48 | if (opt->offset >= codec->priv_data_size || | 48 | if (opt->offset >= codec->priv_data_size || |
| 49 | opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 || | 49 | opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 || |
| 50 | opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) { | 50 | opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) { |
| @@ -62,6 +62,7 @@ int main(void){ · 11 unmodified lines | |||
| 62 | int ret = 0; | 62 | int ret = 0; |
| 63 | 63 | ||
| 64 | while (codec = av_codec_iterate(&iter)) { | 64 | while (codec = av_codec_iterate(&iter)) { |
| 65 | const FFCodec *const codec2 = ffcodec(codec); | ||
| 65 | const AVCodecDescriptor *desc; | 66 | const AVCodecDescriptor *desc; |
| 66 | int is_decoder, is_encoder; | 67 | int is_decoder, is_encoder; |
| 67 | 68 | ||
| @@ -88,14 +89,14 @@ int main(void){ · 20 unmodified lines | |||
| 88 | if (codec->type != AVMEDIA_TYPE_VIDEO) { | 89 | if (codec->type != AVMEDIA_TYPE_VIDEO) { |
| 89 | if (codec->pix_fmts || codec->supported_framerates) | 90 | if (codec->pix_fmts || codec->supported_framerates) |
| 90 | ERR("Non-video codec %s has video-only fields set\n"); | 91 | 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) |
| 92 | ERR("Non-video codec %s exports cropping\n"); | 93 | ERR("Non-video codec %s exports cropping\n"); |
| 93 | } | 94 | } |
| 94 | if (codec->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF && | 95 | if (codec2->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF && |
| 95 | !(codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)) | 96 | !(codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)) |
| 96 | ERR("Codec %s wants mainfunction despite not being " | 97 | ERR("Codec %s wants mainfunction despite not being " |
| 97 | "slice-threading capable"); | 98 | "slice-threading capable"); |
| 98 | if (codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS && | 99 | if (codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS && |
| 99 | !(codec->capabilities & (AV_CODEC_CAP_FRAME_THREADS | | 100 | !(codec->capabilities & (AV_CODEC_CAP_FRAME_THREADS | |
| 100 | AV_CODEC_CAP_SLICE_THREADS | | 101 | AV_CODEC_CAP_SLICE_THREADS | |
| 101 | AV_CODEC_CAP_OTHER_THREADS))) | 102 | AV_CODEC_CAP_OTHER_THREADS))) |
| @@ -108,11 +109,11 @@ int main(void){ · 6 unmodified lines | |||
| 108 | continue; | 109 | continue; |
| 109 | } | 110 | } |
| 110 | if (is_encoder) { | 111 | if (is_encoder) { |
| 111 | if (codec->type == AVMEDIA_TYPE_SUBTITLE ^ !!codec->encode_sub) | 112 | if (codec->type == AVMEDIA_TYPE_SUBTITLE ^ !!codec2->encode_sub) |
| 112 | ERR("Encoder %s is both subtitle encoder and not subtitle encoder."); | 113 | 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) |
| 114 | ERR("Encoder %s does not implement exactly one encode API.\n"); | 115 | 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) |
| 116 | ERR("Encoder %s has decoder-only thread functions or bsf.\n"); | 117 | ERR("Encoder %s has decoder-only thread functions or bsf.\n"); |
| 117 | if (codec->type == AVMEDIA_TYPE_AUDIO) { | 118 | if (codec->type == AVMEDIA_TYPE_AUDIO) { |
| 118 | if (!codec->sample_fmts) { | 119 | if (!codec->sample_fmts) { |
| @@ -120,7 +121,7 @@ int main(void){ · 1 unmodified line | |||
| 120 | ret = 1; | 121 | ret = 1; |
| 121 | } | 122 | } |
| 122 | } | 123 | } |
| 123 | if (codec->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS | | 124 | if (codec2->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS | |
| 124 | FF_CODEC_CAP_SETS_PKT_DTS | | 125 | FF_CODEC_CAP_SETS_PKT_DTS | |
| 125 | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | | 126 | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | |
| 126 | FF_CODEC_CAP_EXPORTS_CROPPING | | 127 | FF_CODEC_CAP_EXPORTS_CROPPING | |
| @@ -134,26 +135,26 @@ int main(void){ · 7 unmodified lines | |||
| 134 | codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH) | 135 | codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH) |
| 135 | ERR("Frame-threaded encoder %s claims to support flushing\n"); | 136 | ERR("Frame-threaded encoder %s claims to support flushing\n"); |
| 136 | } else { | 137 | } else { |
| 137 | if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec->decode) | 138 | if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec2->decode) |
| 138 | ERR("Subtitle decoder %s does not implement decode callback\n"); | 139 | 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) |
| 140 | ERR("Automatic bitstream filtering unsupported for subtitles; " | 141 | ERR("Automatic bitstream filtering unsupported for subtitles; " |
| 141 | "yet decoder %s has it set\n"); | 142 | "yet decoder %s has it set\n"); |
| 142 | if (!!codec->decode + !!codec->receive_frame != 1) | 143 | if (!!codec2->decode + !!codec2->receive_frame != 1) |
| 143 | ERR("Decoder %s does not implement exactly one decode API.\n"); | 144 | ERR("Decoder %s does not implement exactly one decode API.\n"); |
| 144 | if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME | | 145 | if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME | |
| 145 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | | 146 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | |
| 146 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE | | 147 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE | |
| 147 | AV_CODEC_CAP_ENCODER_FLUSH)) | 148 | AV_CODEC_CAP_ENCODER_FLUSH)) |
| 148 | ERR("Decoder %s has encoder-only capabilities\n"); | 149 | 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 && |
| 150 | !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)) | 151 | !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)) |
| 151 | ERR("Decoder %s wants allocated progress without supporting" | 152 | ERR("Decoder %s wants allocated progress without supporting" |
| 152 | "frame threads\n"); | 153 | "frame threads\n"); |
| 153 | } | 154 | } |
| 154 | if (priv_data_size_wrong(codec)) | 155 | if (priv_data_size_wrong(codec2)) |
| 155 | ERR_EXT("Private context of codec %s is impossibly-sized (size %d).", | 156 | ERR_EXT("Private context of codec %s is impossibly-sized (size %d).", |
| 156 | codec->priv_data_size); | 157 | codec2->priv_data_size); |
| 157 | if (!(desc = avcodec_descriptor_get(codec->id))) { | 158 | if (!(desc = avcodec_descriptor_get(codec->id))) { |
| 158 | ERR("Codec %s lacks a corresponding descriptor\n"); | 159 | ERR("Codec %s lacks a corresponding descriptor\n"); |
| 159 | } else if (desc->type != codec->type) | 160 | } else if (desc->type != codec->type) |