| 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 | |||
| 24 | #include "rl.h" | ||
| 25 | |||
| 26 | 66 | av_cold void ff_rl_init_level_run(uint8_t max_level[MAX_LEVEL + 1], | |
| 27 | uint8_t index_run[MAX_RUN + 1], | ||
| 28 | const uint8_t table_run[/* n */], | ||
| 29 | const uint8_t table_level[/* n*/], | ||
| 30 | int n) | ||
| 31 | { | ||
| 32 | 66 | memset(index_run, n, MAX_RUN + 1); | |
| 33 |
2/2✓ Branch 0 taken 7416 times.
✓ Branch 1 taken 66 times.
|
7482 | for (int i = 0; i < n; i++) { |
| 34 | 7416 | int run = table_run[i]; | |
| 35 | 7416 | int level = table_level[i]; | |
| 36 |
2/2✓ Branch 0 taken 2112 times.
✓ Branch 1 taken 5304 times.
|
7416 | if (index_run[run] == n) |
| 37 | 2112 | index_run[run] = i; | |
| 38 |
1/2✓ Branch 0 taken 7416 times.
✗ Branch 1 not taken.
|
7416 | if (level > max_level[run]) |
| 39 | 7416 | max_level[run] = level; | |
| 40 | } | ||
| 41 | 66 | } | |
| 42 | |||
| 43 | 698 | av_cold void ff_rl_init(RLTable *rl, | |
| 44 | uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3]) | ||
| 45 | { | ||
| 46 | int last, run, level, start, end, i; | ||
| 47 | |||
| 48 | /* compute max_level[], max_run[] and index_run[] */ | ||
| 49 |
2/2✓ Branch 0 taken 1396 times.
✓ Branch 1 taken 698 times.
|
2094 | for (last = 0; last < 2; last++) { |
| 50 | 1396 | int8_t *max_level = static_store[last]; | |
| 51 | 1396 | int8_t *max_run = static_store[last] + MAX_RUN + 1; | |
| 52 | 1396 | uint8_t *index_run = static_store[last] + MAX_RUN + 1 + MAX_LEVEL + 1; | |
| 53 |
2/2✓ Branch 0 taken 698 times.
✓ Branch 1 taken 698 times.
|
1396 | if (last == 0) { |
| 54 | 698 | start = 0; | |
| 55 | 698 | end = rl->last; | |
| 56 | } else { | ||
| 57 | 698 | start = rl->last; | |
| 58 | 698 | end = rl->n; | |
| 59 | } | ||
| 60 | |||
| 61 | 1396 | memset(index_run, rl->n, MAX_RUN + 1); | |
| 62 |
2/2✓ Branch 0 taken 80871 times.
✓ Branch 1 taken 1396 times.
|
82267 | for (i = start; i < end; i++) { |
| 63 | 80871 | run = rl->table_run[i]; | |
| 64 | 80871 | level = rl->table_level[i]; | |
| 65 |
2/2✓ Branch 0 taken 38553 times.
✓ Branch 1 taken 42318 times.
|
80871 | if (index_run[run] == rl->n) |
| 66 | 38553 | index_run[run] = i; | |
| 67 |
1/2✓ Branch 0 taken 80871 times.
✗ Branch 1 not taken.
|
80871 | if (level > max_level[run]) |
| 68 | 80871 | max_level[run] = level; | |
| 69 |
2/2✓ Branch 0 taken 63593 times.
✓ Branch 1 taken 17278 times.
|
80871 | if (run > max_run[level]) |
| 70 | 63593 | max_run[level] = run; | |
| 71 | } | ||
| 72 | 1396 | rl->max_level[last] = max_level; | |
| 73 | 1396 | rl->max_run[last] = max_run; | |
| 74 | 1396 | rl->index_run[last] = index_run; | |
| 75 | } | ||
| 76 | 698 | } | |
| 77 | |||
| 78 | 771 | av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size) | |
| 79 | { | ||
| 80 | VLCElem *vlc; | ||
| 81 | |||
| 82 | 771 | ff_vlc_init_table_sparse(rl->rl_vlc[0], static_size, 9, rl->n + 1, | |
| 83 | 771 | &rl->table_vlc[0][1], 4, 2, | |
| 84 | 771 | &rl->table_vlc[0][0], 4, 2, | |
| 85 | NULL, 0, 0, 0); | ||
| 86 | |||
| 87 | 771 | vlc = rl->rl_vlc[0]; | |
| 88 | |||
| 89 | // We count down to avoid trashing the first RL-VLC | ||
| 90 |
2/2✓ Branch 0 taken 24672 times.
✓ Branch 1 taken 771 times.
|
25443 | for (int q = 32; --q >= 0;) { |
| 91 | 24672 | int qmul = q * 2; | |
| 92 | 24672 | int qadd = (q - 1) | 1; | |
| 93 | |||
| 94 |
2/2✓ Branch 0 taken 14043 times.
✓ Branch 1 taken 10629 times.
|
24672 | if (!rl->rl_vlc[q]) |
| 95 | 14043 | continue; | |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 771 times.
✓ Branch 1 taken 9858 times.
|
10629 | if (q == 0) { |
| 98 | 771 | qmul = 1; | |
| 99 | 771 | qadd = 0; | |
| 100 | } | ||
| 101 |
2/2✓ Branch 0 taken 8309236 times.
✓ Branch 1 taken 10629 times.
|
8319865 | for (unsigned i = 0; i < static_size; i++) { |
| 102 | 8309236 | int idx = vlc[i].sym; | |
| 103 | 8309236 | int len = vlc[i].len; | |
| 104 | int level, run; | ||
| 105 | |||
| 106 |
2/2✓ Branch 0 taken 99795 times.
✓ Branch 1 taken 8209441 times.
|
8309236 | if (len == 0) { // illegal code |
| 107 | 99795 | run = 66; | |
| 108 | 99795 | level = MAX_LEVEL; | |
| 109 |
2/2✓ Branch 0 taken 156367 times.
✓ Branch 1 taken 8053074 times.
|
8209441 | } else if (len < 0) { // more bits needed |
| 110 | 156367 | run = 0; | |
| 111 | 156367 | level = idx; | |
| 112 | } else { | ||
| 113 |
2/2✓ Branch 0 taken 131722 times.
✓ Branch 1 taken 7921352 times.
|
8053074 | if (idx == rl->n) { // esc |
| 114 | 131722 | run = 66; | |
| 115 | 131722 | level = 0; | |
| 116 | } else { | ||
| 117 | 7921352 | run = rl->table_run[idx] + 1; | |
| 118 | 7921352 | level = rl->table_level[idx] * qmul + qadd; | |
| 119 |
2/2✓ Branch 0 taken 2386130 times.
✓ Branch 1 taken 5535222 times.
|
7921352 | if (idx >= rl->last) run += 192; |
| 120 | } | ||
| 121 | } | ||
| 122 | 8309236 | rl->rl_vlc[q][i].len8 = len; | |
| 123 | 8309236 | rl->rl_vlc[q][i].level = level; | |
| 124 | 8309236 | rl->rl_vlc[q][i].run = run; | |
| 125 | } | ||
| 126 | } | ||
| 127 | 771 | } | |
| 128 |