FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/rl.c
Date: 2022-07-04 00:18:54
Exec Total Coverage
Lines: 55 55 100.0%
Branches: 29 30 96.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 <stdint.h>
20 #include <string.h>
21
22 #include "libavutil/attributes.h"
23 #include "libavutil/avassert.h"
24
25 #include "rl.h"
26
27 1219 av_cold void ff_rl_init(RLTable *rl,
28 uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
29 {
30 int last, run, level, start, end, i;
31
32 /* compute max_level[], max_run[] and index_run[] */
33
2/2
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 1219 times.
3657 for (last = 0; last < 2; last++) {
34 2438 int8_t *max_level = static_store[last];
35 2438 int8_t *max_run = static_store[last] + MAX_RUN + 1;
36 2438 uint8_t *index_run = static_store[last] + MAX_RUN + 1 + MAX_LEVEL + 1;
37
2/2
✓ Branch 0 taken 1219 times.
✓ Branch 1 taken 1219 times.
2438 if (last == 0) {
38 1219 start = 0;
39 1219 end = rl->last;
40 } else {
41 1219 start = rl->last;
42 1219 end = rl->n;
43 }
44
45 2438 memset(index_run, rl->n, MAX_RUN + 1);
46
2/2
✓ Branch 0 taken 151508 times.
✓ Branch 1 taken 2438 times.
153946 for (i = start; i < end; i++) {
47 151508 run = rl->table_run[i];
48 151508 level = rl->table_level[i];
49
2/2
✓ Branch 0 taken 68953 times.
✓ Branch 1 taken 82555 times.
151508 if (index_run[run] == rl->n)
50 68953 index_run[run] = i;
51
2/2
✓ Branch 0 taken 151502 times.
✓ Branch 1 taken 6 times.
151508 if (level > max_level[run])
52 151502 max_level[run] = level;
53
2/2
✓ Branch 0 taken 119435 times.
✓ Branch 1 taken 32073 times.
151508 if (run > max_run[level])
54 119435 max_run[level] = run;
55 }
56 2438 rl->max_level[last] = max_level;
57 2438 rl->max_run[last] = max_run;
58 2438 rl->index_run[last] = index_run;
59 }
60 1219 }
61
62 865 av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
63 {
64 int i, q;
65 865 VLCElem table[1500] = { 0 };
66 865 VLC vlc = { .table = table, .table_allocated = static_size };
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 av_assert0(static_size <= FF_ARRAY_ELEMS(table));
68 865 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);
69
70
2/2
✓ Branch 0 taken 12500 times.
✓ Branch 1 taken 359 times.
12859 for (q = 0; q < 32; q++) {
71 12500 int qmul = q * 2;
72 12500 int qadd = (q - 1) | 1;
73
74
2/2
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 11994 times.
12500 if (!rl->rl_vlc[q])
75 506 return;
76
77
2/2
✓ Branch 0 taken 865 times.
✓ Branch 1 taken 11129 times.
11994 if (q == 0) {
78 865 qmul = 1;
79 865 qadd = 0;
80 }
81
2/2
✓ Branch 0 taken 9422758 times.
✓ Branch 1 taken 11994 times.
9434752 for (i = 0; i < vlc.table_size; i++) {
82 9422758 int code = vlc.table[i].sym;
83 9422758 int len = vlc.table[i].len;
84 int level, run;
85
86
2/2
✓ Branch 0 taken 95583 times.
✓ Branch 1 taken 9327175 times.
9422758 if (len == 0) { // illegal code
87 95583 run = 66;
88 95583 level = MAX_LEVEL;
89
2/2
✓ Branch 0 taken 177418 times.
✓ Branch 1 taken 9149757 times.
9327175 } else if (len < 0) { // more bits needed
90 177418 run = 0;
91 177418 level = code;
92 } else {
93
2/2
✓ Branch 0 taken 129247 times.
✓ Branch 1 taken 9020510 times.
9149757 if (code == rl->n) { // esc
94 129247 run = 66;
95 129247 level = 0;
96 } else {
97 9020510 run = rl->table_run[code] + 1;
98 9020510 level = rl->table_level[code] * qmul + qadd;
99
2/2
✓ Branch 0 taken 2911365 times.
✓ Branch 1 taken 6109145 times.
9020510 if (code >= rl->last) run += 192;
100 }
101 }
102 9422758 rl->rl_vlc[q][i].len = len;
103 9422758 rl->rl_vlc[q][i].level = level;
104 9422758 rl->rl_vlc[q][i].run = run;
105 }
106 }
107 }
108