Coverage Report

Created: 2026-06-15 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libde265/libde265/sps.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_SPS_H
22
#define DE265_SPS_H
23
24
#include "libde265/vps.h"
25
#include "libde265/vui.h"
26
#include "libde265/bitstream.h"
27
#include "libde265/refpic.h"
28
#include "libde265/de265.h"
29
#include "libde265/cabac.h"
30
31
#include <vector>
32
33
class error_queue;
34
35
// #define MAX_REF_PIC_SETS 64  // maximum according to standard
36
constexpr int MAX_NUM_LT_REF_PICS_SPS = 32;
37
38
// This is just a safety range. It is chosen such that width/height fits into 16bit integers and the total number of pixels in 32bit integers.
39
constexpr int MAX_PICTURE_WIDTH  = 65535;
40
constexpr int MAX_PICTURE_HEIGHT = 65535;
41
42
// pic_width/height_in_luma_samples are stored as uint16_t and PicSizeInSamplesY as uint32_t,
43
// so these limits must keep width/height in 16 bits and their product in 32 bits.
44
static_assert(MAX_PICTURE_WIDTH  <= 0xFFFF, "picture width must fit in uint16_t");
45
static_assert(MAX_PICTURE_HEIGHT <= 0xFFFF, "picture height must fit in uint16_t");
46
static_assert((uint64_t)MAX_PICTURE_WIDTH * MAX_PICTURE_HEIGHT <= 0xFFFFFFFFu,
47
              "total luma sample count must fit in uint32_t");
