FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/rl.c
Date: 2021-09-22 23:55:11
Exec Total Coverage
Lines: 57 58 98.3%
Branches: 30 32 93.8%

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 <stdint.h>
20 #include <string.h>
21
22 #include "libavutil/attributes.h"
23 #include "libavutil/avassert.h"
24
25 #include "rl.h"
26
27 1198 av_cold void ff_rl_init(RLTable *rl,
28 uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
29 {
30 int8_t max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1];
31 uint8_t index_run[MAX_RUN + 1];
32 int last, run, level, start, end, i;
33
34 /* If rl->max_level[0] is set, this RLTable has already been initialized */
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1198 times.
1198 if (rl->max_level[0])
36 return;
37
38 /* compute max_level[], max_run[] and index_run[] */
39
2/2
✓ Branch 0 taken 2396 times.
✓ Branch 1 taken 1198 times.
3594 for (last = 0; last < 2; last++) {
40
2/2
✓ Branch 0 taken 1198 times.
✓ Branch 1 taken 1198 times.
2396 if (last == 0) {
41 1198 start = 0;
42 1198 end = rl->last;
43 } else {
44 1198 start = rl->last;
45 1198 end = rl->n;
46 }
47
48 2396 memset(max_level, 0, MAX_RUN + 1);
49 2396 memset(max_run, 0, MAX_LEVEL + 1);
50 2396 memset(index_run, rl->n, MAX_RUN + 1);
51
2/2
✓ Branch 0 taken 148946 times.
✓ Branch 1 taken 2396 times.
151342 for (i = start; i < end; i++) {
52 148946 run = rl->table_run[i];
53 148946 level = rl->table_level[i];
54
2/2
✓ Branch 0 taken 67778 times.
✓ Branch 1 taken 81168 times.
148946 if (index_run[run] == rl->n)
55 67778 index_run[run] = i;
56
2/2
✓ Branch 0 taken 148940 times.
✓ Branch 1 taken 6 times.
148946 if (level > max_level[run])
57 148940 max_level[run] = level;
58
2/2
✓ Branch 0 taken 117456 times.
✓ Branch 1 taken 31490 times.
148946 if (run > max_run[level])
59 117456 max_run[level] = run;
60 }
61 2396 rl->max_level[last] = static_store[last];
62 2396 memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
63 2396 rl->max_run[last] = static_store[last] + MAX_RUN + 1;
64 2396 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
65 2396 rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
66 2396 memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
67 }
68 }
69
70 848 av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
71 {
72 int i, q;
73 848 VLC_TYPE table[1500][2] = {{0}};
74 848 VLC vlc = { .table = table, .table_allocated = static_size };
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 848 times.
848 av_assert0(static_size <= FF_ARRAY_ELEMS(table));
76 848 init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
77
78
2/2
✓ Branch 0 taken 12256 times.
✓ Branch 1 taken 352 times.
12608 for (q = 0; q < 32; q++) {
79 12256 int qmul = q * 2;
80 12256 int qadd = (q - 1) | 1;
81
82
2/2
✓ Branch 0 taken 496 times.
✓ Branch 1 taken 11760 times.
12256 if (!rl->rl_vlc[q])
83 496 return;
84
85
2/2
✓ Branch 0 taken 848 times.
✓ Branch 1 taken 10912 times.
11760 if (q == 0) {
86 848 qmul = 1;
87 848 qadd = 0;
88 }
89
2/2
✓ Branch 0 taken 9241840 times.
✓ Branch 1 taken 11760 times.
9253600 for (i = 0; i < vlc.table_size; i++) {
90 9241840 int code = vlc.table[i][0];
91 9241840 int len = vlc.table[i][1];
92 int level, run;
93
94
2/2
✓ Branch 0 taken 92676 times.
✓ Branch 1 taken 9149164 times.
9241840 if (len == 0) { // illegal code
95 92676 run = 66;
96 92676 level = MAX_LEVEL;
97
2/2
✓ Branch 0 taken 174016 times.
✓ Branch 1 taken 8975148 times.
9149164 } else if (len < 0) { // more bits needed
98 174016 run = 0;
99 174016 level = code;
100 } else {
101
2/2
✓ Branch 0 taken 125539 times.
✓ Branch 1 taken 8849609 times.
8975148 if (code == rl->n) { // esc
102 125539 run = 66;
103 125539 level = 0;
104 } else {
105 8849609 run = rl->table_run[code] + 1;
106 8849609 level = rl->table_level[code] * qmul + qadd;
107
2/2
✓ Branch 0 taken 2867997 times.
✓ Branch 1 taken 5981612 times.
8849609 if (code >= rl->last) run += 192;
108 }
109 }
110 9241840 rl->rl_vlc[q][i].len = len;
111 9241840 rl->rl_vlc[q][i].level = level;
112 9241840 rl->rl_vlc[q][i].run = run;
113 }
114 }
115 }
116