FFmpeg coverage


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