48
49
enum {
50
  CHROMA_MONO = 0,
51
  CHROMA_420 = 1,
52
  CHROMA_422 = 2,
53
  CHROMA_444 = 3,
54
  CHROMA_444_SEPARATE
55
};
56
57
58
struct scaling_list_data {
59
  // structure size: approx. 4 kB
60
61
  uint8_t ScalingFactor_Size0[6][4][4];
62
  uint8_t ScalingFactor_Size1[6][8][8];
63
  uint8_t ScalingFactor_Size2[6][16][16];
64
  uint8_t ScalingFactor_Size3[6][32][32];
65
};
66
67
68
enum PresetSet {
69
  Preset_Default
70
};
71
72
73
class sps_range_extension
74
{
75
 public:
76
  sps_range_extension();
77
78
  uint8_t transform_skip_rotation_enabled_flag = 0;
79
  uint8_t transform_skip_context_enabled_flag = 0;
80
  uint8_t implicit_rdpcm_enabled_flag = 0;
81
  uint8_t explicit_rdpcm_enabled_flag = 0;
82
  uint8_t extended_precision_processing_flag = 0;
83
  uint8_t intra_smoothing_disabled_flag = 0;
84
  uint8_t high_precision_offsets_enabled_flag = 0;
85
  uint8_t persistent_rice_adaptation_enabled_flag = 0;
86
  uint8_t cabac_bypass_alignment_enabled_flag = 0;
87
88
  de265_error read(error_queue*, bitreader*);
89
  void dump(int fd) const;
90
};
91
92
93
class seq_parameter_set {
94
public:
95
  seq_parameter_set();
96
  ~seq_parameter_set();
97
98
  de265_error read(error_queue*, bitreader*);
99
  de265_error write(error_queue*, CABAC_encoder&);
100
101
  void dump(int fd) const;
102
103
  void set_defaults(enum PresetSet = Preset_Default);
104
  void set_CB_log2size_range(int mini,int maxi);
105
  void set_TB_log2size_range(int mini,int maxi);
106
  void set_resolution(int w,int h);
107
108
  bool sps_read = false; // whether the sps has been read from the bitstream
109
110
111
  uint8_t video_parameter_set_id;
112
  uint8_t sps_max_sub_layers;            // [1;7]
113
  bool sps_temporal_id_nesting_flag;
114
115
  profile_tier_level profile_tier_level_;
116
117
  uint8_t seq_parameter_set_id;       // [0;15]
118
  uint8_t chroma_format_idc;          // [0;3]
119
120
  bool separate_colour_plane_flag;
121
  uint16_t pic_width_in_luma_samples;   // <= MAX_PICTURE_WIDTH  (validated on parse)
122
  uint16_t pic_height_in_luma_samples;  // <= MAX_PICTURE_HEIGHT (validated on parse)
123
  bool conformance_window_flag;
124
125
  int conf_win_left_offset;
126
  int conf_win_right_offset;
127
  int conf_win_top_offset;
128
  int conf_win_bottom_offset;
129
130
  uint8_t bit_depth_luma;              // [8;16]
131
  uint8_t bit_depth_chroma;            // [8;16]
132
133
  uint8_t log2_max_pic_order_cnt_lsb; // [4;16]
134
  bool sps_sub_layer_ordering_info_present_flag;
135
136
  uint8_t sps_max_dec_pic_buffering[7]; // for each temporal layer
137
  uint8_t sps_max_num_reorder_pics[7];
138
  uint32_t sps_max_latency_increase_plus1[7];
139
  bool     sps_max_latency_increase_present[7] = {};
140
141
  uint8_t log2_min_luma_coding_block_size;             // smallest CB size [3;6]
142
  uint8_t log2_diff_max_min_luma_coding_block_size;    // largest  CB size
143
  uint8_t log2_min_transform_block_size;               // smallest TB size [2;5]
144
  uint8_t log2_diff_max_min_transform_block_size;      // largest  TB size
145
  uint8_t max_transform_hierarchy_depth_inter;
146
  uint8_t max_transform_hierarchy_depth_intra;
147
148
  bool scaling_list_enable_flag;
149
  bool sps_scaling_list_data_present_flag; /* if not set, the default scaling lists will be set
150
                                              in scaling_list */
151
152
  struct scaling_list_data scaling_list;
153
154
  bool amp_enabled_flag;
155
  bool sample_adaptive_offset_enabled_flag;
156
  bool pcm_enabled_flag;
157
158
  uint8_t pcm_sample_bit_depth_luma;
159
  uint8_t pcm_sample_bit_depth_chroma;
160
  int  log2_min_pcm_luma_coding_block_size;
161
  int  log2_diff_max_min_pcm_luma_coding_block_size;
162
  bool pcm_loop_filter_disable_flag;
163
164
0
  int num_short_term_ref_pic_sets() const { return ref_pic_sets.size(); }
165
  std::vector<ref_pic_set> ref_pic_sets; // [0 ; num_short_term_ref_pic_set (<=MAX_REF_PIC_SETS) )
166
167
  bool long_term_ref_pics_present_flag;
168
169
  uint8_t num_long_term_ref_pics_sps; // [0;32]
170
171
  int  lt_ref_pic_poc_lsb_sps[MAX_NUM_LT_REF_PICS_SPS];
172
  bool used_by_curr_pic_lt_sps_flag[MAX_NUM_LT_REF_PICS_SPS];
173
174
  bool sps_temporal_mvp_enabled_flag;
175
  bool strong_intra_smoothing_enable_flag;
176
177
  bool vui_parameters_present_flag;
178
  video_usability_information vui;
179
180
  bool sps_extension_present_flag;
181
  bool sps_range_extension_flag;
182
  bool sps_multilayer_extension_flag;
183
  uint8_t sps_extension_6bits;
184
185
  sps_range_extension range_extension;
186
187
  /*
188
    if( sps_extension_flag )
189
    while( more_rbsp_data() )
190
    sps_extension_data_flag
191
    u(1)
192
    rbsp_trailing_bits()
193
  */
194
195
196
  // --- derived values ---
197
198
  de265_error compute_derived_values(bool sanitize_values = false);
199
200
  int BitDepth_Y;
201
  int QpBdOffset_Y;
202
  int BitDepth_C;
203
  int QpBdOffset_C;
204
205
  int ChromaArrayType;
206
  int SubWidthC, SubHeightC;
207
  int WinUnitX, WinUnitY;
208
209
  int MaxPicOrderCntLsb;
210
211
  uint8_t Log2MinCbSizeY;
212
  uint8_t Log2CtbSizeY;
213
  uint8_t MinCbSizeY;
214
  uint8_t CtbSizeY;
215
  uint16_t PicWidthInMinCbsY;
216
  uint16_t PicWidthInCtbsY;
217
  uint16_t PicHeightInMinCbsY;
218
  uint16_t PicHeightInCtbsY;
219
  uint32_t PicSizeInMinCbsY;
220
  uint32_t PicSizeInCtbsY;
221
  uint32_t PicSizeInSamplesY;
222
223
  int CtbWidthC, CtbHeightC;
224
225
  int PicWidthInTbsY; // not in standard
226
  int PicHeightInTbsY; // not in standard
227
  int PicSizeInTbsY; // not in standard
228
229
  int Log2MinTrafoSize;
230
  int Log2MaxTrafoSize;
231
232
  int Log2MinPUSize;
233
  int PicWidthInMinPUs;  // might be rounded up
234
  int PicHeightInMinPUs; // might be rounded up
235
236
  int Log2MinIpcmCbSizeY;
237
  int Log2MaxIpcmCbSizeY;
238
239
  int SpsMaxLatencyPictures[7] = {}; // [temporal layer]
240
241
  uint8_t WpOffsetBdShiftY;
242
  uint8_t WpOffsetBdShiftC;
243
  uint16_t WpOffsetHalfRangeY;
244
  uint16_t WpOffsetHalfRangeC;
245
246
247
0
  int getPUIndexRS(int pixelX,int pixelY) const {
248
0
    return (pixelX>>Log2MinPUSize) + (pixelY>>Log2MinPUSize)*PicWidthInMinPUs;
249
0
  }
250
251
0
  int get_bit_depth(int cIdx) const {
252
0
    if (cIdx==0) return BitDepth_Y;
253
0
    else         return BitDepth_C;
254
0
  }
255
256
0
  int get_chroma_shift_W(int cIdx) const { return cIdx ? SubWidthC -1 : 0; }
257
0
  int get_chroma_shift_H(int cIdx) const { return cIdx ? SubHeightC-1 : 0; }
258
};
259
260
de265_error read_scaling_list(bitreader*, const seq_parameter_set*, scaling_list_data*, bool inPPS);
261
de265_error write_scaling_list(CABAC_encoder& out, const seq_parameter_set* sps,
262
                               scaling_list_data* sclist, bool inPPS);
263
void set_default_scaling_lists(scaling_list_data*);
264
265
#endif