Coverage Report

Created: 2026-06-15 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/bitstream.h
Line
Count
Source
1
/*
2
 * H.265 video codec.
3
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4
 *
5
 * This file is part of libde265.
6
 *
7
 * libde265 is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as
9
 * published by the Free Software Foundation, either version 3 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * libde265 is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifndef DE265_BITSTREAM_H
22
#define DE265_BITSTREAM_H
23
24
#include <cstdint>
25
26
27
// HEVC (ITU-T H.265, E.3.3) allows ue(v) values up to 2^32-2 (e.g. bit_rate_value_minus1),
28
// which requires 31 leading zeros in the exp-Golomb code. 32 leading zeros would give a
29
// minimum codeNum of 2^32-1, which exceeds every syntax element's valid range.
30
constexpr int MAX_UVLC_LEADING_ZEROS = 31;
31
constexpr uint32_t UVLC_ERROR = UINT32_MAX;
32
constexpr int32_t SVLC_ERROR = INT32_MIN;
33
34
35
class bitreader {
36
public:
37
0
  bitreader() = default;
38
  bitreader(unsigned char* buffer, int len);
39
40
  uint32_t get_bits(int n); // n in [0;32]
41
  uint32_t get_bits_fast(int n); // n in [0;32]
42
  uint32_t peek_bits(int n);
43
  void skip_bits(int n);
44
  void skip_bits_fast(int n);
45
  void skip_to_byte_boundary();
46
  void prepare_for_CABAC();
47
  uint32_t get_uvlc();  // may return UVLC_ERROR
48
  int32_t  get_svlc();  // may return SVLC_ERROR
49
50
  bool check_rbsp_trailing_bits(); // return true if remaining filler bits are all zero
51
52
  uint8_t* data = nullptr;
53
  int bytes_remaining = 0;
54
55
private:
56
  void refill(); // refill to at least 56+1 bits
57
58
  uint64_t nextbits = 0; // left-aligned bits
59
  int nextbits_cnt = 0;
60
};
61
62
#endif