28 #define UNCHECKED_BITSTREAM_READER 1
56 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
57 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
58 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
59 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
64 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
65 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
66 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10,
67 10,10,10,11,11,11,11,11,11,12,12,12,12,12,12,13,13,13, 13, 13, 13,
72 #if CONFIG_H264_DXVA2_HWACCEL
75 #if CONFIG_H264_VAAPI_HWACCEL
78 #if CONFIG_H264_VDA_HWACCEL
81 #if CONFIG_H264_VDPAU_HWACCEL
89 #if CONFIG_H264_DXVA2_HWACCEL
92 #if CONFIG_H264_VAAPI_HWACCEL
95 #if CONFIG_H264_VDA_HWACCEL
98 #if CONFIG_H264_VDPAU_HWACCEL
113 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
179 offset[2] = (y >> vshift) * src->
linesize[1];
208 for (i = 0; i < 2; i++) {
258 const int b4_stride = h->
mb_width * 4 + 1;
259 const int b4_array_size = b4_stride * h->
mb_height * 4;
285 (big_mb_num + h->
mb_stride) *
sizeof(uint32_t),
290 for (i = 0; i < 2; i++) {
292 2 * (b4_array_size + 4) *
sizeof(int16_t),
296 4 * mb_array_size *
sizeof(
uint8_t), fail)
308 return (ret < 0) ? ret :
AVERROR(ENOMEM);
351 static const int8_t top[12] = {
354 static const int8_t left[12] = {
360 for (i = 0; i < 4; i++) {
364 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
374 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
375 for (i = 0; i < 4; i++)
380 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
403 "out of range intra chroma pred mode at %d %d\n",
412 "top block unavailable for requested intra mode at %d %d\n",
428 "left block unavailable for requested intra mode at %d %d\n",
438 int *dst_length,
int *consumed,
int length)
451 #define STARTCODE_TEST \
452 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
453 if (src[i + 2] != 3) { \
459 #if HAVE_FAST_UNALIGNED
460 #define FIND_FIRST_ZERO \
461 if (i > 0 && !src[i]) \
466 for (i = 0; i + 1 < length; i += 9) {
468 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
469 0x8000800080008080ULL))
476 for (i = 0; i + 1 < length; i += 5) {
478 (
AV_RN32A(src + i) - 0x01000101U)) &
487 for (i = 0; i + 1 < length; i += 2) {
490 if (i > 0 && src[i - 1] == 0)
512 memcpy(dst, src, length);
519 while (si + 2 < length) {
521 if (src[si + 2] > 3) {
522 dst[di++] = src[si++];
523 dst[di++] = src[si++];
524 }
else if (src[si] == 0 && src[si + 1] == 0) {
525 if (src[si + 2] == 3) {
534 dst[di++] = src[si++];
537 dst[di++] = src[si++];
560 for (r = 1; r < 9; r++) {
569 int height,
int y_offset,
int list)
572 int filter_height_down = (raw_my & 3) ? 3 : 0;
573 int full_my = (raw_my >> 2) + y_offset;
574 int bottom = full_my + filter_height_down +
height;
578 return FFMAX(0, bottom);
582 int height,
int y_offset,
int list0,
583 int list1,
int *nrefs)
599 if (refs[0][ref_n] < 0)
601 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
612 if (refs[1][ref_n] < 0)
614 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
626 const int mb_xy = h->
mb_xy;
629 int nrefs[2] = { 0 };
632 memset(refs, -1,
sizeof(refs));
652 for (i = 0; i < 4; i++) {
655 int y_offset = (i & 2) << 2;
659 IS_DIR(sub_mb_type, 0, 0),
660 IS_DIR(sub_mb_type, 0, 1),
664 IS_DIR(sub_mb_type, 0, 0),
665 IS_DIR(sub_mb_type, 0, 1),
668 IS_DIR(sub_mb_type, 0, 0),
669 IS_DIR(sub_mb_type, 0, 1),
673 IS_DIR(sub_mb_type, 0, 0),
674 IS_DIR(sub_mb_type, 0, 1),
677 IS_DIR(sub_mb_type, 0, 0),
678 IS_DIR(sub_mb_type, 0, 1),
683 for (j = 0; j < 4; j++) {
684 int sub_y_offset = y_offset + 2 * (j & 2);
686 IS_DIR(sub_mb_type, 0, 0),
687 IS_DIR(sub_mb_type, 0, 1),
694 for (list = h->
list_count - 1; list >= 0; list--)
695 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
696 int row = refs[list][ref];
701 int pic_height = 16 * h->
mb_height >> ref_field_picture;
708 FFMIN((row >> 1) - !(row & 1),
712 FFMIN((row >> 1), pic_height - 1),
716 FFMIN(row * 2 + ref_field,
721 FFMIN(row, pic_height - 1),
725 FFMIN(row, pic_height - 1),
737 int src_x_offset,
int src_y_offset,
740 int pixel_shift,
int chroma_idc)
742 const int mx = h->
mv_cache[list][
scan8[n]][0] + src_x_offset * 8;
744 const int luma_xy = (mx & 3) + ((my & 3) << 2);
749 int extra_height = 0;
751 const int full_mx = mx >> 2;
752 const int full_my = my >> 2;
753 const int pic_width = 16 * h->
mb_width;
762 if (full_mx < 0 - extra_width ||
763 full_my < 0 - extra_height ||
764 full_mx + 16 > pic_width + extra_width ||
765 full_my + 16 > pic_height + extra_height) {
769 16 + 5, 16 + 5 , full_mx - 2,
770 full_my - 2, pic_width, pic_height);
782 if (chroma_idc == 3 ) {
789 full_mx - 2, full_my - 2,
790 pic_width, pic_height);
803 full_mx - 2, full_my - 2,
804 pic_width, pic_height);
813 ysh = 3 - (chroma_idc == 2 );
817 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
820 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
822 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
827 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
828 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
832 height >> (chroma_idc == 1 ),
833 mx & 7, (my << (chroma_idc == 2 )) & 7);
837 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
838 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
841 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
842 mx & 7, (my << (chroma_idc == 2 )) & 7);
849 int x_offset,
int y_offset,
854 int list0,
int list1,
855 int pixel_shift,
int chroma_idc)
860 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
861 if (chroma_idc == 3 ) {
862 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
863 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
864 }
else if (chroma_idc == 2 ) {
865 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
866 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
868 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
869 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
871 x_offset += 8 * h->
mb_x;
877 dest_y, dest_cb, dest_cr, x_offset, y_offset,
878 qpix_op, chroma_op, pixel_shift, chroma_idc);
881 chroma_op = chroma_avg;
887 dest_y, dest_cb, dest_cr, x_offset, y_offset,
888 qpix_op, chroma_op, pixel_shift, chroma_idc);
896 int x_offset,
int y_offset,
903 int list0,
int list1,
904 int pixel_shift,
int chroma_idc)
908 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
909 if (chroma_idc == 3 ) {
911 chroma_weight_avg = luma_weight_avg;
912 chroma_weight_op = luma_weight_op;
913 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
914 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
915 }
else if (chroma_idc == 2 ) {
917 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
918 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
920 chroma_height = height >> 1;
921 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
922 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
924 x_offset += 8 * h->
mb_x;
927 if (list0 && list1) {
937 dest_y, dest_cb, dest_cr,
938 x_offset, y_offset, qpix_put, chroma_put,
939 pixel_shift, chroma_idc);
941 tmp_y, tmp_cb, tmp_cr,
942 x_offset, y_offset, qpix_put, chroma_put,
943 pixel_shift, chroma_idc);
947 int weight1 = 64 - weight0;
949 height, 5, weight0, weight1, 0);
951 chroma_height, 5, weight0, weight1, 0);
953 chroma_height, 5, weight0, weight1, 0);
955 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
961 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
967 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
975 int list = list1 ? 1 : 0;
978 mc_dir_part(h, ref, n, square, height, delta, list,
979 dest_y, dest_cb, dest_cr, x_offset, y_offset,
980 qpix_put, chroma_put, pixel_shift, chroma_idc);
1000 int pixel_shift,
int chroma_idc)
1009 int off = (mx << pixel_shift) +
1011 (64 << pixel_shift);
1013 if (chroma_idc == 3 ) {
1017 off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (h->
mb_x&7))*h->
uvlinesize;
1042 for (i = 0; i < 3; i++)
1050 }
else if (h->
DPB) {
1089 for (i = 0; i < 6; i++) {
1091 for (j = 0; j < i; j++)
1100 for (q = 0; q < max_qp + 1; q++) {
1103 for (x = 0; x < 64; x++)
1115 for (i = 0; i < 6; i++) {
1117 for (j = 0; j < i; j++)
1126 for (q = 0; q < max_qp + 1; q++) {
1129 for (x = 0; x < 16; x++)
1144 for (i = 0; i < 6; i++)
1145 for (x = 0; x < 16; x++)
1148 for (i = 0; i < 6; i++)
1149 for (x = 0; x < 64; x++)
1161 row_mb_num * 8 *
sizeof(
uint8_t), fail)
1163 big_mb_num * 48 *
sizeof(
uint8_t), fail)
1167 big_mb_num *
sizeof(uint16_t), fail)
1169 big_mb_num *
sizeof(
uint8_t), fail)
1171 16 * row_mb_num *
sizeof(
uint8_t), fail);
1173 16 * row_mb_num *
sizeof(
uint8_t), fail);
1175 4 * big_mb_num *
sizeof(
uint8_t), fail);
1177 big_mb_num *
sizeof(
uint8_t), fail)
1184 big_mb_num *
sizeof(uint32_t), fail);
1186 big_mb_num *
sizeof(uint32_t), fail);
1188 for (x = 0; x < h->
mb_width; x++) {
1190 const int b_xy = 4 * x + 4 * y * h->
b_stride;
1252 int yc_size = y_size + 2 * c_size;
1267 if (CONFIG_ERROR_RESILIENCE) {
1291 mb_array_size *
sizeof(
uint8_t), fail);
1305 for (i = 0; i < yc_size; i++)
1316 int parse_extradata);
1338 if (CONFIG_ERROR_RESILIENCE) {
1353 if (!buf || size <= 0)
1357 int i, cnt, nalsize;
1358 const unsigned char *p = buf;
1370 cnt = *(p + 5) & 0x1f;
1372 for (i = 0; i < cnt; i++) {
1374 if(nalsize > size - (p-buf))
1378 "Decoding sps %d from avcC failed\n", i);
1385 for (i = 0; i < cnt; i++) {
1387 if(nalsize > size - (p-buf))
1391 "Decoding pps %d from avcC failed\n", i);
1468 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1469 #undef REBASE_PICTURE
1470 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
1471 ((pic && pic >= old_ctx->DPB && \
1472 pic < old_ctx->DPB + old_ctx->picture_count) ? \
1473 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
1481 for (i = 0; i < count; i++) {
1482 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1494 for (i = 0; i < count; i++) {
1495 if (to[i] && !from[i])
1497 else if (from[i] && !to[i])
1501 memcpy(to[i], from[i], size);
1519 #define copy_fields(to, from, start_field, end_field) \
1520 memcpy(&to->start_field, &from->start_field, \
1521 (char *)&to->end_field - (char *)&to->start_field)
1532 int context_reinitialized = 0;
1539 (h->
width != h1->width ||
1540 h->
height != h1->height ||
1549 h->
width = h1->width;
1568 context_reinitialized = 1;
1591 memcpy(h, h1, offsetof(
H264Context, intra_pcm_ptr));
1592 memcpy(&h->
cabac, &h1->cabac,
1599 memset(&h->
er, 0,
sizeof(h->
er));
1600 memset(&h->
me, 0,
sizeof(h->
me));
1604 if (h1->context_initialized) {
1619 for (i = 0; i < 2; i++) {
1642 memcpy(h->
DPB, h1->DPB, h1->picture_count *
sizeof(*h1->DPB));
1671 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1673 for (i = 0; i < 6; i++)
1675 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1677 for (i = 0; i < 6; i++)
1679 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1698 if (context_reinitialized)
1766 if (CONFIG_ERROR_RESILIENCE) {
1774 for (i = 0; i < 16; i++) {
1778 for (i = 0; i < 16; i++) {
1823 int i, pics, out_of_order, out_idx;
1924 for (i = 0; 1; i++) {
1936 out_of_order =
FFMAX(out_of_order, 1);
2002 int linesize,
int uvlinesize,
2012 src_cb -= uvlinesize;
2013 src_cr -= uvlinesize;
2019 AV_COPY128(top_border, src_y + 15 * linesize);
2021 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2025 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2026 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2027 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2028 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2030 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2031 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2033 }
else if (chroma422) {
2035 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2036 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2038 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2039 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2043 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2044 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2046 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2047 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2061 AV_COPY128(top_border, src_y + 16 * linesize);
2063 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2068 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2069 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2070 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2071 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2073 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2074 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2076 }
else if (chroma422) {
2078 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2079 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2081 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2082 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2086 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2087 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2089 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2090 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2098 int linesize,
int uvlinesize,
2099 int xchg,
int chroma444,
2100 int simple,
int pixel_shift)
2102 int deblock_topleft;
2121 deblock_topleft = (h->
mb_x > 0);
2125 src_y -= linesize + 1 + pixel_shift;
2126 src_cb -= uvlinesize + 1 + pixel_shift;
2127 src_cr -= uvlinesize + 1 + pixel_shift;
2132 #define XCHG(a, b, xchg) \
2133 if (pixel_shift) { \
2135 AV_SWAP64(b + 0, a + 0); \
2136 AV_SWAP64(b + 8, a + 8); \
2146 if (deblock_topleft) {
2147 XCHG(top_border_m1 + (8 << pixel_shift),
2148 src_y - (7 << pixel_shift), 1);
2150 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2151 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2154 src_y + (17 << pixel_shift), 1);
2159 if (deblock_topleft) {
2160 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2161 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2163 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2164 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2165 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2166 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2168 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2169 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2173 if (deblock_topleft) {
2174 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2175 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2177 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2178 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2187 if (high_bit_depth) {
2196 if (high_bit_depth) {
2203 int mb_type,
int is_h264,
2205 int transform_bypass,
2215 block_offset += 16 * p;
2218 if (transform_bypass) {
2225 for (i = 0; i < 16; i += 4) {
2226 uint8_t *
const ptr = dest_y + block_offset[i];
2229 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2235 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2236 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2238 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2243 if (transform_bypass) {
2250 for (i = 0; i < 16; i++) {
2251 uint8_t *
const ptr = dest_y + block_offset[i];
2255 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2263 if (!topright_avail) {
2265 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2266 topright = (
uint8_t *)&tr_high;
2268 tr = ptr[3 - linesize] * 0x01010101
u;
2272 topright = ptr + (4 << pixel_shift) - linesize;
2276 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2280 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2281 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2283 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2284 }
else if (CONFIG_SVQ3_DECODER)
2294 if (!transform_bypass)
2299 static const uint8_t dc_mapping[16] = {
2300 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2301 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2302 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2303 10 * 16, 11 * 16, 14 * 16, 15 * 16 };
2304 for (i = 0; i < 16; i++)
2306 pixel_shift, dc_mapping[i],
2311 }
else if (CONFIG_SVQ3_DECODER)
2318 int is_h264,
int simple,
2319 int transform_bypass,
2327 block_offset += 16 * p;
2331 if (transform_bypass) {
2336 h->
mb + (p * 256 << pixel_shift),
2339 for (i = 0; i < 16; i++)
2343 h->
mb + (i * 16 + p * 256 << pixel_shift),
2348 h->
mb + (p * 256 << pixel_shift),
2352 }
else if (h->
cbp & 15) {
2353 if (transform_bypass) {
2354 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2357 for (i = 0; i < 16; i += di)
2360 h->
mb + (i * 16 + p * 256 << pixel_shift),
2365 h->
mb + (p * 256 << pixel_shift),
2370 h->
mb + (p * 256 << pixel_shift),
2375 }
else if (CONFIG_SVQ3_DECODER) {
2376 for (i = 0; i < 16; i++)
2379 uint8_t *
const ptr = dest_y + block_offset[i];
2401 const int mb_xy = h->
mb_xy;
2407 hl_decode_mb_444_complex(h);
2409 hl_decode_mb_444_simple_8(h);
2410 }
else if (is_complex) {
2411 hl_decode_mb_complex(h);
2413 hl_decode_mb_simple_16(h);
2415 hl_decode_mb_simple_8(h);
2421 int luma_def, chroma_def;
2431 for (list = 0; list < 2; list++) {
2434 for (i = 0; i < h->
ref_count[list]; i++) {
2435 int luma_weight_flag, chroma_weight_flag;
2438 if (luma_weight_flag) {
2453 if (chroma_weight_flag) {
2455 for (j = 0; j < 2; j++) {
2466 for (j = 0; j < 2; j++) {
2487 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2489 for (i = 0; i < 2; i++) {
2521 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2523 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2527 int td = av_clip(poc1 - poc0, -128, 127);
2529 int tb = av_clip(cur_poc - poc0, -128, 127);
2530 int tx = (16384 + (
FFABS(td) >> 1)) / td;
2531 int dist_scale_factor = (tb * tx + 32) >> 8;
2532 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2533 w = 64 - dist_scale_factor;
2643 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2654 expected_delta_per_poc_cycle = 0;
2659 if (abs_frame_num > 0) {
2663 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2664 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2672 field_poc[0] = expectedpoc + h->
delta_poc[0];
2702 for (i = 0; i < 16; i++) {
2703 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2708 for (i = 0; i < 64; i++) {
2709 #define T(x) (x >> 3) | ((x & 7) << 3)
2743 if (CONFIG_H264_VDPAU_DECODER &&
2761 "hardware accelerator failed to decode picture\n");
2764 if (CONFIG_H264_VDPAU_DECODER &&
2780 if (CONFIG_ERROR_RESILIENCE &&
2854 "Reenabling low delay requires a codec flush.\n");
2864 "Different bit depth between chroma and luma", 1);
2874 "VDPAU decoding does not support video colorspace.\n");
2890 if (CONFIG_ERROR_RESILIENCE) {
2987 int nb_slices = (HAVE_THREADS &&
3029 "Could not allocate memory for h264\n");
3040 " reducing to %d\n", nb_slices, max_slices);
3041 nb_slices = max_slices;
3055 if (CONFIG_ERROR_RESILIENCE) {
3113 unsigned int first_mb_in_slice;
3114 unsigned int pps_id;
3115 int num_ref_idx_active_override_flag, ret;
3116 unsigned int slice_type, tmp, i, j;
3117 int default_ref_list_done = 0;
3118 int last_pic_structure, last_pic_droppable;
3120 int needs_reinit = 0;
3127 if (first_mb_in_slice == 0) {
3144 if (slice_type > 9) {
3146 "slice type too large (%d) at %d %d\n",
3150 if (slice_type > 4) {
3161 default_ref_list_done = 1;
3176 "non-existing PPS %u referenced\n",
3184 "non-existing SPS %u referenced\n",
3272 "h264_slice_header_init() failed\n");
3279 "Cannot (re-)initialize context during parallel decoding.\n");
3289 "h264_slice_header_init() failed\n");
3326 "Changing field mode (%d -> %d) between slices is not allowed\n",
3333 "unset cur_pic_ptr on %d. slice\n",
3344 if (unwrap_prev_frame_num > h->
frame_num)
3345 unwrap_prev_frame_num -= max_frame_num;
3349 if (unwrap_prev_frame_num < 0)
3350 unwrap_prev_frame_num += max_frame_num;
3376 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3386 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3397 "Invalid field mode combination %d/%d\n",
3402 }
else if (last_pic_droppable != h->
droppable) {
3404 "Cannot combine reference and non-reference fields in the same frame\n");
3518 first_mb_in_slice >= h->
mb_num) {
3568 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3570 if (num_ref_idx_active_override_flag) {
3594 if (!default_ref_list_done)
3612 for (i = 0; i < 2; i++) {
3675 "deblocking_filter_idc %u out of range\n", tmp);
3688 "deblocking filter parameters %d %d out of range\n",
3713 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3718 "Deblocking switched inside frame.\n");
3743 for (j = 0; j < 2; j++) {
3746 for (i = 0; i < 16; i++) {
3766 for (i = 0; i < 16; i++)
3767 ref2frm[i + 2] = 4 * id_list[i] +
3770 ref2frm[18 + 1] = -1;
3771 for (i = 16; i < 48; i++)
3772 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3781 "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",
3822 int mb_type,
int top_xy,
3825 int left_type[LEFT_MBS],
3826 int mb_xy,
int list)
3833 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
3834 const int b8_xy = 4 * top_xy + 2;
3837 ref_cache[0 - 1 * 8] =
3839 ref_cache[2 - 1 * 8] =
3849 const int b8_xy = 4 * left_xy[
LTOP] + 1;
3857 ref_cache[-1 + 16] =
3858 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
f.
ref_index[list][b8_xy + 2 * 1]];
3866 ref_cache[-1 + 16] =
3884 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
3885 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
3886 AV_WN32A(&ref_cache[0 * 8], ref01);
3887 AV_WN32A(&ref_cache[1 * 8], ref01);
3888 AV_WN32A(&ref_cache[2 * 8], ref23);
3889 AV_WN32A(&ref_cache[3 * 8], ref23);
3894 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
3895 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
3896 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
3897 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
3907 const int mb_xy = h->
mb_xy;
3918 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
3923 if (left_mb_field_flag != curr_mb_field_flag)
3926 if (curr_mb_field_flag)
3929 if (left_mb_field_flag != curr_mb_field_flag)
3943 if (qp <= qp_thresh &&
3944 (left_xy[
LTOP] < 0 ||
3950 if ((left_xy[
LTOP] < 0 ||
3965 left_type[
LTOP] = left_type[
LBOT] = 0;
3970 left_type[
LTOP] = left_type[
LBOT] = 0;
3980 top_type, left_type, mb_xy, 0);
3983 top_type, left_type, mb_xy, 1);
3987 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
3988 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
3989 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
3990 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
3995 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
3998 if (left_type[
LTOP]) {
4000 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4001 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4002 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4003 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4010 nnz_cache[4 + 8 * 0] =
4011 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4012 nnz_cache[6 + 8 * 0] =
4013 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4016 nnz_cache[3 + 8 * 1] =
4017 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4020 nnz_cache[3 + 8 * 3] =
4021 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4025 nnz_cache[
scan8[0]] =
4026 nnz_cache[scan8[1]] =
4027 nnz_cache[scan8[2]] =
4028 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4030 nnz_cache[scan8[0 + 4]] =
4031 nnz_cache[scan8[1 + 4]] =
4032 nnz_cache[scan8[2 + 4]] =
4033 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4035 nnz_cache[scan8[0 + 8]] =
4036 nnz_cache[scan8[1 + 8]] =
4037 nnz_cache[scan8[2 + 8]] =
4038 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
4040 nnz_cache[scan8[0 + 12]] =
4041 nnz_cache[scan8[1 + 12]] =
4042 nnz_cache[scan8[2 + 12]] =
4043 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
4052 uint8_t *dest_y, *dest_cb, *dest_cr;
4053 int linesize, uvlinesize, mb_x, mb_y;
4060 for (mb_x = start_x; mb_x < end_x; mb_x++)
4061 for (mb_y = end_mb_y -
FRAME_MBAFF; mb_y <= end_mb_y; mb_y++) {
4075 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
4077 (mb_x << pixel_shift) * (8 <<
CHROMA444) +
4080 (mb_x << pixel_shift) * (8 <<
CHROMA444) +
4105 linesize, uvlinesize);
4108 dest_cr, linesize, uvlinesize);
4140 if ((top + height) >= pic_height)
4141 height += deblock_border;
4142 top -= deblock_border;
4145 if (top >= pic_height || (top + height) < 0)
4148 height =
FFMIN(height, pic_height - top);
4164 int endx,
int endy,
int status)
4166 if (CONFIG_ERROR_RESILIENCE) {
4177 int lf_x_start = h->
mb_x;
4223 if (h->
mb_x >= lf_x_start)
4231 "error while decoding MB %d %d, bytestream (%td)\n",
4241 h->
mb_x = lf_x_start = 0;
4256 if (h->
mb_x > lf_x_start)
4280 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
4288 h->
mb_x = lf_x_start = 0;
4324 if (h->
mb_x > lf_x_start)
4354 if (context_count == 1) {
4358 for (i = 1; i < context_count; i++) {
4360 if (CONFIG_ERROR_RESILIENCE) {
4367 NULL, context_count,
sizeof(
void *));
4375 if (CONFIG_ERROR_RESILIENCE) {
4376 for (i = 1; i < context_count; i++)
4385 int parse_extradata)
4393 int nals_needed = 0;
4396 int first_slice = 0;
4411 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
4413 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
4417 for (; pass <= 1; pass++) {
4420 next_avc = h->
is_avc ? 0 : buf_size;
4430 if (buf_index >= next_avc) {
4435 nalsize = (nalsize << 8) | buf[buf_index++];
4436 if (nalsize <= 0 || nalsize > buf_size - buf_index) {
4438 "AVC: nal size %d\n", nalsize);
4441 next_avc = buf_index + nalsize;
4444 for (; buf_index + 3 < next_avc; buf_index++)
4446 if (buf[buf_index] == 0 &&
4447 buf[buf_index + 1] == 0 &&
4448 buf[buf_index + 2] == 1)
4451 if (buf_index + 3 >= buf_size) {
4452 buf_index = buf_size;
4457 if (buf_index >= next_avc)
4464 &consumed, next_avc - buf_index);
4465 if (ptr ==
NULL || dst_length < 0) {
4469 i = buf_index + consumed;
4471 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
4472 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
4476 while(dst_length > 0 && ptr[dst_length - 1] == 0)
4478 bit_length = !dst_length ? 0
4485 if (h->
is_avc && (nalsize != consumed) && nalsize)
4487 "AVC: Consumed only %d bytes instead of %d\n",
4490 buf_index += consumed;
4501 nals_needed = nal_index;
4508 nals_needed = nal_index;
4531 if (parse_extradata) {
4550 "Invalid mix of idr and non-idr slices\n");
4598 if (CONFIG_H264_VDPAU_DECODER &&
4613 &buf[buf_index - consumed],
4616 }
else if (CONFIG_H264_VDPAU_DECODER &&
4618 static const uint8_t start_code[] = {
4621 sizeof(start_code));
4669 "SPS decoding failure, trying again with the complete NAL\n");
4671 av_assert0(next_avc - buf_index + consumed == nalsize);
4672 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
4675 8*(next_avc - buf_index + consumed - 1));
4705 else if (err == 1) {
4738 if (pos + 10 > buf_size)
4748 int buf_size = avpkt->
size;
4758 if (buf_size == 0) {
4788 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
4789 int cnt= buf[5]&0x1f;
4793 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
4802 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
4822 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
4843 assert(pict->
data[0] || !*got_frame);
4845 if (CONFIG_MPEGVIDEO) {
4940 #if CONFIG_H264_VDPAU_DECODER
4941 AVCodec ff_h264_vdpau_decoder = {
4942 .
name =
"h264_vdpau",
4951 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),