88 int pic_size = width *
height;
89 int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *
90 ((height >> log2_min_cb_size) + 1);
94 int pic_size_in_min_pu = min_pu_width * pic_height_in_min_pu;
101 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 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;
331 "TODO: s->sps->chroma_format_idc == 0 || "
332 "s->sps->separate_colour_plane_flag\n");
351 int slice_address_length;
396 int short_term_ref_pic_set_sps_flag;
403 "Ignoring POC change between slices: %d -> %d\n", s->
poc, poc);
410 short_term_ref_pic_set_sps_flag =
get_bits1(gb);
411 if (!short_term_ref_pic_set_sps_flag) {
418 int numbits, rps_idx;
426 rps_idx = (numbits > 0) ?
get_bits(gb, numbits) : 0;
541 "Invalid number of merging MVP candidates: %d.\n",
557 int deblocking_filter_override_flag = 0;
560 deblocking_filter_override_flag =
get_bits1(gb);
562 if (deblocking_filter_override_flag) {
597 int segments = offset_len >> 4;
598 int rest = (offset_len & 15);
612 for (j = 0; j < segments; j++) {
633 for (i = 0; i <
length; i++)
642 "The slice_qp %d is outside the valid range "
662 #define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
664 #define SET_SAO(elem, value) \
666 if (!sao_merge_up_flag && !sao_merge_left_flag) \
668 else if (sao_merge_left_flag) \
669 sao->elem = CTB(s->sao, rx-1, ry).elem; \
670 else if (sao_merge_up_flag) \
671 sao->elem = CTB(s->sao, rx, ry-1).elem; \
679 int sao_merge_left_flag = 0;
680 int sao_merge_up_flag = 0;
691 if (ry > 0 && !sao_merge_left_flag) {
697 for (c_idx = 0; c_idx < 3; c_idx++) {
713 for (i = 0; i < 4; i++)
717 for (i = 0; i < 4; i++) {
725 }
else if (c_idx != 2) {
731 for (i = 0; i < 4; i++) {
748 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
749 int log2_cb_size,
int log2_trafo_size,
750 int trafo_depth,
int blk_idx)
755 int trafo_size = 1 << log2_trafo_size;
759 if (log2_trafo_size > 2) {
760 trafo_size = trafo_size << (s->
sps->
hshift[1] - 1);
764 }
else if (blk_idx == 3) {
765 trafo_size = trafo_size << (s->
sps->
hshift[1]);
807 if (log2_trafo_size > 2) {
812 }
else if (blk_idx == 3) {
823 int cb_size = 1 << log2_cb_size;
831 for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
832 for (i = (x0 >> log2_min_pu_size); i < (x_end >> log2_min_pu_size); i++)
833 s->
is_pcm[i + j * min_pu_width] = 2;
837 int xBase,
int yBase,
int cb_xBase,
int cb_yBase,
838 int log2_cb_size,
int log2_trafo_size,
839 int trafo_depth,
int blk_idx)
844 if (trafo_depth > 0 && log2_trafo_size == 2) {
855 if (trafo_depth == 1)
867 if (log2_trafo_size <= s->sps->log2_max_trafo_size &&
869 trafo_depth < lc->cu.max_trafo_depth &&
878 if (log2_trafo_size > 2) {
879 if (trafo_depth == 0 ||
891 if (split_transform_flag) {
892 int x1 = x0 + ((1 << log2_trafo_size) >> 1);
893 int y1 = y0 + ((1 << log2_trafo_size) >> 1);
896 log2_trafo_size - 1, trafo_depth + 1, 0);
898 log2_trafo_size - 1, trafo_depth + 1, 1);
900 log2_trafo_size - 1, trafo_depth + 1, 2);
902 log2_trafo_size - 1, trafo_depth + 1, 3);
915 log2_cb_size, log2_trafo_size, trafo_depth, blk_idx);
920 for (i = 0; i < (1 << log2_trafo_size); i += min_tu_size)
921 for (j = 0; j < (1 << log2_trafo_size); j += min_tu_size) {
922 int x_tu = (x0 + j) >> log2_min_tu_size;
923 int y_tu = (y0 + i) >> log2_min_tu_size;
924 s->
cbf_luma[y_tu * min_tu_width + x_tu] = 1;
942 int cb_size = 1 << log2_cb_size;
983 int block_w,
int block_h)
987 ptrdiff_t srcstride = ref->
linesize[0];
1000 if (x_off < extra_left || y_off < extra_top ||
1007 x_off - extra_left, y_off - extra_top,
1008 pic_width, pic_height);
1030 const Mv *
mv,
int x_off,
int y_off,
int block_w,
int block_h)
1035 ptrdiff_t src1stride = ref->
linesize[1];
1036 ptrdiff_t src2stride = ref->
linesize[2];
1037 int pic_width = s->
sps->
width >> 1;
1043 x_off += mv->
x >> 3;
1044 y_off += mv->
y >> 3;
1058 pic_width, pic_height);
1062 block_w, block_h, mx, my, lc->
mc_buffer);
1068 pic_width, pic_height);
1071 block_w, block_h, mx, my,
1075 block_w, block_h, mx, my,
1078 block_w, block_h, mx, my,
1086 int y = (mv->
y >> 2) + y0 + height + 9;
1094 int log2_cb_size,
int partIdx)
1096 #define POS(c_idx, x, y) \
1097 &s->frame->data[c_idx][((y) >> s->sps->vshift[c_idx]) * s->frame->linesize[c_idx] + \
1098 (((x) >> s->sps->hshift[c_idx]) << s->sps->pixel_shift)]
1101 struct MvField current_mv = {{{ 0 }}};
1116 int x_cb = x0 >> log2_min_cb_size;
1117 int y_cb = y0 >> log2_min_cb_size;
1130 log2_cb_size, partIdx, merge_idx, ¤t_mv);
1136 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1146 partIdx, merge_idx, ¤t_mv);
1152 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1159 if (inter_pred_idc !=
PRED_L1) {
1162 current_mv.
ref_idx[0] = ref_idx[0];
1168 partIdx, merge_idx, ¤t_mv, mvp_flag[0], 0);
1173 if (inter_pred_idc !=
PRED_L0) {
1176 current_mv.
ref_idx[1] = ref_idx[1];
1189 partIdx, merge_idx, ¤t_mv, mvp_flag[1], 1);
1199 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
1204 ref0 = refPicList[0].
ref[current_mv.
ref_idx[0]];
1210 ref1 = refPicList[1].
ref[current_mv.
ref_idx[1]];
1221 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH);
1229 tmpstride, nPbW, nPbH);
1234 ¤t_mv.
mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1242 nPbW / 2, nPbH / 2);
1247 nPbW / 2, nPbH / 2);
1260 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH);
1274 ¤t_mv.
mv[1], x0/2, y0/2, nPbW/2, nPbH/2);
1281 dst1, s->
frame->
linesize[1], tmp, tmpstride, nPbW/2, nPbH/2);
1285 dst2, s->
frame->
linesize[2], tmp2, tmpstride, nPbW/2, nPbH/2);
1302 ¤t_mv.
mv[0], x0, y0, nPbW, nPbH);
1304 ¤t_mv.
mv[1], x0, y0, nPbW, nPbH);
1314 tmp, tmp2, tmpstride, nPbW, nPbH);
1317 tmp, tmp2, tmpstride, nPbW, nPbH);
1321 ¤t_mv.
mv[0], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1323 ¤t_mv.
mv[1], x0 / 2, y0 / 2, nPbW / 2, nPbH / 2);
1333 tmpstride, nPbW / 2, nPbH / 2);
1340 tmpstride, nPbW / 2, nPbH / 2);
1352 int prev_intra_luma_pred_flag)
1370 int intra_pred_mode;
1375 if ((y0 - 1) < y_ctb)
1378 if (cand_left == cand_up) {
1379 if (cand_left < 2) {
1384 candidate[0] = cand_left;
1385 candidate[1] = 2 + ((cand_left - 2 - 1 + 32) & 31);
1386 candidate[2] = 2 + ((cand_left - 2 + 1) & 31);
1389 candidate[0] = cand_left;
1390 candidate[1] = cand_up;
1400 if (prev_intra_luma_pred_flag) {
1401 intra_pred_mode = candidate[lc->
pu.
mpm_idx];
1403 if (candidate[0] > candidate[1])
1405 if (candidate[0] > candidate[2])
1407 if (candidate[1] > candidate[2])
1411 for (i = 0; i < 3; i++)
1412 if (intra_pred_mode >= candidate[i])
1419 for (i = 0; i < size_in_pus; i++) {
1420 memset(&s->
tab_ipm[(y_pu + i) * min_pu_width + x_pu],
1421 intra_pred_mode, size_in_pus);
1423 for (j = 0; j < size_in_pus; j++) {
1424 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
is_intra = 1;
1425 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
pred_flag[0] = 0;
1426 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
pred_flag[1] = 0;
1427 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
ref_idx[0] = 0;
1428 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
ref_idx[1] = 0;
1429 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[0].x = 0;
1430 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[0].
y = 0;
1431 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[1].x = 0;
1432 tab_mvf[(y_pu + j) * min_pu_width + x_pu + i].
mv[1].
y = 0;
1436 return intra_pred_mode;
1440 int log2_cb_size,
int ct_depth)
1456 static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
1457 uint8_t prev_intra_luma_pred_flag[4];
1459 int pb_size = (1 << log2_cb_size) >> split;
1460 int side = split + 1;
1464 for (i = 0; i < side; i++)
1465 for (j = 0; j < side; j++)
1468 for (i = 0; i < side; i++) {
1469 for (j = 0; j < side; j++) {
1470 if (prev_intra_luma_pred_flag[2 * i + j])
1477 prev_intra_luma_pred_flag[2 * i + j]);
1482 if (chroma_mode != 4) {
1497 int pb_size = 1 << log2_cb_size;
1505 if (size_in_pus == 0)
1507 for (j = 0; j < size_in_pus; j++) {
1508 memset(&s->
tab_ipm[(y_pu + j) * min_pu_width + x_pu],
INTRA_DC, size_in_pus);
1509 for (k = 0; k < size_in_pus; k++)
1516 int cb_size = 1 << log2_cb_size;
1519 int length = cb_size >> log2_min_cb_size;
1521 int x_cb = x0 >> log2_min_cb_size;
1522 int y_cb = y0 >> log2_min_cb_size;
1534 for (x = 0; x < 4; x++)
1547 x = y_cb * min_cb_width + x_cb;
1548 for (y = 0; y <
length; y++) {
1549 memset(&s->
skip_flag[x], skip_flag, length);
1576 log2_cb_size <= s->sps->pcm.log2_max_pcm_cb_size) {
1625 hls_prediction_unit(s, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3);
1640 log2_cb_size, 0, 0);
1653 x = y_cb * min_cb_width + x_cb;
1654 for (y = 0; y <
length; y++) {
1665 int log2_cb_size,
int cb_depth)
1668 const int cb_size = 1 << log2_cb_size;
1672 if ((x0 + cb_size <= s->sps->width) &&
1673 (y0 + cb_size <= s->sps->height) &&
1688 const int cb_size_split = cb_size >> 1;
1689 const int x1 = x0 + cb_size_split;
1690 const int y1 = y0 + cb_size_split;
1697 if (more_data && x1 < s->sps->width)
1699 if (more_data && y1 < s->sps->height)
1701 if (more_data && x1 < s->sps->width &&
1702 y1 < s->sps->height) {
1706 return ((x1 + cb_size_split) < s->
sps->
width ||
1714 if ((!((x0 + cb_size) %
1716 (x0 + cb_size >= s->
sps->
width)) &&
1721 return !end_of_slice_flag;
1735 int ctb_addr_in_slice = ctb_addr_rs - s->
sh.
slice_addr;
1737 int tile_left_boundary;
1738 int tile_up_boundary;
1739 int slice_left_boundary;
1740 int slice_up_boundary;
1745 if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
1762 tile_left_boundary = ((x_ctb > 0) &&
1764 slice_left_boundary = ((x_ctb > 0) &&
1766 tile_up_boundary = ((y_ctb > 0) &&
1768 slice_up_boundary = ((y_ctb > 0) &&
1771 tile_left_boundary =
1772 tile_up_boundary = 1;
1773 slice_left_boundary = ctb_addr_in_slice > 0;
1774 slice_up_boundary = ctb_addr_in_slice >= s->
sps->
ctb_width;
1778 lc->
ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && tile_left_boundary);
1798 while (more_data && ctb_addr_ts < s->sps->ctb_size) {
1822 if (x_ctb + ctb_size >= s->
sps->
width &&
1846 int *ctb_row_p = input_ctb_row;
1847 int ctb_row = ctb_row_p[job];
1857 ret =
init_get_bits8(&lc->
gb,
s->data +
s->sh.offset[ctb_row - 1],
s->sh.size[ctb_row - 1]);
1864 while(more_data && ctb_addr_ts < s->sps->ctb_size) {
1865 int x_ctb = (ctb_addr_rs %
s->sps->ctb_width) <<
s->sps->log2_ctb_size;
1866 int y_ctb = (ctb_addr_rs /
s->sps->ctb_width) <<
s->sps->log2_ctb_size;
1878 hls_sao_param(
s, x_ctb >>
s->sps->log2_ctb_size, y_ctb >>
s->sps->log2_ctb_size);
1890 if (!more_data && (x_ctb+ctb_size) <
s->sps->width && ctb_row !=
s->sh.num_entry_point_offsets) {
1896 if ((x_ctb+ctb_size) >=
s->sps->width && (y_ctb+ctb_size) >=
s->sps->height ) {
1901 ctb_addr_rs =
s->pps->ctb_addr_ts_to_rs[ctb_addr_ts];
1904 if(x_ctb >=
s->sps->width) {
1919 int startheader, cmpt = 0;
1938 for (j = 0, cmpt = 0, startheader = offset + s->
sh.
entry_point_offset[0]; j < s->skipped_bytes; j++) {
1947 for (j = 0, cmpt = 0, startheader = offset
2011 "nal_unit_type: %d, nuh_layer_id: %dtemporal_id: %d\n",
2014 return nuh_layer_id == 0;
2022 for (c_idx = 0; c_idx < 3; c_idx++) {
2030 int len = min_pu_size >> hshift;
2033 for (n = 0; n < (min_pu_size >> vshift); n++) {
2034 memcpy(dst, src, len);
2156 if (s->
max_ra == INT_MAX) {
2178 }
else if (!s->
ref) {
2188 "Error constructing the reference lists for the current slice.\n");
2207 if (ctb_addr_ts < 0)
2235 #define STARTCODE_TEST \
2236 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
2237 if (src[i + 2] != 3) { \
2243 #if HAVE_FAST_UNALIGNED
2244 #define FIND_FIRST_ZERO \
2245 if (i > 0 && !src[i]) \
2250 for (i = 0; i + 1 <
length; i += 9) {
2252 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
2253 0x8000800080008080ULL))
2260 for (i = 0; i + 1 <
length; i += 5) {
2262 (
AV_RN32A(src + i) - 0x01000101U)) &
2271 for (i = 0; i + 1 <
length; i += 2) {
2274 if (i > 0 && src[i - 1] == 0)
2280 if (i >= length - 1) {
2293 memcpy(dst, src, i);
2295 while (si + 2 < length) {
2297 if (src[si + 2] > 3) {
2298 dst[di++] = src[si++];
2299 dst[di++] = src[si++];
2300 }
else if (src[si] == 0 && src[si + 1] == 0) {
2301 if (src[si + 2] == 3) {
2322 dst[di++] = src[si++];
2325 dst[di++] = src[si++];
2337 int i, consumed,
ret = 0;
2345 while (length >= 4) {
2347 int extract_length = 0;
2352 extract_length = (extract_length << 8) | buf[i];
2356 if (extract_length > length) {
2363 while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
2426 for (i = 0; i < s->
nb_nals; i++) {
2434 "Error parsing NAL unit #%d.\n", i);
2450 for (i = 0; i < 16; i++)
2451 av_log(log_ctx, level,
"%02"PRIx8, md5[i]);
2480 for (i = 0; frame->
data[i]; i++) {
2488 for (j = 0; j < h; j++) {
2493 (
const uint16_t*)src, w);
2501 if (!memcmp(md5, s->
md5[i], 16)) {
2782 int i, j, num_arrays;
2788 nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;
2789 num_arrays = bytestream2_get_byte(&gb);
2796 for (i = 0; i < num_arrays; i++) {
2797 int type = bytestream2_get_byte(&gb) & 0x3f;
2798 int cnt = bytestream2_get_be16(&gb);
2800 for (j = 0; j < cnt; j++) {
2802 int nalsize = bytestream2_peek_be16(&gb) + 2;
2805 "Invalid NAL unit size in extradata.\n");
2812 "Decoding nal unit %d %d from hvcC failed\n", type, i);
2871 memset(s, 0,
sizeof(*s));
2887 #define OFFSET(x) offsetof(HEVCContext, x)
2888 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
2890 {
"strict-displaywin",
"stricly apply default display window size",
OFFSET(strict_def_disp_win),
2908 .priv_class = &hevc_decoder_class,