28 #define UNCHECKED_BITSTREAM_READER 1
57 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
58 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
59 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
60 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
65 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
66 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
67 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10,
68 10,10,10,11,11,11,11,11,11,12,12,12,12,12,12,13,13,13, 13, 13, 13,
73 #if CONFIG_H264_DXVA2_HWACCEL
76 #if CONFIG_H264_VAAPI_HWACCEL
79 #if CONFIG_H264_VDA_HWACCEL
82 #if CONFIG_H264_VDPAU_HWACCEL
90 #if CONFIG_H264_DXVA2_HWACCEL
93 #if CONFIG_H264_VAAPI_HWACCEL
96 #if CONFIG_H264_VDA_HWACCEL
99 #if CONFIG_H264_VDPAU_HWACCEL
114 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
180 offset[2] = (y >> vshift) * src->
linesize[1];
204 for (i = 0; i < 2; i++) {
209 memset((
uint8_t*)pic + off, 0,
sizeof(*pic) - off);
246 for (i = 0; i < 2; i ++) {
262 for (i = 0; i < 2; i++)
318 const int b4_stride = h->
mb_width * 4 + 1;
319 const int b4_array_size = b4_stride * h->
mb_height * 4;
384 for (i = 0; i < 2; i++) {
397 return (ret < 0) ? ret :
AVERROR(ENOMEM);
402 if (pic->
f.
data[0] == NULL)
417 if (i == MAX_PICTURE_COUNT)
434 static const int8_t top[12] = {
437 static const int8_t left[12] = {
443 for (i = 0; i < 4; i++) {
447 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
457 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
458 for (i = 0; i < 4; i++)
463 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
486 "out of range intra chroma pred mode at %d %d\n",
495 "top block unavailable for requested intra mode at %d %d\n",
511 "left block unavailable for requested intra mode at %d %d\n",
521 int *dst_length,
int *consumed,
int length)
534 #define STARTCODE_TEST \
535 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
536 if (src[i + 2] != 3) { \
542 #if HAVE_FAST_UNALIGNED
543 #define FIND_FIRST_ZERO \
544 if (i > 0 && !src[i]) \
549 for (i = 0; i + 1 <
length; i += 9) {
551 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
552 0x8000800080008080ULL))
559 for (i = 0; i + 1 <
length; i += 5) {
561 (
AV_RN32A(src + i) - 0x01000101U)) &
570 for (i = 0; i + 1 <
length; i += 2) {
573 if (i > 0 && src[i - 1] == 0)
595 memcpy(dst, src, length);
602 while (si + 2 < length) {
604 if (src[si + 2] > 3) {
605 dst[di++] = src[si++];
606 dst[di++] = src[si++];
607 }
else if (src[si] == 0 && src[si + 1] == 0) {
608 if (src[si + 2] == 3) {
617 dst[di++] = src[si++];
620 dst[di++] = src[si++];
643 for (r = 1; r < 9; r++) {
652 int height,
int y_offset,
int list)
655 int filter_height_down = (raw_my & 3) ? 3 : 0;
656 int full_my = (raw_my >> 2) + y_offset;
657 int bottom = full_my + filter_height_down +
height;
661 return FFMAX(0, bottom);
665 int height,
int y_offset,
int list0,
666 int list1,
int *nrefs)
682 if (refs[0][ref_n] < 0)
684 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
695 if (refs[1][ref_n] < 0)
697 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
709 const int mb_xy = h->
mb_xy;
712 int nrefs[2] = { 0 };
715 memset(refs, -1,
sizeof(refs));
735 for (i = 0; i < 4; i++) {
738 int y_offset = (i & 2) << 2;
742 IS_DIR(sub_mb_type, 0, 0),
743 IS_DIR(sub_mb_type, 0, 1),
747 IS_DIR(sub_mb_type, 0, 0),
748 IS_DIR(sub_mb_type, 0, 1),
751 IS_DIR(sub_mb_type, 0, 0),
752 IS_DIR(sub_mb_type, 0, 1),
756 IS_DIR(sub_mb_type, 0, 0),
757 IS_DIR(sub_mb_type, 0, 1),
760 IS_DIR(sub_mb_type, 0, 0),
761 IS_DIR(sub_mb_type, 0, 1),
766 for (j = 0; j < 4; j++) {
767 int sub_y_offset = y_offset + 2 * (j & 2);
769 IS_DIR(sub_mb_type, 0, 0),
770 IS_DIR(sub_mb_type, 0, 1),
777 for (list = h->
list_count - 1; list >= 0; list--)
778 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
779 int row = refs[list][ref];
784 int pic_height = 16 * h->
mb_height >> ref_field_picture;
791 FFMIN((row >> 1) - !(row & 1),
795 FFMIN((row >> 1), pic_height - 1),
799 FFMIN(row * 2 + ref_field,
804 FFMIN(row, pic_height - 1),
808 FFMIN(row, pic_height - 1),
820 int src_x_offset,
int src_y_offset,
823 int pixel_shift,
int chroma_idc)
827 const int luma_xy = (mx & 3) + ((my & 3) << 2);
832 int extra_height = 0;
834 const int full_mx = mx >> 2;
835 const int full_my = my >> 2;
836 const int pic_width = 16 * h->
mb_width;
845 if (full_mx < 0 - extra_width ||
846 full_my < 0 - extra_height ||
847 full_mx + 16 > pic_width + extra_width ||
848 full_my + 16 > pic_height + extra_height) {
852 16 + 5, 16 + 5 , full_mx - 2,
853 full_my - 2, pic_width, pic_height);
865 if (chroma_idc == 3 ) {
872 full_mx - 2, full_my - 2,
873 pic_width, pic_height);
886 full_mx - 2, full_my - 2,
887 pic_width, pic_height);
896 ysh = 3 - (chroma_idc == 2 );
897 if (chroma_idc == 1 &&
MB_FIELD(h)) {
900 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
903 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
905 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
910 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
911 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
915 height >> (chroma_idc == 1 ),
916 mx & 7, (my << (chroma_idc == 2 )) & 7);
920 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
921 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
924 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
925 mx & 7, (my << (chroma_idc == 2 )) & 7);
932 int x_offset,
int y_offset,
937 int list0,
int list1,
938 int pixel_shift,
int chroma_idc)
943 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
944 if (chroma_idc == 3 ) {
945 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
946 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
947 }
else if (chroma_idc == 2 ) {
948 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
949 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
951 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
952 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
954 x_offset += 8 * h->
mb_x;
960 dest_y, dest_cb, dest_cr, x_offset, y_offset,
961 qpix_op, chroma_op, pixel_shift, chroma_idc);
964 chroma_op = chroma_avg;
970 dest_y, dest_cb, dest_cr, x_offset, y_offset,
971 qpix_op, chroma_op, pixel_shift, chroma_idc);
979 int x_offset,
int y_offset,
986 int list0,
int list1,
987 int pixel_shift,
int chroma_idc)
991 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
992 if (chroma_idc == 3 ) {
994 chroma_weight_avg = luma_weight_avg;
995 chroma_weight_op = luma_weight_op;
996 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
997 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
998 }
else if (chroma_idc == 2 ) {
1000 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1001 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1003 chroma_height = height >> 1;
1004 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1005 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1007 x_offset += 8 * h->
mb_x;
1010 if (list0 && list1) {
1020 dest_y, dest_cb, dest_cr,
1021 x_offset, y_offset, qpix_put, chroma_put,
1022 pixel_shift, chroma_idc);
1024 tmp_y, tmp_cb, tmp_cr,
1025 x_offset, y_offset, qpix_put, chroma_put,
1026 pixel_shift, chroma_idc);
1030 int weight1 = 64 - weight0;
1032 height, 5, weight0, weight1, 0);
1034 chroma_height, 5, weight0, weight1, 0);
1036 chroma_height, 5, weight0, weight1, 0);
1038 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
1044 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
1050 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
1058 int list = list1 ? 1 : 0;
1061 mc_dir_part(h, ref, n, square, height, delta, list,
1062 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1063 qpix_put, chroma_put, pixel_shift, chroma_idc);
1083 int pixel_shift,
int chroma_idc)
1092 int off = (mx << pixel_shift) +
1094 (64 << pixel_shift);
1096 if (chroma_idc == 3 ) {
1100 off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (h->
mb_x&7))*h->
uvlinesize;
1125 for (i = 0; i < 3; i++)
1133 if (free_rbsp && h->
DPB) {
1137 }
else if (h->
DPB) {
1176 for (i = 0; i < 6; i++) {
1178 for (j = 0; j < i; j++)
1187 for (q = 0; q < max_qp + 1; q++) {
1190 for (x = 0; x < 64; x++)
1202 for (i = 0; i < 6; i++) {
1204 for (j = 0; j < i; j++)
1213 for (q = 0; q < max_qp + 1; q++) {
1216 for (x = 0; x < 16; x++)
1231 for (i = 0; i < 6; i++)
1232 for (x = 0; x < 16; x++)
1235 for (i = 0; i < 6; i++)
1236 for (x = 0; x < 64; x++)
1248 row_mb_num * 8 *
sizeof(
uint8_t), fail)
1250 big_mb_num * 48 *
sizeof(
uint8_t), fail)
1254 big_mb_num *
sizeof(uint16_t), fail)
1256 big_mb_num *
sizeof(
uint8_t), fail)
1258 16 * row_mb_num *
sizeof(
uint8_t), fail);
1260 16 * row_mb_num *
sizeof(
uint8_t), fail);
1262 4 * big_mb_num *
sizeof(
uint8_t), fail);
1264 big_mb_num *
sizeof(
uint8_t), fail)
1271 big_mb_num *
sizeof(uint32_t), fail);
1273 big_mb_num *
sizeof(uint32_t), fail);
1275 for (x = 0; x < h->
mb_width; x++) {
1277 const int b_xy = 4 * x + 4 * y * h->
b_stride;
1338 int yc_size = y_size + 2 * c_size;
1353 if (CONFIG_ERROR_RESILIENCE) {
1377 mb_array_size *
sizeof(
uint8_t), fail);
1391 for (i = 0; i < yc_size; i++)
1402 int parse_extradata);
1408 if (!buf || size <= 0)
1412 int i, cnt, nalsize;
1413 const unsigned char *p =
buf;
1425 cnt = *(p + 5) & 0x1f;
1427 for (i = 0; i < cnt; i++) {
1429 if(nalsize > size - (p-buf))
1433 "Decoding sps %d from avcC failed\n", i);
1440 for (i = 0; i < cnt; i++) {
1442 if(nalsize > size - (p-buf))
1446 "Decoding pps %d from avcC failed\n", i);
1484 if (CONFIG_ERROR_RESILIENCE)
1544 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1545 #undef REBASE_PICTURE
1546 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
1547 ((pic && pic >= old_ctx->DPB && \
1548 pic < old_ctx->DPB + MAX_PICTURE_COUNT) ? \
1549 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
1557 for (i = 0; i <
count; i++) {
1558 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1570 for (i = 0; i <
count; i++) {
1571 if (to[i] && !from[i])
1573 else if (from[i] && !to[i])
1577 memcpy(to[i], from[i], size);
1595 #define copy_fields(to, from, start_field, end_field) \
1596 memcpy(&to->start_field, &from->start_field, \
1597 (char *)&to->end_field - (char *)&to->start_field)
1608 int context_reinitialized = 0;
1615 (h->
width != h1->width ||
1616 h->
height != h1->height ||
1630 h->
width = h1->width;
1649 context_reinitialized = 1;
1672 memcpy(h, h1, offsetof(
H264Context, intra_pcm_ptr));
1673 memcpy(&h->
cabac, &h1->cabac,
1680 memset(&h->
er, 0,
sizeof(h->
er));
1681 memset(&h->
me, 0,
sizeof(h->
me));
1682 memset(&h->
mb, 0,
sizeof(h->
mb));
1693 if (h1->context_initialized) {
1707 for (i = 0; i < 2; i++) {
1732 if (h1->DPB[i].f.data[0] &&
1759 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1761 for (i = 0; i < 6; i++)
1763 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1765 for (i = 0; i < 6; i++)
1767 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1784 if (context_reinitialized)
1853 if (CONFIG_ERROR_RESILIENCE) {
1861 for (i = 0; i < 16; i++) {
1865 for (i = 0; i < 16; i++) {
1902 int i, pics, out_of_order, out_idx;
2002 for (i = 0; 1; i++) {
2014 out_of_order =
FFMAX(out_of_order, 1);
2079 int linesize,
int uvlinesize,
2089 src_cb -= uvlinesize;
2090 src_cr -= uvlinesize;
2096 AV_COPY128(top_border, src_y + 15 * linesize);
2098 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2102 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2103 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2104 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2105 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2107 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2108 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2110 }
else if (chroma422) {
2112 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2113 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2115 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2116 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2120 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2121 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2123 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2124 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2138 AV_COPY128(top_border, src_y + 16 * linesize);
2140 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2145 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2146 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2147 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2148 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2150 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2151 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2153 }
else if (chroma422) {
2155 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2156 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2158 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2159 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2163 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2164 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2166 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2167 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2175 int linesize,
int uvlinesize,
2176 int xchg,
int chroma444,
2177 int simple,
int pixel_shift)
2179 int deblock_topleft;
2198 deblock_topleft = (h->
mb_x > 0);
2202 src_y -= linesize + 1 + pixel_shift;
2203 src_cb -= uvlinesize + 1 + pixel_shift;
2204 src_cr -= uvlinesize + 1 + pixel_shift;
2209 #define XCHG(a, b, xchg) \
2210 if (pixel_shift) { \
2212 AV_SWAP64(b + 0, a + 0); \
2213 AV_SWAP64(b + 8, a + 8); \
2223 if (deblock_topleft) {
2224 XCHG(top_border_m1 + (8 << pixel_shift),
2225 src_y - (7 << pixel_shift), 1);
2227 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2228 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2231 src_y + (17 << pixel_shift), 1);
2235 if (deblock_topleft) {
2236 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2237 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2239 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2240 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2241 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2242 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2244 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2245 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2248 if (deblock_topleft) {
2249 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2250 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2252 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2253 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2262 if (high_bit_depth) {
2271 if (high_bit_depth) {
2278 int mb_type,
int is_h264,
2280 int transform_bypass,
2290 block_offset += 16 * p;
2293 if (transform_bypass) {
2300 for (i = 0; i < 16; i += 4) {
2301 uint8_t *
const ptr = dest_y + block_offset[i];
2304 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2310 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2311 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2313 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2318 if (transform_bypass) {
2325 for (i = 0; i < 16; i++) {
2326 uint8_t *
const ptr = dest_y + block_offset[i];
2330 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2338 if (!topright_avail) {
2340 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2341 topright = (
uint8_t *)&tr_high;
2343 tr = ptr[3 - linesize] * 0x01010101
u;
2347 topright = ptr + (4 << pixel_shift) - linesize;
2351 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2355 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2356 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2358 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2359 }
else if (CONFIG_SVQ3_DECODER)
2369 if (!transform_bypass)
2374 static const uint8_t dc_mapping[16] = {
2375 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2376 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2377 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2378 10 * 16, 11 * 16, 14 * 16, 15 * 16 };
2379 for (i = 0; i < 16; i++)
2381 pixel_shift, dc_mapping[i],
2386 }
else if (CONFIG_SVQ3_DECODER)
2393 int is_h264,
int simple,
2394 int transform_bypass,
2402 block_offset += 16 * p;
2406 if (transform_bypass) {
2411 h->
mb + (p * 256 << pixel_shift),
2414 for (i = 0; i < 16; i++)
2418 h->
mb + (i * 16 + p * 256 << pixel_shift),
2423 h->
mb + (p * 256 << pixel_shift),
2427 }
else if (h->
cbp & 15) {
2428 if (transform_bypass) {
2429 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2432 for (i = 0; i < 16; i += di)
2435 h->
mb + (i * 16 + p * 256 << pixel_shift),
2440 h->
mb + (p * 256 << pixel_shift),
2445 h->
mb + (p * 256 << pixel_shift),
2450 }
else if (CONFIG_SVQ3_DECODER) {
2451 for (i = 0; i < 16; i++)
2454 uint8_t *
const ptr = dest_y + block_offset[i];
2476 const int mb_xy = h->
mb_xy;
2482 hl_decode_mb_444_complex(h);
2484 hl_decode_mb_444_simple_8(h);
2485 }
else if (is_complex) {
2486 hl_decode_mb_complex(h);
2488 hl_decode_mb_simple_16(h);
2490 hl_decode_mb_simple_8(h);
2496 int luma_def, chroma_def;
2506 for (list = 0; list < 2; list++) {
2509 for (i = 0; i < h->
ref_count[list]; i++) {
2510 int luma_weight_flag, chroma_weight_flag;
2513 if (luma_weight_flag) {
2528 if (chroma_weight_flag) {
2530 for (j = 0; j < 2; j++) {
2541 for (j = 0; j < 2; j++) {
2562 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2564 for (i = 0; i < 2; i++) {
2596 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2598 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2602 int td = av_clip(poc1 - poc0, -128, 127);
2604 int tb = av_clip(cur_poc - poc0, -128, 127);
2605 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
2606 int dist_scale_factor = (tb * tx + 32) >> 8;
2607 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2608 w = 64 - dist_scale_factor;
2718 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2729 expected_delta_per_poc_cycle = 0;
2734 if (abs_frame_num > 0) {
2738 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2739 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2747 field_poc[0] = expectedpoc + h->
delta_poc[0];
2763 pic_field_poc[0] = field_poc[0];
2765 pic_field_poc[1] = field_poc[1];
2767 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
2778 for (i = 0; i < 16; i++) {
2779 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2784 for (i = 0; i < 64; i++) {
2785 #define T(x) (x >> 3) | ((x & 7) << 3)
2815 if (CONFIG_H264_VDPAU_DECODER &&
2833 "hardware accelerator failed to decode picture\n");
2836 if (CONFIG_H264_VDPAU_DECODER &&
2852 if (CONFIG_ERROR_RESILIENCE &&
2929 "Reenabling low delay requires a codec flush.\n");
2939 "Different chroma and luma bit depth");
2949 "VDPAU decoding does not support video colorspace.\n");
2965 if (CONFIG_ERROR_RESILIENCE)
3074 if (width <= 0 || height <= 0) {
3098 int nb_slices = (HAVE_THREADS &&
3126 "Could not allocate memory for h264\n");
3137 " reducing to %d\n", nb_slices, max_slices);
3138 nb_slices = max_slices;
3152 if (CONFIG_ERROR_RESILIENCE) {
3210 unsigned int first_mb_in_slice;
3211 unsigned int pps_id;
3212 int num_ref_idx_active_override_flag,
ret;
3213 unsigned int slice_type, tmp, i, j;
3214 int last_pic_structure, last_pic_droppable;
3216 int needs_reinit = 0;
3223 if (first_mb_in_slice == 0) {
3239 if (slice_type > 9) {
3241 "slice type too large (%d) at %d %d\n",
3245 if (slice_type > 4) {
3265 "non-existing PPS %u referenced\n",
3273 "non-existing SPS %u referenced\n",
3369 "h264_slice_header_init() failed\n");
3376 "Cannot (re-)initialize context during parallel decoding.\n");
3386 "h264_slice_header_init() failed\n");
3423 "Changing field mode (%d -> %d) between slices is not allowed\n",
3430 "unset cur_pic_ptr on %d. slice\n",
3441 if (unwrap_prev_frame_num > h->
frame_num)
3442 unwrap_prev_frame_num -= max_frame_num;
3446 if (unwrap_prev_frame_num < 0)
3447 unwrap_prev_frame_num += max_frame_num;
3473 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3483 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3494 "Invalid field mode combination %d/%d\n",
3499 }
else if (last_pic_droppable != h->
droppable) {
3501 "Found reference and non-reference fields in the same frame, which");
3616 first_mb_in_slice >= h->
mb_num) {
3666 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3668 if (num_ref_idx_active_override_flag) {
3713 for (i = 0; i < 2; i++) {
3776 "deblocking_filter_idc %u out of range\n", tmp);
3789 "deblocking filter parameters %d %d out of range\n",
3814 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3819 "Deblocking switched inside frame.\n");
3844 for (j = 0; j < 2; j++) {
3847 for (i = 0; i < 16; i++) {
3849 if (j < h->list_count && i < h->ref_count[j] && h->
ref_list[j][i].
f.
buf[0]) {
3867 for (i = 0; i < 16; i++)
3868 ref2frm[i + 2] = 4 * id_list[i] +
3871 ref2frm[18 + 1] = -1;
3872 for (i = 16; i < 48; i++)
3873 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3882 "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",
3923 int mb_type,
int top_xy,
3926 int left_type[LEFT_MBS],
3927 int mb_xy,
int list)
3934 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
3935 const int b8_xy = 4 * top_xy + 2;
3938 ref_cache[0 - 1 * 8] =
3939 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
3940 ref_cache[2 - 1 * 8] =
3941 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
3950 const int b8_xy = 4 * left_xy[
LTOP] + 1;
3957 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
3958 ref_cache[-1 + 16] =
3959 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
3967 ref_cache[-1 + 16] =
3985 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
3986 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
3987 AV_WN32A(&ref_cache[0 * 8], ref01);
3988 AV_WN32A(&ref_cache[1 * 8], ref01);
3989 AV_WN32A(&ref_cache[2 * 8], ref23);
3990 AV_WN32A(&ref_cache[3 * 8], ref23);
3995 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
3996 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
3997 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
3998 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
4008 const int mb_xy = h->
mb_xy;
4019 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
4024 if (left_mb_field_flag != curr_mb_field_flag)
4027 if (curr_mb_field_flag)
4030 if (left_mb_field_flag != curr_mb_field_flag)
4044 if (qp <= qp_thresh &&
4045 (left_xy[
LTOP] < 0 ||
4051 if ((left_xy[
LTOP] < 0 ||
4066 left_type[
LTOP] = left_type[
LBOT] = 0;
4071 left_type[
LTOP] = left_type[
LBOT] = 0;
4081 top_type, left_type, mb_xy, 0);
4084 top_type, left_type, mb_xy, 1);
4088 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
4089 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
4090 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
4091 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
4096 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
4099 if (left_type[
LTOP]) {
4101 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4102 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4103 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4104 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4111 nnz_cache[4 + 8 * 0] =
4112 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4113 nnz_cache[6 + 8 * 0] =
4114 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4117 nnz_cache[3 + 8 * 1] =
4118 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4121 nnz_cache[3 + 8 * 3] =
4122 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4126 nnz_cache[
scan8[0]] =
4127 nnz_cache[scan8[1]] =
4128 nnz_cache[scan8[2]] =
4129 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4131 nnz_cache[scan8[0 + 4]] =
4132 nnz_cache[scan8[1 + 4]] =
4133 nnz_cache[scan8[2 + 4]] =
4134 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4136 nnz_cache[scan8[0 + 8]] =
4137 nnz_cache[scan8[1 + 8]] =
4138 nnz_cache[scan8[2 + 8]] =
4139 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
4141 nnz_cache[scan8[0 + 12]] =
4142 nnz_cache[scan8[1 + 12]] =
4143 nnz_cache[scan8[2 + 12]] =
4144 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
4153 uint8_t *dest_y, *dest_cb, *dest_cr;
4154 int linesize, uvlinesize, mb_x, mb_y;
4161 for (mb_x = start_x; mb_x < end_x; mb_x++)
4162 for (mb_y = end_mb_y -
FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
4176 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
4178 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4181 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4206 linesize, uvlinesize);
4209 dest_cr, linesize, uvlinesize);
4241 if ((top + height) >= pic_height)
4242 height += deblock_border;
4243 top -= deblock_border;
4246 if (top >= pic_height || (top + height) < 0)
4249 height =
FFMIN(height, pic_height - top);
4265 int endx,
int endy,
int status)
4267 if (CONFIG_ERROR_RESILIENCE) {
4278 int lf_x_start = h->
mb_x;
4334 if (h->
mb_x >= lf_x_start)
4342 "error while decoding MB %d %d, bytestream (%td)\n",
4352 h->
mb_x = lf_x_start = 0;
4367 if (h->
mb_x > lf_x_start)