| 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 | /** | ||
| 20 | * @file | ||
| 21 | * leb128 handling implementations | ||
| 22 | */ | ||
| 23 | |||
| 24 | #ifndef AVCODEC_LEB_H | ||
| 25 | #define AVCODEC_LEB_H | ||
| 26 | |||
| 27 | #include "get_bits.h" | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Read a unsigned integer coded as a variable number of up to eight | ||
| 31 | * little-endian bytes, where the MSB in a byte signals another byte | ||
| 32 | * must be read. | ||
| 33 | * All coded bits are read, but values > UINT_MAX are truncated. | ||
| 34 | */ | ||
| 35 | 13732 | static inline unsigned get_leb(GetBitContext *s) { | |
| 36 | 13732 | int more, i = 0; | |
| 37 | 13732 | unsigned leb = 0; | |
| 38 | |||
| 39 | do { | ||
| 40 | 16440 | int byte = get_bits(s, 8); | |
| 41 | 16440 | unsigned bits = byte & 0x7f; | |
| 42 | 16440 | more = byte & 0x80; | |
| 43 |
2/2✓ Branch 0 taken 16374 times.
✓ Branch 1 taken 66 times.
|
16440 | if (i <= 4) |
| 44 | 16374 | leb |= bits << (i * 7); | |
| 45 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 16419 times.
|
16440 | if (++i == 8) |
| 46 | 21 | break; | |
| 47 |
2/2✓ Branch 0 taken 2708 times.
✓ Branch 1 taken 13711 times.
|
16419 | } while (more); |
| 48 | |||
| 49 | 13732 | return leb; | |
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Read a unsigned integer coded as a variable number of up to eight | ||
| 54 | * little-endian bytes, where the MSB in a byte signals another byte | ||
| 55 | * must be read. | ||
| 56 | */ | ||
| 57 | 3554 | static inline int64_t get_leb128(GetBitContext *gb) { | |
| 58 | 3554 | int64_t ret = 0; | |
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 4264 times.
✓ Branch 1 taken 6 times.
|
4270 | for (int i = 0; i < 8; i++) { |
| 61 | 4264 | int byte = get_bits(gb, 8); | |
| 62 | 4264 | ret |= (int64_t)(byte & 0x7f) << (i * 7); | |
| 63 |
2/2✓ Branch 0 taken 3548 times.
✓ Branch 1 taken 716 times.
|
4264 | if (!(byte & 0x80)) |
| 64 | 3548 | break; | |
| 65 | } | ||
| 66 | |||
| 67 | 3554 | return ret; | |
| 68 | } | ||
| 69 | |||
| 70 | #endif /* AVCODEC_LEB_H */ | ||
| 71 |