FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/rl.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 65 65 100.0%
Functions: 3 3 100.0%
Branches: 33 36 91.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 64 av_cold void ff_rl_init_level_run(uint8_t max_level[MAX_LEVEL + 1],
28 uint8_t index_run[MAX_RUN + 1],
29 const uint8_t table_run[/* n */],
30 const uint8_t table_level[/* n*/],
31 int n)
32 {
33 64 memset(index_run, n, MAX_RUN + 1);
34
2/2
✓ Branch 0 taken 7194 times.
✓ Branch 1 taken 64 times.
7258 for (int i = 0; i < n; i++) {
35 7194 int run = table_run[i];
36 7194 int level = table_level[i];
37
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 5146 times.
7194 if (index_run[run] == n)
38 2048 index_run[run] = i;
39
1/2
✓ Branch 0 taken 7194 times.
✗ Branch 1 not taken.
7194 if (level > max_level[run])
40 7194 max_level[run] = level;
41 }
42 64 }
43
44 1031 av_cold void ff_rl_init(RLTable *rl,
45 uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
46 {
47 int last, run, level, start, end, i;
48
49 /* compute max_level[], max_run[] and index_run[] */
50
2/2
✓ Branch 0 taken 2062 times.
✓ Branch 1 taken 1031 times.
3093 for (last = 0; last < 2; last++) {
51 2062 int8_t *max_level = static_store[last];
52 2062 int8_t *max_run = static_store[last] + MAX_RUN + 1;
53 2062 uint8_t *index_run = static_store[last] + MAX_RUN + 1 + MAX_LEVEL + 1;
54
2/2
✓ Branch 0 taken 1031 times.
✓ Branch 1 taken 1031 times.
2062 if (last == 0) {
55 1031 start = 0;
56 1031 end = rl->last;
57 } else {
58 1031 start = rl->last;
59 1031 end = rl->n;
60 }
61
62 2062 memset(index_run, rl->n, MAX_RUN + 1);
63
2/2
✓ Branch 0 taken 128639 times.
✓ Branch 1 taken 2062 times.
130701 for (i = start; i < end; i++) {
64 128639 run = rl->table_run[i];
65 128639 level = rl->table_level[i];
66
2/2
✓ Branch 0 taken 60488 times.
✓ Branch 1 taken 68151 times.
128639 if (index_run[run] == rl->n)
67 60488 index_run[run] = i;
68
1/2
✓ Branch 0 taken 128639 times.
✗ Branch 1 not taken.
128639 if (level > max_level[run])
69 128639 max_level[run] = level;
70
2/2
✓ Branch 0 taken 102408 times.
✓ Branch 1 taken 26231 times.
128639 if (run > max_run[level])
71 102408 max_run[level] = run;
72 }
73 2062 rl->max_level[last] = max_level;
74 2062 rl->max_run[last] = max_run;
75 2062 rl->index_run[last] = index_run;
76 }
77 1031 }
78
79 776 av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
80 {
81 int i, q;
82 776 VLCElem table[1500] = { 0 };
83 776 VLC vlc = { .table = table, .table_allocated = static_size };
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776 times.
776 av_assert0(static_size <= FF_ARRAY_ELEMS(table));
85 776 vlc_init(&vlc, 9, rl->n + 1,
86 &rl->table_vlc[0][1], 4, 2,
87 &rl->table_vlc[0][0], 4, 2, VLC_INIT_USE_STATIC);
88
89
2/2
✓ Branch 0 taken 11152 times.
✓ Branch 1 taken 320 times.
11472 for (q = 0; q < 32; q++) {
90 11152 int qmul = q * 2;
91 11152 int qadd = (q - 1) | 1;
92
93
2/2
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 10696 times.
11152 if (!rl->rl_vlc[q])
94 456 return;
95
96
2/2
✓ Branch 0 taken 776 times.
✓ Branch 1 taken 9920 times.
10696 if (q == 0) {
97 776 qmul = 1;
98 776 qadd = 0;
99 }
100
2/2
✓ Branch 0 taken 8363448 times.
✓ Branch 1 taken 10696 times.
8374144 for (i = 0; i < vlc.table_size; i++) {
101 8363448 int code = vlc.table[i].sym;
102 8363448 int len = vlc.table[i].len;
103 int level, run;
104
105
2/2
✓ Branch 0 taken 100753 times.
✓ Branch 1 taken 8262695 times.
8363448 if (len == 0) { // illegal code
106 100753 run = 66;
107 100753 level = MAX_LEVEL;
108
2/2
✓ Branch 0 taken 157369 times.
✓ Branch 1 taken 8105326 times.
8262695 } else if (len < 0) { // more bits needed
109 157369 run = 0;
110 157369 level = code;
111 } else {
112
2/2
✓ Branch 0 taken 132914 times.
✓ Branch 1 taken 7972412 times.
8105326 if (code == rl->n) { // esc
113 132914 run = 66;
114 132914 level = 0;
115 } else {
116 7972412 run = rl->table_run[code] + 1;
117 7972412 level = rl->table_level[code] * qmul + qadd;
118
2/2
✓ Branch 0 taken 2399233 times.
✓ Branch 1 taken 5573179 times.
7972412 if (code >= rl->last) run += 192;
119 }
120 }
121 8363448 rl->rl_vlc[q][i].len = len;
122 8363448 rl->rl_vlc[q][i].level = level;
123 8363448 rl->rl_vlc[q][i].run = run;
124 }
125 }
126 }
127