#ifndef DE265_SLICE_H
#define DE265_SLICE_H
#include "libde265/cabac.h"
#include "libde265/de265.h"
#include "libde265/util.h"
#include "libde265/refpic.h"
#include "libde265/threads.h"
#include "contextmodel.h"
#include <vector>
#include <string.h>
#define MAX_NUM_REF_PICS 16
class decoder_context;
class thread_context;
class error_queue;
class seq_parameter_set;
class pic_parameter_set;
enum SliceType
{
SLICE_TYPE_B = 0,
SLICE_TYPE_P = 1,
SLICE_TYPE_I = 2
};
enum PartMode
{
PART_2Nx2N = 0,
PART_2NxN = 1,
PART_Nx2N = 2,
PART_NxN = 3,
PART_2NxnU = 4,
PART_2NxnD = 5,
PART_nLx2N = 6,
PART_nRx2N = 7
};
const char* part_mode_name(enum PartMode);
enum PredMode
{
MODE_INTRA, MODE_INTER, MODE_SKIP
};
enum IntraPredMode
{
INTRA_PLANAR = 0,
INTRA_DC = 1,
INTRA_ANGULAR_2 = 2, INTRA_ANGULAR_3 = 3, INTRA_ANGULAR_4 = 4, INTRA_ANGULAR_5 = 5,
INTRA_ANGULAR_6 = 6, INTRA_ANGULAR_7 = 7, INTRA_ANGULAR_8 = 8, INTRA_ANGULAR_9 = 9,
INTRA_ANGULAR_10 = 10, INTRA_ANGULAR_11 = 11, INTRA_ANGULAR_12 = 12, INTRA_ANGULAR_13 = 13,
INTRA_ANGULAR_14 = 14, INTRA_ANGULAR_15 = 15, INTRA_ANGULAR_16 = 16, INTRA_ANGULAR_17 = 17,
INTRA_ANGULAR_18 = 18, INTRA_ANGULAR_19 = 19, INTRA_ANGULAR_20 = 20, INTRA_ANGULAR_21 = 21,
INTRA_ANGULAR_22 = 22, INTRA_ANGULAR_23 = 23, INTRA_ANGULAR_24 = 24, INTRA_ANGULAR_25 = 25,
INTRA_ANGULAR_26 = 26, INTRA_ANGULAR_27 = 27, INTRA_ANGULAR_28 = 28, INTRA_ANGULAR_29 = 29,
INTRA_ANGULAR_30 = 30, INTRA_ANGULAR_31 = 31, INTRA_ANGULAR_32 = 32, INTRA_ANGULAR_33 = 33,
INTRA_ANGULAR_34 = 34
};
enum IntraChromaPredMode
{
INTRA_CHROMA_PLANAR_OR_34 = 0,
INTRA_CHROMA_ANGULAR_26_OR_34 = 1,
INTRA_CHROMA_ANGULAR_10_OR_34 = 2,
INTRA_CHROMA_DC_OR_34 = 3,
INTRA_CHROMA_LIKE_LUMA = 4
};
enum InterPredIdc
{
PRED_L0=1,
PRED_L1=2,
PRED_BI=3
};
class slice_segment_header {
public:
slice_segment_header() {
reset();
}
de265_error read(bitreader* br, decoder_context*, bool* continueDecoding);
de265_error write(error_queue*, CABAC_encoder&,
const seq_parameter_set* sps,
const pic_parameter_set* pps,
uint8_t nal_unit_type);
void dump_slice_segment_header(const decoder_context*, int fd) const;
void set_defaults();
void reset();
int slice_index;
const pic_parameter_set* pps;
char first_slice_segment_in_pic_flag;
char no_output_of_prior_pics_flag;
int slice_pic_parameter_set_id;
char dependent_slice_segment_flag;
int slice_segment_address;
int slice_type;
char pic_output_flag;
char colour_plane_id;
int slice_pic_order_cnt_lsb;
char short_term_ref_pic_set_sps_flag;
ref_pic_set slice_ref_pic_set;
int short_term_ref_pic_set_idx;
int num_long_term_sps;
int num_long_term_pics;
uint8_t lt_idx_sps[MAX_NUM_REF_PICS];
int poc_lsb_lt[MAX_NUM_REF_PICS];
char used_by_curr_pic_lt_flag[MAX_NUM_REF_PICS];
char delta_poc_msb_present_flag[MAX_NUM_REF_PICS];
int delta_poc_msb_cycle_lt[MAX_NUM_REF_PICS];
char slice_temporal_mvp_enabled_flag;
char slice_sao_luma_flag;
char slice_sao_chroma_flag;
char num_ref_idx_active_override_flag;
int num_ref_idx_l0_active;
int num_ref_idx_l1_active;
char ref_pic_list_modification_flag_l0;
char ref_pic_list_modification_flag_l1;
uint8_t list_entry_l0[16];
uint8_t list_entry_l1[16];
char mvd_l1_zero_flag;
char cabac_init_flag;
char collocated_from_l0_flag;
int collocated_ref_idx;
uint8_t luma_log2_weight_denom;
uint8_t ChromaLog2WeightDenom;
uint8_t luma_weight_flag[2][16];
uint8_t chroma_weight_flag[2][16];
int16_t LumaWeight[2][16];
int8_t luma_offset[2][16];
int16_t ChromaWeight[2][16][2];
int8_t ChromaOffset[2][16][2];
int five_minus_max_num_merge_cand;
int slice_qp_delta;
int slice_cb_qp_offset;
int slice_cr_qp_offset;
char cu_chroma_qp_offset_enabled_flag;
char deblocking_filter_override_flag;
char slice_deblocking_filter_disabled_flag;
int slice_beta_offset;
int slice_tc_offset;
char slice_loop_filter_across_slices_enabled_flag;
int num_entry_point_offsets;
int offset_len;
std::vector<int> entry_point_offset;
int slice_segment_header_extension_length;
int SliceQPY;
int initType;
void compute_derived_values(const pic_parameter_set* pps);
int SliceAddrRS;
int MaxNumMergeCand;
int CurrRpsIdx;
ref_pic_set CurrRps;
int NumPocTotalCurr;
int RefPicList[2][MAX_NUM_REF_PICS];
int RefPicList_POC[2][MAX_NUM_REF_PICS];
int RefPicList_PicState[2][MAX_NUM_REF_PICS];
char LongTermRefPic[2][MAX_NUM_REF_PICS];
context_model_table ctx_model_storage;
bool ctx_model_storage_defined;
std::vector<int> RemoveReferencesList;
};
typedef struct {
unsigned char SaoTypeIdx;
unsigned char SaoEoClass;
uint8_t sao_band_position[3];
int8_t saoOffsetVal[3][4];
} sao_info;
de265_error read_slice_segment_data(thread_context* tctx);
bool alloc_and_init_significant_coeff_ctxIdx_lookupTable();
void free_significant_coeff_ctxIdx_lookupTable();
class thread_task_ctb_row : public thread_task
{
public:
bool firstSliceSubstream;
int debug_startCtbRow;
thread_context* tctx;
virtual void work();
virtual std::string name() const;
};
class thread_task_slice_segment : public thread_task
{
public:
bool firstSliceSubstream;
int debug_startCtbX, debug_startCtbY;
thread_context* tctx;
virtual void work();
virtual std::string name() const;
};
int check_CTB_available(const de265_image* img,
int xC,int yC, int xN,int yN);
#endif