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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);
1650 #define copy_fields(to, from, start_field, end_field) \
1651 memcpy(&to->start_field, &from->start_field, \
1652 (char *)&to->end_field - (char *)&to->start_field)
1663 int context_reinitialized = 0;
1666 if (dst == src || !h1->context_initialized)
1670 (h->
width != h1->width ||
1671 h->
height != h1->height ||
1685 h->
width = h1->width;
1697 context_reinitialized = 1;
1715 memcpy(h, h1,
sizeof(*h1));
1718 memset(&h->
er, 0,
sizeof(h->
er));
1719 memset(&h->
me, 0,
sizeof(h->
me));
1720 memset(&h->
mb, 0,
sizeof(h->
mb));
1747 for (i = 0; i < 2; i++) {
1772 if (h1->DPB[i].f.buf[0] &&
1797 (
void **)h1->sps_buffers,
1802 (
void **)h1->pps_buffers,
1809 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1811 for (i = 0; i < 6; i++)
1813 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1815 for (i = 0; i < 6; i++)
1817 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1834 if (context_reinitialized)
1896 for (i = 0; i < 16; i++) {
1900 for (i = 0; i < 16; i++) {
1951 int i, pics, out_of_order, out_idx;
1952 int invalid = 0, cnt = 0;
2115 invalid += out->
poc == INT_MIN;
2118 cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {
2127 invalid = MAX_DELAYED_PIC_COUNT;
2131 for (i = 1; i < MAX_DELAYED_PIC_COUNT &&
2150 if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
2170 sizeof(*h->
last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
2208 int linesize,
int uvlinesize,
2218 src_cb -= uvlinesize;
2219 src_cr -= uvlinesize;
2225 AV_COPY128(top_border, src_y + 15 * linesize);
2227 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2231 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2232 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2233 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2234 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2236 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2237 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2239 }
else if (chroma422) {
2241 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2242 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2244 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2245 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2249 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2250 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2252 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2253 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2267 AV_COPY128(top_border, src_y + 16 * linesize);
2269 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2274 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2275 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2276 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2277 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2279 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2280 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2282 }
else if (chroma422) {
2284 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2285 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2287 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2288 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2292 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2293 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2295 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2296 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2304 int linesize,
int uvlinesize,
2305 int xchg,
int chroma444,
2306 int simple,
int pixel_shift)
2308 int deblock_topleft;
2327 deblock_topleft = (h->
mb_x > 0);
2331 src_y -= linesize + 1 + pixel_shift;
2332 src_cb -= uvlinesize + 1 + pixel_shift;
2333 src_cr -= uvlinesize + 1 + pixel_shift;
2338 #define XCHG(a, b, xchg) \
2339 if (pixel_shift) { \
2341 AV_SWAP64(b + 0, a + 0); \
2342 AV_SWAP64(b + 8, a + 8); \
2352 if (deblock_topleft) {
2353 XCHG(top_border_m1 + (8 << pixel_shift),
2354 src_y - (7 << pixel_shift), 1);
2356 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2357 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2360 src_y + (17 << pixel_shift), 1);
2366 if (deblock_topleft) {
2367 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2368 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2370 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2371 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2372 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2373 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2375 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2376 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2381 if (deblock_topleft) {
2382 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2383 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2385 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2386 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2395 if (high_bit_depth) {
2402 int index,
int value)
2404 if (high_bit_depth) {
2411 int mb_type,
int is_h264,
2413 int transform_bypass,
2423 block_offset += 16 * p;
2426 if (transform_bypass) {
2433 for (i = 0; i < 16; i += 4) {
2434 uint8_t *
const ptr = dest_y + block_offset[i];
2437 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2443 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2444 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2446 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2451 if (transform_bypass) {
2458 for (i = 0; i < 16; i++) {
2459 uint8_t *
const ptr = dest_y + block_offset[i];
2463 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2470 assert(h->
mb_y || linesize <= block_offset[i]);
2471 if (!topright_avail) {
2473 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2474 topright = (
uint8_t *)&tr_high;
2476 tr = ptr[3 - linesize] * 0x01010101u;
2480 topright = ptr + (4 << pixel_shift) - linesize;
2484 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2488 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2489 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2491 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2502 if (!transform_bypass)
2507 static const uint8_t dc_mapping[16] = {
2508 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2509 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2510 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2511 10 * 16, 11 * 16, 14 * 16, 15 * 16
2513 for (i = 0; i < 16; i++)
2515 pixel_shift, dc_mapping[i],
2527 int is_h264,
int simple,
2528 int transform_bypass,
2536 block_offset += 16 * p;
2540 if (transform_bypass) {
2545 h->
mb + (p * 256 << pixel_shift),
2548 for (i = 0; i < 16; i++)
2552 h->
mb + (i * 16 + p * 256 << pixel_shift),
2557 h->
mb + (p * 256 << pixel_shift),
2561 }
else if (h->
cbp & 15) {
2562 if (transform_bypass) {
2563 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2566 for (i = 0; i < 16; i += di)
2569 h->
mb + (i * 16 + p * 256 << pixel_shift),
2574 h->
mb + (p * 256 << pixel_shift),
2579 h->
mb + (p * 256 << pixel_shift),
2585 for (i = 0; i < 16; i++)
2588 uint8_t *
const ptr = dest_y + block_offset[i];
2610 const int mb_xy = h->
mb_xy;
2617 hl_decode_mb_444_complex(h);
2619 hl_decode_mb_444_simple_8(h);
2620 }
else if (is_complex) {
2621 hl_decode_mb_complex(h);
2623 hl_decode_mb_simple_16(h);
2625 hl_decode_mb_simple_8(h);
2631 int luma_def, chroma_def;
2641 for (list = 0; list < 2; list++) {
2644 for (i = 0; i < h->
ref_count[list]; i++) {
2645 int luma_weight_flag, chroma_weight_flag;
2648 if (luma_weight_flag) {
2663 if (chroma_weight_flag) {
2665 for (j = 0; j < 2; j++) {
2676 for (j = 0; j < 2; j++) {
2697 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2699 for (i = 0; i < 2; i++) {
2731 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2733 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2737 int td = av_clip(poc1 - poc0, -128, 127);
2739 int tb = av_clip(cur_poc - poc0, -128, 127);
2740 int tx = (16384 + (
FFABS(td) >> 1)) / td;
2741 int dist_scale_factor = (tb * tx + 32) >> 8;
2742 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2743 w = 64 - dist_scale_factor;
2847 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2858 expected_delta_per_poc_cycle = 0;
2863 if (abs_frame_num > 0) {
2867 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2868 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2876 field_poc[0] = expectedpoc + h->
delta_poc[0];
2892 pic_field_poc[0] = field_poc[0];
2894 pic_field_poc[1] = field_poc[1];
2895 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
2906 for (i = 0; i < 16; i++) {
2907 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2912 for (i = 0; i < 64; i++) {
2913 #define T(x) (x >> 3) | ((x & 7) << 3)
2961 "hardware accelerator failed to decode picture\n");
3051 "Reenabling low delay requires a codec flush.\n");
3148 if (width <= 0 || height <= 0) {
3211 " reducing to %d\n", nb_slices, max_slices);
3212 nb_slices = max_slices;
3274 int ref_count[2], list_count;
3275 int num_ref_idx_active_override_flag, max_refs;
3284 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3286 if (num_ref_idx_active_override_flag) {
3288 if (ref_count[0] < 1)
3292 if (ref_count[1] < 1)
3303 ref_count[0] = ref_count[1] = 0;
3308 if (ref_count[0] > max_refs || ref_count[1] > max_refs) {
3338 unsigned int first_mb_in_slice;
3339 unsigned int pps_id;
3341 unsigned int slice_type, tmp, i, j;
3342 int default_ref_list_done = 0;
3343 int last_pic_structure, last_pic_droppable;
3344 int needs_reinit = 0;
3345 int field_pic_flag, bottom_field_flag;
3352 if (first_mb_in_slice == 0) {
3368 if (slice_type > 9) {
3370 "slice type %d too large at %d %d\n",
3374 if (slice_type > 4) {
3383 default_ref_list_done = 1;
3404 "non-existing PPS %u referenced\n",
3412 "non-existing SPS %u referenced\n",
3490 "h264_slice_header_init() failed\n");
3497 "Cannot (re-)initialize context during parallel decoding.\n");
3507 "h264_slice_header_init() failed\n");
3528 if (field_pic_flag) {
3542 "Changing field mode (%d -> %d) between slices is not allowed\n",
3549 "unset cur_pic_ptr on slice %d\n",
3560 if (unwrap_prev_frame_num > h->
frame_num)
3561 unwrap_prev_frame_num -= max_frame_num;
3565 if (unwrap_prev_frame_num < 0)
3566 unwrap_prev_frame_num += max_frame_num;
3586 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3596 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
3607 "Invalid field mode combination %d/%d\n",
3612 }
else if (last_pic_droppable != h->
droppable) {
3614 "Found reference and non-reference fields in the same frame, which");
3714 first_mb_in_slice >= h->
mb_num) {
3759 default_ref_list_done = 0;
3761 if (!default_ref_list_done)
3781 for (i = 0; i < 2; i++) {
3845 "deblocking_filter_idc %u out of range\n", tmp);
3860 "deblocking filter parameters %d %d out of range\n",
3885 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3890 "Deblocking switched inside frame.\n");
3906 "Too many slices, increase MAX_SLICES and recompile\n");
3909 for (j = 0; j < 2; j++) {
3912 for (i = 0; i < 16; i++) {
3914 if (j < h->list_count && i < h->ref_count[j] &&
3933 for (i = 0; i < 16; i++)
3936 ref2frm[18 + 1] = -1;
3937 for (i = 16; i < 48; i++)
3938 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3944 "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",
3985 int mb_type,
int top_xy,
3988 int left_type[LEFT_MBS],
3989 int mb_xy,
int list)
3996 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
3997 const int b8_xy = 4 * top_xy + 2;
4000 ref_cache[0 - 1 * 8] =
4001 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
4002 ref_cache[2 - 1 * 8] =
4003 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
4012 const int b8_xy = 4 * left_xy[
LTOP] + 1;
4019 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
4020 ref_cache[-1 + 16] =
4021 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
4029 ref_cache[-1 + 16] =
4047 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
4048 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
4049 AV_WN32A(&ref_cache[0 * 8], ref01);
4050 AV_WN32A(&ref_cache[1 * 8], ref01);
4051 AV_WN32A(&ref_cache[2 * 8], ref23);
4052 AV_WN32A(&ref_cache[3 * 8], ref23);
4057 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
4058 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
4059 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
4060 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
4070 const int mb_xy = h->
mb_xy;
4081 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
4086 if (left_mb_field_flag != curr_mb_field_flag)
4089 if (curr_mb_field_flag)
4092 if (left_mb_field_flag != curr_mb_field_flag)
4106 if (qp <= qp_thresh &&
4107 (left_xy[
LTOP] < 0 ||
4113 if ((left_xy[
LTOP] < 0 ||
4128 left_type[
LTOP] = left_type[
LBOT] = 0;
4133 left_type[
LTOP] = left_type[
LBOT] = 0;
4143 top_type, left_type, mb_xy, 0);
4146 top_type, left_type, mb_xy, 1);
4150 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
4151 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
4152 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
4153 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
4158 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
4161 if (left_type[
LTOP]) {
4163 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4164 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4165 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4166 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4173 nnz_cache[4 + 8 * 0] =
4174 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4175 nnz_cache[6 + 8 * 0] =
4176 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4179 nnz_cache[3 + 8 * 1] =
4180 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4183 nnz_cache[3 + 8 * 3] =
4184 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4188 nnz_cache[
scan8[0]] =
4189 nnz_cache[scan8[1]] =
4190 nnz_cache[scan8[2]] =
4191 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4193 nnz_cache[scan8[0 + 4]] =
4194 nnz_cache[scan8[1 + 4]] =
4195 nnz_cache[scan8[2 + 4]] =
4196 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4198 nnz_cache[scan8[0 + 8]] =
4199 nnz_cache[scan8[1 + 8]] =
4200 nnz_cache[scan8[2 + 8]] =
4201 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
4203 nnz_cache[scan8[0 + 12]] =
4204 nnz_cache[scan8[1 + 12]] =
4205 nnz_cache[scan8[2 + 12]] =
4206 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
4215 uint8_t *dest_y, *dest_cb, *dest_cr;
4216 int linesize, uvlinesize, mb_x, mb_y;
4223 for (mb_x = start_x; mb_x < end_x; mb_x++)
4224 for (mb_y = end_mb_y -
FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
4238 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
4240 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4243 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4268 linesize, uvlinesize);
4271 dest_cr, linesize, uvlinesize);
4303 if ((top + height) >= pic_height)
4304 height += deblock_border;
4305 top -= deblock_border;
4308 if (top >= pic_height || (top + height) < 0)
4311 height =
FFMIN(height, pic_height - top);
4327 int endx,
int endy,
int status)
4329 #if CONFIG_ERROR_RESILIENCE
4340 int lf_x_start = h->
mb_x;
4384 if (h->
mb_x >= lf_x_start)
4390 "error while decoding MB %d %d, bytestream %td\n",
4400 h->
mb_x = lf_x_start = 0;
4415 if (h->
mb_x > lf_x_start)
4439 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
4447 h->
mb_x = lf_x_start = 0;
4483 if (h->
mb_x > lf_x_start)
4512 "Input contains more MB rows than the frame height.\n");
4518 if (context_count == 1) {
4521 for (i = 1; i < context_count; i++) {
4527 NULL, context_count,
sizeof(
void *));
4535 for (i = 1; i < context_count; i++)
4543 int parse_extradata)
4548 unsigned context_count;
4551 int nals_needed = 0;
4563 for (; pass <= 1; pass++) {
4566 next_avc = h->
is_avc ? 0 : buf_size;
4576 if (buf_index >= next_avc) {
4581 nalsize = (nalsize << 8) | buf[buf_index++];
4582 if (nalsize <= 0 || nalsize > buf_size - buf_index) {
4584 "AVC: nal size %d\n", nalsize);
4587 next_avc = buf_index + nalsize;
4590 for (; buf_index + 3 < next_avc; buf_index++)
4592 if (buf[buf_index] == 0 &&
4593 buf[buf_index + 1] == 0 &&
4594 buf[buf_index + 2] == 1)
4597 if (buf_index + 3 >= buf_size) {
4598 buf_index = buf_size;
4603 if (buf_index >= next_avc)
4610 &consumed, next_avc - buf_index);
4611 if (ptr ==
NULL || dst_length < 0) {
4615 i = buf_index + consumed;
4617 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
4618 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
4622 while (dst_length > 0 && ptr[dst_length - 1] == 0)
4624 bit_length = !dst_length ? 0
4630 "NAL %d at %d/%d length %d\n",
4633 if (h->
is_avc && (nalsize != consumed) && nalsize)
4635 "AVC: Consumed only %d bytes instead of %d\n",
4638 buf_index += consumed;
4649 nals_needed = nal_index;
4656 nals_needed = nal_index;
4677 "Ignoring NAL unit %d during extradata parsing\n",
4686 "Invalid mix of idr and non-idr slices\n");
4739 &buf[buf_index - consumed],
4750 "Decoding in chunks is not supported for "
4751 "partitioned slices.\n");
4796 if (ret < 0 && h->is_avc && (nalsize != consumed) && nalsize) {
4798 "SPS decoding failure, trying again with the complete NAL\n");
4835 }
else if (err == 1) {
4857 return (ret < 0) ? ret : buf_index;
4867 if (pos + 10 > buf_size)
4883 for (i = 0; i < 3; i++) {
4888 dst->
data[i] += off;
4897 int buf_size = avpkt->
size;
4910 if (buf_size == 0) {
4978 assert(pict->
buf[0] || !*got_frame);