FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg12framerate.c
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 36 36 100.0%
Branches: 28 34 82.4%

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/rational.h"
20
21 #include "mpeg12.h"
22 #include "mpeg12data.h"
23
24 const AVRational ff_mpeg12_frame_rate_tab[16] = {
25 { 0, 0},
26 {24000, 1001},
27 { 24, 1},
28 { 25, 1},
29 {30000, 1001},
30 { 30, 1},
31 { 50, 1},
32 {60000, 1001},
33 { 60, 1},
34 // Xing's 15fps: (9)
35 { 15, 1},
36 // libmpeg3's "Unofficial economy rates": (10-13)
37 { 5, 1},
38 { 10, 1},
39 { 12, 1},
40 { 15, 1},
41 { 0, 0},
42 };
43
44 183 void ff_mpeg12_find_best_frame_rate(AVRational frame_rate,
45 int *code, int *ext_n, int *ext_d,
46 int nonstandard)
47 {
48
2/4
✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 183 times.
✗ Branch 3 not taken.
183 int mpeg2 = ext_n && ext_d;
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
183 int max_code = nonstandard ? 12 : 8;
50 int c, n, d, best_c, best_n, best_d;
51 183 AVRational best_error = { INT_MAX, 1 };
52
53 // Default to NTSC if the inputs make no sense.
54 183 best_c = 4;
55 183 best_n = best_d = 1;
56
57
2/2
✓ Branch 0 taken 1436 times.
✓ Branch 1 taken 175 times.
1611 for (c = 1; c <= max_code; c++) {
58
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1428 times.
1436 if (av_cmp_q(frame_rate, ff_mpeg12_frame_rate_tab[c]) == 0) {
59 8 best_c = c;
60 8 goto found;
61 }
62 }
63
64
2/2
✓ Branch 0 taken 1364 times.
✓ Branch 1 taken 165 times.
1529 for (c = 1; c <= max_code; c++) {
65
3/4
✓ Branch 0 taken 6797 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5443 times.
✓ Branch 3 taken 1354 times.
6797 for (n = 1; n <= (mpeg2 ? 4 : 1); n++) {
66
3/4
✓ Branch 0 taken 179339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 173906 times.
✓ Branch 3 taken 5433 times.
179339 for (d = 1; d <= (mpeg2 ? 32 : 1); d++) {
67 AVRational test, error;
68 int cmp;
69
70 173906 test = av_mul_q(ff_mpeg12_frame_rate_tab[c],
71 173906 (AVRational) { n, d });
72
73 173906 cmp = av_cmp_q(test, frame_rate);
74
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 173896 times.
173906 if (cmp == 0) {
75 10 best_c = c;
76 10 best_n = n;
77 10 best_d = d;
78 10 goto found;
79 }
80
81
2/2
✓ Branch 0 taken 96555 times.
✓ Branch 1 taken 77341 times.
173896 if (cmp < 0)
82 96555 error = av_div_q(frame_rate, test);
83 else
84 77341 error = av_div_q(test, frame_rate);
85
86 173896 cmp = av_cmp_q(error, best_error);
87
8/8
✓ Branch 0 taken 170477 times.
✓ Branch 1 taken 3419 times.
✓ Branch 2 taken 138 times.
✓ Branch 3 taken 170339 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 126 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 6 times.
173896 if (cmp < 0 || (cmp == 0 && n == 1 && d == 1)) {
88 3425 best_c = c;
89 3425 best_n = n;
90 3425 best_d = d;
91 3425 best_error = error;
92 }
93 }
94 }
95 }
96
97 165 found:
98 183 *code = best_c;
99
1/2
✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
183 if (mpeg2) {
100 183 *ext_n = best_n - 1;
101 183 *ext_d = best_d - 1;
102 }
103 183 }
104