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 uint8_t luma_weight_l0_flag[16];
178 uint8_t chroma_weight_l0_flag[16];
179 uint8_t luma_weight_l1_flag[16];
180 uint8_t chroma_weight_l1_flag[16];
181 int luma_log2_weight_denom;
184 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
185 av_log(logctx,
AV_LOG_ERROR,
"luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
189 if (
sps->chroma_format_idc != 0) {
191 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
192 av_log(logctx,
AV_LOG_ERROR,
"chroma_log2_weight_denom %"PRId64
" is invalid\n", chroma_log2_weight_denom);
200 if (!luma_weight_l0_flag[
i]) {
205 if (
sps->chroma_format_idc != 0) {
210 chroma_weight_l0_flag[
i] = 0;
213 if (luma_weight_l0_flag[
i]) {
215 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
220 if (chroma_weight_l0_flag[
i]) {
221 for (j = 0; j < 2; j++) {
225 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
226 || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
244 if (!luma_weight_l1_flag[
i]) {
249 if (
sps->chroma_format_idc != 0) {
254 chroma_weight_l1_flag[
i] = 0;
257 if (luma_weight_l1_flag[
i]) {
259 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
264 if (chroma_weight_l1_flag[
i]) {
265 for (j = 0; j < 2; j++) {
269 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
270 || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
292 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
293 int prev_delta_msb = 0;
294 unsigned int nb_sps = 0, nb_sh;
298 if (!
sps->long_term_ref_pics_present)
301 if (
sps->num_long_term_ref_pics_sps > 0)
305 if (nb_sps >
sps->num_long_term_ref_pics_sps)
315 uint8_t lt_idx_sps = 0;
317 if (
sps->num_long_term_ref_pics_sps > 1)
320 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
321 rps->
used[
i] = !!(
sps->used_by_curr_pic_lt & (1
U << lt_idx_sps));
332 if (
i &&
i != nb_sps)
333 delta += prev_delta_msb;
335 poc = rps->
poc[
i] + cur_poc -
delta * max_poc_lsb - poc_lsb;
339 prev_delta_msb =
delta;
351 unsigned int num = 0, den = 0;
359 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
360 avctx->
level =
sps->ptl.general_ptl.level_idc;
364 if (
sps->vui.common.video_signal_type_present_flag)
370 if (
sps->vui.common.colour_description_present_flag) {
372 avctx->
color_trc =
sps->vui.common.transfer_characteristics;
381 if (
sps->chroma_format_idc == 1) {
382 if (
sps->vui.common.chroma_loc_info_present_flag) {
383 if (
sps->vui.common.chroma_sample_loc_type_top_field <= 5)
389 if (
vps->vps_timing_info_present_flag) {
390 num =
vps->vps_num_units_in_tick;
391 den =
vps->vps_time_scale;
392 }
else if (
sps->vui.vui_timing_info_present_flag) {
393 num =
sps->vui.vui_num_units_in_tick;
394 den =
sps->vui.vui_time_scale;
397 if (num > 0 && den > 0)
406 if (
s->sei.common.a53_caption.buf_ref)
409 if (
s->sei.common.alternative_transfer.present &&
412 avctx->
color_trc =
s->sei.common.alternative_transfer.preferred_transfer_characteristics;
415 if ((
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present) ||
416 (
s->sei.common.aom_film_grain &&
s->sei.common.aom_film_grain->enable))
427 s->nb_view_ids_available = 0;
429 s->nb_view_pos_available = 0;
432 if (
vps->nb_layers < 2 && !
vps->view_id[0])
435 s->view_ids_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_ids_available));
436 if (!
s->view_ids_available)
440 s->view_pos_available =
av_calloc(
vps->nb_layers,
sizeof(*
s->view_pos_available));
441 if (!
s->view_pos_available)
445 for (
int i = 0;
i <
vps->nb_layers;
i++) {
446 s->view_ids_available[
i] =
vps->view_id[
i];
448 if (
s->view_pos_available) {
455 s->nb_view_ids_available =
vps->nb_layers;
456 s->nb_view_pos_available =
s->view_pos_available ?
vps->nb_layers : 0;
463 unsigned layers_active_output = 0, highest_layer;
465 s->layers_active_output = 1;
466 s->layers_active_decode = 1;
472 if (
s->nb_view_ids == 1 &&
s->view_ids[0] == -1) {
473 layers_active_output = (1 <<
vps->nb_layers) - 1;
475 for (
int i = 0;
i <
s->nb_view_ids;
i++) {
476 int view_id =
s->view_ids[
i];
481 "Invalid view ID requested: %d\n", view_id);
485 for (
int j = 0; j <
vps->nb_layers; j++) {
486 if (
vps->view_id[j] == view_id) {
493 "View ID %d not present in VPS\n", view_id);
496 layers_active_output |= 1 << layer_idx;
500 if (!layers_active_output) {
505 highest_layer =
ff_log2(layers_active_output);
508 "Too many layers requested: %u\n", layers_active_output);
516 s->layers_active_decode = (1 << (highest_layer + 1)) - 1;
517 s->layers_active_output = layers_active_output;
520 s->layers_active_decode,
s->layers_active_output);
527 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
528 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
529 CONFIG_HEVC_D3D12VA_HWACCEL + \
530 CONFIG_HEVC_NVDEC_HWACCEL + \
531 CONFIG_HEVC_VAAPI_HWACCEL + \
532 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
533 CONFIG_HEVC_VDPAU_HWACCEL + \
534 CONFIG_HEVC_VULKAN_HWACCEL)
538 switch (
sps->pix_fmt) {
541 #if CONFIG_HEVC_DXVA2_HWACCEL
544 #if CONFIG_HEVC_D3D11VA_HWACCEL
548 #if CONFIG_HEVC_D3D12VA_HWACCEL
551 #if CONFIG_HEVC_VAAPI_HWACCEL
554 #if CONFIG_HEVC_VDPAU_HWACCEL
557 #if CONFIG_HEVC_NVDEC_HWACCEL
560 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
563 #if CONFIG_HEVC_VULKAN_HWACCEL
568 #if CONFIG_HEVC_DXVA2_HWACCEL
571 #if CONFIG_HEVC_D3D11VA_HWACCEL
575 #if CONFIG_HEVC_D3D12VA_HWACCEL
578 #if CONFIG_HEVC_VAAPI_HWACCEL
581 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
584 #if CONFIG_HEVC_VULKAN_HWACCEL
587 #if CONFIG_HEVC_VDPAU_HWACCEL
590 #if CONFIG_HEVC_NVDEC_HWACCEL
595 #if CONFIG_HEVC_VAAPI_HWACCEL
598 #if CONFIG_HEVC_VDPAU_HWACCEL
601 #if CONFIG_HEVC_NVDEC_HWACCEL
604 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
607 #if CONFIG_HEVC_VULKAN_HWACCEL
613 #if CONFIG_HEVC_VAAPI_HWACCEL
616 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
619 #if CONFIG_HEVC_VULKAN_HWACCEL
624 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
630 #if CONFIG_HEVC_VAAPI_HWACCEL
633 #if CONFIG_HEVC_VDPAU_HWACCEL
636 #if CONFIG_HEVC_VULKAN_HWACCEL
639 #if CONFIG_HEVC_NVDEC_HWACCEL
644 #if CONFIG_HEVC_VAAPI_HWACCEL
647 #if CONFIG_HEVC_VULKAN_HWACCEL
653 *fmt++ =
sps->pix_fmt;
665 s->avctx->pix_fmt =
ret;
710 unsigned pps_id, layer_idx;
731 pps =
s->ps.pps_list[pps_id];
734 layer_idx =
vps->layer_idx[
s->nuh_layer_id];
741 int slice_address_length;
743 if (
pps->dependent_slice_segments_enabled_flag)
755 "Invalid slice segment address: %u.\n",
768 for (
i = 0;
i <
pps->num_extra_slice_header_bits;
i++)
780 !
pps->pps_curr_pic_ref_enabled_flag &&
781 s->nuh_layer_id == 0) {
788 if (
pps->output_flag_present_flag)
791 if (
sps->separate_colour_plane)
795 (
s->nuh_layer_id > 0 &&
796 !(
vps->poc_lsb_not_present & (1 << layer_idx)))) {
803 "Ignoring POC change between slices: %d -> %d\n", poc, sh->
poc);
823 int numbits, rps_idx;
825 if (!
sps->nb_st_rps) {
831 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
845 if (
sps->temporal_mvp_enabled)
860 if (
s->nuh_layer_id > 0) {
861 int num_direct_ref_layers =
vps->num_direct_ref_layers[layer_idx];
863 if (
vps->default_ref_layers_active)
865 else if (num_direct_ref_layers) {
870 "NumDirectRefLayers>1 not supported\n");
876 if (
sps->sao_enabled) {
878 if (
sps->chroma_format_idc) {
915 if (
pps->lists_modification_present_flag && nb_refs > 1) {
933 if (
pps->cabac_init_present_flag)
948 "Invalid collocated_ref_idx: %d.\n",
965 "Invalid number of merging MVP candidates: %d.\n",
971 if (
sps->motion_vector_resolution_control_idc == 2)
981 if (
pps->pic_slice_level_chroma_qp_offsets_present_flag) {
994 if (
pps->pps_slice_act_qp_offsets_present_flag) {
1000 if (
pps->chroma_qp_offset_list_enabled_flag)
1005 if (
pps->deblocking_filter_control_present_flag) {
1006 int deblocking_filter_override_flag = 0;
1008 if (
pps->deblocking_filter_override_enabled_flag)
1009 deblocking_filter_override_flag =
get_bits1(gb);
1011 if (deblocking_filter_override_flag) {
1016 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
1017 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1019 "Invalid deblock filter offsets: %d, %d\n",
1020 beta_offset_div2, tc_offset_div2);
1037 if (
pps->seq_loop_filter_across_slices_enabled_flag &&
1048 if (
pps->tiles_enabled_flag ||
pps->entropy_coding_sync_enabled_flag) {
1052 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
1060 if (offset_len < 1 || offset_len > 32) {
1084 if (
pps->slice_header_extension_present_flag) {
1090 for (
i = 0;
i < length;
i++)
1106 "The slice_qp %d is outside the valid range "
1109 -
sps->qp_bd_offset);
1130 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
1132 #define SET_SAO(elem, value) \
1134 if (!sao_merge_up_flag && !sao_merge_left_flag) \
1135 sao->elem = value; \
1136 else if (sao_merge_left_flag) \
1137 sao->elem = CTB(l->sao, rx-1, ry).elem; \
1138 else if (sao_merge_up_flag) \
1139 sao->elem = CTB(l->sao, rx, ry-1).elem; \
1149 int sao_merge_left_flag = 0;
1150 int sao_merge_up_flag = 0;
1154 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
1155 s->sh.slice_sample_adaptive_offset_flag[1]) {
1160 if (ry > 0 && !sao_merge_left_flag) {
1166 for (c_idx = 0; c_idx < (
sps->chroma_format_idc ? 3 : 1); c_idx++) {
1167 int log2_sao_offset_scale = c_idx == 0 ?
pps->log2_sao_offset_scale_luma :
1168 pps->log2_sao_offset_scale_chroma;
1170 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
1185 for (
i = 0;
i < 4;
i++)
1189 for (
i = 0;
i < 4;
i++) {
1198 }
else if (c_idx != 2) {
1204 for (
i = 0;
i < 4;
i++) {
1212 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1224 if (log2_res_scale_abs_plus1 != 0) {
1227 (1 - 2 * res_scale_sign_flag);
1240 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1241 int log2_cb_size,
int log2_trafo_size,
1242 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1245 const int log2_trafo_size_c = log2_trafo_size -
sps->hshift[1];
1249 int trafo_size = 1 << log2_trafo_size;
1252 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, x0, y0, 0);
1255 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1256 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1259 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1260 (
sps->chroma_format_idc == 2 &&
1261 (cbf_cb[1] || cbf_cr[1]));
1273 "The cu_qp_delta %d is outside the valid range "
1276 -(26 +
sps->qp_bd_offset / 2),
1277 (25 +
sps->qp_bd_offset / 2));
1284 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1287 if (cu_chroma_qp_offset_flag) {
1288 int cu_chroma_qp_offset_idx = 0;
1289 if (
pps->chroma_qp_offset_list_len_minus1 > 0) {
1292 "cu_chroma_qp_offset_idx not yet tested.\n");
1325 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1326 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1327 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1328 lc->
tu.
cross_pf = (
pps->cross_component_prediction_enabled_flag && cbf_luma &&
1335 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1338 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1339 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 1);
1343 log2_trafo_size_c, scan_idx_c, 1);
1346 ptrdiff_t
stride =
s->cur_frame->f->linesize[1];
1347 int hshift =
sps->hshift[1];
1348 int vshift =
sps->vshift[1];
1351 int size = 1 << log2_trafo_size_c;
1353 uint8_t *
dst = &
s->cur_frame->f->data[1][(y0 >> vshift) *
stride +
1354 ((x0 >> hshift) <<
sps->pixel_shift)];
1358 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1365 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1368 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1369 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (
i << log2_trafo_size_c), 2);
1373 log2_trafo_size_c, scan_idx_c, 2);
1376 ptrdiff_t
stride =
s->cur_frame->f->linesize[2];
1377 int hshift =
sps->hshift[2];
1378 int vshift =
sps->vshift[2];
1381 int size = 1 << log2_trafo_size_c;
1383 uint8_t *
dst = &
s->cur_frame->f->data[2][(y0 >> vshift) *
stride +
1384 ((x0 >> hshift) <<
sps->pixel_shift)];
1388 s->hevcdsp.add_residual[log2_trafo_size_c-2](
dst, coeffs,
stride);
1391 }
else if (
sps->chroma_format_idc && blk_idx == 3) {
1392 int trafo_size_h = 1 << (log2_trafo_size + 1);
1393 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1394 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1397 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1398 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 1);
1402 log2_trafo_size, scan_idx_c, 1);
1404 for (
i = 0;
i < (
sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1407 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1408 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (
i << log2_trafo_size), 2);
1412 log2_trafo_size, scan_idx_c, 2);
1416 if (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3) {
1417 int trafo_size_h = 1 << (log2_trafo_size_c +
sps->hshift[1]);
1418 int trafo_size_v = 1 << (log2_trafo_size_c +
sps->vshift[1]);
1420 sps->log2_ctb_size);
1421 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 1);
1422 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0, 2);
1423 if (
sps->chroma_format_idc == 2) {
1425 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1426 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 1);
1427 s->hpc.intra_pred[log2_trafo_size_c - 2](lc,
pps, x0, y0 + (1 << log2_trafo_size_c), 2);
1429 }
else if (blk_idx == 3) {
1430 int trafo_size_h = 1 << (log2_trafo_size + 1);
1431 int trafo_size_v = 1 << (log2_trafo_size +
sps->vshift[1]);
1433 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1434 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 1);
1435 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase, 2);
1436 if (
sps->chroma_format_idc == 2) {
1438 trafo_size_h, trafo_size_v,
sps->log2_ctb_size);
1439 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 1);
1440 s->hpc.intra_pred[log2_trafo_size - 2](lc,
pps, xBase, yBase + (1 << log2_trafo_size), 2);
1449 int x0,
int y0,
int log2_cb_size)
1451 int cb_size = 1 << log2_cb_size;
1452 int log2_min_pu_size =
sps->log2_min_pu_size;
1454 int min_pu_width =
sps->min_pu_width;
1455 int x_end =
FFMIN(x0 + cb_size,
sps->width);
1456 int y_end =
FFMIN(y0 + cb_size,
sps->height);
1459 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1460 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1461 is_pcm[
i + j * min_pu_width] = 2;
1468 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1469 int log2_cb_size,
int log2_trafo_size,
1470 int trafo_depth,
int blk_idx,
1471 const int *base_cbf_cb,
const int *base_cbf_cr)
1474 uint8_t split_transform_flag;
1479 cbf_cb[0] = base_cbf_cb[0];
1480 cbf_cb[1] = base_cbf_cb[1];
1481 cbf_cr[0] = base_cbf_cr[0];
1482 cbf_cr[1] = base_cbf_cr[1];
1485 if (trafo_depth == 1) {
1487 if (
sps->chroma_format_idc == 3) {
1501 if (log2_trafo_size <= sps->log2_max_trafo_size &&
1502 log2_trafo_size >
sps->log2_min_tb_size &&
1503 trafo_depth < lc->cu.max_trafo_depth &&
1507 int inter_split =
sps->max_transform_hierarchy_depth_inter == 0 &&
1512 split_transform_flag = log2_trafo_size >
sps->log2_max_trafo_size ||
1517 if (
sps->chroma_format_idc && (log2_trafo_size > 2 ||
sps->chroma_format_idc == 3)) {
1518 if (trafo_depth == 0 || cbf_cb[0]) {
1520 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1525 if (trafo_depth == 0 || cbf_cr[0]) {
1527 if (
sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1533 if (split_transform_flag) {
1534 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1535 const int x1 = x0 + trafo_size_split;
1536 const int y1 = y0 + trafo_size_split;
1538 #define SUBDIVIDE(x, y, idx) \
1540 ret = hls_transform_tree(lc, l, pps, sps, \
1541 x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1542 log2_trafo_size - 1, trafo_depth + 1, idx, \
1555 int min_tu_size = 1 <<
sps->log2_min_tb_size;
1556 int log2_min_tu_size =
sps->log2_min_tb_size;
1557 int min_tu_width =
sps->min_tb_width;
1561 cbf_cb[0] || cbf_cr[0] ||
1562 (
sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1567 x0, y0, xBase, yBase, cb_xBase, cb_yBase,
1568 log2_cb_size, log2_trafo_size,
1569 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1575 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1576 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1577 int x_tu = (x0 + j) >> log2_min_tu_size;
1578 int y_tu = (y0 +
i) >> log2_min_tu_size;
1579 l->
cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1582 if (!
s->sh.disable_deblocking_filter_flag) {
1584 if (
pps->transquant_bypass_enable_flag &&
1593 const HEVCPPS *
pps,
int x0,
int y0,
int log2_cb_size)
1598 int cb_size = 1 << log2_cb_size;
1599 ptrdiff_t stride0 =
s->cur_frame->f->linesize[0];
1600 ptrdiff_t stride1 =
s->cur_frame->f->linesize[1];
1601 ptrdiff_t stride2 =
s->cur_frame->f->linesize[2];
1602 uint8_t *dst0 = &
s->cur_frame->f->data[0][y0 * stride0 + (x0 <<
sps->pixel_shift)];
1603 uint8_t *dst1 = &
s->cur_frame->f->data[1][(y0 >>
sps->vshift[1]) * stride1 + ((x0 >>
sps->hshift[1]) <<
sps->pixel_shift)];
1604 uint8_t *dst2 = &
s->cur_frame->f->data[2][(y0 >>
sps->vshift[2]) * stride2 + ((x0 >>
sps->hshift[2]) <<
sps->pixel_shift)];
1606 int length = cb_size * cb_size *
sps->pcm.bit_depth +
1607 (((cb_size >>
sps->hshift[1]) * (cb_size >>
sps->vshift[1])) +
1608 ((cb_size >>
sps->hshift[2]) * (cb_size >>
sps->vshift[2]))) *
1609 sps->pcm.bit_depth_chroma;
1610 const uint8_t *pcm =
skip_bytes(&lc->
cc, (length + 7) >> 3);
1613 if (!
s->sh.disable_deblocking_filter_flag)
1620 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
sps->pcm.bit_depth);
1621 if (
sps->chroma_format_idc) {
1622 s->hevcdsp.put_pcm(dst1, stride1,
1623 cb_size >>
sps->hshift[1],
1624 cb_size >>
sps->vshift[1],
1625 &gb,
sps->pcm.bit_depth_chroma);
1626 s->hevcdsp.put_pcm(dst2, stride2,
1627 cb_size >>
sps->hshift[2],
1628 cb_size >>
sps->vshift[2],
1629 &gb,
sps->pcm.bit_depth_chroma);
1653 uint8_t *
dst, ptrdiff_t dststride,
1655 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1658 const uint8_t *
src =
ref->data[0];
1660 int pic_width =
sps->width;
1661 int pic_height =
sps->height;
1664 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1668 x_off +=
mv->x >> 2;
1669 y_off +=
mv->y >> 2;
1675 ref ==
s->cur_frame->f) {
1685 pic_width, pic_height);
1692 block_h,
mx,
my, block_w);
1695 block_h,
s->sh.luma_log2_weight_denom,
1696 luma_weight, luma_offset,
mx,
my, block_w);
1717 uint8_t *
dst, ptrdiff_t dststride,
1718 const AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1719 int block_w,
int block_h,
const AVFrame *ref1,
1720 const Mv *mv1,
struct MvField *current_mv)
1723 ptrdiff_t src0stride = ref0->
linesize[0];
1724 ptrdiff_t src1stride = ref1->
linesize[0];
1725 int pic_width =
sps->width;
1726 int pic_height =
sps->height;
1727 int mx0 = mv0->
x & 3;
1728 int my0 = mv0->
y & 3;
1729 int mx1 = mv1->
x & 3;
1730 int my1 = mv1->
y & 3;
1731 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1733 int x_off0 = x_off + (mv0->
x >> 2);
1734 int y_off0 = y_off + (mv0->
y >> 2);
1735 int x_off1 = x_off + (mv1->
x >> 2);
1736 int y_off1 = y_off + (mv1->
y >> 2);
1739 const uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1740 const uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1750 edge_emu_stride, src0stride,
1754 pic_width, pic_height);
1756 src0stride = edge_emu_stride;
1767 edge_emu_stride, src1stride,
1771 pic_width, pic_height);
1773 src1stride = edge_emu_stride;
1776 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1777 block_h, mx0, my0, block_w);
1779 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1780 block_h, mx1, my1, block_w);
1782 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](
dst, dststride,
src1, src1stride, lc->
tmp,
1783 block_h,
s->sh.luma_log2_weight_denom,
1784 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1785 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1786 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1787 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1812 ptrdiff_t dststride,
const uint8_t *
src0, ptrdiff_t
srcstride,
int reflist,
1813 int x_off,
int y_off,
int block_w,
int block_h,
1814 const struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1817 int pic_width =
sps->width >>
sps->hshift[1];
1818 int pic_height =
sps->height >>
sps->vshift[1];
1819 const Mv *
mv = ¤t_mv->
mv[reflist];
1820 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1823 int hshift =
sps->hshift[1];
1824 int vshift =
sps->vshift[1];
1827 intptr_t _mx =
mx << (1 - hshift);
1828 intptr_t _my =
my << (1 - vshift);
1829 int emu =
src0 ==
s->cur_frame->f->data[1] ||
src0 ==
s->cur_frame->f->data[2];
1831 x_off +=
mv->x >> (2 + hshift);
1832 y_off +=
mv->y >> (2 + vshift);
1842 (edge_emu_stride + (1 <<
sps->pixel_shift));
1848 pic_width, pic_height);
1855 block_h, _mx, _my, block_w);
1858 block_h,
s->sh.chroma_log2_weight_denom,
1859 chroma_weight, chroma_offset, _mx, _my, block_w);
1881 uint8_t *dst0, ptrdiff_t dststride,
1883 int x_off,
int y_off,
int block_w,
int block_h,
const MvField *current_mv,
int cidx)
1886 const uint8_t *
src1 = ref0->
data[cidx+1];
1887 const uint8_t *
src2 = ref1->
data[cidx+1];
1888 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1889 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1890 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
pps->weighted_pred_flag) ||
1892 int pic_width =
sps->width >>
sps->hshift[1];
1893 int pic_height =
sps->height >>
sps->vshift[1];
1894 const Mv *
const mv0 = ¤t_mv->
mv[0];
1895 const Mv *
const mv1 = ¤t_mv->
mv[1];
1896 int hshift =
sps->hshift[1];
1897 int vshift =
sps->vshift[1];
1903 intptr_t _mx0 = mx0 << (1 - hshift);
1904 intptr_t _my0 = my0 << (1 - vshift);
1905 intptr_t _mx1 = mx1 << (1 - hshift);
1906 intptr_t _my1 = my1 << (1 - vshift);
1908 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1909 int y_off0 = y_off + (mv0->
y >> (2 + vshift));
1910 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1911 int y_off1 = y_off + (mv1->
y >> (2 + vshift));
1913 src1 += y_off0 * src1stride + (int)((
unsigned)x_off0 <<
sps->pixel_shift);
1914 src2 += y_off1 * src2stride + (int)((
unsigned)x_off1 <<
sps->pixel_shift);
1922 (edge_emu_stride + (1 <<
sps->pixel_shift));
1925 edge_emu_stride, src1stride,
1929 pic_width, pic_height);
1932 src1stride = edge_emu_stride;
1941 (edge_emu_stride + (1 <<
sps->pixel_shift));
1944 edge_emu_stride, src2stride,
1948 pic_width, pic_height);
1951 src2stride = edge_emu_stride;
1954 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
1955 block_h, _mx0, _my0, block_w);
1957 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
1959 block_h, _mx1, _my1, block_w);
1961 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->cur_frame->f->linesize[cidx+1],
1964 s->sh.chroma_log2_weight_denom,
1965 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
1966 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
1967 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
1968 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
1969 _mx1, _my1, block_w);
1984 int x0,
int y0,
int nPbW,
1985 int nPbH,
int log2_cb_size,
int part_idx,
1997 if (inter_pred_idc !=
PRED_L1) {
1998 if (
s->sh.nb_refs[
L0])
2005 part_idx, merge_idx,
mv, mvp_flag, 0);
2010 if (inter_pred_idc !=
PRED_L0) {
2011 if (
s->sh.nb_refs[
L1])
2014 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
2023 part_idx, merge_idx,
mv, mvp_flag, 1);
2032 int x0,
int y0,
int nPbW,
int nPbH,
2033 int log2_cb_size,
int partIdx,
int idx)
2035 #define POS(c_idx, x, y) \
2036 &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
2037 (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)]
2040 struct MvField current_mv = {{{ 0 }}};
2042 int min_pu_width =
sps->min_pu_width;
2044 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2045 const RefPicList *refPicList =
s->cur_frame->refPicList;
2047 const int *linesize =
s->cur_frame->f->linesize;
2048 uint8_t *dst0 =
POS(0, x0, y0);
2049 uint8_t *dst1 =
POS(1, x0, y0);
2050 uint8_t *dst2 =
POS(2, x0, y0);
2051 int log2_min_cb_size =
sps->log2_min_cb_size;
2052 int min_cb_width =
sps->min_cb_width;
2053 int x_cb = x0 >> log2_min_cb_size;
2054 int y_cb = y0 >> log2_min_cb_size;
2064 if (
s->sh.max_num_merge_cand > 1)
2070 partIdx, merge_idx, ¤t_mv);
2073 partIdx, merge_idx, ¤t_mv);
2076 x_pu = x0 >>
sps->log2_min_pu_size;
2077 y_pu = y0 >>
sps->log2_min_pu_size;
2079 for (j = 0; j < nPbH >>
sps->log2_min_pu_size; j++)
2080 for (
i = 0; i < nPbW >>
sps->log2_min_pu_size;
i++)
2081 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
2084 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
2085 if (!ref0 || !ref0->
f)
2090 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
2091 if (!ref1 || !ref1->f)
2097 int x0_c = x0 >>
sps->hshift[1];
2098 int y0_c = y0 >>
sps->vshift[1];
2099 int nPbW_c = nPbW >>
sps->hshift[1];
2100 int nPbH_c = nPbH >>
sps->vshift[1];
2103 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2104 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
2105 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
2107 if (
sps->chroma_format_idc) {
2109 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2110 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
2112 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2113 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
2116 int x0_c = x0 >>
sps->hshift[1];
2117 int y0_c = y0 >>
sps->vshift[1];
2118 int nPbW_c = nPbW >>
sps->hshift[1];
2119 int nPbH_c = nPbH >>
sps->vshift[1];
2122 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
2123 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
2124 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
2126 if (
sps->chroma_format_idc) {
2128 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2129 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
2132 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
2133 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
2136 int x0_c = x0 >>
sps->hshift[1];
2137 int y0_c = y0 >>
sps->vshift[1];
2138 int nPbW_c = nPbW >>
sps->hshift[1];
2139 int nPbH_c = nPbH >>
sps->vshift[1];
2142 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
2143 ref1->f, ¤t_mv.
mv[1], ¤t_mv);
2145 if (
sps->chroma_format_idc) {
2147 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
2150 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
2160 int x0,
int y0,
int pu_size,
2161 int prev_intra_luma_pred_flag)
2164 int x_pu = x0 >>
sps->log2_min_pu_size;
2165 int y_pu = y0 >>
sps->log2_min_pu_size;
2166 int min_pu_width =
sps->min_pu_width;
2167 int size_in_pus = pu_size >>
sps->log2_min_pu_size;
2176 int y_ctb = (y0 >> (
sps->log2_ctb_size)) << (
sps->log2_ctb_size);
2178 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2179 int intra_pred_mode;
2184 if ((y0 - 1) < y_ctb)
2187 if (cand_left == cand_up) {
2188 if (cand_left < 2) {
2193 candidate[0] = cand_left;
2194 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
2195 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
2198 candidate[0] = cand_left;
2199 candidate[1] = cand_up;
2209 if (prev_intra_luma_pred_flag) {
2210 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
2212 if (candidate[0] > candidate[1])
2213 FFSWAP(uint8_t, candidate[0], candidate[1]);
2214 if (candidate[0] > candidate[2])
2215 FFSWAP(uint8_t, candidate[0], candidate[2]);
2216 if (candidate[1] > candidate[2])
2217 FFSWAP(uint8_t, candidate[1], candidate[2]);
2220 for (
i = 0;
i < 3;
i++)
2221 if (intra_pred_mode >= candidate[
i])
2228 for (
i = 0;
i < size_in_pus;
i++) {
2229 memset(&l->
tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
2230 intra_pred_mode, size_in_pus);
2232 for (j = 0; j < size_in_pus; j++) {
2237 return intra_pred_mode;
2242 int log2_cb_size,
int ct_depth)
2244 int length = (1 << log2_cb_size) >>
sps->log2_min_cb_size;
2245 int x_cb = x0 >>
sps->log2_min_cb_size;
2246 int y_cb = y0 >>
sps->log2_min_cb_size;
2249 for (y = 0; y < length; y++)
2250 memset(&tab_ct_depth[(y_cb + y) *
sps->min_cb_width + x_cb],
2255 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2256 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2263 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2264 uint8_t prev_intra_luma_pred_flag[4];
2266 int pb_size = (1 << log2_cb_size) >>
split;
2267 int side =
split + 1;
2271 for (
i = 0;
i < side;
i++)
2272 for (j = 0; j < side; j++)
2275 for (
i = 0;
i < side;
i++) {
2276 for (j = 0; j < side; j++) {
2277 if (prev_intra_luma_pred_flag[2 *
i + j])
2284 x0 + pb_size * j, y0 + pb_size *
i, pb_size,
2285 prev_intra_luma_pred_flag[2 *
i + j]);
2289 if (
sps->chroma_format_idc == 3) {
2290 for (
i = 0;
i < side;
i++) {
2291 for (j = 0; j < side; j++) {
2293 if (chroma_mode != 4) {
2303 }
else if (
sps->chroma_format_idc == 2) {
2306 if (chroma_mode != 4) {
2310 mode_idx = intra_chroma_table[chroma_mode];
2315 }
else if (
sps->chroma_format_idc != 0) {
2317 if (chroma_mode != 4) {
2335 int pb_size = 1 << log2_cb_size;
2336 int size_in_pus = pb_size >>
sps->log2_min_pu_size;
2337 int min_pu_width =
sps->min_pu_width;
2338 MvField *tab_mvf =
s->cur_frame->tab_mvf;
2339 int x_pu = x0 >>
sps->log2_min_pu_size;
2340 int y_pu = y0 >>
sps->log2_min_pu_size;
2343 if (size_in_pus == 0)
2345 for (j = 0; j < size_in_pus; j++)
2346 memset(&l->
tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2348 for (j = 0; j < size_in_pus; j++)
2349 for (k = 0; k < size_in_pus; k++)
2356 int x0,
int y0,
int log2_cb_size)
2358 int cb_size = 1 << log2_cb_size;
2359 int log2_min_cb_size =
sps->log2_min_cb_size;
2360 int length = cb_size >> log2_min_cb_size;
2361 int min_cb_width =
sps->min_cb_width;
2362 int x_cb = x0 >> log2_min_cb_size;
2363 int y_cb = y0 >> log2_min_cb_size;
2364 int idx = log2_cb_size - 2;
2365 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2375 for (x = 0; x < 4; x++)
2377 if (
pps->transquant_bypass_enable_flag) {
2388 x0b, y0b, x_cb, y_cb,
2391 x = y_cb * min_cb_width + x_cb;
2392 for (y = 0; y < length; y++) {
2393 memset(&l->
skip_flag[x], skip_flag, length);
2398 x = y_cb * min_cb_width + x_cb;
2399 for (y = 0; y < length; y++) {
2407 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2410 if (!
s->sh.disable_deblocking_filter_flag)
2418 log2_cb_size ==
sps->log2_min_cb_size) {
2426 log2_cb_size >=
sps->pcm.log2_min_pcm_cb_size &&
2427 log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
2433 if (
sps->pcm_loop_filter_disabled)
2446 x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
2450 x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
2452 x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
2456 x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
2458 x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
2462 x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
2464 x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
2468 x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
2470 x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
2474 x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
2476 x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2480 x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
2482 x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2486 x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
2488 x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2490 x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2492 x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2498 int rqt_root_cbf = 1;
2505 const static int cbf[2] = { 0 };
2508 sps->max_transform_hierarchy_depth_inter;
2509 ret =
hls_transform_tree(lc, l,
pps,
sps, x0, y0, x0, y0, x0, y0,
2511 log2_cb_size, 0, 0, cbf, cbf);
2515 if (!
s->sh.disable_deblocking_filter_flag)
2524 x = y_cb * min_cb_width + x_cb;
2525 for (y = 0; y < length; y++) {
2530 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2531 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2544 int log2_cb_size,
int cb_depth)
2547 const int cb_size = 1 << log2_cb_size;
2552 if (x0 + cb_size <= sps->
width &&
2553 y0 + cb_size <= sps->
height &&
2554 log2_cb_size >
sps->log2_min_cb_size) {
2556 sps, cb_depth, x0, y0);
2558 split_cu = (log2_cb_size >
sps->log2_min_cb_size);
2560 if (
pps->cu_qp_delta_enabled_flag &&
2561 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth) {
2566 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2567 log2_cb_size >=
sps->log2_ctb_size -
pps->diff_cu_chroma_qp_offset_depth) {
2572 int qp_block_mask = (1 << (
sps->log2_ctb_size -
pps->diff_cu_qp_delta_depth)) - 1;
2573 const int cb_size_split = cb_size >> 1;
2574 const int x1 = x0 + cb_size_split;
2575 const int y1 = y0 + cb_size_split;
2580 x0, y0, log2_cb_size - 1, cb_depth + 1);
2584 if (more_data && x1 < sps->
width) {
2586 x1, y0, log2_cb_size - 1, cb_depth + 1);
2590 if (more_data && y1 < sps->
height) {
2592 x0, y1, log2_cb_size - 1, cb_depth + 1);
2596 if (more_data && x1 < sps->
width &&
2599 x1, y1, log2_cb_size - 1, cb_depth + 1);
2604 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2605 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2609 return ((x1 + cb_size_split) <
sps->width ||
2610 (y1 + cb_size_split) <
sps->height);
2617 if ((!((x0 + cb_size) %
2618 (1 << (
sps->log2_ctb_size))) ||
2619 (x0 + cb_size >=
sps->width)) &&
2621 (1 << (
sps->log2_ctb_size))) ||
2622 (y0 + cb_size >=
sps->height))) {
2624 return !end_of_slice_flag;
2636 int x_ctb,
int y_ctb,
int ctb_addr_ts)
2639 int ctb_size = 1 <<
sps->log2_ctb_size;
2640 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2641 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2645 if (
pps->entropy_coding_sync_enabled_flag) {
2646 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2649 }
else if (
pps->tiles_enabled_flag) {
2650 if (ctb_addr_ts &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[ctb_addr_ts - 1]) {
2651 int idxX =
pps->col_idxX[x_ctb >>
sps->log2_ctb_size];
2662 if (
pps->tiles_enabled_flag) {
2663 if (x_ctb > 0 &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2667 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]])
2672 if (ctb_addr_in_slice <= 0)
2674 if (ctb_addr_in_slice < sps->ctb_width)
2680 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]]));
2681 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]]));
2690 const uint8_t *slice_data = gb->
buffer +
s->sh.data_offset;
2692 int ctb_size = 1 <<
sps->log2_ctb_size;
2696 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2699 while (more_data && ctb_addr_ts < sps->ctb_size) {
2700 int ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2702 x_ctb = (ctb_addr_rs % ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2703 y_ctb = (ctb_addr_rs / ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size)) <<
sps->log2_ctb_size;
2713 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2720 if (more_data < 0) {
2731 if (x_ctb + ctb_size >=
sps->width &&
2732 y_ctb + ctb_size >=
sps->height)
2739 int job,
int thread)
2746 int ctb_size = 1 <<
sps->log2_ctb_size;
2749 int ctb_addr_rs =
s->sh.slice_ctb_addr_rs + ctb_row * ((
sps->width + ctb_size - 1) >>
sps->log2_ctb_size);
2750 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2752 const uint8_t *
data =
s->data +
s->sh.offset[ctb_row];
2753 const size_t data_size =
s->sh.size[ctb_row];
2762 while(more_data && ctb_addr_ts < sps->ctb_size) {
2763 int x_ctb = (ctb_addr_rs %
sps->ctb_width) <<
sps->log2_ctb_size;
2764 int y_ctb = (ctb_addr_rs /
sps->ctb_width) <<
sps->log2_ctb_size;
2784 x_ctb >>
sps->log2_ctb_size, y_ctb >>
sps->log2_ctb_size);
2792 if (more_data < 0) {
2803 if (!more_data && (x_ctb+ctb_size) <
sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2810 if ((x_ctb+ctb_size) >=
sps->width && (y_ctb+ctb_size) >=
sps->height ) {
2815 ctb_addr_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2818 if(x_ctb >=
sps->width) {
2835 if (
s->nb_wpp_progress < count) {
2837 sizeof(*
s->wpp_progress));
2841 s->wpp_progress =
tmp;
2842 memset(
s->wpp_progress +
s->nb_wpp_progress, 0,
2843 (count -
s->nb_wpp_progress) *
sizeof(*
s->wpp_progress));
2845 for (
int i =
s->nb_wpp_progress;
i < count;
i++) {
2849 s->nb_wpp_progress =
i + 1;
2853 for (
int i = 0;
i < count;
i++)
2864 int length = nal->
size;
2867 int64_t startheader, cmpt = 0;
2870 if (
s->sh.slice_ctb_addr_rs +
s->sh.num_entry_point_offsets *
sps->ctb_width >=
sps->ctb_width *
sps->ctb_height) {
2872 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2873 sps->ctb_width,
sps->ctb_height
2878 if (
s->avctx->thread_count >
s->nb_local_ctx) {
2884 memcpy(
tmp,
s->local_ctx,
sizeof(*
s->local_ctx) *
s->nb_local_ctx);
2888 for (
unsigned i =
s->nb_local_ctx; i < s->avctx->thread_count;
i++) {
2889 tmp = &
s->local_ctx[
i];
2891 memset(
tmp, 0,
sizeof(*
tmp));
2893 tmp->logctx =
s->avctx;
2895 tmp->common_cabac_state = &
s->cabac;
2898 s->nb_local_ctx =
s->avctx->thread_count;
2903 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2910 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2911 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2912 for (j = 0, cmpt = 0, startheader =
offset
2913 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2919 s->sh.size[
i] =
s->sh.entry_point_offset[
i] - cmpt;
2924 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2929 s->sh.size [
s->sh.num_entry_point_offsets] = length -
offset;
2930 s->sh.offset[
s->sh.num_entry_point_offsets] =
offset;
2932 s->sh.offset[0] =
s->sh.data_offset;
2933 s->sh.size[0] =
s->sh.offset[1] -
s->sh.offset[0];
2937 for (
i = 1;
i <
s->nb_local_ctx;
i++) {
2938 s->local_ctx[
i].first_qp_group = 1;
2939 s->local_ctx[
i].qp_y =
s->local_ctx[0].qp_y;
2951 if (
pps->entropy_coding_sync_enabled_flag)
2954 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
2967 if (!
s->sh.first_slice_in_pic_flag)
2968 s->slice_idx += !
s->sh.dependent_slice_segment_flag;
2970 if (!
s->sh.dependent_slice_segment_flag &&
s->sh.slice_type !=
HEVC_SLICE_I) {
2974 "Error constructing the reference lists for the current slice.\n");
2979 s->slice_initialized = 1;
2981 if (
s->avctx->hwaccel)
2986 "SCC profile is not yet implemented in hevc native decoder.\n");
2990 if (
s->sh.dependent_slice_segment_flag) {
2991 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2992 int prev_rs =
pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2999 s->local_ctx[0].first_qp_group = !
s->sh.dependent_slice_segment_flag;
3001 if (!
pps->cu_qp_delta_enabled_flag)
3002 s->local_ctx[0].qp_y =
s->sh.slice_qp;
3004 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
3005 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
3008 s->sh.num_entry_point_offsets > 0 &&
3009 pps->num_tile_rows == 1 &&
pps->num_tile_columns == 1)
3024 if (
IS_IRAP(
s) &&
s->no_rasl_output_flag) {
3025 if (
s->sei.common.mastering_display.present > 0)
3026 s->sei.common.mastering_display.present--;
3028 if (
s->sei.common.content_light.present > 0)
3029 s->sei.common.content_light.present--;
3034 sps->bit_depth,
sps->bit_depth_chroma,
3035 s->cur_frame->poc );
3039 if (
s->sei.timecode.present) {
3044 sizeof(uint32_t) * 4, &tcside);
3049 tc_sd = (uint32_t*)tcside->
data;
3050 tc_sd[0] =
s->sei.timecode.num_clock_ts;
3052 for (
int i = 0;
i < tc_sd[0];
i++) {
3053 int drop =
s->sei.timecode.cnt_dropped_flag[
i];
3054 int hh =
s->sei.timecode.hours_value[
i];
3055 int mm =
s->sei.timecode.minutes_value[
i];
3056 int ss =
s->sei.timecode.seconds_value[
i];
3057 int ff =
s->sei.timecode.n_frames[
i];
3065 s->sei.timecode.num_clock_ts = 0;
3068 if (
s->sei.common.dynamic_hdr_plus.info) {
3089 if (
s->sei.common.dynamic_hdr_vivid.info) {
3107 for (
int i = nal_idx;
i <
s->pkt.nb_nals;
i++) {
3113 !(
s->layers_active_decode & (1 <<
s->vps->layer_idx[layer_id])))
3116 switch (nal->
type) {
3149 const HEVCPPS *
const pps =
s->ps.pps_list[
s->sh.pps_id];
3151 int pic_size_in_ctb = ((
sps->width >>
sps->log2_min_cb_size) + 1) *
3152 ((
sps->height >>
sps->log2_min_cb_size) + 1);
3153 int new_sequence = (l == &
s->layers[0]) &&
3155 int prev_layers_active_decode =
s->layers_active_decode;
3156 int prev_layers_active_output =
s->layers_active_output;
3159 if (
sps->vps !=
s->vps && l != &
s->layers[0]) {
3167 const HEVCSPS *sps_base =
s->layers[0].sps;
3170 if (l != &
s->layers[0]) {
3173 "Access unit starts with a non-base layer frame\n");
3182 !
sps->vui.common.video_signal_type_present_flag)
3189 "Base/non-base layer SPS have unsupported parameter combination\n");
3200 if (l == &
s->layers[0]) {
3216 memset(l->
is_pcm, 0, (
sps->min_pu_width + 1) * (
sps->min_pu_height + 1));
3223 s->first_nal_type =
s->nal_unit_type;
3231 if (
s->temporal_id == 0 &&
3239 s->poc_tid0 =
s->poc;
3241 if (
pps->tiles_enabled_flag)
3242 s->local_ctx[0].end_of_tiles_x =
pps->column_width[0] <<
sps->log2_ctb_size;
3246 0, 0,
s->sh.no_output_of_prior_pics_flag);
3270 s->cur_frame->needs_fg = ((
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present) ||
3271 (
s->sei.common.aom_film_grain &&
s->sei.common.aom_film_grain->enable)) &&
3279 if (
s->cur_frame->needs_fg &&
3280 (
s->sei.common.film_grain_characteristics &&
s->sei.common.film_grain_characteristics->present &&
3282 s->cur_frame->f->format) ||
3285 "Unsupported film grain parameters. Ignoring film grain.\n");
3286 s->cur_frame->needs_fg = 0;
3289 if (
s->cur_frame->needs_fg) {
3290 s->cur_frame->frame_grain->format =
s->cur_frame->f->format;
3291 s->cur_frame->frame_grain->width =
s->cur_frame->f->width;
3292 s->cur_frame->frame_grain->height =
s->cur_frame->f->height;
3301 s->cur_frame->f->pict_type = 3 -
s->sh.slice_type;
3304 sps->temporal_layer[
sps->max_sub_layers - 1].num_reorder_pics,
3305 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering, 0);
3309 if (
s->avctx->hwaccel) {
3318 if (l == &
s->layers[0])
3321 if (nal_idx >=
s->finish_setup_nal_idx)
3330 s->cur_frame =
s->collocated_ref =
NULL;
3331 s->slice_initialized = 0;
3338 char msg_buf[4 * (50 + 2 * 2 * 16 )];
3346 pixel_shift =
desc->comp[0].depth > 8;
3351 if (pixel_shift && !
s->checksum_buf) {
3354 frame->linesize[2]));
3355 if (!
s->checksum_buf)
3362 int width =
s->avctx->coded_width;
3363 int height =
s->avctx->coded_height;
3369 for (j = 0; j <
h; j++) {
3373 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3374 (
const uint16_t *)
src,
w);
3375 src =
s->checksum_buf;
3382 #define MD5_PRI "%016" PRIx64 "%016" PRIx64
3383 #define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
3385 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3387 "plane %d - correct " MD5_PRI "; ",
3391 "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
3398 "Verifying checksum for frame with POC %d: %s\n",
3410 if (
out->needs_fg) {
3413 switch (fgp->
type) {
3433 if (
s->avctx->hwaccel) {
3437 "hardware accelerator failed to decode picture\n");
3442 s->sei.picture_hash.is_md5) {
3448 s->sei.picture_hash.is_md5 = 0;
3451 l -
s->layers,
s->poc);
3458 const int layer_idx =
s->vps ?
s->vps->layer_idx[
s->nuh_layer_id] : 0;
3465 if (layer_idx < 0 ||
3466 (
s->nuh_layer_id > 0 && !(
s->layers_active_decode & (1 << layer_idx))))
3472 s->slice_initialized = 0;
3480 s->no_rasl_output_flag)) {
3485 if (
s->cur_layer != layer_idx &&
3486 s->layers[
s->cur_layer].cur_frame &&
3490 s->cur_layer = layer_idx;
3491 l = &
s->layers[
s->cur_layer];
3493 if (
s->sh.first_slice_in_pic_flag) {
3495 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
3507 if (
s->nal_unit_type !=
s->first_nal_type) {
3509 "Non-matching NAL types of the VCL NALUs: %d %d\n",
3510 s->first_nal_type,
s->nal_unit_type);
3527 s->nal_unit_type = nal->
type;
3543 switch (
s->nal_unit_type) {
3594 "Skipping NAL unit %d\n",
s->nal_unit_type);
3602 "Skipping invalid undecodable NALU: %d\n",
s->nal_unit_type);
3611 int eos_at_start = 1;
3614 s->cur_frame =
s->collocated_ref =
NULL;
3615 s->last_eos =
s->eos;
3617 s->slice_initialized = 0;
3627 s->nal_length_size,
s->avctx->codec_id,
flags);
3630 "Error splitting the input into NAL units.\n");
3634 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3656 s->pkt.nals[
s->pkt.nb_nals - 1].size > 2 && !
s->pkt.nals[
s->pkt.nb_nals - 1].nuh_layer_id
3657 && !
s->pkt.nals[
s->pkt.nb_nals - 1].temporal_id) {
3658 H2645NAL *nal = &
s->pkt.nals[
s->pkt.nb_nals - 1];
3661 av_log(
s->avctx,
AV_LOG_WARNING,
"Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
3670 s->avctx->err_recognition);
3679 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3689 "Error parsing NAL unit #%d.\n",
i);
3716 &
s->nal_length_size,
s->avctx->err_recognition,
3717 s->apply_defdispwin,
s->avctx);
3723 if (
first &&
s->ps.sps_list[
i]) {
3762 s->layers_active_output, 0, 0, 0);
3769 s->pkt_dts = avpkt->
dts;
3772 if (sd && sd_size > 0) {
3779 if (sd && sd_size >=
sizeof(
s->dovi_ctx.cfg)) {
3780 int old =
s->dovi_ctx.cfg.dv_profile;
3784 "New DOVI configuration record from input packet (profile %d -> %u).\n",
3785 old,
s->dovi_ctx.cfg.dv_profile);
3809 if (
src->needs_fg) {
3822 dst->nb_rpl_elems =
src->nb_rpl_elems;
3825 dst->ctb_count =
src->ctb_count;
3828 dst->base_layer_frame =
src->base_layer_frame;
3831 src->hwaccel_picture_private);
3866 for (
int i = 0;
i <
s->nb_wpp_progress;
i++)
3892 s->nb_local_ctx = 1;
3894 s->local_ctx[0].parent =
s;
3895 s->local_ctx[0].logctx = avctx;
3896 s->local_ctx[0].common_cabac_state = &
s->cabac;
3899 if (!
s->output_fifo)
3917 s->dovi_ctx.logctx = avctx;
3976 memcmp(
s->view_ids, s0->
view_ids,
sizeof(*
s->view_ids) *
s->nb_view_ids)) {
4029 s->sei.picture_timing.picture_struct = 0;
4049 if (sd && sd->
size >=
sizeof(
s->dovi_ctx.cfg))
4069 #define OFFSET(x) offsetof(HEVCContext, x)
4070 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
4073 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
4075 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
4077 {
"view_ids",
"Array of view IDs that should be decoded and output; a single -1 to decode all views",
4079 .min = -1, .max = INT_MAX, .flags =
PAR },
4080 {
"view_ids_available",
"Array of available view IDs is exported here",
4083 {
"view_pos_available",
"Array of view positions for view_ids_available is exported here, as AVStereo3DView",
4119 #if CONFIG_HEVC_DXVA2_HWACCEL
4122 #if CONFIG_HEVC_D3D11VA_HWACCEL
4125 #if CONFIG_HEVC_D3D11VA2_HWACCEL
4128 #if CONFIG_HEVC_D3D12VA_HWACCEL
4131 #if CONFIG_HEVC_NVDEC_HWACCEL
4134 #if CONFIG_HEVC_VAAPI_HWACCEL
4137 #if CONFIG_HEVC_VDPAU_HWACCEL
4140 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
4143 #if CONFIG_HEVC_VULKAN_HWACCEL