47 const uint8_t ff_hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 };
89 int log2_min_cb_size =
sps->log2_min_cb_size;
92 int pic_size_in_ctb = ((
width >> log2_min_cb_size) + 1) *
93 ((
height >> log2_min_cb_size) + 1);
94 int ctb_count =
sps->ctb_width *
sps->ctb_height;
95 int min_pu_size =
sps->min_pu_width *
sps->min_pu_height;
97 s->bs_width = (
width >> 2) + 1;
98 s->bs_height = (
height >> 2) + 1;
102 if (!
s->sao || !
s->deblock)
107 if (!
s->skip_flag || !
s->tab_ct_depth)
113 if (!
s->tab_ipm || !
s->cbf_luma || !
s->is_pcm)
118 sizeof(*
s->tab_slice_address));
120 sizeof(*
s->qp_y_tab));
121 if (!
s->qp_y_tab || !
s->filter_slice_edges || !
s->tab_slice_address)
126 if (!
s->horizontal_bs || !
s->vertical_bs)
133 if (!
s->tab_mvf_pool || !
s->rpl_tab_pool)
147 uint8_t luma_weight_l0_flag[16];
148 uint8_t chroma_weight_l0_flag[16];
149 uint8_t luma_weight_l1_flag[16];
150 uint8_t chroma_weight_l1_flag[16];
151 int luma_log2_weight_denom;
154 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
155 av_log(
s->avctx,
AV_LOG_ERROR,
"luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
158 s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
159 if (
s->ps.sps->chroma_format_idc != 0) {
160 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)
get_se_golomb(gb);
161 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
162 av_log(
s->avctx,
AV_LOG_ERROR,
"chroma_log2_weight_denom %"PRId64
" is invalid\n", chroma_log2_weight_denom);
165 s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
168 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++) {
170 if (!luma_weight_l0_flag[
i]) {
171 s->sh.luma_weight_l0[
i] = 1 <<
s->sh.luma_log2_weight_denom;
172 s->sh.luma_offset_l0[
i] = 0;
175 if (
s->ps.sps->chroma_format_idc != 0) {
176 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++)
179 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++)
180 chroma_weight_l0_flag[
i] = 0;
182 for (
i = 0;
i <
s->sh.nb_refs[
L0];
i++) {
183 if (luma_weight_l0_flag[
i]) {
185 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
187 s->sh.luma_weight_l0[
i] = (1 <<
s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
190 if (chroma_weight_l0_flag[
i]) {
191 for (j = 0; j < 2; j++) {
195 if ( (int8_t)delta_chroma_weight_l0 != delta_chroma_weight_l0
196 || delta_chroma_offset_l0 < -(1<<17) || delta_chroma_offset_l0 > (1<<17)) {
200 s->sh.chroma_weight_l0[
i][j] = (1 <<
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
201 s->sh.chroma_offset_l0[
i][j] = av_clip((delta_chroma_offset_l0 - ((128 *
s->sh.chroma_weight_l0[
i][j])
202 >>
s->sh.chroma_log2_weight_denom) + 128), -128, 127);
205 s->sh.chroma_weight_l0[
i][0] = 1 <<
s->sh.chroma_log2_weight_denom;
206 s->sh.chroma_offset_l0[
i][0] = 0;
207 s->sh.chroma_weight_l0[
i][1] = 1 <<
s->sh.chroma_log2_weight_denom;
208 s->sh.chroma_offset_l0[
i][1] = 0;
212 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++) {
214 if (!luma_weight_l1_flag[
i]) {
215 s->sh.luma_weight_l1[
i] = 1 <<
s->sh.luma_log2_weight_denom;
216 s->sh.luma_offset_l1[
i] = 0;
219 if (
s->ps.sps->chroma_format_idc != 0) {
220 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++)
223 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++)
224 chroma_weight_l1_flag[
i] = 0;
226 for (
i = 0;
i <
s->sh.nb_refs[
L1];
i++) {
227 if (luma_weight_l1_flag[
i]) {
229 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
231 s->sh.luma_weight_l1[
i] = (1 <<
s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
234 if (chroma_weight_l1_flag[
i]) {
235 for (j = 0; j < 2; j++) {
239 if ( (int8_t)delta_chroma_weight_l1 != delta_chroma_weight_l1
240 || delta_chroma_offset_l1 < -(1<<17) || delta_chroma_offset_l1 > (1<<17)) {
244 s->sh.chroma_weight_l1[
i][j] = (1 <<
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
245 s->sh.chroma_offset_l1[
i][j] = av_clip((delta_chroma_offset_l1 - ((128 *
s->sh.chroma_weight_l1[
i][j])
246 >>
s->sh.chroma_log2_weight_denom) + 128), -128, 127);
249 s->sh.chroma_weight_l1[
i][0] = 1 <<
s->sh.chroma_log2_weight_denom;
250 s->sh.chroma_offset_l1[
i][0] = 0;
251 s->sh.chroma_weight_l1[
i][1] = 1 <<
s->sh.chroma_log2_weight_denom;
252 s->sh.chroma_offset_l1[
i][1] = 0;
262 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
263 int prev_delta_msb = 0;
264 unsigned int nb_sps = 0, nb_sh;
268 if (!
sps->long_term_ref_pics_present_flag)
271 if (
sps->num_long_term_ref_pics_sps > 0)
275 if (nb_sps >
sps->num_long_term_ref_pics_sps)
288 if (
sps->num_long_term_ref_pics_sps > 1)
289 lt_idx_sps =
get_bits(gb, av_ceil_log2(
sps->num_long_term_ref_pics_sps));
291 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
292 rps->
used[
i] =
sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
299 if (delta_poc_msb_present) {
303 if (
i &&
i != nb_sps)
304 delta += prev_delta_msb;
306 poc = rps->
poc[
i] +
s->poc -
delta * max_poc_lsb -
s->sh.pic_order_cnt_lsb;
310 prev_delta_msb =
delta;
323 unsigned int num = 0, den = 0;
328 avctx->
width =
sps->width - ow->left_offset - ow->right_offset;
329 avctx->
height =
sps->height - ow->top_offset - ow->bottom_offset;
331 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
332 avctx->
level =
sps->ptl.general_ptl.level_idc;
336 if (
sps->vui.video_signal_type_present_flag)
342 if (
sps->vui.colour_description_present_flag) {
352 if (
vps->vps_timing_info_present_flag) {
353 num =
vps->vps_num_units_in_tick;
354 den =
vps->vps_time_scale;
355 }
else if (
sps->vui.vui_timing_info_present_flag) {
356 num =
sps->vui.vui_num_units_in_tick;
357 den =
sps->vui.vui_time_scale;
360 if (num != 0 && den != 0)
364 if (
s->sei.alternative_transfer.present &&
367 avctx->
color_trc =
s->sei.alternative_transfer.preferred_transfer_characteristics;
373 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
374 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
375 CONFIG_HEVC_NVDEC_HWACCEL + \
376 CONFIG_HEVC_VAAPI_HWACCEL + \
377 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
378 CONFIG_HEVC_VDPAU_HWACCEL)
381 switch (
sps->pix_fmt) {
384 #if CONFIG_HEVC_DXVA2_HWACCEL
387 #if CONFIG_HEVC_D3D11VA_HWACCEL
391 #if CONFIG_HEVC_VAAPI_HWACCEL
394 #if CONFIG_HEVC_VDPAU_HWACCEL
397 #if CONFIG_HEVC_NVDEC_HWACCEL
400 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
405 #if CONFIG_HEVC_DXVA2_HWACCEL
408 #if CONFIG_HEVC_D3D11VA_HWACCEL
412 #if CONFIG_HEVC_VAAPI_HWACCEL
415 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
418 #if CONFIG_HEVC_NVDEC_HWACCEL
423 #if CONFIG_HEVC_VDPAU_HWACCEL
426 #if CONFIG_HEVC_NVDEC_HWACCEL
433 #if CONFIG_HEVC_NVDEC_HWACCEL
469 for (
i = 0;
i < 3;
i++) {
474 if (
sps->sao_enabled && !
s->avctx->hwaccel) {
475 int c_count = (
sps->chroma_format_idc != 0) ? 3 : 1;
478 for(c_idx = 0; c_idx < c_count; c_idx++) {
479 int w =
sps->width >>
sps->hshift[c_idx];
480 int h =
sps->height >>
sps->vshift[c_idx];
481 s->sao_pixel_buffer_h[c_idx] =
484 s->sao_pixel_buffer_v[c_idx] =
491 s->ps.vps = (
HEVCVPS*)
s->ps.vps_list[
s->ps.sps->vps_id]->data;
510 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
515 s->seq_decode = (
s->seq_decode + 1) & 0xff;
538 if (
s->ps.sps != (
HEVCSPS*)
s->ps.sps_list[
s->ps.pps->sps_id]->data) {
540 const HEVCSPS *last_sps =
s->ps.sps;
544 if (
sps->width != last_sps->width ||
sps->height != last_sps->height ||
545 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering !=
546 last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
560 s->seq_decode = (
s->seq_decode + 1) & 0xff;
566 int slice_address_length;
568 if (
s->ps.pps->dependent_slice_segments_enabled_flag)
571 slice_address_length = av_ceil_log2(
s->ps.sps->ctb_width *
572 s->ps.sps->ctb_height);
576 "Invalid slice segment address: %u.\n",
588 s->slice_initialized = 0;
592 s->slice_initialized = 0;
594 for (
i = 0;
i <
s->ps.pps->num_extra_slice_header_bits;
i++)
612 if (
s->ps.pps->output_flag_present_flag)
615 if (
s->ps.sps->separate_colour_plane_flag)
625 "Ignoring POC change between slices: %d -> %d\n",
s->poc, poc);
641 int numbits, rps_idx;
643 if (!
s->ps.sps->nb_st_rps) {
648 numbits = av_ceil_log2(
s->ps.sps->nb_st_rps);
649 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
663 if (
s->ps.sps->sps_temporal_mvp_enabled_flag)
668 s->sh.short_term_rps =
NULL;
683 if (
s->ps.sps->sao_enabled) {
685 if (
s->ps.sps->chroma_format_idc) {
699 sh->
nb_refs[
L0] =
s->ps.pps->num_ref_idx_l0_default_active;
701 sh->
nb_refs[
L1] =
s->ps.pps->num_ref_idx_l1_default_active;
722 if (
s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
740 if (
s->ps.pps->cabac_init_present_flag)
755 "Invalid collocated_ref_idx: %d.\n",
772 "Invalid number of merging MVP candidates: %d.\n",
780 if (
s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
793 if (
s->ps.pps->chroma_qp_offset_list_enabled_flag)
798 if (
s->ps.pps->deblocking_filter_control_present_flag) {
799 int deblocking_filter_override_flag = 0;
801 if (
s->ps.pps->deblocking_filter_override_enabled_flag)
802 deblocking_filter_override_flag =
get_bits1(gb);
804 if (deblocking_filter_override_flag) {
809 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
810 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
812 "Invalid deblock filter offsets: %d, %d\n",
813 beta_offset_div2, tc_offset_div2);
830 if (
s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
838 }
else if (!
s->slice_initialized) {
844 if (
s->ps.pps->tiles_enabled_flag ||
s->ps.pps->entropy_coding_sync_enabled_flag) {
848 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
856 if (offset_len < 1 || offset_len > 32) {
877 if (
s->threads_number > 1 && (
s->ps.pps->num_tile_rows > 1 ||
s->ps.pps->num_tile_columns > 1)) {
878 s->enable_parallel_tiles = 0;
879 s->threads_number = 1;
881 s->enable_parallel_tiles = 0;
883 s->enable_parallel_tiles = 0;
886 if (
s->ps.pps->slice_header_extension_present_flag) {
899 sh->
slice_qp < -
s->ps.sps->qp_bd_offset) {
901 "The slice_qp %d is outside the valid range "
904 -
s->ps.sps->qp_bd_offset);
910 if (!
s->sh.slice_ctb_addr_rs &&
s->sh.dependent_slice_segment_flag) {
921 s->HEVClc->first_qp_group = !
s->sh.dependent_slice_segment_flag;
923 if (!
s->ps.pps->cu_qp_delta_enabled_flag)
924 s->HEVClc->qp_y =
s->sh.slice_qp;
926 s->slice_initialized = 1;
927 s->HEVClc->tu.cu_qp_offset_cb = 0;
928 s->HEVClc->tu.cu_qp_offset_cr = 0;
933 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
935 #define SET_SAO(elem, value) \
937 if (!sao_merge_up_flag && !sao_merge_left_flag) \
939 else if (sao_merge_left_flag) \
940 sao->elem = CTB(s->sao, rx-1, ry).elem; \
941 else if (sao_merge_up_flag) \
942 sao->elem = CTB(s->sao, rx, ry-1).elem; \
950 int sao_merge_left_flag = 0;
951 int sao_merge_up_flag = 0;
955 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
956 s->sh.slice_sample_adaptive_offset_flag[1]) {
961 if (ry > 0 && !sao_merge_left_flag) {
967 for (c_idx = 0; c_idx < (
s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
968 int log2_sao_offset_scale = c_idx == 0 ?
s->ps.pps->log2_sao_offset_scale_luma :
969 s->ps.pps->log2_sao_offset_scale_chroma;
971 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
986 for (
i = 0;
i < 4;
i++)
990 for (
i = 0;
i < 4;
i++) {
999 }
else if (c_idx != 2) {
1005 for (
i = 0;
i < 4;
i++) {
1013 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1025 if (log2_res_scale_abs_plus1 != 0) {
1028 (1 - 2 * res_scale_sign_flag);
1038 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1039 int log2_cb_size,
int log2_trafo_size,
1040 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1043 const int log2_trafo_size_c = log2_trafo_size -
s->ps.sps->hshift[1];
1047 int trafo_size = 1 << log2_trafo_size;
1050 s->hpc.intra_pred[log2_trafo_size - 2](
s, x0, y0, 0);
1053 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1054 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1057 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1058 (
s->ps.sps->chroma_format_idc == 2 &&
1059 (cbf_cb[1] || cbf_cr[1]));
1071 "The cu_qp_delta %d is outside the valid range "
1074 -(26 +
s->ps.sps->qp_bd_offset / 2),
1075 (25 +
s->ps.sps->qp_bd_offset / 2));
1082 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1085 if (cu_chroma_qp_offset_flag) {
1086 int cu_chroma_qp_offset_idx = 0;
1087 if (
s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
1090 "cu_chroma_qp_offset_idx not yet tested.\n");
1123 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1124 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1125 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1126 lc->
tu.
cross_pf = (
s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
1133 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1136 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 1);
1140 log2_trafo_size_c, scan_idx_c, 1);
1143 ptrdiff_t
stride =
s->frame->linesize[1];
1144 int hshift =
s->ps.sps->hshift[1];
1145 int vshift =
s->ps.sps->vshift[1];
1148 int size = 1 << log2_trafo_size_c;
1151 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1155 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1162 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1165 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 2);
1169 log2_trafo_size_c, scan_idx_c, 2);
1172 ptrdiff_t
stride =
s->frame->linesize[2];
1173 int hshift =
s->ps.sps->hshift[2];
1174 int vshift =
s->ps.sps->vshift[2];
1177 int size = 1 << log2_trafo_size_c;
1180 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1184 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1187 }
else if (
s->ps.sps->chroma_format_idc && blk_idx == 3) {
1188 int trafo_size_h = 1 << (log2_trafo_size + 1);
1189 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1190 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1193 trafo_size_h, trafo_size_v);
1194 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 1);
1198 log2_trafo_size, scan_idx_c, 1);
1200 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1203 trafo_size_h, trafo_size_v);
1204 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 2);
1208 log2_trafo_size, scan_idx_c, 2);
1212 if (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3) {
1213 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1214 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1216 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 1);
1217 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 2);
1218 if (
s->ps.sps->chroma_format_idc == 2) {
1220 trafo_size_h, trafo_size_v);
1221 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 1);
1222 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 2);
1224 }
else if (blk_idx == 3) {
1225 int trafo_size_h = 1 << (log2_trafo_size + 1);
1226 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1228 trafo_size_h, trafo_size_v);
1229 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 1);
1230 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 2);
1231 if (
s->ps.sps->chroma_format_idc == 2) {
1233 trafo_size_h, trafo_size_v);
1234 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 1);
1235 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 2);
1245 int cb_size = 1 << log2_cb_size;
1246 int log2_min_pu_size =
s->ps.sps->log2_min_pu_size;
1248 int min_pu_width =
s->ps.sps->min_pu_width;
1249 int x_end =
FFMIN(x0 + cb_size,
s->ps.sps->width);
1250 int y_end =
FFMIN(y0 + cb_size,
s->ps.sps->height);
1253 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1254 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1255 s->is_pcm[
i + j * min_pu_width] = 2;
1259 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1260 int log2_cb_size,
int log2_trafo_size,
1261 int trafo_depth,
int blk_idx,
1262 const int *base_cbf_cb,
const int *base_cbf_cr)
1270 cbf_cb[0] = base_cbf_cb[0];
1271 cbf_cb[1] = base_cbf_cb[1];
1272 cbf_cr[0] = base_cbf_cr[0];
1273 cbf_cr[1] = base_cbf_cr[1];
1276 if (trafo_depth == 1) {
1278 if (
s->ps.sps->chroma_format_idc == 3) {
1292 if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
1293 log2_trafo_size >
s->ps.sps->log2_min_tb_size &&
1294 trafo_depth < lc->cu.max_trafo_depth &&
1298 int inter_split =
s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
1303 split_transform_flag = log2_trafo_size >
s->ps.sps->log2_max_trafo_size ||
1308 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1309 if (trafo_depth == 0 || cbf_cb[0]) {
1311 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1316 if (trafo_depth == 0 || cbf_cr[0]) {
1318 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1324 if (split_transform_flag) {
1325 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1326 const int x1 = x0 + trafo_size_split;
1327 const int y1 = y0 + trafo_size_split;
1329 #define SUBDIVIDE(x, y, idx) \
1331 ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1332 log2_trafo_size - 1, trafo_depth + 1, idx, \
1345 int min_tu_size = 1 <<
s->ps.sps->log2_min_tb_size;
1346 int log2_min_tu_size =
s->ps.sps->log2_min_tb_size;
1347 int min_tu_width =
s->ps.sps->min_tb_width;
1351 cbf_cb[0] || cbf_cr[0] ||
1352 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1357 log2_cb_size, log2_trafo_size,
1358 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1364 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1365 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1366 int x_tu = (x0 + j) >> log2_min_tu_size;
1367 int y_tu = (y0 +
i) >> log2_min_tu_size;
1368 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1371 if (!
s->sh.disable_deblocking_filter_flag) {
1373 if (
s->ps.pps->transquant_bypass_enable_flag &&
1385 int cb_size = 1 << log2_cb_size;
1386 ptrdiff_t stride0 =
s->frame->linesize[0];
1387 ptrdiff_t stride1 =
s->frame->linesize[1];
1388 ptrdiff_t stride2 =
s->frame->linesize[2];
1389 uint8_t *dst0 = &
s->frame->data[0][y0 * stride0 + (x0 <<
s->ps.sps->pixel_shift)];
1390 uint8_t *dst1 = &
s->frame->data[1][(y0 >>
s->ps.sps->vshift[1]) * stride1 + ((x0 >>
s->ps.sps->hshift[1]) <<
s->ps.sps->pixel_shift)];
1391 uint8_t *dst2 = &
s->frame->data[2][(y0 >>
s->ps.sps->vshift[2]) * stride2 + ((x0 >>
s->ps.sps->hshift[2]) <<
s->ps.sps->pixel_shift)];
1393 int length = cb_size * cb_size *
s->ps.sps->pcm.bit_depth +
1394 (((cb_size >>
s->ps.sps->hshift[1]) * (cb_size >>
s->ps.sps->vshift[1])) +
1395 ((cb_size >>
s->ps.sps->hshift[2]) * (cb_size >>
s->ps.sps->vshift[2]))) *
1396 s->ps.sps->pcm.bit_depth_chroma;
1400 if (!
s->sh.disable_deblocking_filter_flag)
1407 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
s->ps.sps->pcm.bit_depth);
1408 if (
s->ps.sps->chroma_format_idc) {
1409 s->hevcdsp.put_pcm(dst1, stride1,
1410 cb_size >>
s->ps.sps->hshift[1],
1411 cb_size >>
s->ps.sps->vshift[1],
1412 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1413 s->hevcdsp.put_pcm(dst2, stride2,
1414 cb_size >>
s->ps.sps->hshift[2],
1415 cb_size >>
s->ps.sps->vshift[2],
1416 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1440 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1444 ptrdiff_t srcstride =
ref->linesize[0];
1445 int pic_width =
s->ps.sps->width;
1446 int pic_height =
s->ps.sps->height;
1449 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1450 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1453 x_off +=
mv->x >> 2;
1454 y_off +=
mv->y >> 2;
1455 src += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1465 edge_emu_stride, srcstride,
1469 pic_width, pic_height);
1471 srcstride = edge_emu_stride;
1475 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1476 block_h, mx, my, block_w);
1478 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1479 block_h,
s->sh.luma_log2_weight_denom,
1480 luma_weight, luma_offset, mx, my, block_w);
1500 AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1501 int block_w,
int block_h,
AVFrame *ref1,
const Mv *mv1,
struct MvField *current_mv)
1504 ptrdiff_t src0stride = ref0->
linesize[0];
1505 ptrdiff_t src1stride = ref1->
linesize[0];
1506 int pic_width =
s->ps.sps->width;
1507 int pic_height =
s->ps.sps->height;
1508 int mx0 = mv0->
x & 3;
1509 int my0 = mv0->
y & 3;
1510 int mx1 = mv1->
x & 3;
1511 int my1 = mv1->
y & 3;
1512 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1513 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1514 int x_off0 = x_off + (mv0->
x >> 2);
1515 int y_off0 = y_off + (mv0->
y >> 2);
1516 int x_off1 = x_off + (mv1->
x >> 2);
1517 int y_off1 = y_off + (mv1->
y >> 2);
1520 uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1521 uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1531 edge_emu_stride, src0stride,
1535 pic_width, pic_height);
1537 src0stride = edge_emu_stride;
1548 edge_emu_stride, src1stride,
1552 pic_width, pic_height);
1554 src1stride = edge_emu_stride;
1557 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1558 block_h, mx0, my0, block_w);
1560 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1561 block_h, mx1, my1, block_w);
1563 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1564 block_h,
s->sh.luma_log2_weight_denom,
1565 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1566 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1567 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1568 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1591 ptrdiff_t dststride,
uint8_t *
src0, ptrdiff_t srcstride,
int reflist,
1592 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1595 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1596 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1597 const Mv *
mv = ¤t_mv->
mv[reflist];
1598 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1599 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1601 int hshift =
s->ps.sps->hshift[1];
1602 int vshift =
s->ps.sps->vshift[1];
1603 intptr_t mx = av_mod_uintp2(
mv->x, 2 + hshift);
1604 intptr_t my = av_mod_uintp2(
mv->y, 2 + vshift);
1605 intptr_t _mx = mx << (1 - hshift);
1606 intptr_t _my = my << (1 - vshift);
1608 x_off +=
mv->x >> (2 + hshift);
1609 y_off +=
mv->y >> (2 + vshift);
1610 src0 += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1618 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1620 edge_emu_stride, srcstride,
1624 pic_width, pic_height);
1627 srcstride = edge_emu_stride;
1630 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1631 block_h, _mx, _my, block_w);
1633 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1634 block_h,
s->sh.chroma_log2_weight_denom,
1635 chroma_weight, chroma_offset, _mx, _my, block_w);
1656 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int cidx)
1661 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1662 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1663 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1664 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1665 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1666 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1667 Mv *mv0 = ¤t_mv->
mv[0];
1668 Mv *mv1 = ¤t_mv->
mv[1];
1669 int hshift =
s->ps.sps->hshift[1];
1670 int vshift =
s->ps.sps->vshift[1];
1672 intptr_t mx0 = av_mod_uintp2(mv0->
x, 2 + hshift);
1673 intptr_t my0 = av_mod_uintp2(mv0->
y, 2 + vshift);
1674 intptr_t mx1 = av_mod_uintp2(mv1->
x, 2 + hshift);
1675 intptr_t my1 = av_mod_uintp2(mv1->
y, 2 + vshift);
1676 intptr_t _mx0 = mx0 << (1 - hshift);
1677 intptr_t _my0 = my0 << (1 - vshift);
1678 intptr_t _mx1 = mx1 << (1 - hshift);
1679 intptr_t _my1 = my1 << (1 - vshift);
1681 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1682 int y_off0 = y_off + (mv0->
y >> (2 + vshift));
1683 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1684 int y_off1 = y_off + (mv1->
y >> (2 + vshift));
1686 src1 += y_off0 * src1stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1687 src2 += y_off1 * src2stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1695 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1698 edge_emu_stride, src1stride,
1702 pic_width, pic_height);
1705 src1stride = edge_emu_stride;
1714 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1717 edge_emu_stride, src2stride,
1721 pic_width, pic_height);
1724 src2stride = edge_emu_stride;
1727 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
1728 block_h, _mx0, _my0, block_w);
1730 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1731 src2, src2stride, lc->
tmp,
1732 block_h, _mx1, _my1, block_w);
1734 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1735 src2, src2stride, lc->
tmp,
1737 s->sh.chroma_log2_weight_denom,
1738 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
1739 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
1740 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
1741 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
1742 _mx1, _my1, block_w);
1756 int nPbH,
int log2_cb_size,
int part_idx,
1768 if (inter_pred_idc !=
PRED_L1) {
1769 if (
s->sh.nb_refs[
L0])
1776 part_idx, merge_idx,
mv, mvp_flag, 0);
1781 if (inter_pred_idc !=
PRED_L0) {
1782 if (
s->sh.nb_refs[
L1])
1785 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
1794 part_idx, merge_idx,
mv, mvp_flag, 1);
1802 int log2_cb_size,
int partIdx,
int idx)
1804 #define POS(c_idx, x, y) \
1805 &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1806 (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
1809 struct MvField current_mv = {{{ 0 }}};
1811 int min_pu_width =
s->ps.sps->min_pu_width;
1813 MvField *tab_mvf =
s->ref->tab_mvf;
1819 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
1820 int min_cb_width =
s->ps.sps->min_cb_width;
1821 int x_cb = x0 >> log2_min_cb_size;
1822 int y_cb = y0 >> log2_min_cb_size;
1826 int skip_flag =
SAMPLE_CTB(
s->skip_flag, x_cb, y_cb);
1832 if (
s->sh.max_num_merge_cand > 1)
1838 partIdx, merge_idx, ¤t_mv);
1841 partIdx, merge_idx, ¤t_mv);
1844 x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1845 y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1847 for (j = 0; j < nPbH >>
s->ps.sps->log2_min_pu_size; j++)
1848 for (
i = 0; i < nPbW >>
s->ps.sps->log2_min_pu_size;
i++)
1849 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
1852 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
1858 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
1865 int x0_c = x0 >>
s->ps.sps->hshift[1];
1866 int y0_c = y0 >>
s->ps.sps->vshift[1];
1867 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1868 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1871 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1872 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
1873 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
1875 if (
s->ps.sps->chroma_format_idc) {
1877 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1878 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
1880 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1881 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
1884 int x0_c = x0 >>
s->ps.sps->hshift[1];
1885 int y0_c = y0 >>
s->ps.sps->vshift[1];
1886 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1887 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1890 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
1891 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
1892 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
1894 if (
s->ps.sps->chroma_format_idc) {
1895 chroma_mc_uni(
s, dst1,
s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1],
1896 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1897 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
1899 chroma_mc_uni(
s, dst2,
s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2],
1900 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1901 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
1904 int x0_c = x0 >>
s->ps.sps->hshift[1];
1905 int y0_c = y0 >>
s->ps.sps->vshift[1];
1906 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1907 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1910 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1911 ref1->frame, ¤t_mv.
mv[1], ¤t_mv);
1913 if (
s->ps.sps->chroma_format_idc) {
1915 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
1918 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
1927 int prev_intra_luma_pred_flag)
1930 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1931 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1932 int min_pu_width =
s->ps.sps->min_pu_width;
1933 int size_in_pus = pu_size >>
s->ps.sps->log2_min_pu_size;
1934 int x0b = av_mod_uintp2(x0,
s->ps.sps->log2_ctb_size);
1935 int y0b = av_mod_uintp2(y0,
s->ps.sps->log2_ctb_size);
1938 s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] :
INTRA_DC;
1940 s->tab_ipm[y_pu * min_pu_width + x_pu - 1] :
INTRA_DC;
1942 int y_ctb = (y0 >> (
s->ps.sps->log2_ctb_size)) << (
s->ps.sps->log2_ctb_size);
1944 MvField *tab_mvf =
s->ref->tab_mvf;
1945 int intra_pred_mode;
1950 if ((y0 - 1) < y_ctb)
1953 if (cand_left == cand_up) {
1954 if (cand_left < 2) {
1959 candidate[0] = cand_left;
1960 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
1961 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
1964 candidate[0] = cand_left;
1965 candidate[1] = cand_up;
1975 if (prev_intra_luma_pred_flag) {
1976 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
1978 if (candidate[0] > candidate[1])
1980 if (candidate[0] > candidate[2])
1982 if (candidate[1] > candidate[2])
1986 for (
i = 0;
i < 3;
i++)
1987 if (intra_pred_mode >= candidate[
i])
1994 for (
i = 0;
i < size_in_pus;
i++) {
1995 memset(&
s->tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
1996 intra_pred_mode, size_in_pus);
1998 for (j = 0; j < size_in_pus; j++) {
2003 return intra_pred_mode;
2007 int log2_cb_size,
int ct_depth)
2009 int length = (1 << log2_cb_size) >>
s->ps.sps->log2_min_cb_size;
2010 int x_cb = x0 >>
s->ps.sps->log2_min_cb_size;
2011 int y_cb = y0 >>
s->ps.sps->log2_min_cb_size;
2015 memset(&
s->tab_ct_depth[(y_cb + y) *
s->ps.sps->min_cb_width + x_cb],
2020 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2021 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2027 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2028 uint8_t prev_intra_luma_pred_flag[4];
2030 int pb_size = (1 << log2_cb_size) >>
split;
2031 int side =
split + 1;
2035 for (
i = 0;
i < side;
i++)
2036 for (j = 0; j < side; j++)
2039 for (
i = 0;
i < side;
i++) {
2040 for (j = 0; j < side; j++) {
2041 if (prev_intra_luma_pred_flag[2 *
i + j])
2048 prev_intra_luma_pred_flag[2 *
i + j]);
2052 if (
s->ps.sps->chroma_format_idc == 3) {
2053 for (
i = 0;
i < side;
i++) {
2054 for (j = 0; j < side; j++) {
2056 if (chroma_mode != 4) {
2066 }
else if (
s->ps.sps->chroma_format_idc == 2) {
2069 if (chroma_mode != 4) {
2073 mode_idx = intra_chroma_table[chroma_mode];
2078 }
else if (
s->ps.sps->chroma_format_idc != 0) {
2080 if (chroma_mode != 4) {
2096 int pb_size = 1 << log2_cb_size;
2097 int size_in_pus = pb_size >>
s->ps.sps->log2_min_pu_size;
2098 int min_pu_width =
s->ps.sps->min_pu_width;
2099 MvField *tab_mvf =
s->ref->tab_mvf;
2100 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
2101 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
2104 if (size_in_pus == 0)
2106 for (j = 0; j < size_in_pus; j++)
2107 memset(&
s->tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2109 for (j = 0; j < size_in_pus; j++)
2110 for (k = 0; k < size_in_pus; k++)
2116 int cb_size = 1 << log2_cb_size;
2118 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
2119 int length = cb_size >> log2_min_cb_size;
2120 int min_cb_width =
s->ps.sps->min_cb_width;
2121 int x_cb = x0 >> log2_min_cb_size;
2122 int y_cb = y0 >> log2_min_cb_size;
2123 int idx = log2_cb_size - 2;
2124 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2134 for (x = 0; x < 4; x++)
2136 if (
s->ps.pps->transquant_bypass_enable_flag) {
2146 x = y_cb * min_cb_width + x_cb;
2147 for (y = 0; y <
length; y++) {
2148 memset(&
s->skip_flag[x], skip_flag,
length);
2153 x = y_cb * min_cb_width + x_cb;
2154 for (y = 0; y <
length; y++) {
2155 memset(&
s->skip_flag[x], 0,
length);
2164 if (!
s->sh.disable_deblocking_filter_flag)
2172 log2_cb_size ==
s->ps.sps->log2_min_cb_size) {
2180 log2_cb_size >=
s->ps.sps->pcm.log2_min_pcm_cb_size &&
2181 log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) {
2187 if (
s->ps.sps->pcm.loop_filter_disable_flag)
2219 hls_prediction_unit(
s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2223 hls_prediction_unit(
s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2227 hls_prediction_unit(
s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2228 hls_prediction_unit(
s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2229 hls_prediction_unit(
s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2235 int rqt_root_cbf = 1;
2242 const static int cbf[2] = { 0 };
2245 s->ps.sps->max_transform_hierarchy_depth_inter;
2248 log2_cb_size, 0, 0, cbf, cbf);
2252 if (!
s->sh.disable_deblocking_filter_flag)
2261 x = y_cb * min_cb_width + x_cb;
2262 for (y = 0; y <
length; y++) {
2267 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2268 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2278 int log2_cb_size,
int cb_depth)
2281 const int cb_size = 1 << log2_cb_size;
2286 if (x0 + cb_size <= s->ps.sps->width &&
2287 y0 + cb_size <= s->ps.sps->height &&
2288 log2_cb_size >
s->ps.sps->log2_min_cb_size) {
2291 split_cu = (log2_cb_size >
s->ps.sps->log2_min_cb_size);
2293 if (
s->ps.pps->cu_qp_delta_enabled_flag &&
2294 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth) {
2299 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2300 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_chroma_qp_offset_depth) {
2305 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2306 const int cb_size_split = cb_size >> 1;
2307 const int x1 = x0 + cb_size_split;
2308 const int y1 = y0 + cb_size_split;
2316 if (more_data && x1 < s->ps.sps->width) {
2321 if (more_data && y1 < s->ps.sps->height) {
2326 if (more_data && x1 < s->ps.sps->width &&
2327 y1 < s->ps.sps->height) {
2333 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2334 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2338 return ((x1 + cb_size_split) <
s->ps.sps->width ||
2339 (y1 + cb_size_split) <
s->ps.sps->height);
2346 if ((!((x0 + cb_size) %
2347 (1 << (
s->ps.sps->log2_ctb_size))) ||
2348 (x0 + cb_size >=
s->ps.sps->width)) &&
2350 (1 << (
s->ps.sps->log2_ctb_size))) ||
2351 (y0 + cb_size >=
s->ps.sps->height))) {
2353 return !end_of_slice_flag;
2366 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2367 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2368 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2370 s->tab_slice_address[ctb_addr_rs] =
s->sh.slice_addr;
2372 if (
s->ps.pps->entropy_coding_sync_enabled_flag) {
2373 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2376 }
else if (
s->ps.pps->tiles_enabled_flag) {
2377 if (ctb_addr_ts &&
s->ps.pps->tile_id[ctb_addr_ts] !=
s->ps.pps->tile_id[ctb_addr_ts - 1]) {
2378 int idxX =
s->ps.pps->col_idxX[x_ctb >>
s->ps.sps->log2_ctb_size];
2379 lc->
end_of_tiles_x = x_ctb + (
s->ps.pps->column_width[idxX] <<
s->ps.sps->log2_ctb_size);
2389 if (
s->ps.pps->tiles_enabled_flag) {
2390 if (x_ctb > 0 &&
s->ps.pps->tile_id[ctb_addr_ts] !=
s->ps.pps->tile_id[
s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
2392 if (x_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs - 1])
2394 if (y_ctb > 0 &&
s->ps.pps->tile_id[ctb_addr_ts] !=
s->ps.pps->tile_id[
s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs -
s->ps.sps->ctb_width]])
2396 if (y_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs -
s->ps.sps->ctb_width])
2399 if (ctb_addr_in_slice <= 0)
2401 if (ctb_addr_in_slice < s->ps.sps->ctb_width)
2407 lc->
ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >=
s->ps.sps->ctb_width) && (
s->ps.pps->tile_id[ctb_addr_ts] ==
s->ps.pps->tile_id[
s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 -
s->ps.sps->ctb_width]]));
2408 lc->
ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >=
s->ps.sps->ctb_width) && (
s->ps.pps->tile_id[ctb_addr_ts] ==
s->ps.pps->tile_id[
s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 -
s->ps.sps->ctb_width]]));
2414 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2418 int ctb_addr_ts =
s->ps.pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2421 if (!ctb_addr_ts &&
s->sh.dependent_slice_segment_flag) {
2426 if (
s->sh.dependent_slice_segment_flag) {
2427 int prev_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2428 if (
s->tab_slice_address[prev_rs] !=
s->sh.slice_addr) {
2434 while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2435 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2437 x_ctb = (ctb_addr_rs % ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2438 y_ctb = (ctb_addr_rs / ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2443 s->tab_slice_address[ctb_addr_rs] = -1;
2447 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2449 s->deblock[ctb_addr_rs].beta_offset =
s->sh.beta_offset;
2450 s->deblock[ctb_addr_rs].tc_offset =
s->sh.tc_offset;
2451 s->filter_slice_edges[ctb_addr_rs] =
s->sh.slice_loop_filter_across_slices_enabled_flag;
2454 if (more_data < 0) {
2455 s->tab_slice_address[ctb_addr_rs] = -1;
2465 if (x_ctb + ctb_size >=
s->ps.sps->width &&
2466 y_ctb + ctb_size >=
s->ps.sps->height)
2487 int ctb_size = 1<<
s1->ps.sps->log2_ctb_size;
2489 int *ctb_row_p = input_ctb_row;
2490 int ctb_row = ctb_row_p[job];
2491 int ctb_addr_rs =
s1->sh.slice_ctb_addr_rs + ctb_row * ((
s1->ps.sps->width + ctb_size - 1) >>
s1->ps.sps->log2_ctb_size);
2492 int ctb_addr_ts =
s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2493 int thread = ctb_row %
s1->threads_number;
2496 s =
s1->sList[self_id];
2506 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2507 int x_ctb = (ctb_addr_rs %
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2508 int y_ctb = (ctb_addr_rs /
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2522 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2525 if (more_data < 0) {
2536 if (!more_data && (x_ctb+ctb_size) <
s->ps.sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2542 if ((x_ctb+ctb_size) >=
s->ps.sps->width && (y_ctb+ctb_size) >=
s->ps.sps->height ) {
2547 ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2550 if(x_ctb >=
s->ps.sps->width) {
2558 s->tab_slice_address[ctb_addr_rs] = -1;
2572 int64_t startheader, cmpt = 0;
2581 if (
s->sh.slice_ctb_addr_rs +
s->sh.num_entry_point_offsets *
s->ps.sps->ctb_width >=
s->ps.sps->ctb_width *
s->ps.sps->ctb_height) {
2583 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2584 s->ps.sps->ctb_width,
s->ps.sps->ctb_height
2593 for (
i = 1;
i <
s->threads_number;
i++) {
2597 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2603 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2610 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2611 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2612 for (j = 0, cmpt = 0, startheader =
offset
2613 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2619 s->sh.size[
i - 1] =
s->sh.entry_point_offset[
i] - cmpt;
2623 if (
s->sh.num_entry_point_offsets != 0) {
2624 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2631 s->sh.offset[
s->sh.num_entry_point_offsets - 1] =
offset;
2636 for (
i = 1;
i <
s->threads_number;
i++) {
2637 s->sList[
i]->HEVClc->first_qp_group = 1;
2638 s->sList[
i]->HEVClc->qp_y =
s->sList[0]->HEVClc->qp_y;
2640 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2646 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++) {
2651 if (
s->ps.pps->entropy_coding_sync_enabled_flag)
2654 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
2666 if (
s->sei.frame_packing.present &&
2667 s->sei.frame_packing.arrangement_type >= 3 &&
2668 s->sei.frame_packing.arrangement_type <= 5 &&
2669 s->sei.frame_packing.content_interpretation_type > 0 &&
2670 s->sei.frame_packing.content_interpretation_type < 3) {
2675 switch (
s->sei.frame_packing.arrangement_type) {
2677 if (
s->sei.frame_packing.quincunx_subsampling)
2690 if (
s->sei.frame_packing.content_interpretation_type == 2)
2693 if (
s->sei.frame_packing.arrangement_type == 5) {
2694 if (
s->sei.frame_packing.current_frame_is_frame0_flag)
2701 if (
s->sei.display_orientation.present &&
2702 (
s->sei.display_orientation.anticlockwise_rotation ||
2703 s->sei.display_orientation.hflip ||
s->sei.display_orientation.vflip)) {
2704 double angle =
s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16);
2713 s->sei.display_orientation.hflip,
2714 s->sei.display_orientation.vflip);
2719 if (
s->sei.mastering_display.present > 0 &&
2721 s->sei.mastering_display.present--;
2723 if (
s->sei.mastering_display.present) {
2725 const int mapping[3] = {2, 0, 1};
2726 const int chroma_den = 50000;
2727 const int luma_den = 10000;
2734 for (
i = 0;
i < 3;
i++) {
2735 const int j = mapping[
i];
2741 metadata->
white_point[0].
num =
s->sei.mastering_display.white_point[0];
2743 metadata->
white_point[1].
num =
s->sei.mastering_display.white_point[1];
2755 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
2764 "min_luminance=%f, max_luminance=%f\n",
2769 if (
s->sei.content_light.present > 0 &&
2771 s->sei.content_light.present--;
2773 if (
s->sei.content_light.present) {
2778 metadata->
MaxCLL =
s->sei.content_light.max_content_light_level;
2779 metadata->
MaxFALL =
s->sei.content_light.max_pic_average_light_level;
2786 if (
s->sei.a53_caption.a53_caption) {
2789 s->sei.a53_caption.a53_caption_size);
2791 memcpy(sd->
data,
s->sei.a53_caption.a53_caption,
s->sei.a53_caption.a53_caption_size);
2792 av_freep(&
s->sei.a53_caption.a53_caption);
2793 s->sei.a53_caption.a53_caption_size = 0;
2803 int pic_size_in_ctb = ((
s->ps.sps->width >>
s->ps.sps->log2_min_cb_size) + 1) *
2804 ((
s->ps.sps->height >>
s->ps.sps->log2_min_cb_size) + 1);
2807 memset(
s->horizontal_bs, 0,
s->bs_width *
s->bs_height);
2808 memset(
s->vertical_bs, 0,
s->bs_width *
s->bs_height);
2809 memset(
s->cbf_luma, 0,
s->ps.sps->min_tb_width *
s->ps.sps->min_tb_height);
2810 memset(
s->is_pcm, 0, (
s->ps.sps->min_pu_width + 1) * (
s->ps.sps->min_pu_height + 1));
2811 memset(
s->tab_slice_address, -1, pic_size_in_ctb *
sizeof(*
s->tab_slice_address));
2814 s->first_nal_type =
s->nal_unit_type;
2818 if (
s->ps.pps->tiles_enabled_flag)
2819 lc->
end_of_tiles_x =
s->ps.pps->column_width[0] <<
s->ps.sps->log2_ctb_size;
2837 s->frame->pict_type = 3 -
s->sh.slice_type;
2847 if (!
s->avctx->hwaccel)
2863 int ctb_addr_ts,
ret;
2866 s->nal_unit_type = nal->
type;
2869 switch (
s->nal_unit_type) {
2871 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2872 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2884 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2885 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2893 s->apply_defdispwin);
2898 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2899 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2912 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2913 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2956 if (
s->sh.first_slice_in_pic_flag) {
2957 if (
s->max_ra == INT_MAX) {
2962 s->max_ra = INT_MIN;
2967 s->poc <=
s->max_ra) {
2972 s->max_ra = INT_MIN;
2979 }
else if (!
s->ref) {
2984 if (
s->nal_unit_type !=
s->first_nal_type) {
2986 "Non-matching NAL types of the VCL NALUs: %d %d\n",
2987 s->first_nal_type,
s->nal_unit_type);
2991 if (!
s->sh.dependent_slice_segment_flag &&
2996 "Error constructing the reference lists for the current slice.\n");
3001 if (
s->sh.first_slice_in_pic_flag &&
s->avctx->hwaccel) {
3002 ret =
s->avctx->hwaccel->start_frame(
s->avctx,
NULL, 0);
3007 if (
s->avctx->hwaccel) {
3012 if (
s->threads_number > 1 &&
s->sh.num_entry_point_offsets > 0)
3016 if (ctb_addr_ts >= (
s->ps.sps->ctb_width *
s->ps.sps->ctb_height)) {
3020 if (ctb_addr_ts < 0) {
3028 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3029 s->max_ra = INT_MAX;
3036 "Skipping NAL unit %d\n",
s->nal_unit_type);
3049 int eos_at_start = 1;
3052 s->last_eos =
s->eos;
3059 s->nal_length_size,
s->avctx->codec_id, 1, 0);
3062 "Error splitting the input into NAL units.\n");
3066 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3080 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3089 if (
ret >= 0 &&
s->overlap > 2)
3093 "Error parsing NAL unit #%d.\n",
i);
3108 for (
i = 0;
i < 16;
i++)
3121 pixel_shift =
desc->comp[0].depth > 8;
3129 if (pixel_shift && !
s->checksum_buf) {
3132 frame->linesize[2]));
3133 if (!
s->checksum_buf)
3139 int width =
s->avctx->coded_width;
3140 int height =
s->avctx->coded_height;
3146 for (j = 0; j <
h; j++) {
3150 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3151 (
const uint16_t *)
src,
w);
3152 src =
s->checksum_buf;
3159 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3183 &
s->nal_length_size,
s->avctx->err_recognition,
3184 s->apply_defdispwin,
s->avctx);
3190 if (
first &&
s->ps.sps_list[
i]) {
3204 int new_extradata_size;
3218 &new_extradata_size);
3219 if (new_extradata && new_extradata_size > 0) {
3233 "hardware accelerator failed to decode picture\n");
3240 s->sei.picture_hash.is_md5) {
3248 s->sei.picture_hash.is_md5 = 0;
3250 if (
s->is_decoded) {
3255 if (
s->output_frame->buf[0]) {
3290 if (
src->hwaccel_picture_private) {
3314 for (
i = 0;
i < 3;
i++) {
3331 for (
i = 1;
i <
s->threads_number;
i++) {
3338 if (
s->HEVClc ==
s->HEVClcList[0])
3359 s->HEVClcList[0] =
s->HEVClc;
3363 if (!
s->cabac_state)
3367 if (!
s->output_frame)
3372 if (!
s->DPB[
i].frame)
3374 s->DPB[
i].tf.f =
s->DPB[
i].frame;
3377 s->max_ra = INT_MAX;
3385 s->context_initialized = 1;
3405 if (!
s->context_initialized) {
3413 if (
s0->DPB[
i].frame->buf[0]) {
3420 if (
s->ps.sps !=
s0->ps.sps)
3424 if (
s0->ps.vps_list[
i]) {
3426 if (!
s->ps.vps_list[
i])
3433 if (
s0->ps.sps_list[
i]) {
3435 if (!
s->ps.sps_list[
i])
3442 if (
s0->ps.pps_list[
i]) {
3444 if (!
s->ps.pps_list[
i])
3449 if (
s->ps.sps !=
s0->ps.sps)
3453 s->seq_decode =
s0->seq_decode;
3454 s->seq_output =
s0->seq_output;
3455 s->pocTid0 =
s0->pocTid0;
3456 s->max_ra =
s0->max_ra;
3458 s->no_rasl_output_flag =
s0->no_rasl_output_flag;
3460 s->is_nalff =
s0->is_nalff;
3461 s->nal_length_size =
s0->nal_length_size;
3463 s->threads_number =
s0->threads_number;
3464 s->threads_type =
s0->threads_type;
3467 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3468 s->max_ra = INT_MAX;
3471 s->sei.frame_packing =
s0->sei.frame_packing;
3472 s->sei.display_orientation =
s0->sei.display_orientation;
3473 s->sei.mastering_display =
s0->sei.mastering_display;
3474 s->sei.content_light =
s0->sei.content_light;
3475 s->sei.alternative_transfer =
s0->sei.alternative_transfer;
3492 s->enable_parallel_tiles = 0;
3493 s->sei.picture_timing.picture_struct = 0;
3501 s->threads_number = 1;
3525 memset(
s, 0,
sizeof(*
s));
3540 s->max_ra = INT_MAX;
3544 #define OFFSET(x) offsetof(HEVCContext, x)
3545 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
3548 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
3550 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
3580 #if CONFIG_HEVC_DXVA2_HWACCEL
3583 #if CONFIG_HEVC_D3D11VA_HWACCEL
3586 #if CONFIG_HEVC_D3D11VA2_HWACCEL
3589 #if CONFIG_HEVC_NVDEC_HWACCEL
3592 #if CONFIG_HEVC_VAAPI_HWACCEL
3595 #if CONFIG_HEVC_VDPAU_HWACCEL
3598 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL