89 int pic_size = width *
height;
90 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
91 ((height >> log2_min_cb_size) + 1);
98 s->
sao = av_mallocz_array(ctb_count,
sizeof(*s->
sao));
146 uint8_t luma_weight_l0_flag[16];
147 uint8_t chroma_weight_l0_flag[16];
148 uint8_t luma_weight_l1_flag[16];
149 uint8_t chroma_weight_l1_flag[16];
159 if (!luma_weight_l0_flag[i]) {
166 chroma_weight_l0_flag[i] =
get_bits1(gb);
169 chroma_weight_l0_flag[i] = 0;
172 if (luma_weight_l0_flag[i]) {
177 if (chroma_weight_l0_flag[i]) {
178 for (j = 0; j < 2; j++) {
195 if (!luma_weight_l1_flag[i]) {
202 chroma_weight_l1_flag[i] =
get_bits1(gb);
205 chroma_weight_l1_flag[i] = 0;
208 if (luma_weight_l1_flag[i]) {
213 if (chroma_weight_l1_flag[i]) {
214 for (j = 0; j < 2; j++) {
235 int prev_delta_msb = 0;
236 unsigned int nb_sps = 0, nb_sh;
252 for (i = 0; i < rps->
nb_refs; i++) {
269 if (delta_poc_msb_present) {
272 if (i && i != nb_sps)
273 delta += prev_delta_msb;
276 prev_delta_msb =
delta;
286 unsigned int num = 0, den = 0;
340 if (num != 0 && den != 0)
397 int slice_address_length;
407 "Invalid slice segment address: %u.\n",
448 int short_term_ref_pic_set_sps_flag, poc;
454 "Ignoring POC change between slices: %d -> %d\n", s->
poc, poc);
461 short_term_ref_pic_set_sps_flag =
get_bits1(gb);
462 if (!short_term_ref_pic_set_sps_flag) {
469 int numbits, rps_idx;
477 rps_idx = numbits > 0 ?
get_bits(gb, numbits) : 0;
578 "Invalid collocated_ref_idx: %d.\n",
593 "Invalid number of merging MVP candidates: %d.\n",
610 int deblocking_filter_override_flag = 0;
613 deblocking_filter_override_flag =
get_bits1(gb);
615 if (deblocking_filter_override_flag) {
650 int segments = offset_len >> 4;
651 int rest = (offset_len & 15);
665 for (j = 0; j < segments; j++) {
686 for (i = 0; i <
length; i++)
695 "The slice_qp %d is outside the valid range "
719 #define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
721 #define SET_SAO(elem, value) \
723 if (!sao_merge_up_flag && !sao_merge_left_flag) \
725 else if (sao_merge_left_flag) \
726 sao->elem = CTB(s->sao, rx-1, ry).elem; \
727 else if (sao_merge_up_flag) \
728 sao->elem = CTB(s->sao, rx, ry-1).elem; \
736 int sao_merge_left_flag = 0;
737 int sao_merge_up_flag = 0;
748 if (ry > 0 && !sao_merge_left_flag) {
754 for (c_idx = 0; c_idx < 3; c_idx++) {
770 for (i = 0; i < 4; i++)
774 for (i = 0; i < 4; i++) {
783 }
else if (c_idx != 2) {
789 for (i = 0; i < 4; i++) {
805 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
806 int log2_cb_size,
int log2_trafo_size,
807 int trafo_depth,
int blk_idx)
812 int trafo_size = 1 << log2_trafo_size;
816 if (log2_trafo_size > 2) {
817 trafo_size = trafo_size << (s->
sps->
hshift[1] - 1);
821 }
else if (blk_idx == 3) {
822 trafo_size = trafo_size << s->
sps->
hshift[1];
824 trafo_size, trafo_size);
846 "The cu_qp_delta %d is outside the valid range "
877 if (log2_trafo_size > 2) {
882 }
else if (blk_idx == 3) {
894 int cb_size = 1 << log2_cb_size;
902 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
903 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
904 s->
is_pcm[i + j * min_pu_width] = 2;
908 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
909 int log2_cb_size,
int log2_trafo_size,
910 int trafo_depth,
int blk_idx)
916 if (trafo_depth > 0 && log2_trafo_size == 2) {
927 if (trafo_depth == 1)
940 if (log2_trafo_size <= s->sps->log2_max_trafo_size &&
942 trafo_depth < lc->cu.max_trafo_depth &&
951 if (log2_trafo_size > 2) {
952 if (trafo_depth == 0 ||
958 if (trafo_depth == 0 ||
965 if (split_transform_flag) {
966 int x1 = x0 + ((1 << log2_trafo_size) >> 1);
967 int y1 = y0 + ((1 << log2_trafo_size) >> 1);
970 log2_cb_size, log2_trafo_size - 1,
975 log2_cb_size, log2_trafo_size - 1,
980 log2_cb_size, log2_trafo_size - 1,
985 log2_cb_size, log2_trafo_size - 1,
1001 log2_cb_size, log2_trafo_size, trafo_depth,
1008 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
1009 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
1010 int x_tu = (x0 + j) >> log2_min_tu_size;
1011 int y_tu = (y0 + i) >> log2_min_tu_size;
1012 s->
cbf_luma[y_tu * min_tu_width + x_tu] = 1;
1032 int cb_size = 1 << log2_cb_size;
1073 int block_w,
int block_h)
1077 ptrdiff_t srcstride = ref->
linesize[0];
1086 x_off += mv->
x >> 2;
1087 y_off += mv->
y >> 2;
1090 if (x_off < extra_left || y_off < extra_top ||
1095 int buf_offset = extra_top *
1099 edge_emu_stride, srcstride,
1102 x_off - extra_left, y_off - extra_top,
1103 pic_width, pic_height);
1105 srcstride = edge_emu_stride;
1127 int x_off,
int y_off,
int block_w,
int block_h)
1132 ptrdiff_t src1stride = ref->
linesize[1];
1133 ptrdiff_t src2stride = ref->
linesize[2];
1134 int pic_width = s->
sps->
width >> 1;
1140 x_off += mv->
x >> 3;
1141 y_off += mv->
y >> 3;
1157 edge_emu_stride, src1stride,
1161 pic_width, pic_height);
1164 src1stride = edge_emu_stride;
1166 block_w, block_h, mx, my, lc->
mc_buffer);
1169 edge_emu_stride, src2stride,
1173 pic_width, pic_height);
1175 src2stride = edge_emu_stride;
1178 block_w, block_h, mx, my,
1182 block_w, block_h, mx, my,
1185 block_w, block_h, mx, my,
1193 int y = (mv->
y >> 2) + y0 + height + 9;
1201 int log2_cb_size,
int partIdx)
1203 #define POS(c_idx, x, y) \
1204 &s->frame->data[c_idx][((y) >> s->sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1205 (((x) >> s->sps->hshift[c_idx]) << s->sps->pixel_shift)]
1208 struct MvField current_mv = {{{ 0 }}};
1223 int x_cb = x0 >> log2_min_cb_size;
1224 int y_cb = y0 >> log2_min_cb_size;
1239 log2_cb_size, partIdx,
1240 merge_idx, ¤t_mv);
1246 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1256 partIdx, merge_idx, ¤t_mv);
1262 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1269 if (inter_pred_idc !=
PRED_L1) {
1272 current_mv.
ref_idx[0] = ref_idx[0];
1278 partIdx, merge_idx, ¤t_mv,
1284 if (inter_pred_idc !=
PRED_L0) {
1287 current_mv.
ref_idx[1] = ref_idx[1];
1300 partIdx, merge_idx, ¤t_mv,
1311 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1316 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
1322 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
1333 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH);
1341 tmpstride, nPbW, nPbH);
1346 ¤t_mv.
mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1354 nPbW / 2, nPbH / 2);
1359 nPbW / 2, nPbH / 2);
1372 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH);
1386 ¤t_mv.
mv[1], x0/2, y0/2, nPbW/2, nPbH/2);
1393 dst1, s->
frame->
linesize[1], tmp, tmpstride, nPbW/2, nPbH/2);
1397 dst2, s->
frame->
linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2);
1414 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH);
1416 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH);
1426 tmp, tmp2, tmpstride, nPbW, nPbH);
1429 tmp, tmp2, tmpstride, nPbW, nPbH);
1433 ¤t_mv.
mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1435 ¤t_mv.
mv[1], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1445 tmpstride, nPbW / 2, nPbH / 2);
1452 tmpstride, nPbW / 2, nPbH / 2);
1464 int prev_intra_luma_pred_flag)
1482 int intra_pred_mode;
1487 if ((y0 - 1) < y_ctb)
1490 if (cand_left == cand_up) {
1491 if (cand_left < 2) {
1496 candidate[0] = cand_left;
1497 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
1498 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
1501 candidate[0] = cand_left;
1502 candidate[1] = cand_up;
1512 if (prev_intra_luma_pred_flag) {
1513 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
1515 if (candidate[0] > candidate[1])
1517 if (candidate[0] > candidate[2])
1519 if (candidate[1] > candidate[2])
1523 for (i = 0; i < 3; i++)
1524 if (intra_pred_mode >= candidate[i])
1531 for (i = 0; i < size_in_pus; i++) {
1532 memset(&s->
tab_ipm[(y_pu + i) * min_pu_width + x_pu],
1533 intra_pred_mode, size_in_pus);
1535 for (j = 0; j < size_in_pus; j++) {
1536 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
is_intra = 1;
1537 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
pred_flag[0] = 0;
1538 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
pred_flag[1] = 0;
1539 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
ref_idx[0] = 0;
1540 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
ref_idx[1] = 0;
1541 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[0].x = 0;
1542 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[0].
y = 0;
1543 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[1].x = 0;
1544 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[1].
y = 0;
1548 return intra_pred_mode;
1552 int log2_cb_size,
int ct_depth)
1568 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
1569 uint8_t prev_intra_luma_pred_flag[4];
1571 int pb_size = (1 << log2_cb_size) >> split;
1572 int side = split + 1;
1576 for (i = 0; i < side; i++)
1577 for (j = 0; j < side; j++)
1580 for (i = 0; i < side; i++) {
1581 for (j = 0; j < side; j++) {
1582 if (prev_intra_luma_pred_flag[2 * i + j])
1589 prev_intra_luma_pred_flag[2 * i + j]);
1594 if (chroma_mode != 4) {
1609 int pb_size = 1 << log2_cb_size;
1617 if (size_in_pus == 0)
1619 for (j = 0; j < size_in_pus; j++) {
1620 memset(&s->
tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
1621 for (k = 0; k < size_in_pus; k++)
1628 int cb_size = 1 << log2_cb_size;
1631 int length = cb_size >> log2_min_cb_size;
1633 int x_cb = x0 >> log2_min_cb_size;
1634 int y_cb = y0 >> log2_min_cb_size;
1647 for (x = 0; x < 4; x++)
1660 x = y_cb * min_cb_width + x_cb;
1661 for (y = 0; y <
length; y++) {
1662 memset(&s->
skip_flag[x], skip_flag, length);
1689 log2_cb_size <= s->sps->pcm.log2_max_pcm_cb_size) {
1737 hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3);
1753 log2_cb_size, 0, 0);
1768 x = y_cb * min_cb_width + x_cb;
1769 for (y = 0; y <
length; y++) {
1774 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
1775 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0) {
1785 int log2_cb_size,
int cb_depth)
1788 const int cb_size = 1 << log2_cb_size;
1793 if (x0 + cb_size <= s->sps->width &&
1794 y0 + cb_size <= s->sps->height &&
1809 const int cb_size_split = cb_size >> 1;
1810 const int x1 = x0 + cb_size_split;
1811 const int y1 = y0 + cb_size_split;
1819 if (more_data && x1 < s->sps->width) {
1824 if (more_data && y1 < s->sps->height) {
1829 if (more_data && x1 < s->sps->width &&
1830 y1 < s->sps->height) {
1836 if(((x0 + (1<<log2_cb_size)) & qp_block_mask) == 0 &&
1837 ((y0 + (1<<log2_cb_size)) & qp_block_mask) == 0)
1841 return ((x1 + cb_size_split) < s->
sps->
width ||
1849 if ((!((x0 + cb_size) %
1851 (x0 + cb_size >= s->
sps->
width)) &&
1856 return !end_of_slice_flag;
1871 int ctb_addr_in_slice = ctb_addr_rs - s->
sh.
slice_addr;
1873 int tile_left_boundary, tile_up_boundary;
1874 int slice_left_boundary, slice_up_boundary;
1879 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
1895 tile_left_boundary = x_ctb > 0 &&
1897 slice_left_boundary = x_ctb > 0 &&
1899 tile_up_boundary = y_ctb > 0 &&
1901 slice_up_boundary = y_ctb > 0 &&
1904 tile_left_boundary =
1905 tile_up_boundary = 0;
1906 slice_left_boundary = ctb_addr_in_slice <= 0;
1907 slice_up_boundary = ctb_addr_in_slice < s->
sps->
ctb_width;
1911 lc->
ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !tile_left_boundary);
1939 while (more_data && ctb_addr_ts < s->sps->ctb_size) {
1955 if (more_data < 0) {
1966 if (x_ctb + ctb_size >= s->
sps->
width &&
1990 int *ctb_row_p = input_ctb_row;
1991 int ctb_row = ctb_row_p[job];
2001 ret =
init_get_bits8(&lc->
gb,
s->data +
s->sh.offset[ctb_row - 1],
s->sh.size[ctb_row - 1]);
2008 while(more_data && ctb_addr_ts < s->sps->ctb_size) {
2009 int x_ctb = (ctb_addr_rs %
s->sps->ctb_width) <<
s->sps->log2_ctb_size;
2010 int y_ctb = (ctb_addr_rs /
s->sps->ctb_width) <<
s->sps->log2_ctb_size;
2022 hls_sao_param(
s, x_ctb >>
s->sps->log2_ctb_size, y_ctb >>
s->sps->log2_ctb_size);
2025 if (more_data < 0) {
2026 s->tab_slice_address[ctb_addr_rs] = -1;
2036 if (!more_data && (x_ctb+ctb_size) <
s->sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
2042 if ((x_ctb+ctb_size) >=
s->sps->width && (y_ctb+ctb_size) >=
s->sps->height ) {
2047 ctb_addr_rs =
s->pps->ctb_addr_ts_to_rs[ctb_addr_ts];
2050 if(x_ctb >=
s->sps->width) {
2065 int startheader, cmpt = 0;
2083 for (j = 0, cmpt = 0, startheader = offset + s->
sh.
entry_point_offset[0]; j < s->skipped_bytes; j++) {
2092 for (j = 0, cmpt = 0, startheader = offset
2156 "nal_unit_type: %d, nuh_layer_id: %dtemporal_id: %d\n",
2159 return nuh_layer_id == 0;
2167 for (c_idx = 0; c_idx < 3; c_idx++) {
2175 int len = min_pu_size >> hshift;
2178 for (n = 0; n < (min_pu_size >> vshift); n++) {
2179 memcpy(dst, src, len);
2278 int ctb_addr_ts,
ret;
2334 if (s->
max_ra == INT_MAX) {
2356 }
else if (!s->
ref) {
2363 "Non-matching NAL types of the VCL NALUs: %d %d\n",
2373 "Error constructing the reference lists for the current slice.\n");
2390 if (ctb_addr_ts < 0) {
2424 #define STARTCODE_TEST \
2425 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
2426 if (src[i + 2] != 3) { \
2432 #if HAVE_FAST_UNALIGNED
2433 #define FIND_FIRST_ZERO \
2434 if (i > 0 && !src[i]) \
2439 for (i = 0; i + 1 <
length; i += 9) {
2441 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
2442 0x8000800080008080ULL))
2449 for (i = 0; i + 1 <
length; i += 5) {
2451 (
AV_RN32A(src + i) - 0x01000101U)) &
2460 for (i = 0; i + 1 <
length; i += 2) {
2463 if (i > 0 && src[i - 1] == 0)
2469 if (i >= length - 1) {
2482 memcpy(dst, src, i);
2484 while (si + 2 < length) {
2486 if (src[si + 2] > 3) {
2487 dst[di++] = src[si++];
2488 dst[di++] = src[si++];
2489 }
else if (src[si] == 0 && src[si + 1] == 0) {
2490 if (src[si + 2] == 3) {
2511 dst[di++] = src[si++];
2514 dst[di++] = src[si++];
2526 int i, consumed,
ret = 0;
2534 while (length >= 4) {
2536 int extract_length = 0;
2541 extract_length = (extract_length << 8) | buf[i];
2545 if (extract_length > length) {
2552 while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
2616 for (i = 0; i < s->
nb_nals; i++) {
2624 "Error parsing NAL unit #%d.\n", i);
2639 for (i = 0; i < 16; i++)
2640 av_log(log_ctx, level,
"%02"PRIx8, md5[i]);
2669 for (i = 0; frame->
data[i]; i++) {
2677 for (j = 0; j < h; j++) {
2682 (
const uint16_t*)src, w);
2690 if (!memcmp(md5, s->
md5[i], 16)) {
2979 int i, j, num_arrays, nal_len_size;
2984 nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;
2985 num_arrays = bytestream2_get_byte(&gb);
2992 for (i = 0; i < num_arrays; i++) {
2993 int type = bytestream2_get_byte(&gb) & 0x3f;
2994 int cnt = bytestream2_get_be16(&gb);
2996 for (j = 0; j < cnt; j++) {
2998 int nalsize = bytestream2_peek_be16(&gb) + 2;
3001 "Invalid NAL unit size in extradata.\n");
3008 "Decoding nal unit %d %d from hvcC failed\n",
3070 memset(s, 0,
sizeof(*s));
3086 #define OFFSET(x) offsetof(HEVCContext, x)
3087 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
3097 {
"apply_defdispwin",
"Apply default display window from VUI",
OFFSET(apply_defdispwin),
3099 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(apply_defdispwin),
3117 .priv_class = &hevc_decoder_class,