aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickaƫl Raulet <mraulet@insa-rennes.fr>2013-10-27 13:29:50 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-10-27 23:46:54 +0100
commit3106cbd32118b121b5ae3dbf1e586a41c2f0793f (patch)
treec0b3602721af46d63e3e9ca67fa021a904101b60
parent3c3ece24ea1e6fdc8984234184bec18bc8f70750 (diff)
downloadffmpeg-3106cbd32118b121b5ae3dbf1e586a41c2f0793f.tar.gz
hevc: more cosmetic(cherry picked from commit 9697abe41daa234602915f85bf6b1c0ca0252cff)
Decreases the difference to Anton Khirnovs patch v5 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/hevc.c261
-rw-r--r--libavcodec/hevc_cabac.c6
2 files changed, 131 insertions, 136 deletions
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index acf55c0f9d..4949b7a741 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -89,9 +89,9 @@ static int pic_arrays_init(HEVCContext *s)
int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
((height >> log2_min_cb_size) + 1);
int ctb_count = s->sps->ctb_width * s->sps->ctb_height;
- int pic_width_in_min_pu = width >> s->sps->log2_min_pu_size;
+ int min_pu_width = width >> s->sps->log2_min_pu_size;
int pic_height_in_min_pu = height >> s->sps->log2_min_pu_size;
- int pic_size_in_min_pu = pic_width_in_min_pu * pic_height_in_min_pu;
+ int pic_size_in_min_pu = min_pu_width * pic_height_in_min_pu;
int pic_width_in_min_tu = width >> s->sps->log2_min_tb_size;
int pic_height_in_min_tu = height >> s->sps->log2_min_tb_size;
@@ -116,8 +116,8 @@ static int pic_arrays_init(HEVCContext *s)
goto fail;
s->filter_slice_edges = av_malloc(ctb_count);
- s->tab_slice_address = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address));
- s->qp_y_tab = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab));
+ s->tab_slice_address = av_malloc(pic_size_in_ctb * sizeof(*s->tab_slice_address));
+ s->qp_y_tab = av_malloc(pic_size_in_ctb * sizeof(*s->qp_y_tab));
if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
goto fail;
@@ -128,12 +128,9 @@ static int pic_arrays_init(HEVCContext *s)
s->tab_mvf_pool = av_buffer_pool_init(pic_size_in_min_pu * sizeof(MvField),
av_buffer_alloc);
- if (!s->tab_mvf_pool)
- goto fail;
-
s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),
av_buffer_allocz);
- if (!s->rpl_tab_pool)
+ if (!s->tab_mvf_pool || !s->rpl_tab_pool)
goto fail;
return 0;
@@ -164,14 +161,12 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
s->sh.luma_offset_l0[i] = 0;
}
}
- if (s->sps->chroma_format_idc != 0) { //fix me ! invert "if" and "for"
- for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+ if (s->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 {
- for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+ for (i = 0; i < s->sh.nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = 0;
- }
}
for (i = 0; i < s->sh.nb_refs[L0]; i++) {
if (luma_weight_l0_flag[i]) {
@@ -185,7 +180,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
int delta_chroma_offset_l0 = get_se_golomb(gb);
s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
s->sh.chroma_offset_l0[i][j] = av_clip_c((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j])
- >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+ >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
}
} else {
s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom;
@@ -203,13 +198,11 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
}
}
if (s->sps->chroma_format_idc != 0) {
- for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+ for (i = 0; i < s->sh.nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = get_bits1(gb);
- }
} else {
- for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+ for (i = 0; i < s->sh.nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = 0;
- }
}
for (i = 0; i < s->sh.nb_refs[L1]; i++) {
if (luma_weight_l1_flag[i]) {
@@ -223,7 +216,7 @@ static void pred_weight_table(HEVCContext *s, GetBitContext *gb)
int delta_chroma_offset_l1 = get_se_golomb(gb);
s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
s->sh.chroma_offset_l1[i][j] = av_clip_c((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j])
- >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+ >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
}
} else {
s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom;
@@ -238,7 +231,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;
- int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
+ int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
int prev_delta_msb = 0;
int nb_sps = 0, nb_sh;
int i;
@@ -297,7 +290,7 @@ static int hls_slice_header(HEVCContext *s)
sh->first_slice_in_pic_flag = get_bits1(gb);
if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
s->seq_decode = (s->seq_decode + 1) & 0xff;
- s->max_ra = INT_MAX;
+ s->max_ra = INT_MAX;
if (IS_IDR(s))
ff_hevc_clear_refs(s);
}
@@ -361,7 +354,7 @@ static int hls_slice_header(HEVCContext *s)
sh->dependent_slice_segment_flag = get_bits1(gb);
slice_address_length = av_ceil_log2(s->sps->ctb_width *
- s->sps->ctb_height);
+ s->sps->ctb_height);
sh->slice_segment_addr = get_bits(gb, slice_address_length);
if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
@@ -375,8 +368,8 @@ static int hls_slice_header(HEVCContext *s)
}
} else {
sh->slice_segment_addr = sh->slice_addr = 0;
- s->slice_idx = 0;
- s->slice_initialized = 0;
+ s->slice_idx = 0;
+ s->slice_initialized = 0;
}
if (!sh->dependent_slice_segment_flag) {
@@ -450,6 +443,7 @@ static int hls_slice_header(HEVCContext *s)
s->poc = 0;
}
+ /* 8.3.1 */
if (s->temporal_id == 0 &&
s->nal_unit_type != NAL_TRAIL_N &&
s->nal_unit_type != NAL_TSA_N &&
@@ -462,8 +456,8 @@ static int hls_slice_header(HEVCContext *s)
if (s->sps->sao_enabled) {
sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
- sh->slice_sample_adaptive_offset_flag[2] =
- sh->slice_sample_adaptive_offset_flag[1] = get_bits1(gb);
+ sh->slice_sample_adaptive_offset_flag[1] =
+ sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
} else {
sh->slice_sample_adaptive_offset_flag[0] = 0;
sh->slice_sample_adaptive_offset_flag[1] = 0;
@@ -542,6 +536,12 @@ static int hls_slice_header(HEVCContext *s)
}
sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb);
+ if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Invalid number of merging MVP candidates: %d.\n",
+ sh->max_num_merge_cand);
+ return AVERROR_INVALIDDATA;
+ }
}
sh->slice_qp_delta = get_se_golomb(gb);
@@ -729,12 +729,12 @@ static void hls_sao_param(HEVCContext *s, int rx, int ry)
#undef CTB
-static void hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase,
- int log2_cb_size, int log2_trafo_size, int trafo_depth, int blk_idx)
+static void hls_transform_unit(HEVCContext *s, int x0, int y0,
+ int xBase, int yBase, int cb_xBase, int cb_yBase,
+ int log2_cb_size, int log2_trafo_size,
+ int trafo_depth, int blk_idx)
{
HEVCLocalContext *lc = s->HEVClc;
- int scan_idx = SCAN_DIAG;
- int scan_idx_c = SCAN_DIAG;
if (lc->cu.pred_mode == MODE_INTRA) {
int trafo_size = 1 << log2_trafo_size;
@@ -742,12 +742,12 @@ static void hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int y
s->hpc.intra_pred(s, x0, y0, log2_trafo_size, 0);
if (log2_trafo_size > 2) {
- trafo_size = trafo_size<<(s->sps->hshift[1]-1);
+ trafo_size = trafo_size << (s->sps->hshift[1] - 1);
ff_hevc_set_neighbour_available(s, x0, y0, trafo_size, trafo_size);
s->hpc.intra_pred(s, x0, y0, log2_trafo_size - 1, 1);
s->hpc.intra_pred(s, x0, y0, log2_trafo_size - 1, 2);
} else if (blk_idx == 3) {
- trafo_size = trafo_size<<(s->sps->hshift[1]);
+ trafo_size = trafo_size << (s->sps->hshift[1]);
ff_hevc_set_neighbour_available(s, xBase, yBase, trafo_size, trafo_size);
s->hpc.intra_pred(s, xBase, yBase, log2_trafo_size, 1);
s->hpc.intra_pred(s, xBase, yBase, log2_trafo_size, 2);
@@ -757,6 +757,9 @@ static void hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int y
if (lc->tt.cbf_luma ||
SAMPLE_CBF(lc->tt.cbf_cb[trafo_depth], x0, y0) ||
SAMPLE_CBF(lc->tt.cbf_cr[trafo_depth], x0, 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) {
lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(s);
if (lc->tu.cu_qp_delta != 0)
@@ -802,17 +805,17 @@ static void hls_transform_unit(HEVCContext *s, int x0, int y0, int xBase, int y
static void set_deblocking_bypass(HEVCContext *s, int x0, int y0, int log2_cb_size)
{
- int cb_size = 1 << log2_cb_size;
+ int cb_size = 1 << log2_cb_size;
int log2_min_pu_size = s->sps->log2_min_pu_size;
- int pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
+ int min_pu_width = s->sps->width >> s->sps->log2_min_pu_size;
int x_end = FFMIN(x0 + cb_size, s->sps->width);
int y_end = FFMIN(y0 + cb_size, s->sps->height);
int i, j;
for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
- s->is_pcm[i + j * pic_width_in_min_pu] = 2;
+ s->is_pcm[i + j * min_pu_width] = 2;
}
static void hls_transform_tree(HEVCContext *s, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase,
@@ -1071,7 +1074,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nP
enum InterPredIdc inter_pred_idc = PRED_L0;
struct MvField current_mv = {{{ 0 }}};
- int pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
+ int min_pu_width = s->sps->width >> s->sps->log2_min_pu_size;
MvField *tab_mvf = s->ref->tab_mvf;
RefPicList *refPicList = s->ref->refPicList;
@@ -1104,7 +1107,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nP
for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i] = current_mv;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
} else { /* MODE_INTER */
lc->pu.merge_flag = ff_hevc_merge_flag_decode(s);
if (lc->pu.merge_flag) {
@@ -1120,7 +1123,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nP
for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
for (j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i] = current_mv;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
} else {
ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH);
if (s->sh.slice_type == B_SLICE)
@@ -1166,7 +1169,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, int y0, int nPbW, int nP
for (i = 0; i < nPbW >> s->sps->log2_min_pu_size; i++)
for(j = 0; j < nPbH >> s->sps->log2_min_pu_size; j++)
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i] = current_mv;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
}
}
@@ -1319,13 +1322,13 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
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 pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
+ int min_pu_width = s->sps->width >> s->sps->log2_min_pu_size;
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 cand_up = (lc->ctb_up_flag || y0b) ? s->tab_ipm[(y_pu-1)*pic_width_in_min_pu+x_pu] : INTRA_DC ;
- int cand_left = (lc->ctb_left_flag || x0b) ? s->tab_ipm[y_pu*pic_width_in_min_pu+x_pu-1] : INTRA_DC ;
+ 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);
MvField *tab_mvf = s->ref->tab_mvf;
@@ -1380,19 +1383,19 @@ static int luma_intra_pred_mode(HEVCContext *s, int x0, int y0, int pu_size,
if(!size_in_pus)
size_in_pus = 1;
for (i = 0; i < size_in_pus; i++) {
- memset(&s->tab_ipm[(y_pu + i) * pic_width_in_min_pu + x_pu],
+ memset(&s->tab_ipm[(y_pu + i) * min_pu_width + x_pu],
intra_pred_mode, size_in_pus);
for (j = 0; j < size_in_pus; j++) {
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].is_intra = 1;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].pred_flag[0] = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].pred_flag[1] = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].ref_idx[0] = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].ref_idx[1] = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].mv[0].x = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].mv[0].y = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].mv[1].x = 0;
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + i].mv[1].y = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].is_intra = 1;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag[0] = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].pred_flag[1] = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].ref_idx[0] = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].ref_idx[1] = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[0].x = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[0].y = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[1].x = 0;
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].mv[1].y = 0;
}
}
@@ -1454,20 +1457,20 @@ static void intra_prediction_unit(HEVCContext *s, int x0, int y0, int log2_cb_si
static void intra_prediction_unit_default_value(HEVCContext *s, int x0, int y0, int log2_cb_size)
{
HEVCLocalContext *lc = s->HEVClc;
- int pb_size = 1 << log2_cb_size;
- int size_in_pus = pb_size >> s->sps->log2_min_pu_size;
- int pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
- 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 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;
+ 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 j, k;
if (size_in_pus == 0)
size_in_pus = 1;
for (j = 0; j < size_in_pus; j++) {
- memset(&s->tab_ipm[(y_pu + j) * pic_width_in_min_pu + x_pu], INTRA_DC, size_in_pus);
- for (k = 0; k <size_in_pus; k++)
- tab_mvf[(y_pu + j) * pic_width_in_min_pu + x_pu + k].is_intra = lc->cu.pred_mode == MODE_INTRA;
+ memset(&s->tab_ipm[(y_pu + j) * min_pu_width + x_pu], INTRA_DC, size_in_pus);
+ for (k = 0; k < size_in_pus; k++)
+ tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].is_intra = lc->cu.pred_mode == MODE_INTRA;
}
}
@@ -1477,19 +1480,19 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
HEVCLocalContext *lc = s->HEVClc;
int log2_min_cb_size = s->sps->log2_min_cb_size;
int length = cb_size >> log2_min_cb_size;
- int min_cb_width = s->sps->width >> log2_min_cb_size;
+ int min_cb_width = s->sps->min_cb_width;
int x_cb = x0 >> log2_min_cb_size;
int y_cb = y0 >> log2_min_cb_size;
int x, y;
- lc->cu.x = x0;
- lc->cu.y = y0;
+ lc->cu.x = x0;
+ lc->cu.y = y0;
lc->cu.rqt_root_cbf = 1;
- lc->cu.pred_mode = MODE_INTRA;
- lc->cu.part_mode = PART_2Nx2N;
- lc->cu.intra_split_flag = 0;
- lc->cu.pcm_flag = 0;
+ lc->cu.pred_mode = MODE_INTRA;
+ lc->cu.part_mode = PART_2Nx2N;
+ lc->cu.intra_split_flag = 0;
+ lc->cu.pcm_flag = 0;
SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0;
for (x = 0; x < 4; x++)
lc->pu.intra_pred_mode[x] = 1;
@@ -1525,7 +1528,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
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) {
- lc->cu.part_mode = ff_hevc_part_mode_decode(s, log2_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;
}
@@ -1540,7 +1543,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
int ret;
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->sps->pcm.loop_filter_disable_flag)
set_deblocking_bypass(s, x0, y0, log2_cb_size);
if (ret < 0)
@@ -1594,8 +1597,8 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
}
if (lc->cu.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->sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
+ s->sps->max_transform_hierarchy_depth_inter;
hls_transform_tree(s, x0, y0, x0, y0, x0, y0, log2_cb_size,
log2_cb_size, 0, 0);
} else {
@@ -1621,14 +1624,16 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
return 0;
}
-static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int log2_cb_size, int cb_depth)
+static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
+ int log2_cb_size, int cb_depth)
{
HEVCLocalContext *lc = s->HEVClc;
+ const int cb_size = 1 << log2_cb_size;
int ret;
lc->ct.depth = cb_depth;
- if ((x0 + (1 << log2_cb_size) <= s->sps->width) &&
- (y0 + (1 << log2_cb_size) <= s->sps->height) &&
+ if ((x0 + cb_size <= s->sps->width) &&
+ (y0 + cb_size <= s->sps->height) &&
log2_cb_size > s->sps->log2_min_cb_size) {
SAMPLE(s->split_cu_flag, x0, y0) =
ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
@@ -1643,10 +1648,10 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int log2_cb_size,
}
if (SAMPLE(s->split_cu_flag, x0, y0)) {
+ const int cb_size_split = cb_size >> 1;
+ const int x1 = x0 + cb_size_split;
+ const int y1 = y0 + cb_size_split;
int more_data = 0;
- int cb_size = (1 << (log2_cb_size)) >> 1;
- int x1 = x0 + cb_size;
- int y1 = y0 + cb_size;
more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
@@ -1661,20 +1666,20 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int log2_cb_size,
return hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1);
}
if (more_data)
- return ((x1 + cb_size) < s->sps->width ||
- (y1 + cb_size) < s->sps->height);
+ return ((x1 + cb_size_split) < s->sps->width ||
+ (y1 + cb_size_split) < s->sps->height);
else
return 0;
} else {
ret = hls_coding_unit(s, x0, y0, log2_cb_size);
if (ret < 0)
return ret;
- if ((!((x0 + (1 << log2_cb_size)) %
+ if ((!((x0 + cb_size) %
(1 << (s->sps->log2_ctb_size))) ||
- (x0 + (1 << log2_cb_size) >= s->sps->width)) &&
- (!((y0 + (1 << log2_cb_size)) %
+ (x0 + cb_size >= s->sps->width)) &&
+ (!((y0 + cb_size) %
(1 << (s->sps->log2_ctb_size))) ||
- (y0 + (1 << log2_cb_size) >= s->sps->height))) {
+ (y0 + cb_size >= s->sps->height))) {
int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s);
return !end_of_slice_flag;
} else {
@@ -1685,10 +1690,6 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0, int log2_cb_size,
return 0;
}
-/**
- * 7.3.4
- */
-
static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_addr_ts)
{
HEVCLocalContext *lc = s->HEVClc;
@@ -1703,7 +1704,6 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_a
s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
-
if (s->pps->entropy_coding_sync_enabled_flag) {
if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
lc->first_qp_group = 1;
@@ -1712,7 +1712,7 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_a
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->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->pps->column_width[idxX] << s->sps->log2_ctb_size);
lc->first_qp_group = 1;
}
} else {
@@ -1722,19 +1722,19 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_a
lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->sps->height);
if (s->pps->tiles_enabled_flag) {
- tile_left_boundary = ((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]]));
+ tile_left_boundary = ((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]]));
slice_left_boundary = ((x_ctb > 0) &&
(s->tab_slice_address[ctb_addr_rs] == s->tab_slice_address[ctb_addr_rs - 1]));
- tile_up_boundary = ((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]]));
+ tile_up_boundary = ((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]]));
slice_up_boundary = ((y_ctb > 0) &&
(s->tab_slice_address[ctb_addr_rs] == s->tab_slice_address[ctb_addr_rs - s->sps->ctb_width]));
} else {
- tile_left_boundary =
- tile_up_boundary = 1;
+ tile_left_boundary =
+ tile_up_boundary = 1;
slice_left_boundary = ctb_addr_in_slice > 0;
- slice_up_boundary = ctb_addr_in_slice >= s->sps->ctb_width;
+ slice_up_boundary = ctb_addr_in_slice >= s->sps->ctb_width;
}
lc->slice_or_tiles_left_boundary = (!slice_left_boundary) + (!tile_left_boundary << 1);
lc->slice_or_tiles_up_boundary = (!slice_up_boundary + (!tile_up_boundary << 1));
@@ -1969,31 +1969,29 @@ static int hls_nal_unit(HEVCContext *s)
"nal_unit_type: %d, nuh_layer_id: %dtemporal_id: %d\n",
s->nal_unit_type, nuh_layer_id, s->temporal_id);
- return (nuh_layer_id == 0);
+ return nuh_layer_id == 0;
}
static void restore_tqb_pixels(HEVCContext *s)
{
- int pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
- int pic_height_in_min_pu = s->sps->height >> s->sps->log2_min_pu_size;
- int min_pu_size = 1 << s->sps->log2_min_pu_size;
+ int min_pu_size = 1 << s->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 < pic_height_in_min_pu; y++) {
- for (x = 0; x < pic_width_in_min_pu; x++) {
- if (s->is_pcm[y*pic_width_in_min_pu+x]) {
+ 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 n;
- int len = min_pu_size >> hshift;
+ 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)];
- for (n = 0;n < (min_pu_size >> vshift); n++) {
- memcpy(dst,src,len);
- src += stride;
- dst += stride;
+ for (n = 0; n < (min_pu_size >> vshift); n++) {
+ memcpy(dst, src, len);
+ src += stride;
+ dst += stride;
}
}
}
@@ -2004,22 +2002,18 @@ static void restore_tqb_pixels(HEVCContext *s)
static int hevc_frame_start(HEVCContext *s)
{
HEVCLocalContext *lc = s->HEVClc;
- int pic_width_in_min_pu = s->sps->width >> s->sps->log2_min_pu_size;
- int pic_height_in_min_pu = s->sps->height >> s->sps->log2_min_pu_size;
- int pic_width_in_min_tu = s->sps->width >> s->sps->log2_min_tb_size;
- int pic_height_in_min_tu = s->sps->height >> s->sps->log2_min_tb_size;
int ret;
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, pic_width_in_min_tu * pic_height_in_min_tu);
- memset(s->is_pcm, 0, pic_width_in_min_pu * pic_height_in_min_pu);
+ 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);
lc->start_of_tiles_x = 0;
s->is_decoded = 0;
if (s->pps->tiles_enabled_flag)
- lc->end_of_tiles_x = s->pps->column_width[0] << s->sps->log2_ctb_size;
+ lc->end_of_tiles_x = s->pps->column_width[0] << s->sps->log2_ctb_size;
ret = ff_hevc_set_new_ref(s, s->sps->sao_enabled ? &s->sao_frame : &s->frame,
s->poc);
@@ -2057,7 +2051,7 @@ fail:
static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
{
HEVCLocalContext *lc = s->HEVClc;
- GetBitContext *gb = &lc->gb;
+ GetBitContext *gb = &lc->gb;
int ctb_addr_ts;
int ret;
@@ -2068,7 +2062,7 @@ static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
ret = hls_nal_unit(s);
if (ret < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\n",
- s->nal_unit_type);
+ s->nal_unit_type);
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return ret;
return 0;
@@ -2118,10 +2112,7 @@ static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
return ret;
if (s->max_ra == INT_MAX) {
- if (s->nal_unit_type == NAL_CRA_NUT ||
- s->nal_unit_type == NAL_BLA_W_LP ||
- s->nal_unit_type == NAL_BLA_N_LP ||
- s->nal_unit_type == NAL_BLA_W_RADL) {
+ if (s->nal_unit_type == NAL_CRA_NUT || IS_BLA(s)) {
s->max_ra = s->poc;
} else {
if (IS_IDR(s))
@@ -2151,8 +2142,8 @@ static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
s->sh.slice_type != I_SLICE) {
ret = ff_hevc_slice_rpl(s);
if (ret < 0) {
- av_log(s->avctx, AV_LOG_WARNING, "Error constructing the reference "
- "lists for the current slice.\n");
+ av_log(s->avctx, AV_LOG_WARNING,
+ "Error constructing the reference lists for the current slice.\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return ret;
}
@@ -2183,7 +2174,8 @@ static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
case NAL_FD_NUT:
break;
default:
- av_log(s->avctx, AV_LOG_INFO, "Skipping NAL unit %d\n", s->nal_unit_type);
+ av_log(s->avctx, AV_LOG_INFO,
+ "Skipping NAL unit %d\n", s->nal_unit_type);
}
return 0;
@@ -2265,9 +2257,9 @@ int ff_hevc_extract_rbsp(HEVCContext *s, const uint8_t *src, int length,
dst[di++] = src[si++];
} else if (src[si] == 0 && src[si + 1] == 0) {
if (src[si + 2] == 3) { // escape
- dst[di++] = 0;
- dst[di++] = 0;
- si += 3;
+ dst[di++] = 0;
+ dst[di++] = 0;
+ si += 3;
s->skipped_bytes++;
if (s->skipped_bytes_pos_size < s->skipped_bytes) {
@@ -2380,7 +2372,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
goto fail;
hls_nal_unit(s);
- if (s->nal_unit_type == NAL_EOS_NUT || s->nal_unit_type == NAL_EOB_NUT)
+ if (s->nal_unit_type == NAL_EOS_NUT ||
+ s->nal_unit_type == NAL_EOB_NUT)
s->eos = 1;
buf += consumed;
@@ -2395,7 +2388,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
ret = decode_nal_unit(s, s->nals[i].data, s->nals[i].size);
if (ret < 0) {
- av_log(s->avctx, AV_LOG_WARNING, "Error parsing NAL unit #%d.\n", i);
+ av_log(s->avctx, AV_LOG_WARNING,
+ "Error parsing NAL unit #%d.\n", i);
if (s->avctx->err_recognition & AV_EF_EXPLODE)
goto fail;
}
@@ -2762,7 +2756,8 @@ static int hevc_decode_extradata(HEVCContext *s)
// +2 for the nal size field
int nalsize = bytestream2_peek_be16(&gb) + 2;
if (bytestream2_get_bytes_left(&gb) < nalsize) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid NAL unit size in extradata.\n");
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Invalid NAL unit size in extradata.\n");
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 937d75bb94..0fa7afa767 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -656,15 +656,15 @@ 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->width >> s->sps->log2_min_cb_size;
+ int min_cb_width = s->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);
if (s->HEVClc->ctb_left_flag || x0b)
- inc = SAMPLE_CTB(s->skip_flag, x_cb-1, y_cb);
+ inc = !!SAMPLE_CTB(s->skip_flag, x_cb-1, y_cb);
if (s->HEVClc->ctb_up_flag || y0b)
- inc += SAMPLE_CTB(s->skip_flag, x_cb, y_cb-1);
+ inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb-1);
return GET_CABAC(elem_offset[SKIP_FLAG] + inc);
}