51 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
52 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
53 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
57 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
58 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
59 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
63 #if CONFIG_H264_DXVA2_HWACCEL
66 #if CONFIG_H264_VAAPI_HWACCEL
69 #if CONFIG_H264_VDA_HWACCEL
83 static const int8_t top[12] = {
86 static const int8_t left[12] = {
92 for (i = 0; i < 4; i++) {
96 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
106 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
107 for (i = 0; i < 4; i++)
112 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
136 "out of range intra chroma pred mode at %d %d\n",
145 "top block unavailable for requested intra mode at %d %d\n",
161 "left block unavailable for requested intra mode at %d %d\n",
171 int *dst_length,
int *consumed,
int length)
184 #define STARTCODE_TEST \
185 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
186 if (src[i + 2] != 3) { \
192 #if HAVE_FAST_UNALIGNED
193 #define FIND_FIRST_ZERO \
194 if (i > 0 && !src[i]) \
199 for (i = 0; i + 1 < length; i += 9) {
201 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
202 0x8000800080008080ULL))
209 for (i = 0; i + 1 < length; i += 5) {
211 (
AV_RN32A(src + i) - 0x01000101U)) &
220 for (i = 0; i + 1 < length; i += 2) {
223 if (i > 0 && src[i - 1] == 0)
229 if (i >= length - 1) {
230 *dst_length = length;
231 *consumed = length + 1;
246 while (si + 2 < length) {
248 if (src[si + 2] > 3) {
249 dst[di++] = src[si++];
250 dst[di++] = src[si++];
251 }
else if (src[si] == 0 && src[si + 1] == 0) {
252 if (src[si + 2] == 3) {
261 dst[di++] = src[si++];
264 dst[di++] = src[si++];
287 for (r = 1; r < 9; r++) {
296 int height,
int y_offset,
int list)
299 int filter_height_up = (raw_my & 3) ? 2 : 0;
300 int filter_height_down = (raw_my & 3) ? 3 : 0;
301 int full_my = (raw_my >> 2) + y_offset;
302 int top = full_my - filter_height_up;
303 int bottom = full_my + filter_height_down +
height;
305 return FFMAX(abs(top), bottom);
309 int height,
int y_offset,
int list0,
310 int list1,
int *nrefs)
327 if (refs[0][ref_n] < 0)
329 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
340 if (refs[1][ref_n] < 0)
342 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
355 const int mb_xy = h->
mb_xy;
358 int nrefs[2] = { 0 };
361 memset(refs, -1,
sizeof(refs));
381 for (i = 0; i < 4; i++) {
384 int y_offset = (i & 2) << 2;
388 IS_DIR(sub_mb_type, 0, 0),
389 IS_DIR(sub_mb_type, 0, 1),
393 IS_DIR(sub_mb_type, 0, 0),
394 IS_DIR(sub_mb_type, 0, 1),
397 IS_DIR(sub_mb_type, 0, 0),
398 IS_DIR(sub_mb_type, 0, 1),
402 IS_DIR(sub_mb_type, 0, 0),
403 IS_DIR(sub_mb_type, 0, 1),
406 IS_DIR(sub_mb_type, 0, 0),
407 IS_DIR(sub_mb_type, 0, 1),
412 for (j = 0; j < 4; j++) {
413 int sub_y_offset = y_offset + 2 * (j & 2);
415 IS_DIR(sub_mb_type, 0, 0),
416 IS_DIR(sub_mb_type, 0, 1),
423 for (list = h->
list_count - 1; list >= 0; list--)
424 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
425 int row = refs[list][ref];
430 int pic_height = 16 * s->
mb_height >> ref_field_picture;
437 FFMIN((row >> 1) - !(row & 1),
441 FFMIN((row >> 1), pic_height - 1),
445 FFMIN(row * 2 + ref_field,
450 FFMIN(row, pic_height - 1),
454 FFMIN(row, pic_height - 1),
466 int src_x_offset,
int src_y_offset,
469 int pixel_shift,
int chroma_idc)
472 const int mx = h->
mv_cache[list][
scan8[n]][0] + src_x_offset * 8;
474 const int luma_xy = (mx & 3) + ((my & 3) << 2);
475 int offset = ((mx >> 2) << pixel_shift) + (my >> 2) * h->
mb_linesize;
481 const int full_mx = mx >> 2;
482 const int full_my = my >> 2;
483 const int pic_width = 16 * s->
mb_width;
492 if (full_mx < 0 - extra_width ||
493 full_my < 0 - extra_height ||
494 full_mx + 16 > pic_width + extra_width ||
495 full_my + 16 > pic_height + extra_height) {
499 16 + 5, 16 + 5 , full_mx - 2,
500 full_my - 2, pic_width, pic_height);
512 if (chroma_idc == 3 ) {
513 src_cb = pic->
f.
data[1] + offset;
519 full_mx - 2, full_my - 2,
520 pic_width, pic_height);
527 src_cr = pic->
f.
data[2] + offset;
533 full_mx - 2, full_my - 2,
534 pic_width, pic_height);
543 ysh = 3 - (chroma_idc == 2 );
547 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
550 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
552 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
557 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
558 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
562 height >> (chroma_idc == 1 ),
563 mx & 7, (my << (chroma_idc == 2 )) & 7);
567 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
568 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
571 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
572 mx & 7, (my << (chroma_idc == 2 )) & 7);
579 int x_offset,
int y_offset,
584 int list0,
int list1,
585 int pixel_shift,
int chroma_idc)
591 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
592 if (chroma_idc == 3 ) {
593 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
594 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
595 }
else if (chroma_idc == 2 ) {
596 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
597 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
599 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
600 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
602 x_offset += 8 * s->
mb_x;
608 dest_y, dest_cb, dest_cr, x_offset, y_offset,
609 qpix_op, chroma_op, pixel_shift, chroma_idc);
612 chroma_op = chroma_avg;
618 dest_y, dest_cb, dest_cr, x_offset, y_offset,
619 qpix_op, chroma_op, pixel_shift, chroma_idc);
627 int x_offset,
int y_offset,
634 int list0,
int list1,
635 int pixel_shift,
int chroma_idc)
640 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
641 if (chroma_idc == 3 ) {
643 chroma_weight_avg = luma_weight_avg;
644 chroma_weight_op = luma_weight_op;
645 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
646 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
647 }
else if (chroma_idc == 2 ) {
649 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
650 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
652 chroma_height = height >> 1;
653 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
654 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
656 x_offset += 8 * s->
mb_x;
659 if (list0 && list1) {
669 dest_y, dest_cb, dest_cr,
670 x_offset, y_offset, qpix_put, chroma_put,
671 pixel_shift, chroma_idc);
673 tmp_y, tmp_cb, tmp_cr,
674 x_offset, y_offset, qpix_put, chroma_put,
675 pixel_shift, chroma_idc);
679 int weight1 = 64 - weight0;
681 height, 5, weight0, weight1, 0);
683 chroma_height, 5, weight0, weight1, 0);
685 chroma_height, 5, weight0, weight1, 0);
687 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
693 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
699 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
707 int list = list1 ? 1 : 0;
710 mc_dir_part(h, ref, n, square, height, delta, list,
711 dest_y, dest_cb, dest_cr, x_offset, y_offset,
712 qpix_put, chroma_put, pixel_shift, chroma_idc);
732 int pixel_shift,
int chroma_idc)
742 int off = (mx << pixel_shift) +
746 if (chroma_idc == 3 ) {
750 off = ((mx >> 1) << pixel_shift) +
800 for (i = 0; i < 6; i++) {
802 for (j = 0; j < i; j++)
811 for (q = 0; q < max_qp + 1; q++) {
814 for (x = 0; x < 64; x++)
826 for (i = 0; i < 6; i++) {
828 for (j = 0; j < i; j++)
837 for (q = 0; q < max_qp + 1; q++) {
838 int shift =
div6[q] + 2;
840 for (x = 0; x < 16; x++)
855 for (i = 0; i < 6; i++)
856 for (x = 0; x < 16; x++)
859 for (i = 0; i < 6; i++)
860 for (x = 0; x < 64; x++)
873 row_mb_num * 8 *
sizeof(
uint8_t), fail)
875 big_mb_num * 48 *
sizeof(
uint8_t), fail)
879 big_mb_num *
sizeof(uint16_t), fail)
881 big_mb_num *
sizeof(
uint8_t), fail)
883 16 * row_mb_num *
sizeof(
uint8_t), fail);
885 16 * row_mb_num *
sizeof(
uint8_t), fail);
887 4 * big_mb_num *
sizeof(
uint8_t), fail);
889 big_mb_num *
sizeof(
uint8_t), fail)
896 big_mb_num *
sizeof(uint32_t), fail);
898 big_mb_num *
sizeof(uint32_t), fail);
902 const int b_xy = 4 * x + 4 * y * h->
b_stride;
965 int parse_extradata);
1007 cnt = *(p + 5) & 0x1f;
1009 for (i = 0; i < cnt; i++) {
1015 "Decoding sps %d from avcC failed\n", i);
1022 for (i = 0; i < cnt; i++) {
1028 "Decoding pps %d from avcC failed\n", i);
1096 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1104 for (i = 0; i < count; i++) {
1105 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1117 for (i = 0; i < count; i++) {
1118 if (to[i] && !from[i])
1120 else if (from[i] && !to[i])
1124 memcpy(to[i], from[i], size);
1142 #define copy_fields(to, from, start_field, end_field) \
1143 memcpy(&to->start_field, &from->start_field, \
1144 (char *)&to->end_field - (char *)&to->start_field)
1158 if (dst == src || !
s1->context_initialized)
1205 memcpy(&h->
s + 1, &h1->s + 1,
1215 for (i = 0; i < 2; i++) {
1245 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1247 for (i = 0; i < 6; i++)
1249 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1251 for (i = 0; i < 6; i++)
1253 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1307 for (i = 0; i < 16; i++) {
1311 for (i = 0; i < 16; i++) {
1364 int i, pics, out_of_order, out_idx;
1365 int invalid = 0, cnt = 0;
1490 invalid += out->
poc == INT_MIN;
1493 cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {
1502 invalid = MAX_DELAYED_PIC_COUNT;
1506 for (i = 1; i < MAX_DELAYED_PIC_COUNT &&
1525 if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
1546 sizeof(*h->
last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
1575 int linesize,
int uvlinesize,
1586 src_cb -= uvlinesize;
1587 src_cr -= uvlinesize;
1593 AV_COPY128(top_border, src_y + 15 * linesize);
1595 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
1599 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
1600 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
1601 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
1602 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
1604 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
1605 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
1607 }
else if (chroma422) {
1609 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
1610 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
1612 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
1613 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
1617 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
1618 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
1620 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
1621 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
1635 AV_COPY128(top_border, src_y + 16 * linesize);
1637 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
1642 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
1643 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
1644 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
1645 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
1647 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
1648 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
1650 }
else if (chroma422) {
1652 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
1653 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
1655 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
1656 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
1660 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
1661 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
1663 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
1664 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
1672 int linesize,
int uvlinesize,
1673 int xchg,
int chroma444,
1674 int simple,
int pixel_shift)
1677 int deblock_topleft;
1696 deblock_topleft = (s->
mb_x > 0);
1700 src_y -= linesize + 1 + pixel_shift;
1701 src_cb -= uvlinesize + 1 + pixel_shift;
1702 src_cr -= uvlinesize + 1 + pixel_shift;
1707 #define XCHG(a, b, xchg) \
1708 if (pixel_shift) { \
1710 AV_SWAP64(b + 0, a + 0); \
1711 AV_SWAP64(b + 8, a + 8); \
1721 if (deblock_topleft) {
1722 XCHG(top_border_m1 + (8 << pixel_shift),
1723 src_y - (7 << pixel_shift), 1);
1725 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
1726 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
1729 src_y + (17 << pixel_shift), 1);
1734 if (deblock_topleft) {
1735 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
1736 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
1738 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
1739 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
1740 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
1741 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
1743 XCHG(h->
top_borders[top_idx][s->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
1744 XCHG(h->
top_borders[top_idx][s->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
1748 if (deblock_topleft) {
1749 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
1750 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
1752 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
1753 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
1762 if (high_bit_depth) {
1769 int index,
int value)
1771 if (high_bit_depth) {
1778 int mb_type,
int is_h264,
1780 int transform_bypass,
1791 block_offset += 16 * p;
1795 if (transform_bypass) {
1802 for (i = 0; i < 16; i += 4) {
1803 uint8_t *
const ptr = dest_y + block_offset[i];
1806 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1812 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
1813 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1815 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1820 if (transform_bypass) {
1827 for (i = 0; i < 16; i++) {
1828 uint8_t *
const ptr = dest_y + block_offset[i];
1832 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1839 assert(s->
mb_y || linesize <= block_offset[i]);
1840 if (!topright_avail) {
1842 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
1843 topright = (
uint8_t *)&tr_high;
1845 tr = ptr[3 - linesize] * 0x01010101u;
1849 topright = ptr + (4 << pixel_shift) - linesize;
1853 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
1857 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
1858 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1860 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
1872 if (!transform_bypass)
1877 static const uint8_t dc_mapping[16] = {
1878 0 * 16, 1 * 16, 4 * 16, 5 * 16,
1879 2 * 16, 3 * 16, 6 * 16, 7 * 16,
1880 8 * 16, 9 * 16, 12 * 16, 13 * 16,
1881 10 * 16, 11 * 16, 14 * 16, 15 * 16 };
1882 for (i = 0; i < 16; i++)
1884 pixel_shift, dc_mapping[i],
1896 int is_h264,
int simple,
1897 int transform_bypass,
1906 block_offset += 16 * p;
1910 if (transform_bypass) {
1915 h->
mb + (p * 256 << pixel_shift),
1918 for (i = 0; i < 16; i++)
1922 h->
mb + (i * 16 + p * 256 << pixel_shift),
1927 h->
mb + (p * 256 << pixel_shift),
1931 }
else if (h->
cbp & 15) {
1932 if (transform_bypass) {
1933 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
1936 for (i = 0; i < 16; i += di)
1939 h->
mb + (i * 16 + p * 256 << pixel_shift),
1944 h->
mb + (p * 256 << pixel_shift),
1949 h->
mb + (p * 256 << pixel_shift),
1955 for (i = 0; i < 16; i++)
1958 uint8_t *
const ptr = dest_y + block_offset[i];
1981 const int mb_xy = h->
mb_xy;
1987 hl_decode_mb_444_complex(h);
1989 hl_decode_mb_444_simple_8(h);
1990 }
else if (is_complex) {
1991 hl_decode_mb_complex(h);
1993 hl_decode_mb_simple_16(h);
1995 hl_decode_mb_simple_8(h);
2002 int luma_def, chroma_def;
2012 for (list = 0; list < 2; list++) {
2015 for (i = 0; i < h->
ref_count[list]; i++) {
2016 int luma_weight_flag, chroma_weight_flag;
2019 if (luma_weight_flag) {
2034 if (chroma_weight_flag) {
2036 for (j = 0; j < 2; j++) {
2047 for (j = 0; j < 2; j++) {
2069 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2071 for (i = 0; i < 2; i++) {
2103 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2105 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2109 int td = av_clip(poc1 - poc0, -128, 127);
2111 int tb = av_clip(cur_poc - poc0, -128, 127);
2112 int tx = (16384 + (
FFABS(td) >> 1)) / td;
2113 int dist_scale_factor = (tb * tx + 32) >> 8;
2114 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2115 w = 64 - dist_scale_factor;
2200 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2211 expected_delta_per_poc_cycle = 0;
2216 if (abs_frame_num > 0) {
2220 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2221 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2229 field_poc[0] = expectedpoc + h->
delta_poc[0];
2259 for (i = 0; i < 16; i++) {
2260 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2265 for (i = 0; i < 64; i++) {
2266 #define T(x) (x >> 3) | ((x & 7) << 3)
2319 "hardware accelerator failed to decode picture\n");
2365 "Failed to allocate scratch buffers\n");
2422 "Reenabling low delay requires a codec flush.\n");
2432 "Different bit depth between chroma and luma", 1);
2442 "VDPAU decoding does not support video colorspace.\n");
2554 "Could not allocate memory for h264\n");
2601 unsigned int first_mb_in_slice;
2602 unsigned int pps_id;
2603 int num_ref_idx_active_override_flag, max_refs, ret;
2604 unsigned int slice_type, tmp, i, j;
2605 int default_ref_list_done = 0;
2606 int last_pic_structure, last_pic_droppable;
2607 int needs_reinit = 0;
2621 if (first_mb_in_slice == 0) {
2638 if (slice_type > 9) {
2640 "slice type too large (%d) at %d %d\n",
2644 if (slice_type > 4) {
2653 default_ref_list_done = 1;
2674 "non-existing PPS %u referenced\n",
2682 "non-existing SPS %u referenced\n",
2767 "h264_slice_header_init() failed\n");
2775 "Cannot (re-)initialize context during parallel decoding.\n");
2785 "h264_slice_header_init() failed\n");
2818 "Changing field mode (%d -> %d) between slices is not allowed\n",
2825 "unset current_picture_ptr on %d. slice\n",
2836 if (unwrap_prev_frame_num > h->
frame_num)
2837 unwrap_prev_frame_num -= max_frame_num;
2841 if (unwrap_prev_frame_num < 0)
2842 unwrap_prev_frame_num += max_frame_num;
2868 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
2878 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
2889 "Invalid field mode combination %d/%d\n",
2894 }
else if (last_pic_droppable != s->
droppable) {
2896 "Cannot combine reference and non-reference fields in the same frame\n");
2996 first_mb_in_slice >= s->
mb_num) {
3043 num_ref_idx_active_override_flag =
get_bits1(&s->
gb);
3045 if (num_ref_idx_active_override_flag) {
3074 if (!default_ref_list_done)
3103 for (i = 0; i < 2; i++) {
3166 "deblocking_filter_idc %u out of range\n", tmp);
3179 "deblocking filter parameters %d %d out of range\n",
3204 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3209 "Deblocking switched inside frame.\n");
3225 "Too many slices, increase MAX_SLICES and recompile\n");
3228 for (j = 0; j < 2; j++) {
3231 for (i = 0; i < 16; i++) {
3251 for (i = 0; i < 16; i++)
3252 ref2frm[i + 2] = 4 * id_list[i] +
3255 ref2frm[18 + 1] = -1;
3256 for (i = 16; i < 48; i++)
3257 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3270 "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",
3312 int mb_type,
int top_xy,
3315 int left_type[LEFT_MBS],
3316 int mb_xy,
int list)
3323 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
3324 const int b8_xy = 4 * top_xy + 2;
3327 ref_cache[0 - 1 * 8] =
3329 ref_cache[2 - 1 * 8] =
3339 const int b8_xy = 4 * left_xy[
LTOP] + 1;
3347 ref_cache[-1 + 16] =
3356 ref_cache[-1 + 16] =
3374 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
3375 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
3376 AV_WN32A(&ref_cache[0 * 8], ref01);
3377 AV_WN32A(&ref_cache[1 * 8], ref01);
3378 AV_WN32A(&ref_cache[2 * 8], ref23);
3379 AV_WN32A(&ref_cache[3 * 8], ref23);
3384 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
3385 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
3386 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
3387 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
3398 const int mb_xy = h->
mb_xy;
3409 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
3414 if (left_mb_field_flag != curr_mb_field_flag)
3417 if (curr_mb_field_flag)
3420 if (left_mb_field_flag != curr_mb_field_flag)
3434 if (qp <= qp_thresh &&
3435 (left_xy[
LTOP] < 0 ||
3441 if ((left_xy[
LTOP] < 0 ||
3456 left_type[
LTOP] = left_type[
LBOT] = 0;
3461 left_type[
LTOP] = left_type[
LBOT] = 0;
3471 top_type, left_type, mb_xy, 0);
3474 top_type, left_type, mb_xy, 1);
3478 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
3479 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
3480 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
3481 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
3486 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
3489 if (left_type[
LTOP]) {
3491 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
3492 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
3493 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
3494 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
3501 nnz_cache[4 + 8 * 0] =
3502 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
3503 nnz_cache[6 + 8 * 0] =
3504 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
3507 nnz_cache[3 + 8 * 1] =
3508 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
3511 nnz_cache[3 + 8 * 3] =
3512 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
3516 nnz_cache[
scan8[0]] =
3517 nnz_cache[scan8[1]] =
3518 nnz_cache[scan8[2]] =
3519 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
3521 nnz_cache[scan8[0 + 4]] =
3522 nnz_cache[scan8[1 + 4]] =
3523 nnz_cache[scan8[2 + 4]] =
3524 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
3526 nnz_cache[scan8[0 + 8]] =
3527 nnz_cache[scan8[1 + 8]] =
3528 nnz_cache[scan8[2 + 8]] =
3529 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
3531 nnz_cache[scan8[0 + 12]] =
3532 nnz_cache[scan8[1 + 12]] =
3533 nnz_cache[scan8[2 + 12]] =
3534 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
3544 uint8_t *dest_y, *dest_cb, *dest_cr;
3545 int linesize, uvlinesize, mb_x, mb_y;
3552 for (mb_x = start_x; mb_x < end_x; mb_x++)
3553 for (mb_y = end_mb_y -
FRAME_MBAFF; mb_y <= end_mb_y; mb_y++) {
3567 ((mb_x << pixel_shift) + mb_y * s->
linesize) * 16;
3569 (mb_x << pixel_shift) * (8 <<
CHROMA444) +
3572 (mb_x << pixel_shift) * (8 <<
CHROMA444) +
3597 linesize, uvlinesize);
3600 dest_cr, linesize, uvlinesize);
3634 if ((top + height) >= pic_height)
3635 height += deblock_border;
3636 top -= deblock_border;
3642 height =
FFMIN(height, pic_height - top);
3643 if (top < h->emu_edge_height) {
3663 int lf_x_start = s->
mb_x;
3708 if (s->
mb_x >= lf_x_start)
3714 "error while decoding MB %d %d, bytestream (%td)\n",
3724 s->
mb_x = lf_x_start = 0;
3739 if (s->
mb_x > lf_x_start)
3763 "error while decoding MB %d %d\n", s->
mb_x, s->
mb_y);
3771 s->
mb_x = lf_x_start = 0;
3806 if (s->
mb_x > lf_x_start)
3837 if (context_count == 1) {
3840 for (i = 1; i < context_count; i++) {
3847 NULL, context_count,
sizeof(
void *));
3855 for (i = 1; i < context_count; i++)
3863 int parse_extradata)
3872 int nals_needed = 0;
3883 for (; pass <= 1; pass++) {
3886 next_avc = h->
is_avc ? 0 : buf_size;
3896 if (buf_index >= next_avc) {
3901 nalsize = (nalsize << 8) | buf[buf_index++];
3902 if (nalsize <= 0 || nalsize > buf_size - buf_index) {
3904 "AVC: nal size %d\n", nalsize);
3907 next_avc = buf_index + nalsize;
3910 for (; buf_index + 3 < next_avc; buf_index++)
3912 if (buf[buf_index] == 0 &&
3913 buf[buf_index + 1] == 0 &&
3914 buf[buf_index + 2] == 1)
3917 if (buf_index + 3 >= buf_size) {
3918 buf_index = buf_size;
3923 if (buf_index >= next_avc)
3930 &consumed, next_avc - buf_index);
3931 if (ptr ==
NULL || dst_length < 0) {
3935 i = buf_index + consumed;
3937 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
3938 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
3942 while (ptr[dst_length - 1] == 0 && dst_length > 0)
3944 bit_length = !dst_length ? 0
3950 "NAL %d at %d/%d length %d\n",
3953 if (h->
is_avc && (nalsize != consumed) && nalsize)
3955 "AVC: Consumed only %d bytes instead of %d\n",
3958 buf_index += consumed;
3969 nals_needed = nal_index;
3976 nals_needed = nal_index;
4002 "Invalid mix of idr and non-idr slices\n");
4042 &buf[buf_index - consumed],
4047 static const uint8_t start_code[] = {
4050 sizeof(start_code));
4095 h->
is_avc && (nalsize != consumed) && nalsize) {
4097 "SPS decoding failure, trying again with the complete NAL\n");
4133 else if (err == 1) {
4166 if (pos + 10 > buf_size)
4176 int buf_size = avpkt->
size;
4187 if (buf_size == 0) {
4250 assert(pict->
data[0] || !*got_frame);
4318 #if CONFIG_H264_VDPAU_DECODER
4319 AVCodec ff_h264_vdpau_decoder = {
4320 .
name =
"h264_vdpau",
4329 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
Picture default_ref_list[2][32]
base reference list for all slices of a coded picture
#define PICT_BOTTOM_FIELD
void ff_h264_direct_dist_scale_factor(H264Context *const h)
enum AVPixelFormat ff_hwaccel_pixfmt_list_420[]
int video_signal_type_present_flag
void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
int ff_h264_decode_mb_cabac(H264Context *h)
Decode a CABAC coded macroblock.
static void clone_tables(H264Context *dst, H264Context *src, int i)
Mimic alloc_tables(), but for every context thread.
#define FF_PROFILE_H264_CONSTRAINED
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ff_h264_decode_seq_parameter_set(H264Context *h)
Decode SPS.
discard all frames except keyframes
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
void(* prefetch)(uint8_t *buf, ptrdiff_t stride, int h)
Prefetch memory into cache (if supported by hardware).
unsigned int top_samples_available
static enum PixelFormat get_pixel_format(H264Context *h)
static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, int parse_extradata)
unsigned int topleft_samples_available
int single_decode_warning
1 if the single thread fallback warning has already been displayed, 0 otherwise.
5: top field, bottom field, top field repeated, in that order
static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, int mb_type, int is_h264, int simple, int transform_bypass, int pixel_shift, int *block_offset, int linesize, uint8_t *dest_y, int p)
const uint8_t ff_zigzag_direct[64]
GetBitContext * intra_gb_ptr
void ff_release_unused_pictures(MpegEncContext *s, int remove_current)
This structure describes decoded (raw) audio or video data.
#define FF_PROFILE_H264_INTRA
void ff_vdpau_h264_picture_complete(MpegEncContext *s)
static void copy_parameter_set(void **to, void **from, int count, int size)
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
#define FF_PROFILE_H264_MAIN
3: top field, bottom field, in that order
const uint8_t * ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length)
Decode a network abstraction layer unit.
av_cold int ff_MPV_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int chroma_qp_index_offset[2]
const uint8_t * bytestream_end
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
int luma_weight_flag[2]
7.4.3.2 luma_weight_lX_flag
MMCO mmco[MAX_MMCO_COUNT]
memory management control operations buffer.
static void align_get_bits(GetBitContext *s)
static av_always_inline void mc_part_weighted(H264Context *h, int n, int square, int height, int delta, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int x_offset, int y_offset, qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, int list0, int list1, int pixel_shift, int chroma_idc)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static const uint8_t field_scan8x8[64]
static void init_dequant_tables(H264Context *h)
int bitstream_restriction_flag
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
void(* h264_idct_add16intra)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[15 *8])
int repeat_pict
When decoding, this signals how much the picture must be delayed.
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
#define CODEC_CAP_HWACCEL_VDPAU
HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the b...
void * thread_opaque
used by multithreading to store frame-specific info
static av_always_inline int dctcoef_get(DCTELEM *mb, int high_bit_depth, int index)
int field_picture
whether or not the picture was encoded in separate fields
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
#define FF_QSCALE_TYPE_H264
const uint8_t * field_scan8x8_q0
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int is_avc
Used to parse AVC variant of h264.
static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
uint8_t zigzag_scan8x8_cavlc[64]
int ff_h264_get_profile(SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64]
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
static int context_init(H264Context *h)
Init context Allocate buffers which are not shared amongst multiple threads.
int mmco_reset
h264 MMCO_RESET set this 1. Reordering code must not mix pictures before and after MMCO_RESET...
#define FF_PROFILE_H264_HIGH_422
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
uint32_t num_units_in_tick
#define FF_PROFILE_H264_HIGH_444_INTRA
struct H264Context H264Context
H264Context.
4: bottom field, top field, in that order
int mb_num
number of MBs of a picture
static int get_lowest_part_list_y(H264Context *h, Picture *pic, int n, int height, int y_offset, int list)
#define AV_PIX_FMT_YUV444P10
void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc)
#define FF_PROFILE_H264_HIGH_444
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static const uint8_t rem6[QP_MAX_NUM+1]
unsigned current_sps_id
id of the current SPS
static av_always_inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int height, int delta, int list, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int src_x_offset, int src_y_offset, qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op, int pixel_shift, int chroma_idc)
static av_always_inline uint32_t pack16to32(int a, int b)
int encoding
true if we are encoding (vs decoding)
static const uint8_t zigzag_scan[16]
#define AV_PIX_FMT_YUV420P9
void ff_h264_init_cabac_states(H264Context *h)
#define FF_PROFILE_H264_CAVLC_444
#define USES_LIST(a, list)
does this mb use listX, note does not work if subMBs
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
uint8_t * chroma_pred_mode_table
#define IS_DIR(a, part, list)
static const uint8_t div6[QP_MAX_NUM+1]
enum AVDiscard skip_frame
int ff_h264_decode_ref_pic_list_reordering(H264Context *h)
static const uint8_t golomb_to_pict_type[5]
struct AVHWAccel * hwaccel
Hardware accelerator in use.
int long_ref
1->long term reference 0->short term reference
static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, int is_h264, int simple, int transform_bypass, int pixel_shift, int *block_offset, int linesize, uint8_t *dest_y, int p)
static int decode_init_thread_copy(AVCodecContext *avctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
uint8_t scaling_matrix4[6][16]
const uint8_t * bytestream
int ref2frm[MAX_SLICES][2][64]
reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 ...
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, ptrdiff_t linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Copy a rectangular area of samples to a temporary buffer and replicate the border samples...
int deblocking_filter_parameters_present
deblocking_filter_parameters_present_flag
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
DCTELEM mb_luma_dc[3][16 *2]
uint32_t(*[6] dequant4_coeff)[16]
int ff_MPV_common_frame_size_change(MpegEncContext *s)
int prev_frame_num_offset
for POC type 2
void(* h264_luma_dc_dequant_idct)(DCTELEM *output, DCTELEM *input, int qmul)
int offset_for_non_ref_pic
#define AV_PIX_FMT_GBRP10
int context_reinitialized
void ff_h264_reset_sei(H264Context *h)
Reset SEI values at the beginning of the frame.
int luma_weight[48][2][2]
enum OutputFormat out_format
output format
int bit_depth_chroma
bit_depth_chroma_minus8 + 8
void(* qpel_mc_func)(uint8_t *dst, uint8_t *src, int stride)
enum AVColorPrimaries color_primaries
av_cold void ff_h264_decode_init_vlc(void)
void(* h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride)
DCTELEM mb[16 *48 *2]
as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
Picture ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
int cabac
entropy_coding_mode_flag
qpel_mc_func(* qpel_put)[16]
#define LUMA_DC_BLOCK_INDEX
#define DIAG_DOWN_LEFT_PRED
static const uint8_t dequant8_coeff_init[6][6]
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
unsigned int crop_right
frame_cropping_rect_right_offset
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define AV_PIX_FMT_YUV420P10
Picture current_picture
copy of the current picture structure.
void ff_h264_fill_mbaff_ref_list(H264Context *h)
int transform_bypass
qpprime_y_zero_transform_bypass_flag
static int init_poc(H264Context *h)
static int get_bits_count(const GetBitContext *s)
static int decode_rbsp_trailing(H264Context *h, const uint8_t *src)
Identify the exact end of the bitstream.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
int ff_h264_get_slice_type(const H264Context *h)
Reconstruct bitstream slice_type.
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
#define AV_PIX_FMT_YUV444P9
static const uint8_t dequant8_coeff_init_scan[16]
int flags2
AVCodecContext.flags2.
int interlaced_frame
The content of the picture is interlaced.
#define MAX_DELAYED_PIC_COUNT
int mb_height
number of MBs horizontally & vertically
void ff_MPV_frame_end(MpegEncContext *s)
void(* pred4x4[9+3+3])(uint8_t *src, const uint8_t *topright, ptrdiff_t stride)
Picture * next_output_pic
#define FF_COMPLIANCE_STRICT
static av_cold void common_init(H264Context *h)
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int luma_log2_weight_denom
static int h264_set_parameter_from_sps(H264Context *h)
int chroma_weight[48][2][2][2]
static int init(AVCodecParserContext *s)
int last_pocs[MAX_DELAYED_PIC_COUNT]
static void init_dequant4_coeff_table(H264Context *h)
void(* pred8x8l_add[2])(uint8_t *pix, const DCTELEM *block, ptrdiff_t stride)
const uint8_t * zigzag_scan8x8_cavlc_q0
H.264 / AVC / MPEG4 part10 codec.
static int get_bits_left(GetBitContext *gb)
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
int slice_context_count
number of used thread_contexts
int mb_aff
mb_adaptive_frame_field_flag
enum AVColorTransferCharacteristic color_trc
void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
Set the intra prediction function pointers.
int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
int has_b_frames
Size of the frame reordering buffer in the decoder.
#define FF_PROFILE_H264_HIGH_10
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
static int decode_slice_header(H264Context *h, H264Context *h0)
Decode a slice header.
const uint8_t * zigzag_scan_q0
int poc_type
pic_order_cnt_type
Multithreading support functions.
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
void(* h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int height, int log2_denom, int weightd, int weights, int offset)
static const uint16_t mask[17]
void ff_h264_hl_decode_mb(H264Context *h)
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
int partitioned_frame
is current frame partitioned
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
discard all bidirectional frames
void ff_h264_direct_ref_list_init(H264Context *const h)
static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale)
Get the chroma qp.
GetBitContext * inter_gb_ptr
void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)
static void copy_picture_range(Picture **to, Picture **from, int count, MpegEncContext *new_base, MpegEncContext *old_base)
#define ALZHEIMER_DC_L0T_PRED8x8
int unrestricted_mv
mv can point outside of the coded picture
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
int active_thread_type
Which multithreading methods are in use by the codec.
int mb_field_decoding_flag
#define FF_DEBUG_PICT_INFO
static void flush_dpb(AVCodecContext *avctx)
static int h264_slice_header_init(H264Context *, int)
int capabilities
Codec capabilities.
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
uint8_t * base[AV_NUM_DATA_POINTERS]
pointer to the first allocated byte of the picture.
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
uint8_t(*[2] mvd_table)[2]
int prev_interlaced_frame
Complement sei_pic_struct SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced...
int direct_spatial_mv_pred
#define CODEC_FLAG_LOW_DELAY
simple assert() macros that are a bit more flexible than ISO C assert().
void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
int weighted_pred
weighted_pred_flag
void av_log(void *avcl, int level, const char *fmt,...)
static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size)
Return the number of bytes consumed for building the current frame.
const char * name
Name of the codec implementation.
void(* h264_chroma_mc_func)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x, int y)
static void predict_field_decoding_flag(H264Context *h)
int quarter_sample
1->qpel, 0->half pel ME/MC
int ff_h264_decode_mb_cavlc(H264Context *h)
Decode a macroblock.
int low_delay
no reordering needed / has no b-frames
#define CODEC_FLAG_EMU_EDGE
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
int delta_pic_order_always_zero_flag
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
int new
flag to keep track if the decoder context needs re-init due to changed SPS
int dct_bits
Size of DCT coefficients.
int offset_for_top_to_bottom_field
#define IN_RANGE(a, b, size)
uint8_t zigzag_scan8x8[64]
int picture_count
number of allocated pictures (MAX_PICTURE_COUNT * avctx->thread_count)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static const uint8_t scan8[16 *3+3]
void ff_mpeg_flush(AVCodecContext *avctx)
void(* add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int resync_mb_x
x position of last resync marker
the normal 2^n-1 "JPEG" YUV ranges
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int chroma444, int simple, int pixel_shift)
uint8_t scaling_matrix8[6][64]
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
useful rectangle filling function
the normal 219*2^(n-8) "MPEG" YUV ranges
void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
int refs
number of reference frames
unsigned int left_samples_available
int ref_frame_count
num_ref_frames
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
void ff_h264_filter_mb(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize)
int frame_num_offset
for POC type 2
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
uint8_t field_scan8x8_cavlc[64]
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
int colour_description_present_flag
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static const uint8_t field_scan8x8_cavlc[64]
int width
picture width / height.
static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncContext *const s, int mb_type, int top_xy, int left_xy[LEFT_MBS], int top_type, int left_type[LEFT_MBS], int mb_xy, int list)
Picture * current_picture_ptr
pointer to the current picture
int long_ref_count
number of actual long term references
void ff_copy_picture(Picture *dst, Picture *src)
qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]
#define CODEC_CAP_FRAME_THREADS
void(* pred4x4_add[2])(uint8_t *pix, const DCTELEM *block, ptrdiff_t stride)
static void implicit_weight_table(H264Context *h, int field)
Initialize implicit_weight table.
PPS * pps_buffers[MAX_PPS_COUNT]
static av_always_inline void prefetch_motion(H264Context *h, int list, int pixel_shift, int chroma_idc)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
void ff_er_frame_end(MpegEncContext *s)
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length)
Decode PPS.
void ff_vdpau_h264_picture_start(MpegEncContext *s)
Context Adaptive Binary Arithmetic Coder inline functions.
int init_qp
pic_init_qp_minus26 + 26
int frame_num
h264 frame_num (raw frame_num from slice header)
int8_t intra4x4_pred_mode_cache[5 *8]
uint8_t * bipred_scratchpad
int max_pic_num
max_frame_num or 2 * max_frame_num for field pics.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static const uint8_t field_scan[16]
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice)
int ff_mpv_frame_size_alloc(MpegEncContext *s, int linesize)
#define FF_PROFILE_H264_HIGH
static int decode_slice(struct AVCodecContext *avctx, void *arg)
unsigned int topright_samples_available
const uint8_t * zigzag_scan8x8_q0
#define CODEC_FLAG2_CHUNKS
int curr_pic_num
frame_num for frames or 2 * frame_num + 1 for field pics.
static void init_scan_tables(H264Context *h)
initialize scan tables
static int av_unused get_cabac_terminate(CABACContext *c)
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function for encode/decode called after coding/decoding the header and before a frame is code...
#define FF_PROFILE_H264_HIGH_422_INTRA
static void loop_filter(H264Context *h, int start_x, int end_x)
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]
void(* h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride)
void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
#define PART_NOT_AVAILABLE
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
void ff_vdpau_add_data_chunk(MpegEncContext *s, const uint8_t *buf, int buf_size)
int first_field
is 1 for the first field of a field picture 0 otherwise
int dequant_coeff_pps
reinit tables when pps changes
int pic_order_present
pic_order_present_flag
static void idct_add(uint8_t *dest, int line_size, DCTELEM *block)
SPS * sps_buffers[MAX_SPS_COUNT]
void(* h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride)
struct H264Context * thread_context[MAX_THREADS]
int chroma_log2_weight_denom
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
static void flush_change(H264Context *h)
short offset_for_ref_frame[256]
int timing_info_present_flag
static void decode_finish_row(H264Context *h)
Draw edges and report progress for the last MB row.
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
Execute the reference picture marking (memory management control operations).
#define FF_PROFILE_H264_BASELINE
struct MpegEncContext * thread_context[MAX_THREADS]
H264 / AVC / MPEG4 part10 codec data table
int ff_h264_frame_start(H264Context *h)
void ff_thread_await_progress(AVFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
int slice_alpha_c0_offset
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
void ff_h264_remove_all_refs(H264Context *h)
int prev_frame_num
frame_num of the last pic for POC type 1/2
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
static void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int height, int y_offset, int list0, int list1, int *nrefs)
int ff_h264_decode_sei(H264Context *h)
Decode SEI.
int implicit_weight[48][48][2]
int max_contexts
Max number of threads / contexts.
main external API structure.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
static void close(AVCodecParserContext *s)
int ff_h264_check_intra4x4_pred_mode(H264Context *h)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
static void decode_postinit(H264Context *h, int setup_finished)
Run setup operations that must be run after slice header decoding.
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
int height
picture size. must be a multiple of 16
static enum AVPixelFormat hwaccel_pixfmt_list_h264_jpeg_420[]
int16_t(*[2] motion_val)[2]
motion vector table
static void init_dequant8_coeff_table(H264Context *h)
qpel_mc_func put_2tap_qpel_pixels_tab[4][16]
Picture * picture
main picture buffer
int data_partitioning
data partitioning flag from header
void(* pred16x16[4+3+2])(uint8_t *src, ptrdiff_t stride)
H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstre...
int constraint_set_flags
constraint_set[0-3]_flag
static unsigned int get_bits1(GetBitContext *s)
SEI_PicStructType sei_pic_struct
pic_struct in picture timing SEI message
void(* h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride)
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
const uint8_t * field_scan8x8_cavlc_q0
void ff_draw_horiz_band(MpegEncContext *s, int y, int h)
uint32_t(*[6] dequant8_coeff)[64]
static av_cold int h264_decode_end(AVCodecContext *avctx)
int qp_thresh
QP threshold to skip loopfilter.
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int pixel_shift
0 for 8-bit H264, 1 for high-bit-depth H264
#define FF_INPUT_BUFFER_PADDING_SIZE
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, int first_slice)
void ff_er_frame_start(MpegEncContext *s)
static void await_references(H264Context *h)
Wait until all reference frames are available for MC operations.
AVHWAccel * ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
Return the hardware accelerated codec for codec codec_id and pixel format pix_fmt.
void(* h264_weight_func)(uint8_t *block, int stride, int height, int log2_denom, int weight, int offset)
#define FF_BUG_AUTODETECT
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
DSPContext dsp
pointers for accelerated dsp functions
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
6: bottom field, top field, bottom field repeated, in that order
void(* h264_idct8_add4)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[15 *8])
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
#define CODEC_CAP_SLICE_THREADS
int block_offset[2 *(16 *3)]
block_offset[ 0..23] for frame macroblocks block_offset[24..47] for field macroblocks ...
int field_poc[2]
h264 top/bottom POC
int transform_8x8_mode
transform_8x8_mode_flag
static int pred_weight_table(H264Context *h)
int pic_struct_present_flag
av_cold void ff_h264_free_context(H264Context *h)
Free any data that may have been allocated in the H264 context like SPS, PPS etc. ...
qpel_mc_func put_h264_qpel_pixels_tab[4][16]
#define FIELD_OR_MBAFF_PICTURE
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int8_t * qscale_table
QP table.
qpel_mc_func(* qpel_avg)[16]
#define FF_PROFILE_H264_HIGH_10_INTRA
void ff_h264_filter_mb_fast(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize)
void(* clear_blocks)(DCTELEM *blocks)
#define AV_PIX_FMT_YUV422P10
struct MpegEncContext * owner2
pointer to the MpegEncContext that allocated this picture
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
static void idr(H264Context *h)
instantaneous decoder refresh.
static int field_end(H264Context *h, int in_setup)
hardware decoding through VDA
discard all non reference
#define FF_PROFILE_H264_EXTENDED
int mb_height
pic_height_in_map_units_minus1 + 1
qpel_mc_func avg_h264_qpel_pixels_tab[4][16]
static const uint8_t dequant4_coeff_init[6][3]
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
uint16_t * slice_table_base
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
#define AVERROR_INVALIDDATA
H.264 / AVC / MPEG4 part10 motion vector predicion.
Picture last_picture
copy of the previous picture structure.
#define AV_PIX_FMT_YUV422P9
Picture * last_picture_ptr
pointer to the previous picture.
static int execute_decode_slices(H264Context *h, int context_count)
Call decode_slice() for each context.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
int cur_chroma_format_idc
enum AVDiscard skip_loop_filter
int sei_ct_type
Bit set of clock types for fields/frames in picture timing SEI message.
#define AVERROR_PATCHWELCOME
int bit_depth_luma
bit_depth_luma_minus8 + 8
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple)
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
int top_field_first
If the content is interlaced, is top field displayed first.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
const uint16_t ff_h264_mb_sizes[4]
void ff_MPV_common_end(MpegEncContext *s)
void ff_print_debug_info(MpegEncContext *s, AVFrame *pict)
Print debugging info for the given picture.
void(* h264_idct_add16)(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[15 *8])
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
int ff_h264_decode_extradata(H264Context *h)
uint8_t(*[2] top_borders)[(16 *3)*2]
int resync_mb_y
y position of last resync marker
struct AVCodecInternal * internal
Private context used for internal data.
void ff_init_cabac_states(CABACContext *c)
static int fill_filter_caches(H264Context *h, int mb_type)
void(* add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size)
Picture next_picture
copy of the next picture structure.
int key_frame
1 -> keyframe, 0-> not
int linesize
line size, in bytes, may be different from width
int current_slice
current slice number, used to initalize slice_num of each thread/context
int mb_width
pic_width_in_mbs_minus1 + 1
const uint8_t * field_scan_q0
static void free_tables(H264Context *h, int free_rbsp)
int ff_h264_fill_default_ref_list(H264Context *h)
Fill the default_ref_list.
int flags
AVCodecContext.flags (HQ, MV4, ...)
uint8_t field_scan8x8[64]
#define FF_DEBUG_STARTCODE
int workaround_bugs
workaround bugs in encoders which cannot be detected automatically
#define copy_fields(to, from, start_field, end_field)
int chroma_weight_flag[2]
7.4.3.2 chroma_weight_lX_flag
static av_always_inline void mc_part_std(H264Context *h, int n, int square, int height, int delta, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int x_offset, int y_offset, qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, int list0, int list1, int pixel_shift, int chroma_idc)
int8_t * intra4x4_pred_mode
static av_always_inline void dctcoef_set(DCTELEM *mb, int high_bit_depth, int index, int value)
void ff_thread_report_progress(AVFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
int mb_linesize
may be equal to s->linesize or s->linesize * 2, for mbaff
static int clone_slice(H264Context *dst, H264Context *src)
Replicate H264 "master" context to thread contexts.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
int deblocking_filter
disable_deblocking_filter_idc with 1 <-> 0
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
uint8_t(* non_zero_count)[48]
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
int uvlinesize
line size, for chroma in bytes, may be different from width
AVPixelFormat
Pixel format.
This structure stores compressed data.
int sei_recovery_frame_cnt
recovery_frame_cnt from SEI message
static const uint8_t zigzag_scan8x8_cavlc[64]
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
void(* pred8x8l[9+3])(uint8_t *src, int topleft, int topright, ptrdiff_t stride)
void(* pred16x16_add[3])(uint8_t *pix, const int *block_offset, const DCTELEM *block, ptrdiff_t stride)
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
unsigned int rbsp_buffer_size[2]
Context Adaptive Binary Arithmetic Coder.
void ff_MPV_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
#define FF_PROFILE_UNKNOWN
int8_t ref_cache[2][5 *8]
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
int short_ref_count
number of actual short term references
static const AVProfile profiles[]
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)
enum AVColorSpace colorspace