FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/mpeg12framerate.c
Date: 2024-07-24 19:24:46
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 1 1 100.0%
Branches: 32 56 57.1%

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 <stddef.h>
20
21 #include "libavutil/log.h"
22 #include "libavcodec/mpeg12.h"
23 #include "libavcodec/mpeg12data.h"
24
25 1 int main(void)
26 {
27 int i;
28
29 #define TEST_MATCH(frame_rate, code, ext_n, ext_d) do { \
30 AVRational fr = frame_rate; \
31 int c, n, d; \
32 ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
33 if (c != code || n != ext_n || d != ext_d) { \
34 av_log(NULL, AV_LOG_ERROR, "Failed to match %d/%d: " \
35 "code = %d, ext_n = %d, ext_d = %d.\n", \
36 fr.num, fr.den, c, n, d); \
37 return 1; \
38 } \
39 } while (0)
40 #define TEST_EXACT(frn, frd) do { \
41 AVRational fr = (AVRational) { frn, frd }; \
42 int c, n, d; \
43 ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
44 if (av_cmp_q(fr, av_mul_q(ff_mpeg12_frame_rate_tab[c], \
45 (AVRational) { n + 1, d + 1 })) != 0) { \
46 av_log(NULL, AV_LOG_ERROR, "Failed to find exact %d/%d: " \
47 "code = %d, ext_n = %d, ext_d = %d.\n", \
48 fr.num, fr.den, c, n, d); \
49 return 1; \
50 } \
51 } while (0)
52
53 // Framerates in the table must be chosen exactly.
54
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (i = 1; i <= 8; i++)
55
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
8 TEST_MATCH(ff_mpeg12_frame_rate_tab[i], i, 0, 0);
56
57 // As should the same ones with small perturbations.
58 // (1/1000 used here to be smaller than half the difference
59 // between 24 and 24000/1001.)
60
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (i = 1; i <= 8; i++) {
61
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
8 TEST_MATCH(av_sub_q(ff_mpeg12_frame_rate_tab[i],
62 (AVRational) { 1, 1000 }), i, 0, 0);
63
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
8 TEST_MATCH(av_add_q(ff_mpeg12_frame_rate_tab[i],
64 (AVRational) { 1, 1000 }), i, 0, 0);
65 }
66
67 // Exactly constructable framerates should be exact. Note that some
68 // values can be made in multiple ways (e.g. 12 = 24 / 2 == 60 / 5),
69 // and there is no reason to favour any particular choice.
70
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 1, 1);
71
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 2, 1);
72
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 12, 1);
73
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 15000, 1001);
74
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 15, 1);
75
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 120, 1);
76
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT(120000, 1001);
77
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 200, 1);
78
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 TEST_EXACT( 240, 1);
79
80 // Values higher than 240 (the highest representable, as 60 * 4 / 1)
81 // should be mapped to 240.
82
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1 times.
77 for (i = 240; i < 1000; i += 10)
83
3/6
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 76 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 76 times.
76 TEST_MATCH(((AVRational) { i, 1 }), 8, 3, 0);
84 // Values lower than 24000/32032 (the lowest representable, as
85 // 24000/1001 * 1 / 32) should be mapped to 24000/32032.
86
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 1 times.
75 for (i = 74; i > 0; i--)
87
3/6
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 74 times.
74 TEST_MATCH(((AVRational) { i, 100 }), 1, 0, 31);
88
89 1 return 0;
90 }
91