Commit b11acd57 authored by Anton Khirnov's avatar Anton Khirnov

hevc: remove HEVCContext usage from hevc_ps

Factor out the parameter sets into a separate struct and use it instead.

This will allow us to reuse this code in the parser.
parent ab05ed4c
This diff is collapsed.
......@@ -525,6 +525,17 @@ typedef struct HEVCPPS {
int *min_tb_addr_zs; ///< MinTbAddrZS
} HEVCPPS;
typedef struct HEVCParamSets {
AVBufferRef *vps_list[MAX_VPS_COUNT];
AVBufferRef *sps_list[MAX_SPS_COUNT];
AVBufferRef *pps_list[MAX_PPS_COUNT];
/* currently active parameter sets */
const HEVCVPS *vps;
const HEVCSPS *sps;
const HEVCPPS *pps;
} HEVCParamSets;
typedef struct SliceHeader {
unsigned int pps_id;
......@@ -769,12 +780,7 @@ typedef struct HEVCContext {
AVFrame *tmp_frame;
AVFrame *output_frame;
const HEVCVPS *vps;
const HEVCSPS *sps;
const HEVCPPS *pps;
AVBufferRef *vps_list[MAX_VPS_COUNT];
AVBufferRef *sps_list[MAX_SPS_COUNT];
AVBufferRef *pps_list[MAX_PPS_COUNT];
HEVCParamSets ps;
AVBufferPool *tab_mvf_pool;
AVBufferPool *rpl_tab_pool;
......@@ -878,9 +884,12 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx);
int ff_hevc_decode_nal_vps(HEVCContext *s);
int ff_hevc_decode_nal_sps(HEVCContext *s);
int ff_hevc_decode_nal_pps(HEVCContext *s);
int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
HEVCParamSets *ps);
int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
HEVCParamSets *ps, int apply_defdispwin);
int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
HEVCParamSets *ps);
int ff_hevc_decode_nal_sei(HEVCContext *s);
/**
......
......@@ -325,10 +325,10 @@ static const uint8_t init_values[3][HEVC_CONTEXTS] = {
void ff_hevc_save_states(HEVCContext *s, int ctb_addr_ts)
{
if (s->pps->entropy_coding_sync_enabled_flag &&
(ctb_addr_ts % s->sps->ctb_width == 2 ||
(s->sps->ctb_width == 2 &&
ctb_addr_ts % s->sps->ctb_width == 0))) {
if (s->ps.pps->entropy_coding_sync_enabled_flag &&
(ctb_addr_ts % s->ps.sps->ctb_width == 2 ||
(s->ps.sps->ctb_width == 2 &&
ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
memcpy(s->cabac_state, s->HEVClc.cabac_state, HEVC_CONTEXTS);
}
}
......@@ -376,34 +376,34 @@ static void cabac_init_state(HEVCContext *s)
void ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
{
if (ctb_addr_ts == s->pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
cabac_init_decoder(s);
if (s->sh.dependent_slice_segment_flag == 0 ||
(s->pps->tiles_enabled_flag &&
s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[ctb_addr_ts - 1]))
(s->ps.pps->tiles_enabled_flag &&
s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]))
cabac_init_state(s);
if (!s->sh.first_slice_in_pic_flag &&
s->pps->entropy_coding_sync_enabled_flag) {
if (ctb_addr_ts % s->sps->ctb_width == 0) {
if (s->sps->ctb_width == 1)
s->ps.pps->entropy_coding_sync_enabled_flag) {
if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
if (s->ps.sps->ctb_width == 1)
cabac_init_state(s);
else if (s->sh.dependent_slice_segment_flag == 1)
load_states(s);
}
}
} else {
if (s->pps->tiles_enabled_flag &&
s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[ctb_addr_ts - 1]) {
if (s->ps.pps->tiles_enabled_flag &&
s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {
cabac_reinit(&s->HEVClc);
cabac_init_state(s);
}
if (s->pps->entropy_coding_sync_enabled_flag) {
if (ctb_addr_ts % s->sps->ctb_width == 0) {
if (s->ps.pps->entropy_coding_sync_enabled_flag) {
if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
get_cabac_terminate(&s->HEVClc.cc);
cabac_reinit(&s->HEVClc);
if (s->sps->ctb_width == 1)
if (s->ps.sps->ctb_width == 1)
cabac_init_state(s);
else
load_states(s);
......@@ -442,7 +442,7 @@ int ff_hevc_sao_band_position_decode(HEVCContext *s)
int ff_hevc_sao_offset_abs_decode(HEVCContext *s)
{
int i = 0;
int length = (1 << (FFMIN(s->sps->bit_depth, 10) - 5)) - 1;
int length = (1 << (FFMIN(s->ps.sps->bit_depth, 10) - 5)) - 1;
while (i < length && get_cabac_bypass(&s->HEVClc.cc))
i++;
......@@ -473,10 +473,10 @@ int ff_hevc_cu_transquant_bypass_flag_decode(HEVCContext *s)
int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb)
{
int min_cb_width = s->sps->min_cb_width;
int min_cb_width = s->ps.sps->min_cb_width;
int inc = 0;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x0b = x0 & ((1 << s->ps.sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->ps.sps->log2_ctb_size) - 1);
if (s->HEVClc.ctb_left_flag || x0b)
inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
......@@ -524,15 +524,15 @@ int ff_hevc_pred_mode_decode(HEVCContext *s)
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0)
{
int inc = 0, depth_left = 0, depth_top = 0;
int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1);
int x_cb = x0 >> s->sps->log2_min_cb_size;
int y_cb = y0 >> s->sps->log2_min_cb_size;
int x0b = x0 & ((1 << s->ps.sps->log2_ctb_size) - 1);
int y0b = y0 & ((1 << s->ps.sps->log2_ctb_size) - 1);
int x_cb = x0 >> s->ps.sps->log2_min_cb_size;
int y_cb = y0 >> s->ps.sps->log2_min_cb_size;
if (s->HEVClc.ctb_left_flag || x0b)
depth_left = s->tab_ct_depth[(y_cb) * s->sps->min_cb_width + x_cb - 1];
depth_left = s->tab_ct_depth[(y_cb) * s->ps.sps->min_cb_width + x_cb - 1];
if (s->HEVClc.ctb_up_flag || y0b)
depth_top = s->tab_ct_depth[(y_cb - 1) * s->sps->min_cb_width + x_cb];
depth_top = s->tab_ct_depth[(y_cb - 1) * s->ps.sps->min_cb_width + x_cb];
inc += (depth_left > ct_depth);
inc += (depth_top > ct_depth);
......@@ -544,7 +544,7 @@ int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size)
{
if (GET_CABAC(elem_offset[PART_MODE])) // 1
return PART_2Nx2N;
if (log2_cb_size == s->sps->log2_min_cb_size) {
if (log2_cb_size == s->ps.sps->log2_min_cb_size) {
if (s->HEVClc.cu.pred_mode == MODE_INTRA) // 0
return PART_NxN;
if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
......@@ -556,7 +556,7 @@ int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size)
return PART_NxN; // 000
}
if (!s->sps->amp_enabled_flag) {
if (!s->ps.sps->amp_enabled_flag) {
if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
return PART_2NxN;
return PART_Nx2N;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -55,11 +55,11 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags)
RefPicList *ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *ref, int x0, int y0)
{
int x_cb = x0 >> s->sps->log2_ctb_size;
int y_cb = y0 >> s->sps->log2_ctb_size;
int pic_width_cb = (s->sps->width + (1 << s->sps->log2_ctb_size) - 1) >>
s->sps->log2_ctb_size;
int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
int x_cb = x0 >> s->ps.sps->log2_ctb_size;
int y_cb = y0 >> s->ps.sps->log2_ctb_size;
int pic_width_cb = (s->ps.sps->width + (1 << s->ps.sps->log2_ctb_size) - 1) >>
s->ps.sps->log2_ctb_size;
int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
return (RefPicList *)ref->rpl_tab[ctb_addr_ts];
}
......@@ -105,7 +105,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
if (!frame->rpl_tab_buf)
goto fail;
frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data;
frame->ctb_count = s->sps->ctb_width * s->sps->ctb_height;
frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
for (j = 0; j < frame->ctb_count; j++)
frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data;
......@@ -161,7 +161,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
ref->poc = poc;
ref->sequence = s->seq_decode;
ref->window = s->sps->output_window;
ref->window = s->ps.sps->output_window;
return 0;
}
......@@ -186,8 +186,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
}
/* wait for more frames before output */
if (!flush && s->seq_output == s->seq_decode && s->sps &&
nb_output <= s->sps->temporal_layer[s->sps->max_sub_layers - 1].num_reorder_pics)
if (!flush && s->seq_output == s->seq_decode && s->ps.sps &&
nb_output <= s->ps.sps->temporal_layer[s->ps.sps->max_sub_layers - 1].num_reorder_pics)
return 0;
if (nb_output) {
......@@ -230,7 +230,7 @@ static int init_slice_rpl(HEVCContext *s)
{
HEVCFrame *frame = s->ref;
int ctb_count = frame->ctb_count;
int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
int i;
if (s->slice_idx >= frame->rpl_buf->size / sizeof(RefPicListTab))
......@@ -317,7 +317,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
static HEVCFrame *find_ref_idx(HEVCContext *s, int poc)
{
int i;
int LtMask = (1 << s->sps->log2_max_poc_lsb) - 1;
int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1;
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
HEVCFrame *ref = &s->DPB[i];
......@@ -356,16 +356,16 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
return NULL;
if (!s->avctx->hwaccel) {
if (!s->sps->pixel_shift) {
if (!s->ps.sps->pixel_shift) {
for (i = 0; frame->frame->buf[i]; i++)
memset(frame->frame->buf[i]->data, 1 << (s->sps->bit_depth - 1),
memset(frame->frame->buf[i]->data, 1 << (s->ps.sps->bit_depth - 1),
frame->frame->buf[i]->size);
} else {
for (i = 0; frame->frame->data[i]; i++)
for (y = 0; y < (s->sps->height >> s->sps->vshift[i]); y++)
for (x = 0; x < (s->sps->width >> s->sps->hshift[i]); x++) {
for (y = 0; y < (s->ps.sps->height >> s->ps.sps->vshift[i]); y++)
for (x = 0; x < (s->ps.sps->width >> s->ps.sps->hshift[i]); x++) {
AV_WN16(frame->frame->data[i] + y * frame->frame->linesize[i] + 2 * x,
1 << (s->sps->bit_depth - 1));
1 << (s->ps.sps->bit_depth - 1));
}
}
}
......@@ -464,7 +464,7 @@ fail:
int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb)
{
int max_poc_lsb = 1 << s->sps->log2_max_poc_lsb;
int max_poc_lsb = 1 << s->ps.sps->log2_max_poc_lsb;
int prev_poc_lsb = s->pocTid0 % max_poc_lsb;
int prev_poc_msb = s->pocTid0 - prev_poc_lsb;
int poc_msb;
......
......@@ -32,7 +32,7 @@ static av_always_inline void FUNC(intra_pred)(HEVCContext *s, int x0, int y0,
int log2_size, int c_idx)
{
#define PU(x) \
((x) >> s->sps->log2_min_pu_size)
((x) >> s->ps.sps->log2_min_pu_size)
#define MVF(x, y) \
(s->ref->tab_mvf[(x) + (y) * min_pu_width])
#define MVF_PU(x, y) \
......@@ -40,7 +40,7 @@ static av_always_inline void FUNC(intra_pred)(HEVCContext *s, int x0, int y0,
#define IS_INTRA(x, y) \
MVF_PU(x, y).is_intra
#define MIN_TB_ADDR_ZS(x, y) \
s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)]
s->ps.pps->min_tb_addr_zs[(y) * s->ps.sps->min_tb_width + (x)]
#define EXTEND(ptr, val, len) \
do { \
......@@ -70,21 +70,21 @@ do { \
ptr[i] = ptr[i - 1]
HEVCLocalContext *lc = &s->HEVClc;
int i;
int hshift = s->sps->hshift[c_idx];
int vshift = s->sps->vshift[c_idx];
int hshift = s->ps.sps->hshift[c_idx];
int vshift = s->ps.sps->vshift[c_idx];
int size = (1 << log2_size);
int size_in_luma = size << hshift;
int size_in_tbs = size_in_luma >> s->sps->log2_min_tb_size;
int size_in_tbs = size_in_luma >> s->ps.sps->log2_min_tb_size;
int x = x0 >> hshift;
int y = y0 >> vshift;
int x_tb = x0 >> s->sps->log2_min_tb_size;
int y_tb = y0 >> s->sps->log2_min_tb_size;
int x_tb = x0 >> s->ps.sps->log2_min_tb_size;
int y_tb = y0 >> s->ps.sps->log2_min_tb_size;
int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb);
ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(pixel);
pixel *src = (pixel*)s->frame->data[c_idx] + x + y * stride;
int min_pu_width = s->sps->min_pu_width;
int min_pu_width = s->ps.sps->min_pu_width;
enum IntraPredMode mode = c_idx ? lc->pu.intra_pred_mode_c :
lc->tu.cur_intra_pred_mode;
......@@ -105,21 +105,21 @@ do { \
int cand_up = lc->na.cand_up;
int cand_up_right = lc->na.cand_up_right && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb + size_in_tbs, y_tb - 1);
int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma, s->sps->height) -
int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma, s->ps.sps->height) -
(y0 + size_in_luma)) >> vshift;
int top_right_size = (FFMIN(x0 + 2 * size_in_luma, s->sps->width) -
int top_right_size = (FFMIN(x0 + 2 * size_in_luma, s->ps.sps->width) -
(x0 + size_in_luma)) >> hshift;
if (s->pps->constrained_intra_pred_flag == 1) {
if (s->ps.pps->constrained_intra_pred_flag == 1) {
int size_in_luma_pu = PU(size_in_luma);
int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
int on_pu_edge_x = !(x0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
int on_pu_edge_y = !(y0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
if (!size_in_luma_pu)
size_in_luma_pu++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_bottom_pu = PU(y0 + size_in_luma);
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_bottom_pu);
int max = FFMIN(size_in_luma_pu, s->ps.sps->min_pu_height - y_bottom_pu);
cand_bottom_left = 0;
for (i = 0; i < max; i++)
cand_bottom_left |= MVF(x_left_pu, y_bottom_pu + i).is_intra;
......@@ -127,7 +127,7 @@ do { \
if (cand_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_left_pu = PU(y0);
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_left_pu);
int max = FFMIN(size_in_luma_pu, s->ps.sps->min_pu_height - y_left_pu);
cand_left = 0;
for (i = 0; i < max; i++)
cand_left |= MVF(x_left_pu, y_left_pu + i).is_intra;
......@@ -140,7 +140,7 @@ do { \
if (cand_up == 1 && on_pu_edge_y) {
int x_top_pu = PU(x0);
int y_top_pu = PU(y0 - 1);
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_top_pu);
int max = FFMIN(size_in_luma_pu, s->ps.sps->min_pu_width - x_top_pu);
cand_up = 0;
for (i = 0; i < max; i++)
cand_up |= MVF(x_top_pu + i, y_top_pu).is_intra;
......@@ -148,7 +148,7 @@ do { \
if (cand_up_right == 1 && on_pu_edge_y) {
int y_top_pu = PU(y0 - 1);
int x_right_pu = PU(x0 + size_in_luma);
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_right_pu);
int max = FFMIN(size_in_luma_pu, s->ps.sps->min_pu_width - x_right_pu);
cand_up_right = 0;
for (i = 0; i < max; i++)
cand_up_right |= MVF(x_right_pu + i, y_top_pu).is_intra;
......@@ -179,20 +179,20 @@ do { \
size - top_right_size);
}
if (s->pps->constrained_intra_pred_flag == 1) {
if (s->ps.pps->constrained_intra_pred_flag == 1) {
if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) {
int size_max_x = x0 + ((2 * size) << hshift) < s->sps->width ?
2 * size : (s->sps->width - x0) >> hshift;
int size_max_y = y0 + ((2 * size) << vshift) < s->sps->height ?
2 * size : (s->sps->height - y0) >> vshift;
int size_max_x = x0 + ((2 * size) << hshift) < s->ps.sps->width ?
2 * size : (s->ps.sps->width - x0) >> hshift;
int size_max_y = y0 + ((2 * size) << vshift) < s->ps.sps->height ?
2 * size : (s->ps.sps->height - y0) >> vshift;
int j = size + (cand_bottom_left? bottom_left_size: 0) -1;
if (!cand_up_right) {
size_max_x = x0 + ((size) << hshift) < s->sps->width ?
size : (s->sps->width - x0) >> hshift;
size_max_x = x0 + ((size) << hshift) < s->ps.sps->width ?
size : (s->ps.sps->width - x0) >> hshift;
}
if (!cand_bottom_left) {
size_max_y = y0 + (( size) << vshift) < s->sps->height ?
size : (s->sps->height - y0) >> vshift;
size_max_y = y0 + (( size) << vshift) < s->ps.sps->height ?
size : (s->ps.sps->height - y0) >> vshift;
}
if (cand_bottom_left || cand_left || cand_up_left) {
while (j > -1 && !IS_INTRA(-1, j))
......@@ -284,7 +284,7 @@ do { \
FFABS((int)mode - 10));
if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) {
int threshold = 1 << (BIT_DEPTH - 5);
if (s->sps->sps_strong_intra_smoothing_enable_flag &&
if (s->ps.sps->sps_strong_intra_smoothing_enable_flag &&
log2_size == 5 &&
FFABS(top[-1] + top[63] - 2 * top[31]) < threshold &&
FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment