Coverage Report

Created: 2026-05-30 06:10

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