26 #include "config_components.h"
61 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 };
92 for (
int i = 0;
i < 3;
i++) {
104 int log2_min_cb_size =
sps->log2_min_cb_size;
107 int pic_size_in_ctb = ((
width >> log2_min_cb_size) + 1) *
108 ((
height >> log2_min_cb_size) + 1);
109 int ctb_count =
sps->ctb_width *
sps->ctb_height;
110 int min_pu_size =
sps->min_pu_width *
sps->min_pu_height;
149 if (
sps->sao_enabled) {
150 int c_count = (
sps->chroma_format_idc != 0) ? 3 : 1;
152 for (
int c_idx = 0; c_idx < c_count; c_idx++) {
153 int w =
sps->width >>
sps->hshift[c_idx];
154 int h =
sps->height >>
sps->vshift[c_idx];
179 int luma_log2_weight_denom;
180 unsigned luma_weight_flags, chroma_weight_flags;
183 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
184 av_log(logctx,
AV_LOG_ERROR,
"luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
188 if (
sps->chroma_format_idc != 0) {
190 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
191 av_log(logctx,
AV_LOG_ERROR,
"chroma_log2_weight_denom %"PRId64
" is invalid\n", chroma_log2_weight_denom);
200 unsigned flag_bit = 1 << (sh->
nb_refs[
L0] - 1 -
i);
202 if (luma_weight_flags & flag_bit) {
204 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
212 if (chroma_weight_flags & flag_bit) {
213 for (j = 0; j < 2; j++) {
217 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
218 || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
237 unsigned flag_bit = 1 << (sh->
nb_refs[
L1] - 1 -
i);
239 if (luma_weight_flags & flag_bit) {
241 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
249 if (chroma_weight_flags & flag_bit) {
250 for (j = 0; j < 2; j++) {
254 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
255 || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
277 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
278 int prev_delta_msb = 0;
279 unsigned int nb_sps = 0, nb_sh;
283 if (!
sps->long_term_ref_pics_present)
286 if (
sps->num_long_term_ref_pics_sps > 0)
290 if (nb_sps >
sps->num_long_term_ref_pics_sps)
300 uint8_t lt_idx_sps = 0;
302 if (
sps->num_long_term_ref_pics_sps > 1)
305 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
306 rps->
used[
i] = !!(
sps->used_by_curr_pic_lt & (1
U << lt_idx_sps));
317 if (
i &&
i != nb_sps)
318 delta += prev_delta_msb;
320 poc = rps->
poc[
i] + cur_poc -
delta * max_poc_lsb - poc_lsb;
324 prev_delta_msb =
delta;
336 unsigned int num = 0, den = 0;
344 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
345 avctx->
level =
sps->ptl.general_ptl.level_idc;
349 if (
sps->vui.common.video_signal_type_present_flag)
355 if (
sps->vui.common.colour_description_present_flag) {
357 avctx->
color_trc =
sps->vui.common.transfer_characteristics;
366 if (
sps->chroma_format_idc == 1) {
367 if (
sps->vui.common.chroma_loc_info_present_flag) {
368 if (
sps->vui.common.chroma_sample_loc_type_top_field <= 5)
374 if (
vps->vps_timing_info_present_flag) {
375 num =
vps->vps_num_units_in_tick;
376 den =
vps->vps_time_scale;
377 }
else if (
sps->vui.vui_timing_info_present_flag) {
378 num =
sps->vui.vui_num_units_in_tick;
379 den =
sps->vui.vui_time_scale;
382 if (num > 0 && den > 0)
391 #if FF_API_CODEC_PROPS
393 if (
s->sei.common.a53_caption.buf_ref)
398 if (
s->sei.common.alternative_transfer.present &&
401 avctx->
color_trc =
s->sei.common.alternative_transfer.preferred_transfer_characteristics;
404 #if FF_API_CODEC_PROPS
406 if ((
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present) ||
407 s->sei.common.aom_film_grain.enable)
420 s->nb_view_ids_available = 0;
422 s->nb_view_pos_available = 0;
425 if (
vps->nb_layers < 2 && !
vps->view_id[0])
428 s->view_ids_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_ids_available));
429 if (!
s->view_ids_available)
433 s->view_pos_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_pos_available));
434 if (!
s->view_pos_available)
438 for (
int i = 0;
i <
vps->nb_layers;
i++) {
439 s->view_ids_available[
i] =
vps->view_id[
i];
441 if (
s->view_pos_available) {
448 s->nb_view_ids_available =
vps->nb_layers;
449 s->nb_view_pos_available =
s->view_pos_available ?
vps->nb_layers : 0;
459 if (
vps->nb_layers != 2 || !
vps->layer_id_in_nuh[1])
475 unsigned layers_active_output = 0, highest_layer;
477 s->layers_active_output = 1;
478 s->layers_active_decode = 1;
486 s->layers_active_decode = (1 <<
vps->nb_layers) - 1;
487 s->layers_active_output = 1;
496 if (
s->nb_view_ids == 1 &&
s->view_ids[0] == -1) {
497 layers_active_output = (1 <<
vps->nb_layers) - 1;
499 for (
int i = 0;
i <
s->nb_view_ids;
i++) {
500 int view_id =
s->view_ids[
i];
505 "Invalid view ID requested: %d\n", view_id);
509 for (
int j = 0; j <
vps->nb_layers; j++) {
510 if (
vps->view_id[j] == view_id) {
517 "View ID %d not present in VPS\n", view_id);
520 layers_active_output |= 1 << layer_idx;
524 if (!layers_active_output) {
529 highest_layer =
ff_log2(layers_active_output);
532 "Too many layers requested: %u\n", layers_active_output);
540 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
541 s->layers_active_output = layers_active_output;
544 s->layers_active_decode,
s->layers_active_output);
579 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
580 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
581 CONFIG_HEVC_D3D12VA_HWACCEL + \
582 CONFIG_HEVC_NVDEC_HWACCEL + \
583 CONFIG_HEVC_VAAPI_HWACCEL + \
584 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
585 CONFIG_HEVC_VDPAU_HWACCEL + \
586 CONFIG_HEVC_VULKAN_HWACCEL)
594 switch (
sps->pix_fmt) {
597 #if CONFIG_HEVC_DXVA2_HWACCEL
600 #if CONFIG_HEVC_D3D11VA_HWACCEL
604 #if CONFIG_HEVC_D3D12VA_HWACCEL
607 #if CONFIG_HEVC_VAAPI_HWACCEL
610 #if CONFIG_HEVC_VDPAU_HWACCEL
613 #if CONFIG_HEVC_NVDEC_HWACCEL
616 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
619 #if CONFIG_HEVC_VULKAN_HWACCEL
624 #if CONFIG_HEVC_DXVA2_HWACCEL
627 #if CONFIG_HEVC_D3D11VA_HWACCEL
631 #if CONFIG_HEVC_D3D12VA_HWACCEL
634 #if CONFIG_HEVC_VAAPI_HWACCEL
637 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
640 #if CONFIG_HEVC_VULKAN_HWACCEL
643 #if CONFIG_HEVC_VDPAU_HWACCEL
646 #if CONFIG_HEVC_NVDEC_HWACCEL
651 #if CONFIG_HEVC_VAAPI_HWACCEL
654 #if CONFIG_HEVC_VDPAU_HWACCEL
657 #if CONFIG_HEVC_NVDEC_HWACCEL
660 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
663 #if CONFIG_HEVC_VULKAN_HWACCEL
669 #if CONFIG_HEVC_VAAPI_HWACCEL
672 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
675 #if CONFIG_HEVC_VULKAN_HWACCEL
678 #if CONFIG_HEVC_NVDEC_HWACCEL
683 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
689 #if CONFIG_HEVC_VAAPI_HWACCEL
692 #if CONFIG_HEVC_VDPAU_HWACCEL
695 #if CONFIG_HEVC_VULKAN_HWACCEL
698 #if CONFIG_HEVC_NVDEC_HWACCEL
703 #if CONFIG_HEVC_VAAPI_HWACCEL
706 #if CONFIG_HEVC_VULKAN_HWACCEL
709 #if CONFIG_HEVC_NVDEC_HWACCEL
717 *fmt++ =
sps->pix_fmt;
729 s->avctx->pix_fmt =
ret;
774 unsigned pps_id, layer_idx;
795 pps =
s->ps.pps_list[pps_id];
798 layer_idx =
vps->layer_idx[
s->nuh_layer_id];
805 int slice_address_length;
807 if (
pps->dependent_slice_segments_enabled_flag)
819 "Invalid slice segment address: %u.\n",
832 for (
i = 0;
i <
pps->num_extra_slice_header_bits;
i++)
844 !
pps->pps_curr_pic_ref_enabled_flag &&
845 s->nuh_layer_id == 0) {
852 if (
pps->output_flag_present_flag)
855 if (
sps->separate_colour_plane)
859 (
s->nuh_layer_id > 0 &&
860 !(
vps->poc_lsb_not_present & (1 << layer_idx)))) {
867 "Ignoring POC change between slices: %d -> %d\n", poc, sh->
poc);
887 int numbits, rps_idx;
889 if (!
sps->nb_st_rps) {
895 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
909 if (
sps->temporal_mvp_enabled)
925 if (
s->nuh_layer_id > 0) {
926 int num_direct_ref_layers =
vps->num_direct_ref_layers[layer_idx];
928 if (
vps->default_ref_layers_active)
930 else if (num_direct_ref_layers) {
935 "NumDirectRefLayers>1 not supported\n");
941 if (
sps->sao_enabled) {
943 if (
sps->chroma_format_idc) {
980 if (
pps->lists_modification_present_flag && nb_refs > 1) {
998 if (
pps->cabac_init_present_flag)
1013 "Invalid collocated_ref_idx: %d.\n",
1030 "Invalid number of merging MVP candidates: %d.\n",
1036 if (
sps->motion_vector_resolution_control_idc == 2)
1046 if (
pps->pic_slice_level_chroma_qp_offsets_present_flag) {
1059 if (
pps->pps_slice_act_qp_offsets_present_flag) {
1065 if (
pps->chroma_qp_offset_list_enabled_flag)
1070 if (
pps->deblocking_filter_control_present_flag) {
1071 int deblocking_filter_override_flag = 0;
1073 if (
pps->deblocking_filter_override_enabled_flag)
1074 deblocking_filter_override_flag =
get_bits1(gb);
1076 if (deblocking_filter_override_flag) {
1081 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1082 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1084 "Invalid deblock filter offsets: %d, %d\n",
1085 beta_offset_div2, tc_offset_div2);
1102 if (
pps->seq_loop_filter_across_slices_enabled_flag &&
1113 if (
pps->tiles_enabled_flag ||
pps->entropy_coding_sync_enabled_flag) {
1116 if (num_entry_point_offsets >
get_bits_left(gb) || num_entry_point_offsets > UINT16_MAX) {
1117 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1125 if (offset_len < 1 || offset_len > 32) {
1149 if (
pps->slice_header_extension_present_flag) {
1155 for (
i = 0;
i < length;
i++)
1177 "The slice_qp %d is outside the valid range "
1180 -
sps->qp_bd_offset);
1195 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1197 #define SET_SAO(elem, value) \
1199 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1200 sao->elem = value; \
1201 else if (sao_merge_left_flag) \
1202 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1203 else if (sao_merge_up_flag) \
1204 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1214 int sao_merge_left_flag = 0;
1215 int sao_merge_up_flag = 0;
1219 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
1220 s->sh.slice_sample_adaptive_offset_flag[1]) {
1225 if (ry > 0 && !sao_merge_left_flag) {
1231 for (c_idx = 0; c_idx < (
sps->chroma_format_idc ? 3 : 1); c_idx++) {
1232 int log2_sao_offset_scale = c_idx == 0 ?
pps->log2_sao_offset_scale_luma :
1233 pps->log2_sao_offset_scale_chroma;
1235 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1250 for (
i = 0;
i < 4;
i++)
1254 for (
i = 0;
i < 4;
i++) {
1263 }
else if (c_idx != 2) {
1269 for (
i = 0;
i < 4;
i++) {
1277 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1289 if (log2_res_scale_abs_plus1 != 0) {
1292 (1 - 2 * res_scale_sign_flag);
1305 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1306 int log2_cb_size,
int log2_trafo_size,
1307 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1310 const int log2_trafo_size_c = log2_trafo_size -
sps->hshift[1];
1314 int trafo_size = 1 << log2_trafo_size;
1317 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, x0, y0, 0);
1320 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1321 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1324 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1325 (
sps->chroma_format_idc == 2 &&
1326 (cbf_cb[1] || cbf_cr[1]));
1338 "The cu_qp_delta %d is outside the valid range "
1341 -(26 +
sps->qp_bd_offset / 2),
1342 (25 +
sps->qp_bd_offset / 2));
1349 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1352 if (cu_chroma_qp_offset_flag) {
1353 int cu_chroma_qp_offset_idx = 0;
1354 if (
pps->chroma_qp_offset_list_len_minus1 > 0) {
1357 "cu_chroma_qp_offset_idx not yet tested.\n");
1390 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1391 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1392 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1393 lc->
tu.
cross_pf = (
pps->cross_component_prediction_enabled_flag && cbf_luma &&
1400 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1403 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1404 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 1);
1408 log2_trafo_size_c, scan_idx_c, 1);
1411 ptrdiff_t
stride =
s->cur_frame->f->linesize[1];
1412 int hshift =
sps->hshift[1];
1413 int vshift =
sps->vshift[1];
1416 int size = 1 << log2_trafo_size_c;
1418 uint8_t *
dst = &
s->cur_frame->f->data[1][(y0 >> vshift) *
stride +
1419 ((x0 >> hshift) <<
sps->pixel_shift)];
1423 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1430 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1433 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1434 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 2);
1438 log2_trafo_size_c, scan_idx_c, 2);
1441 ptrdiff_t
stride =
s->cur_frame->f->linesize[2];
1442 int hshift =
sps->hshift[2];
1443 int vshift =
sps->vshift[2];
1446 int size = 1 << log2_trafo_size_c;
1448 uint8_t *
dst = &
s->cur_frame->f->data[2][(y0 >> vshift) *
stride +
1449 ((x0 >> hshift) <<
sps->pixel_shift)];
1453 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1456 }
else if (
sps->chroma_format_idc && blk_idx == 3) {
1457 int trafo_size_h = 1 << (log2_trafo_size + 1);
1458 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1459 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1462 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1463 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 1);
1467 log2_trafo_size, scan_idx_c, 1);
1469 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1472 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1473 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 2);
1477 log2_trafo_size, scan_idx_c, 2);
1481 if (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3) {
1482 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1483 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1485 sps->log2_ctb_size);
1486 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 1);
1487 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 2);
1488 if (
sps->chroma_format_idc == 2) {
1490 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1491 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1492 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1494 }
else if (blk_idx == 3) {
1495 int trafo_size_h = 1 << (log2_trafo_size + 1);
1496 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1498 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1499 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 1);
1500 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 2);
1501 if (
sps->chroma_format_idc == 2) {
1503 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1504 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 1);
1505 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 2);
1514 int x0,
int y0,
int log2_cb_size)
1516 int cb_size = 1 << log2_cb_size;
1517 int log2_min_pu_size =
sps->log2_min_pu_size;
1519 int min_pu_width =
sps->min_pu_width;
1520 int x_end =
FFMIN(x0 + cb_size,
sps->width);
1521 int y_end =
FFMIN(y0 + cb_size,
sps->height);
1524 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1525 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1526 is_pcm[
i + j * min_pu_width] = 2;
1533 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1534 int log2_cb_size,
int log2_trafo_size,
1535 int trafo_depth,
int blk_idx,
1536 const int *base_cbf_cb,
const int *base_cbf_cr)
1539 uint8_t split_transform_flag;
1544 cbf_cb[0] = base_cbf_cb[0];
1545 cbf_cb[1] = base_cbf_cb[1];
1546 cbf_cr[0] = base_cbf_cr[0];
1547 cbf_cr[1] = base_cbf_cr[1];
1550 if (trafo_depth == 1) {
1552 if (
sps->chroma_format_idc == 3) {
1566 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1567 log2_trafo_size >
sps->log2_min_tb_size &&
1568 trafo_depth < lc->cu.max_trafo_depth &&
1572 int inter_split =
sps->max_transform_hierarchy_depth_inter == 0 &&
1577 split_transform_flag = log2_trafo_size >
sps->log2_max_trafo_size ||
1582 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1583 if (trafo_depth == 0 || cbf_cb[0]) {
1585 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1590 if (trafo_depth == 0 || cbf_cr[0]) {
1592 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1598 if (split_transform_flag) {
1599 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1600 const int x1 = x0 + trafo_size_split;
1601 const int y1 = y0 + trafo_size_split;
1603 #define SUBDIVIDE(x, y, idx) \
1605 ret = hls_transform_tree(lc, l, pps, sps, \
1606 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1607 log2_trafo_size - 1, trafo_depth + 1, idx, \
1620 int min_tu_size = 1 <<
sps->log2_min_tb_size;
1621 int log2_min_tu_size =
sps->log2_min_tb_size;
1622 int min_tu_width =
sps->min_tb_width;
1626 cbf_cb[0] || cbf_cr[0] ||
1627 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1632 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1633 log2_cb_size, log2_trafo_size,
1634 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1640 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1641 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1642 int x_tu = (x0 + j) >> log2_min_tu_size;
1643 int y_tu = (y0 +
i) >> log2_min_tu_size;
1644 l->
cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1647 if (!
s->sh.disable_deblocking_filter_flag) {
1649 if (
pps->transquant_bypass_enable_flag &&
1658 const HEVCPPS *
pps,
int x0,
int y0,
int log2_cb_size)
1663 int cb_size = 1 << log2_cb_size;
1664 ptrdiff_t stride0 =
s->cur_frame->f->linesize[0];
1665 ptrdiff_t stride1 =
s->cur_frame->f->linesize[1];
1666 ptrdiff_t stride2 =
s->cur_frame->f->linesize[2];
1667 uint8_t *dst0 = &
s->cur_frame->f->data[0][y0 * stride0 + (x0 <<
sps->pixel_shift)];
1668 uint8_t *dst1 = &
s->cur_frame->f->data[1][(y0 >>
sps->vshift[1]) * stride1 + ((x0 >>
sps->hshift[1]) <<
sps->pixel_shift)];
1669 uint8_t *dst2 = &
s->cur_frame->f->data[2][(y0 >>
sps->vshift[2]) * stride2 + ((x0 >>
sps->hshift[2]) <<
sps->pixel_shift)];
1671 int length = cb_size * cb_size *
sps->pcm.bit_depth +
1672 (((cb_size >>
sps->hshift[1]) * (cb_size >>
sps->vshift[1])) +
1673 ((cb_size >>
sps->hshift[2]) * (cb_size >>
sps->vshift[2]))) *
1674 sps->pcm.bit_depth_chroma;
1675 const uint8_t *pcm =
skip_bytes(&lc->
cc, (length + 7) >> 3);
1678 if (!
s->sh.disable_deblocking_filter_flag)
1685 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
sps->pcm.bit_depth);
1686 if (
sps->chroma_format_idc) {
1687 s->hevcdsp.put_pcm(dst1, stride1,
1688 cb_size >>
sps->hshift[1],
1689 cb_size >>
sps->vshift[1],
1690 &gb,
sps->pcm.bit_depth_chroma);
1691 s->hevcdsp.put_pcm(dst2, stride2,
1692 cb_size >>
sps->hshift[2],
1693 cb_size >>
sps->vshift[2],
1694 &gb,
sps->pcm.bit_depth_chroma);
1718 uint8_t *
dst, ptrdiff_t dststride,
1720 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1723 const uint8_t *
src =
ref->data[0];
1725 int pic_width =
sps->width;
1726 int pic_height =
sps->height;
1729 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1733 x_off +=
mv->x >> 2;
1734 y_off +=
mv->y >> 2;
1740 ref ==
s->cur_frame->f) {
1750 pic_width, pic_height);
1757 block_h,
mx,
my, block_w);
1760 block_h,
s->sh.luma_log2_weight_denom,
1761 luma_weight, luma_offset,
mx,
my, block_w);
1782 uint8_t *
dst, ptrdiff_t dststride,
1783 const AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1784 int block_w,
int block_h,
const AVFrame *ref1,
1785 const Mv *mv1,
struct MvField *current_mv)
1788 ptrdiff_t src0stride = ref0->
linesize[0];
1789 ptrdiff_t src1stride = ref1->
linesize[0];
1790 int pic_width =
sps->width;
1791 int pic_height =
sps->height;
1792 int mx0 = mv0->
x & 3;
1793 int my0 = mv0->
y & 3;
1794 int mx1 = mv1->
x & 3;
1795 int my1 = mv1->
y & 3;
1796 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1798 int x_off0 = x_off + (mv0->
x >> 2);
1799 int y_off0 = y_off + (mv0->
y >> 2);
1800 int x_off1 = x_off + (mv1->
x >> 2);
1801 int y_off1 = y_off + (mv1->
y >> 2);
1804 const uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1805 const uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1815 edge_emu_stride, src0stride,
1819 pic_width, pic_height);
1821 src0stride = edge_emu_stride;
1832 edge_emu_stride, src1stride,
1836 pic_width, pic_height);
1838 src1stride = edge_emu_stride;
1841 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1842 block_h, mx0, my0, block_w);
1844 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1845 block_h, mx1, my1, block_w);
1847 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1848 block_h,
s->sh.luma_log2_weight_denom,
1849 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1850 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1851 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1852 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1877 ptrdiff_t dststride,
const uint8_t *
src0, ptrdiff_t
srcstride,
int reflist,
1878 int x_off,
int y_off,
int block_w,
int block_h,
1879 const struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1882 int pic_width =
sps->width >>
sps->hshift[1];
1883 int pic_height =
sps->height >>
sps->vshift[1];
1884 const Mv *
mv = ¤t_mv->
mv[reflist];
1885 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1888 int hshift =
sps->hshift[1];
1889 int vshift =
sps->vshift[1];
1892 intptr_t _mx =
mx << (1 - hshift);
1893 intptr_t _my =
my << (1 - vshift);
1894 int emu =
src0 ==
s->cur_frame->f->data[1] ||
src0 ==
s->cur_frame->f->data[2];
1896 x_off +=
mv->x >> (2 + hshift);
1897 y_off +=
mv->y >> (2 + vshift);
1907 (edge_emu_stride + (1 <<
sps->pixel_shift));
1913 pic_width, pic_height);
1920 block_h, _mx, _my, block_w);
1923 block_h,
s->sh.chroma_log2_weight_denom,
1924 chroma_weight, chroma_offset, _mx, _my, block_w);
1946 uint8_t *dst0, ptrdiff_t dststride,
1948 int x_off,
int y_off,
int block_w,
int block_h,
const MvField *current_mv,
int cidx)
1951 const uint8_t *
src1 = ref0->
data[cidx+1];
1952 const uint8_t *
src2 = ref1->
data[cidx+1];
1953 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1954 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1955 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1957 int pic_width =
sps->width >>
sps->hshift[1];
1958 int pic_height =
sps->height >>
sps->vshift[1];
1959 const Mv *
const mv0 = ¤t_mv->
mv[0];
1960 const Mv *
const mv1 = ¤t_mv->
mv[1];
1961 int hshift =
sps->hshift[1];
1962 int vshift =
sps->vshift[1];
1968 intptr_t _mx0 = mx0 << (1 - hshift);
1969 intptr_t _my0 = my0 << (1 - vshift);
1970 intptr_t _mx1 = mx1 << (1 - hshift);
1971 intptr_t _my1 = my1 << (1 - vshift);
1973 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1974 int y_off0 = y_off + (mv0->
y >> (2 + vshift));
1975 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1976 int y_off1 = y_off + (mv1->
y >> (2 + vshift));
1978 src1 += y_off0 * src1stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1979 src2 += y_off1 * src2stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1987 (edge_emu_stride + (1 <<
sps->pixel_shift));
1990 edge_emu_stride, src1stride,
1994 pic_width, pic_height);
1997 src1stride = edge_emu_stride;
2006 (edge_emu_stride + (1 <<
sps->pixel_shift));
2009 edge_emu_stride, src2stride,
2013 pic_width, pic_height);
2016 src2stride = edge_emu_stride;
2019 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
2020 block_h, _mx0, _my0, block_w);
2022 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
2024 block_h, _mx1, _my1, block_w);
2026 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
2029 s->sh.chroma_log2_weight_denom,
2030 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
2031 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
2032 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
2033 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
2034 _mx1, _my1, block_w);
2049 int x0,
int y0,
int nPbW,
2050 int nPbH,
int log2_cb_size,
int part_idx,
2062 if (inter_pred_idc !=
PRED_L1) {
2063 if (
s->sh.nb_refs[
L0])
2070 part_idx, merge_idx,
mv, mvp_flag, 0);
2075 if (inter_pred_idc !=
PRED_L0) {
2076 if (
s->sh.nb_refs[
L1])
2079 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
2088 part_idx, merge_idx,
mv, mvp_flag, 1);
2097 int x0,
int y0,
int nPbW,
int nPbH,
2098 int log2_cb_size,
int partIdx,
int idx)
2100 #define POS(c_idx, x, y) \
2101 s->cur_frame->f->data[c_idx] ? \
2102 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2103 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)] : NULL
2106 struct MvField current_mv = {{{ 0 }}};
2108 int min_pu_width =
sps->min_pu_width;
2110 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2111 const RefPicList *refPicList =
s->cur_frame->refPicList;
2113 const int *linesize =
s->cur_frame->f->linesize;
2114 uint8_t *dst0 =
s->cur_frame->f->data[0] + y0 * linesize[0] + (x0 <<
sps->pixel_shift);
2115 uint8_t *dst1 =
POS(1, x0, y0);
2116 uint8_t *dst2 =
POS(2, x0, y0);
2117 int log2_min_cb_size =
sps->log2_min_cb_size;
2118 int min_cb_width =
sps->min_cb_width;
2119 int x_cb = x0 >> log2_min_cb_size;
2120 int y_cb = y0 >> log2_min_cb_size;
2130 if (
s->sh.max_num_merge_cand > 1)
2136 partIdx, merge_idx, ¤t_mv);
2139 partIdx, merge_idx, ¤t_mv);
2142 x_pu = x0 >>
sps->log2_min_pu_size;
2143 y_pu = y0 >>
sps->log2_min_pu_size;
2145 for (j = 0; j < nPbH >>
sps->log2_min_pu_size; j++)
2146 for (
i = 0; i < nPbW >>
sps->log2_min_pu_size;
i++)
2147 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
2150 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
2151 if (!ref0 || !ref0->
f)
2156 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
2157 if (!ref1 || !ref1->f)
2163 int x0_c = x0 >>
sps->hshift[1];
2164 int y0_c = y0 >>
sps->vshift[1];
2165 int nPbW_c = nPbW >>
sps->hshift[1];
2166 int nPbH_c = nPbH >>
sps->vshift[1];
2169 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2170 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
2171 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
2173 if (
sps->chroma_format_idc) {
2175 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2176 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
2178 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2179 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
2182 int x0_c = x0 >>
sps->hshift[1];
2183 int y0_c = y0 >>
sps->vshift[1];
2184 int nPbW_c = nPbW >>
sps->hshift[1];
2185 int nPbH_c = nPbH >>
sps->vshift[1];
2188 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
2189 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
2190 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
2192 if (
sps->chroma_format_idc) {
2194 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2195 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
2198 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2199 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
2202 int x0_c = x0 >>
sps->hshift[1];
2203 int y0_c = y0 >>
sps->vshift[1];
2204 int nPbW_c = nPbW >>
sps->hshift[1];
2205 int nPbH_c = nPbH >>
sps->vshift[1];
2208 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2209 ref1->f, ¤t_mv.
mv[1], ¤t_mv);
2211 if (
sps->chroma_format_idc) {
2213 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
2216 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
2226 int x0,
int y0,
int pu_size,
2227 int prev_intra_luma_pred_flag)
2230 int x_pu = x0 >>
sps->log2_min_pu_size;
2231 int y_pu = y0 >>
sps->log2_min_pu_size;
2232 int min_pu_width =
sps->min_pu_width;
2233 int size_in_pus = pu_size >>
sps->log2_min_pu_size;
2242 int y_ctb = (y0 >> (
sps->log2_ctb_size)) << (
sps->log2_ctb_size);
2244 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2245 int intra_pred_mode;
2250 if ((y0 - 1) < y_ctb)
2253 if (cand_left == cand_up) {
2254 if (cand_left < 2) {
2259 candidate[0] = cand_left;
2260 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2261 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2264 candidate[0] = cand_left;
2265 candidate[1] = cand_up;
2275 if (prev_intra_luma_pred_flag) {
2276 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
2278 if (candidate[0] > candidate[1])
2279 FFSWAP(uint8_t, candidate[0], candidate[1]);
2280 if (candidate[0] > candidate[2])
2281 FFSWAP(uint8_t, candidate[0], candidate[2]);
2282 if (candidate[1] > candidate[2])
2283 FFSWAP(uint8_t, candidate[1], candidate[2]);
2286 for (
i = 0;
i < 3;
i++)
2287 if (intra_pred_mode >= candidate[
i])
2294 for (
i = 0;
i < size_in_pus;
i++) {
2295 memset(&l->
tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
2296 intra_pred_mode, size_in_pus);
2298 for (j = 0; j < size_in_pus; j++) {
2303 return intra_pred_mode;
2308 int log2_cb_size,
int ct_depth)
2310 int length = (1 << log2_cb_size) >>
sps->log2_min_cb_size;
2311 int x_cb = x0 >>
sps->log2_min_cb_size;
2312 int y_cb = y0 >>
sps->log2_min_cb_size;
2315 for (y = 0; y < length; y++)
2316 memset(&tab_ct_depth[(y_cb + y) *
sps->min_cb_width + x_cb],
2321 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2322 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2329 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2330 uint8_t prev_intra_luma_pred_flag[4];
2332 int pb_size = (1 << log2_cb_size) >>
split;
2333 int side =
split + 1;
2337 for (
i = 0;
i < side;
i++)
2338 for (j = 0; j < side; j++)
2341 for (
i = 0;
i < side;
i++) {
2342 for (j = 0; j < side; j++) {
2343 if (prev_intra_luma_pred_flag[2 *
i + j])
2350 x0 + pb_size * j, y0 + pb_size *
i, pb_size,
2351 prev_intra_luma_pred_flag[2 *
i + j]);
2355 if (
sps->chroma_format_idc == 3) {
2356 for (
i = 0;
i < side;
i++) {
2357 for (j = 0; j < side; j++) {
2359 if (chroma_mode != 4) {
2369 }
else if (
sps->chroma_format_idc == 2) {
2372 if (chroma_mode != 4) {
2376 mode_idx = intra_chroma_table[chroma_mode];
2381 }
else if (
sps->chroma_format_idc != 0) {
2383 if (chroma_mode != 4) {
2401 int pb_size = 1 << log2_cb_size;
2402 int size_in_pus = pb_size >>
sps->log2_min_pu_size;
2403 int min_pu_width =
sps->min_pu_width;
2404 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2405 int x_pu = x0 >>
sps->log2_min_pu_size;
2406 int y_pu = y0 >>
sps->log2_min_pu_size;
2409 if (size_in_pus == 0)
2411 for (j = 0; j < size_in_pus; j++)
2412 memset(&l->
tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2414 for (j = 0; j < size_in_pus; j++)
2415 for (k = 0; k < size_in_pus; k++)
2422 int x0,
int y0,
int log2_cb_size)
2424 int cb_size = 1 << log2_cb_size;
2425 int log2_min_cb_size =
sps->log2_min_cb_size;
2426 int length = cb_size >> log2_min_cb_size;
2427 int min_cb_width =
sps->min_cb_width;
2428 int x_cb = x0 >> log2_min_cb_size;
2429 int y_cb = y0 >> log2_min_cb_size;
2430 int idx = log2_cb_size - 2;
2431 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2441 for (x = 0; x < 4; x++)
2443 if (
pps->transquant_bypass_enable_flag) {
2454 x0b, y0b, x_cb, y_cb,
2457 x = y_cb * min_cb_width + x_cb;
2458 for (y = 0; y < length; y++) {
2459 memset(&l->
skip_flag[x], skip_flag, length);
2464 x = y_cb * min_cb_width + x_cb;
2465 for (y = 0; y < length; y++) {
2473 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2476 if (!
s->sh.disable_deblocking_filter_flag)
2484 log2_cb_size ==
sps->log2_min_cb_size) {
2492 log2_cb_size >=
sps->pcm.log2_min_pcm_cb_size &&
2493 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2499 if (
sps->pcm_loop_filter_disabled)
2512 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2516 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2518 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2522 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2524 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2528 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2530 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2534 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2536 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2540 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2542 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2546 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2548 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2552 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2554 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2556 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2558 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2564 int rqt_root_cbf = 1;
2571 const static int cbf[2] = { 0 };
2574 sps->max_transform_hierarchy_depth_inter;
2575 ret =
hls_transform_tree(lc, l,
pps,
sps, x0, y0, x0, y0, x0, y0,
2577 log2_cb_size, 0, 0, cbf, cbf);
2581 if (!
s->sh.disable_deblocking_filter_flag)
2590 x = y_cb * min_cb_width + x_cb;
2591 for (y = 0; y < length; y++) {
2596 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2597 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2610 int log2_cb_size,
int cb_depth)
2613 const int cb_size = 1 << log2_cb_size;
2618 if (x0 + cb_size <= sps->
width &&
2619 y0 + cb_size <= sps->
height &&
2620 log2_cb_size >
sps->log2_min_cb_size) {
2622 sps, cb_depth, x0, y0);
2624 split_cu = (log2_cb_size >
sps->log2_min_cb_size);
2626 if (
pps->cu_qp_delta_enabled_flag &&
2627 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth) {
2632 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2633 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_chroma_qp_offset_depth) {
2638 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2639 const int cb_size_split = cb_size >> 1;
2640 const int x1 = x0 + cb_size_split;
2641 const int y1 = y0 + cb_size_split;
2646 x0, y0, log2_cb_size - 1, cb_depth + 1);
2650 if (more_data && x1 < sps->
width) {
2652 x1, y0, log2_cb_size - 1, cb_depth + 1);
2656 if (more_data && y1 < sps->
height) {
2658 x0, y1, log2_cb_size - 1, cb_depth + 1);
2662 if (more_data && x1 < sps->
width &&
2665 x1, y1, log2_cb_size - 1, cb_depth + 1);
2670 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2671 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2675 return ((x1 + cb_size_split) <
sps->width ||
2676 (y1 + cb_size_split) <
sps->height);
2683 if ((!((x0 + cb_size) %
2684 (1 << (
sps->log2_ctb_size))) ||
2685 (x0 + cb_size >=
sps->width)) &&
2687 (1 << (
sps->log2_ctb_size))) ||
2688 (y0 + cb_size >=
sps->height))) {
2690 return !end_of_slice_flag;
2702 int x_ctb,
int y_ctb,
int ctb_addr_ts)
2705 int ctb_size = 1 <<
sps->log2_ctb_size;
2706 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2707 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2711 if (
pps->entropy_coding_sync_enabled_flag) {
2712 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2715 }
else if (
pps->tiles_enabled_flag) {
2716 if (ctb_addr_ts &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[ctb_addr_ts - 1]) {
2717 int idxX =
pps->col_idxX[x_ctb >>
sps->log2_ctb_size];
2728 if (
pps->tiles_enabled_flag) {
2729 if (x_ctb > 0 &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2733 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]])
2738 if (ctb_addr_in_slice <= 0)
2740 if (ctb_addr_in_slice < sps->ctb_width)
2746 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]]));
2747 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]]));
2756 const uint8_t *slice_data = gb->
buffer +
s->sh.data_offset;
2758 int ctb_size = 1 <<
sps->log2_ctb_size;
2762 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2765 while (more_data && ctb_addr_ts < sps->ctb_size) {
2766 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2768 x_ctb = (ctb_addr_rs % ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2769 y_ctb = (ctb_addr_rs / ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2779 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2786 if (more_data < 0) {
2797 if (x_ctb + ctb_size >=
sps->width &&
2798 y_ctb + ctb_size >=
sps->height)
2805 int job,
int thread)
2812 int ctb_size = 1 <<
sps->log2_ctb_size;
2815 int ctb_addr_rs =
s->sh.slice_ctb_addr_rs + ctb_row * ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size);
2816 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2818 const uint8_t *
data =
s->data +
s->sh.offset[ctb_row];
2819 const size_t data_size =
s->sh.size[ctb_row];
2828 while(more_data && ctb_addr_ts < sps->ctb_size) {
2829 int x_ctb = (ctb_addr_rs %
sps->ctb_width) <<
sps->log2_ctb_size;
2830 int y_ctb = (ctb_addr_rs /
sps->ctb_width) <<
sps->log2_ctb_size;
2850 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2858 if (more_data < 0) {
2869 if (!more_data && (x_ctb+ctb_size) <
sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2876 if ((x_ctb+ctb_size) >=
sps->width && (y_ctb+ctb_size) >=
sps->height ) {
2881 ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2884 if(x_ctb >=
sps->width) {
2901 if (
s->nb_wpp_progress < count) {
2903 sizeof(*
s->wpp_progress));
2907 s->wpp_progress =
tmp;
2908 memset(
s->wpp_progress +
s->nb_wpp_progress, 0,
2909 (count -
s->nb_wpp_progress) *
sizeof(*
s->wpp_progress));
2911 for (
int i =
s->nb_wpp_progress;
i < count;
i++) {
2915 s->nb_wpp_progress =
i + 1;
2919 for (
int i = 0;
i < count;
i++)
2930 int length = nal->
size;
2933 int64_t startheader, cmpt = 0;
2936 if (
s->sh.slice_ctb_addr_rs +
s->sh.num_entry_point_offsets *
sps->ctb_width >=
sps->ctb_width *
sps->ctb_height) {
2938 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2939 sps->ctb_width,
sps->ctb_height
2944 if (
s->avctx->thread_count >
s->nb_local_ctx) {
2950 memcpy(
tmp,
s->local_ctx,
sizeof(*
s->local_ctx) *
s->nb_local_ctx);
2954 for (
unsigned i =
s->nb_local_ctx; i < s->avctx->thread_count;
i++) {
2955 tmp = &
s->local_ctx[
i];
2957 memset(
tmp, 0,
sizeof(*
tmp));
2959 tmp->logctx =
s->avctx;
2961 tmp->common_cabac_state = &
s->cabac;
2964 s->nb_local_ctx =
s->avctx->thread_count;
2969 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2976 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2977 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2978 for (j = 0, cmpt = 0, startheader =
offset
2979 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2985 s->sh.size[
i] =
s->sh.entry_point_offset[
i] - cmpt;
2990 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2995 s->sh.size [
s->sh.num_entry_point_offsets] = length -
offset;
2996 s->sh.offset[
s->sh.num_entry_point_offsets] =
offset;
2998 s->sh.offset[0] =
s->sh.data_offset;
2999 s->sh.size[0] =
s->sh.offset[1] -
s->sh.offset[0];
3003 for (
i = 1;
i <
s->nb_local_ctx;
i++) {
3004 s->local_ctx[
i].first_qp_group = 1;
3005 s->local_ctx[
i].qp_y =
s->local_ctx[0].qp_y;
3017 if (
pps->entropy_coding_sync_enabled_flag)
3020 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
3033 if (!
s->sh.first_slice_in_pic_flag)
3034 s->slice_idx += !
s->sh.dependent_slice_segment_flag;
3036 if (!
s->sh.dependent_slice_segment_flag &&
s->sh.slice_type !=
HEVC_SLICE_I) {
3040 "Error constructing the reference lists for the current slice.\n");
3045 s->slice_initialized = 1;
3047 if (
s->avctx->hwaccel)
3052 "SCC profile is not yet implemented in hevc native decoder.\n");
3056 if (
s->sh.dependent_slice_segment_flag) {
3057 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
3058 int prev_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
3065 s->local_ctx[0].first_qp_group = !
s->sh.dependent_slice_segment_flag;
3067 if (!
pps->cu_qp_delta_enabled_flag)
3068 s->local_ctx[0].qp_y =
s->sh.slice_qp;
3070 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3071 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3074 s->sh.num_entry_point_offsets > 0 &&
3075 pps->num_tile_rows == 1 &&
pps->num_tile_columns == 1)
3090 if (
IS_IRAP(
s) &&
s->no_rasl_output_flag) {
3091 if (
s->sei.common.mastering_display.present > 0)
3092 s->sei.common.mastering_display.present--;
3094 if (
s->sei.common.content_light.present > 0)
3095 s->sei.common.content_light.present--;
3100 sps->bit_depth,
sps->bit_depth_chroma,
3101 s->cur_frame->poc );
3105 if (
s->sei.timecode.present) {
3110 sizeof(uint32_t) * 4, &tcside);
3115 tc_sd = (uint32_t*)tcside->
data;
3116 tc_sd[0] =
s->sei.timecode.num_clock_ts;
3118 for (
int i = 0;
i < tc_sd[0];
i++) {
3119 int drop =
s->sei.timecode.cnt_dropped_flag[
i];
3120 int hh =
s->sei.timecode.hours_value[
i];
3121 int mm =
s->sei.timecode.minutes_value[
i];
3122 int ss =
s->sei.timecode.seconds_value[
i];
3123 int ff =
s->sei.timecode.n_frames[
i];
3131 s->sei.timecode.num_clock_ts = 0;
3134 if (
s->sei.common.dynamic_hdr_plus.info) {
3155 if (
s->sei.common.dynamic_hdr_vivid.info) {
3158 &
s->sei.common.dynamic_hdr_vivid.info,
3170 for (
int i = nal_idx;
i <
s->pkt.nb_nals;
i++) {
3176 !(
s->layers_active_decode & (1 <<
s->vps->layer_idx[layer_id])))
3179 switch (nal->
type) {
3212 const HEVCPPS *
const pps =
s->ps.pps_list[
s->sh.pps_id];
3214 int pic_size_in_ctb = ((
sps->width >>
sps->log2_min_cb_size) + 1) *
3215 ((
sps->height >>
sps->log2_min_cb_size) + 1);
3216 int new_sequence = (l == &
s->layers[0]) &&
3218 int prev_layers_active_decode =
s->layers_active_decode;
3219 int prev_layers_active_output =
s->layers_active_output;
3222 if (
sps->vps !=
s->vps && l != &
s->layers[0]) {
3230 const HEVCSPS *sps_base =
s->layers[0].sps;
3233 if (l != &
s->layers[0]) {
3236 "Access unit starts with a non-base layer frame\n");
3245 !
sps->vui.common.video_signal_type_present_flag)
3258 "Base/non-base layer SPS have unsupported parameter combination\n");
3269 if (l == &
s->layers[0]) {
3285 memset(l->
is_pcm, 0, (
sps->min_pu_width + 1) * (
sps->min_pu_height + 1));
3292 s->first_nal_type =
s->nal_unit_type;
3302 s->sei.recovery_point.has_recovery_poc) {
3304 s->recovery_poc =
s->poc +
s->sei.recovery_point.recovery_poc_cnt;
3305 else if (
s->poc >=
s->recovery_poc)
3310 if (
s->temporal_id == 0 &&
3318 s->poc_tid0 =
s->poc;
3320 if (
pps->tiles_enabled_flag)
3321 s->local_ctx[0].end_of_tiles_x =
pps->column_width[0] <<
sps->log2_ctb_size;
3325 0, 0,
s->sh.no_output_of_prior_pics_flag);
3349 s->cur_frame->needs_fg = ((
s->sei.common.film_grain_characteristics &&
3350 s->sei.common.film_grain_characteristics->present) ||
3351 s->sei.common.aom_film_grain.enable) &&
3359 if (
s->cur_frame->needs_fg &&
3360 (
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present &&
3362 s->cur_frame->f->format) ||
3365 "Unsupported film grain parameters. Ignoring film grain.\n");
3366 s->cur_frame->needs_fg = 0;
3369 if (
s->cur_frame->needs_fg) {
3370 s->cur_frame->frame_grain->format =
s->cur_frame->f->format;
3371 s->cur_frame->frame_grain->width =
s->cur_frame->f->width;
3372 s->cur_frame->frame_grain->height =
s->cur_frame->f->height;
3381 s->cur_frame->f->pict_type = 3 -
s->sh.slice_type;
3384 sps->temporal_layer[
sps->max_sub_layers - 1].num_reorder_pics,
3385 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3389 if (
s->avctx->hwaccel) {
3401 if (l == &
s->layers[0])
3404 if (nal_idx >=
s->finish_setup_nal_idx)
3413 s->cur_frame =
s->collocated_ref =
NULL;
3420 char msg_buf[4 * (50 + 2 * 2 * 16 )];
3428 pixel_shift =
desc->comp[0].depth > 8;
3433 if (pixel_shift && !
s->checksum_buf) {
3436 frame->linesize[2]));
3437 if (!
s->checksum_buf)
3444 int width =
s->avctx->coded_width;
3445 int height =
s->avctx->coded_height;
3451 for (j = 0; j <
h; j++) {
3455 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3456 (
const uint16_t *)
src,
w);
3457 src =
s->checksum_buf;
3464 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3465 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3467 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3469 "plane %d - correct " MD5_PRI "; ",
3473 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3480 "Verifying checksum for frame with POC %d: %s\n",
3492 if (
out->needs_fg) {
3495 switch (fgp->
type) {
3509 if (
s->avctx->hwaccel) {
3513 "hardware accelerator failed to decode picture\n");
3518 s->sei.picture_hash.is_md5) {
3524 s->sei.picture_hash.is_md5 = 0;
3527 l -
s->layers,
s->poc);
3534 const int layer_idx =
s->vps ?
s->vps->layer_idx[
s->nuh_layer_id] : 0;
3541 if (layer_idx < 0 ||
3542 (
s->nuh_layer_id > 0 && !(
s->layers_active_decode & (1 << layer_idx))))
3549 s->slice_initialized = 0;
3558 s->no_rasl_output_flag)) {
3563 if (
s->cur_layer != layer_idx &&
3564 s->layers[
s->cur_layer].cur_frame &&
3568 s->cur_layer = layer_idx;
3569 l = &
s->layers[
s->cur_layer];
3571 if (
s->sh.first_slice_in_pic_flag) {
3573 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
3585 if (
s->nal_unit_type !=
s->first_nal_type) {
3587 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3588 s->first_nal_type,
s->nal_unit_type);
3605 s->nal_unit_type = nal->
type;
3621 switch (
s->nal_unit_type) {
3672 "Skipping NAL unit %d\n",
s->nal_unit_type);
3680 "Skipping invalid undecodable NALU: %d\n",
s->nal_unit_type);
3689 s->sei.recovery_point.has_recovery_poc = 0;
3695 int eos_at_start = 1;
3698 s->cur_frame =
s->collocated_ref =
NULL;
3699 s->last_eos =
s->eos;
3701 s->slice_initialized = 0;
3713 s->nal_length_size,
s->avctx->codec_id,
flags);
3716 "Error splitting the input into NAL units.\n");
3720 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3743 s->pkt.nals[
s->pkt.nb_nals - 1].size > 2 && !
s->pkt.nals[
s->pkt.nb_nals - 1].nuh_layer_id
3744 && !
s->pkt.nals[
s->pkt.nb_nals - 1].temporal_id) {
3745 H2645NAL *nal = &
s->pkt.nals[
s->pkt.nb_nals - 1];
3748 av_log(
s->avctx,
AV_LOG_WARNING,
"Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3759 s->avctx->err_recognition);
3768 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3778 "Error parsing NAL unit #%d.\n",
i);
3805 &
s->nal_length_size,
s->avctx->err_recognition,
3806 s->apply_defdispwin,
s->avctx);
3812 if (
first &&
s->ps.sps_list[
i]) {
3851 s->layers_active_output, 0, 0, 0);
3858 s->pkt_dts = avpkt->
dts;
3861 if (sd && sd_size > 0) {
3868 if (sd && sd_size >=
sizeof(
s->dovi_ctx.cfg)) {
3869 int old =
s->dovi_ctx.cfg.dv_profile;
3873 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3874 old,
s->dovi_ctx.cfg.dv_profile);
3898 if (
src->needs_fg) {
3911 dst->nb_rpl_elems =
src->nb_rpl_elems;
3914 dst->ctb_count =
src->ctb_count;
3917 dst->base_layer_frame =
src->base_layer_frame;
3920 src->hwaccel_picture_private);
3954 for (
int i = 0;
i <
s->nb_wpp_progress;
i++)
3980 s->nb_local_ctx = 1;
3982 s->local_ctx[0].parent =
s;
3983 s->local_ctx[0].logctx = avctx;
3984 s->local_ctx[0].common_cabac_state = &
s->cabac;
3987 if (!
s->output_fifo)
4005 s->dovi_ctx.logctx = avctx;
4064 memcmp(
s->view_ids, s0->
view_ids,
sizeof(*
s->view_ids) *
s->nb_view_ids)) {
4111 if (
sei->tdrdi.present) {
4125 tdrdi->prec_ref_display_width =
sei->tdrdi.prec_ref_display_width;
4126 tdrdi->ref_viewing_distance_flag =
sei->tdrdi.ref_viewing_distance_flag;
4127 tdrdi->prec_ref_viewing_dist =
sei->tdrdi.prec_ref_viewing_dist;
4128 tdrdi->num_ref_displays =
sei->tdrdi.num_ref_displays;
4129 for (
int i = 0;
i <
sei->tdrdi.num_ref_displays;
i++) {
4165 s->sei.picture_timing.picture_struct = 0;
4185 if (sd && sd->
size >=
sizeof(
s->dovi_ctx.cfg))
4205 #define OFFSET(x) offsetof(HEVCContext, x)
4206 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4209 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
4211 {
"strict-displaywin",
"strictly apply default display window size",
OFFSET(apply_defdispwin),
4213 {
"view_ids",
"Array of view IDs that should be decoded and output; a single -1 to decode all views",
4215 .min = -1, .max = INT_MAX, .flags =
PAR },
4216 {
"view_ids_available",
"Array of available view IDs is exported here",
4219 {
"view_pos_available",
"Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4255 #if CONFIG_HEVC_DXVA2_HWACCEL
4258 #if CONFIG_HEVC_D3D11VA_HWACCEL
4261 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4264 #if CONFIG_HEVC_D3D12VA_HWACCEL
4267 #if CONFIG_HEVC_NVDEC_HWACCEL
4270 #if CONFIG_HEVC_VAAPI_HWACCEL
4273 #if CONFIG_HEVC_VDPAU_HWACCEL
4276 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4279 #if CONFIG_HEVC_VULKAN_HWACCEL