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 8,
112 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
113 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
114 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
115 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
116 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
117 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
118 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
119 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
120 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
121 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
122 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
123 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
124 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
125 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
126 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
127 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
140 0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
144 { 20, 18, 32, 19, 25, 24 },
145 { 22, 19, 35, 21, 28, 26 },
146 { 26, 23, 42, 24, 33, 31 },
147 { 28, 25, 45, 26, 35, 33 },
148 { 32, 28, 51, 30, 40, 38 },
149 { 36, 32, 58, 34, 46, 43 },
153 #if CONFIG_H264_DXVA2_HWACCEL
156 #if CONFIG_H264_VAAPI_HWACCEL
159 #if CONFIG_H264_VDA_HWACCEL
162 #if CONFIG_H264_VDPAU_HWACCEL
170 #if CONFIG_H264_DXVA2_HWACCEL
173 #if CONFIG_H264_VAAPI_HWACCEL
176 #if CONFIG_H264_VDA_HWACCEL
179 #if CONFIG_H264_VDPAU_HWACCEL
188 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
245 offset[2] = (y >> vshift) * src->
linesize[1];
269 for (i = 0; i < 2; i++) {
274 memset((
uint8_t*)pic + off, 0,
sizeof(*pic) - off);
310 for (i = 0; i < 2; i++) {
326 for (i = 0; i < 2; i++)
378 const int b4_stride = h->
mb_width * 4 + 1;
379 const int b4_array_size = b4_stride * h->
mb_height * 4;
441 for (i = 0; i < 2; i++) {
454 return (ret < 0) ? ret :
AVERROR(ENOMEM);
474 if (i == MAX_PICTURE_COUNT)
491 static const int8_t top[12] = {
494 static const int8_t left[12] = {
500 for (i = 0; i < 4; i++) {
504 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
514 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
515 for (i = 0; i < 4; i++)
520 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
543 "out of range intra chroma pred mode at %d %d\n",
552 "top block unavailable for requested intra mode at %d %d\n",
568 "left block unavailable for requested intra mode at %d %d\n",
578 int *dst_length,
int *consumed,
int length)
591 #define STARTCODE_TEST \
592 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
593 if (src[i + 2] != 3) { \
600 #if HAVE_FAST_UNALIGNED
601 #define FIND_FIRST_ZERO \
602 if (i > 0 && !src[i]) \
608 for (i = 0; i + 1 < length; i += 9) {
610 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
611 0x8000800080008080ULL))
618 for (i = 0; i + 1 < length; i += 5) {
620 (
AV_RN32A(src + i) - 0x01000101U)) &
629 for (i = 0; i + 1 < length; i += 2) {
632 if (i > 0 && src[i - 1] == 0)
638 if (i >= length - 1) {
639 *dst_length = length;
640 *consumed = length + 1;
655 while (si + 2 < length) {
657 if (src[si + 2] > 3) {
658 dst[di++] = src[si++];
659 dst[di++] = src[si++];
660 }
else if (src[si] == 0 && src[si + 1] == 0) {
661 if (src[si + 2] == 3) {
670 dst[di++] = src[si++];
673 dst[di++] = src[si++];
696 for (r = 1; r < 9; r++) {
705 int height,
int y_offset,
int list)
708 int filter_height_up = (raw_my & 3) ? 2 : 0;
709 int filter_height_down = (raw_my & 3) ? 3 : 0;
710 int full_my = (raw_my >> 2) + y_offset;
711 int top = full_my - filter_height_up;
712 int bottom = full_my + filter_height_down +
height;
714 return FFMAX(abs(top), bottom);
718 int height,
int y_offset,
int list0,
719 int list1,
int *nrefs)
735 if (refs[0][ref_n] < 0)
737 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
748 if (refs[1][ref_n] < 0)
750 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
762 const int mb_xy = h->
mb_xy;
765 int nrefs[2] = { 0 };
768 memset(refs, -1,
sizeof(refs));
788 for (i = 0; i < 4; i++) {
791 int y_offset = (i & 2) << 2;
795 IS_DIR(sub_mb_type, 0, 0),
796 IS_DIR(sub_mb_type, 0, 1),
800 IS_DIR(sub_mb_type, 0, 0),
801 IS_DIR(sub_mb_type, 0, 1),
804 IS_DIR(sub_mb_type, 0, 0),
805 IS_DIR(sub_mb_type, 0, 1),
809 IS_DIR(sub_mb_type, 0, 0),
810 IS_DIR(sub_mb_type, 0, 1),
813 IS_DIR(sub_mb_type, 0, 0),
814 IS_DIR(sub_mb_type, 0, 1),
819 for (j = 0; j < 4; j++) {
820 int sub_y_offset = y_offset + 2 * (j & 2);
822 IS_DIR(sub_mb_type, 0, 0),
823 IS_DIR(sub_mb_type, 0, 1),
830 for (list = h->
list_count - 1; list >= 0; list--)
831 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
832 int row = refs[list][ref];
837 int pic_height = 16 * h->
mb_height >> ref_field_picture;
844 FFMIN((row >> 1) - !(row & 1),
848 FFMIN((row >> 1), pic_height - 1),
852 FFMIN(row * 2 + ref_field,
857 FFMIN(row, pic_height - 1),
861 FFMIN(row, pic_height - 1),
873 int src_x_offset,
int src_y_offset,
876 int pixel_shift,
int chroma_idc)
878 const int mx = h->
mv_cache[list][
scan8[n]][0] + src_x_offset * 8;
880 const int luma_xy = (mx & 3) + ((my & 3) << 2);
881 ptrdiff_t offset = ((mx >> 2) << pixel_shift) + (my >> 2) * h->
mb_linesize;
885 int extra_height = 0;
887 const int full_mx = mx >> 2;
888 const int full_my = my >> 2;
889 const int pic_width = 16 * h->
mb_width;
898 if (full_mx < 0 - extra_width ||
899 full_my < 0 - extra_height ||
900 full_mx + 16 > pic_width + extra_width ||
901 full_my + 16 > pic_height + extra_height) {
905 16 + 5, 16 + 5 , full_mx - 2,
906 full_my - 2, pic_width, pic_height);
918 if (chroma_idc == 3 ) {
919 src_cb = pic->
f.
data[1] + offset;
925 full_mx - 2, full_my - 2,
926 pic_width, pic_height);
933 src_cr = pic->
f.
data[2] + offset;
939 full_mx - 2, full_my - 2,
940 pic_width, pic_height);
949 ysh = 3 - (chroma_idc == 2 );
950 if (chroma_idc == 1 &&
MB_FIELD(h)) {
953 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
956 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
958 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
964 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
965 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
969 height >> (chroma_idc == 1 ),
970 mx & 7, (my << (chroma_idc == 2 )) & 7);
975 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
976 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
979 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
980 mx & 7, (my << (chroma_idc == 2 )) & 7);
987 int x_offset,
int y_offset,
992 int list0,
int list1,
993 int pixel_shift,
int chroma_idc)
998 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
999 if (chroma_idc == 3 ) {
1000 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1001 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1002 }
else if (chroma_idc == 2 ) {
1003 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1004 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1006 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1007 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1009 x_offset += 8 * h->
mb_x;
1015 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1016 qpix_op, chroma_op, pixel_shift, chroma_idc);
1019 chroma_op = chroma_avg;
1025 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1026 qpix_op, chroma_op, pixel_shift, chroma_idc);
1034 int x_offset,
int y_offset,
1041 int list0,
int list1,
1042 int pixel_shift,
int chroma_idc)
1046 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1047 if (chroma_idc == 3 ) {
1049 chroma_weight_avg = luma_weight_avg;
1050 chroma_weight_op = luma_weight_op;
1051 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1052 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1053 }
else if (chroma_idc == 2 ) {
1055 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1056 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1058 chroma_height = height >> 1;
1059 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1060 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1062 x_offset += 8 * h->
mb_x;
1065 if (list0 && list1) {
1075 dest_y, dest_cb, dest_cr,
1076 x_offset, y_offset, qpix_put, chroma_put,
1077 pixel_shift, chroma_idc);
1079 tmp_y, tmp_cb, tmp_cr,
1080 x_offset, y_offset, qpix_put, chroma_put,
1081 pixel_shift, chroma_idc);
1085 int weight1 = 64 - weight0;
1087 height, 5, weight0, weight1, 0);
1089 chroma_height, 5, weight0, weight1, 0);
1091 chroma_height, 5, weight0, weight1, 0);
1093 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
1099 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
1105 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
1113 int list = list1 ? 1 : 0;
1116 mc_dir_part(h, ref, n, square, height, delta, list,
1117 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1118 qpix_put, chroma_put, pixel_shift, chroma_idc);
1138 int pixel_shift,
int chroma_idc)
1147 int off = (mx << pixel_shift) +
1149 (64 << pixel_shift);
1151 if (chroma_idc == 3 ) {
1155 off = ((mx >> 1) << pixel_shift) +
1157 (64 << pixel_shift);
1187 if (free_rbsp && h->
DPB) {
1191 }
else if (h->
DPB) {
1230 for (i = 0; i < 6; i++) {
1232 for (j = 0; j < i; j++)
1241 for (q = 0; q < max_qp + 1; q++) {
1242 int shift =
div6[q];
1244 for (x = 0; x < 64; x++)
1256 for (i = 0; i < 6; i++) {
1258 for (j = 0; j < i; j++)
1267 for (q = 0; q < max_qp + 1; q++) {
1268 int shift =
div6[q] + 2;
1270 for (x = 0; x < 16; x++)
1285 for (i = 0; i < 6; i++)
1286 for (x = 0; x < 16; x++)
1289 for (i = 0; i < 6; i++)
1290 for (x = 0; x < 64; x++)
1302 row_mb_num * 8 *
sizeof(
uint8_t), fail)
1304 big_mb_num * 48 *
sizeof(
uint8_t), fail)
1308 big_mb_num *
sizeof(uint16_t), fail)
1310 big_mb_num *
sizeof(
uint8_t), fail)
1312 16 * row_mb_num *
sizeof(
uint8_t), fail);
1314 16 * row_mb_num *
sizeof(
uint8_t), fail);
1316 4 * big_mb_num *
sizeof(
uint8_t), fail);
1318 big_mb_num *
sizeof(
uint8_t), fail)
1325 big_mb_num *
sizeof(uint32_t), fail);
1327 big_mb_num *
sizeof(uint32_t), fail);
1329 for (x = 0; x < h->
mb_width; x++) {
1331 const int b_xy = 4 * x + 4 * y * h->
b_stride;
1392 int yc_size = y_size + 2 * c_size;
1431 mb_array_size *
sizeof(
uint8_t), fail);
1445 for (i = 0; i < yc_size; i++)
1456 int parse_extradata);
1464 int i, cnt, nalsize;
1478 cnt = *(p + 5) & 0x1f;
1480 for (i = 0; i < cnt; i++) {
1487 "Decoding sps %d from avcC failed\n", i);
1494 for (i = 0; i < cnt; i++) {
1501 "Decoding pps %d from avcC failed\n", i);
1594 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1595 #undef REBASE_PICTURE
1596 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
1597 ((pic && pic >= old_ctx->DPB && \
1598 pic < old_ctx->DPB + MAX_PICTURE_COUNT) ? \
1599 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
1607 for (i = 0; i < count; i++) {
1608 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1620 for (i = 0; i < count; i++) {
1621 if (to[i] && !from[i]) {
1623 }
else if (from[i] && !to[i]) {
1630 memcpy(to[i], from[i], size);
1655 #define copy_fields(to, from, start_field, end_field) \
1656 memcpy(&to->start_field, &from->start_field, \
1657 (char *)&to->end_field - (char *)&to->start_field)
1668 int context_reinitialized = 0;
1671 if (dst == src || !h1->context_initialized)
1675 (h->
width != h1->width ||
1676 h->
height != h1->height ||
1690 h->
width = h1->width;
1702 context_reinitialized = 1;
1720 memcpy(h, h1,
sizeof(*h1));
1723 memset(&h->
er, 0,
sizeof(h->
er));
1724 memset(&h->
me, 0,
sizeof(h->
me));
1725 memset(&h->
mb, 0,
sizeof(h->
mb));
1752 for (i = 0; i < 2; i++) {
1777 if (h1->DPB[i].f.buf[0] &&
1784 if (h1->cur_pic.f.buf[0]) {
1805 (
void **)h1->sps_buffers,
1810 (
void **)h1->pps_buffers,
1817 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1819 for (i = 0; i < 6; i++)
1821 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1823 for (i = 0; i < 6; i++)
1825 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1842 if (context_reinitialized)
1904 for (i = 0; i < 16; i++) {
1908 for (i = 0; i < 16; i++) {
1959 int i, pics, out_of_order, out_idx;
1960 int invalid = 0, cnt = 0;
2123 invalid += out->
poc == INT_MIN;
2126 cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {
2135 invalid = MAX_DELAYED_PIC_COUNT;
2139 for (i = 1; i < MAX_DELAYED_PIC_COUNT &&
2158 if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
2178 sizeof(*h->
last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
2216 int linesize,
int uvlinesize,
2226 src_cb -= uvlinesize;
2227 src_cr -= uvlinesize;
2233 AV_COPY128(top_border, src_y + 15 * linesize);
2235 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2239 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2240 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2241 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2242 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2244 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2245 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2247 }
else if (chroma422) {
2249 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2250 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2252 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2253 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2257 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2258 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2260 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2261 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2275 AV_COPY128(top_border, src_y + 16 * linesize);
2277 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2282 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2283 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2284 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2285 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2287 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2288 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2290 }
else if (chroma422) {
2292 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2293 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2295 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2296 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2300 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2301 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2303 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2304 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2312 int linesize,
int uvlinesize,
2313 int xchg,
int chroma444,
2314 int simple,
int pixel_shift)
2316 int deblock_topleft;
2335 deblock_topleft = (h->
mb_x > 0);
2339 src_y -= linesize + 1 + pixel_shift;
2340 src_cb -= uvlinesize + 1 + pixel_shift;
2341 src_cr -= uvlinesize + 1 + pixel_shift;
2346 #define XCHG(a, b, xchg) \
2347 if (pixel_shift) { \
2349 AV_SWAP64(b + 0, a + 0); \
2350 AV_SWAP64(b + 8, a + 8); \
2360 if (deblock_topleft) {
2361 XCHG(top_border_m1 + (8 << pixel_shift),
2362 src_y - (7 << pixel_shift), 1);
2364 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2365 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2368 src_y + (17 << pixel_shift), 1);
2374 if (deblock_topleft) {
2375 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2376 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2378 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2379 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2380 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2381 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2383 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2384 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2389 if (deblock_topleft) {
2390 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2391 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2393 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2394 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2403 if (high_bit_depth) {
2410 int index,
int value)
2412 if (high_bit_depth) {
2419 int mb_type,
int is_h264,
2421 int transform_bypass,
2431 block_offset += 16 * p;
2434 if (transform_bypass) {
2441 for (i = 0; i < 16; i += 4) {
2442 uint8_t *
const ptr = dest_y + block_offset[i];
2445 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2451 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2452 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2454 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2459 if (transform_bypass) {
2466 for (i = 0; i < 16; i++) {
2467 uint8_t *
const ptr = dest_y + block_offset[i];
2471 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2478 assert(h->
mb_y || linesize <= block_offset[i]);
2479 if (!topright_avail) {
2481 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2482 topright = (
uint8_t *)&tr_high;
2484 tr = ptr[3 - linesize] * 0x01010101u;
2488 topright = ptr + (4 << pixel_shift) - linesize;
2492 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2496 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2497 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2499 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2510 if (!transform_bypass)
2515 static const uint8_t dc_mapping[16] = {
2516 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2517 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2518 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2519 10 * 16, 11 * 16, 14 * 16, 15 * 16
2521 for (i = 0; i < 16; i++)
2523 pixel_shift, dc_mapping[i],
2535 int is_h264,
int simple,
2536 int transform_bypass,
2544 block_offset += 16 * p;
2548 if (transform_bypass) {
2553 h->
mb + (p * 256 << pixel_shift),
2556 for (i = 0; i < 16; i++)
2560 h->
mb + (i * 16 + p * 256 << pixel_shift),
2565 h->
mb + (p * 256 << pixel_shift),
2569 }
else if (h->
cbp & 15) {
2570 if (transform_bypass) {
2571 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2574 for (i = 0; i < 16; i += di)
2577 h->
mb + (i * 16 + p * 256 << pixel_shift),
2582 h->
mb + (p * 256 << pixel_shift),
2587 h->
mb + (p * 256 << pixel_shift),
2593 for (i = 0; i < 16; i++)
2596 uint8_t *
const ptr = dest_y + block_offset[i];
2618 const int mb_xy = h->
mb_xy;
2625 hl_decode_mb_444_complex(h);
2627 hl_decode_mb_444_simple_8(h);
2628 }
else if (is_complex) {
2629 hl_decode_mb_complex(h);
2631 hl_decode_mb_simple_16(h);
2633 hl_decode_mb_simple_8(h);
2639 int luma_def, chroma_def;
2649 for (list = 0; list < 2; list++) {
2652 for (i = 0; i < h->
ref_count[list]; i++) {
2653 int luma_weight_flag, chroma_weight_flag;
2656 if (luma_weight_flag) {
2671 if (chroma_weight_flag) {
2673 for (j = 0; j < 2; j++) {
2684 for (j = 0; j < 2; j++) {
2705 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2707 for (i = 0; i < 2; i++) {
2739 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2741 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2745 int td = av_clip(poc1 - poc0, -128, 127);
2747 int tb = av_clip(cur_poc - poc0, -128, 127);
2748 int tx = (16384 + (
FFABS(td) >> 1)) / td;
2749 int dist_scale_factor = (tb * tx + 32) >> 8;
2750 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2751 w = 64 - dist_scale_factor;
2855 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2866 expected_delta_per_poc_cycle = 0;
2871 if (abs_frame_num > 0) {
2875 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2876 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2884 field_poc[0] = expectedpoc + h->
delta_poc[0];
2900 pic_field_poc[0] = field_poc[0];
2902 pic_field_poc[1] = field_poc[1];
2903 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
2914 for (i = 0; i < 16; i++) {
2915 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2920 for (i = 0; i < 64; i++) {
2921 #define T(x) (x >> 3) | ((x & 7) << 3)
2969 "hardware accelerator failed to decode picture\n");
3059 "Reenabling low delay requires a codec flush.\n");
3167 if (width <= 0 || height <= 0) {
3230 " reducing to %d\n", nb_slices, max_slices);
3231 nb_slices = max_slices;
3293 int ref_count[2], list_count;
3294 int num_ref_idx_active_override_flag, max_refs;
3303 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3305 if (num_ref_idx_active_override_flag) {
3307 if (ref_count[0] < 1)
3311 if (ref_count[1] < 1)
3322 ref_count[0] = ref_count[1] = 0;
3327 if (ref_count[0] > max_refs || ref_count[1] > max_refs) {
3357 unsigned int first_mb_in_slice;
3358 unsigned int pps_id;
3360 unsigned int slice_type, tmp, i, j;
3361 int default_ref_list_done = 0;
3362 int last_pic_structure, last_pic_droppable;
3363 int needs_reinit = 0;
3364 int field_pic_flag, bottom_field_flag;
3371 if (first_mb_in_slice == 0) {
3387 if (slice_type > 9) {
3389 "slice type %d too large at %d %d\n",
3393 if (slice_type > 4) {
3402 default_ref_list_done = 1;
3423 "non-existing PPS %u referenced\n",
3431 "non-existing SPS %u referenced\n",
3510 "h264_slice_header_init() failed\n");
3517 "Cannot (re-)initialize context during parallel decoding.\n");
3527 "h264_slice_header_init() failed\n");
3548 if (field_pic_flag) {
3562 "Changing field mode (%d -> %d) between slices is not allowed\n",
3569 "unset cur_pic_ptr on slice %d\n",
3580 if (unwrap_prev_frame_num > h->
frame_num)
3581 unwrap_prev_frame_num -= max_frame_num;
3585 if (unwrap_prev_frame_num < 0)
3586 unwrap_prev_frame_num += max_frame_num;
3606 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3616 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3627 "Invalid field mode combination %d/%d\n",
3632 }
else if (last_pic_droppable != h->
droppable) {
3634 "Found reference and non-reference fields in the same frame, which");
3734 first_mb_in_slice >= h->
mb_num) {
3779 default_ref_list_done = 0;
3781 if (!default_ref_list_done)
3801 for (i = 0; i < 2; i++) {
3865 "deblocking_filter_idc %u out of range\n", tmp);
3880 "deblocking filter parameters %d %d out of range\n",
3905 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3910 "Deblocking switched inside frame.\n");
3926 "Too many slices, increase MAX_SLICES and recompile\n");
3929 for (j = 0; j < 2; j++) {
3932 for (i = 0; i < 16; i++) {
3934 if (j < h->list_count && i < h->ref_count[j] &&
3953 for (i = 0; i < 16; i++)
3956 ref2frm[18 + 1] = -1;
3957 for (i = 16; i < 48; i++)
3958 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3964 "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",
4005 int mb_type,
int top_xy,
4008 int left_type[LEFT_MBS],
4009 int mb_xy,
int list)
4016 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
4017 const int b8_xy = 4 * top_xy + 2;
4020 ref_cache[0 - 1 * 8] =
4021 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
4022 ref_cache[2 - 1 * 8] =
4023 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
4032 const int b8_xy = 4 * left_xy[
LTOP] + 1;
4039 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
4040 ref_cache[-1 + 16] =
4041 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
4049 ref_cache[-1 + 16] =
4067 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
4068 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
4069 AV_WN32A(&ref_cache[0 * 8], ref01);
4070 AV_WN32A(&ref_cache[1 * 8], ref01);
4071 AV_WN32A(&ref_cache[2 * 8], ref23);
4072 AV_WN32A(&ref_cache[3 * 8], ref23);
4077 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
4078 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
4079 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
4080 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
4090 const int mb_xy = h->
mb_xy;
4101 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
4106 if (left_mb_field_flag != curr_mb_field_flag)
4109 if (curr_mb_field_flag)
4112 if (left_mb_field_flag != curr_mb_field_flag)
4126 if (qp <= qp_thresh &&
4127 (left_xy[
LTOP] < 0 ||
4133 if ((left_xy[
LTOP] < 0 ||
4148 left_type[
LTOP] = left_type[
LBOT] = 0;
4153 left_type[
LTOP] = left_type[
LBOT] = 0;
4163 top_type, left_type, mb_xy, 0);
4166 top_type, left_type, mb_xy, 1);
4170 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
4171 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
4172 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
4173 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
4178 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
4181 if (left_type[
LTOP]) {
4183 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4184 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4185 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4186 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4193 nnz_cache[4 + 8 * 0] =
4194 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4195 nnz_cache[6 + 8 * 0] =
4196 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4199 nnz_cache[3 + 8 * 1] =
4200 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4203 nnz_cache[3 + 8 * 3] =
4204 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4208 nnz_cache[
scan8[0]] =
4209 nnz_cache[scan8[1]] =
4210 nnz_cache[scan8[2]] =
4211 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4213 nnz_cache[scan8[0 + 4]] =
4214 nnz_cache[scan8[1 + 4]] =
4215 nnz_cache[scan8[2 + 4]] =
4216 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4218 nnz_cache[scan8[0 + 8]] =
4219 nnz_cache[scan8[1 + 8]] =
4220 nnz_cache[scan8[2 + 8]] =
4221 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
4223 nnz_cache[scan8[0 + 12]] =
4224 nnz_cache[scan8[1 + 12]] =
4225 nnz_cache[scan8[2 + 12]] =
4226 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
4235 uint8_t *dest_y, *dest_cb, *dest_cr;
4236 int linesize, uvlinesize, mb_x, mb_y;
4243 for (mb_x = start_x; mb_x < end_x; mb_x++)
4244 for (mb_y = end_mb_y -
FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
4258 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
4260 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4263 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4288 linesize, uvlinesize);
4291 dest_cr, linesize, uvlinesize);
4323 if ((top + height) >= pic_height)
4324 height += deblock_border;
4325 top -= deblock_border;
4328 if (top >= pic_height || (top + height) < 0)
4331 height =
FFMIN(height, pic_height - top);
4347 int endx,
int endy,
int status)
4349 #if CONFIG_ERROR_RESILIENCE
4360 int lf_x_start = h->
mb_x;
4404 if (h->
mb_x >= lf_x_start)
4410 "error while decoding MB %d %d, bytestream %td\n",
4420 h->
mb_x = lf_x_start = 0;
4435 if (h->
mb_x > lf_x_start)
4459 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
4467 h->
mb_x = lf_x_start = 0;
4503 if (h->
mb_x > lf_x_start)
4532 "Input contains more MB rows than the frame height.\n");
4538 if (context_count == 1) {
4541 for (i = 1; i < context_count; i++) {
4547 NULL, context_count,
sizeof(
void *));
4555 for (i = 1; i < context_count; i++)
4563 int parse_extradata)
4568 unsigned context_count;
4571 int nals_needed = 0;
4583 for (; pass <= 1; pass++) {
4586 next_avc = h->
is_avc ? 0 : buf_size;
4596 if (buf_index >= next_avc) {
4601 nalsize = (nalsize << 8) | buf[buf_index++];
4602 if (nalsize <= 0 || nalsize > buf_size - buf_index) {
4604 "AVC: nal size %d\n", nalsize);
4607 next_avc = buf_index + nalsize;
4610 for (; buf_index + 3 < next_avc; buf_index++)
4612 if (buf[buf_index] == 0 &&
4613 buf[buf_index + 1] == 0 &&
4614 buf[buf_index + 2] == 1)
4617 if (buf_index + 3 >= buf_size) {
4618 buf_index = buf_size;
4623 if (buf_index >= next_avc)
4630 &consumed, next_avc - buf_index);
4631 if (ptr ==
NULL || dst_length < 0) {
4635 i = buf_index + consumed;
4637 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
4638 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
4642 while (dst_length > 0 && ptr[dst_length - 1] == 0)
4644 bit_length = !dst_length ? 0
4650 "NAL %d at %d/%d length %d\n",
4653 if (h->
is_avc && (nalsize != consumed) && nalsize)
4655 "AVC: Consumed only %d bytes instead of %d\n",
4658 buf_index += consumed;
4669 nals_needed = nal_index;
4676 nals_needed = nal_index;
4697 "Ignoring NAL unit %d during extradata parsing\n",
4706 "Invalid mix of idr and non-idr slices\n");
4759 &buf[buf_index - consumed],
4770 "Decoding in chunks is not supported for "
4771 "partitioned slices.\n");
4816 if (ret < 0 && h->is_avc && (nalsize != consumed) && nalsize) {
4818 "SPS decoding failure, trying again with the complete NAL\n");
4855 }
else if (err == 1) {
4877 return (ret < 0) ? ret : buf_index;
4887 if (pos + 10 > buf_size)
4903 for (i = 0; i < 3; i++) {
4908 dst->
data[i] += off;
4917 int buf_size = avpkt->
size;
4930 if (buf_size == 0) {
4998 assert(pict->
buf[0] || !*got_frame);