From b11acd57326db6c2cc1475dd0bea2a06fbc85aa2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 9 Jul 2015 14:22:43 +0200 Subject: 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. --- libavcodec/hevc.c | 475 +++++++++++++++++++++-------------------- libavcodec/hevc.h | 27 ++- libavcodec/hevc_cabac.c | 54 ++--- libavcodec/hevc_filter.c | 140 ++++++------ libavcodec/hevc_mvs.c | 96 ++++----- libavcodec/hevc_ps.c | 99 ++++----- libavcodec/hevc_refs.c | 34 +-- libavcodec/hevcpred_template.c | 54 ++--- 8 files changed, 495 insertions(+), 484 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c index 88198fca8c..9b1cd66495 100644 --- a/libavcodec/hevc.c +++ b/libavcodec/hevc.c @@ -252,7 +252,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb) uint8_t chroma_weight_l1_flag[16]; s->sh.luma_log2_weight_denom = av_clip(get_ue_golomb_long(gb), 0, 7); - if (s->sps->chroma_format_idc != 0) { + if (s->ps.sps->chroma_format_idc != 0) { int delta = get_se_golomb(gb); s->sh.chroma_log2_weight_denom = av_clip(s->sh.luma_log2_weight_denom + delta, 0, 7); } @@ -264,7 +264,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb) s->sh.luma_offset_l0[i] = 0; } } - if (s->sps->chroma_format_idc != 0) { // FIXME: invert "if" and "for" + if (s->ps.sps->chroma_format_idc != 0) { // FIXME: invert "if" and "for" for (i = 0; i < s->sh.nb_refs[L0]; i++) chroma_weight_l0_flag[i] = get_bits1(gb); } else { @@ -300,7 +300,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb) s->sh.luma_offset_l1[i] = 0; } } - if (s->sps->chroma_format_idc != 0) { + if (s->ps.sps->chroma_format_idc != 0) { for (i = 0; i < s->sh.nb_refs[L1]; i++) chroma_weight_l1_flag[i] = get_bits1(gb); } else { @@ -333,7 +333,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb) static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb) { - const HEVCSPS *sps = s->sps; + const HEVCSPS *sps = s->ps.sps; int max_poc_lsb = 1 << sps->log2_max_poc_lsb; int prev_delta_msb = 0; unsigned int nb_sps = 0, nb_sh; @@ -386,7 +386,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb) static void export_stream_params(AVCodecContext *avctx, const HEVCContext *s, const HEVCSPS *sps) { - const HEVCVPS *vps = (const HEVCVPS*)s->vps_list[sps->vps_id]->data; + const HEVCVPS *vps = (const HEVCVPS*)s->ps.vps_list[sps->vps_id]->data; unsigned int num = 0, den = 0; avctx->pix_fmt = sps->pix_fmt; @@ -471,14 +471,14 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) s->frame = s->tmp_frame; } - s->sps = sps; - s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data; + s->ps.sps = sps; + s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data; return 0; fail: pic_arrays_free(s); - s->sps = NULL; + s->ps.sps = NULL; return ret; } @@ -500,22 +500,22 @@ static int hls_slice_header(HEVCContext *s) sh->no_output_of_prior_pics_flag = get_bits1(gb); sh->pps_id = get_ue_golomb_long(gb); - if (sh->pps_id >= MAX_PPS_COUNT || !s->pps_list[sh->pps_id]) { + if (sh->pps_id >= MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); return AVERROR_INVALIDDATA; } if (!sh->first_slice_in_pic_flag && - s->pps != (HEVCPPS*)s->pps_list[sh->pps_id]->data) { + s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) { av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); return AVERROR_INVALIDDATA; } - s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]->data; + s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data; - if (s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]->data) { - s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]->data; + if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) { + s->ps.sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data; ff_hevc_clear_refs(s); - ret = set_sps(s, s->sps); + ret = set_sps(s, s->ps.sps); if (ret < 0) return ret; @@ -527,13 +527,13 @@ static int hls_slice_header(HEVCContext *s) if (!sh->first_slice_in_pic_flag) { int slice_address_length; - if (s->pps->dependent_slice_segments_enabled_flag) + if (s->ps.pps->dependent_slice_segments_enabled_flag) sh->dependent_slice_segment_flag = get_bits1(gb); - slice_address_length = av_ceil_log2(s->sps->ctb_width * - s->sps->ctb_height); + slice_address_length = av_ceil_log2(s->ps.sps->ctb_width * + s->ps.sps->ctb_height); sh->slice_segment_addr = slice_address_length ? get_bits(gb, slice_address_length) : 0; - if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) { + if (sh->slice_segment_addr >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) { av_log(s->avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", sh->slice_segment_addr); @@ -553,7 +553,7 @@ static int hls_slice_header(HEVCContext *s) if (!sh->dependent_slice_segment_flag) { s->slice_initialized = 0; - for (i = 0; i < s->pps->num_extra_slice_header_bits; i++) + for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] sh->slice_type = get_ue_golomb_long(gb); @@ -571,16 +571,16 @@ static int hls_slice_header(HEVCContext *s) // when flag is not present, picture is inferred to be output sh->pic_output_flag = 1; - if (s->pps->output_flag_present_flag) + if (s->ps.pps->output_flag_present_flag) sh->pic_output_flag = get_bits1(gb); - if (s->sps->separate_colour_plane_flag) + if (s->ps.sps->separate_colour_plane_flag) sh->colour_plane_id = get_bits(gb, 2); if (!IS_IDR(s)) { int poc; - sh->pic_order_cnt_lsb = get_bits(gb, s->sps->log2_max_poc_lsb); + sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb); poc = ff_hevc_compute_poc(s, sh->pic_order_cnt_lsb); if (!sh->first_slice_in_pic_flag && poc != s->poc) { av_log(s->avctx, AV_LOG_WARNING, @@ -594,7 +594,7 @@ static int hls_slice_header(HEVCContext *s) sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); if (!sh->short_term_ref_pic_set_sps_flag) { int pos = get_bits_left(gb); - ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->sps, 1); + ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1); if (ret < 0) return ret; @@ -603,14 +603,14 @@ static int hls_slice_header(HEVCContext *s) } else { int numbits, rps_idx; - if (!s->sps->nb_st_rps) { + if (!s->ps.sps->nb_st_rps) { av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); return AVERROR_INVALIDDATA; } - numbits = av_ceil_log2(s->sps->nb_st_rps); + numbits = av_ceil_log2(s->ps.sps->nb_st_rps); rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; - sh->short_term_rps = &s->sps->st_rps[rps_idx]; + sh->short_term_rps = &s->ps.sps->st_rps[rps_idx]; } ret = decode_lt_rps(s, &sh->long_term_rps, gb); @@ -620,7 +620,7 @@ static int hls_slice_header(HEVCContext *s) return AVERROR_INVALIDDATA; } - if (s->sps->sps_temporal_mvp_enabled_flag) + if (s->ps.sps->sps_temporal_mvp_enabled_flag) sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); else sh->slice_temporal_mvp_enabled_flag = 0; @@ -640,7 +640,7 @@ static int hls_slice_header(HEVCContext *s) s->nal_unit_type != NAL_RASL_R) s->pocTid0 = s->poc; - if (s->sps->sao_enabled) { + if (s->ps.sps->sao_enabled) { sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); sh->slice_sample_adaptive_offset_flag[1] = sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); @@ -654,9 +654,9 @@ static int hls_slice_header(HEVCContext *s) if (sh->slice_type == P_SLICE || sh->slice_type == B_SLICE) { int nb_refs; - sh->nb_refs[L0] = s->pps->num_ref_idx_l0_default_active; + sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active; if (sh->slice_type == B_SLICE) - sh->nb_refs[L1] = s->pps->num_ref_idx_l1_default_active; + sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active; if (get_bits1(gb)) { // num_ref_idx_active_override_flag sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1; @@ -677,7 +677,7 @@ static int hls_slice_header(HEVCContext *s) return AVERROR_INVALIDDATA; } - if (s->pps->lists_modification_present_flag && nb_refs > 1) { + if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) { sh->rpl_modification_flag[0] = get_bits1(gb); if (sh->rpl_modification_flag[0]) { for (i = 0; i < sh->nb_refs[L0]; i++) @@ -695,7 +695,7 @@ static int hls_slice_header(HEVCContext *s) if (sh->slice_type == B_SLICE) sh->mvd_l1_zero_flag = get_bits1(gb); - if (s->pps->cabac_init_present_flag) + if (s->ps.pps->cabac_init_present_flag) sh->cabac_init_flag = get_bits1(gb); else sh->cabac_init_flag = 0; @@ -717,8 +717,8 @@ static int hls_slice_header(HEVCContext *s) } } - if ((s->pps->weighted_pred_flag && sh->slice_type == P_SLICE) || - (s->pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) { + if ((s->ps.pps->weighted_pred_flag && sh->slice_type == P_SLICE) || + (s->ps.pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) { pred_weight_table(s, gb); } @@ -733,7 +733,7 @@ static int hls_slice_header(HEVCContext *s) sh->slice_qp_delta = get_se_golomb(gb); - if (s->pps->pic_slice_level_chroma_qp_offsets_present_flag) { + if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) { sh->slice_cb_qp_offset = get_se_golomb(gb); sh->slice_cr_qp_offset = get_se_golomb(gb); } else { @@ -741,10 +741,10 @@ static int hls_slice_header(HEVCContext *s) sh->slice_cr_qp_offset = 0; } - if (s->pps->deblocking_filter_control_present_flag) { + if (s->ps.pps->deblocking_filter_control_present_flag) { int deblocking_filter_override_flag = 0; - if (s->pps->deblocking_filter_override_enabled_flag) + if (s->ps.pps->deblocking_filter_override_enabled_flag) deblocking_filter_override_flag = get_bits1(gb); if (deblocking_filter_override_flag) { @@ -754,9 +754,9 @@ static int hls_slice_header(HEVCContext *s) sh->tc_offset = get_se_golomb(gb) * 2; } } else { - sh->disable_deblocking_filter_flag = s->pps->disable_dbf; - sh->beta_offset = s->pps->beta_offset; - sh->tc_offset = s->pps->tc_offset; + sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf; + sh->beta_offset = s->ps.pps->beta_offset; + sh->tc_offset = s->ps.pps->tc_offset; } } else { sh->disable_deblocking_filter_flag = 0; @@ -764,13 +764,13 @@ static int hls_slice_header(HEVCContext *s) sh->tc_offset = 0; } - if (s->pps->seq_loop_filter_across_slices_enabled_flag && + if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag && (sh->slice_sample_adaptive_offset_flag[0] || sh->slice_sample_adaptive_offset_flag[1] || !sh->disable_deblocking_filter_flag)) { sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); } else { - sh->slice_loop_filter_across_slices_enabled_flag = s->pps->seq_loop_filter_across_slices_enabled_flag; + sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag; } } else if (!s->slice_initialized) { av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); @@ -778,7 +778,7 @@ static int hls_slice_header(HEVCContext *s) } sh->num_entry_point_offsets = 0; - if (s->pps->tiles_enabled_flag || s->pps->entropy_coding_sync_enabled_flag) { + if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) { sh->num_entry_point_offsets = get_ue_golomb_long(gb); if (sh->num_entry_point_offsets > 0) { int offset_len = get_ue_golomb_long(gb) + 1; @@ -788,21 +788,21 @@ static int hls_slice_header(HEVCContext *s) } } - if (s->pps->slice_header_extension_present_flag) { + if (s->ps.pps->slice_header_extension_present_flag) { unsigned int length = get_ue_golomb_long(gb); for (i = 0; i < length; i++) skip_bits(gb, 8); // slice_header_extension_data_byte } // Inferred parameters - sh->slice_qp = 26 + s->pps->pic_init_qp_minus26 + sh->slice_qp_delta; + sh->slice_qp = 26 + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta; if (sh->slice_qp > 51 || - sh->slice_qp < -s->sps->qp_bd_offset) { + sh->slice_qp < -s->ps.sps->qp_bd_offset) { av_log(s->avctx, AV_LOG_ERROR, "The slice_qp %d is outside the valid range " "[%d, 51].\n", sh->slice_qp, - -s->sps->qp_bd_offset); + -s->ps.sps->qp_bd_offset); return AVERROR_INVALIDDATA; } @@ -815,16 +815,16 @@ static int hls_slice_header(HEVCContext *s) s->HEVClc.first_qp_group = !s->sh.dependent_slice_segment_flag; - if (!s->pps->cu_qp_delta_enabled_flag) - s->HEVClc.qp_y = FFUMOD(s->sh.slice_qp + 52 + 2 * s->sps->qp_bd_offset, - 52 + s->sps->qp_bd_offset) - s->sps->qp_bd_offset; + if (!s->ps.pps->cu_qp_delta_enabled_flag) + s->HEVClc.qp_y = FFUMOD(s->sh.slice_qp + 52 + 2 * s->ps.sps->qp_bd_offset, + 52 + s->ps.sps->qp_bd_offset) - s->ps.sps->qp_bd_offset; s->slice_initialized = 1; return 0; } -#define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)]) +#define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)]) #define SET_SAO(elem, value) \ do { \ @@ -843,7 +843,7 @@ static void hls_sao_param(HEVCContext *s, int rx, int ry) HEVCLocalContext *lc = &s->HEVClc; int sao_merge_left_flag = 0; int sao_merge_up_flag = 0; - int shift = s->sps->bit_depth - FFMIN(s->sps->bit_depth, 10); + int shift = s->ps.sps->bit_depth - FFMIN(s->ps.sps->bit_depth, 10); SAOParams *sao = &CTB(s->sao, rx, ry); int c_idx, i; @@ -933,10 +933,10 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off; ptrdiff_t stride = s->frame->linesize[c_idx]; - 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]; uint8_t *dst = &s->frame->data[c_idx][(y0 >> vshift) * stride + - ((x0 >> hshift) << s->sps->pixel_shift)]; + ((x0 >> hshift) << s->ps.sps->pixel_shift)]; DECLARE_ALIGNED(16, int16_t, coeffs[MAX_TB_SIZE * MAX_TB_SIZE]) = { 0 }; DECLARE_ALIGNED(8, uint8_t, significant_coeff_group_flag[8][8]) = { { 0 } }; @@ -966,16 +966,16 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, int qp_y = lc->qp_y; if (c_idx == 0) { - qp = qp_y + s->sps->qp_bd_offset; + qp = qp_y + s->ps.sps->qp_bd_offset; } else { int qp_i, offset; if (c_idx == 1) - offset = s->pps->cb_qp_offset + s->sh.slice_cb_qp_offset; + offset = s->ps.pps->cb_qp_offset + s->sh.slice_cb_qp_offset; else - offset = s->pps->cr_qp_offset + s->sh.slice_cr_qp_offset; + offset = s->ps.pps->cr_qp_offset + s->sh.slice_cr_qp_offset; - qp_i = av_clip(qp_y + offset, -s->sps->qp_bd_offset, 57); + qp_i = av_clip(qp_y + offset, -s->ps.sps->qp_bd_offset, 57); if (qp_i < 30) qp = qp_i; else if (qp_i > 43) @@ -983,18 +983,18 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, else qp = qp_c[qp_i - 30]; - qp += s->sps->qp_bd_offset; + qp += s->ps.sps->qp_bd_offset; } - shift = s->sps->bit_depth + log2_trafo_size - 5; + shift = s->ps.sps->bit_depth + log2_trafo_size - 5; add = 1 << (shift - 1); scale = level_scale[rem6[qp]] << (div6[qp]); scale_m = 16; // default when no custom scaling lists. dc_scale = 16; - if (s->sps->scaling_list_enable_flag) { - const ScalingList *sl = s->pps->scaling_list_data_present_flag ? - &s->pps->scaling_list : &s->sps->scaling_list; + if (s->ps.sps->scaling_list_enable_flag) { + const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ? + &s->ps.pps->scaling_list : &s->ps.sps->scaling_list; int matrix_id = lc->cu.pred_mode != MODE_INTRA; if (log2_trafo_size != 5) @@ -1006,7 +1006,7 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, } } - if (s->pps->transform_skip_enabled_flag && + if (s->ps.pps->transform_skip_enabled_flag && !lc->cu.cu_transquant_bypass_flag && log2_trafo_size == 2) { transform_skip_flag = ff_hevc_transform_skip_flag_decode(s, c_idx); @@ -1190,7 +1190,7 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, if (first_greater1_coeff_idx != -1) { coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += ff_hevc_coeff_abs_level_greater2_flag_decode(s, c_idx, ctx_set); } - if (!s->pps->sign_data_hiding_flag || !sign_hidden) { + if (!s->ps.pps->sign_data_hiding_flag || !sign_hidden) { coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag); } else { coeff_sign_flag = ff_hevc_coeff_sign_flag(s, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1)); @@ -1208,7 +1208,7 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, if ((trans_coeff_level) > (3 * (1 << c_rice_param))) c_rice_param = FFMIN(c_rice_param + 1, 4); } - if (s->pps->sign_data_hiding_flag && sign_hidden) { + if (s->ps.pps->sign_data_hiding_flag && sign_hidden) { sum_abs += trans_coeff_level; if (n == first_nz_pos_in_cg && ((sum_abs & 1) == 1)) trans_coeff_level = -trans_coeff_level; @@ -1217,7 +1217,7 @@ static void hls_residual_coding(HEVCContext *s, int x0, int y0, trans_coeff_level = -trans_coeff_level; coeff_sign_flag <<= 1; if (!lc->cu.cu_transquant_bypass_flag) { - if (s->sps->scaling_list_enable_flag) { + if (s->ps.sps->scaling_list_enable_flag) { if (y_c || x_c || log2_trafo_size < 4) { int pos; switch (log2_trafo_size) { @@ -1271,12 +1271,12 @@ static int hls_transform_unit(HEVCContext *s, int x0, int y0, s->hpc.intra_pred[log2_trafo_size - 2](s, x0, y0, 0); if (log2_trafo_size > 2) { - trafo_size = trafo_size << (s->sps->hshift[1] - 1); + trafo_size = trafo_size << (s->ps.sps->hshift[1] - 1); ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size); s->hpc.intra_pred[log2_trafo_size - 3](s, x0, y0, 1); s->hpc.intra_pred[log2_trafo_size - 3](s, x0, y0, 2); } else if (blk_idx == 3) { - trafo_size = trafo_size << s->sps->hshift[1]; + trafo_size = trafo_size << s->ps.sps->hshift[1]; ff_hevc_set_neighbour_available(s, xBase, yBase, trafo_size, trafo_size); s->hpc.intra_pred[log2_trafo_size - 2](s, xBase, yBase, 1); @@ -1288,21 +1288,21 @@ static int hls_transform_unit(HEVCContext *s, int x0, int y0, int scan_idx = SCAN_DIAG; int scan_idx_c = SCAN_DIAG; - if (s->pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { + if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) { lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(s); if (lc->tu.cu_qp_delta != 0) if (ff_hevc_cu_qp_delta_sign_flag(s) == 1) lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta; lc->tu.is_cu_qp_delta_coded = 1; - if (lc->tu.cu_qp_delta < -(26 + s->sps->qp_bd_offset / 2) || - lc->tu.cu_qp_delta > (25 + s->sps->qp_bd_offset / 2)) { + if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) || + lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) { av_log(s->avctx, AV_LOG_ERROR, "The cu_qp_delta %d is outside the valid range " "[%d, %d].\n", lc->tu.cu_qp_delta, - -(26 + s->sps->qp_bd_offset / 2), - (25 + s->sps->qp_bd_offset / 2)); + -(26 + s->ps.sps->qp_bd_offset / 2), + (25 + s->ps.sps->qp_bd_offset / 2)); return AVERROR_INVALIDDATA; } @@ -1347,11 +1347,11 @@ static int hls_transform_unit(HEVCContext *s, int x0, int y0, static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size) { int cb_size = 1 << log2_cb_size; - int log2_min_pu_size = s->sps->log2_min_pu_size; + int log2_min_pu_size = s->ps.sps->log2_min_pu_size; - int min_pu_width = s->sps->min_pu_width; - int x_end = FFMIN(x0 + cb_size, s->sps->width); - int y_end = FFMIN(y0 + cb_size, s->sps->height); + int min_pu_width = s->ps.sps->min_pu_width; + int x_end = FFMIN(x0 + cb_size, s->ps.sps->width); + int y_end = FFMIN(y0 + cb_size, s->ps.sps->height); int i, j; for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++) @@ -1376,18 +1376,18 @@ static int hls_transform_tree(HEVCContext *s, int x0, int y0, lc->tu.cur_intra_pred_mode = lc->pu.intra_pred_mode[0]; } - if (log2_trafo_size <= s->sps->log2_max_trafo_size && - log2_trafo_size > s->sps->log2_min_tb_size && + if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size && + log2_trafo_size > s->ps.sps->log2_min_tb_size && trafo_depth < lc->cu.max_trafo_depth && !(lc->cu.intra_split_flag && trafo_depth == 0)) { split_transform_flag = ff_hevc_split_transform_flag_decode(s, log2_trafo_size); } else { - int inter_split = s->sps->max_transform_hierarchy_depth_inter == 0 && + int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 && lc->cu.pred_mode == MODE_INTER && lc->cu.part_mode != PART_2Nx2N && trafo_depth == 0; - split_transform_flag = log2_trafo_size > s->sps->log2_max_trafo_size || + split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size || (lc->cu.intra_split_flag && trafo_depth == 0) || inter_split; } @@ -1422,9 +1422,9 @@ do { #undef SUBDIVIDE } else { - int min_tu_size = 1 << s->sps->log2_min_tb_size; - int log2_min_tu_size = s->sps->log2_min_tb_size; - int min_tu_width = s->sps->min_tb_width; + int min_tu_size = 1 << s->ps.sps->log2_min_tb_size; + int log2_min_tu_size = s->ps.sps->log2_min_tb_size; + int min_tu_width = s->ps.sps->min_tb_width; int cbf_luma = 1; if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 || @@ -1448,7 +1448,7 @@ do { } if (!s->sh.disable_deblocking_filter_flag) { ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size); - if (s->pps->transquant_bypass_enable_flag && + if (s->ps.pps->transquant_bypass_enable_flag && lc->cu.cu_transquant_bypass_flag) set_deblocking_bypass(s, x0, y0, log2_trafo_size); } @@ -1463,13 +1463,13 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) GetBitContext gb; int cb_size = 1 << log2_cb_size; int stride0 = s->frame->linesize[0]; - uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->sps->pixel_shift)]; + uint8_t *dst0 = &s->frame->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)]; int stride1 = s->frame->linesize[1]; - uint8_t *dst1 = &s->frame->data[1][(y0 >> s->sps->vshift[1]) * stride1 + ((x0 >> s->sps->hshift[1]) << s->sps->pixel_shift)]; + uint8_t *dst1 = &s->frame->data[1][(y0 >> s->ps.sps->vshift[1]) * stride1 + ((x0 >> s->ps.sps->hshift[1]) << s->ps.sps->pixel_shift)]; int stride2 = s->frame->linesize[2]; - uint8_t *dst2 = &s->frame->data[2][(y0 >> s->sps->vshift[2]) * stride2 + ((x0 >> s->sps->hshift[2]) << s->sps->pixel_shift)]; + uint8_t *dst2 = &s->frame->data[2][(y0 >> s->ps.sps->vshift[2]) * stride2 + ((x0 >> s->ps.sps->hshift[2]) << s->ps.sps->pixel_shift)]; - int length = cb_size * cb_size * s->sps->pcm.bit_depth + ((cb_size * cb_size) >> 1) * s->sps->pcm.bit_depth_chroma; + int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth + ((cb_size * cb_size) >> 1) * s->ps.sps->pcm.bit_depth_chroma; const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); int ret; @@ -1480,9 +1480,9 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) if (ret < 0) return ret; - s->hevcdsp.put_pcm(dst0, stride0, cb_size, &gb, s->sps->pcm.bit_depth); - s->hevcdsp.put_pcm(dst1, stride1, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma); - s->hevcdsp.put_pcm(dst2, stride2, cb_size / 2, &gb, s->sps->pcm.bit_depth_chroma); + s->hevcdsp.put_pcm(dst0, stride0, cb_size, &gb, s->ps.sps->pcm.bit_depth); + s->hevcdsp.put_pcm(dst1, stride1, cb_size / 2, &gb, s->ps.sps->pcm.bit_depth_chroma); + s->hevcdsp.put_pcm(dst2, stride2, cb_size / 2, &gb, s->ps.sps->pcm.bit_depth_chroma); return 0; } @@ -1530,8 +1530,8 @@ static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride, HEVCLocalContext *lc = &s->HEVClc; uint8_t *src = ref->data[0]; ptrdiff_t srcstride = ref->linesize[0]; - int pic_width = s->sps->width; - int pic_height = s->sps->height; + int pic_width = s->ps.sps->width; + int pic_height = s->ps.sps->height; int mx = mv->x & 3; int my = mv->y & 3; @@ -1540,15 +1540,15 @@ static void luma_mc(HEVCContext *s, int16_t *dst, ptrdiff_t dststride, x_off += mv->x >> 2; y_off += mv->y >> 2; - src += y_off * srcstride + (x_off << s->sps->pixel_shift); + src += y_off * srcstride + (x_off << s->ps.sps->pixel_shift); if (x_off < extra_left || y_off < extra_top || x_off >= pic_width - block_w - ff_hevc_qpel_extra_after[mx] || y_off >= pic_height - block_h - ff_hevc_qpel_extra_after[my]) { - const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->sps->pixel_shift; - int offset = extra_top * srcstride + (extra_left << s->sps->pixel_shift); + const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; + int offset = extra_top * srcstride + (extra_left << s->ps.sps->pixel_shift); int buf_offset = extra_top * - edge_emu_stride + (extra_left << s->sps->pixel_shift); + edge_emu_stride + (extra_left << s->ps.sps->pixel_shift); s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset, edge_emu_stride, srcstride, @@ -1586,27 +1586,27 @@ static void chroma_mc(HEVCContext *s, int16_t *dst1, int16_t *dst2, uint8_t *src2 = ref->data[2]; ptrdiff_t src1stride = ref->linesize[1]; ptrdiff_t src2stride = ref->linesize[2]; - int pic_width = s->sps->width >> 1; - int pic_height = s->sps->height >> 1; + int pic_width = s->ps.sps->width >> 1; + int pic_height = s->ps.sps->height >> 1; int mx = mv->x & 7; int my = mv->y & 7; x_off += mv->x >> 3; y_off += mv->y >> 3; - src1 += y_off * src1stride + (x_off << s->sps->pixel_shift); - src2 += y_off * src2stride + (x_off << s->sps->pixel_shift); + src1 += y_off * src1stride + (x_off << s->ps.sps->pixel_shift); + src2 += y_off * src2stride + (x_off << s->ps.sps->pixel_shift); if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER || x_off >= pic_width - block_w - EPEL_EXTRA_AFTER || y_off >= pic_height - block_h - EPEL_EXTRA_AFTER) { - const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->sps->pixel_shift; - int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->sps->pixel_shift)); + const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift; + int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift)); int buf_offset1 = EPEL_EXTRA_BEFORE * - (edge_emu_stride + (1 << s->sps->pixel_shift)); - int offset2 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->sps->pixel_shift)); + (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); + int offset2 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift)); int buf_offset2 = EPEL_EXTRA_BEFORE * - (edge_emu_stride + (1 << s->sps->pixel_shift)); + (edge_emu_stride + (1 << s->ps.sps->pixel_shift)); s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1, edge_emu_stride, src1stride, @@ -1698,13 +1698,13 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int log2_cb_size, int partIdx) { #define POS(c_idx, x, y) \ - &s->frame->data[c_idx][((y) >> s->sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \ - (((x) >> s->sps->hshift[c_idx]) << s->sps->pixel_shift)] + &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \ + (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)] HEVCLocalContext *lc = &s->HEVClc; int merge_idx = 0; struct MvField current_mv = {{{ 0 }}}; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->ps.sps->min_pu_width; MvField *tab_mvf = s->ref->tab_mvf; RefPicList *refPicList = s->ref->refPicList; @@ -1715,8 +1715,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, uint8_t *dst0 = POS(0, x0, y0); uint8_t *dst1 = POS(1, x0, y0); uint8_t *dst2 = POS(2, x0, y0); - int log2_min_cb_size = s->sps->log2_min_cb_size; - int min_cb_width = s->sps->min_cb_width; + int log2_min_cb_size = s->ps.sps->log2_min_cb_size; + int min_cb_width = s->ps.sps->min_cb_width; int x_cb = x0 >> log2_min_cb_size; int y_cb = y0 >> log2_min_cb_size; int x_pu, y_pu; @@ -1740,11 +1740,11 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, partIdx, merge_idx, ¤t_mv); } - x_pu = x0 >> s->sps->log2_min_pu_size; - y_pu = y0 >> s->sps->log2_min_pu_size; + x_pu = x0 >> s->ps.sps->log2_min_pu_size; + y_pu = y0 >> s->ps.sps->log2_min_pu_size; - for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++) - for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++) + for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++) + for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; if (current_mv.pred_flag[0]) { @@ -1767,8 +1767,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, luma_mc(s, tmp, tmpstride, ref0->frame, ¤t_mv.mv[0], x0, y0, nPbW, nPbH); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l0[current_mv.ref_idx[0]], s->sh.luma_offset_l0[current_mv.ref_idx[0]], @@ -1780,8 +1780,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, chroma_mc(s, tmp, tmp2, tmpstride, ref0->frame, ¤t_mv.mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0], @@ -1803,8 +1803,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, luma_mc(s, tmp, tmpstride, ref1->frame, ¤t_mv.mv[1], x0, y0, nPbW, nPbH); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l1[current_mv.ref_idx[1]], s->sh.luma_offset_l1[current_mv.ref_idx[1]], @@ -1817,8 +1817,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, chroma_mc(s, tmp, tmp2, tmpstride, ref1->frame, ¤t_mv.mv[1], x0/2, y0/2, nPbW/2, nPbH/2); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0], @@ -1842,8 +1842,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, luma_mc(s, tmp2, tmpstride, ref1->frame, ¤t_mv.mv[1], x0, y0, nPbW, nPbH); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred_avg(s->sh.luma_log2_weight_denom, s->sh.luma_weight_l0[current_mv.ref_idx[0]], s->sh.luma_weight_l1[current_mv.ref_idx[1]], @@ -1861,8 +1861,8 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, chroma_mc(s, tmp3, tmp4, tmpstride, ref1->frame, ¤t_mv.mv[1], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2); - if ((s->sh.slice_type == P_SLICE && s->pps->weighted_pred_flag) || - (s->sh.slice_type == B_SLICE && s->pps->weighted_bipred_flag)) { + if ((s->sh.slice_type == P_SLICE && s->ps.pps->weighted_pred_flag) || + (s->sh.slice_type == B_SLICE && s->ps.pps->weighted_bipred_flag)) { s->hevcdsp.weighted_pred_avg(s->sh.chroma_log2_weight_denom, s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], @@ -1891,19 +1891,19 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size, int prev_intra_luma_pred_flag) { HEVCLocalContext *lc = &s->HEVClc; - int x_pu = x0 >> s->sps->log2_min_pu_size; - int y_pu = y0 >> s->sps->log2_min_pu_size; - int min_pu_width = s->sps->min_pu_width; - int size_in_pus = pu_size >> s->sps->log2_min_pu_size; - int x0b = x0 & ((1 << s->sps->log2_ctb_size) - 1); - int y0b = y0 & ((1 << s->sps->log2_ctb_size) - 1); + int x_pu = x0 >> s->ps.sps->log2_min_pu_size; + int y_pu = y0 >> s->ps.sps->log2_min_pu_size; + int min_pu_width = s->ps.sps->min_pu_width; + int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size; + int x0b = x0 & ((1 << s->ps.sps->log2_ctb_size) - 1); + int y0b = y0 & ((1 << s->ps.sps->log2_ctb_size) - 1); int cand_up = (lc->ctb_up_flag || y0b) ? s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC; int cand_left = (lc->ctb_left_flag || x0b) ? s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC; - int y_ctb = (y0 >> (s->sps->log2_ctb_size)) << (s->sps->log2_ctb_size); + int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size); MvField *tab_mvf = s->ref->tab_mvf; int intra_pred_mode; @@ -1978,13 +1978,13 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size, static av_always_inline void set_ct_depth(HEVCContext *s, int x0, int y0, int log2_cb_size, int ct_depth) { - int length = (1 << log2_cb_size) >> s->sps->log2_min_cb_size; - int x_cb = x0 >> s->sps->log2_min_cb_size; - int y_cb = y0 >> s->sps->log2_min_cb_size; + int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size; + int x_cb = x0 >> s->ps.sps->log2_min_cb_size; + int y_cb = y0 >> s->ps.sps->log2_min_cb_size; int y; for (y = 0; y < length; y++) - memset(&s->tab_ct_depth[(y_cb + y) * s->sps->min_cb_width + x_cb], + memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb], ct_depth, length); } @@ -2034,11 +2034,11 @@ static void intra_prediction_unit_default_value(HEVCContext *s, { HEVCLocalContext *lc = &s->HEVClc; int pb_size = 1 << log2_cb_size; - int size_in_pus = pb_size >> s->sps->log2_min_pu_size; - int min_pu_width = s->sps->min_pu_width; + int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size; + int min_pu_width = s->ps.sps->min_pu_width; MvField *tab_mvf = s->ref->tab_mvf; - int x_pu = x0 >> s->sps->log2_min_pu_size; - int y_pu = y0 >> s->sps->log2_min_pu_size; + int x_pu = x0 >> s->ps.sps->log2_min_pu_size; + int y_pu = y0 >> s->ps.sps->log2_min_pu_size; int j, k; if (size_in_pus == 0) @@ -2054,9 +2054,9 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) { int cb_size = 1 << log2_cb_size; HEVCLocalContext *lc = &s->HEVClc; - int log2_min_cb_size = s->sps->log2_min_cb_size; + int log2_min_cb_size = s->ps.sps->log2_min_cb_size; int length = cb_size >> log2_min_cb_size; - int min_cb_width = s->sps->min_cb_width; + int min_cb_width = s->ps.sps->min_cb_width; int x_cb = x0 >> log2_min_cb_size; int y_cb = y0 >> log2_min_cb_size; int x, y, ret; @@ -2070,7 +2070,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0; for (x = 0; x < 4; x++) lc->pu.intra_pred_mode[x] = 1; - if (s->pps->transquant_bypass_enable_flag) { + if (s->ps.pps->transquant_bypass_enable_flag) { lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(s); if (lc->cu.cu_transquant_bypass_flag) set_deblocking_bypass(s, x0, y0, log2_cb_size); @@ -2100,22 +2100,22 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) if (s->sh.slice_type != I_SLICE) lc->cu.pred_mode = ff_hevc_pred_mode_decode(s); if (lc->cu.pred_mode != MODE_INTRA || - log2_cb_size == s->sps->log2_min_cb_size) { + log2_cb_size == s->ps.sps->log2_min_cb_size) { lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_cb_size); lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN && lc->cu.pred_mode == MODE_INTRA; } if (lc->cu.pred_mode == MODE_INTRA) { - if (lc->cu.part_mode == PART_2Nx2N && s->sps->pcm_enabled_flag && - log2_cb_size >= s->sps->pcm.log2_min_pcm_cb_size && - log2_cb_size <= s->sps->pcm.log2_max_pcm_cb_size) { + if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled_flag && + log2_cb_size >= s->ps.sps->pcm.log2_min_pcm_cb_size && + log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) { pcm_flag = ff_hevc_pcm_flag_decode(s); } if (pcm_flag) { intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); ret = hls_pcm_sample(s, x0, y0, log2_cb_size); - if (s->sps->pcm.loop_filter_disable_flag) + if (s->ps.sps->pcm.loop_filter_disable_flag) set_deblocking_bypass(s, x0, y0, log2_cb_size); if (ret < 0) @@ -2171,8 +2171,8 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) } if (rqt_root_cbf) { lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? - s->sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : - s->sps->max_transform_hierarchy_depth_inter; + s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : + s->ps.sps->max_transform_hierarchy_depth_inter; ret = hls_transform_tree(s, x0, y0, x0, y0, x0, y0, log2_cb_size, log2_cb_size, 0, 0, 0, 0); @@ -2185,7 +2185,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) } } - if (s->pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) + if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) ff_hevc_set_qPy(s, x0, y0, x0, y0, log2_cb_size); x = y_cb * min_cb_width + x_cb; @@ -2207,15 +2207,15 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int split_cu; lc->ct.depth = cb_depth; - if (x0 + cb_size <= s->sps->width && - y0 + cb_size <= s->sps->height && - log2_cb_size > s->sps->log2_min_cb_size) { + if (x0 + cb_size <= s->ps.sps->width && + y0 + cb_size <= s->ps.sps->height && + log2_cb_size > s->ps.sps->log2_min_cb_size) { split_cu = ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0); } else { - split_cu = (log2_cb_size > s->sps->log2_min_cb_size); + split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size); } - if (s->pps->cu_qp_delta_enabled_flag && - log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) { + if (s->ps.pps->cu_qp_delta_enabled_flag && + log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) { lc->tu.is_cu_qp_delta_coded = 0; lc->tu.cu_qp_delta = 0; } @@ -2230,7 +2230,7 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, #define SUBDIVIDE(x, y) \ do { \ - if (x < s->sps->width && y < s->sps->height) { \ + if (x < s->ps.sps->width && y < s->ps.sps->height) { \ int ret = hls_coding_quadtree(s, x, y, log2_cb_size, cb_depth);\ if (ret < 0) \ return ret; \ @@ -2254,77 +2254,77 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_addr_ts) { HEVCLocalContext *lc = &s->HEVClc; - int ctb_size = 1 << s->sps->log2_ctb_size; - int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts]; + int ctb_size = 1 << s->ps.sps->log2_ctb_size; + int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; - if (s->pps->entropy_coding_sync_enabled_flag) { + if (s->ps.pps->entropy_coding_sync_enabled_flag) { if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) lc->first_qp_group = 1; - lc->end_of_tiles_x = s->sps->width; - } else if (s->pps->tiles_enabled_flag) { - if (ctb_addr_ts && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[ctb_addr_ts - 1]) { - int idxX = s->pps->col_idxX[x_ctb >> s->sps->log2_ctb_size]; + lc->end_of_tiles_x = s->ps.sps->width; + } else if (s->ps.pps->tiles_enabled_flag) { + if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) { + int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size]; lc->start_of_tiles_x = x_ctb; - lc->end_of_tiles_x = x_ctb + (s->pps->column_width[idxX] << s->sps->log2_ctb_size); + lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size); lc->first_qp_group = 1; } } else { - lc->end_of_tiles_x = s->sps->width; + lc->end_of_tiles_x = s->ps.sps->width; } - lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->sps->height); + lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height); lc->boundary_flags = 0; - if (s->pps->tiles_enabled_flag) { - if (x_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) + if (s->ps.pps->tiles_enabled_flag) { + if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) lc->boundary_flags |= BOUNDARY_LEFT_TILE; if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1]) lc->boundary_flags |= BOUNDARY_LEFT_SLICE; - if (y_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]]) + if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]]) lc->boundary_flags |= BOUNDARY_UPPER_TILE; - if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->sps->ctb_width]) + if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width]) lc->boundary_flags |= BOUNDARY_UPPER_SLICE; } else { if (!ctb_addr_in_slice > 0) lc->boundary_flags |= BOUNDARY_LEFT_SLICE; - if (ctb_addr_in_slice < s->sps->ctb_width) + if (ctb_addr_in_slice < s->ps.sps->ctb_width) lc->boundary_flags |= BOUNDARY_UPPER_SLICE; } lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); - lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); - lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->sps->ctb_width]])); - lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->sps->ctb_width]])); + lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); + lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]])); + lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]])); } static int hls_slice_data(HEVCContext *s) { - int ctb_size = 1 << s->sps->log2_ctb_size; + int ctb_size = 1 << s->ps.sps->log2_ctb_size; int more_data = 1; int x_ctb = 0; int y_ctb = 0; - int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; + int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]; int ret; - while (more_data && ctb_addr_ts < s->sps->ctb_size) { - int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts]; + while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) { + int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; - x_ctb = (ctb_addr_rs % ((s->sps->width + ctb_size - 1) >> s->sps->log2_ctb_size)) << s->sps->log2_ctb_size; - y_ctb = (ctb_addr_rs / ((s->sps->width + ctb_size - 1) >> s->sps->log2_ctb_size)) << s->sps->log2_ctb_size; + x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; + y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size; hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts); ff_hevc_cabac_init(s, ctb_addr_ts); - hls_sao_param(s, x_ctb >> s->sps->log2_ctb_size, y_ctb >> s->sps->log2_ctb_size); + hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size); s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; - ret = hls_coding_quadtree(s, x_ctb, y_ctb, s->sps->log2_ctb_size, 0); + ret = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0); if (ret < 0) return ret; more_data = !ff_hevc_end_of_slice_flag_decode(s); @@ -2334,8 +2334,8 @@ static int hls_slice_data(HEVCContext *s) ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size); } - if (x_ctb + ctb_size >= s->sps->width && - y_ctb + ctb_size >= s->sps->height) + if (x_ctb + ctb_size >= s->ps.sps->width && + y_ctb + ctb_size >= s->ps.sps->height) ff_hevc_hls_filter(s, x_ctb, y_ctb); return ctb_addr_ts; @@ -2369,20 +2369,20 @@ static int hls_nal_unit(HEVCContext *s) static void restore_tqb_pixels(HEVCContext *s) { - int min_pu_size = 1 << s->sps->log2_min_pu_size; + int min_pu_size = 1 << s->ps.sps->log2_min_pu_size; int x, y, c_idx; for (c_idx = 0; c_idx < 3; c_idx++) { ptrdiff_t stride = s->frame->linesize[c_idx]; - int hshift = s->sps->hshift[c_idx]; - int vshift = s->sps->vshift[c_idx]; - for (y = 0; y < s->sps->min_pu_height; y++) { - for (x = 0; x < s->sps->min_pu_width; x++) { - if (s->is_pcm[y * s->sps->min_pu_width + x]) { + int hshift = s->ps.sps->hshift[c_idx]; + int vshift = s->ps.sps->vshift[c_idx]; + for (y = 0; y < s->ps.sps->min_pu_height; y++) { + for (x = 0; x < s->ps.sps->min_pu_width; x++) { + if (s->is_pcm[y * s->ps.sps->min_pu_width + x]) { int n; int len = min_pu_size >> hshift; - uint8_t *src = &s->frame->data[c_idx][((y << s->sps->log2_min_pu_size) >> vshift) * stride + (((x << s->sps->log2_min_pu_size) >> hshift) << s->sps->pixel_shift)]; - uint8_t *dst = &s->sao_frame->data[c_idx][((y << s->sps->log2_min_pu_size) >> vshift) * stride + (((x << s->sps->log2_min_pu_size) >> hshift) << s->sps->pixel_shift)]; + uint8_t *src = &s->frame->data[c_idx][((y << s->ps.sps->log2_min_pu_size) >> vshift) * stride + (((x << s->ps.sps->log2_min_pu_size) >> hshift) << s->ps.sps->pixel_shift)]; + uint8_t *dst = &s->sao_frame->data[c_idx][((y << s->ps.sps->log2_min_pu_size) >> vshift) * stride + (((x << s->ps.sps->log2_min_pu_size) >> hshift) << s->ps.sps->pixel_shift)]; for (n = 0; n < (min_pu_size >> vshift); n++) { memcpy(dst, src, len); src += stride; @@ -2450,17 +2450,17 @@ static int hevc_frame_start(HEVCContext *s) memset(s->horizontal_bs, 0, 2 * s->bs_width * (s->bs_height + 1)); memset(s->vertical_bs, 0, 2 * s->bs_width * (s->bs_height + 1)); - memset(s->cbf_luma, 0, s->sps->min_tb_width * s->sps->min_tb_height); - memset(s->is_pcm, 0, s->sps->min_pu_width * s->sps->min_pu_height); + memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height); + memset(s->is_pcm, 0, s->ps.sps->min_pu_width * s->ps.sps->min_pu_height); lc->start_of_tiles_x = 0; s->is_decoded = 0; s->first_nal_type = s->nal_unit_type; - if (s->pps->tiles_enabled_flag) - lc->end_of_tiles_x = s->pps->column_width[0] << s->sps->log2_ctb_size; + if (s->ps.pps->tiles_enabled_flag) + lc->end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size; - ret = ff_hevc_set_new_ref(s, s->sps->sao_enabled ? &s->sao_frame : &s->frame, + ret = ff_hevc_set_new_ref(s, s->ps.sps->sao_enabled ? &s->sao_frame : &s->frame, s->poc); if (ret < 0) goto fail; @@ -2513,17 +2513,18 @@ static int decode_nal_unit(HEVCContext *s, const HEVCNAL *nal) switch (s->nal_unit_type) { case NAL_VPS: - ret = ff_hevc_decode_nal_vps(s); + ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps); if (ret < 0) goto fail; break; case NAL_SPS: - ret = ff_hevc_decode_nal_sps(s); + ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps, + s->apply_defdispwin); if (ret < 0) goto fail; break; case NAL_PPS: - ret = ff_hevc_decode_nal_pps(s); + ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps); if (ret < 0) goto fail; break; @@ -2609,11 +2610,11 @@ static int decode_nal_unit(HEVCContext *s, const HEVCNAL *nal) goto fail; } else { ctb_addr_ts = hls_slice_data(s); - if (ctb_addr_ts >= (s->sps->ctb_width * s->sps->ctb_height)) { + if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) { s->is_decoded = 1; - if ((s->pps->transquant_bypass_enable_flag || - (s->sps->pcm.loop_filter_disable_flag && s->sps->pcm_enabled_flag)) && - s->sps->sao_enabled) + if ((s->ps.pps->transquant_bypass_enable_flag || + (s->ps.sps->pcm.loop_filter_disable_flag && s->ps.sps->pcm_enabled_flag)) && + s->ps.sps->sao_enabled) restore_tqb_pixels(s); } @@ -2914,12 +2915,12 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) av_frame_free(&s->DPB[i].frame); } - for (i = 0; i < FF_ARRAY_ELEMS(s->vps_list); i++) - av_buffer_unref(&s->vps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) - av_buffer_unref(&s->sps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) - av_buffer_unref(&s->pps_list[i]); + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) + av_buffer_unref(&s->ps.vps_list[i]); + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) + av_buffer_unref(&s->ps.sps_list[i]); + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) + av_buffer_unref(&s->ps.pps_list[i]); for (i = 0; i < s->nals_allocated; i++) av_freep(&s->nals[i].rbsp_buffer); @@ -2990,35 +2991,35 @@ static int hevc_update_thread_context(AVCodecContext *dst, } } - for (i = 0; i < FF_ARRAY_ELEMS(s->vps_list); i++) { - av_buffer_unref(&s->vps_list[i]); - if (s0->vps_list[i]) { - s->vps_list[i] = av_buffer_ref(s0->vps_list[i]); - if (!s->vps_list[i]) + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) { + av_buffer_unref(&s->ps.vps_list[i]); + if (s0->ps.vps_list[i]) { + s->ps.vps_list[i] = av_buffer_ref(s0->ps.vps_list[i]); + if (!s->ps.vps_list[i]) return AVERROR(ENOMEM); } } - for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) { - av_buffer_unref(&s->sps_list[i]); - if (s0->sps_list[i]) { - s->sps_list[i] = av_buffer_ref(s0->sps_list[i]); - if (!s->sps_list[i]) + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { + av_buffer_unref(&s->ps.sps_list[i]); + if (s0->ps.sps_list[i]) { + s->ps.sps_list[i] = av_buffer_ref(s0->ps.sps_list[i]); + if (!s->ps.sps_list[i]) return AVERROR(ENOMEM); } } - for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) { - av_buffer_unref(&s->pps_list[i]); - if (s0->pps_list[i]) { - s->pps_list[i] = av_buffer_ref(s0->pps_list[i]); - if (!s->pps_list[i]) + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) { + av_buffer_unref(&s->ps.pps_list[i]); + if (s0->ps.pps_list[i]) { + s->ps.pps_list[i] = av_buffer_ref(s0->ps.pps_list[i]); + if (!s->ps.pps_list[i]) return AVERROR(ENOMEM); } } - if (s->sps != s0->sps) - ret = set_sps(s, s0->sps); + if (s->ps.sps != s0->ps.sps) + ret = set_sps(s, s0->ps.sps); s->seq_decode = s0->seq_decode; s->seq_output = s0->seq_output; @@ -3099,9 +3100,9 @@ static int hevc_decode_extradata(HEVCContext *s) } /* export stream parameters from the first SPS */ - for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) { - if (s->sps_list[i]) { - const HEVCSPS *sps = (const HEVCSPS*)s->sps_list[i]->data; + for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { + if (s->ps.sps_list[i]) { + const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; export_stream_params(s->avctx, s, sps); break; } diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h index 60377c21de..32c9dc3834 100644 --- a/libavcodec/hevc.h +++ b/libavcodec/hevc.h @@ -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); /** diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c index efcaa860c7..b01808fd84 100644 --- a/libavcodec/hevc_cabac.c +++ b/libavcodec/hevc_cabac.c @@ -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; diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 2f3a3c413a..769977b44d 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -54,9 +54,9 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) // slice qp offset is not used for deblocking if (c_idx == 1) - offset = s->pps->cb_qp_offset; + offset = s->ps.pps->cb_qp_offset; else - offset = s->pps->cr_qp_offset; + offset = s->ps.pps->cr_qp_offset; qp_i = av_clip(qp_y + offset, 0, 57); if (qp_i < 30) @@ -74,15 +74,15 @@ static int get_qPy_pred(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size) { HEVCLocalContext *lc = &s->HEVClc; - int ctb_size_mask = (1 << s->sps->log2_ctb_size) - 1; - int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size - - s->pps->diff_cu_qp_delta_depth)) - 1; + int ctb_size_mask = (1 << s->ps.sps->log2_ctb_size) - 1; + int MinCuQpDeltaSizeMask = (1 << (s->ps.sps->log2_ctb_size - + s->ps.pps->diff_cu_qp_delta_depth)) - 1; int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask); int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask); - int min_cb_width = s->sps->min_cb_width; - int min_cb_height = s->sps->min_cb_height; - int x_cb = xQgBase >> s->sps->log2_min_cb_size; - int y_cb = yQgBase >> s->sps->log2_min_cb_size; + int min_cb_width = s->ps.sps->min_cb_width; + int min_cb_height = s->ps.sps->min_cb_height; + int x_cb = xQgBase >> s->ps.sps->log2_min_cb_size; + int y_cb = yQgBase >> s->ps.sps->log2_min_cb_size; int availableA = (xBase & ctb_size_mask) && (xQgBase & ctb_size_mask); int availableB = (yBase & ctb_size_mask) && @@ -95,8 +95,8 @@ static int get_qPy_pred(HEVCContext *s, int xC, int yC, qPy_pred = s->sh.slice_qp; } else { qPy_pred = lc->qp_y; - if (log2_cb_size < s->sps->log2_ctb_size - - s->pps->diff_cu_qp_delta_depth) { + if (log2_cb_size < s->ps.sps->log2_ctb_size - + s->ps.pps->diff_cu_qp_delta_depth) { static const int offsetX[8][8] = { { -1, 1, 3, 1, 7, 1, 3, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, @@ -117,19 +117,19 @@ static int get_qPy_pred(HEVCContext *s, int xC, int yC, { 1, 0, 3, 2, 5, 4, 7, 6 }, { 0, 1, 2, 3, 4, 5, 6, 7 } }; - int xC0b = (xC - (xC & ctb_size_mask)) >> s->sps->log2_min_cb_size; - int yC0b = (yC - (yC & ctb_size_mask)) >> s->sps->log2_min_cb_size; - int idxX = (xQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; - int idxY = (yQgBase & ctb_size_mask) >> s->sps->log2_min_cb_size; - int idx_mask = ctb_size_mask >> s->sps->log2_min_cb_size; + int xC0b = (xC - (xC & ctb_size_mask)) >> s->ps.sps->log2_min_cb_size; + int yC0b = (yC - (yC & ctb_size_mask)) >> s->ps.sps->log2_min_cb_size; + int idxX = (xQgBase & ctb_size_mask) >> s->ps.sps->log2_min_cb_size; + int idxY = (yQgBase & ctb_size_mask) >> s->ps.sps->log2_min_cb_size; + int idx_mask = ctb_size_mask >> s->ps.sps->log2_min_cb_size; int x, y; x = FFMIN(xC0b + offsetX[idxX][idxY], min_cb_width - 1); y = FFMIN(yC0b + (offsetY[idxX][idxY] & idx_mask), min_cb_height - 1); - if (xC0b == (lc->start_of_tiles_x >> s->sps->log2_min_cb_size) && + if (xC0b == (lc->start_of_tiles_x >> s->ps.sps->log2_min_cb_size) && offsetX[idxX][idxY] == -1) { - x = (lc->end_of_tiles_x >> s->sps->log2_min_cb_size) - 1; + x = (lc->end_of_tiles_x >> s->ps.sps->log2_min_cb_size) - 1; y = yC0b - 1; } qPy_pred = s->qp_y_tab[y * min_cb_width + x]; @@ -157,7 +157,7 @@ void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int qp_y = get_qPy_pred(s, xC, yC, xBase, yBase, log2_cb_size); if (s->HEVClc.tu.cu_qp_delta != 0) { - int off = s->sps->qp_bd_offset; + int off = s->ps.sps->qp_bd_offset; s->HEVClc.qp_y = FFUMOD(qp_y + s->HEVClc.tu.cu_qp_delta + 52 + 2 * off, 52 + off) - off; } else @@ -166,10 +166,10 @@ void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, static int get_qPy(HEVCContext *s, int xC, int yC) { - int log2_min_cb_size = s->sps->log2_min_cb_size; + int log2_min_cb_size = s->ps.sps->log2_min_cb_size; int x = xC >> log2_min_cb_size; int y = yC >> log2_min_cb_size; - return s->qp_y_tab[x + y * s->sps->min_cb_width]; + return s->qp_y_tab[x + y * s->ps.sps->min_cb_width]; } static void copy_CTB(uint8_t *dst, uint8_t *src, @@ -184,7 +184,7 @@ static void copy_CTB(uint8_t *dst, uint8_t *src, } } -#define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)]) +#define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)]) static void sao_filter_CTB(HEVCContext *s, int x, int y) { @@ -196,30 +196,30 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) SAOParams *sao[4]; int classes[4]; int x_shift = 0, y_shift = 0; - int x_ctb = x >> s->sps->log2_ctb_size; - int y_ctb = y >> s->sps->log2_ctb_size; - int ctb_addr_rs = y_ctb * s->sps->ctb_width + x_ctb; - int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[ctb_addr_rs]; + int x_ctb = x >> s->ps.sps->log2_ctb_size; + int y_ctb = y >> s->ps.sps->log2_ctb_size; + int ctb_addr_rs = y_ctb * s->ps.sps->ctb_width + x_ctb; + int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs]; // flags indicating unfilterable edges uint8_t vert_edge[] = { 0, 0, 0, 0 }; uint8_t horiz_edge[] = { 0, 0, 0, 0 }; uint8_t diag_edge[] = { 0, 0, 0, 0 }; uint8_t lfase[3]; // current, above, left - uint8_t no_tile_filter = s->pps->tiles_enabled_flag && - !s->pps->loop_filter_across_tiles_enabled_flag; + uint8_t no_tile_filter = s->ps.pps->tiles_enabled_flag && + !s->ps.pps->loop_filter_across_tiles_enabled_flag; uint8_t left_tile_edge = 0, up_tile_edge = 0; sao[0] = &CTB(s->sao, x_ctb, y_ctb); edges[0] = x_ctb == 0; edges[1] = y_ctb == 0; - edges[2] = x_ctb == s->sps->ctb_width - 1; - edges[3] = y_ctb == s->sps->ctb_height - 1; + edges[2] = x_ctb == s->ps.sps->ctb_width - 1; + edges[3] = y_ctb == s->ps.sps->ctb_height - 1; lfase[0] = CTB(s->filter_slice_edges, x_ctb, y_ctb); classes[0] = 0; if (!edges[0]) { - left_tile_edge = no_tile_filter && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]]; + left_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]]; sao[class] = &CTB(s->sao, x_ctb - 1, y_ctb); vert_edge[0] = (!lfase[0] && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb)) || left_tile_edge; vert_edge[2] = vert_edge[0]; @@ -230,7 +230,7 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) } if (!edges[1]) { - up_tile_edge = no_tile_filter && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]]; + up_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]]; sao[class] = &CTB(s->sao, x_ctb, y_ctb - 1); horiz_edge[0] = (!lfase[0] && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) || up_tile_edge; horiz_edge[1] = horiz_edge[0]; @@ -275,18 +275,18 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) int x0 = x >> chroma; int y0 = y >> chroma; int stride = s->frame->linesize[c_idx]; - int ctb_size = (1 << (s->sps->log2_ctb_size)) >> s->sps->hshift[c_idx]; + int ctb_size = (1 << (s->ps.sps->log2_ctb_size)) >> s->ps.sps->hshift[c_idx]; int width = FFMIN(ctb_size, - (s->sps->width >> s->sps->hshift[c_idx]) - x0); + (s->ps.sps->width >> s->ps.sps->hshift[c_idx]) - x0); int height = FFMIN(ctb_size, - (s->sps->height >> s->sps->vshift[c_idx]) - y0); + (s->ps.sps->height >> s->ps.sps->vshift[c_idx]) - y0); - uint8_t *src = &s->frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)]; - uint8_t *dst = &s->sao_frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)]; - int offset = (y_shift >> chroma) * stride + ((x_shift >> chroma) << s->sps->pixel_shift); + uint8_t *src = &s->frame->data[c_idx][y0 * stride + (x0 << s->ps.sps->pixel_shift)]; + uint8_t *dst = &s->sao_frame->data[c_idx][y0 * stride + (x0 << s->ps.sps->pixel_shift)]; + int offset = (y_shift >> chroma) * stride + ((x_shift >> chroma) << s->ps.sps->pixel_shift); copy_CTB(dst - offset, src - offset, - (edges[2] ? width + (x_shift >> chroma) : width) << s->sps->pixel_shift, + (edges[2] ? width + (x_shift >> chroma) : width) << s->ps.sps->pixel_shift, (edges[3] ? height + (y_shift >> chroma) : height), stride); for (class_index = 0; class_index < class; class_index++) { @@ -316,7 +316,7 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) static int get_pcm(HEVCContext *s, int x, int y) { - int log2_min_pu_size = s->sps->log2_min_pu_size; + int log2_min_pu_size = s->ps.sps->log2_min_pu_size; int x_pu, y_pu; if (x < 0 || y < 0) @@ -325,9 +325,9 @@ static int get_pcm(HEVCContext *s, int x, int y) x_pu = x >> log2_min_pu_size; y_pu = y >> log2_min_pu_size; - if (x_pu >= s->sps->min_pu_width || y_pu >= s->sps->min_pu_height) + if (x_pu >= s->ps.sps->min_pu_width || y_pu >= s->ps.sps->min_pu_height) return 2; - return s->is_pcm[y_pu * s->sps->min_pu_width + x_pu]; + return s->is_pcm[y_pu * s->ps.sps->min_pu_width + x_pu]; } #define TC_CALC(qp, bs) \ @@ -343,16 +343,16 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) uint8_t no_p[2] = { 0 }; uint8_t no_q[2] = { 0 }; - int log2_ctb_size = s->sps->log2_ctb_size; + int log2_ctb_size = s->ps.sps->log2_ctb_size; int ctb_size = 1 << log2_ctb_size; int ctb = (x0 >> log2_ctb_size) + - (y0 >> log2_ctb_size) * s->sps->ctb_width; + (y0 >> log2_ctb_size) * s->ps.sps->ctb_width; int cur_tc_offset = s->deblock[ctb].tc_offset; int cur_beta_offset = s->deblock[ctb].beta_offset; int tc_offset, left_tc_offset, beta_offset, left_beta_offset; - int pcmf = (s->sps->pcm_enabled_flag && - s->sps->pcm.loop_filter_disable_flag) || - s->pps->transquant_bypass_enable_flag; + int pcmf = (s->ps.sps->pcm_enabled_flag && + s->ps.sps->pcm.loop_filter_disable_flag) || + s->ps.pps->transquant_bypass_enable_flag; if (x0) { left_tc_offset = s->deblock[ctb - 1].tc_offset; @@ -360,11 +360,11 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) } x_end = x0 + ctb_size; - if (x_end > s->sps->width) - x_end = s->sps->width; + if (x_end > s->ps.sps->width) + x_end = s->ps.sps->width; y_end = y0 + ctb_size; - if (y_end > s->sps->height) - y_end = s->sps->height; + if (y_end > s->ps.sps->height) + y_end = s->ps.sps->height; tc_offset = cur_tc_offset; beta_offset = cur_beta_offset; @@ -381,7 +381,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) tc[0] = bs0 ? TC_CALC(qp, bs0) : 0; tc[1] = bs1 ? TC_CALC(qp, bs1) : 0; - src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; + src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->ps.sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 4); @@ -410,7 +410,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0; - src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; + src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->ps.sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 8); @@ -429,7 +429,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) } // horizontal filtering luma - if (x_end != s->sps->width) + if (x_end != s->ps.sps->width) x_end -= 8; for (y = y0 ? y0 : 8; y < y_end; y += 8) { for (x = x0 ? x0 - 8 : 0; x < x_end; x += 8) { @@ -444,7 +444,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) beta = betatable[av_clip(qp + beta_offset, 0, MAX_QP)]; tc[0] = bs0 ? TC_CALC(qp, bs0) : 0; tc[1] = bs1 ? TC_CALC(qp, bs1) : 0; - src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; + src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->ps.sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 4, y - 1); @@ -486,7 +486,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0; - src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; + src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->ps.sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 8, y - 1); @@ -588,10 +588,10 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, { HEVCLocalContext *lc = &s->HEVClc; MvField *tab_mvf = s->ref->tab_mvf; - int log2_min_pu_size = s->sps->log2_min_pu_size; - int log2_min_tu_size = s->sps->log2_min_tb_size; - int min_pu_width = s->sps->min_pu_width; - int min_tu_width = s->sps->min_tb_width; + int log2_min_pu_size = s->ps.sps->log2_min_pu_size; + int log2_min_tu_size = s->ps.sps->log2_min_tb_size; + int min_pu_width = s->ps.sps->min_pu_width; + int min_tu_width = s->ps.sps->min_tb_width; int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width + (x0 >> log2_min_pu_size)].is_intra; int boundary_upper, boundary_left; @@ -601,10 +601,10 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, if (boundary_upper && ((!s->sh.slice_loop_filter_across_slices_enabled_flag && lc->boundary_flags & BOUNDARY_UPPER_SLICE && - (y0 % (1 << s->sps->log2_ctb_size)) == 0) || - (!s->pps->loop_filter_across_tiles_enabled_flag && + (y0 % (1 << s->ps.sps->log2_ctb_size)) == 0) || + (!s->ps.pps->loop_filter_across_tiles_enabled_flag && lc->boundary_flags & BOUNDARY_UPPER_TILE && - (y0 % (1 << s->sps->log2_ctb_size)) == 0))) + (y0 % (1 << s->ps.sps->log2_ctb_size)) == 0))) boundary_upper = 0; if (boundary_upper) { @@ -633,7 +633,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, } // bs for TU internal horizontal PU boundaries - if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra) { + if (log2_trafo_size > s->ps.sps->log2_min_pu_size && !is_intra) { RefPicList *rpl = s->ref->refPicList; for (j = 8; j < (1 << log2_trafo_size); j += 8) { @@ -663,10 +663,10 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, if (boundary_left && ((!s->sh.slice_loop_filter_across_slices_enabled_flag && lc->boundary_flags & BOUNDARY_LEFT_SLICE && - (x0 % (1 << s->sps->log2_ctb_size)) == 0) || - (!s->pps->loop_filter_across_tiles_enabled_flag && + (x0 % (1 << s->ps.sps->log2_ctb_size)) == 0) || + (!s->ps.pps->loop_filter_across_tiles_enabled_flag && lc->boundary_flags & BOUNDARY_LEFT_TILE && - (x0 % (1 << s->sps->log2_ctb_size)) == 0))) + (x0 % (1 << s->ps.sps->log2_ctb_size)) == 0))) boundary_left = 0; if (boundary_left) { @@ -729,7 +729,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, void ff_hevc_hls_filter(HEVCContext *s, int x, int y) { deblocking_filter_CTB(s, x, y); - if (s->sps->sao_enabled) + if (s->ps.sps->sao_enabled) sao_filter_CTB(s, x, y); } @@ -737,10 +737,10 @@ void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size) { if (y_ctb && x_ctb) ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb - ctb_size); - if (y_ctb && x_ctb >= s->sps->width - ctb_size) { + if (y_ctb && x_ctb >= s->ps.sps->width - ctb_size) { ff_hevc_hls_filter(s, x_ctb, y_ctb - ctb_size); ff_thread_report_progress(&s->ref->tf, y_ctb - ctb_size, 0); } - if (x_ctb && y_ctb >= s->sps->height - ctb_size) + if (x_ctb && y_ctb >= s->ps.sps->height - ctb_size) ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb); } diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c index 23ea2ec2ee..b99223c07b 100644 --- a/libavcodec/hevc_mvs.c +++ b/libavcodec/hevc_mvs.c @@ -42,17 +42,17 @@ void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0, int nPbW, int nPbH) { HEVCLocalContext *lc = &s->HEVClc; - 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); lc->na.cand_up = (lc->ctb_up_flag || y0b); lc->na.cand_left = (lc->ctb_left_flag || x0b); lc->na.cand_up_left = (!x0b && !y0b) ? lc->ctb_up_left_flag : lc->na.cand_left && lc->na.cand_up; lc->na.cand_up_right_sap = - ((x0b + nPbW) == (1 << s->sps->log2_ctb_size)) ? + ((x0b + nPbW) == (1 << s->ps.sps->log2_ctb_size)) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up; lc->na.cand_up_right = - ((x0b + nPbW) == (1 << s->sps->log2_ctb_size) ? + ((x0b + nPbW) == (1 << s->ps.sps->log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up ) && (x0 + nPbW) < lc->end_of_tiles_x; lc->na.cand_bottom_left = ((y0 + nPbH) >= lc->end_of_tiles_y) ? 0 : lc->na.cand_left; @@ -65,18 +65,18 @@ static int z_scan_block_avail(HEVCContext *s, int xCurr, int yCurr, int xN, int yN) { #define MIN_TB_ADDR_ZS(x, y) \ - s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)] - int Curr = MIN_TB_ADDR_ZS(xCurr >> s->sps->log2_min_tb_size, - yCurr >> s->sps->log2_min_tb_size); + s->ps.pps->min_tb_addr_zs[(y) * s->ps.sps->min_tb_width + (x)] + int Curr = MIN_TB_ADDR_ZS(xCurr >> s->ps.sps->log2_min_tb_size, + yCurr >> s->ps.sps->log2_min_tb_size); int N; if (xN < 0 || yN < 0 || - xN >= s->sps->width || - yN >= s->sps->height) + xN >= s->ps.sps->width || + yN >= s->ps.sps->height) return 0; - N = MIN_TB_ADDR_ZS(xN >> s->sps->log2_min_tb_size, - yN >> s->sps->log2_min_tb_size); + N = MIN_TB_ADDR_ZS(xN >> s->ps.sps->log2_min_tb_size, + yN >> s->ps.sps->log2_min_tb_size); return N <= Curr; } @@ -112,7 +112,7 @@ static int check_prediction_block_available(HEVCContext *s, int log2_cb_size, //check if the two luma locations belong to the same mostion estimation region static int isDiffMER(HEVCContext *s, int xN, int yN, int xP, int yP) { - uint8_t plevel = s->pps->log2_parallel_merge_level; + uint8_t plevel = s->ps.pps->log2_parallel_merge_level; return xN >> plevel == xP >> plevel && yN >> plevel == yP >> plevel; @@ -251,7 +251,7 @@ static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0, MvField *tab_mvf; MvField temp_col; int x, y, x_pu, y_pu; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->ps.sps->min_pu_width; int availableFlagLXCol = 0; int colPic; @@ -270,14 +270,14 @@ static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0, y = y0 + nPbH; if (tab_mvf && - (y0 >> s->sps->log2_ctb_size) == (y >> s->sps->log2_ctb_size) && - y < s->sps->height && - x < s->sps->width) { + (y0 >> s->ps.sps->log2_ctb_size) == (y >> s->ps.sps->log2_ctb_size) && + y < s->ps.sps->height && + x < s->ps.sps->width) { x &= ~15; y &= ~15; ff_thread_await_progress(&ref->tf, y, 0); - x_pu = x >> s->sps->log2_min_pu_size; - y_pu = y >> s->sps->log2_min_pu_size; + x_pu = x >> s->ps.sps->log2_min_pu_size; + y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS; } @@ -289,8 +289,8 @@ static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0, x &= ~15; y &= ~15; ff_thread_await_progress(&ref->tf, y, 0); - x_pu = x >> s->sps->log2_min_pu_size; - y_pu = y >> s->sps->log2_min_pu_size; + x_pu = x >> s->ps.sps->log2_min_pu_size; + y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS; } @@ -322,7 +322,7 @@ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, RefPicList *refPicList = s->ref->refPicList; MvField *tab_mvf = s->ref->tab_mvf; - const int min_pu_width = s->sps->min_pu_width; + const int min_pu_width = s->ps.sps->min_pu_width; const int cand_bottom_left = lc->na.cand_bottom_left; const int cand_left = lc->na.cand_left; @@ -332,28 +332,28 @@ static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0, const int xA1 = x0 - 1; const int yA1 = y0 + nPbH - 1; - const int xA1_pu = xA1 >> s->sps->log2_min_pu_size; - const int yA1_pu = yA1 >> s->sps->log2_min_pu_size; + const int xA1_pu = xA1 >> s->ps.sps->log2_min_pu_size; + const int yA1_pu = yA1 >> s->ps.sps->log2_min_pu_size; const int xB1 = x0 + nPbW - 1; const int yB1 = y0 - 1; - const int xB1_pu = xB1 >> s->sps->log2_min_pu_size; - const int yB1_pu = yB1 >> s->sps->log2_min_pu_size; + const int xB1_pu = xB1 >> s->ps.sps->log2_min_pu_size; + const int yB1_pu = yB1 >> s->ps.sps->log2_min_pu_size; const int xB0 = x0 + nPbW; const int yB0 = y0 - 1; - const int xB0_pu = xB0 >> s->sps->log2_min_pu_size; - const int yB0_pu = yB0 >> s->sps->log2_min_pu_size; + const int xB0_pu = xB0 >> s->ps.sps->log2_min_pu_size; + const int yB0_pu = yB0 >> s->ps.sps->log2_min_pu_size; const int xA0 = x0 - 1; const int yA0 = y0 + nPbH; - const int xA0_pu = xA0 >> s->sps->log2_min_pu_size; - const int yA0_pu = yA0 >> s->sps->log2_min_pu_size; + const int xA0_pu = xA0 >> s->ps.sps->log2_min_pu_size; + const int yA0_pu = yA0 >> s->ps.sps->log2_min_pu_size; const int xB2 = x0 - 1; const int yB2 = y0 - 1; - const int xB2_pu = xB2 >> s->sps->log2_min_pu_size; - const int yB2_pu = yB2 >> s->sps->log2_min_pu_size; + const int xB2_pu = xB2 >> s->ps.sps->log2_min_pu_size; + const int yB2_pu = yB2 >> s->ps.sps->log2_min_pu_size; const int nb_refs = (s->sh.slice_type == P_SLICE) ? s->sh.nb_refs[0] : FFMIN(s->sh.nb_refs[0], s->sh.nb_refs[1]); @@ -554,7 +554,7 @@ void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH2 = nPbH; HEVCLocalContext *lc = &s->HEVClc; - if (s->pps->log2_parallel_merge_level > 2 && nCS == 8) { + if (s->ps.pps->log2_parallel_merge_level > 2 && nCS == 8) { singleMCLFlag = 1; x0 = lc->cu.x; y0 = lc->cu.y; @@ -599,7 +599,7 @@ static int mv_mp_mode_mx(HEVCContext *s, int x, int y, int pred_flag_index, Mv *mv, int ref_idx_curr, int ref_idx) { MvField *tab_mvf = s->ref->tab_mvf; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->ps.sps->min_pu_width; RefPicList *refPicList = s->ref->refPicList; @@ -615,7 +615,7 @@ static int mv_mp_mode_mx_lt(HEVCContext *s, int x, int y, int pred_flag_index, Mv *mv, int ref_idx_curr, int ref_idx) { MvField *tab_mvf = s->ref->tab_mvf; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->ps.sps->min_pu_width; RefPicList *refPicList = s->ref->refPicList; int currIsLongTerm = refPicList[ref_idx_curr].isLongTerm[ref_idx]; @@ -653,7 +653,7 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, int availableFlagLXA0 = 0; int availableFlagLXB0 = 0; int numMVPCandLX = 0; - int min_pu_width = s->sps->min_pu_width; + int min_pu_width = s->ps.sps->min_pu_width; int xA0, yA0; int xA0_pu, yA0_pu; @@ -681,15 +681,15 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, int ref_idx = 0; int pred_flag_index_l0; int pred_flag_index_l1; - 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); int cand_up = (lc->ctb_up_flag || y0b); int cand_left = (lc->ctb_left_flag || x0b); int cand_up_left = (!x0b && !y0b) ? lc->ctb_up_left_flag : cand_left && cand_up; int cand_up_right = - (x0b + nPbW == (1 << s->sps->log2_ctb_size) || + (x0b + nPbW == (1 << s->ps.sps->log2_ctb_size) || x0 + nPbW >= lc->end_of_tiles_x) ? lc->ctb_up_right_flag && !y0b : cand_up; int cand_bottom_left = (y0 + nPbH >= lc->end_of_tiles_y) ? 0 : cand_left; @@ -702,16 +702,16 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, // left bottom spatial candidate xA0 = x0 - 1; yA0 = y0 + nPbH; - xA0_pu = xA0 >> s->sps->log2_min_pu_size; - yA0_pu = yA0 >> s->sps->log2_min_pu_size; + xA0_pu = xA0 >> s->ps.sps->log2_min_pu_size; + yA0_pu = yA0 >> s->ps.sps->log2_min_pu_size; is_available_a0 = PRED_BLOCK_AVAILABLE(A0) && AVAILABLE(cand_bottom_left, A0); //left spatial merge candidate xA1 = x0 - 1; yA1 = y0 + nPbH - 1; - xA1_pu = xA1 >> s->sps->log2_min_pu_size; - yA1_pu = yA1 >> s->sps->log2_min_pu_size; + xA1_pu = xA1 >> s->ps.sps->log2_min_pu_size; + yA1_pu = yA1 >> s->ps.sps->log2_min_pu_size; is_available_a1 = AVAILABLE(cand_left, A1); if (is_available_a0 || is_available_a1) @@ -750,8 +750,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, // above right spatial merge candidate xB0 = x0 + nPbW; yB0 = y0 - 1; - xB0_pu = xB0 >> s->sps->log2_min_pu_size; - yB0_pu = yB0 >> s->sps->log2_min_pu_size; + xB0_pu = xB0 >> s->ps.sps->log2_min_pu_size; + yB0_pu = yB0 >> s->ps.sps->log2_min_pu_size; is_available_b0 = PRED_BLOCK_AVAILABLE(B0) && AVAILABLE(cand_up_right, B0); @@ -765,8 +765,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, // above spatial merge candidate xB1 = x0 + nPbW - 1; yB1 = y0 - 1; - xB1_pu = xB1 >> s->sps->log2_min_pu_size; - yB1_pu = yB1 >> s->sps->log2_min_pu_size; + xB1_pu = xB1 >> s->ps.sps->log2_min_pu_size; + yB1_pu = yB1 >> s->ps.sps->log2_min_pu_size; is_available_b1 = AVAILABLE(cand_up, B1); @@ -781,8 +781,8 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, // above left spatial merge candidate xB2 = x0 - 1; yB2 = y0 - 1; - xB2_pu = xB2 >> s->sps->log2_min_pu_size; - yB2_pu = yB2 >> s->sps->log2_min_pu_size; + xB2_pu = xB2 >> s->ps.sps->log2_min_pu_size; + yB2_pu = yB2 >> s->ps.sps->log2_min_pu_size; is_available_b2 = AVAILABLE(cand_up_left, B2); if (is_available_b2) { diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 98d4a2f3ee..6102905709 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -70,14 +70,14 @@ static const AVRational vui_sar[] = { { 2, 1 }, }; -static void remove_pps(HEVCContext *s, int id) +static void remove_pps(HEVCParamSets *s, int id) { if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data) s->pps = NULL; av_buffer_unref(&s->pps_list[id]); } -static void remove_sps(HEVCContext *s, int id) +static void remove_sps(HEVCParamSets *s, int id) { int i; if (s->sps_list[id]) { @@ -92,7 +92,7 @@ static void remove_sps(HEVCContext *s, int id) av_buffer_unref(&s->sps_list[id]); } -static void remove_vps(HEVCContext *s, int id) +static void remove_vps(HEVCParamSets *s, int id) { int i; if (s->vps_list[id]) { @@ -350,10 +350,10 @@ static void decode_hrd(GetBitContext *gb, int common_inf_present, } } -int ff_hevc_decode_nal_vps(HEVCContext *s) +int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, + HEVCParamSets *ps) { int i,j; - GetBitContext *gb = &s->HEVClc.gb; int vps_id = 0; HEVCVPS *vps; AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps)); @@ -362,16 +362,16 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) return AVERROR(ENOMEM); vps = (HEVCVPS*)vps_buf->data; - av_log(s->avctx, AV_LOG_DEBUG, "Decoding VPS\n"); + av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); vps_id = get_bits(gb, 4); if (vps_id >= MAX_VPS_COUNT) { - av_log(s->avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id); + av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id); goto err; } if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits - av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n"); + av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n"); goto err; } @@ -380,17 +380,17 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) vps->vps_temporal_id_nesting_flag = get_bits1(gb); if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits - av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n"); + av_log(avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n"); goto err; } if (vps->vps_max_sub_layers > MAX_SUB_LAYERS) { - av_log(s->avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", vps->vps_max_sub_layers); goto err; } - parse_ptl(gb, s->avctx, &vps->ptl, vps->vps_max_sub_layers); + parse_ptl(gb, avctx, &vps->ptl, vps->vps_max_sub_layers); vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); @@ -401,14 +401,14 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1; if (vps->vps_max_dec_pic_buffering[i] > MAX_DPB_SIZE) { - av_log(s->avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n", vps->vps_max_dec_pic_buffering[i] - 1); goto err; } if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) { - av_log(s->avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n", + av_log(avctx, AV_LOG_WARNING, "vps_max_num_reorder_pics out of range: %d\n", vps->vps_num_reorder_pics[i]); - if (s->avctx->err_recognition & AV_EF_EXPLODE) + if (avctx->err_recognition & AV_EF_EXPLODE) goto err; } } @@ -438,12 +438,12 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) } get_bits1(gb); /* vps_extension_flag */ - if (s->vps_list[vps_id] && - !memcmp(s->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) { + if (ps->vps_list[vps_id] && + !memcmp(ps->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) { av_buffer_unref(&vps_buf); } else { - remove_vps(s, vps_id); - s->vps_list[vps_id] = vps_buf; + remove_vps(ps, vps_id); + ps->vps_list[vps_id] = vps_buf; } return 0; @@ -968,7 +968,8 @@ err: return ret; } -int ff_hevc_decode_nal_sps(HEVCContext *s) +int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, + HEVCParamSets *ps, int apply_defdispwin) { HEVCSPS *sps; AVBufferRef *sps_buf = av_buffer_allocz(sizeof(*sps)); @@ -979,18 +980,18 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) return AVERROR(ENOMEM); sps = (HEVCSPS*)sps_buf->data; - av_log(s->avctx, AV_LOG_DEBUG, "Decoding SPS\n"); + av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); - ret = ff_hevc_parse_sps(sps, &s->HEVClc.gb, &sps_id, - s->apply_defdispwin, - s->vps_list, s->avctx); + ret = ff_hevc_parse_sps(sps, gb, &sps_id, + apply_defdispwin, + ps->vps_list, avctx); if (ret < 0) { av_buffer_unref(&sps_buf); return ret; } - if (s->avctx->debug & FF_DEBUG_BITSTREAM) { - av_log(s->avctx, AV_LOG_DEBUG, + if (avctx->debug & FF_DEBUG_BITSTREAM) { + av_log(avctx, AV_LOG_DEBUG, "Parsed SPS: id %d; coded wxh: %dx%d; " "cropped wxh: %dx%d; pix_fmt: %s.\n", sps_id, sps->width, sps->height, @@ -1001,12 +1002,12 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) /* check if this is a repeat of an already parsed SPS, then keep the * original one. * otherwise drop all PPSes that depend on it */ - if (s->sps_list[sps_id] && - !memcmp(s->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) { + if (ps->sps_list[sps_id] && + !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) { av_buffer_unref(&sps_buf); } else { - remove_sps(s, sps_id); - s->sps_list[sps_id] = sps_buf; + remove_sps(ps, sps_id); + ps->sps_list[sps_id] = sps_buf; } return 0; @@ -1030,9 +1031,9 @@ static void hevc_pps_free(void *opaque, uint8_t *data) av_freep(&pps); } -int ff_hevc_decode_nal_pps(HEVCContext *s) +int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, + HEVCParamSets *ps) { - GetBitContext *gb = &s->HEVClc.gb; HEVCSPS *sps = NULL; int pic_area_in_ctbs, pic_area_in_min_tbs; int log2_diff_ctb_min_tb_size; @@ -1053,7 +1054,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) return AVERROR(ENOMEM); } - av_log(s->avctx, AV_LOG_DEBUG, "Decoding PPS\n"); + av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); // Default values pps->loop_filter_across_tiles_enabled_flag = 1; @@ -1067,22 +1068,22 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) // Coded parameters pps_id = get_ue_golomb_long(gb); if (pps_id >= MAX_PPS_COUNT) { - av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); + av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); ret = AVERROR_INVALIDDATA; goto err; } pps->sps_id = get_ue_golomb_long(gb); if (pps->sps_id >= MAX_SPS_COUNT) { - av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); + av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } - if (!s->sps_list[pps->sps_id]) { - av_log(s->avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); + if (!ps->sps_list[pps->sps_id]) { + av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } - sps = (HEVCSPS *)s->sps_list[pps->sps_id]->data; + sps = (HEVCSPS *)ps->sps_list[pps->sps_id]->data; pps->dependent_slice_segments_enabled_flag = get_bits1(gb); pps->output_flag_present_flag = get_bits1(gb); @@ -1107,14 +1108,14 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->cb_qp_offset = get_se_golomb(gb); if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) { - av_log(s->avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", pps->cb_qp_offset); ret = AVERROR_INVALIDDATA; goto err; } pps->cr_qp_offset = get_se_golomb(gb); if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) { - av_log(s->avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", pps->cr_qp_offset); ret = AVERROR_INVALIDDATA; goto err; @@ -1133,14 +1134,14 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->num_tile_rows = get_ue_golomb_long(gb) + 1; if (pps->num_tile_columns == 0 || pps->num_tile_columns >= sps->width) { - av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", pps->num_tile_columns - 1); ret = AVERROR_INVALIDDATA; goto err; } if (pps->num_tile_rows == 0 || pps->num_tile_rows >= sps->height) { - av_log(s->avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", pps->num_tile_rows - 1); ret = AVERROR_INVALIDDATA; goto err; @@ -1161,7 +1162,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) sum += pps->column_width[i]; } if (sum >= sps->ctb_width) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); + av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); ret = AVERROR_INVALIDDATA; goto err; } @@ -1173,7 +1174,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) sum += pps->row_height[i]; } if (sum >= sps->ctb_height) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); + av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); ret = AVERROR_INVALIDDATA; goto err; } @@ -1192,13 +1193,13 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->beta_offset = get_se_golomb(gb) * 2; pps->tc_offset = get_se_golomb(gb) * 2; if (pps->beta_offset/2 < -6 || pps->beta_offset/2 > 6) { - av_log(s->avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", pps->beta_offset/2); ret = AVERROR_INVALIDDATA; goto err; } if (pps->tc_offset/2 < -6 || pps->tc_offset/2 > 6) { - av_log(s->avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", pps->tc_offset/2); ret = AVERROR_INVALIDDATA; goto err; @@ -1209,14 +1210,14 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) pps->scaling_list_data_present_flag = get_bits1(gb); if (pps->scaling_list_data_present_flag) { set_default_scaling_list_data(&pps->scaling_list); - ret = scaling_list_data(gb, s->avctx, &pps->scaling_list); + ret = scaling_list_data(gb, avctx, &pps->scaling_list); if (ret < 0) goto err; } pps->lists_modification_present_flag = get_bits1(gb); pps->log2_parallel_merge_level = get_ue_golomb_long(gb) + 2; if (pps->log2_parallel_merge_level > sps->log2_ctb_size) { - av_log(s->avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", + av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", pps->log2_parallel_merge_level - 2); ret = AVERROR_INVALIDDATA; goto err; @@ -1350,8 +1351,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) } } - remove_pps(s, pps_id); - s->pps_list[pps_id] = pps_buf; + remove_pps(ps, pps_id); + ps->pps_list[pps_id] = pps_buf; return 0; diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index f232d03020..a4889a19c1 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -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; diff --git a/libavcodec/hevcpred_template.c b/libavcodec/hevcpred_template.c index 53b9c590b6..039882bb52 100644 --- a/libavcodec/hevcpred_template.c +++ b/libavcodec/hevcpred_template.c @@ -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) { -- cgit v1.2.3