48 const uint8_t ff_hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 };
90 int log2_min_cb_size =
sps->log2_min_cb_size;
93 int pic_size_in_ctb = ((
width >> log2_min_cb_size) + 1) *
94 ((
height >> log2_min_cb_size) + 1);
95 int ctb_count =
sps->ctb_width *
sps->ctb_height;
96 int min_pu_size =
sps->min_pu_width *
sps->min_pu_height;
98 s->bs_width = (
width >> 2) + 1;
99 s->bs_height = (
height >> 2) + 1;
103 if (!
s->sao || !
s->deblock)
108 if (!
s->skip_flag || !
s->tab_ct_depth)
114 if (!
s->tab_ipm || !
s->cbf_luma || !
s->is_pcm)
119 sizeof(*
s->tab_slice_address));
121 sizeof(*
s->qp_y_tab));
122 if (!
s->qp_y_tab || !
s->filter_slice_edges || !
s->tab_slice_address)
127 if (!
s->horizontal_bs || !
s->vertical_bs)
134 if (!
s->tab_mvf_pool || !
s->rpl_tab_pool)
148 uint8_t luma_weight_l0_flag[16];
149 uint8_t chroma_weight_l0_flag[16];
150 uint8_t luma_weight_l1_flag[16];
151 uint8_t chroma_weight_l1_flag[16];
152 int luma_log2_weight_denom;
155 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
156 av_log(
s->avctx,
AV_LOG_ERROR,
"luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
159 s->sh.luma_log2_weight_denom =
av_clip_uintp2(luma_log2_weight_denom, 3);
160 if (
s->ps.sps->chroma_format_idc != 0) {
161 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)
get_se_golomb(gb);
162 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
163 av_log(
s->avctx,
AV_LOG_ERROR,
"chroma_log2_weight_denom %"PRId64
" is invalid\n", chroma_log2_weight_denom);
166 s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
169 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++) {
171 if (!luma_weight_l0_flag[
i]) {
172 s->sh.luma_weight_l0[
i] = 1 <<
s->sh.luma_log2_weight_denom;
173 s->sh.luma_offset_l0[
i] = 0;
176 if (
s->ps.sps->chroma_format_idc != 0) {
177 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++)
180 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++)
181 chroma_weight_l0_flag[
i] = 0;
183 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++) {
184 if (luma_weight_l0_flag[
i]) {
186 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
188 s->sh.luma_weight_l0[
i] = (1 <<
s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
191 if (chroma_weight_l0_flag[
i]) {
192 for (j = 0; j < 2; j++) {
196 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
197 || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
201 s->sh.chroma_weight_l0[
i][j] = (1 <<
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
202 s->sh.chroma_offset_l0[
i][j] =
av_clip((delta_chroma_offset_l0 - ((128 *
s->sh.chroma_weight_l0[
i][j])
203 >>
s->sh.chroma_log2_weight_denom) + 128), -128, 127);
206 s->sh.chroma_weight_l0[
i][0] = 1 <<
s->sh.chroma_log2_weight_denom;
207 s->sh.chroma_offset_l0[
i][0] = 0;
208 s->sh.chroma_weight_l0[
i][1] = 1 <<
s->sh.chroma_log2_weight_denom;
209 s->sh.chroma_offset_l0[
i][1] = 0;
213 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++) {
215 if (!luma_weight_l1_flag[
i]) {
216 s->sh.luma_weight_l1[
i] = 1 <<
s->sh.luma_log2_weight_denom;
217 s->sh.luma_offset_l1[
i] = 0;
220 if (
s->ps.sps->chroma_format_idc != 0) {
221 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++)
224 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++)
225 chroma_weight_l1_flag[
i] = 0;
227 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++) {
228 if (luma_weight_l1_flag[
i]) {
230 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
232 s->sh.luma_weight_l1[
i] = (1 <<
s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
235 if (chroma_weight_l1_flag[
i]) {
236 for (j = 0; j < 2; j++) {
240 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
241 || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
245 s->sh.chroma_weight_l1[
i][j] = (1 <<
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
246 s->sh.chroma_offset_l1[
i][j] =
av_clip((delta_chroma_offset_l1 - ((128 *
s->sh.chroma_weight_l1[
i][j])
247 >>
s->sh.chroma_log2_weight_denom) + 128), -128, 127);
250 s->sh.chroma_weight_l1[
i][0] = 1 <<
s->sh.chroma_log2_weight_denom;
251 s->sh.chroma_offset_l1[
i][0] = 0;
252 s->sh.chroma_weight_l1[
i][1] = 1 <<
s->sh.chroma_log2_weight_denom;
253 s->sh.chroma_offset_l1[
i][1] = 0;
263 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
264 int prev_delta_msb = 0;
265 unsigned int nb_sps = 0, nb_sh;
269 if (!
sps->long_term_ref_pics_present_flag)
272 if (
sps->num_long_term_ref_pics_sps > 0)
276 if (nb_sps >
sps->num_long_term_ref_pics_sps)
288 if (
sps->num_long_term_ref_pics_sps > 1)
291 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
292 rps->
used[
i] =
sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
303 if (
i &&
i != nb_sps)
304 delta += prev_delta_msb;
306 poc = rps->
poc[
i] +
s->poc -
delta * max_poc_lsb -
s->sh.pic_order_cnt_lsb;
310 prev_delta_msb =
delta;
323 unsigned int num = 0, den = 0;
328 avctx->
width =
sps->width - ow->left_offset - ow->right_offset;
329 avctx->
height =
sps->height - ow->top_offset - ow->bottom_offset;
331 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
332 avctx->
level =
sps->ptl.general_ptl.level_idc;
336 if (
sps->vui.video_signal_type_present_flag)
342 if (
sps->vui.colour_description_present_flag) {
353 if (
sps->chroma_format_idc == 1) {
354 if (
sps->vui.chroma_loc_info_present_flag) {
355 if (
sps->vui.chroma_sample_loc_type_top_field <= 5)
361 if (
vps->vps_timing_info_present_flag) {
362 num =
vps->vps_num_units_in_tick;
363 den =
vps->vps_time_scale;
364 }
else if (
sps->vui.vui_timing_info_present_flag) {
365 num =
sps->vui.vui_num_units_in_tick;
366 den =
sps->vui.vui_time_scale;
369 if (num != 0 && den != 0)
378 if (
s->sei.a53_caption.buf_ref)
381 if (
s->sei.alternative_transfer.present &&
384 avctx->
color_trc =
s->sei.alternative_transfer.preferred_transfer_characteristics;
392 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
393 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
394 CONFIG_HEVC_NVDEC_HWACCEL + \
395 CONFIG_HEVC_VAAPI_HWACCEL + \
396 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
397 CONFIG_HEVC_VDPAU_HWACCEL)
400 switch (
sps->pix_fmt) {
403 #if CONFIG_HEVC_DXVA2_HWACCEL
406 #if CONFIG_HEVC_D3D11VA_HWACCEL
410 #if CONFIG_HEVC_VAAPI_HWACCEL
413 #if CONFIG_HEVC_VDPAU_HWACCEL
416 #if CONFIG_HEVC_NVDEC_HWACCEL
419 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
424 #if CONFIG_HEVC_DXVA2_HWACCEL
427 #if CONFIG_HEVC_D3D11VA_HWACCEL
431 #if CONFIG_HEVC_VAAPI_HWACCEL
434 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
437 #if CONFIG_HEVC_VDPAU_HWACCEL
440 #if CONFIG_HEVC_NVDEC_HWACCEL
445 #if CONFIG_HEVC_VDPAU_HWACCEL
448 #if CONFIG_HEVC_NVDEC_HWACCEL
454 #if CONFIG_HEVC_VAAPI_HWACCEL
461 #if CONFIG_HEVC_VDPAU_HWACCEL
464 #if CONFIG_HEVC_NVDEC_HWACCEL
470 *fmt++ =
sps->pix_fmt;
500 for (
i = 0;
i < 3;
i++) {
505 if (
sps->sao_enabled && !
s->avctx->hwaccel) {
506 int c_count = (
sps->chroma_format_idc != 0) ? 3 : 1;
509 for(c_idx = 0; c_idx < c_count; c_idx++) {
510 int w =
sps->width >>
sps->hshift[c_idx];
511 int h =
sps->height >>
sps->vshift[c_idx];
512 s->sao_pixel_buffer_h[c_idx] =
515 s->sao_pixel_buffer_v[c_idx] =
518 if (!
s->sao_pixel_buffer_h[c_idx] ||
519 !
s->sao_pixel_buffer_v[c_idx])
525 s->ps.vps = (
HEVCVPS*)
s->ps.vps_list[
s->ps.sps->vps_id]->data;
531 for (
i = 0;
i < 3;
i++) {
548 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
553 s->seq_decode = (
s->seq_decode + 1) & 0xff;
576 if (
s->ps.sps != (
HEVCSPS*)
s->ps.sps_list[
s->ps.pps->sps_id]->data) {
578 const HEVCSPS *last_sps =
s->ps.sps;
582 if (
sps->width != last_sps->width ||
sps->height != last_sps->height ||
583 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering !=
584 last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
598 s->seq_decode = (
s->seq_decode + 1) & 0xff;
608 int slice_address_length;
610 if (
s->ps.pps->dependent_slice_segments_enabled_flag)
614 s->ps.sps->ctb_height);
618 "Invalid slice segment address: %u.\n",
630 s->slice_initialized = 0;
634 s->slice_initialized = 0;
636 for (
i = 0;
i <
s->ps.pps->num_extra_slice_header_bits;
i++)
654 if (
s->ps.pps->output_flag_present_flag)
657 if (
s->ps.sps->separate_colour_plane_flag)
667 "Ignoring POC change between slices: %d -> %d\n",
s->poc, poc);
683 int numbits, rps_idx;
685 if (!
s->ps.sps->nb_st_rps) {
691 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
705 if (
s->ps.sps->sps_temporal_mvp_enabled_flag)
710 s->sh.short_term_rps =
NULL;
725 if (
s->ps.sps->sao_enabled) {
727 if (
s->ps.sps->chroma_format_idc) {
741 sh->
nb_refs[
L0] =
s->ps.pps->num_ref_idx_l0_default_active;
743 sh->
nb_refs[
L1] =
s->ps.pps->num_ref_idx_l1_default_active;
764 if (
s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
782 if (
s->ps.pps->cabac_init_present_flag)
797 "Invalid collocated_ref_idx: %d.\n",
814 "Invalid number of merging MVP candidates: %d.\n",
822 if (
s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
835 if (
s->ps.pps->chroma_qp_offset_list_enabled_flag)
840 if (
s->ps.pps->deblocking_filter_control_present_flag) {
841 int deblocking_filter_override_flag = 0;
843 if (
s->ps.pps->deblocking_filter_override_enabled_flag)
844 deblocking_filter_override_flag =
get_bits1(gb);
846 if (deblocking_filter_override_flag) {
851 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
852 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
854 "Invalid deblock filter offsets: %d, %d\n",
855 beta_offset_div2, tc_offset_div2);
872 if (
s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
880 }
else if (!
s->slice_initialized) {
886 if (
s->ps.pps->tiles_enabled_flag ||
s->ps.pps->entropy_coding_sync_enabled_flag) {
890 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
898 if (offset_len < 1 || offset_len > 32) {
919 if (
s->threads_number > 1 && (
s->ps.pps->num_tile_rows > 1 ||
s->ps.pps->num_tile_columns > 1)) {
920 s->enable_parallel_tiles = 0;
921 s->threads_number = 1;
923 s->enable_parallel_tiles = 0;
925 s->enable_parallel_tiles = 0;
928 if (
s->ps.pps->slice_header_extension_present_flag) {
934 for (
i = 0;
i < length;
i++)
941 sh->
slice_qp < -
s->ps.sps->qp_bd_offset) {
943 "The slice_qp %d is outside the valid range "
946 -
s->ps.sps->qp_bd_offset);
952 if (!
s->sh.slice_ctb_addr_rs &&
s->sh.dependent_slice_segment_flag) {
963 s->HEVClc->first_qp_group = !
s->sh.dependent_slice_segment_flag;
965 if (!
s->ps.pps->cu_qp_delta_enabled_flag)
966 s->HEVClc->qp_y =
s->sh.slice_qp;
968 s->slice_initialized = 1;
969 s->HEVClc->tu.cu_qp_offset_cb = 0;
970 s->HEVClc->tu.cu_qp_offset_cr = 0;
975 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
977 #define SET_SAO(elem, value) \
979 if (!sao_merge_up_flag && !sao_merge_left_flag) \
981 else if (sao_merge_left_flag) \
982 sao->elem = CTB(s->sao, rx-1, ry).elem; \
983 else if (sao_merge_up_flag) \
984 sao->elem = CTB(s->sao, rx, ry-1).elem; \
992 int sao_merge_left_flag = 0;
993 int sao_merge_up_flag = 0;
997 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
998 s->sh.slice_sample_adaptive_offset_flag[1]) {
1003 if (ry > 0 && !sao_merge_left_flag) {
1009 for (c_idx = 0; c_idx < (
s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
1010 int log2_sao_offset_scale = c_idx == 0 ?
s->ps.pps->log2_sao_offset_scale_luma :
1011 s->ps.pps->log2_sao_offset_scale_chroma;
1013 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1028 for (
i = 0;
i < 4;
i++)
1032 for (
i = 0;
i < 4;
i++) {
1041 }
else if (c_idx != 2) {
1047 for (
i = 0;
i < 4;
i++) {
1055 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1067 if (log2_res_scale_abs_plus1 != 0) {
1070 (1 - 2 * res_scale_sign_flag);
1080 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1081 int log2_cb_size,
int log2_trafo_size,
1082 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1085 const int log2_trafo_size_c = log2_trafo_size -
s->ps.sps->hshift[1];
1089 int trafo_size = 1 << log2_trafo_size;
1092 s->hpc.intra_pred[log2_trafo_size - 2](
s, x0, y0, 0);
1095 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1096 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1099 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1100 (
s->ps.sps->chroma_format_idc == 2 &&
1101 (cbf_cb[1] || cbf_cr[1]));
1113 "The cu_qp_delta %d is outside the valid range "
1116 -(26 +
s->ps.sps->qp_bd_offset / 2),
1117 (25 +
s->ps.sps->qp_bd_offset / 2));
1124 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1127 if (cu_chroma_qp_offset_flag) {
1128 int cu_chroma_qp_offset_idx = 0;
1129 if (
s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
1132 "cu_chroma_qp_offset_idx not yet tested.\n");
1165 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1166 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1167 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1168 lc->
tu.
cross_pf = (
s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
1175 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1178 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 1);
1182 log2_trafo_size_c, scan_idx_c, 1);
1185 ptrdiff_t
stride =
s->frame->linesize[1];
1186 int hshift =
s->ps.sps->hshift[1];
1187 int vshift =
s->ps.sps->vshift[1];
1190 int size = 1 << log2_trafo_size_c;
1193 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1197 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1204 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1207 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 2);
1211 log2_trafo_size_c, scan_idx_c, 2);
1214 ptrdiff_t
stride =
s->frame->linesize[2];
1215 int hshift =
s->ps.sps->hshift[2];
1216 int vshift =
s->ps.sps->vshift[2];
1219 int size = 1 << log2_trafo_size_c;
1222 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1226 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1229 }
else if (
s->ps.sps->chroma_format_idc && blk_idx == 3) {
1230 int trafo_size_h = 1 << (log2_trafo_size + 1);
1231 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1232 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1235 trafo_size_h, trafo_size_v);
1236 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 1);
1240 log2_trafo_size, scan_idx_c, 1);
1242 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1245 trafo_size_h, trafo_size_v);
1246 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 2);
1250 log2_trafo_size, scan_idx_c, 2);
1254 if (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3) {
1255 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1256 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1258 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 1);
1259 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 2);
1260 if (
s->ps.sps->chroma_format_idc == 2) {
1262 trafo_size_h, trafo_size_v);
1263 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 1);
1264 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 2);
1266 }
else if (blk_idx == 3) {
1267 int trafo_size_h = 1 << (log2_trafo_size + 1);
1268 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1270 trafo_size_h, trafo_size_v);
1271 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 1);
1272 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 2);
1273 if (
s->ps.sps->chroma_format_idc == 2) {
1275 trafo_size_h, trafo_size_v);
1276 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 1);
1277 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 2);
1287 int cb_size = 1 << log2_cb_size;
1288 int log2_min_pu_size =
s->ps.sps->log2_min_pu_size;
1290 int min_pu_width =
s->ps.sps->min_pu_width;
1291 int x_end =
FFMIN(x0 + cb_size,
s->ps.sps->width);
1292 int y_end =
FFMIN(y0 + cb_size,
s->ps.sps->height);
1295 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1296 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1297 s->is_pcm[
i + j * min_pu_width] = 2;
1301 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1302 int log2_cb_size,
int log2_trafo_size,
1303 int trafo_depth,
int blk_idx,
1304 const int *base_cbf_cb,
const int *base_cbf_cr)
1312 cbf_cb[0] = base_cbf_cb[0];
1313 cbf_cb[1] = base_cbf_cb[1];
1314 cbf_cr[0] = base_cbf_cr[0];
1315 cbf_cr[1] = base_cbf_cr[1];
1318 if (trafo_depth == 1) {
1320 if (
s->ps.sps->chroma_format_idc == 3) {
1334 if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
1335 log2_trafo_size >
s->ps.sps->log2_min_tb_size &&
1336 trafo_depth < lc->cu.max_trafo_depth &&
1340 int inter_split =
s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
1345 split_transform_flag = log2_trafo_size >
s->ps.sps->log2_max_trafo_size ||
1350 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1351 if (trafo_depth == 0 || cbf_cb[0]) {
1353 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1358 if (trafo_depth == 0 || cbf_cr[0]) {
1360 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1366 if (split_transform_flag) {
1367 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1368 const int x1 = x0 + trafo_size_split;
1369 const int y1 = y0 + trafo_size_split;
1371 #define SUBDIVIDE(x, y, idx) \
1373 ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1374 log2_trafo_size - 1, trafo_depth + 1, idx, \
1387 int min_tu_size = 1 <<
s->ps.sps->log2_min_tb_size;
1388 int log2_min_tu_size =
s->ps.sps->log2_min_tb_size;
1389 int min_tu_width =
s->ps.sps->min_tb_width;
1393 cbf_cb[0] || cbf_cr[0] ||
1394 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1399 log2_cb_size, log2_trafo_size,
1400 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1406 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1407 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1408 int x_tu = (x0 + j) >> log2_min_tu_size;
1409 int y_tu = (y0 +
i) >> log2_min_tu_size;
1410 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1413 if (!
s->sh.disable_deblocking_filter_flag) {
1415 if (
s->ps.pps->transquant_bypass_enable_flag &&
1427 int cb_size = 1 << log2_cb_size;
1428 ptrdiff_t stride0 =
s->frame->linesize[0];
1429 ptrdiff_t stride1 =
s->frame->linesize[1];
1430 ptrdiff_t stride2 =
s->frame->linesize[2];
1431 uint8_t *dst0 = &
s->frame->data[0][y0 * stride0 + (x0 <<
s->ps.sps->pixel_shift)];
1432 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)];
1433 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)];
1435 int length = cb_size * cb_size *
s->ps.sps->pcm.bit_depth +
1436 (((cb_size >>
s->ps.sps->hshift[1]) * (cb_size >>
s->ps.sps->vshift[1])) +
1437 ((cb_size >>
s->ps.sps->hshift[2]) * (cb_size >>
s->ps.sps->vshift[2]))) *
1438 s->ps.sps->pcm.bit_depth_chroma;
1442 if (!
s->sh.disable_deblocking_filter_flag)
1449 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
s->ps.sps->pcm.bit_depth);
1450 if (
s->ps.sps->chroma_format_idc) {
1451 s->hevcdsp.put_pcm(dst1, stride1,
1452 cb_size >>
s->ps.sps->hshift[1],
1453 cb_size >>
s->ps.sps->vshift[1],
1454 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1455 s->hevcdsp.put_pcm(dst2, stride2,
1456 cb_size >>
s->ps.sps->hshift[2],
1457 cb_size >>
s->ps.sps->vshift[2],
1458 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1482 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1486 ptrdiff_t srcstride =
ref->linesize[0];
1487 int pic_width =
s->ps.sps->width;
1488 int pic_height =
s->ps.sps->height;
1491 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1492 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1495 x_off +=
mv->x >> 2;
1496 y_off +=
mv->y >> 2;
1497 src += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1507 edge_emu_stride, srcstride,
1511 pic_width, pic_height);
1513 srcstride = edge_emu_stride;
1517 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1518 block_h, mx, my, block_w);
1520 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1521 block_h,
s->sh.luma_log2_weight_denom,
1522 luma_weight, luma_offset, mx, my, block_w);
1542 AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1543 int block_w,
int block_h,
AVFrame *ref1,
const Mv *mv1,
struct MvField *current_mv)
1546 ptrdiff_t src0stride = ref0->
linesize[0];
1547 ptrdiff_t src1stride = ref1->
linesize[0];
1548 int pic_width =
s->ps.sps->width;
1549 int pic_height =
s->ps.sps->height;
1550 int mx0 = mv0->
x & 3;
1551 int my0 = mv0->
y & 3;
1552 int mx1 = mv1->
x & 3;
1553 int my1 = mv1->
y & 3;
1554 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1555 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1556 int x_off0 = x_off + (mv0->
x >> 2);
1557 int y_off0 = y_off + (mv0->
y >> 2);
1558 int x_off1 = x_off + (mv1->
x >> 2);
1559 int y_off1 = y_off + (mv1->
y >> 2);
1562 uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1563 uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1573 edge_emu_stride, src0stride,
1577 pic_width, pic_height);
1579 src0stride = edge_emu_stride;
1590 edge_emu_stride, src1stride,
1594 pic_width, pic_height);
1596 src1stride = edge_emu_stride;
1599 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1600 block_h, mx0, my0, block_w);
1602 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1603 block_h, mx1, my1, block_w);
1605 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1606 block_h,
s->sh.luma_log2_weight_denom,
1607 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1608 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1609 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1610 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1633 ptrdiff_t dststride,
uint8_t *
src0, ptrdiff_t srcstride,
int reflist,
1634 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1637 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1638 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1639 const Mv *
mv = ¤t_mv->
mv[reflist];
1640 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1641 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1643 int hshift =
s->ps.sps->hshift[1];
1644 int vshift =
s->ps.sps->vshift[1];
1647 intptr_t _mx = mx << (1 - hshift);
1648 intptr_t _my = my << (1 - vshift);
1650 x_off +=
mv->x >> (2 + hshift);
1651 y_off +=
mv->y >> (2 + vshift);
1652 src0 += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1660 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1662 edge_emu_stride, srcstride,
1666 pic_width, pic_height);
1669 srcstride = edge_emu_stride;
1672 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1673 block_h, _mx, _my, block_w);
1675 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1676 block_h,
s->sh.chroma_log2_weight_denom,
1677 chroma_weight, chroma_offset, _mx, _my, block_w);
1698 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int cidx)
1703 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1704 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1705 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1706 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1707 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1708 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1709 Mv *mv0 = ¤t_mv->
mv[0];
1710 Mv *mv1 = ¤t_mv->
mv[1];
1711 int hshift =
s->ps.sps->hshift[1];
1712 int vshift =
s->ps.sps->vshift[1];
1718 intptr_t _mx0 = mx0 << (1 - hshift);
1719 intptr_t _my0 = my0 << (1 - vshift);
1720 intptr_t _mx1 = mx1 << (1 - hshift);
1721 intptr_t _my1 = my1 << (1 - vshift);
1723 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1724 int y_off0 = y_off + (mv0->
y >> (2 + vshift));
1725 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1726 int y_off1 = y_off + (mv1->
y >> (2 + vshift));
1728 src1 += y_off0 * src1stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1729 src2 += y_off1 * src2stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1737 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1740 edge_emu_stride, src1stride,
1744 pic_width, pic_height);
1747 src1stride = edge_emu_stride;
1756 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1759 edge_emu_stride, src2stride,
1763 pic_width, pic_height);
1766 src2stride = edge_emu_stride;
1769 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
1770 block_h, _mx0, _my0, block_w);
1772 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1773 src2, src2stride, lc->
tmp,
1774 block_h, _mx1, _my1, block_w);
1776 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1777 src2, src2stride, lc->
tmp,
1779 s->sh.chroma_log2_weight_denom,
1780 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
1781 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
1782 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
1783 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
1784 _mx1, _my1, block_w);
1798 int nPbH,
int log2_cb_size,
int part_idx,
1810 if (inter_pred_idc !=
PRED_L1) {
1811 if (
s->sh.nb_refs[
L0])
1818 part_idx, merge_idx,
mv, mvp_flag, 0);
1823 if (inter_pred_idc !=
PRED_L0) {
1824 if (
s->sh.nb_refs[
L1])
1827 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
1836 part_idx, merge_idx,
mv, mvp_flag, 1);
1844 int log2_cb_size,
int partIdx,
int idx)
1846 #define POS(c_idx, x, y) \
1847 &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1848 (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
1851 struct MvField current_mv = {{{ 0 }}};
1853 int min_pu_width =
s->ps.sps->min_pu_width;
1855 MvField *tab_mvf =
s->ref->tab_mvf;
1861 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
1862 int min_cb_width =
s->ps.sps->min_cb_width;
1863 int x_cb = x0 >> log2_min_cb_size;
1864 int y_cb = y0 >> log2_min_cb_size;
1868 int skip_flag =
SAMPLE_CTB(
s->skip_flag, x_cb, y_cb);
1874 if (
s->sh.max_num_merge_cand > 1)
1880 partIdx, merge_idx, ¤t_mv);
1883 partIdx, merge_idx, ¤t_mv);
1886 x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1887 y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1889 for (j = 0; j < nPbH >>
s->ps.sps->log2_min_pu_size; j++)
1890 for (
i = 0; i < nPbW >>
s->ps.sps->log2_min_pu_size;
i++)
1891 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
1894 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
1900 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
1907 int x0_c = x0 >>
s->ps.sps->hshift[1];
1908 int y0_c = y0 >>
s->ps.sps->vshift[1];
1909 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1910 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1913 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1914 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
1915 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
1917 if (
s->ps.sps->chroma_format_idc) {
1919 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1920 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
1922 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1923 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
1926 int x0_c = x0 >>
s->ps.sps->hshift[1];
1927 int y0_c = y0 >>
s->ps.sps->vshift[1];
1928 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1929 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1932 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
1933 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
1934 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
1936 if (
s->ps.sps->chroma_format_idc) {
1937 chroma_mc_uni(
s, dst1,
s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1],
1938 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1939 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
1941 chroma_mc_uni(
s, dst2,
s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2],
1942 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1943 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
1946 int x0_c = x0 >>
s->ps.sps->hshift[1];
1947 int y0_c = y0 >>
s->ps.sps->vshift[1];
1948 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1949 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1952 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1953 ref1->frame, ¤t_mv.
mv[1], ¤t_mv);
1955 if (
s->ps.sps->chroma_format_idc) {
1957 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
1960 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
1969 int prev_intra_luma_pred_flag)
1972 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1973 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1974 int min_pu_width =
s->ps.sps->min_pu_width;
1975 int size_in_pus = pu_size >>
s->ps.sps->log2_min_pu_size;
1980 s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] :
INTRA_DC;
1982 s->tab_ipm[y_pu * min_pu_width + x_pu - 1] :
INTRA_DC;
1984 int y_ctb = (y0 >> (
s->ps.sps->log2_ctb_size)) << (
s->ps.sps->log2_ctb_size);
1986 MvField *tab_mvf =
s->ref->tab_mvf;
1987 int intra_pred_mode;
1992 if ((y0 - 1) < y_ctb)
1995 if (cand_left == cand_up) {
1996 if (cand_left < 2) {
2001 candidate[0] = cand_left;
2002 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2003 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2006 candidate[0] = cand_left;
2007 candidate[1] = cand_up;
2017 if (prev_intra_luma_pred_flag) {
2018 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
2020 if (candidate[0] > candidate[1])
2022 if (candidate[0] > candidate[2])
2024 if (candidate[1] > candidate[2])
2028 for (
i = 0;
i < 3;
i++)
2029 if (intra_pred_mode >= candidate[
i])
2036 for (
i = 0;
i < size_in_pus;
i++) {
2037 memset(&
s->tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
2038 intra_pred_mode, size_in_pus);
2040 for (j = 0; j < size_in_pus; j++) {
2045 return intra_pred_mode;
2049 int log2_cb_size,
int ct_depth)
2051 int length = (1 << log2_cb_size) >>
s->ps.sps->log2_min_cb_size;
2052 int x_cb = x0 >>
s->ps.sps->log2_min_cb_size;
2053 int y_cb = y0 >>
s->ps.sps->log2_min_cb_size;
2056 for (y = 0; y < length; y++)
2057 memset(&
s->tab_ct_depth[(y_cb + y) *
s->ps.sps->min_cb_width + x_cb],
2062 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2063 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2069 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2070 uint8_t prev_intra_luma_pred_flag[4];
2072 int pb_size = (1 << log2_cb_size) >>
split;
2073 int side =
split + 1;
2077 for (
i = 0;
i < side;
i++)
2078 for (j = 0; j < side; j++)
2081 for (
i = 0;
i < side;
i++) {
2082 for (j = 0; j < side; j++) {
2083 if (prev_intra_luma_pred_flag[2 *
i + j])
2090 prev_intra_luma_pred_flag[2 *
i + j]);
2094 if (
s->ps.sps->chroma_format_idc == 3) {
2095 for (
i = 0;
i < side;
i++) {
2096 for (j = 0; j < side; j++) {
2098 if (chroma_mode != 4) {
2108 }
else if (
s->ps.sps->chroma_format_idc == 2) {
2111 if (chroma_mode != 4) {
2115 mode_idx = intra_chroma_table[chroma_mode];
2120 }
else if (
s->ps.sps->chroma_format_idc != 0) {
2122 if (chroma_mode != 4) {
2138 int pb_size = 1 << log2_cb_size;
2139 int size_in_pus = pb_size >>
s->ps.sps->log2_min_pu_size;
2140 int min_pu_width =
s->ps.sps->min_pu_width;
2141 MvField *tab_mvf =
s->ref->tab_mvf;
2142 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
2143 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
2146 if (size_in_pus == 0)
2148 for (j = 0; j < size_in_pus; j++)
2149 memset(&
s->tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2151 for (j = 0; j < size_in_pus; j++)
2152 for (k = 0; k < size_in_pus; k++)
2158 int cb_size = 1 << log2_cb_size;
2160 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
2161 int length = cb_size >> log2_min_cb_size;
2162 int min_cb_width =
s->ps.sps->min_cb_width;
2163 int x_cb = x0 >> log2_min_cb_size;
2164 int y_cb = y0 >> log2_min_cb_size;
2165 int idx = log2_cb_size - 2;
2166 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2176 for (x = 0; x < 4; x++)
2178 if (
s->ps.pps->transquant_bypass_enable_flag) {
2188 x = y_cb * min_cb_width + x_cb;
2189 for (y = 0; y < length; y++) {
2190 memset(&
s->skip_flag[x], skip_flag, length);
2195 x = y_cb * min_cb_width + x_cb;
2196 for (y = 0; y < length; y++) {
2197 memset(&
s->skip_flag[x], 0, length);
2206 if (!
s->sh.disable_deblocking_filter_flag)
2214 log2_cb_size ==
s->ps.sps->log2_min_cb_size) {
2222 log2_cb_size >=
s->ps.sps->pcm.log2_min_pcm_cb_size &&
2223 log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) {
2229 if (
s->ps.sps->pcm.loop_filter_disable_flag)
2261 hls_prediction_unit(
s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2265 hls_prediction_unit(
s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2269 hls_prediction_unit(
s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2270 hls_prediction_unit(
s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2271 hls_prediction_unit(
s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2277 int rqt_root_cbf = 1;
2284 const static int cbf[2] = { 0 };
2287 s->ps.sps->max_transform_hierarchy_depth_inter;
2290 log2_cb_size, 0, 0, cbf, cbf);
2294 if (!
s->sh.disable_deblocking_filter_flag)
2303 x = y_cb * min_cb_width + x_cb;
2304 for (y = 0; y < length; y++) {
2305 memset(&
s->qp_y_tab[x], lc->
qp_y, length);
2309 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2310 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2320 int log2_cb_size,
int cb_depth)
2323 const int cb_size = 1 << log2_cb_size;
2328 if (x0 + cb_size <= s->ps.sps->width &&
2329 y0 + cb_size <= s->ps.sps->height &&
2330 log2_cb_size >
s->ps.sps->log2_min_cb_size) {
2333 split_cu = (log2_cb_size >
s->ps.sps->log2_min_cb_size);
2335 if (
s->ps.pps->cu_qp_delta_enabled_flag &&
2336 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth) {
2341 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2342 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_chroma_qp_offset_depth) {
2347 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2348 const int cb_size_split = cb_size >> 1;
2349 const int x1 = x0 + cb_size_split;
2350 const int y1 = y0 + cb_size_split;
2358 if (more_data && x1 < s->ps.sps->width) {
2363 if (more_data && y1 < s->ps.sps->height) {
2368 if (more_data && x1 < s->ps.sps->width &&
2369 y1 < s->ps.sps->height) {
2375 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2376 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2380 return ((x1 + cb_size_split) <
s->ps.sps->width ||
2381 (y1 + cb_size_split) <
s->ps.sps->height);
2388 if ((!((x0 + cb_size) %
2389 (1 << (
s->ps.sps->log2_ctb_size))) ||
2390 (x0 + cb_size >=
s->ps.sps->width)) &&
2392 (1 << (
s->ps.sps->log2_ctb_size))) ||
2393 (y0 + cb_size >=
s->ps.sps->height))) {
2395 return !end_of_slice_flag;
2408 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2409 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2410 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2412 s->tab_slice_address[ctb_addr_rs] =
s->sh.slice_addr;
2414 if (
s->ps.pps->entropy_coding_sync_enabled_flag) {
2415 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2418 }
else if (
s->ps.pps->tiles_enabled_flag) {
2419 if (ctb_addr_ts &&
s->ps.pps->tile_id[ctb_addr_ts] !=
s->ps.pps->tile_id[ctb_addr_ts - 1]) {
2420 int idxX =
s->ps.pps->col_idxX[x_ctb >>
s->ps.sps->log2_ctb_size];
2421 lc->
end_of_tiles_x = x_ctb + (
s->ps.pps->column_width[idxX] <<
s->ps.sps->log2_ctb_size);
2431 if (
s->ps.pps->tiles_enabled_flag) {
2432 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]])
2434 if (x_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs - 1])
2436 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]])
2438 if (y_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs -
s->ps.sps->ctb_width])
2441 if (ctb_addr_in_slice <= 0)
2443 if (ctb_addr_in_slice < s->ps.sps->ctb_width)
2449 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]]));
2450 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]]));
2456 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2460 int ctb_addr_ts =
s->ps.pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2463 if (!ctb_addr_ts &&
s->sh.dependent_slice_segment_flag) {
2468 if (
s->sh.dependent_slice_segment_flag) {
2469 int prev_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2470 if (
s->tab_slice_address[prev_rs] !=
s->sh.slice_addr) {
2476 while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2477 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2479 x_ctb = (ctb_addr_rs % ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2480 y_ctb = (ctb_addr_rs / ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2485 s->tab_slice_address[ctb_addr_rs] = -1;
2489 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2491 s->deblock[ctb_addr_rs].beta_offset =
s->sh.beta_offset;
2492 s->deblock[ctb_addr_rs].tc_offset =
s->sh.tc_offset;
2493 s->filter_slice_edges[ctb_addr_rs] =
s->sh.slice_loop_filter_across_slices_enabled_flag;
2496 if (more_data < 0) {
2497 s->tab_slice_address[ctb_addr_rs] = -1;
2507 if (x_ctb + ctb_size >=
s->ps.sps->width &&
2508 y_ctb + ctb_size >=
s->ps.sps->height)
2529 int ctb_size = 1<<
s1->ps.sps->log2_ctb_size;
2531 int *ctb_row_p = input_ctb_row;
2532 int ctb_row = ctb_row_p[job];
2533 int ctb_addr_rs =
s1->sh.slice_ctb_addr_rs + ctb_row * ((
s1->ps.sps->width + ctb_size - 1) >>
s1->ps.sps->log2_ctb_size);
2534 int ctb_addr_ts =
s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2535 int thread = ctb_row %
s1->threads_number;
2538 s =
s1->sList[self_id];
2548 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2549 int x_ctb = (ctb_addr_rs %
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2550 int y_ctb = (ctb_addr_rs /
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2564 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2567 if (more_data < 0) {
2578 if (!more_data && (x_ctb+ctb_size) <
s->ps.sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2584 if ((x_ctb+ctb_size) >=
s->ps.sps->width && (y_ctb+ctb_size) >=
s->ps.sps->height ) {
2589 ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2592 if(x_ctb >=
s->ps.sps->width) {
2600 s->tab_slice_address[ctb_addr_rs] = -1;
2609 int length = nal->
size;
2614 int64_t startheader, cmpt = 0;
2623 if (
s->sh.slice_ctb_addr_rs +
s->sh.num_entry_point_offsets *
s->ps.sps->ctb_width >=
s->ps.sps->ctb_width *
s->ps.sps->ctb_height) {
2625 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2626 s->ps.sps->ctb_width,
s->ps.sps->ctb_height
2634 for (
i = 1;
i <
s->threads_number;
i++) {
2635 if (
s->sList[
i] &&
s->HEVClcList[
i])
2641 if (!
s->sList[
i] || !
s->HEVClcList[
i]) {
2646 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2651 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2658 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2659 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2660 for (j = 0, cmpt = 0, startheader =
offset
2661 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2667 s->sh.size[
i - 1] =
s->sh.entry_point_offset[
i] - cmpt;
2671 if (
s->sh.num_entry_point_offsets != 0) {
2672 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2678 s->sh.size[
s->sh.num_entry_point_offsets - 1] = length -
offset;
2679 s->sh.offset[
s->sh.num_entry_point_offsets - 1] =
offset;
2684 for (
i = 1;
i <
s->threads_number;
i++) {
2685 s->sList[
i]->HEVClc->first_qp_group = 1;
2686 s->sList[
i]->HEVClc->qp_y =
s->sList[0]->HEVClc->qp_y;
2688 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2694 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++) {
2699 if (
s->ps.pps->entropy_coding_sync_enabled_flag)
2702 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
2714 if (
s->sei.frame_packing.present &&
2715 s->sei.frame_packing.arrangement_type >= 3 &&
2716 s->sei.frame_packing.arrangement_type <= 5 &&
2717 s->sei.frame_packing.content_interpretation_type > 0 &&
2718 s->sei.frame_packing.content_interpretation_type < 3) {
2723 switch (
s->sei.frame_packing.arrangement_type) {
2725 if (
s->sei.frame_packing.quincunx_subsampling)
2738 if (
s->sei.frame_packing.content_interpretation_type == 2)
2741 if (
s->sei.frame_packing.arrangement_type == 5) {
2742 if (
s->sei.frame_packing.current_frame_is_frame0_flag)
2749 if (
s->sei.display_orientation.present &&
2750 (
s->sei.display_orientation.anticlockwise_rotation ||
2751 s->sei.display_orientation.hflip ||
s->sei.display_orientation.vflip)) {
2752 double angle =
s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16);
2761 s->sei.display_orientation.hflip,
2762 s->sei.display_orientation.vflip);
2767 if (
s->sei.mastering_display.present > 0 &&
2769 s->sei.mastering_display.present--;
2771 if (
s->sei.mastering_display.present) {
2773 const int mapping[3] = {2, 0, 1};
2774 const int chroma_den = 50000;
2775 const int luma_den = 10000;
2782 for (
i = 0;
i < 3;
i++) {
2783 const int j = mapping[
i];
2789 metadata->
white_point[0].
num =
s->sei.mastering_display.white_point[0];
2791 metadata->
white_point[1].
num =
s->sei.mastering_display.white_point[1];
2803 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
2812 "min_luminance=%f, max_luminance=%f\n",
2817 if (
s->sei.content_light.present > 0 &&
2819 s->sei.content_light.present--;
2821 if (
s->sei.content_light.present) {
2826 metadata->
MaxCLL =
s->sei.content_light.max_content_light_level;
2827 metadata->
MaxFALL =
s->sei.content_light.max_pic_average_light_level;
2834 if (
s->sei.a53_caption.buf_ref) {
2843 for (
int i = 0;
i <
s->sei.unregistered.nb_buf_ref;
i++) {
2855 s->sei.unregistered.nb_buf_ref = 0;
2857 if (
s->sei.timecode.present) {
2861 sizeof(uint32_t) * 4);
2865 tc_sd = (uint32_t*)tcside->
data;
2866 tc_sd[0] =
s->sei.timecode.num_clock_ts;
2868 for (
int i = 0;
i < tc_sd[0];
i++) {
2869 int drop =
s->sei.timecode.cnt_dropped_flag[
i];
2870 int hh =
s->sei.timecode.hours_value[
i];
2871 int mm =
s->sei.timecode.minutes_value[
i];
2872 int ss =
s->sei.timecode.seconds_value[
i];
2873 int ff =
s->sei.timecode.n_frames[
i];
2880 s->sei.timecode.num_clock_ts = 0;
2883 if (
s->sei.dynamic_hdr_plus.info) {
2900 int pic_size_in_ctb = ((
s->ps.sps->width >>
s->ps.sps->log2_min_cb_size) + 1) *
2901 ((
s->ps.sps->height >>
s->ps.sps->log2_min_cb_size) + 1);
2904 memset(
s->horizontal_bs, 0,
s->bs_width *
s->bs_height);
2905 memset(
s->vertical_bs, 0,
s->bs_width *
s->bs_height);
2906 memset(
s->cbf_luma, 0,
s->ps.sps->min_tb_width *
s->ps.sps->min_tb_height);
2907 memset(
s->is_pcm, 0, (
s->ps.sps->min_pu_width + 1) * (
s->ps.sps->min_pu_height + 1));
2908 memset(
s->tab_slice_address, -1, pic_size_in_ctb *
sizeof(*
s->tab_slice_address));
2911 s->first_nal_type =
s->nal_unit_type;
2915 if (
s->ps.pps->tiles_enabled_flag)
2916 lc->
end_of_tiles_x =
s->ps.pps->column_width[0] <<
s->ps.sps->log2_ctb_size;
2934 s->frame->pict_type = 3 -
s->sh.slice_type;
2944 if (!
s->avctx->hwaccel)
2960 int ctb_addr_ts,
ret;
2963 s->nal_unit_type = nal->
type;
2966 switch (
s->nal_unit_type) {
2968 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2969 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2981 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2982 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2990 s->apply_defdispwin);
2995 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2996 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
3009 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
3010 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
3053 if (
s->sh.first_slice_in_pic_flag) {
3054 if (
s->max_ra == INT_MAX) {
3059 s->max_ra = INT_MIN;
3064 s->poc <=
s->max_ra) {
3069 s->max_ra = INT_MIN;
3076 }
else if (!
s->ref) {
3081 if (
s->nal_unit_type !=
s->first_nal_type) {
3083 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3084 s->first_nal_type,
s->nal_unit_type);
3088 if (!
s->sh.dependent_slice_segment_flag &&
3093 "Error constructing the reference lists for the current slice.\n");
3098 if (
s->sh.first_slice_in_pic_flag &&
s->avctx->hwaccel) {
3099 ret =
s->avctx->hwaccel->start_frame(
s->avctx,
NULL, 0);
3104 if (
s->avctx->hwaccel) {
3109 if (
s->threads_number > 1 &&
s->sh.num_entry_point_offsets > 0)
3113 if (ctb_addr_ts >= (
s->ps.sps->ctb_width *
s->ps.sps->ctb_height)) {
3117 if (ctb_addr_ts < 0) {
3125 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3126 s->max_ra = INT_MAX;
3133 "Skipping NAL unit %d\n",
s->nal_unit_type);
3146 int eos_at_start = 1;
3149 s->last_eos =
s->eos;
3156 s->nal_length_size,
s->avctx->codec_id, 1, 0);
3159 "Error splitting the input into NAL units.\n");
3163 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3177 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3186 if (
ret >= 0 &&
s->overlap > 2)
3190 "Error parsing NAL unit #%d.\n",
i);
3205 for (
i = 0;
i < 16;
i++)
3218 pixel_shift =
desc->comp[0].depth > 8;
3226 if (pixel_shift && !
s->checksum_buf) {
3229 frame->linesize[2]));
3230 if (!
s->checksum_buf)
3236 int width =
s->avctx->coded_width;
3237 int height =
s->avctx->coded_height;
3243 for (j = 0; j <
h; j++) {
3247 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3248 (
const uint16_t *)
src,
w);
3249 src =
s->checksum_buf;
3256 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3280 &
s->nal_length_size,
s->avctx->err_recognition,
3281 s->apply_defdispwin,
s->avctx);
3287 if (
first &&
s->ps.sps_list[
i]) {
3320 &new_extradata_size);
3321 if (new_extradata && new_extradata_size > 0) {
3335 "hardware accelerator failed to decode picture\n");
3342 s->sei.picture_hash.is_md5) {
3350 s->sei.picture_hash.is_md5 = 0;
3352 if (
s->is_decoded) {
3357 if (
s->output_frame->buf[0]) {
3392 if (
src->hwaccel_picture_private) {
3416 for (
i = 0;
i < 3;
i++) {
3433 if (
s->HEVClcList &&
s->sList) {
3434 for (
i = 1;
i <
s->threads_number;
i++) {
3460 if (!
s->HEVClc || !
s->HEVClcList || !
s->sList)
3462 s->HEVClcList[0] =
s->HEVClc;
3466 if (!
s->cabac_state)
3470 if (!
s->output_frame)
3475 if (!
s->DPB[
i].frame)
3477 s->DPB[
i].tf.f =
s->DPB[
i].frame;
3480 s->max_ra = INT_MAX;
3488 s->context_initialized = 1;
3508 if (!
s->context_initialized) {
3516 if (
s0->DPB[
i].frame->buf[0]) {
3523 if (
s->ps.sps !=
s0->ps.sps)
3543 if (
s->ps.sps !=
s0->ps.sps)
3547 s->seq_decode =
s0->seq_decode;
3548 s->seq_output =
s0->seq_output;
3549 s->pocTid0 =
s0->pocTid0;
3550 s->max_ra =
s0->max_ra;
3552 s->no_rasl_output_flag =
s0->no_rasl_output_flag;
3554 s->is_nalff =
s0->is_nalff;
3555 s->nal_length_size =
s0->nal_length_size;
3557 s->threads_number =
s0->threads_number;
3558 s->threads_type =
s0->threads_type;
3561 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3562 s->max_ra = INT_MAX;
3569 for (
i = 0;
i <
s->sei.unregistered.nb_buf_ref;
i++)
3571 s->sei.unregistered.nb_buf_ref = 0;
3573 if (
s0->sei.unregistered.nb_buf_ref) {
3575 s0->sei.unregistered.nb_buf_ref,
3576 sizeof(*
s->sei.unregistered.buf_ref));
3580 for (
i = 0;
i <
s0->sei.unregistered.nb_buf_ref;
i++) {
3582 if (!
s->sei.unregistered.buf_ref[
i])
3584 s->sei.unregistered.nb_buf_ref++;
3592 s->sei.frame_packing =
s0->sei.frame_packing;
3593 s->sei.display_orientation =
s0->sei.display_orientation;
3594 s->sei.mastering_display =
s0->sei.mastering_display;
3595 s->sei.content_light =
s0->sei.content_light;
3596 s->sei.alternative_transfer =
s0->sei.alternative_transfer;
3614 s->threads_number = 1;
3625 s->enable_parallel_tiles = 0;
3626 s->sei.picture_timing.picture_struct = 0;
3648 s->max_ra = INT_MAX;
3652 #define OFFSET(x) offsetof(HEVCContext, x)
3653 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
3656 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
3658 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
3688 #if CONFIG_HEVC_DXVA2_HWACCEL
3691 #if CONFIG_HEVC_D3D11VA_HWACCEL
3694 #if CONFIG_HEVC_D3D11VA2_HWACCEL
3697 #if CONFIG_HEVC_NVDEC_HWACCEL
3700 #if CONFIG_HEVC_VAAPI_HWACCEL
3703 #if CONFIG_HEVC_VDPAU_HWACCEL
3706 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL