FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/avcodec.c
Date: 2022-10-02 18:56:10
Exec Total Coverage
Lines: 65 102 63.7%
Branches: 90 139 64.7%

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 #include "libavutil/opt.h"
20 #include "libavcodec/codec.h"
21 #include "libavcodec/codec_desc.h"
22 #include "libavcodec/codec_internal.h"
23 #include "libavcodec/internal.h"
24
25 static const char *get_type_string(enum AVMediaType type)
26 {
27 const char *ret = av_get_media_type_string(type);
28 return ret ? ret : "unknown";
29 }
30
31 #define AV_LOG(...) av_log(NULL, AV_LOG_FATAL, __VA_ARGS__)
32 #define ERR_INTERNAL(msg, ...) \
33 do { \
34 AV_LOG(msg, codec->name __VA_ARGS__); \
35 ret = 1; \
36 } while (0)
37 #define ERR(msg) ERR_INTERNAL(msg, )
38 #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
39
40 677 static int priv_data_size_wrong(const FFCodec *codec)
41 {
42
1/2
✓ Branch 0 taken 677 times.
✗ Branch 1 not taken.
677 if (codec->priv_data_size < 0 ||
43
3/4
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 542 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 135 times.
677 codec->p.priv_class && codec->priv_data_size < sizeof(AVClass*))
44 return 1;
45
3/4
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 542 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 135 times.
677 if (!codec->p.priv_class || !codec->p.priv_class->option)
46 542 return 0;
47
2/2
✓ Branch 0 taken 1515 times.
✓ Branch 1 taken 135 times.
1650 for (const AVOption *opt = codec->p.priv_class->option; opt->name; opt++) {
48
1/2
✓ Branch 0 taken 1515 times.
✗ Branch 1 not taken.
1515 if (opt->offset >= codec->priv_data_size ||
49
3/4
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 778 times.
✓ Branch 2 taken 737 times.
✗ Branch 3 not taken.
1515 opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 ||
50
4/6
✓ Branch 0 taken 778 times.
✓ Branch 1 taken 737 times.
✓ Branch 2 taken 778 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 778 times.
1515 opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) {
51 AV_LOG("Option %s offset %d nonsensical\n",
52 opt->name, opt->offset);
53 return 1;
54 }
55 }
56 135 return 0;
57 }
58
59 1 int main(void){
60 1 void *iter = NULL;
61 1 const AVCodec *codec = NULL;
62 1 int ret = 0;
63
64
2/2
✓ Branch 1 taken 677 times.
✓ Branch 2 taken 1 times.
678 while (codec = av_codec_iterate(&iter)) {
65 677 const FFCodec *const codec2 = ffcodec(codec);
66 const AVCodecDescriptor *desc;
67 677 int is_decoder = 0, is_encoder = 0;
68
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 677 times.
677 if (!codec->name) {
70 AV_LOG("Codec for format %s has no name\n",
71 avcodec_get_name(codec->id));
72 ret = 1;
73 continue;
74 }
75
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 369 times.
677 if (codec->type != AVMEDIA_TYPE_VIDEO &&
76
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 275 times.
308 codec->type != AVMEDIA_TYPE_AUDIO &&
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 codec->type != AVMEDIA_TYPE_SUBTITLE)
78 ERR_EXT("Codec %s has unsupported type %s\n",
79 get_type_string(codec->type));
80
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 275 times.
677 if (codec->type != AVMEDIA_TYPE_AUDIO) {
81
2/4
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
402 if (codec->ch_layouts || codec->sample_fmts ||
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 402 times.
402 codec->supported_samplerates)
83 ERR("Non-audio codec %s has audio-only fields set\n");
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 402 times.
402 if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
85 AV_CODEC_CAP_CHANNEL_CONF |
86 AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
87 ERR("Non-audio codec %s has audio-only capabilities set\n");
88 }
89
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 369 times.
677 if (codec->type != AVMEDIA_TYPE_VIDEO) {
90
2/4
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 308 times.
308 if (codec->pix_fmts || codec->supported_framerates)
91 ERR("Non-video codec %s has video-only fields set\n");
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
308 if (codec2->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)
93 ERR("Non-video codec %s exports cropping\n");
94 }
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 676 times.
677 if (codec2->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF &&
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 !(codec->capabilities & AV_CODEC_CAP_SLICE_THREADS))
97 ERR("Codec %s wants mainfunction despite not being "
98 "slice-threading capable");
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 677 times.
677 if (codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS &&
100 !(codec->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
101 AV_CODEC_CAP_SLICE_THREADS |
102 AV_CODEC_CAP_OTHER_THREADS)))
103 ERR("Codec %s has private-only threading support\n");
104
105
2/3
✓ Branch 0 taken 491 times.
✓ Branch 1 taken 186 times.
✗ Branch 2 not taken.
677 switch (codec2->cb_type) {
106 491 case FF_CODEC_CB_TYPE_DECODE:
107 case FF_CODEC_CB_TYPE_DECODE_SUB:
108 case FF_CODEC_CB_TYPE_RECEIVE_FRAME:
109 491 is_decoder = 1;
110 491 break;
111 186 case FF_CODEC_CB_TYPE_ENCODE:
112 case FF_CODEC_CB_TYPE_ENCODE_SUB:
113 case FF_CODEC_CB_TYPE_RECEIVE_PACKET:
114 186 is_encoder = 1;
115 186 break;
116 default:
117 ERR("Codec %s has unknown cb_type\n");
118 continue;
119 }
120
2/4
✓ Branch 1 taken 677 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 677 times.
1354 if (is_decoder != av_codec_is_decoder(codec) ||
121 677 is_encoder != av_codec_is_encoder(codec)) {
122 ERR("Codec %s cb_type and av_codec_is_(de|en)coder inconsistent.\n");
123 continue;
124 }
125 #define CHECK(TYPE, type) (codec2->cb_type == FF_CODEC_CB_TYPE_ ## TYPE && !codec2->cb.type)
126
6/8
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 225 times.
✓ Branch 2 taken 452 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 655 times.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
677 if (CHECK(DECODE, decode) || CHECK(DECODE_SUB, decode_sub) ||
127
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 666 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
677 CHECK(RECEIVE_PACKET, receive_packet) ||
128
6/8
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 513 times.
✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 666 times.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
677 CHECK(ENCODE, encode) || CHECK(ENCODE_SUB, encode_sub) ||
129
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 660 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
677 CHECK(RECEIVE_FRAME, receive_frame)) {
130 ERR_EXT("Codec %s does not implement its %s callback.\n",
131 is_decoder ? "decoding" : "encoding");
132 }
133 #undef CHECK
134
2/2
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 491 times.
677 if (is_encoder) {
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if ((codec->type == AVMEDIA_TYPE_SUBTITLE) != (codec2->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB))
136 ERR("Encoder %s is both subtitle encoder and not subtitle encoder.");
137
3/6
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 186 times.
186 if (codec2->update_thread_context || codec2->update_thread_context_for_user || codec2->bsfs)
138 ERR("Encoder %s has decoder-only thread functions or bsf.\n");
139
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 111 times.
186 if (codec->type == AVMEDIA_TYPE_AUDIO) {
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
75 if (!codec->sample_fmts) {
141 av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
142 ret = 1;
143 }
144 }
145
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if (codec2->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS |
146 FF_CODEC_CAP_SETS_PKT_DTS |
147 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
148 FF_CODEC_CAP_EXPORTS_CROPPING |
149 186 FF_CODEC_CAP_SETS_FRAME_PROPS) ||
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING |
151 AV_CODEC_CAP_CHANNEL_CONF |
152 AV_CODEC_CAP_DRAW_HORIZ_BAND |
153 AV_CODEC_CAP_SUBFRAMES))
154 ERR("Encoder %s has decoder-only capabilities set\n");
155
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 163 times.
186 if (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS &&
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH)
157 ERR("Frame-threaded encoder %s claims to support flushing\n");
158
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 163 times.
186 if (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS &&
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 codec->capabilities & AV_CODEC_CAP_DELAY)
160 ERR("Frame-threaded encoder %s claims to have delay\n");
161 } else {
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 491 times.
491 if ((codec->type == AVMEDIA_TYPE_SUBTITLE) != (codec2->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB))
163 ERR("Subtitle decoder %s does not implement decode_sub callback\n");
164
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 469 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
491 if (codec->type == AVMEDIA_TYPE_SUBTITLE && codec2->bsfs)
165 ERR("Automatic bitstream filtering unsupported for subtitles; "
166 "yet decoder %s has it set\n");
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 491 times.
491 if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
168 AV_CODEC_CAP_VARIABLE_FRAME_SIZE |
169 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
170 AV_CODEC_CAP_ENCODER_FLUSH))
171 ERR("Decoder %s has encoder-only capabilities\n");
172
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 476 times.
491 if (codec2->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
174 ERR("Decoder %s wants allocated progress without supporting"
175 "frame threads\n");
176 }
177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
677 if (priv_data_size_wrong(codec2))
178 ERR_EXT("Private context of codec %s is impossibly-sized (size %d).",
179 codec2->priv_data_size);
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
677 if (!(desc = avcodec_descriptor_get(codec->id))) {
181 ERR("Codec %s lacks a corresponding descriptor\n");
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 677 times.
677 } else if (desc->type != codec->type)
183 ERR_EXT("The type of AVCodec %s and its AVCodecDescriptor differ: "
184 "%s vs %s\n",
185 get_type_string(codec->type), get_type_string(desc->type));
186 }
187 1 return ret;
188 }
189