Coverage Report

Created: 2026-06-10 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/pps.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_PPS_H
22
#define DE265_PPS_H
23
24
#include "libde265/bitstream.h"
25
#include "libde265/sps.h" // for scaling list only
26
27
#include <vector>
28
#include <memory>
29
30
constexpr int DE265_MAX_TILE_COLUMNS = 10;
31
constexpr int DE265_MAX_TILE_ROWS    = 10;
32
33
class decoder_context;
34
class pic_parameter_set;
35
36
37
class pps_range_extension
38
{
39
 public:
40
1.53k
  pps_range_extension() { reset(); }
41
42
  void reset();
43
44
  bool read(bitreader*, decoder_context*, const pic_parameter_set*);
45
  void dump(int fd) const;
46
47
  uint8_t log2_max_transform_skip_block_size;
48
  bool    cross_component_prediction_enabled_flag;
49
  bool    chroma_qp_offset_list_enabled_flag;
50
  uint8_t diff_cu_chroma_qp_offset_depth;
51
  uint8_t chroma_qp_offset_list_len;
52
  int8_t  cb_qp_offset_list[6];
53
  int8_t  cr_qp_offset_list[6];
54
  uint8_t log2_sao_offset_scale_luma;
55
  uint8_t log2_sao_offset_scale_chroma;
56
};
57
58
59
// Picture-geometry-derived scan-order tables (HEVC Sec. 6.5). They depend only
60
// on the picture/tile geometry, are immutable after construction, and are shared
61
// read-only across pic_parameter_set instances (and across independent decoder
62
// contexts) through a small library-scope cache -- see pps.cc. Sharing avoids
63
// recomputing the (potentially large) MinTbAddrZS table once per decoder when
64
// many contexts decode images of the same geometry (e.g. libheif tile grids).
65
struct pps_scan_tables {
66
  std::vector<uint32_t> CtbAddrRStoTS; // #CTBs
67
  std::vector<uint32_t> CtbAddrTStoRS; // #CTBs
68
  std::vector<uint32_t> TileId;        // #CTBs  // index in tile-scan order
69
  std::vector<uint32_t> TileIdRS;      // #CTBs  // index in raster-scan order
70
  std::vector<uint32_t> MinTbAddrZS;   // #TBs   [x + y*PicWidthInTbsY]
71
};
72
73
// Library-scope scan-table cache lifecycle, tied to de265_init() / de265_free()
74
// so the cache is released when the library is de-initialized (no leak at exit).
75
void pps_scan_cache_init();
76
void pps_scan_cache_free();
77
78
79
class pic_parameter_set {
80
public:
81
  pic_parameter_set();
82
  ~pic_parameter_set();
83
84
3.07k
  void reset() { set_defaults(); }
85
  bool read(bitreader*, decoder_context*);
86
  bool write(error_queue*, CABAC_encoder&,
87
             const seq_parameter_set* sps);
88
89
  bool is_tile_start_CTB(int ctbX,int ctbY) const;
90
  void dump(int fd) const;
91
92
93
  void set_defaults(enum PresetSet = Preset_Default);
94
95
  bool pps_read; // whether this pps has been read from bitstream
96
  std::shared_ptr<const seq_parameter_set> sps;
97
98
99
  uint8_t pic_parameter_set_id;
100
  uint8_t seq_parameter_set_id;
101
  bool dependent_slice_segments_enabled_flag;
102
  bool sign_data_hiding_flag;
103
  bool cabac_init_present_flag;
104
  uint8_t num_ref_idx_l0_default_active; // [1;16]
105
  uint8_t num_ref_idx_l1_default_active; // [1;16]
106
107
  int pic_init_qp;
108
  bool constrained_intra_pred_flag;
109
  bool transform_skip_enabled_flag;
110
111
  // --- QP ---
112
113
  bool cu_qp_delta_enabled_flag;
114
  uint8_t diff_cu_qp_delta_depth;   // [ 0 ; log2_diff_max_min_luma_coding_block_size ]
115
116
  int  pic_cb_qp_offset;
117
  int  pic_cr_qp_offset;
118
  bool pps_slice_chroma_qp_offsets_present_flag;
119
120
121
  bool weighted_pred_flag;
122
  bool weighted_bipred_flag;
123
  bool output_flag_present_flag;
124
  bool transquant_bypass_enable_flag;
125
  bool entropy_coding_sync_enabled_flag;
126
127
128
  // --- tiles ---
129
130
  bool tiles_enabled_flag;
131
  uint8_t num_tile_columns;  // [1;PicWidthInCtbsY] max DE265_MAX_TILE_COLUMNS
132
  uint8_t num_tile_rows;     // [1;PicHeightInCtbsY] max DE265_MAX_TILE_ROWS
133
  bool uniform_spacing_flag;
134
135
136
  // --- ---
137
138
  bool loop_filter_across_tiles_enabled_flag;
139
  bool pps_loop_filter_across_slices_enabled_flag;
140
  bool deblocking_filter_control_present_flag;
141
142
  bool deblocking_filter_override_enabled_flag;
143
  bool pic_disable_deblocking_filter_flag;
144
145
  int8_t beta_offset;  // [-12;12]
146
  int8_t tc_offset;    // [-12;12]
147
148
  bool pic_scaling_list_data_present_flag;
149
  scaling_list_data scaling_list; // contains valid data if sps->scaling_list_enabled_flag set
150
151
  bool lists_modification_present_flag;
152
  uint8_t log2_parallel_merge_level; // [2 ; log2(max CB size)]
153
  uint8_t num_extra_slice_header_bits;
154
  bool slice_segment_header_extension_present_flag;
155
  bool pps_extension_flag;
156
  bool pps_range_extension_flag;
157
  bool pps_multilayer_extension_flag;
158
  uint8_t pps_extension_6bits;
159
160
  pps_range_extension range_extension;
161
162
163
  // --- derived values ---
164
165
  int Log2MinCuQpDeltaSize;
166
  int Log2MinCuChromaQpOffsetSize;
167
  int Log2MaxTransformSkipSize;
168
169
  uint16_t colWidth [ DE265_MAX_TILE_COLUMNS ];
170
  uint16_t rowHeight[ DE265_MAX_TILE_ROWS ];
171
  uint16_t colBd    [ DE265_MAX_TILE_COLUMNS+1 ];
172
  uint16_t rowBd    [ DE265_MAX_TILE_ROWS+1 ];
173
174
  // Derived scan-order tables (Sec. 6.5), shared read-only via the library-scope
175
  // cache. Access as scan->CtbAddrRStoTS[...], scan->MinTbAddrZS[...], etc.
176
  std::shared_ptr<const pps_scan_tables> scan;
177
178
  void set_derived_values(const seq_parameter_set* sps);
179
};
180
181
#endif