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, 30, 40, 38 },
159 { 36, 32, 58, 34, 46, 43 },
163 #if CONFIG_H264_DXVA2_HWACCEL
166 #if CONFIG_H264_VAAPI_HWACCEL
169 #if CONFIG_H264_VDA_HWACCEL
172 #if CONFIG_H264_VDPAU_HWACCEL
180 #if CONFIG_H264_DXVA2_HWACCEL
183 #if CONFIG_H264_VAAPI_HWACCEL
186 #if CONFIG_H264_VDA_HWACCEL
189 #if CONFIG_H264_VDPAU_HWACCEL
204 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
270 offset[2] = (y >> vshift) * src->
linesize[1];
294 for (i = 0; i < 2; i++) {
299 memset((
uint8_t*)pic + off, 0,
sizeof(*pic) - off);
335 for (i = 0; i < 2; i++) {
351 for (i = 0; i < 2; i++)
407 const int b4_stride = h->
mb_width * 4 + 1;
408 const int b4_array_size = b4_stride * h->
mb_height * 4;
459 int h_chroma_shift, v_chroma_shift;
461 &h_chroma_shift, &v_chroma_shift);
465 0x80, FF_CEIL_RSHIFT(h->
avctx->
width, h_chroma_shift));
467 0x80, FF_CEIL_RSHIFT(h->
avctx->
width, h_chroma_shift));
485 for (i = 0; i < 2; i++) {
498 return (ret < 0) ? ret :
AVERROR(ENOMEM);
518 if (i == MAX_PICTURE_COUNT)
535 static const int8_t top[12] = {
538 static const int8_t left[12] = {
544 for (i = 0; i < 4; i++) {
548 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
558 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
559 for (i = 0; i < 4; i++)
564 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
587 "out of range intra chroma pred mode at %d %d\n",
596 "top block unavailable for requested intra mode at %d %d\n",
612 "left block unavailable for requested intra mode at %d %d\n",
622 int *dst_length,
int *consumed,
int length)
635 #define STARTCODE_TEST \
636 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
637 if (src[i + 2] != 3) { \
644 #if HAVE_FAST_UNALIGNED
645 #define FIND_FIRST_ZERO \
646 if (i > 0 && !src[i]) \
652 for (i = 0; i + 1 <
length; i += 9) {
654 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
655 0x8000800080008080ULL))
662 for (i = 0; i + 1 <
length; i += 5) {
664 (
AV_RN32A(src + i) - 0x01000101U)) &
673 for (i = 0; i + 1 <
length; i += 2) {
676 if (i > 0 && src[i - 1] == 0)
698 memcpy(dst, src, length);
705 while (si + 2 < length) {
707 if (src[si + 2] > 3) {
708 dst[di++] = src[si++];
709 dst[di++] = src[si++];
710 }
else if (src[si] == 0 && src[si + 1] == 0) {
711 if (src[si + 2] == 3) {
720 dst[di++] = src[si++];
723 dst[di++] = src[si++];
746 for (r = 1; r < 9; r++) {
755 int height,
int y_offset,
int list)
758 int filter_height_down = (raw_my & 3) ? 3 : 0;
759 int full_my = (raw_my >> 2) + y_offset;
760 int bottom = full_my + filter_height_down +
height;
764 return FFMAX(0, bottom);
768 int height,
int y_offset,
int list0,
769 int list1,
int *nrefs)
785 if (refs[0][ref_n] < 0)
787 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
798 if (refs[1][ref_n] < 0)
800 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
812 const int mb_xy = h->
mb_xy;
815 int nrefs[2] = { 0 };
818 memset(refs, -1,
sizeof(refs));
838 for (i = 0; i < 4; i++) {
841 int y_offset = (i & 2) << 2;
845 IS_DIR(sub_mb_type, 0, 0),
846 IS_DIR(sub_mb_type, 0, 1),
850 IS_DIR(sub_mb_type, 0, 0),
851 IS_DIR(sub_mb_type, 0, 1),
854 IS_DIR(sub_mb_type, 0, 0),
855 IS_DIR(sub_mb_type, 0, 1),
859 IS_DIR(sub_mb_type, 0, 0),
860 IS_DIR(sub_mb_type, 0, 1),
863 IS_DIR(sub_mb_type, 0, 0),
864 IS_DIR(sub_mb_type, 0, 1),
869 for (j = 0; j < 4; j++) {
870 int sub_y_offset = y_offset + 2 * (j & 2);
872 IS_DIR(sub_mb_type, 0, 0),
873 IS_DIR(sub_mb_type, 0, 1),
880 for (list = h->
list_count - 1; list >= 0; list--)
881 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
882 int row = refs[list][ref];
887 int pic_height = 16 * h->
mb_height >> ref_field_picture;
894 FFMIN((row >> 1) - !(row & 1),
898 FFMIN((row >> 1), pic_height - 1),
902 FFMIN(row * 2 + ref_field,
907 FFMIN(row, pic_height - 1),
911 FFMIN(row, pic_height - 1),
923 int src_x_offset,
int src_y_offset,
926 int pixel_shift,
int chroma_idc)
930 const int luma_xy = (mx & 3) + ((my & 3) << 2);
935 int extra_height = 0;
937 const int full_mx = mx >> 2;
938 const int full_my = my >> 2;
939 const int pic_width = 16 * h->
mb_width;
948 if (full_mx < 0 - extra_width ||
949 full_my < 0 - extra_height ||
950 full_mx + 16 > pic_width + extra_width ||
951 full_my + 16 > pic_height + extra_height) {
955 16 + 5, 16 + 5 , full_mx - 2,
956 full_my - 2, pic_width, pic_height);
968 if (chroma_idc == 3 ) {
975 full_mx - 2, full_my - 2,
976 pic_width, pic_height);
989 full_mx - 2, full_my - 2,
990 pic_width, pic_height);
999 ysh = 3 - (chroma_idc == 2 );
1000 if (chroma_idc == 1 &&
MB_FIELD(h)) {
1003 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
1006 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
1008 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
1014 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
1015 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
1019 height >> (chroma_idc == 1 ),
1020 mx & 7, (my << (chroma_idc == 2 )) & 7);
1025 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
1026 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
1029 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
1030 mx & 7, (my << (chroma_idc == 2 )) & 7);
1037 int x_offset,
int y_offset,
1042 int list0,
int list1,
1043 int pixel_shift,
int chroma_idc)
1048 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1049 if (chroma_idc == 3 ) {
1050 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1051 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1052 }
else if (chroma_idc == 2 ) {
1053 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1054 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1056 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1057 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1059 x_offset += 8 * h->
mb_x;
1065 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1066 qpix_op, chroma_op, pixel_shift, chroma_idc);
1069 chroma_op = chroma_avg;
1075 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1076 qpix_op, chroma_op, pixel_shift, chroma_idc);
1084 int x_offset,
int y_offset,
1091 int list0,
int list1,
1092 int pixel_shift,
int chroma_idc)
1096 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1097 if (chroma_idc == 3 ) {
1099 chroma_weight_avg = luma_weight_avg;
1100 chroma_weight_op = luma_weight_op;
1101 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1102 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1103 }
else if (chroma_idc == 2 ) {
1105 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1106 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1108 chroma_height = height >> 1;
1109 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1110 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1112 x_offset += 8 * h->
mb_x;
1115 if (list0 && list1) {
1125 dest_y, dest_cb, dest_cr,
1126 x_offset, y_offset, qpix_put, chroma_put,
1127 pixel_shift, chroma_idc);
1129 tmp_y, tmp_cb, tmp_cr,
1130 x_offset, y_offset, qpix_put, chroma_put,
1131 pixel_shift, chroma_idc);
1135 int weight1 = 64 - weight0;
1137 height, 5, weight0, weight1, 0);
1139 chroma_height, 5, weight0, weight1, 0);
1141 chroma_height, 5, weight0, weight1, 0);
1143 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
1149 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
1155 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
1163 int list = list1 ? 1 : 0;
1166 mc_dir_part(h, ref, n, square, height, delta, list,
1167 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1168 qpix_put, chroma_put, pixel_shift, chroma_idc);
1188 int pixel_shift,
int chroma_idc)
1197 int off = (mx << pixel_shift) +
1199 (64 << pixel_shift);
1201 if (chroma_idc == 3 ) {
1205 off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (h->
mb_x&7))*h->
uvlinesize;
1235 if (free_rbsp && h->
DPB) {
1239 }
else if (h->
DPB) {
1278 for (i = 0; i < 6; i++) {
1280 for (j = 0; j < i; j++)
1289 for (q = 0; q < max_qp + 1; q++) {
1292 for (x = 0; x < 64; x++)
1304 for (i = 0; i < 6; i++) {
1306 for (j = 0; j < i; j++)
1315 for (q = 0; q < max_qp + 1; q++) {
1318 for (x = 0; x < 16; x++)
1335 for (i = 0; i < 6; i++)
1336 for (x = 0; x < 16; x++)
1339 for (i = 0; i < 6; i++)
1340 for (x = 0; x < 64; x++)
1352 row_mb_num * 8 *
sizeof(
uint8_t), fail)
1354 big_mb_num * 48 *
sizeof(
uint8_t), fail)
1358 big_mb_num *
sizeof(uint16_t), fail)
1360 big_mb_num *
sizeof(
uint8_t), fail)
1362 16 * row_mb_num *
sizeof(
uint8_t), fail);
1364 16 * row_mb_num *
sizeof(
uint8_t), fail);
1366 4 * big_mb_num *
sizeof(
uint8_t), fail);
1368 big_mb_num *
sizeof(
uint8_t), fail)
1375 big_mb_num *
sizeof(uint32_t), fail);
1377 big_mb_num *
sizeof(uint32_t), fail);
1379 for (x = 0; x < h->
mb_width; x++) {
1381 const int b_xy = 4 * x + 4 * y * h->
b_stride;
1442 int yc_size = y_size + 2 * c_size;
1457 if (CONFIG_ERROR_RESILIENCE) {
1481 mb_array_size *
sizeof(
uint8_t), fail);
1495 for (i = 0; i < yc_size; i++)
1506 int parse_extradata);
1513 if (!buf || size <= 0)
1517 int i, cnt, nalsize;
1518 const unsigned char *p =
buf;
1524 "avcC %d too short\n", size);
1531 cnt = *(p + 5) & 0x1f;
1533 for (i = 0; i < cnt; i++) {
1535 if(nalsize > size - (p-buf))
1540 "Decoding sps %d from avcC failed\n", i);
1547 for (i = 0; i < cnt; i++) {
1549 if(nalsize > size - (p-buf))
1554 "Decoding pps %d from avcC failed\n", i);
1594 if (CONFIG_ERROR_RESILIENCE)
1660 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1661 #undef REBASE_PICTURE
1662 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
1663 ((pic && pic >= old_ctx->DPB && \
1664 pic < old_ctx->DPB + MAX_PICTURE_COUNT) ? \
1665 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
1673 for (i = 0; i <
count; i++) {
1674 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1686 for (i = 0; i <
count; i++) {
1687 if (to[i] && !from[i]) {
1689 }
else if (from[i] && !to[i]) {
1696 memcpy(to[i], from[i], size);
1720 #define copy_fields(to, from, start_field, end_field) \
1721 memcpy(&to->start_field, &from->start_field, \
1722 (char *)&to->end_field - (char *)&to->start_field)
1733 int context_reinitialized = 0;
1740 (h->
width != h1->width ||
1741 h->
height != h1->height ||
1755 h->
width = h1->width;
1764 (
void **)h1->sps_buffers,
1769 (
void **)h1->pps_buffers,
1778 context_reinitialized = 1;
1803 memcpy(h, h1, offsetof(
H264Context, intra_pcm_ptr));
1804 memcpy(&h->
cabac, &h1->cabac,
1811 memset(&h->
er, 0,
sizeof(h->
er));
1812 memset(&h->
me, 0,
sizeof(h->
me));
1813 memset(&h->
mb, 0,
sizeof(h->
mb));
1823 for (i = 0; i < 2; i++) {
1828 if (h1->context_initialized) {
1867 if (h1->DPB && h1->DPB[i].f.buf[0] &&
1886 (
void **)h1->sps_buffers,
1891 (
void **)h1->pps_buffers,
1898 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1900 for (i = 0; i < 6; i++)
1902 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1904 for (i = 0; i < 6; i++)
1906 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1923 if (context_reinitialized)
1992 if (CONFIG_ERROR_RESILIENCE) {
1999 if (CONFIG_ERROR_RESILIENCE) {
2007 for (i = 0; i < 16; i++) {
2011 for (i = 0; i < 16; i++) {
2048 int i, pics, out_of_order, out_idx;
2189 for (i = 0; 1; i++) {
2201 out_of_order =
FFMAX(out_of_order, 1);
2271 int linesize,
int uvlinesize,
2281 src_cb -= uvlinesize;
2282 src_cr -= uvlinesize;
2288 AV_COPY128(top_border, src_y + 15 * linesize);
2290 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2294 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2295 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2296 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2297 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2299 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2300 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2302 }
else if (chroma422) {
2304 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2305 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2307 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2308 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2312 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2313 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2315 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2316 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2330 AV_COPY128(top_border, src_y + 16 * linesize);
2332 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2337 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2338 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2339 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2340 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2342 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2343 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2345 }
else if (chroma422) {
2347 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2348 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2350 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2351 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2355 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2356 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2358 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2359 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2367 int linesize,
int uvlinesize,
2368 int xchg,
int chroma444,
2369 int simple,
int pixel_shift)
2371 int deblock_topleft;
2390 deblock_topleft = (h->
mb_x > 0);
2394 src_y -= linesize + 1 + pixel_shift;
2395 src_cb -= uvlinesize + 1 + pixel_shift;
2396 src_cr -= uvlinesize + 1 + pixel_shift;
2401 #define XCHG(a, b, xchg) \
2402 if (pixel_shift) { \
2404 AV_SWAP64(b + 0, a + 0); \
2405 AV_SWAP64(b + 8, a + 8); \
2415 if (deblock_topleft) {
2416 XCHG(top_border_m1 + (8 << pixel_shift),
2417 src_y - (7 << pixel_shift), 1);
2419 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2420 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2423 src_y + (17 << pixel_shift), 1);
2427 if (deblock_topleft) {
2428 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2429 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2431 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2432 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2433 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2434 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2436 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2437 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2440 if (deblock_topleft) {
2441 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2442 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2444 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2445 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2454 if (high_bit_depth) {
2463 if (high_bit_depth) {
2470 int mb_type,
int is_h264,
2472 int transform_bypass,
2482 block_offset += 16 * p;
2485 if (transform_bypass) {
2492 for (i = 0; i < 16; i += 4) {
2493 uint8_t *
const ptr = dest_y + block_offset[i];
2496 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2502 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2503 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2505 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2510 if (transform_bypass) {
2517 for (i = 0; i < 16; i++) {
2518 uint8_t *
const ptr = dest_y + block_offset[i];
2522 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2530 if (!topright_avail) {
2532 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2533 topright = (
uint8_t *)&tr_high;
2535 tr = ptr[3 - linesize] * 0x01010101
u;
2539 topright = ptr + (4 << pixel_shift) - linesize;
2543 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2547 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2548 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2550 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2551 }
else if (CONFIG_SVQ3_DECODER)
2561 if (!transform_bypass)
2566 static const uint8_t dc_mapping[16] = {
2567 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2568 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2569 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2570 10 * 16, 11 * 16, 14 * 16, 15 * 16
2572 for (i = 0; i < 16; i++)
2574 pixel_shift, dc_mapping[i],
2579 }
else if (CONFIG_SVQ3_DECODER)
2586 int is_h264,
int simple,
2587 int transform_bypass,
2595 block_offset += 16 * p;
2599 if (transform_bypass) {
2604 h->
mb + (p * 256 << pixel_shift),
2607 for (i = 0; i < 16; i++)
2611 h->
mb + (i * 16 + p * 256 << pixel_shift),
2616 h->
mb + (p * 256 << pixel_shift),
2620 }
else if (h->
cbp & 15) {
2621 if (transform_bypass) {
2622 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2625 for (i = 0; i < 16; i += di)
2628 h->
mb + (i * 16 + p * 256 << pixel_shift),
2633 h->
mb + (p * 256 << pixel_shift),
2638 h->
mb + (p * 256 << pixel_shift),
2643 }
else if (CONFIG_SVQ3_DECODER) {
2644 for (i = 0; i < 16; i++)
2647 uint8_t *
const ptr = dest_y + block_offset[i];
2669 const int mb_xy = h->
mb_xy;
2671 int is_complex = CONFIG_SMALL || h->
is_complex ||
2676 hl_decode_mb_444_complex(h);
2678 hl_decode_mb_444_simple_8(h);
2679 }
else if (is_complex) {
2680 hl_decode_mb_complex(h);
2682 hl_decode_mb_simple_16(h);
2684 hl_decode_mb_simple_8(h);
2690 int luma_def, chroma_def;
2700 for (list = 0; list < 2; list++) {
2703 for (i = 0; i < h->
ref_count[list]; i++) {
2704 int luma_weight_flag, chroma_weight_flag;
2707 if (luma_weight_flag) {
2722 if (chroma_weight_flag) {
2724 for (j = 0; j < 2; j++) {
2735 for (j = 0; j < 2; j++) {
2756 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2758 for (i = 0; i < 2; i++) {
2790 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2792 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2796 int td = av_clip(poc1 - poc0, -128, 127);
2798 int tb = av_clip(cur_poc - poc0, -128, 127);
2799 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
2800 int dist_scale_factor = (tb * tx + 32) >> 8;
2801 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2802 w = 64 - dist_scale_factor;
2918 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2929 expected_delta_per_poc_cycle = 0;
2934 if (abs_frame_num > 0) {
2938 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2939 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2947 field_poc[0] = expectedpoc + h->
delta_poc[0];
2963 pic_field_poc[0] = field_poc[0];
2965 pic_field_poc[1] = field_poc[1];
2966 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
2977 for (i = 0; i < 16; i++) {
2978 #define TRANSPOSE(x) (x >> 2) | ((x << 2) & 0xF)
2983 for (i = 0; i < 64; i++) {
2984 #define TRANSPOSE(x) (x >> 3) | ((x & 7) << 3)
3014 if (CONFIG_H264_VDPAU_DECODER &&
3032 "hardware accelerator failed to decode picture\n");
3035 if (CONFIG_H264_VDPAU_DECODER &&
3127 "Reenabling low delay requires a codec flush.\n");
3141 "VDPAU decoding does not support video colorspace.\n");
3157 if (CONFIG_ERROR_RESILIENCE)
3266 if (width <= 0 || height <= 0) {
3290 int nb_slices = (HAVE_THREADS &&
3329 " reducing to %d\n", nb_slices, max_slices);
3330 nb_slices = max_slices;
3347 if (CONFIG_ERROR_RESILIENCE) {
3395 int ref_count[2], list_count;
3396 int num_ref_idx_active_override_flag;
3408 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3410 if (num_ref_idx_active_override_flag) {
3419 if (ref_count[0]-1 > max[0] || ref_count[1]-1 > max[1]){
3420 av_log(h->
avctx,
AV_LOG_ERROR,
"reference overflow %u > %u or %u > %u\n", ref_count[0]-1, max[0], ref_count[1]-1, max[1]);
3432 ref_count[0] = ref_count[1] = 0;
3470 unsigned int first_mb_in_slice;
3471 unsigned int pps_id;
3473 unsigned int slice_type, tmp, i, j;
3474 int last_pic_structure, last_pic_droppable;
3476 int needs_reinit = 0;
3477 int field_pic_flag, bottom_field_flag;
3484 if (first_mb_in_slice == 0) {
3500 if (slice_type > 9) {
3502 "slice type %d too large at %d %d\n",
3506 if (slice_type > 4) {
3532 "non-existing PPS %u referenced\n",
3538 "PPS change from %d to %d forbidden\n",
3546 "non-existing SPS %u referenced\n",
3625 "changing width %d -> %d / height %d -> %d on "
3644 "h264_slice_header_init() failed\n");
3651 "Cannot (re-)initialize context during parallel decoding.\n");
3661 "h264_slice_header_init() failed\n");
3686 if (field_pic_flag) {
3700 "Changing field mode (%d -> %d) between slices is not allowed\n",
3707 "unset cur_pic_ptr on slice %d\n",
3718 if (unwrap_prev_frame_num > h->
frame_num)
3719 unwrap_prev_frame_num -= max_frame_num;
3723 if (unwrap_prev_frame_num < 0)
3724 unwrap_prev_frame_num += max_frame_num;
3771 "Invalid field mode combination %d/%d\n",
3776 }
else if (last_pic_droppable != h->
droppable) {
3778 "Found reference and non-reference fields in the same frame, which");
3903 first_mb_in_slice >= h->
mb_num) {
3973 for (i = 0; i < 2; i++) {
4037 "deblocking_filter_idc %u out of range\n", tmp);
4052 "deblocking filter parameters %d %d out of range\n",
4077 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
4082 "Deblocking switched inside frame.\n");
4107 for (j = 0; j < 2; j++) {
4110 for (i = 0; i < 16; i++) {
4112 if (j < h->list_count && i < h->ref_count[j] &&
4131 for (i = 0; i < 16; i++)
4134 ref2frm[18 + 1] = -1;
4135 for (i = 16; i < 48; i++)
4136 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
4150 "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
4191 int mb_type,
int top_xy,
4194 int left_type[LEFT_MBS],
4195 int mb_xy,
int list)
4202 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
4203 const int b8_xy = 4 * top_xy + 2;
4206 ref_cache[0 - 1 * 8] =
4207 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
4208 ref_cache[2 - 1 * 8] =
4209 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
4218 const int b8_xy = 4 * left_xy[
LTOP] + 1;
4225 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
4226 ref_cache[-1 + 16] =
4227 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
4235 ref_cache[-1 + 16] =
4253 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
4254 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
4255 AV_WN32A(&ref_cache[0 * 8], ref01);
4256 AV_WN32A(&ref_cache[1 * 8], ref01);
4257 AV_WN32A(&ref_cache[2 * 8], ref23);
4258 AV_WN32A(&ref_cache[3 * 8], ref23);
4263 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
4264 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
4265 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
4266 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
4276 const int mb_xy = h->
mb_xy;
4287 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
4292 if (left_mb_field_flag != curr_mb_field_flag)
4295 if (curr_mb_field_flag)
4298 if (left_mb_field_flag != curr_mb_field_flag)
4312 if (qp <= qp_thresh &&
4313 (left_xy[
LTOP] < 0 ||
4319 if ((left_xy[
LTOP] < 0 ||
4334 left_type[
LTOP] = left_type[
LBOT] = 0;
4339 left_type[
LTOP] = left_type[
LBOT] = 0;
4349 top_type, left_type, mb_xy, 0);
4352 top_type, left_type, mb_xy, 1);
4356 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
4357 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
4358 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
4359 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
4364 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
4367 if (left_type[
LTOP]) {
4369 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4370 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4371 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4372 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4379 nnz_cache[4 + 8 * 0] =
4380 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4381 nnz_cache[6 + 8 * 0] =
4382 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4385 nnz_cache[3 + 8 * 1] =
4386 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4389 nnz_cache[3 + 8 * 3] =
4390 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4394 nnz_cache[
scan8[0]] =
4395 nnz_cache[scan8[1]] =
4396 nnz_cache[scan8[2]] =
4397 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4399 nnz_cache[scan8[0 + 4]] =
4400 nnz_cache[scan8[1 + 4]] =
4401 nnz_cache[scan8[2 + 4]] =
4402 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4404 nnz_cache[scan8[0 + 8]] =
4405 nnz_cache[scan8[1 + 8]] =
4406 nnz_cache[scan8[2 + 8]] =
4407 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) &