digiKam
slice.h
Go to the documentation of this file.
1 /*
2  * H.265 video codec.
3  * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4  *
5  * Authors: struktur AG, Dirk Farin <farin@struktur.de>
6  * Min Chen <chenm003@163.com>
7  *
8  * This file is part of libde265.
9  *
10  * libde265 is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as
12  * published by the Free Software Foundation, either version 3 of
13  * the License, or (at your option) any later version.
14  *
15  * libde265 is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with libde265. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef DE265_SLICE_H
25 #define DE265_SLICE_H
26 
27 #include "libde265/cabac.h"
28 #include "libde265/de265.h"
29 #include "libde265/util.h"
30 #include "libde265/refpic.h"
31 #include "libde265/threads.h"
32 #include "contextmodel.h"
33 
34 #include <vector>
35 #include <string.h>
36 #include <memory>
37 
38 #define MAX_NUM_REF_PICS 16
39 
40 class decoder_context;
41 class thread_context;
42 class error_queue;
43 class seq_parameter_set;
44 class pic_parameter_set;
45 
47  {
50  SLICE_TYPE_I = 2
51  };
52 
53 /*
54  2Nx2N 2NxN Nx2N NxN
55  +-------+ +-------+ +---+---+ +---+---+
56  | | | | | | | | | |
57  | | |_______| | | | |___|___|
58  | | | | | | | | | |
59  | | | | | | | | | |
60  +-------+ +-------+ +---+---+ +---+---+
61 
62  2NxnU 2NxnD nLx2N nRx2N
63  +-------+ +-------+ +-+-----+ +-----+-+
64  |_______| | | | | | | | |
65  | | | | | | | | | |
66  | | |_______| | | | | | |
67  | | | | | | | | | |
68  +-------+ +-------+ +-+-----+ +-----+-+
69 
70  - AMP only if CU size > min CU size -> minimum PU size = CUsize/2
71  - NxN only if size >= 16x16 (-> minimum block size = 8x8)
72  - minimum block size for Bi-Pred is 8x8 (wikipedia: Coding_tree_unit)
73 */
75  {
77  PART_2NxN = 1,
78  PART_Nx2N = 2,
79  PART_NxN = 3,
83  PART_nRx2N = 7
84  };
85 
86 const char* part_mode_name(enum PartMode);
87 
88 
90  {
92  };
93 
95  {
97  INTRA_DC = 1,
106  INTRA_ANGULAR_34 = 34
107  };
108 
109 
111  {
117  };
118 
119 
121  {
122  // note: values have to match the decoding function decode_inter_pred_idc()
125  PRED_BI=3
126  };
127 
128 
129 
131 public:
133  reset();
134  }
135 
136  de265_error read(bitreader* br, decoder_context*, bool* continueDecoding);
138  const seq_parameter_set* sps,
139  const pic_parameter_set* pps,
140  uint8_t nal_unit_type);
141 
142  void dump_slice_segment_header(const decoder_context*, int fd) const;
143 
144  void set_defaults();
145  void reset();
146 
147 
148  int slice_index; // index through all slices in a picture (internal only)
149  std::shared_ptr<const pic_parameter_set> pps;
150 
151 
157 
164 
168 
172 
175 
179 
181  int num_ref_idx_l0_active; // [1;16]
182  int num_ref_idx_l1_active; // [1;16]
183 
186  uint8_t list_entry_l0[16];
187  uint8_t list_entry_l1[16];
188 
193 
194  // --- pred_weight_table ---
195 
196  uint8_t luma_log2_weight_denom; // [0;7]
197  uint8_t ChromaLog2WeightDenom; // [0;7]
198 
199  // first index is L0/L1
200  uint8_t luma_weight_flag[2][16]; // bool
201  uint8_t chroma_weight_flag[2][16]; // bool
202  int16_t LumaWeight[2][16];
203  int8_t luma_offset[2][16];
204  int16_t ChromaWeight[2][16][2];
205  int8_t ChromaOffset[2][16][2];
206 
207 
210 
213 
215 
218  int slice_beta_offset; // = pps->beta_offset if undefined
219  int slice_tc_offset; // = pps->tc_offset if undefined
220 
222 
225  std::vector<int> entry_point_offset;
226 
228 
229 
230  // --- derived data ---
231 
232  int SliceQPY;
233  int initType;
234 
236 
237 
238  // --- data for external modules ---
239 
240  int SliceAddrRS; // slice_segment_address of last independent slice
241 
242  int MaxNumMergeCand; // directly derived from 'five_minus_max_num_merge_cand'
244  ref_pic_set CurrRps; // the active reference-picture set
246 
247  // number of entries: num_ref_idx_l0_active / num_ref_idx_l1_active
248  int RefPicList[2][MAX_NUM_REF_PICS]; // contains buffer IDs (D:indices into DPB/E:frame number)
250  int RefPicList_PicState[2][MAX_NUM_REF_PICS]; /* We have to save the PicState because the decoding
251  of an image may be delayed and the PicState can
252  change in the mean-time (e.g. from ShortTerm to
253  LongTerm). PicState is used in motion.cc */
254 
255  char LongTermRefPic[2][MAX_NUM_REF_PICS]; /* Flag whether the picture at this ref-pic-list
256  is a long-term picture. */
257 
258  // context storage for dependent slices (stores CABAC model at end of slice segment)
260  bool ctx_model_storage_defined; // whether there is valid data in ctx_model_storage
261 
262  std::vector<int> RemoveReferencesList; // images that can be removed from the DPB before decoding this slice
263 
264 };
265 
266 
267 
268 typedef struct {
269  // TODO: we could combine SaoTypeIdx and SaoEoClass into one byte to make the struct 16 bytes only
270 
271  unsigned char SaoTypeIdx; // use with (SaoTypeIdx>>(2*cIdx)) & 0x3
272  unsigned char SaoEoClass; // use with (SaoTypeIdx>>(2*cIdx)) & 0x3
273 
274  uint8_t sao_band_position[3];
275  int8_t saoOffsetVal[3][4]; // index with [][idx-1] as saoOffsetVal[][0]==0 always
276 } sao_info;
277 
278 
279 
280 
282 
285 
286 
288 {
289 public:
293 
294  virtual void work();
295  virtual std::string name() const;
296 };
297 
299 {
300 public:
304 
305  virtual void work();
306  virtual std::string name() const;
307 };
308 
309 
311  int xC,int yC, int xN,int yN);
312 
313 #endif
Definition: cabac.h:55
Definition: contextmodel.h:100
Definition: decctx.h:291
Definition: decctx.h:128
Definition: pps.h:59
Definition: refpic.h:30
Definition: sps.h:86
Definition: slice.h:130
uint8_t ChromaLog2WeightDenom
Definition: slice.h:197
slice_segment_header()
Definition: slice.h:132
int short_term_ref_pic_set_idx
Definition: slice.h:165
int CurrRpsIdx
Definition: slice.h:243
int five_minus_max_num_merge_cand
Definition: slice.h:208
int MaxNumMergeCand
Definition: slice.h:242
int collocated_ref_idx
Definition: slice.h:192
char ref_pic_list_modification_flag_l1
Definition: slice.h:185
int slice_cr_qp_offset
Definition: slice.h:212
char mvd_l1_zero_flag
Definition: slice.h:189
char slice_deblocking_filter_disabled_flag
Definition: slice.h:217
int8_t luma_offset[2][16]
Definition: slice.h:203
char pic_output_flag
Definition: slice.h:159
char collocated_from_l0_flag
Definition: slice.h:191
int NumPocTotalCurr
Definition: slice.h:245
de265_error write(error_queue *, CABAC_encoder &, const seq_parameter_set *sps, const pic_parameter_set *pps, uint8_t nal_unit_type)
uint8_t list_entry_l0[16]
Definition: slice.h:186
void compute_derived_values(const pic_parameter_set *pps)
uint8_t lt_idx_sps[MAX_NUM_REF_PICS]
Definition: slice.h:169
int slice_segment_header_extension_length
Definition: slice.h:227
context_model_table ctx_model_storage
Definition: slice.h:259
char slice_sao_luma_flag
Definition: slice.h:177
bool ctx_model_storage_defined
Definition: slice.h:260
int16_t LumaWeight[2][16]
Definition: slice.h:202
std::vector< int > RemoveReferencesList
Definition: slice.h:262
char slice_loop_filter_across_slices_enabled_flag
Definition: slice.h:221
std::shared_ptr< const pic_parameter_set > pps
Definition: slice.h:149
char slice_sao_chroma_flag
Definition: slice.h:178
char cabac_init_flag
Definition: slice.h:190
char dependent_slice_segment_flag
Definition: slice.h:155
uint8_t luma_weight_flag[2][16]
Definition: slice.h:200
char used_by_curr_pic_lt_flag[MAX_NUM_REF_PICS]
Definition: slice.h:171
int slice_type
Definition: slice.h:158
int num_long_term_pics
Definition: slice.h:167
de265_error read(bitreader *br, decoder_context *, bool *continueDecoding)
int slice_cb_qp_offset
Definition: slice.h:211
int SliceQPY
Definition: slice.h:232
char ref_pic_list_modification_flag_l0
Definition: slice.h:184
void dump_slice_segment_header(const decoder_context *, int fd) const
ref_pic_set CurrRps
Definition: slice.h:244
uint8_t luma_log2_weight_denom
Definition: slice.h:196
int RefPicList_PicState[2][MAX_NUM_REF_PICS]
Definition: slice.h:250
char delta_poc_msb_present_flag[MAX_NUM_REF_PICS]
Definition: slice.h:173
int RefPicList_POC[2][MAX_NUM_REF_PICS]
Definition: slice.h:249
int num_long_term_sps
Definition: slice.h:166
int num_ref_idx_l1_active
Definition: slice.h:182
int slice_pic_parameter_set_id
Definition: slice.h:154
char deblocking_filter_override_flag
Definition: slice.h:216
int num_entry_point_offsets
Definition: slice.h:223
int num_ref_idx_l0_active
Definition: slice.h:181
char first_slice_segment_in_pic_flag
Definition: slice.h:152
std::vector< int > entry_point_offset
Definition: slice.h:225
int delta_poc_msb_cycle_lt[MAX_NUM_REF_PICS]
Definition: slice.h:174
int slice_beta_offset
Definition: slice.h:218
char cu_chroma_qp_offset_enabled_flag
Definition: slice.h:214
char colour_plane_id
Definition: slice.h:160
int8_t ChromaOffset[2][16][2]
Definition: slice.h:205
int slice_segment_address
Definition: slice.h:156
uint8_t chroma_weight_flag[2][16]
Definition: slice.h:201
int slice_index
Definition: slice.h:148
int16_t ChromaWeight[2][16][2]
Definition: slice.h:204
char slice_temporal_mvp_enabled_flag
Definition: slice.h:176
int initType
Definition: slice.h:233
int slice_qp_delta
Definition: slice.h:209
char short_term_ref_pic_set_sps_flag
Definition: slice.h:162
int RefPicList[2][MAX_NUM_REF_PICS]
Definition: slice.h:248
char no_output_of_prior_pics_flag
Definition: slice.h:153
uint8_t list_entry_l1[16]
Definition: slice.h:187
int SliceAddrRS
Definition: slice.h:240
int poc_lsb_lt[MAX_NUM_REF_PICS]
Definition: slice.h:170
char num_ref_idx_active_override_flag
Definition: slice.h:180
ref_pic_set slice_ref_pic_set
Definition: slice.h:163
char LongTermRefPic[2][MAX_NUM_REF_PICS]
Definition: slice.h:255
int slice_tc_offset
Definition: slice.h:219
int slice_pic_order_cnt_lsb
Definition: slice.h:161
int offset_len
Definition: slice.h:224
Definition: decctx.h:54
Definition: slice.h:288
bool firstSliceSubstream
Definition: slice.h:290
thread_context * tctx
Definition: slice.h:292
virtual std::string name() const
int debug_startCtbRow
Definition: slice.h:291
virtual void work()
Definition: slice.h:299
thread_context * tctx
Definition: slice.h:303
int debug_startCtbY
Definition: slice.h:302
virtual std::string name() const
int debug_startCtbX
Definition: slice.h:302
bool firstSliceSubstream
Definition: slice.h:301
Definition: threads.h:102
de265_error
Definition: de265.h:82
#define MAX_NUM_REF_PICS
Definition: slice.h:38
PredMode
Definition: slice.h:90
@ MODE_INTRA
Definition: slice.h:91
@ MODE_INTER
Definition: slice.h:91
@ MODE_SKIP
Definition: slice.h:91
PartMode
Definition: slice.h:75
@ PART_2Nx2N
Definition: slice.h:76
@ PART_Nx2N
Definition: slice.h:78
@ PART_NxN
Definition: slice.h:79
@ PART_2NxnD
Definition: slice.h:81
@ PART_nLx2N
Definition: slice.h:82
@ PART_2NxN
Definition: slice.h:77
@ PART_2NxnU
Definition: slice.h:80
@ PART_nRx2N
Definition: slice.h:83
const char * part_mode_name(enum PartMode)
de265_error read_slice_segment_data(thread_context *tctx)
IntraPredMode
Definition: slice.h:95
@ INTRA_ANGULAR_22
Definition: slice.h:103
@ INTRA_ANGULAR_7
Definition: slice.h:99
@ INTRA_ANGULAR_17
Definition: slice.h:101
@ INTRA_ANGULAR_26
Definition: slice.h:104
@ INTRA_ANGULAR_31
Definition: slice.h:105
@ INTRA_ANGULAR_4
Definition: slice.h:98
@ INTRA_DC
Definition: slice.h:97
@ INTRA_ANGULAR_14
Definition: slice.h:101
@ INTRA_ANGULAR_5
Definition: slice.h:98
@ INTRA_ANGULAR_8
Definition: slice.h:99
@ INTRA_ANGULAR_3
Definition: slice.h:98
@ INTRA_ANGULAR_13
Definition: slice.h:100
@ INTRA_ANGULAR_21
Definition: slice.h:102
@ INTRA_ANGULAR_23
Definition: slice.h:103
@ INTRA_ANGULAR_10
Definition: slice.h:100
@ INTRA_ANGULAR_12
Definition: slice.h:100
@ INTRA_ANGULAR_19
Definition: slice.h:102
@ INTRA_ANGULAR_29
Definition: slice.h:104
@ INTRA_ANGULAR_34
Definition: slice.h:106
@ INTRA_ANGULAR_33
Definition: slice.h:105
@ INTRA_ANGULAR_6
Definition: slice.h:99
@ INTRA_ANGULAR_2
Definition: slice.h:98
@ INTRA_ANGULAR_25
Definition: slice.h:103
@ INTRA_ANGULAR_20
Definition: slice.h:102
@ INTRA_ANGULAR_18
Definition: slice.h:102
@ INTRA_ANGULAR_24
Definition: slice.h:103
@ INTRA_ANGULAR_9
Definition: slice.h:99
@ INTRA_ANGULAR_30
Definition: slice.h:105
@ INTRA_ANGULAR_16
Definition: slice.h:101
@ INTRA_ANGULAR_11
Definition: slice.h:100
@ INTRA_ANGULAR_28
Definition: slice.h:104
@ INTRA_ANGULAR_15
Definition: slice.h:101
@ INTRA_PLANAR
Definition: slice.h:96
@ INTRA_ANGULAR_32
Definition: slice.h:105
@ INTRA_ANGULAR_27
Definition: slice.h:104
InterPredIdc
Definition: slice.h:121
@ PRED_L0
Definition: slice.h:123
@ PRED_BI
Definition: slice.h:125
@ PRED_L1
Definition: slice.h:124
void free_significant_coeff_ctxIdx_lookupTable()
SliceType
Definition: slice.h:47
@ SLICE_TYPE_I
Definition: slice.h:50
@ SLICE_TYPE_P
Definition: slice.h:49
@ SLICE_TYPE_B
Definition: slice.h:48
bool alloc_and_init_significant_coeff_ctxIdx_lookupTable()
IntraChromaPredMode
Definition: slice.h:111
@ INTRA_CHROMA_LIKE_LUMA
Definition: slice.h:116
@ INTRA_CHROMA_DC_OR_34
Definition: slice.h:115
@ INTRA_CHROMA_ANGULAR_26_OR_34
Definition: slice.h:113
@ INTRA_CHROMA_ANGULAR_10_OR_34
Definition: slice.h:114
@ INTRA_CHROMA_PLANAR_OR_34
Definition: slice.h:112
int check_CTB_available(const de265_image *img, int xC, int yC, int xN, int yN)
Definition: bitstream.h:39
Definition: image.h:222
Definition: slice.h:268
unsigned char SaoEoClass
Definition: slice.h:272
unsigned char SaoTypeIdx
Definition: slice.h:271