26 #include "config_components.h"
59 static const uint8_t
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 for (
int i = 0;
i < 3;
i++) {
102 int log2_min_cb_size =
sps->log2_min_cb_size;
105 int pic_size_in_ctb = ((
width >> log2_min_cb_size) + 1) *
106 ((
height >> log2_min_cb_size) + 1);
107 int ctb_count =
sps->ctb_width *
sps->ctb_height;
108 int min_pu_size =
sps->min_pu_width *
sps->min_pu_height;
147 if (
sps->sao_enabled) {
148 int c_count = (
sps->chroma_format_idc != 0) ? 3 : 1;
150 for (
int c_idx = 0; c_idx < c_count; c_idx++) {
151 int w =
sps->width >>
sps->hshift[c_idx];
152 int h =
sps->height >>
sps->vshift[c_idx];
177 int luma_log2_weight_denom;
178 unsigned luma_weight_flags, chroma_weight_flags;
181 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
182 av_log(logctx,
AV_LOG_ERROR,
"luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
186 if (
sps->chroma_format_idc != 0) {
188 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
189 av_log(logctx,
AV_LOG_ERROR,
"chroma_log2_weight_denom %"PRId64
" is invalid\n", chroma_log2_weight_denom);
198 unsigned flag_bit = 1 << (sh->
nb_refs[
L0] - 1 -
i);
200 if (luma_weight_flags & flag_bit) {
202 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
210 if (chroma_weight_flags & flag_bit) {
211 for (j = 0; j < 2; j++) {
215 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
216 || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
235 unsigned flag_bit = 1 << (sh->
nb_refs[
L1] - 1 -
i);
237 if (luma_weight_flags & flag_bit) {
239 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
247 if (chroma_weight_flags & flag_bit) {
248 for (j = 0; j < 2; j++) {
252 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
253 || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
275 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
276 int prev_delta_msb = 0;
277 unsigned int nb_sps = 0, nb_sh;
281 if (!
sps->long_term_ref_pics_present)
284 if (
sps->num_long_term_ref_pics_sps > 0)
288 if (nb_sps >
sps->num_long_term_ref_pics_sps)
298 uint8_t lt_idx_sps = 0;
300 if (
sps->num_long_term_ref_pics_sps > 1)
303 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
304 rps->
used[
i] = !!(
sps->used_by_curr_pic_lt & (1
U << lt_idx_sps));
315 if (
i &&
i != nb_sps)
316 delta += prev_delta_msb;
318 poc = rps->
poc[
i] + cur_poc -
delta * max_poc_lsb - poc_lsb;
322 prev_delta_msb =
delta;
334 unsigned int num = 0, den = 0;
342 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
343 avctx->
level =
sps->ptl.general_ptl.level_idc;
347 if (
sps->vui.common.video_signal_type_present_flag)
353 if (
sps->vui.common.colour_description_present_flag) {
355 avctx->
color_trc =
sps->vui.common.transfer_characteristics;
364 if (
sps->chroma_format_idc == 1) {
365 if (
sps->vui.common.chroma_loc_info_present_flag) {
366 if (
sps->vui.common.chroma_sample_loc_type_top_field <= 5)
372 if (
vps->vps_timing_info_present_flag) {
373 num =
vps->vps_num_units_in_tick;
374 den =
vps->vps_time_scale;
375 }
else if (
sps->vui.vui_timing_info_present_flag) {
376 num =
sps->vui.vui_num_units_in_tick;
377 den =
sps->vui.vui_time_scale;
380 if (num > 0 && den > 0)
389 #if FF_API_CODEC_PROPS
391 if (
s->sei.common.a53_caption.buf_ref)
396 if (
s->sei.common.alternative_transfer.present &&
399 avctx->
color_trc =
s->sei.common.alternative_transfer.preferred_transfer_characteristics;
402 #if FF_API_CODEC_PROPS
404 if ((
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present) ||
405 s->sei.common.aom_film_grain.enable)
418 s->nb_view_ids_available = 0;
420 s->nb_view_pos_available = 0;
423 if (
vps->nb_layers < 2 && !
vps->view_id[0])
426 s->view_ids_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_ids_available));
427 if (!
s->view_ids_available)
431 s->view_pos_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_pos_available));
432 if (!
s->view_pos_available)
436 for (
int i = 0;
i <
vps->nb_layers;
i++) {
437 s->view_ids_available[
i] =
vps->view_id[
i];
439 if (
s->view_pos_available) {
446 s->nb_view_ids_available =
vps->nb_layers;
447 s->nb_view_pos_available =
s->view_pos_available ?
vps->nb_layers : 0;
457 if (
vps->nb_layers != 2 || !
vps->layer_id_in_nuh[1])
473 unsigned layers_active_output = 0, highest_layer;
475 s->layers_active_output = 1;
476 s->layers_active_decode = 1;
484 s->layers_active_decode = (1 <<
vps->nb_layers) - 1;
485 s->layers_active_output = 1;
494 if (
s->nb_view_ids == 1 &&
s->view_ids[0] == -1) {
495 layers_active_output = (1 <<
vps->nb_layers) - 1;
497 for (
int i = 0;
i <
s->nb_view_ids;
i++) {
498 int view_id =
s->view_ids[
i];
503 "Invalid view ID requested: %d\n", view_id);
507 for (
int j = 0; j <
vps->nb_layers; j++) {
508 if (
vps->view_id[j] == view_id) {
515 "View ID %d not present in VPS\n", view_id);
518 layers_active_output |= 1 << layer_idx;
522 if (!layers_active_output) {
527 highest_layer =
ff_log2(layers_active_output);
530 "Too many layers requested: %u\n", layers_active_output);
538 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
539 s->layers_active_output = layers_active_output;
542 s->layers_active_decode,
s->layers_active_output);
577 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
578 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
579 CONFIG_HEVC_D3D12VA_HWACCEL + \
580 CONFIG_HEVC_NVDEC_HWACCEL + \
581 CONFIG_HEVC_VAAPI_HWACCEL + \
582 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
583 CONFIG_HEVC_VDPAU_HWACCEL + \
584 CONFIG_HEVC_VULKAN_HWACCEL)
592 switch (
sps->pix_fmt) {
595 #if CONFIG_HEVC_DXVA2_HWACCEL
598 #if CONFIG_HEVC_D3D11VA_HWACCEL
602 #if CONFIG_HEVC_D3D12VA_HWACCEL
605 #if CONFIG_HEVC_VAAPI_HWACCEL
608 #if CONFIG_HEVC_VDPAU_HWACCEL
611 #if CONFIG_HEVC_NVDEC_HWACCEL
614 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
617 #if CONFIG_HEVC_VULKAN_HWACCEL
622 #if CONFIG_HEVC_DXVA2_HWACCEL
625 #if CONFIG_HEVC_D3D11VA_HWACCEL
629 #if CONFIG_HEVC_D3D12VA_HWACCEL
632 #if CONFIG_HEVC_VAAPI_HWACCEL
635 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
638 #if CONFIG_HEVC_VULKAN_HWACCEL
641 #if CONFIG_HEVC_VDPAU_HWACCEL
644 #if CONFIG_HEVC_NVDEC_HWACCEL
649 #if CONFIG_HEVC_VAAPI_HWACCEL
652 #if CONFIG_HEVC_VDPAU_HWACCEL
655 #if CONFIG_HEVC_NVDEC_HWACCEL
658 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
661 #if CONFIG_HEVC_VULKAN_HWACCEL
667 #if CONFIG_HEVC_VAAPI_HWACCEL
670 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
673 #if CONFIG_HEVC_VULKAN_HWACCEL
676 #if CONFIG_HEVC_NVDEC_HWACCEL
681 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
687 #if CONFIG_HEVC_VAAPI_HWACCEL
690 #if CONFIG_HEVC_VDPAU_HWACCEL
693 #if CONFIG_HEVC_VULKAN_HWACCEL
696 #if CONFIG_HEVC_NVDEC_HWACCEL
701 #if CONFIG_HEVC_VAAPI_HWACCEL
704 #if CONFIG_HEVC_VULKAN_HWACCEL
707 #if CONFIG_HEVC_NVDEC_HWACCEL
715 *fmt++ =
sps->pix_fmt;
727 s->avctx->pix_fmt =
ret;
772 unsigned pps_id, layer_idx;
793 pps =
s->ps.pps_list[pps_id];
796 layer_idx =
vps->layer_idx[
s->nuh_layer_id];
803 int slice_address_length;
805 if (
pps->dependent_slice_segments_enabled_flag)
817 "Invalid slice segment address: %u.\n",
830 for (
i = 0;
i <
pps->num_extra_slice_header_bits;
i++)
842 !
pps->pps_curr_pic_ref_enabled_flag &&
843 s->nuh_layer_id == 0) {
850 if (
pps->output_flag_present_flag)
853 if (
sps->separate_colour_plane)
857 (
s->nuh_layer_id > 0 &&
858 !(
vps->poc_lsb_not_present & (1 << layer_idx)))) {
865 "Ignoring POC change between slices: %d -> %d\n", poc, sh->
poc);
885 int numbits, rps_idx;
887 if (!
sps->nb_st_rps) {
893 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
907 if (
sps->temporal_mvp_enabled)
922 if (
s->nuh_layer_id > 0) {
923 int num_direct_ref_layers =
vps->num_direct_ref_layers[layer_idx];
925 if (
vps->default_ref_layers_active)
927 else if (num_direct_ref_layers) {
932 "NumDirectRefLayers>1 not supported\n");
938 if (
sps->sao_enabled) {
940 if (
sps->chroma_format_idc) {
977 if (
pps->lists_modification_present_flag && nb_refs > 1) {
995 if (
pps->cabac_init_present_flag)
1010 "Invalid collocated_ref_idx: %d.\n",
1027 "Invalid number of merging MVP candidates: %d.\n",
1033 if (
sps->motion_vector_resolution_control_idc == 2)
1043 if (
pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1056 if (
pps->pps_slice_act_qp_offsets_present_flag) {
1062 if (
pps->chroma_qp_offset_list_enabled_flag)
1067 if (
pps->deblocking_filter_control_present_flag) {
1068 int deblocking_filter_override_flag = 0;
1070 if (
pps->deblocking_filter_override_enabled_flag)
1071 deblocking_filter_override_flag =
get_bits1(gb);
1073 if (deblocking_filter_override_flag) {
1078 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1079 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1081 "Invalid deblock filter offsets: %d, %d\n",
1082 beta_offset_div2, tc_offset_div2);
1099 if (
pps->seq_loop_filter_across_slices_enabled_flag &&
1110 if (
pps->tiles_enabled_flag ||
pps->entropy_coding_sync_enabled_flag) {
1114 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1122 if (offset_len < 1 || offset_len > 32) {
1146 if (
pps->slice_header_extension_present_flag) {
1152 for (
i = 0;
i < length;
i++)
1168 "The slice_qp %d is outside the valid range "
1171 -
sps->qp_bd_offset);
1192 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1194 #define SET_SAO(elem, value) \
1196 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1197 sao->elem = value; \
1198 else if (sao_merge_left_flag) \
1199 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1200 else if (sao_merge_up_flag) \
1201 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1211 int sao_merge_left_flag = 0;
1212 int sao_merge_up_flag = 0;
1216 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
1217 s->sh.slice_sample_adaptive_offset_flag[1]) {
1222 if (ry > 0 && !sao_merge_left_flag) {
1228 for (c_idx = 0; c_idx < (
sps->chroma_format_idc ? 3 : 1); c_idx++) {
1229 int log2_sao_offset_scale = c_idx == 0 ?
pps->log2_sao_offset_scale_luma :
1230 pps->log2_sao_offset_scale_chroma;
1232 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1247 for (
i = 0;
i < 4;
i++)
1251 for (
i = 0;
i < 4;
i++) {
1260 }
else if (c_idx != 2) {
1266 for (
i = 0;
i < 4;
i++) {
1274 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1286 if (log2_res_scale_abs_plus1 != 0) {
1289 (1 - 2 * res_scale_sign_flag);
1302 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1303 int log2_cb_size,
int log2_trafo_size,
1304 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1307 const int log2_trafo_size_c = log2_trafo_size -
sps->hshift[1];
1311 int trafo_size = 1 << log2_trafo_size;
1314 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, x0, y0, 0);
1317 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1318 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1321 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1322 (
sps->chroma_format_idc == 2 &&
1323 (cbf_cb[1] || cbf_cr[1]));
1335 "The cu_qp_delta %d is outside the valid range "
1338 -(26 +
sps->qp_bd_offset / 2),
1339 (25 +
sps->qp_bd_offset / 2));
1346 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1349 if (cu_chroma_qp_offset_flag) {
1350 int cu_chroma_qp_offset_idx = 0;
1351 if (
pps->chroma_qp_offset_list_len_minus1 > 0) {
1354 "cu_chroma_qp_offset_idx not yet tested.\n");
1387 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1388 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1389 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1390 lc->
tu.
cross_pf = (
pps->cross_component_prediction_enabled_flag && cbf_luma &&
1397 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1400 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1401 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 1);
1405 log2_trafo_size_c, scan_idx_c, 1);
1408 ptrdiff_t
stride =
s->cur_frame->f->linesize[1];
1409 int hshift =
sps->hshift[1];
1413 int size = 1 << log2_trafo_size_c;
1416 ((x0 >> hshift) <<
sps->pixel_shift)];
1420 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1427 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1430 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1431 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 2);
1435 log2_trafo_size_c, scan_idx_c, 2);
1438 ptrdiff_t
stride =
s->cur_frame->f->linesize[2];
1439 int hshift =
sps->hshift[2];
1443 int size = 1 << log2_trafo_size_c;
1446 ((x0 >> hshift) <<
sps->pixel_shift)];
1450 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1453 }
else if (
sps->chroma_format_idc && blk_idx == 3) {
1454 int trafo_size_h = 1 << (log2_trafo_size + 1);
1455 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1456 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1459 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1460 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 1);
1464 log2_trafo_size, scan_idx_c, 1);
1466 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1469 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1470 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 2);
1474 log2_trafo_size, scan_idx_c, 2);
1478 if (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3) {
1479 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1480 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1482 sps->log2_ctb_size);
1483 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 1);
1484 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 2);
1485 if (
sps->chroma_format_idc == 2) {
1487 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1488 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1489 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1491 }
else if (blk_idx == 3) {
1492 int trafo_size_h = 1 << (log2_trafo_size + 1);
1493 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1495 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1496 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 1);
1497 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 2);
1498 if (
sps->chroma_format_idc == 2) {
1500 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1501 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 1);
1502 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 2);
1511 int x0,
int y0,
int log2_cb_size)
1513 int cb_size = 1 << log2_cb_size;
1514 int log2_min_pu_size =
sps->log2_min_pu_size;
1516 int min_pu_width =
sps->min_pu_width;
1517 int x_end =
FFMIN(x0 + cb_size,
sps->width);
1518 int y_end =
FFMIN(y0 + cb_size,
sps->height);
1521 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1522 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1523 is_pcm[
i + j * min_pu_width] = 2;
1530 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1531 int log2_cb_size,
int log2_trafo_size,
1532 int trafo_depth,
int blk_idx,
1533 const int *base_cbf_cb,
const int *base_cbf_cr)
1536 uint8_t split_transform_flag;
1541 cbf_cb[0] = base_cbf_cb[0];
1542 cbf_cb[1] = base_cbf_cb[1];
1543 cbf_cr[0] = base_cbf_cr[0];
1544 cbf_cr[1] = base_cbf_cr[1];
1547 if (trafo_depth == 1) {
1549 if (
sps->chroma_format_idc == 3) {
1563 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1564 log2_trafo_size >
sps->log2_min_tb_size &&
1565 trafo_depth < lc->cu.max_trafo_depth &&
1569 int inter_split =
sps->max_transform_hierarchy_depth_inter == 0 &&
1574 split_transform_flag = log2_trafo_size >
sps->log2_max_trafo_size ||
1579 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1580 if (trafo_depth == 0 || cbf_cb[0]) {
1582 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1587 if (trafo_depth == 0 || cbf_cr[0]) {
1589 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1595 if (split_transform_flag) {
1596 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1597 const int x1 = x0 + trafo_size_split;
1598 const int y1 = y0 + trafo_size_split;
1600 #define SUBDIVIDE(x, y, idx) \
1602 ret = hls_transform_tree(lc, l, pps, sps, \
1603 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1604 log2_trafo_size - 1, trafo_depth + 1, idx, \
1617 int min_tu_size = 1 <<
sps->log2_min_tb_size;
1618 int log2_min_tu_size =
sps->log2_min_tb_size;
1619 int min_tu_width =
sps->min_tb_width;
1623 cbf_cb[0] || cbf_cr[0] ||
1624 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1629 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1630 log2_cb_size, log2_trafo_size,
1631 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1637 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1638 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1639 int x_tu = (x0 + j) >> log2_min_tu_size;
1640 int y_tu = (y0 +
i) >> log2_min_tu_size;
1641 l->
cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1644 if (!
s->sh.disable_deblocking_filter_flag) {
1646 if (
pps->transquant_bypass_enable_flag &&
1655 const HEVCPPS *
pps,
int x0,
int y0,
int log2_cb_size)
1660 int cb_size = 1 << log2_cb_size;
1661 ptrdiff_t stride0 =
s->cur_frame->f->linesize[0];
1662 ptrdiff_t stride1 =
s->cur_frame->f->linesize[1];
1663 ptrdiff_t stride2 =
s->cur_frame->f->linesize[2];
1664 uint8_t *dst0 = &
s->cur_frame->f->data[0][y0 * stride0 + (x0 <<
sps->pixel_shift)];
1665 uint8_t *dst1 = &
s->cur_frame->f->data[1][(y0 >>
sps->vshift[1]) * stride1 + ((x0 >>
sps->hshift[1]) <<
sps->pixel_shift)];
1666 uint8_t *dst2 = &
s->cur_frame->f->data[2][(y0 >>
sps->vshift[2]) * stride2 + ((x0 >>
sps->hshift[2]) <<
sps->pixel_shift)];
1668 int length = cb_size * cb_size *
sps->pcm.bit_depth +
1669 (((cb_size >>
sps->hshift[1]) * (cb_size >>
sps->vshift[1])) +
1670 ((cb_size >>
sps->hshift[2]) * (cb_size >>
sps->vshift[2]))) *
1671 sps->pcm.bit_depth_chroma;
1672 const uint8_t *pcm =
skip_bytes(&lc->
cc, (length + 7) >> 3);
1675 if (!
s->sh.disable_deblocking_filter_flag)
1682 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
sps->pcm.bit_depth);
1683 if (
sps->chroma_format_idc) {
1684 s->hevcdsp.put_pcm(dst1, stride1,
1685 cb_size >>
sps->hshift[1],
1686 cb_size >>
sps->vshift[1],
1687 &gb,
sps->pcm.bit_depth_chroma);
1688 s->hevcdsp.put_pcm(dst2, stride2,
1689 cb_size >>
sps->hshift[2],
1690 cb_size >>
sps->vshift[2],
1691 &gb,
sps->pcm.bit_depth_chroma);
1715 uint8_t *
dst, ptrdiff_t dststride,
1717 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1720 const uint8_t *
src =
ref->data[0];
1722 int pic_width =
sps->width;
1723 int pic_height =
sps->height;
1726 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1730 x_off +=
mv->x >> 2;
1731 y_off +=
mv->y >> 2;
1737 ref ==
s->cur_frame->f) {
1747 pic_width, pic_height);
1754 block_h,
mx,
my, block_w);
1757 block_h,
s->sh.luma_log2_weight_denom,
1758 luma_weight, luma_offset,
mx,
my, block_w);
1779 uint8_t *
dst, ptrdiff_t dststride,
1780 const AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1781 int block_w,
int block_h,
const AVFrame *ref1,
1782 const Mv *mv1,
struct MvField *current_mv)
1785 ptrdiff_t src0stride = ref0->
linesize[0];
1786 ptrdiff_t src1stride = ref1->
linesize[0];
1787 int pic_width =
sps->width;
1788 int pic_height =
sps->height;
1789 int mx0 = mv0->
x & 3;
1790 int my0 = mv0->
y & 3;
1791 int mx1 = mv1->
x & 3;
1792 int my1 = mv1->
y & 3;
1793 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1795 int x_off0 = x_off + (mv0->
x >> 2);
1796 int y_off0 = y_off + (mv0->
y >> 2);
1797 int x_off1 = x_off + (mv1->
x >> 2);
1798 int y_off1 = y_off + (mv1->
y >> 2);
1801 const uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1802 const uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1812 edge_emu_stride, src0stride,
1816 pic_width, pic_height);
1818 src0stride = edge_emu_stride;
1829 edge_emu_stride, src1stride,
1833 pic_width, pic_height);
1835 src1stride = edge_emu_stride;
1838 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1839 block_h, mx0, my0, block_w);
1841 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1842 block_h, mx1, my1, block_w);
1844 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1845 block_h,
s->sh.luma_log2_weight_denom,
1846 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1847 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1848 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1849 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1874 ptrdiff_t dststride,
const uint8_t *
src0, ptrdiff_t
srcstride,
int reflist,
1875 int x_off,
int y_off,
int block_w,
int block_h,
1876 const struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1879 int pic_width =
sps->width >>
sps->hshift[1];
1880 int pic_height =
sps->height >>
sps->vshift[1];
1881 const Mv *
mv = ¤t_mv->
mv[reflist];
1882 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1885 int hshift =
sps->hshift[1];
1889 intptr_t _mx =
mx << (1 - hshift);
1891 int emu =
src0 ==
s->cur_frame->f->data[1] ||
src0 ==
s->cur_frame->f->data[2];
1893 x_off +=
mv->x >> (2 + hshift);
1904 (edge_emu_stride + (1 <<
sps->pixel_shift));
1910 pic_width, pic_height);
1917 block_h, _mx, _my, block_w);
1920 block_h,
s->sh.chroma_log2_weight_denom,
1921 chroma_weight, chroma_offset, _mx, _my, block_w);
1943 uint8_t *dst0, ptrdiff_t dststride,
1945 int x_off,
int y_off,
int block_w,
int block_h,
const MvField *current_mv,
int cidx)
1948 const uint8_t *
src1 = ref0->
data[cidx+1];
1949 const uint8_t *
src2 = ref1->
data[cidx+1];
1950 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1951 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1952 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1954 int pic_width =
sps->width >>
sps->hshift[1];
1955 int pic_height =
sps->height >>
sps->vshift[1];
1956 const Mv *
const mv0 = ¤t_mv->
mv[0];
1957 const Mv *
const mv1 = ¤t_mv->
mv[1];
1958 int hshift =
sps->hshift[1];
1965 intptr_t _mx0 = mx0 << (1 - hshift);
1966 intptr_t _my0 = my0 << (1 -
vshift);
1967 intptr_t _mx1 = mx1 << (1 - hshift);
1968 intptr_t _my1 = my1 << (1 -
vshift);
1970 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1971 int y_off0 = y_off + (mv0->
y >> (2 +
vshift));
1972 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1973 int y_off1 = y_off + (mv1->
y >> (2 +
vshift));
1975 src1 += y_off0 * src1stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1976 src2 += y_off1 * src2stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1984 (edge_emu_stride + (1 <<
sps->pixel_shift));
1987 edge_emu_stride, src1stride,
1991 pic_width, pic_height);
1994 src1stride = edge_emu_stride;
2003 (edge_emu_stride + (1 <<
sps->pixel_shift));
2006 edge_emu_stride, src2stride,
2010 pic_width, pic_height);
2013 src2stride = edge_emu_stride;
2016 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
2017 block_h, _mx0, _my0, block_w);
2019 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
2021 block_h, _mx1, _my1, block_w);
2023 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
2026 s->sh.chroma_log2_weight_denom,
2027 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
2028 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
2029 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
2030 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
2031 _mx1, _my1, block_w);
2046 int x0,
int y0,
int nPbW,
2047 int nPbH,
int log2_cb_size,
int part_idx,
2059 if (inter_pred_idc !=
PRED_L1) {
2060 if (
s->sh.nb_refs[
L0])
2067 part_idx, merge_idx,
mv, mvp_flag, 0);
2072 if (inter_pred_idc !=
PRED_L0) {
2073 if (
s->sh.nb_refs[
L1])
2076 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
2085 part_idx, merge_idx,
mv, mvp_flag, 1);
2094 int x0,
int y0,
int nPbW,
int nPbH,
2095 int log2_cb_size,
int partIdx,
int idx)
2097 #define POS(c_idx, x, y) \
2098 &s->cur_frame->f->data[c_idx] ? \
2099 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2100 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2103 struct MvField current_mv = {{{ 0 }}};
2105 int min_pu_width =
sps->min_pu_width;
2107 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2108 const RefPicList *refPicList =
s->cur_frame->refPicList;
2110 const int *linesize =
s->cur_frame->f->linesize;
2111 uint8_t *dst0 =
s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 <<
sps->pixel_shift);
2112 uint8_t *dst1 =
POS(1, x0, y0);
2113 uint8_t *dst2 =
POS(2, x0, y0);
2114 int log2_min_cb_size =
sps->log2_min_cb_size;
2115 int min_cb_width =
sps->min_cb_width;
2116 int x_cb = x0 >> log2_min_cb_size;
2117 int y_cb = y0 >> log2_min_cb_size;
2127 if (
s->sh.max_num_merge_cand > 1)
2133 partIdx, merge_idx, ¤t_mv);
2136 partIdx, merge_idx, ¤t_mv);
2139 x_pu = x0 >>
sps->log2_min_pu_size;
2140 y_pu = y0 >>
sps->log2_min_pu_size;
2142 for (j = 0; j < nPbH >>
sps->log2_min_pu_size; j++)
2143 for (
i = 0; i < nPbW >>
sps->log2_min_pu_size;
i++)
2144 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
2147 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
2148 if (!ref0 || !ref0->
f)
2153 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
2154 if (!ref1 || !ref1->f)
2160 int x0_c = x0 >>
sps->hshift[1];
2161 int y0_c = y0 >>
sps->vshift[1];
2162 int nPbW_c = nPbW >>
sps->hshift[1];
2163 int nPbH_c = nPbH >>
sps->vshift[1];
2166 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2167 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
2168 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
2170 if (
sps->chroma_format_idc) {
2172 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2173 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
2175 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2176 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
2179 int x0_c = x0 >>
sps->hshift[1];
2180 int y0_c = y0 >>
sps->vshift[1];
2181 int nPbW_c = nPbW >>
sps->hshift[1];
2182 int nPbH_c = nPbH >>
sps->vshift[1];
2185 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
2186 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
2187 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
2189 if (
sps->chroma_format_idc) {
2191 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2192 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
2195 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2196 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
2199 int x0_c = x0 >>
sps->hshift[1];
2200 int y0_c = y0 >>
sps->vshift[1];
2201 int nPbW_c = nPbW >>
sps->hshift[1];
2202 int nPbH_c = nPbH >>
sps->vshift[1];
2205 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2206 ref1->f, ¤t_mv.
mv[1], ¤t_mv);
2208 if (
sps->chroma_format_idc) {
2210 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
2213 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
2223 int x0,
int y0,
int pu_size,
2224 int prev_intra_luma_pred_flag)
2227 int x_pu = x0 >>
sps->log2_min_pu_size;
2228 int y_pu = y0 >>
sps->log2_min_pu_size;
2229 int min_pu_width =
sps->min_pu_width;
2230 int size_in_pus = pu_size >>
sps->log2_min_pu_size;
2239 int y_ctb = (y0 >> (
sps->log2_ctb_size)) << (
sps->log2_ctb_size);
2241 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2242 int intra_pred_mode;
2247 if ((y0 - 1) < y_ctb)
2250 if (cand_left == cand_up) {
2251 if (cand_left < 2) {
2256 candidate[0] = cand_left;
2257 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2258 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2261 candidate[0] = cand_left;
2262 candidate[1] = cand_up;
2272 if (prev_intra_luma_pred_flag) {
2273 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
2275 if (candidate[0] > candidate[1])
2276 FFSWAP(uint8_t, candidate[0], candidate[1]);
2277 if (candidate[0] > candidate[2])
2278 FFSWAP(uint8_t, candidate[0], candidate[2]);
2279 if (candidate[1] > candidate[2])
2280 FFSWAP(uint8_t, candidate[1], candidate[2]);
2283 for (
i = 0;
i < 3;
i++)
2284 if (intra_pred_mode >= candidate[
i])
2291 for (
i = 0;
i < size_in_pus;
i++) {
2292 memset(&l->
tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
2293 intra_pred_mode, size_in_pus);
2295 for (j = 0; j < size_in_pus; j++) {
2300 return intra_pred_mode;
2305 int log2_cb_size,
int ct_depth)
2307 int length = (1 << log2_cb_size) >>
sps->log2_min_cb_size;
2308 int x_cb = x0 >>
sps->log2_min_cb_size;
2309 int y_cb = y0 >>
sps->log2_min_cb_size;
2312 for (y = 0; y < length; y++)
2313 memset(&tab_ct_depth[(y_cb + y) *
sps->min_cb_width + x_cb],
2318 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2319 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2326 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2327 uint8_t prev_intra_luma_pred_flag[4];
2329 int pb_size = (1 << log2_cb_size) >>
split;
2330 int side =
split + 1;
2334 for (
i = 0;
i < side;
i++)
2335 for (j = 0; j < side; j++)
2338 for (
i = 0;
i < side;
i++) {
2339 for (j = 0; j < side; j++) {
2340 if (prev_intra_luma_pred_flag[2 *
i + j])
2347 x0 + pb_size * j, y0 + pb_size *
i, pb_size,
2348 prev_intra_luma_pred_flag[2 *
i + j]);
2352 if (
sps->chroma_format_idc == 3) {
2353 for (
i = 0;
i < side;
i++) {
2354 for (j = 0; j < side; j++) {
2356 if (chroma_mode != 4) {
2366 }
else if (
sps->chroma_format_idc == 2) {
2369 if (chroma_mode != 4) {
2373 mode_idx = intra_chroma_table[chroma_mode];
2378 }
else if (
sps->chroma_format_idc != 0) {
2380 if (chroma_mode != 4) {
2398 int pb_size = 1 << log2_cb_size;
2399 int size_in_pus = pb_size >>
sps->log2_min_pu_size;
2400 int min_pu_width =
sps->min_pu_width;
2401 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2402 int x_pu = x0 >>
sps->log2_min_pu_size;
2403 int y_pu = y0 >>
sps->log2_min_pu_size;
2406 if (size_in_pus == 0)
2408 for (j = 0; j < size_in_pus; j++)
2409 memset(&l->
tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2411 for (j = 0; j < size_in_pus; j++)
2412 for (k = 0; k < size_in_pus; k++)
2419 int x0,
int y0,
int log2_cb_size)
2421 int cb_size = 1 << log2_cb_size;
2422 int log2_min_cb_size =
sps->log2_min_cb_size;
2423 int length = cb_size >> log2_min_cb_size;
2424 int min_cb_width =
sps->min_cb_width;
2425 int x_cb = x0 >> log2_min_cb_size;
2426 int y_cb = y0 >> log2_min_cb_size;
2427 int idx = log2_cb_size - 2;
2428 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2438 for (x = 0; x < 4; x++)
2440 if (
pps->transquant_bypass_enable_flag) {
2451 x0b, y0b, x_cb, y_cb,
2454 x = y_cb * min_cb_width + x_cb;
2455 for (y = 0; y < length; y++) {
2456 memset(&l->
skip_flag[x], skip_flag, length);
2461 x = y_cb * min_cb_width + x_cb;
2462 for (y = 0; y < length; y++) {
2470 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2473 if (!
s->sh.disable_deblocking_filter_flag)
2481 log2_cb_size ==
sps->log2_min_cb_size) {
2489 log2_cb_size >=
sps->pcm.log2_min_pcm_cb_size &&
2490 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2496 if (
sps->pcm_loop_filter_disabled)
2509 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2513 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2515 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2519 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2521 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2525 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2527 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2531 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2533 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2537 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2539 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2543 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2545 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2549 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2551 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2553 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2555 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2561 int rqt_root_cbf = 1;
2568 const static int cbf[2] = { 0 };
2571 sps->max_transform_hierarchy_depth_inter;
2572 ret =
hls_transform_tree(lc, l,
pps,
sps, x0, y0, x0, y0, x0, y0,
2574 log2_cb_size, 0, 0, cbf, cbf);
2578 if (!
s->sh.disable_deblocking_filter_flag)
2587 x = y_cb * min_cb_width + x_cb;
2588 for (y = 0; y < length; y++) {
2593 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2594 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2607 int log2_cb_size,
int cb_depth)
2610 const int cb_size = 1 << log2_cb_size;
2615 if (x0 + cb_size <= sps->
width &&
2616 y0 + cb_size <= sps->
height &&
2617 log2_cb_size >
sps->log2_min_cb_size) {
2619 sps, cb_depth, x0, y0);
2621 split_cu = (log2_cb_size >
sps->log2_min_cb_size);
2623 if (
pps->cu_qp_delta_enabled_flag &&
2624 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth) {
2629 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2630 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_chroma_qp_offset_depth) {
2635 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2636 const int cb_size_split = cb_size >> 1;
2637 const int x1 = x0 + cb_size_split;
2638 const int y1 = y0 + cb_size_split;
2643 x0, y0, log2_cb_size - 1, cb_depth + 1);
2647 if (more_data && x1 < sps->
width) {
2649 x1, y0, log2_cb_size - 1, cb_depth + 1);
2653 if (more_data && y1 < sps->
height) {
2655 x0, y1, log2_cb_size - 1, cb_depth + 1);
2659 if (more_data && x1 < sps->
width &&
2662 x1, y1, log2_cb_size - 1, cb_depth + 1);
2667 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2668 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2672 return ((x1 + cb_size_split) <
sps->width ||
2673 (y1 + cb_size_split) <
sps->height);
2680 if ((!((x0 + cb_size) %
2681 (1 << (
sps->log2_ctb_size))) ||
2682 (x0 + cb_size >=
sps->width)) &&
2684 (1 << (
sps->log2_ctb_size))) ||
2685 (y0 + cb_size >=
sps->height))) {
2687 return !end_of_slice_flag;
2699 int x_ctb,
int y_ctb,
int ctb_addr_ts)
2702 int ctb_size = 1 <<
sps->log2_ctb_size;
2703 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2704 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2708 if (
pps->entropy_coding_sync_enabled_flag) {
2709 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2712 }
else if (
pps->tiles_enabled_flag) {
2713 if (ctb_addr_ts &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[ctb_addr_ts - 1]) {
2714 int idxX =
pps->col_idxX[x_ctb >>
sps->log2_ctb_size];
2725 if (
pps->tiles_enabled_flag) {
2726 if (x_ctb > 0 &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2730 if (y_ctb > 0 &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs -
sps->ctb_width]])
2735 if (ctb_addr_in_slice <= 0)
2737 if (ctb_addr_in_slice < sps->ctb_width)
2743 lc->
ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >=
sps->ctb_width) && (
pps->tile_id[ctb_addr_ts] ==
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 -
sps->ctb_width]]));
2744 lc->
ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >=
sps->ctb_width) && (
pps->tile_id[ctb_addr_ts] ==
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 -
sps->ctb_width]]));
2753 const uint8_t *slice_data = gb->
buffer +
s->sh.data_offset;
2755 int ctb_size = 1 <<
sps->log2_ctb_size;
2759 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2762 while (more_data && ctb_addr_ts < sps->ctb_size) {
2763 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2765 x_ctb = (ctb_addr_rs % ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2766 y_ctb = (ctb_addr_rs / ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2776 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2783 if (more_data < 0) {
2794 if (x_ctb + ctb_size >=
sps->width &&
2795 y_ctb + ctb_size >=
sps->height)
2802 int job,
int thread)
2809 int ctb_size = 1 <<
sps->log2_ctb_size;
2812 int ctb_addr_rs =
s->sh.slice_ctb_addr_rs + ctb_row * ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size);
2813 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2815 const uint8_t *
data =
s->data +
s->sh.offset[ctb_row];
2816 const size_t data_size =
s->sh.size[ctb_row];
2825 while(more_data && ctb_addr_ts < sps->ctb_size) {
2826 int x_ctb = (ctb_addr_rs %
sps->ctb_width) <<
sps->log2_ctb_size;
2827 int y_ctb = (ctb_addr_rs /
sps->ctb_width) <<
sps->log2_ctb_size;
2847 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2855 if (more_data < 0) {
2866 if (!more_data && (x_ctb+ctb_size) <
sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2873 if ((x_ctb+ctb_size) >=
sps->width && (y_ctb+ctb_size) >=
sps->height ) {
2878 ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2881 if(x_ctb >=
sps->width) {
2898 if (
s->nb_wpp_progress < count) {
2900 sizeof(*
s->wpp_progress));
2904 s->wpp_progress =
tmp;
2905 memset(
s->wpp_progress +
s->nb_wpp_progress, 0,
2906 (count -
s->nb_wpp_progress) *
sizeof(*
s->wpp_progress));
2908 for (
int i =
s->nb_wpp_progress;
i < count;
i++) {
2912 s->nb_wpp_progress =
i + 1;
2916 for (
int i = 0;
i < count;
i++)
2927 int length = nal->
size;
2930 int64_t startheader, cmpt = 0;
2933 if (
s->sh.slice_ctb_addr_rs +
s->sh.num_entry_point_offsets *
sps->ctb_width >=
sps->ctb_width *
sps->ctb_height) {
2935 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2936 sps->ctb_width,
sps->ctb_height
2941 if (
s->avctx->thread_count >
s->nb_local_ctx) {
2947 memcpy(
tmp,
s->local_ctx,
sizeof(*
s->local_ctx) *
s->nb_local_ctx);
2951 for (
unsigned i =
s->nb_local_ctx; i < s->avctx->thread_count;
i++) {
2952 tmp = &
s->local_ctx[
i];
2954 memset(
tmp, 0,
sizeof(*
tmp));
2956 tmp->logctx =
s->avctx;
2958 tmp->common_cabac_state = &
s->cabac;
2961 s->nb_local_ctx =
s->avctx->thread_count;
2966 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2973 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2974 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2975 for (j = 0, cmpt = 0, startheader =
offset
2976 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2982 s->sh.size[
i] =
s->sh.entry_point_offset[
i] - cmpt;
2987 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2992 s->sh.size [
s->sh.num_entry_point_offsets] = length -
offset;
2993 s->sh.offset[
s->sh.num_entry_point_offsets] =
offset;
2995 s->sh.offset[0] =
s->sh.data_offset;
2996 s->sh.size[0] =
s->sh.offset[1] -
s->sh.offset[0];
3000 for (
i = 1;
i <
s->nb_local_ctx;
i++) {
3001 s->local_ctx[
i].first_qp_group = 1;
3002 s->local_ctx[
i].qp_y =
s->local_ctx[0].qp_y;
3014 if (
pps->entropy_coding_sync_enabled_flag)
3017 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
3030 if (!
s->sh.first_slice_in_pic_flag)
3031 s->slice_idx += !
s->sh.dependent_slice_segment_flag;
3033 if (!
s->sh.dependent_slice_segment_flag &&
s->sh.slice_type !=
HEVC_SLICE_I) {
3037 "Error constructing the reference lists for the current slice.\n");
3042 s->slice_initialized = 1;
3044 if (
s->avctx->hwaccel)
3049 "SCC profile is not yet implemented in hevc native decoder.\n");
3053 if (
s->sh.dependent_slice_segment_flag) {
3054 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
3055 int prev_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3062 s->local_ctx[0].first_qp_group = !
s->sh.dependent_slice_segment_flag;
3064 if (!
pps->cu_qp_delta_enabled_flag)
3065 s->local_ctx[0].qp_y =
s->sh.slice_qp;
3067 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3068 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3071 s->sh.num_entry_point_offsets > 0 &&
3072 pps->num_tile_rows == 1 &&
pps->num_tile_columns == 1)
3087 if (
IS_IRAP(
s) &&
s->no_rasl_output_flag) {
3088 if (
s->sei.common.mastering_display.present > 0)
3089 s->sei.common.mastering_display.present--;
3091 if (
s->sei.common.content_light.present > 0)
3092 s->sei.common.content_light.present--;
3097 sps->bit_depth,
sps->bit_depth_chroma,
3098 s->cur_frame->poc );
3102 if (
s->sei.timecode.present) {
3107 sizeof(uint32_t) * 4, &tcside);
3112 tc_sd = (uint32_t*)tcside->
data;
3113 tc_sd[0] =
s->sei.timecode.num_clock_ts;
3115 for (
int i = 0;
i < tc_sd[0];
i++) {
3116 int drop =
s->sei.timecode.cnt_dropped_flag[
i];
3117 int hh =
s->sei.timecode.hours_value[
i];
3118 int mm =
s->sei.timecode.minutes_value[
i];
3119 int ss =
s->sei.timecode.seconds_value[
i];
3120 int ff =
s->sei.timecode.n_frames[
i];
3128 s->sei.timecode.num_clock_ts = 0;
3131 if (
s->sei.common.dynamic_hdr_plus.info) {
3152 if (
s->sei.common.dynamic_hdr_vivid.info) {
3155 &
s->sei.common.dynamic_hdr_vivid.info,
3167 for (
int i = nal_idx;
i <
s->pkt.nb_nals;
i++) {
3173 !(
s->layers_active_decode & (1 <<
s->vps->layer_idx[layer_id])))
3176 switch (nal->
type) {
3209 const HEVCPPS *
const pps =
s->ps.pps_list[
s->sh.pps_id];
3211 int pic_size_in_ctb = ((
sps->width >>
sps->log2_min_cb_size) + 1) *
3212 ((
sps->height >>
sps->log2_min_cb_size) + 1);
3213 int new_sequence = (l == &
s->layers[0]) &&
3215 int prev_layers_active_decode =
s->layers_active_decode;
3216 int prev_layers_active_output =
s->layers_active_output;
3219 if (
sps->vps !=
s->vps && l != &
s->layers[0]) {
3227 const HEVCSPS *sps_base =
s->layers[0].sps;
3230 if (l != &
s->layers[0]) {
3233 "Access unit starts with a non-base layer frame\n");
3242 !
sps->vui.common.video_signal_type_present_flag)
3255 "Base/non-base layer SPS have unsupported parameter combination\n");
3266 if (l == &
s->layers[0]) {
3282 memset(l->
is_pcm, 0, (
sps->min_pu_width + 1) * (
sps->min_pu_height + 1));
3289 s->first_nal_type =
s->nal_unit_type;
3299 s->sei.recovery_point.has_recovery_poc) {
3301 s->recovery_poc =
s->poc +
s->sei.recovery_point.recovery_poc_cnt;
3302 else if (
s->poc >=
s->recovery_poc)
3307 if (
s->temporal_id == 0 &&
3315 s->poc_tid0 =
s->poc;
3317 if (
pps->tiles_enabled_flag)
3318 s->local_ctx[0].end_of_tiles_x =
pps->column_width[0] <<
sps->log2_ctb_size;
3322 0, 0,
s->sh.no_output_of_prior_pics_flag);
3346 s->cur_frame->needs_fg = ((
s->sei.common.film_grain_characteristics &&
3347 s->sei.common.film_grain_characteristics->present) ||
3348 s->sei.common.aom_film_grain.enable) &&
3356 if (
s->cur_frame->needs_fg &&
3357 (
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present &&
3359 s->cur_frame->f->format) ||
3362 "Unsupported film grain parameters. Ignoring film grain.\n");
3363 s->cur_frame->needs_fg = 0;
3366 if (
s->cur_frame->needs_fg) {
3367 s->cur_frame->frame_grain->format =
s->cur_frame->f->format;
3368 s->cur_frame->frame_grain->width =
s->cur_frame->f->width;
3369 s->cur_frame->frame_grain->height =
s->cur_frame->f->height;
3378 s->cur_frame->f->pict_type = 3 -
s->sh.slice_type;
3381 sps->temporal_layer[
sps->max_sub_layers - 1].num_reorder_pics,
3382 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3386 if (
s->avctx->hwaccel) {
3398 if (l == &
s->layers[0])
3401 if (nal_idx >=
s->finish_setup_nal_idx)
3410 s->cur_frame =
s->collocated_ref =
NULL;
3411 s->slice_initialized = 0;
3418 char msg_buf[4 * (50 + 2 * 2 * 16 )];
3426 pixel_shift =
desc->comp[0].depth > 8;
3431 if (pixel_shift && !
s->checksum_buf) {
3434 frame->linesize[2]));
3435 if (!
s->checksum_buf)
3442 int width =
s->avctx->coded_width;
3443 int height =
s->avctx->coded_height;
3449 for (j = 0; j <
h; j++) {
3453 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3454 (
const uint16_t *)
src,
w);
3455 src =
s->checksum_buf;
3462 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3463 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3465 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3467 "plane %d - correct " MD5_PRI "; ",
3471 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3478 "Verifying checksum for frame with POC %d: %s\n",
3490 if (
out->needs_fg) {
3493 switch (fgp->
type) {
3508 if (
s->avctx->hwaccel) {
3512 "hardware accelerator failed to decode picture\n");
3517 s->sei.picture_hash.is_md5) {
3523 s->sei.picture_hash.is_md5 = 0;
3526 l -
s->layers,
s->poc);
3533 const int layer_idx =
s->vps ?
s->vps->layer_idx[
s->nuh_layer_id] : 0;
3540 if (layer_idx < 0 ||
3541 (
s->nuh_layer_id > 0 && !(
s->layers_active_decode & (1 << layer_idx))))
3547 s->slice_initialized = 0;
3555 s->no_rasl_output_flag)) {
3560 if (
s->cur_layer != layer_idx &&
3561 s->layers[
s->cur_layer].cur_frame &&
3565 s->cur_layer = layer_idx;
3566 l = &
s->layers[
s->cur_layer];
3568 if (
s->sh.first_slice_in_pic_flag) {
3570 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
3582 if (
s->nal_unit_type !=
s->first_nal_type) {
3584 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3585 s->first_nal_type,
s->nal_unit_type);
3602 s->nal_unit_type = nal->
type;
3618 switch (
s->nal_unit_type) {
3669 "Skipping NAL unit %d\n",
s->nal_unit_type);
3677 "Skipping invalid undecodable NALU: %d\n",
s->nal_unit_type);
3686 s->sei.recovery_point.has_recovery_poc = 0;
3692 int eos_at_start = 1;
3695 s->cur_frame =
s->collocated_ref =
NULL;
3696 s->last_eos =
s->eos;
3698 s->slice_initialized = 0;
3710 s->nal_length_size,
s->avctx->codec_id,
flags);
3713 "Error splitting the input into NAL units.\n");
3717 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3740 s->pkt.nals[
s->pkt.nb_nals - 1].size > 2 && !
s->pkt.nals[
s->pkt.nb_nals - 1].nuh_layer_id
3741 && !
s->pkt.nals[
s->pkt.nb_nals - 1].temporal_id) {
3742 H2645NAL *nal = &
s->pkt.nals[
s->pkt.nb_nals - 1];
3745 av_log(
s->avctx,
AV_LOG_WARNING,
"Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3754 s->avctx->err_recognition);
3763 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3773 "Error parsing NAL unit #%d.\n",
i);
3800 &
s->nal_length_size,
s->avctx->err_recognition,
3801 s->apply_defdispwin,
s->avctx);
3807 if (
first &&
s->ps.sps_list[
i]) {
3846 s->layers_active_output, 0, 0, 0);
3853 s->pkt_dts = avpkt->
dts;
3856 if (sd && sd_size > 0) {
3863 if (sd && sd_size >=
sizeof(
s->dovi_ctx.cfg)) {
3864 int old =
s->dovi_ctx.cfg.dv_profile;
3868 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3869 old,
s->dovi_ctx.cfg.dv_profile);
3893 if (
src->needs_fg) {
3906 dst->nb_rpl_elems =
src->nb_rpl_elems;
3909 dst->ctb_count =
src->ctb_count;
3912 dst->base_layer_frame =
src->base_layer_frame;
3915 src->hwaccel_picture_private);
3949 for (
int i = 0;
i <
s->nb_wpp_progress;
i++)
3975 s->nb_local_ctx = 1;
3977 s->local_ctx[0].parent =
s;
3978 s->local_ctx[0].logctx = avctx;
3979 s->local_ctx[0].common_cabac_state = &
s->cabac;
3982 if (!
s->output_fifo)
4000 s->dovi_ctx.logctx = avctx;
4059 memcmp(
s->view_ids, s0->
view_ids,
sizeof(*
s->view_ids) *
s->nb_view_ids)) {
4111 s->sei.picture_timing.picture_struct = 0;
4131 if (sd && sd->
size >=
sizeof(
s->dovi_ctx.cfg))
4151 #define OFFSET(x) offsetof(HEVCContext, x)
4152 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4155 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
4157 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
4159 {
"view_ids",
"Array of view IDs that should be decoded and output; a single -1 to decode all views",
4161 .min = -1, .max = INT_MAX, .flags =
PAR },
4162 {
"view_ids_available",
"Array of available view IDs is exported here",
4165 {
"view_pos_available",
"Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4201 #if CONFIG_HEVC_DXVA2_HWACCEL
4204 #if CONFIG_HEVC_D3D11VA_HWACCEL
4207 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4210 #if CONFIG_HEVC_D3D12VA_HWACCEL
4213 #if CONFIG_HEVC_NVDEC_HWACCEL
4216 #if CONFIG_HEVC_VAAPI_HWACCEL
4219 #if CONFIG_HEVC_VDPAU_HWACCEL
4222 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4225 #if CONFIG_HEVC_VULKAN_HWACCEL