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)
287 if (
sps->num_long_term_ref_pics_sps > 1)
288 lt_idx_sps =
get_bits(gb, av_ceil_log2(
sps->num_long_term_ref_pics_sps));
290 rps->
poc[
i] =
sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
291 rps->
used[
i] =
sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
302 if (
i &&
i != nb_sps)
303 delta += prev_delta_msb;
305 poc = rps->
poc[
i] +
s->poc -
delta * max_poc_lsb -
s->sh.pic_order_cnt_lsb;
309 prev_delta_msb =
delta;
322 unsigned int num = 0, den = 0;
327 avctx->
width =
sps->width - ow->left_offset - ow->right_offset;
328 avctx->
height =
sps->height - ow->top_offset - ow->bottom_offset;
330 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
331 avctx->
level =
sps->ptl.general_ptl.level_idc;
335 if (
sps->vui.video_signal_type_present_flag)
341 if (
sps->vui.colour_description_present_flag) {
351 if (
vps->vps_timing_info_present_flag) {
352 num =
vps->vps_num_units_in_tick;
353 den =
vps->vps_time_scale;
354 }
else if (
sps->vui.vui_timing_info_present_flag) {
355 num =
sps->vui.vui_num_units_in_tick;
356 den =
sps->vui.vui_time_scale;
359 if (num != 0 && den != 0)
363 if (
s->sei.alternative_transfer.present &&
366 avctx->
color_trc =
s->sei.alternative_transfer.preferred_transfer_characteristics;
372 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
373 CONFIG_HEVC_D3D11VA_HWACCEL * 2 + \
374 CONFIG_HEVC_NVDEC_HWACCEL + \
375 CONFIG_HEVC_VAAPI_HWACCEL + \
376 CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
377 CONFIG_HEVC_VDPAU_HWACCEL)
380 switch (
sps->pix_fmt) {
383 #if CONFIG_HEVC_DXVA2_HWACCEL
386 #if CONFIG_HEVC_D3D11VA_HWACCEL
390 #if CONFIG_HEVC_VAAPI_HWACCEL
393 #if CONFIG_HEVC_VDPAU_HWACCEL
396 #if CONFIG_HEVC_NVDEC_HWACCEL
399 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
404 #if CONFIG_HEVC_DXVA2_HWACCEL
407 #if CONFIG_HEVC_D3D11VA_HWACCEL
411 #if CONFIG_HEVC_VAAPI_HWACCEL
414 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
417 #if CONFIG_HEVC_NVDEC_HWACCEL
422 #if CONFIG_HEVC_VDPAU_HWACCEL
425 #if CONFIG_HEVC_NVDEC_HWACCEL
431 #if CONFIG_HEVC_VAAPI_HWACCEL
438 #if CONFIG_HEVC_NVDEC_HWACCEL
444 *fmt++ =
sps->pix_fmt;
474 for (
i = 0;
i < 3;
i++) {
479 if (
sps->sao_enabled && !
s->avctx->hwaccel) {
480 int c_count = (
sps->chroma_format_idc != 0) ? 3 : 1;
483 for(c_idx = 0; c_idx < c_count; c_idx++) {
484 int w =
sps->width >>
sps->hshift[c_idx];
485 int h =
sps->height >>
sps->vshift[c_idx];
486 s->sao_pixel_buffer_h[c_idx] =
489 s->sao_pixel_buffer_v[c_idx] =
496 s->ps.vps = (
HEVCVPS*)
s->ps.vps_list[
s->ps.sps->vps_id]->data;
515 av_log(
s->avctx,
AV_LOG_ERROR,
"Two slices reporting being the first in the same frame.\n");
520 s->seq_decode = (
s->seq_decode + 1) & 0xff;
543 if (
s->ps.sps != (
HEVCSPS*)
s->ps.sps_list[
s->ps.pps->sps_id]->data) {
545 const HEVCSPS *last_sps =
s->ps.sps;
549 if (
sps->width != last_sps->width ||
sps->height != last_sps->height ||
550 sps->temporal_layer[
sps->max_sub_layers - 1].max_dec_pic_buffering !=
551 last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
565 s->seq_decode = (
s->seq_decode + 1) & 0xff;
571 int slice_address_length;
573 if (
s->ps.pps->dependent_slice_segments_enabled_flag)
576 slice_address_length = av_ceil_log2(
s->ps.sps->ctb_width *
577 s->ps.sps->ctb_height);
581 "Invalid slice segment address: %u.\n",
593 s->slice_initialized = 0;
597 s->slice_initialized = 0;
599 for (
i = 0;
i <
s->ps.pps->num_extra_slice_header_bits;
i++)
617 if (
s->ps.pps->output_flag_present_flag)
620 if (
s->ps.sps->separate_colour_plane_flag)
630 "Ignoring POC change between slices: %d -> %d\n",
s->poc, poc);
646 int numbits, rps_idx;
648 if (!
s->ps.sps->nb_st_rps) {
653 numbits = av_ceil_log2(
s->ps.sps->nb_st_rps);
654 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
668 if (
s->ps.sps->sps_temporal_mvp_enabled_flag)
673 s->sh.short_term_rps =
NULL;
688 if (
s->ps.sps->sao_enabled) {
690 if (
s->ps.sps->chroma_format_idc) {
704 sh->
nb_refs[
L0] =
s->ps.pps->num_ref_idx_l0_default_active;
706 sh->
nb_refs[
L1] =
s->ps.pps->num_ref_idx_l1_default_active;
727 if (
s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
745 if (
s->ps.pps->cabac_init_present_flag)
760 "Invalid collocated_ref_idx: %d.\n",
777 "Invalid number of merging MVP candidates: %d.\n",
785 if (
s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
798 if (
s->ps.pps->chroma_qp_offset_list_enabled_flag)
803 if (
s->ps.pps->deblocking_filter_control_present_flag) {
804 int deblocking_filter_override_flag = 0;
806 if (
s->ps.pps->deblocking_filter_override_enabled_flag)
807 deblocking_filter_override_flag =
get_bits1(gb);
809 if (deblocking_filter_override_flag) {
814 if (beta_offset_div2 < -6 || beta_offset_div2 > 6 ||
815 tc_offset_div2 < -6 || tc_offset_div2 > 6) {
817 "Invalid deblock filter offsets: %d, %d\n",
818 beta_offset_div2, tc_offset_div2);
835 if (
s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
843 }
else if (!
s->slice_initialized) {
849 if (
s->ps.pps->tiles_enabled_flag ||
s->ps.pps->entropy_coding_sync_enabled_flag) {
853 av_log(
s->avctx,
AV_LOG_ERROR,
"num_entry_point_offsets %d is invalid\n", num_entry_point_offsets);
861 if (offset_len < 1 || offset_len > 32) {
882 if (
s->threads_number > 1 && (
s->ps.pps->num_tile_rows > 1 ||
s->ps.pps->num_tile_columns > 1)) {
883 s->enable_parallel_tiles = 0;
884 s->threads_number = 1;
886 s->enable_parallel_tiles = 0;
888 s->enable_parallel_tiles = 0;
891 if (
s->ps.pps->slice_header_extension_present_flag) {
897 for (
i = 0;
i < length;
i++)
904 sh->
slice_qp < -
s->ps.sps->qp_bd_offset) {
906 "The slice_qp %d is outside the valid range "
909 -
s->ps.sps->qp_bd_offset);
915 if (!
s->sh.slice_ctb_addr_rs &&
s->sh.dependent_slice_segment_flag) {
926 s->HEVClc->first_qp_group = !
s->sh.dependent_slice_segment_flag;
928 if (!
s->ps.pps->cu_qp_delta_enabled_flag)
929 s->HEVClc->qp_y =
s->sh.slice_qp;
931 s->slice_initialized = 1;
932 s->HEVClc->tu.cu_qp_offset_cb = 0;
933 s->HEVClc->tu.cu_qp_offset_cr = 0;
938 #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
940 #define SET_SAO(elem, value) \
942 if (!sao_merge_up_flag && !sao_merge_left_flag) \
944 else if (sao_merge_left_flag) \
945 sao->elem = CTB(s->sao, rx-1, ry).elem; \
946 else if (sao_merge_up_flag) \
947 sao->elem = CTB(s->sao, rx, ry-1).elem; \
955 int sao_merge_left_flag = 0;
956 int sao_merge_up_flag = 0;
960 if (
s->sh.slice_sample_adaptive_offset_flag[0] ||
961 s->sh.slice_sample_adaptive_offset_flag[1]) {
966 if (ry > 0 && !sao_merge_left_flag) {
972 for (c_idx = 0; c_idx < (
s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
973 int log2_sao_offset_scale = c_idx == 0 ?
s->ps.pps->log2_sao_offset_scale_luma :
974 s->ps.pps->log2_sao_offset_scale_chroma;
976 if (!
s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
991 for (
i = 0;
i < 4;
i++)
995 for (
i = 0;
i < 4;
i++) {
1004 }
else if (c_idx != 2) {
1010 for (
i = 0;
i < 4;
i++) {
1018 sao->
offset_val[c_idx][
i + 1] *= 1 << log2_sao_offset_scale;
1030 if (log2_res_scale_abs_plus1 != 0) {
1033 (1 - 2 * res_scale_sign_flag);
1043 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1044 int log2_cb_size,
int log2_trafo_size,
1045 int blk_idx,
int cbf_luma,
int *cbf_cb,
int *cbf_cr)
1048 const int log2_trafo_size_c = log2_trafo_size -
s->ps.sps->hshift[1];
1052 int trafo_size = 1 << log2_trafo_size;
1055 s->hpc.intra_pred[log2_trafo_size - 2](
s, x0, y0, 0);
1058 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
1059 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1062 int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
1063 (
s->ps.sps->chroma_format_idc == 2 &&
1064 (cbf_cb[1] || cbf_cr[1]));
1076 "The cu_qp_delta %d is outside the valid range "
1079 -(26 +
s->ps.sps->qp_bd_offset / 2),
1080 (25 +
s->ps.sps->qp_bd_offset / 2));
1087 if (
s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
1090 if (cu_chroma_qp_offset_flag) {
1091 int cu_chroma_qp_offset_idx = 0;
1092 if (
s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
1095 "cu_chroma_qp_offset_idx not yet tested.\n");
1128 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1129 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1130 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1131 lc->
tu.
cross_pf = (
s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
1138 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1141 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 1);
1145 log2_trafo_size_c, scan_idx_c, 1);
1148 ptrdiff_t
stride =
s->frame->linesize[1];
1149 int hshift =
s->ps.sps->hshift[1];
1150 int vshift =
s->ps.sps->vshift[1];
1153 int size = 1 << log2_trafo_size_c;
1156 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1160 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1167 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1170 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (
i << log2_trafo_size_c), 2);
1174 log2_trafo_size_c, scan_idx_c, 2);
1177 ptrdiff_t
stride =
s->frame->linesize[2];
1178 int hshift =
s->ps.sps->hshift[2];
1179 int vshift =
s->ps.sps->vshift[2];
1182 int size = 1 << log2_trafo_size_c;
1185 ((x0 >> hshift) <<
s->ps.sps->pixel_shift)];
1189 s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs,
stride);
1192 }
else if (
s->ps.sps->chroma_format_idc && blk_idx == 3) {
1193 int trafo_size_h = 1 << (log2_trafo_size + 1);
1194 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1195 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1198 trafo_size_h, trafo_size_v);
1199 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 1);
1203 log2_trafo_size, scan_idx_c, 1);
1205 for (
i = 0;
i < (
s->ps.sps->chroma_format_idc == 2 ? 2 : 1);
i++) {
1208 trafo_size_h, trafo_size_v);
1209 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (
i << log2_trafo_size), 2);
1213 log2_trafo_size, scan_idx_c, 2);
1217 if (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3) {
1218 int trafo_size_h = 1 << (log2_trafo_size_c +
s->ps.sps->hshift[1]);
1219 int trafo_size_v = 1 << (log2_trafo_size_c +
s->ps.sps->vshift[1]);
1221 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 1);
1222 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0, 2);
1223 if (
s->ps.sps->chroma_format_idc == 2) {
1225 trafo_size_h, trafo_size_v);
1226 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 1);
1227 s->hpc.intra_pred[log2_trafo_size_c - 2](
s, x0, y0 + (1 << log2_trafo_size_c), 2);
1229 }
else if (blk_idx == 3) {
1230 int trafo_size_h = 1 << (log2_trafo_size + 1);
1231 int trafo_size_v = 1 << (log2_trafo_size +
s->ps.sps->vshift[1]);
1233 trafo_size_h, trafo_size_v);
1234 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 1);
1235 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase, 2);
1236 if (
s->ps.sps->chroma_format_idc == 2) {
1238 trafo_size_h, trafo_size_v);
1239 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 1);
1240 s->hpc.intra_pred[log2_trafo_size - 2](
s, xBase, yBase + (1 << (log2_trafo_size)), 2);
1250 int cb_size = 1 << log2_cb_size;
1251 int log2_min_pu_size =
s->ps.sps->log2_min_pu_size;
1253 int min_pu_width =
s->ps.sps->min_pu_width;
1254 int x_end =
FFMIN(x0 + cb_size,
s->ps.sps->width);
1255 int y_end =
FFMIN(y0 + cb_size,
s->ps.sps->height);
1258 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
1259 for (
i = (x0 >> log2_min_pu_size);
i < (x_end >> log2_min_pu_size);
i++)
1260 s->is_pcm[
i + j * min_pu_width] = 2;
1264 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
1265 int log2_cb_size,
int log2_trafo_size,
1266 int trafo_depth,
int blk_idx,
1267 const int *base_cbf_cb,
const int *base_cbf_cr)
1275 cbf_cb[0] = base_cbf_cb[0];
1276 cbf_cb[1] = base_cbf_cb[1];
1277 cbf_cr[0] = base_cbf_cr[0];
1278 cbf_cr[1] = base_cbf_cr[1];
1281 if (trafo_depth == 1) {
1283 if (
s->ps.sps->chroma_format_idc == 3) {
1297 if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
1298 log2_trafo_size >
s->ps.sps->log2_min_tb_size &&
1299 trafo_depth < lc->cu.max_trafo_depth &&
1303 int inter_split =
s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
1308 split_transform_flag = log2_trafo_size >
s->ps.sps->log2_max_trafo_size ||
1313 if (
s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 ||
s->ps.sps->chroma_format_idc == 3)) {
1314 if (trafo_depth == 0 || cbf_cb[0]) {
1316 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1321 if (trafo_depth == 0 || cbf_cr[0]) {
1323 if (
s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
1329 if (split_transform_flag) {
1330 const int trafo_size_split = 1 << (log2_trafo_size - 1);
1331 const int x1 = x0 + trafo_size_split;
1332 const int y1 = y0 + trafo_size_split;
1334 #define SUBDIVIDE(x, y, idx) \
1336 ret = hls_transform_tree(s, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
1337 log2_trafo_size - 1, trafo_depth + 1, idx, \
1350 int min_tu_size = 1 <<
s->ps.sps->log2_min_tb_size;
1351 int log2_min_tu_size =
s->ps.sps->log2_min_tb_size;
1352 int min_tu_width =
s->ps.sps->min_tb_width;
1356 cbf_cb[0] || cbf_cr[0] ||
1357 (
s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
1362 log2_cb_size, log2_trafo_size,
1363 blk_idx, cbf_luma, cbf_cb, cbf_cr);
1369 for (
i = 0;
i < (1 << log2_trafo_size);
i += min_tu_size)
1370 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1371 int x_tu = (x0 + j) >> log2_min_tu_size;
1372 int y_tu = (y0 +
i) >> log2_min_tu_size;
1373 s->cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1376 if (!
s->sh.disable_deblocking_filter_flag) {
1378 if (
s->ps.pps->transquant_bypass_enable_flag &&
1390 int cb_size = 1 << log2_cb_size;
1391 ptrdiff_t stride0 =
s->frame->linesize[0];
1392 ptrdiff_t stride1 =
s->frame->linesize[1];
1393 ptrdiff_t stride2 =
s->frame->linesize[2];
1394 uint8_t *dst0 = &
s->frame->data[0][y0 * stride0 + (x0 <<
s->ps.sps->pixel_shift)];
1395 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)];
1396 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)];
1398 int length = cb_size * cb_size *
s->ps.sps->pcm.bit_depth +
1399 (((cb_size >>
s->ps.sps->hshift[1]) * (cb_size >>
s->ps.sps->vshift[1])) +
1400 ((cb_size >>
s->ps.sps->hshift[2]) * (cb_size >>
s->ps.sps->vshift[2]))) *
1401 s->ps.sps->pcm.bit_depth_chroma;
1405 if (!
s->sh.disable_deblocking_filter_flag)
1412 s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb,
s->ps.sps->pcm.bit_depth);
1413 if (
s->ps.sps->chroma_format_idc) {
1414 s->hevcdsp.put_pcm(dst1, stride1,
1415 cb_size >>
s->ps.sps->hshift[1],
1416 cb_size >>
s->ps.sps->vshift[1],
1417 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1418 s->hevcdsp.put_pcm(dst2, stride2,
1419 cb_size >>
s->ps.sps->hshift[2],
1420 cb_size >>
s->ps.sps->vshift[2],
1421 &gb,
s->ps.sps->pcm.bit_depth_chroma);
1445 int block_w,
int block_h,
int luma_weight,
int luma_offset)
1449 ptrdiff_t srcstride =
ref->linesize[0];
1450 int pic_width =
s->ps.sps->width;
1451 int pic_height =
s->ps.sps->height;
1454 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1455 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1458 x_off +=
mv->x >> 2;
1459 y_off +=
mv->y >> 2;
1460 src += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1470 edge_emu_stride, srcstride,
1474 pic_width, pic_height);
1476 srcstride = edge_emu_stride;
1480 s->hevcdsp.put_hevc_qpel_uni[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1481 block_h, mx, my, block_w);
1483 s->hevcdsp.put_hevc_qpel_uni_w[idx][!!my][!!mx](dst, dststride,
src, srcstride,
1484 block_h,
s->sh.luma_log2_weight_denom,
1485 luma_weight, luma_offset, mx, my, block_w);
1505 AVFrame *ref0,
const Mv *mv0,
int x_off,
int y_off,
1506 int block_w,
int block_h,
AVFrame *ref1,
const Mv *mv1,
struct MvField *current_mv)
1509 ptrdiff_t src0stride = ref0->
linesize[0];
1510 ptrdiff_t src1stride = ref1->
linesize[0];
1511 int pic_width =
s->ps.sps->width;
1512 int pic_height =
s->ps.sps->height;
1513 int mx0 = mv0->
x & 3;
1514 int my0 = mv0->
y & 3;
1515 int mx1 = mv1->
x & 3;
1516 int my1 = mv1->
y & 3;
1517 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1518 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1519 int x_off0 = x_off + (mv0->
x >> 2);
1520 int y_off0 = y_off + (mv0->
y >> 2);
1521 int x_off1 = x_off + (mv1->
x >> 2);
1522 int y_off1 = y_off + (mv1->
y >> 2);
1525 uint8_t *
src0 = ref0->
data[0] + y_off0 * src0stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1526 uint8_t *
src1 = ref1->
data[0] + y_off1 * src1stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1536 edge_emu_stride, src0stride,
1540 pic_width, pic_height);
1542 src0stride = edge_emu_stride;
1553 edge_emu_stride, src1stride,
1557 pic_width, pic_height);
1559 src1stride = edge_emu_stride;
1562 s->hevcdsp.put_hevc_qpel[idx][!!my0][!!mx0](lc->
tmp,
src0, src0stride,
1563 block_h, mx0, my0, block_w);
1565 s->hevcdsp.put_hevc_qpel_bi[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1566 block_h, mx1, my1, block_w);
1568 s->hevcdsp.put_hevc_qpel_bi_w[idx][!!my1][!!mx1](dst, dststride,
src1, src1stride, lc->
tmp,
1569 block_h,
s->sh.luma_log2_weight_denom,
1570 s->sh.luma_weight_l0[current_mv->
ref_idx[0]],
1571 s->sh.luma_weight_l1[current_mv->
ref_idx[1]],
1572 s->sh.luma_offset_l0[current_mv->
ref_idx[0]],
1573 s->sh.luma_offset_l1[current_mv->
ref_idx[1]],
1596 ptrdiff_t dststride,
uint8_t *
src0, ptrdiff_t srcstride,
int reflist,
1597 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int chroma_weight,
int chroma_offset)
1600 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1601 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1602 const Mv *
mv = ¤t_mv->
mv[reflist];
1603 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1604 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1606 int hshift =
s->ps.sps->hshift[1];
1607 int vshift =
s->ps.sps->vshift[1];
1608 intptr_t mx = av_mod_uintp2(
mv->x, 2 + hshift);
1609 intptr_t my = av_mod_uintp2(
mv->y, 2 + vshift);
1610 intptr_t _mx = mx << (1 - hshift);
1611 intptr_t _my = my << (1 - vshift);
1613 x_off +=
mv->x >> (2 + hshift);
1614 y_off +=
mv->y >> (2 + vshift);
1615 src0 += y_off * srcstride + (x_off * (1 <<
s->ps.sps->pixel_shift));
1623 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1625 edge_emu_stride, srcstride,
1629 pic_width, pic_height);
1632 srcstride = edge_emu_stride;
1635 s->hevcdsp.put_hevc_epel_uni[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1636 block_h, _mx, _my, block_w);
1638 s->hevcdsp.put_hevc_epel_uni_w[idx][!!my][!!mx](dst0, dststride,
src0, srcstride,
1639 block_h,
s->sh.chroma_log2_weight_denom,
1640 chroma_weight, chroma_offset, _mx, _my, block_w);
1661 int x_off,
int y_off,
int block_w,
int block_h,
struct MvField *current_mv,
int cidx)
1666 ptrdiff_t src1stride = ref0->
linesize[cidx+1];
1667 ptrdiff_t src2stride = ref1->
linesize[cidx+1];
1668 int weight_flag = (
s->sh.slice_type ==
HEVC_SLICE_P &&
s->ps.pps->weighted_pred_flag) ||
1669 (
s->sh.slice_type ==
HEVC_SLICE_B &&
s->ps.pps->weighted_bipred_flag);
1670 int pic_width =
s->ps.sps->width >>
s->ps.sps->hshift[1];
1671 int pic_height =
s->ps.sps->height >>
s->ps.sps->vshift[1];
1672 Mv *mv0 = ¤t_mv->
mv[0];
1673 Mv *mv1 = ¤t_mv->
mv[1];
1674 int hshift =
s->ps.sps->hshift[1];
1675 int vshift =
s->ps.sps->vshift[1];
1677 intptr_t mx0 = av_mod_uintp2(mv0->
x, 2 + hshift);
1678 intptr_t my0 = av_mod_uintp2(mv0->
y, 2 + vshift);
1679 intptr_t mx1 = av_mod_uintp2(mv1->
x, 2 + hshift);
1680 intptr_t my1 = av_mod_uintp2(mv1->
y, 2 + vshift);
1681 intptr_t _mx0 = mx0 << (1 - hshift);
1682 intptr_t _my0 = my0 << (1 - vshift);
1683 intptr_t _mx1 = mx1 << (1 - hshift);
1684 intptr_t _my1 = my1 << (1 - vshift);
1686 int x_off0 = x_off + (mv0->
x >> (2 + hshift));
1687 int y_off0 = y_off + (mv0->
y >> (2 + vshift));
1688 int x_off1 = x_off + (mv1->
x >> (2 + hshift));
1689 int y_off1 = y_off + (mv1->
y >> (2 + vshift));
1691 src1 += y_off0 * src1stride + (
int)((
unsigned)x_off0 <<
s->ps.sps->pixel_shift);
1692 src2 += y_off1 * src2stride + (
int)((
unsigned)x_off1 <<
s->ps.sps->pixel_shift);
1700 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1703 edge_emu_stride, src1stride,
1707 pic_width, pic_height);
1710 src1stride = edge_emu_stride;
1719 (edge_emu_stride + (1 <<
s->ps.sps->pixel_shift));
1722 edge_emu_stride, src2stride,
1726 pic_width, pic_height);
1729 src2stride = edge_emu_stride;
1732 s->hevcdsp.put_hevc_epel[idx][!!my0][!!mx0](lc->
tmp,
src1, src1stride,
1733 block_h, _mx0, _my0, block_w);
1735 s->hevcdsp.put_hevc_epel_bi[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1736 src2, src2stride, lc->
tmp,
1737 block_h, _mx1, _my1, block_w);
1739 s->hevcdsp.put_hevc_epel_bi_w[idx][!!my1][!!mx1](dst0,
s->frame->linesize[cidx+1],
1740 src2, src2stride, lc->
tmp,
1742 s->sh.chroma_log2_weight_denom,
1743 s->sh.chroma_weight_l0[current_mv->
ref_idx[0]][cidx],
1744 s->sh.chroma_weight_l1[current_mv->
ref_idx[1]][cidx],
1745 s->sh.chroma_offset_l0[current_mv->
ref_idx[0]][cidx],
1746 s->sh.chroma_offset_l1[current_mv->
ref_idx[1]][cidx],
1747 _mx1, _my1, block_w);
1761 int nPbH,
int log2_cb_size,
int part_idx,
1773 if (inter_pred_idc !=
PRED_L1) {
1774 if (
s->sh.nb_refs[
L0])
1781 part_idx, merge_idx,
mv, mvp_flag, 0);
1786 if (inter_pred_idc !=
PRED_L0) {
1787 if (
s->sh.nb_refs[
L1])
1790 if (
s->sh.mvd_l1_zero_flag == 1 && inter_pred_idc ==
PRED_BI) {
1799 part_idx, merge_idx,
mv, mvp_flag, 1);
1807 int log2_cb_size,
int partIdx,
int idx)
1809 #define POS(c_idx, x, y) \
1810 &s->frame->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1811 (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
1814 struct MvField current_mv = {{{ 0 }}};
1816 int min_pu_width =
s->ps.sps->min_pu_width;
1818 MvField *tab_mvf =
s->ref->tab_mvf;
1824 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
1825 int min_cb_width =
s->ps.sps->min_cb_width;
1826 int x_cb = x0 >> log2_min_cb_size;
1827 int y_cb = y0 >> log2_min_cb_size;
1831 int skip_flag =
SAMPLE_CTB(
s->skip_flag, x_cb, y_cb);
1837 if (
s->sh.max_num_merge_cand > 1)
1843 partIdx, merge_idx, ¤t_mv);
1846 partIdx, merge_idx, ¤t_mv);
1849 x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1850 y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1852 for (j = 0; j < nPbH >>
s->ps.sps->log2_min_pu_size; j++)
1853 for (
i = 0; i < nPbW >>
s->ps.sps->log2_min_pu_size;
i++)
1854 tab_mvf[(y_pu + j) * min_pu_width + x_pu +
i] = current_mv;
1857 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
1863 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
1870 int x0_c = x0 >>
s->ps.sps->hshift[1];
1871 int y0_c = y0 >>
s->ps.sps->vshift[1];
1872 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1873 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1876 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1877 s->sh.luma_weight_l0[current_mv.
ref_idx[0]],
1878 s->sh.luma_offset_l0[current_mv.
ref_idx[0]]);
1880 if (
s->ps.sps->chroma_format_idc) {
1882 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1883 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][0],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][0]);
1885 0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1886 s->sh.chroma_weight_l0[current_mv.
ref_idx[0]][1],
s->sh.chroma_offset_l0[current_mv.
ref_idx[0]][1]);
1889 int x0_c = x0 >>
s->ps.sps->hshift[1];
1890 int y0_c = y0 >>
s->ps.sps->vshift[1];
1891 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1892 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1895 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH,
1896 s->sh.luma_weight_l1[current_mv.
ref_idx[1]],
1897 s->sh.luma_offset_l1[current_mv.
ref_idx[1]]);
1899 if (
s->ps.sps->chroma_format_idc) {
1900 chroma_mc_uni(
s, dst1,
s->frame->linesize[1], ref1->frame->data[1], ref1->frame->linesize[1],
1901 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1902 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][0],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][0]);
1904 chroma_mc_uni(
s, dst2,
s->frame->linesize[2], ref1->frame->data[2], ref1->frame->linesize[2],
1905 1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
1906 s->sh.chroma_weight_l1[current_mv.
ref_idx[1]][1],
s->sh.chroma_offset_l1[current_mv.
ref_idx[1]][1]);
1909 int x0_c = x0 >>
s->ps.sps->hshift[1];
1910 int y0_c = y0 >>
s->ps.sps->vshift[1];
1911 int nPbW_c = nPbW >>
s->ps.sps->hshift[1];
1912 int nPbH_c = nPbH >>
s->ps.sps->vshift[1];
1915 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH,
1916 ref1->frame, ¤t_mv.
mv[1], ¤t_mv);
1918 if (
s->ps.sps->chroma_format_idc) {
1920 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
1923 x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
1932 int prev_intra_luma_pred_flag)
1935 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
1936 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
1937 int min_pu_width =
s->ps.sps->min_pu_width;
1938 int size_in_pus = pu_size >>
s->ps.sps->log2_min_pu_size;
1939 int x0b = av_mod_uintp2(x0,
s->ps.sps->log2_ctb_size);
1940 int y0b = av_mod_uintp2(y0,
s->ps.sps->log2_ctb_size);
1943 s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] :
INTRA_DC;
1945 s->tab_ipm[y_pu * min_pu_width + x_pu - 1] :
INTRA_DC;
1947 int y_ctb = (y0 >> (
s->ps.sps->log2_ctb_size)) << (
s->ps.sps->log2_ctb_size);
1949 MvField *tab_mvf =
s->ref->tab_mvf;
1950 int intra_pred_mode;
1955 if ((y0 - 1) < y_ctb)
1958 if (cand_left == cand_up) {
1959 if (cand_left < 2) {
1964 candidate[0] = cand_left;
1965 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
1966 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
1969 candidate[0] = cand_left;
1970 candidate[1] = cand_up;
1980 if (prev_intra_luma_pred_flag) {
1981 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
1983 if (candidate[0] > candidate[1])
1985 if (candidate[0] > candidate[2])
1987 if (candidate[1] > candidate[2])
1991 for (
i = 0;
i < 3;
i++)
1992 if (intra_pred_mode >= candidate[
i])
1999 for (
i = 0;
i < size_in_pus;
i++) {
2000 memset(&
s->tab_ipm[(y_pu +
i) * min_pu_width + x_pu],
2001 intra_pred_mode, size_in_pus);
2003 for (j = 0; j < size_in_pus; j++) {
2008 return intra_pred_mode;
2012 int log2_cb_size,
int ct_depth)
2014 int length = (1 << log2_cb_size) >>
s->ps.sps->log2_min_cb_size;
2015 int x_cb = x0 >>
s->ps.sps->log2_min_cb_size;
2016 int y_cb = y0 >>
s->ps.sps->log2_min_cb_size;
2019 for (y = 0; y < length; y++)
2020 memset(&
s->tab_ct_depth[(y_cb + y) *
s->ps.sps->min_cb_width + x_cb],
2025 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
2026 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
2032 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
2033 uint8_t prev_intra_luma_pred_flag[4];
2035 int pb_size = (1 << log2_cb_size) >>
split;
2036 int side =
split + 1;
2040 for (
i = 0;
i < side;
i++)
2041 for (j = 0; j < side; j++)
2044 for (
i = 0;
i < side;
i++) {
2045 for (j = 0; j < side; j++) {
2046 if (prev_intra_luma_pred_flag[2 *
i + j])
2053 prev_intra_luma_pred_flag[2 *
i + j]);
2057 if (
s->ps.sps->chroma_format_idc == 3) {
2058 for (
i = 0;
i < side;
i++) {
2059 for (j = 0; j < side; j++) {
2061 if (chroma_mode != 4) {
2071 }
else if (
s->ps.sps->chroma_format_idc == 2) {
2074 if (chroma_mode != 4) {
2078 mode_idx = intra_chroma_table[chroma_mode];
2083 }
else if (
s->ps.sps->chroma_format_idc != 0) {
2085 if (chroma_mode != 4) {
2101 int pb_size = 1 << log2_cb_size;
2102 int size_in_pus = pb_size >>
s->ps.sps->log2_min_pu_size;
2103 int min_pu_width =
s->ps.sps->min_pu_width;
2104 MvField *tab_mvf =
s->ref->tab_mvf;
2105 int x_pu = x0 >>
s->ps.sps->log2_min_pu_size;
2106 int y_pu = y0 >>
s->ps.sps->log2_min_pu_size;
2109 if (size_in_pus == 0)
2111 for (j = 0; j < size_in_pus; j++)
2112 memset(&
s->tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
2114 for (j = 0; j < size_in_pus; j++)
2115 for (k = 0; k < size_in_pus; k++)
2121 int cb_size = 1 << log2_cb_size;
2123 int log2_min_cb_size =
s->ps.sps->log2_min_cb_size;
2124 int length = cb_size >> log2_min_cb_size;
2125 int min_cb_width =
s->ps.sps->min_cb_width;
2126 int x_cb = x0 >> log2_min_cb_size;
2127 int y_cb = y0 >> log2_min_cb_size;
2128 int idx = log2_cb_size - 2;
2129 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2139 for (x = 0; x < 4; x++)
2141 if (
s->ps.pps->transquant_bypass_enable_flag) {
2151 x = y_cb * min_cb_width + x_cb;
2152 for (y = 0; y < length; y++) {
2153 memset(&
s->skip_flag[x], skip_flag, length);
2158 x = y_cb * min_cb_width + x_cb;
2159 for (y = 0; y < length; y++) {
2160 memset(&
s->skip_flag[x], 0, length);
2169 if (!
s->sh.disable_deblocking_filter_flag)
2177 log2_cb_size ==
s->ps.sps->log2_min_cb_size) {
2185 log2_cb_size >=
s->ps.sps->pcm.log2_min_pcm_cb_size &&
2186 log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) {
2192 if (
s->ps.sps->pcm.loop_filter_disable_flag)
2224 hls_prediction_unit(
s, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
2228 hls_prediction_unit(
s, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
2232 hls_prediction_unit(
s, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
2233 hls_prediction_unit(
s, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
2234 hls_prediction_unit(
s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
2240 int rqt_root_cbf = 1;
2247 const static int cbf[2] = { 0 };
2250 s->ps.sps->max_transform_hierarchy_depth_inter;
2253 log2_cb_size, 0, 0, cbf, cbf);
2257 if (!
s->sh.disable_deblocking_filter_flag)
2266 x = y_cb * min_cb_width + x_cb;
2267 for (y = 0; y < length; y++) {
2268 memset(&
s->qp_y_tab[x], lc->
qp_y, length);
2272 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2273 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
2283 int log2_cb_size,
int cb_depth)
2286 const int cb_size = 1 << log2_cb_size;
2291 if (x0 + cb_size <= s->ps.sps->width &&
2292 y0 + cb_size <= s->ps.sps->height &&
2293 log2_cb_size >
s->ps.sps->log2_min_cb_size) {
2296 split_cu = (log2_cb_size >
s->ps.sps->log2_min_cb_size);
2298 if (
s->ps.pps->cu_qp_delta_enabled_flag &&
2299 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth) {
2304 if (
s->sh.cu_chroma_qp_offset_enabled_flag &&
2305 log2_cb_size >=
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_chroma_qp_offset_depth) {
2310 int qp_block_mask = (1<<(
s->ps.sps->log2_ctb_size -
s->ps.pps->diff_cu_qp_delta_depth)) - 1;
2311 const int cb_size_split = cb_size >> 1;
2312 const int x1 = x0 + cb_size_split;
2313 const int y1 = y0 + cb_size_split;
2321 if (more_data && x1 < s->ps.sps->width) {
2326 if (more_data && y1 < s->ps.sps->height) {
2331 if (more_data && x1 < s->ps.sps->width &&
2332 y1 < s->ps.sps->height) {
2338 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
2339 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
2343 return ((x1 + cb_size_split) <
s->ps.sps->width ||
2344 (y1 + cb_size_split) <
s->ps.sps->height);
2351 if ((!((x0 + cb_size) %
2352 (1 << (
s->ps.sps->log2_ctb_size))) ||
2353 (x0 + cb_size >=
s->ps.sps->width)) &&
2355 (1 << (
s->ps.sps->log2_ctb_size))) ||
2356 (y0 + cb_size >=
s->ps.sps->height))) {
2358 return !end_of_slice_flag;
2371 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2372 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2373 int ctb_addr_in_slice = ctb_addr_rs -
s->sh.slice_addr;
2375 s->tab_slice_address[ctb_addr_rs] =
s->sh.slice_addr;
2377 if (
s->ps.pps->entropy_coding_sync_enabled_flag) {
2378 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
2381 }
else if (
s->ps.pps->tiles_enabled_flag) {
2382 if (ctb_addr_ts &&
s->ps.pps->tile_id[ctb_addr_ts] !=
s->ps.pps->tile_id[ctb_addr_ts - 1]) {
2383 int idxX =
s->ps.pps->col_idxX[x_ctb >>
s->ps.sps->log2_ctb_size];
2384 lc->
end_of_tiles_x = x_ctb + (
s->ps.pps->column_width[idxX] <<
s->ps.sps->log2_ctb_size);
2394 if (
s->ps.pps->tiles_enabled_flag) {
2395 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]])
2397 if (x_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs - 1])
2399 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]])
2401 if (y_ctb > 0 &&
s->tab_slice_address[ctb_addr_rs] !=
s->tab_slice_address[ctb_addr_rs -
s->ps.sps->ctb_width])
2404 if (ctb_addr_in_slice <= 0)
2406 if (ctb_addr_in_slice < s->ps.sps->ctb_width)
2412 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]]));
2413 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]]));
2419 int ctb_size = 1 <<
s->ps.sps->log2_ctb_size;
2423 int ctb_addr_ts =
s->ps.pps->ctb_addr_rs_to_ts[
s->sh.slice_ctb_addr_rs];
2426 if (!ctb_addr_ts &&
s->sh.dependent_slice_segment_flag) {
2431 if (
s->sh.dependent_slice_segment_flag) {
2432 int prev_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
2433 if (
s->tab_slice_address[prev_rs] !=
s->sh.slice_addr) {
2439 while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2440 int ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2442 x_ctb = (ctb_addr_rs % ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2443 y_ctb = (ctb_addr_rs / ((
s->ps.sps->width + ctb_size - 1) >>
s->ps.sps->log2_ctb_size)) <<
s->ps.sps->log2_ctb_size;
2448 s->tab_slice_address[ctb_addr_rs] = -1;
2452 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2454 s->deblock[ctb_addr_rs].beta_offset =
s->sh.beta_offset;
2455 s->deblock[ctb_addr_rs].tc_offset =
s->sh.tc_offset;
2456 s->filter_slice_edges[ctb_addr_rs] =
s->sh.slice_loop_filter_across_slices_enabled_flag;
2459 if (more_data < 0) {
2460 s->tab_slice_address[ctb_addr_rs] = -1;
2470 if (x_ctb + ctb_size >=
s->ps.sps->width &&
2471 y_ctb + ctb_size >=
s->ps.sps->height)
2492 int ctb_size = 1<<
s1->ps.sps->log2_ctb_size;
2494 int *ctb_row_p = input_ctb_row;
2495 int ctb_row = ctb_row_p[job];
2496 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);
2497 int ctb_addr_ts =
s1->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
2498 int thread = ctb_row %
s1->threads_number;
2501 s =
s1->sList[self_id];
2511 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
2512 int x_ctb = (ctb_addr_rs %
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2513 int y_ctb = (ctb_addr_rs /
s->ps.sps->ctb_width) <<
s->ps.sps->log2_ctb_size;
2527 hls_sao_param(
s, x_ctb >>
s->ps.sps->log2_ctb_size, y_ctb >>
s->ps.sps->log2_ctb_size);
2530 if (more_data < 0) {
2541 if (!more_data && (x_ctb+ctb_size) <
s->ps.sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2547 if ((x_ctb+ctb_size) >=
s->ps.sps->width && (y_ctb+ctb_size) >=
s->ps.sps->height ) {
2552 ctb_addr_rs =
s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2555 if(x_ctb >=
s->ps.sps->width) {
2563 s->tab_slice_address[ctb_addr_rs] = -1;
2572 int length = nal->
size;
2577 int64_t startheader, cmpt = 0;
2586 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) {
2588 s->sh.slice_ctb_addr_rs,
s->sh.num_entry_point_offsets,
2589 s->ps.sps->ctb_width,
s->ps.sps->ctb_height
2598 for (
i = 1;
i <
s->threads_number;
i++) {
2602 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2608 for (j = 0, cmpt = 0, startheader =
offset +
s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
2615 for (
i = 1;
i <
s->sh.num_entry_point_offsets;
i++) {
2616 offset += (
s->sh.entry_point_offset[
i - 1] - cmpt);
2617 for (j = 0, cmpt = 0, startheader =
offset
2618 +
s->sh.entry_point_offset[
i]; j < nal->skipped_bytes; j++) {
2624 s->sh.size[
i - 1] =
s->sh.entry_point_offset[
i] - cmpt;
2628 if (
s->sh.num_entry_point_offsets != 0) {
2629 offset +=
s->sh.entry_point_offset[
s->sh.num_entry_point_offsets - 1] - cmpt;
2635 s->sh.size[
s->sh.num_entry_point_offsets - 1] = length -
offset;
2636 s->sh.offset[
s->sh.num_entry_point_offsets - 1] =
offset;
2641 for (
i = 1;
i <
s->threads_number;
i++) {
2642 s->sList[
i]->HEVClc->first_qp_group = 1;
2643 s->sList[
i]->HEVClc->qp_y =
s->sList[0]->HEVClc->qp_y;
2645 s->sList[
i]->HEVClc =
s->HEVClcList[
i];
2651 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++) {
2656 if (
s->ps.pps->entropy_coding_sync_enabled_flag)
2659 for (
i = 0;
i <=
s->sh.num_entry_point_offsets;
i++)
2671 if (
s->sei.frame_packing.present &&
2672 s->sei.frame_packing.arrangement_type >= 3 &&
2673 s->sei.frame_packing.arrangement_type <= 5 &&
2674 s->sei.frame_packing.content_interpretation_type > 0 &&
2675 s->sei.frame_packing.content_interpretation_type < 3) {
2680 switch (
s->sei.frame_packing.arrangement_type) {
2682 if (
s->sei.frame_packing.quincunx_subsampling)
2695 if (
s->sei.frame_packing.content_interpretation_type == 2)
2698 if (
s->sei.frame_packing.arrangement_type == 5) {
2699 if (
s->sei.frame_packing.current_frame_is_frame0_flag)
2706 if (
s->sei.display_orientation.present &&
2707 (
s->sei.display_orientation.anticlockwise_rotation ||
2708 s->sei.display_orientation.hflip ||
s->sei.display_orientation.vflip)) {
2709 double angle =
s->sei.display_orientation.anticlockwise_rotation * 360 / (double) (1 << 16);
2718 s->sei.display_orientation.hflip,
2719 s->sei.display_orientation.vflip);
2724 if (
s->sei.mastering_display.present > 0 &&
2726 s->sei.mastering_display.present--;
2728 if (
s->sei.mastering_display.present) {
2730 const int mapping[3] = {2, 0, 1};
2731 const int chroma_den = 50000;
2732 const int luma_den = 10000;
2739 for (
i = 0;
i < 3;
i++) {
2740 const int j = mapping[
i];
2746 metadata->
white_point[0].
num =
s->sei.mastering_display.white_point[0];
2748 metadata->
white_point[1].
num =
s->sei.mastering_display.white_point[1];
2760 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
2769 "min_luminance=%f, max_luminance=%f\n",
2774 if (
s->sei.content_light.present > 0 &&
2776 s->sei.content_light.present--;
2778 if (
s->sei.content_light.present) {
2783 metadata->
MaxCLL =
s->sei.content_light.max_content_light_level;
2784 metadata->
MaxFALL =
s->sei.content_light.max_pic_average_light_level;
2791 if (
s->sei.a53_caption.buf_ref) {
2808 int pic_size_in_ctb = ((
s->ps.sps->width >>
s->ps.sps->log2_min_cb_size) + 1) *
2809 ((
s->ps.sps->height >>
s->ps.sps->log2_min_cb_size) + 1);
2812 memset(
s->horizontal_bs, 0,
s->bs_width *
s->bs_height);
2813 memset(
s->vertical_bs, 0,
s->bs_width *
s->bs_height);
2814 memset(
s->cbf_luma, 0,
s->ps.sps->min_tb_width *
s->ps.sps->min_tb_height);
2815 memset(
s->is_pcm, 0, (
s->ps.sps->min_pu_width + 1) * (
s->ps.sps->min_pu_height + 1));
2816 memset(
s->tab_slice_address, -1, pic_size_in_ctb *
sizeof(*
s->tab_slice_address));
2819 s->first_nal_type =
s->nal_unit_type;
2823 if (
s->ps.pps->tiles_enabled_flag)
2824 lc->
end_of_tiles_x =
s->ps.pps->column_width[0] <<
s->ps.sps->log2_ctb_size;
2842 s->frame->pict_type = 3 -
s->sh.slice_type;
2852 if (!
s->avctx->hwaccel)
2868 int ctb_addr_ts,
ret;
2871 s->nal_unit_type = nal->
type;
2874 switch (
s->nal_unit_type) {
2876 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2877 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2889 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2890 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2898 s->apply_defdispwin);
2903 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2904 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2917 if (
s->avctx->hwaccel &&
s->avctx->hwaccel->decode_params) {
2918 ret =
s->avctx->hwaccel->decode_params(
s->avctx,
2961 if (
s->sh.first_slice_in_pic_flag) {
2962 if (
s->max_ra == INT_MAX) {
2967 s->max_ra = INT_MIN;
2972 s->poc <=
s->max_ra) {
2977 s->max_ra = INT_MIN;
2984 }
else if (!
s->ref) {
2989 if (
s->nal_unit_type !=
s->first_nal_type) {
2991 "Non-matching NAL types of the VCL NALUs: %d %d\n",
2992 s->first_nal_type,
s->nal_unit_type);
2996 if (!
s->sh.dependent_slice_segment_flag &&
3001 "Error constructing the reference lists for the current slice.\n");
3006 if (
s->sh.first_slice_in_pic_flag &&
s->avctx->hwaccel) {
3007 ret =
s->avctx->hwaccel->start_frame(
s->avctx,
NULL, 0);
3012 if (
s->avctx->hwaccel) {
3017 if (
s->threads_number > 1 &&
s->sh.num_entry_point_offsets > 0)
3021 if (ctb_addr_ts >= (
s->ps.sps->ctb_width *
s->ps.sps->ctb_height)) {
3025 if (ctb_addr_ts < 0) {
3033 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3034 s->max_ra = INT_MAX;
3041 "Skipping NAL unit %d\n",
s->nal_unit_type);
3054 int eos_at_start = 1;
3057 s->last_eos =
s->eos;
3064 s->nal_length_size,
s->avctx->codec_id, 1, 0);
3067 "Error splitting the input into NAL units.\n");
3071 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3085 for (
i = 0;
i <
s->pkt.nb_nals;
i++) {
3094 if (
ret >= 0 &&
s->overlap > 2)
3098 "Error parsing NAL unit #%d.\n",
i);
3113 for (
i = 0;
i < 16;
i++)
3126 pixel_shift =
desc->comp[0].depth > 8;
3134 if (pixel_shift && !
s->checksum_buf) {
3137 frame->linesize[2]));
3138 if (!
s->checksum_buf)
3144 int width =
s->avctx->coded_width;
3145 int height =
s->avctx->coded_height;
3151 for (j = 0; j <
h; j++) {
3155 s->bdsp.bswap16_buf((uint16_t *)
s->checksum_buf,
3156 (
const uint16_t *)
src,
w);
3157 src =
s->checksum_buf;
3164 if (!memcmp(
md5,
s->sei.picture_hash.md5[
i], 16)) {
3188 &
s->nal_length_size,
s->avctx->err_recognition,
3189 s->apply_defdispwin,
s->avctx);
3195 if (
first &&
s->ps.sps_list[
i]) {
3209 int new_extradata_size;
3223 &new_extradata_size);
3224 if (new_extradata && new_extradata_size > 0) {
3238 "hardware accelerator failed to decode picture\n");
3245 s->sei.picture_hash.is_md5) {
3253 s->sei.picture_hash.is_md5 = 0;
3255 if (
s->is_decoded) {
3260 if (
s->output_frame->buf[0]) {
3295 if (
src->hwaccel_picture_private) {
3319 for (
i = 0;
i < 3;
i++) {
3336 for (
i = 1;
i <
s->threads_number;
i++) {
3343 if (
s->HEVClc ==
s->HEVClcList[0])
3364 s->HEVClcList[0] =
s->HEVClc;
3368 if (!
s->cabac_state)
3372 if (!
s->output_frame)
3377 if (!
s->DPB[
i].frame)
3379 s->DPB[
i].tf.f =
s->DPB[
i].frame;
3382 s->max_ra = INT_MAX;
3390 s->context_initialized = 1;
3410 if (!
s->context_initialized) {
3418 if (
s0->DPB[
i].frame->buf[0]) {
3425 if (
s->ps.sps !=
s0->ps.sps)
3429 if (
s0->ps.vps_list[
i]) {
3431 if (!
s->ps.vps_list[
i])
3438 if (
s0->ps.sps_list[
i]) {
3440 if (!
s->ps.sps_list[
i])
3447 if (
s0->ps.pps_list[
i]) {
3449 if (!
s->ps.pps_list[
i])
3454 if (
s->ps.sps !=
s0->ps.sps)
3458 s->seq_decode =
s0->seq_decode;
3459 s->seq_output =
s0->seq_output;
3460 s->pocTid0 =
s0->pocTid0;
3461 s->max_ra =
s0->max_ra;
3463 s->no_rasl_output_flag =
s0->no_rasl_output_flag;
3465 s->is_nalff =
s0->is_nalff;
3466 s->nal_length_size =
s0->nal_length_size;
3468 s->threads_number =
s0->threads_number;
3469 s->threads_type =
s0->threads_type;
3472 s->seq_decode = (
s->seq_decode + 1) & 0xff;
3473 s->max_ra = INT_MAX;
3477 if (
s0->sei.a53_caption.buf_ref) {
3479 if (!
s->sei.a53_caption.buf_ref)
3483 s->sei.frame_packing =
s0->sei.frame_packing;
3484 s->sei.display_orientation =
s0->sei.display_orientation;
3485 s->sei.mastering_display =
s0->sei.mastering_display;
3486 s->sei.content_light =
s0->sei.content_light;
3487 s->sei.alternative_transfer =
s0->sei.alternative_transfer;
3502 s->enable_parallel_tiles = 0;
3503 s->sei.picture_timing.picture_struct = 0;
3511 s->threads_number = 1;
3536 s->max_ra = INT_MAX;
3540 #define OFFSET(x) offsetof(HEVCContext, x)
3541 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
3544 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
3546 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
3576 #if CONFIG_HEVC_DXVA2_HWACCEL
3579 #if CONFIG_HEVC_D3D11VA_HWACCEL
3582 #if CONFIG_HEVC_D3D11VA2_HWACCEL
3585 #if CONFIG_HEVC_NVDEC_HWACCEL
3588 #if CONFIG_HEVC_VAAPI_HWACCEL
3591 #if CONFIG_HEVC_VDPAU_HWACCEL
3594 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL