28 #define UNCHECKED_BITSTREAM_READER 1
30 #include "libavutil/avassert.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
58 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
59 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
60 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
61 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
66 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
67 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
68 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10,
69 10,10,10,11,11,11,11,11,11,12,12,12,12,12,12,13,13,13, 13, 13, 13,
74 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
75 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
76 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
77 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
81 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
82 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
83 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
84 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
85 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
86 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
87 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
88 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
89 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
90 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
91 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
92 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
93 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
94 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
95 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
96 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
100 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
101 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
102 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
103 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
104 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
105 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
106 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
107 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
108 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
109 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
110 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
111 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
112 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
113 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
114 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
115 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
120 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
121 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
122 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
123 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
124 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
125 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
126 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
127 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
128 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
129 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
130 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
131 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
132 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
133 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
134 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
135 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
148 0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
152 { 20, 18, 32, 19, 25, 24 },
153 { 22, 19, 35, 21, 28, 26 },
154 { 26, 23, 42, 24, 33, 31 },
155 { 28, 25, 45, 26, 35, 33 },
156 { 32, 28, 51, 30, 40, 38 },
157 { 36, 32, 58, 34, 46, 43 },
161 #if CONFIG_H264_DXVA2_HWACCEL
164 #if CONFIG_H264_VAAPI_HWACCEL
167 #if CONFIG_H264_VDA_HWACCEL
170 #if CONFIG_H264_VDPAU_HWACCEL
178 #if CONFIG_H264_DXVA2_HWACCEL
181 #if CONFIG_H264_VAAPI_HWACCEL
184 #if CONFIG_H264_VDA_HWACCEL
187 #if CONFIG_H264_VDPAU_HWACCEL
202 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
268 offset[2] = (y >> vshift) * src->
linesize[1];
292 for (i = 0; i < 2; i++) {
297 memset((
uint8_t*)pic + off, 0,
sizeof(*pic) - off);
333 for (i = 0; i < 2; i++) {
349 for (i = 0; i < 2; i++)
404 const int b4_stride = h->
mb_width * 4 + 1;
405 const int b4_array_size = b4_stride * h->
mb_height * 4;
470 for (i = 0; i < 2; i++) {
483 return (ret < 0) ? ret :
AVERROR(ENOMEM);
488 if (pic->
f.
data[0] == NULL)
503 if (i == MAX_PICTURE_COUNT)
520 static const int8_t top[12] = {
523 static const int8_t left[12] = {
529 for (i = 0; i < 4; i++) {
533 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
543 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
544 for (i = 0; i < 4; i++)
549 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
572 "out of range intra chroma pred mode at %d %d\n",
581 "top block unavailable for requested intra mode at %d %d\n",
597 "left block unavailable for requested intra mode at %d %d\n",
607 int *dst_length,
int *consumed,
int length)
620 #define STARTCODE_TEST \
621 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
622 if (src[i + 2] != 3) { \
629 #if HAVE_FAST_UNALIGNED
630 #define FIND_FIRST_ZERO \
631 if (i > 0 && !src[i]) \
637 for (i = 0; i + 1 <
length; i += 9) {
639 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
640 0x8000800080008080ULL))
647 for (i = 0; i + 1 <
length; i += 5) {
649 (
AV_RN32A(src + i) - 0x01000101U)) &
658 for (i = 0; i + 1 <
length; i += 2) {
661 if (i > 0 && src[i - 1] == 0)
683 memcpy(dst, src, length);
690 while (si + 2 < length) {
692 if (src[si + 2] > 3) {
693 dst[di++] = src[si++];
694 dst[di++] = src[si++];
695 }
else if (src[si] == 0 && src[si + 1] == 0) {
696 if (src[si + 2] == 3) {
705 dst[di++] = src[si++];
708 dst[di++] = src[si++];
731 for (r = 1; r < 9; r++) {
740 int height,
int y_offset,
int list)
743 int filter_height_down = (raw_my & 3) ? 3 : 0;
744 int full_my = (raw_my >> 2) + y_offset;
745 int bottom = full_my + filter_height_down +
height;
749 return FFMAX(0, bottom);
753 int height,
int y_offset,
int list0,
754 int list1,
int *nrefs)
770 if (refs[0][ref_n] < 0)
772 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
783 if (refs[1][ref_n] < 0)
785 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
797 const int mb_xy = h->
mb_xy;
800 int nrefs[2] = { 0 };
803 memset(refs, -1,
sizeof(refs));
823 for (i = 0; i < 4; i++) {
826 int y_offset = (i & 2) << 2;
830 IS_DIR(sub_mb_type, 0, 0),
831 IS_DIR(sub_mb_type, 0, 1),
835 IS_DIR(sub_mb_type, 0, 0),
836 IS_DIR(sub_mb_type, 0, 1),
839 IS_DIR(sub_mb_type, 0, 0),
840 IS_DIR(sub_mb_type, 0, 1),
844 IS_DIR(sub_mb_type, 0, 0),
845 IS_DIR(sub_mb_type, 0, 1),
848 IS_DIR(sub_mb_type, 0, 0),
849 IS_DIR(sub_mb_type, 0, 1),
854 for (j = 0; j < 4; j++) {
855 int sub_y_offset = y_offset + 2 * (j & 2);
857 IS_DIR(sub_mb_type, 0, 0),
858 IS_DIR(sub_mb_type, 0, 1),
865 for (list = h->
list_count - 1; list >= 0; list--)
866 for (ref = 0; ref < 48 && nrefs[list]; ref++) {
867 int row = refs[list][ref];
872 int pic_height = 16 * h->
mb_height >> ref_field_picture;
879 FFMIN((row >> 1) - !(row & 1),
883 FFMIN((row >> 1), pic_height - 1),
887 FFMIN(row * 2 + ref_field,
892 FFMIN(row, pic_height - 1),
896 FFMIN(row, pic_height - 1),
908 int src_x_offset,
int src_y_offset,
911 int pixel_shift,
int chroma_idc)
915 const int luma_xy = (mx & 3) + ((my & 3) << 2);
920 int extra_height = 0;
922 const int full_mx = mx >> 2;
923 const int full_my = my >> 2;
924 const int pic_width = 16 * h->
mb_width;
933 if (full_mx < 0 - extra_width ||
934 full_my < 0 - extra_height ||
935 full_mx + 16 > pic_width + extra_width ||
936 full_my + 16 > pic_height + extra_height) {
940 16 + 5, 16 + 5 , full_mx - 2,
941 full_my - 2, pic_width, pic_height);
953 if (chroma_idc == 3 ) {
960 full_mx - 2, full_my - 2,
961 pic_width, pic_height);
974 full_mx - 2, full_my - 2,
975 pic_width, pic_height);
984 ysh = 3 - (chroma_idc == 2 );
985 if (chroma_idc == 1 &&
MB_FIELD(h)) {
988 emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
991 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) +
993 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) +
998 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
999 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
1003 height >> (chroma_idc == 1 ),
1004 mx & 7, (my << (chroma_idc == 2 )) & 7);
1008 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
1009 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
1012 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
1013 mx & 7, (my << (chroma_idc == 2 )) & 7);
1020 int x_offset,
int y_offset,
1025 int list0,
int list1,
1026 int pixel_shift,
int chroma_idc)
1031 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1032 if (chroma_idc == 3 ) {
1033 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1034 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1035 }
else if (chroma_idc == 2 ) {
1036 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1037 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1039 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1040 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1042 x_offset += 8 * h->
mb_x;
1048 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1049 qpix_op, chroma_op, pixel_shift, chroma_idc);
1052 chroma_op = chroma_avg;
1058 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1059 qpix_op, chroma_op, pixel_shift, chroma_idc);
1067 int x_offset,
int y_offset,
1074 int list0,
int list1,
1075 int pixel_shift,
int chroma_idc)
1079 dest_y += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1080 if (chroma_idc == 3 ) {
1082 chroma_weight_avg = luma_weight_avg;
1083 chroma_weight_op = luma_weight_op;
1084 dest_cb += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1085 dest_cr += (2 * x_offset << pixel_shift) + 2 * y_offset * h->
mb_linesize;
1086 }
else if (chroma_idc == 2 ) {
1088 dest_cb += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1089 dest_cr += (x_offset << pixel_shift) + 2 * y_offset * h->
mb_uvlinesize;
1091 chroma_height = height >> 1;
1092 dest_cb += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1093 dest_cr += (x_offset << pixel_shift) + y_offset * h->
mb_uvlinesize;
1095 x_offset += 8 * h->
mb_x;
1098 if (list0 && list1) {
1108 dest_y, dest_cb, dest_cr,
1109 x_offset, y_offset, qpix_put, chroma_put,
1110 pixel_shift, chroma_idc);
1112 tmp_y, tmp_cb, tmp_cr,
1113 x_offset, y_offset, qpix_put, chroma_put,
1114 pixel_shift, chroma_idc);
1118 int weight1 = 64 - weight0;
1120 height, 5, weight0, weight1, 0);
1122 chroma_height, 5, weight0, weight1, 0);
1124 chroma_height, 5, weight0, weight1, 0);
1126 luma_weight_avg(dest_y, tmp_y, h->
mb_linesize, height,
1132 chroma_weight_avg(dest_cb, tmp_cb, h->
mb_uvlinesize, chroma_height,
1138 chroma_weight_avg(dest_cr, tmp_cr, h->
mb_uvlinesize, chroma_height,
1146 int list = list1 ? 1 : 0;
1149 mc_dir_part(h, ref, n, square, height, delta, list,
1150 dest_y, dest_cb, dest_cr, x_offset, y_offset,
1151 qpix_put, chroma_put, pixel_shift, chroma_idc);
1171 int pixel_shift,
int chroma_idc)
1180 int off = (mx << pixel_shift) +
1182 (64 << pixel_shift);
1184 if (chroma_idc == 3 ) {
1188 off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (h->
mb_x&7))*h->
uvlinesize;
1213 for (i = 0; i < 3; i++)
1221 if (free_rbsp && h->
DPB) {
1225 }
else if (h->
DPB) {
1264 for (i = 0; i < 6; i++) {
1266 for (j = 0; j < i; j++)
1275 for (q = 0; q < max_qp + 1; q++) {
1278 for (x = 0; x < 64; x++)
1290 for (i = 0; i < 6; i++) {
1292 for (j = 0; j < i; j++)
1301 for (q = 0; q < max_qp + 1; q++) {
1304 for (x = 0; x < 16; x++)
1319 for (i = 0; i < 6; i++)
1320 for (x = 0; x < 16; x++)
1323 for (i = 0; i < 6; i++)
1324 for (x = 0; x < 64; x++)
1342 big_mb_num *
sizeof(uint16_t),
fail)
1359 big_mb_num *
sizeof(uint32_t),
fail);
1361 big_mb_num *
sizeof(uint32_t),
fail);
1363 for (x = 0; x < h->
mb_width; x++) {
1365 const int b_xy = 4 * x + 4 * y * h->
b_stride;
1426 int yc_size = y_size + 2 * c_size;
1479 for (i = 0; i < yc_size; i++)
1490 int parse_extradata);
1497 if (!buf || size <= 0)
1501 int i, cnt, nalsize;
1502 const unsigned char *p =
buf;
1514 cnt = *(p + 5) & 0x1f;
1516 for (i = 0; i < cnt; i++) {
1518 if(nalsize > size - (p-buf))
1523 "Decoding sps %d from avcC failed\n", i);
1530 for (i = 0; i < cnt; i++) {
1532 if(nalsize > size - (p-buf))
1537 "Decoding pps %d from avcC failed\n", i);
1643 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
1644 #undef REBASE_PICTURE
1645 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
1646 ((pic && pic >= old_ctx->DPB && \
1647 pic < old_ctx->DPB + MAX_PICTURE_COUNT) ? \
1648 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
1656 for (i = 0; i <
count; i++) {
1657 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1669 for (i = 0; i <
count; i++) {
1670 if (to[i] && !from[i])
1672 else if (from[i] && !to[i])
1676 memcpy(to[i], from[i], size);
1698 #define copy_fields(to, from, start_field, end_field) \
1699 memcpy(&to->start_field, &from->start_field, \
1700 (char *)&to->end_field - (char *)&to->start_field)
1711 int context_reinitialized = 0;
1718 (h->
width != h1->width ||
1719 h->
height != h1->height ||
1733 h->
width = h1->width;
1752 context_reinitialized = 1;
1777 memcpy(h, h1, offsetof(
H264Context, intra_pcm_ptr));
1778 memcpy(&h->
cabac, &h1->cabac,
1785 memset(&h->
er, 0,
sizeof(h->
er));
1786 memset(&h->
me, 0,
sizeof(h->
me));
1787 memset(&h->
mb, 0,
sizeof(h->
mb));
1797 for (i = 0; i < 2; i++) {
1802 if (h1->context_initialized) {
1842 if (h1->DPB[i].f.data[0] &&
1869 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1871 for (i = 0; i < 6; i++)
1873 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
1875 for (i = 0; i < 6; i++)
1877 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
1894 if (context_reinitialized)
1971 for (i = 0; i < 16; i++) {
1975 for (i = 0; i < 16; i++) {
2012 int i, pics, out_of_order, out_idx;
2112 for (i = 0; 1; i++) {
2124 out_of_order =
FFMAX(out_of_order, 1);
2189 int linesize,
int uvlinesize,
2199 src_cb -= uvlinesize;
2200 src_cr -= uvlinesize;
2206 AV_COPY128(top_border, src_y + 15 * linesize);
2208 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
2212 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2213 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
2214 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
2215 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
2217 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
2218 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
2220 }
else if (chroma422) {
2222 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
2223 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
2225 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
2226 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
2230 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
2231 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
2233 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
2234 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
2248 AV_COPY128(top_border, src_y + 16 * linesize);
2250 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
2255 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
2256 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
2257 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
2258 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
2260 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
2261 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
2263 }
else if (chroma422) {
2265 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
2266 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
2268 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
2269 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
2273 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
2274 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
2276 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
2277 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
2285 int linesize,
int uvlinesize,
2286 int xchg,
int chroma444,
2287 int simple,
int pixel_shift)
2289 int deblock_topleft;
2308 deblock_topleft = (h->
mb_x > 0);
2312 src_y -= linesize + 1 + pixel_shift;
2313 src_cb -= uvlinesize + 1 + pixel_shift;
2314 src_cr -= uvlinesize + 1 + pixel_shift;
2319 #define XCHG(a, b, xchg) \
2320 if (pixel_shift) { \
2322 AV_SWAP64(b + 0, a + 0); \
2323 AV_SWAP64(b + 8, a + 8); \
2333 if (deblock_topleft) {
2334 XCHG(top_border_m1 + (8 << pixel_shift),
2335 src_y - (7 << pixel_shift), 1);
2337 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
2338 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
2341 src_y + (17 << pixel_shift), 1);
2345 if (deblock_topleft) {
2346 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2347 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2349 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
2350 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
2351 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
2352 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
2354 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
2355 XCHG(h->
top_borders[top_idx][h->
mb_x + 1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
2358 if (deblock_topleft) {
2359 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
2360 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
2362 XCHG(top_border + (16 << pixel_shift), src_cb + 1 + pixel_shift, 1);
2363 XCHG(top_border + (24 << pixel_shift), src_cr + 1 + pixel_shift, 1);
2372 if (high_bit_depth) {
2381 if (high_bit_depth) {
2388 int mb_type,
int is_h264,
2390 int transform_bypass,
2400 block_offset += 16 * p;
2403 if (transform_bypass) {
2410 for (i = 0; i < 16; i += 4) {
2411 uint8_t *
const ptr = dest_y + block_offset[i];
2414 h->
hpc.
pred8x8l_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2420 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2421 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2423 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2428 if (transform_bypass) {
2435 for (i = 0; i < 16; i++) {
2436 uint8_t *
const ptr = dest_y + block_offset[i];
2440 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2448 if (!topright_avail) {
2450 tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
2451 topright = (
uint8_t *)&tr_high;
2453 tr = ptr[3 - linesize] * 0x01010101
u;
2457 topright = ptr + (4 << pixel_shift) - linesize;
2461 h->
hpc.
pred4x4[dir](ptr, topright, linesize);
2465 if (nnz == 1 &&
dctcoef_get(h->
mb, pixel_shift, i * 16 + p * 256))
2466 idct_dc_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2468 idct_add(ptr, h->
mb + (i * 16 + p * 256 << pixel_shift), linesize);
2479 if (!transform_bypass)
2484 static const uint8_t dc_mapping[16] = {
2485 0 * 16, 1 * 16, 4 * 16, 5 * 16,
2486 2 * 16, 3 * 16, 6 * 16, 7 * 16,
2487 8 * 16, 9 * 16, 12 * 16, 13 * 16,
2488 10 * 16, 11 * 16, 14 * 16, 15 * 16
2490 for (i = 0; i < 16; i++)
2492 pixel_shift, dc_mapping[i],
2504 int is_h264,
int simple,
2505 int transform_bypass,
2513 block_offset += 16 * p;
2517 if (transform_bypass) {
2522 h->
mb + (p * 256 << pixel_shift),
2525 for (i = 0; i < 16; i++)
2529 h->
mb + (i * 16 + p * 256 << pixel_shift),
2534 h->
mb + (p * 256 << pixel_shift),
2538 }
else if (h->
cbp & 15) {
2539 if (transform_bypass) {
2540 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
2543 for (i = 0; i < 16; i += di)
2546 h->
mb + (i * 16 + p * 256 << pixel_shift),
2551 h->
mb + (p * 256 << pixel_shift),
2556 h->
mb + (p * 256 << pixel_shift),
2562 for (i = 0; i < 16; i++)
2565 uint8_t *
const ptr = dest_y + block_offset[i];
2587 const int mb_xy = h->
mb_xy;
2594 hl_decode_mb_444_complex(h);
2596 hl_decode_mb_444_simple_8(h);
2597 }
else if (is_complex) {
2598 hl_decode_mb_complex(h);
2600 hl_decode_mb_simple_16(h);
2602 hl_decode_mb_simple_8(h);
2608 int luma_def, chroma_def;
2618 for (list = 0; list < 2; list++) {
2621 for (i = 0; i < h->
ref_count[list]; i++) {
2622 int luma_weight_flag, chroma_weight_flag;
2625 if (luma_weight_flag) {
2640 if (chroma_weight_flag) {
2642 for (j = 0; j < 2; j++) {
2653 for (j = 0; j < 2; j++) {
2674 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2676 for (i = 0; i < 2; i++) {
2708 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
2710 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
2714 int td = av_clip(poc1 - poc0, -128, 127);
2716 int tb = av_clip(cur_poc - poc0, -128, 127);
2717 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
2718 int dist_scale_factor = (tb * tx + 32) >> 8;
2719 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
2720 w = 64 - dist_scale_factor;
2833 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2844 expected_delta_per_poc_cycle = 0;
2849 if (abs_frame_num > 0) {
2853 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2854 for (i = 0; i <= frame_num_in_poc_cycle; i++)
2862 field_poc[0] = expectedpoc + h->
delta_poc[0];
2878 pic_field_poc[0] = field_poc[0];
2880 pic_field_poc[1] = field_poc[1];
2881 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
2892 for (i = 0; i < 16; i++) {
2893 #define T(x) (x >> 2) | ((x << 2) & 0xF)
2898 for (i = 0; i < 64; i++) {
2899 #define T(x) (x >> 3) | ((x & 7) << 3)
2947 "hardware accelerator failed to decode picture\n");
3043 "Reenabling low delay requires a codec flush.\n");
3053 "Different chroma and luma bit depth");
3063 "VDPAU decoding does not support video colorspace.\n");
3188 if (width <= 0 || height <= 0) {
3241 "Could not allocate memory for h264\n");
3252 " reducing to %d\n", nb_slices, max_slices);
3253 nb_slices = max_slices;
3316 int num_ref_idx_active_override_flag;
3328 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
3330 if (num_ref_idx_active_override_flag) {
3369 unsigned int first_mb_in_slice;
3370 unsigned int pps_id;
3372 unsigned int slice_type, tmp, i, j;
3373 int last_pic_structure, last_pic_droppable;
3375 int needs_reinit = 0;
3376 int field_pic_flag, bottom_field_flag;
3383 if (first_mb_in_slice == 0) {
3399 if (slice_type > 9) {
3401 "slice type too large (%d) at %d %d\n",
3405 if (slice_type > 4) {
3425 "non-existing PPS %u referenced\n",
3433 "non-existing SPS %u referenced\n",
3528 "h264_slice_header_init() failed\n");
3535 "Cannot (re-)initialize context during parallel decoding.\n");
3545 "h264_slice_header_init() failed\n");
3570 if (field_pic_flag) {
3584 "Changing field mode (%d -> %d) between slices is not allowed\n",
3591 "unset cur_pic_ptr on %d. slice\n",
3602 if (unwrap_prev_frame_num > h->
frame_num)
3603 unwrap_prev_frame_num -= max_frame_num;
3607 if (unwrap_prev_frame_num < 0)
3608 unwrap_prev_frame_num += max_frame_num;
3655 "Invalid field mode combination %d/%d\n",
3660 }
else if (last_pic_droppable != h->
droppable) {
3662 "Found reference and non-reference fields in the same frame, which");
3783 first_mb_in_slice >= h->
mb_num) {
3853 for (i = 0; i < 2; i++) {
3917 "deblocking_filter_idc %u out of range\n", tmp);
3930 "deblocking filter parameters %d %d out of range\n",
3955 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3960 "Deblocking switched inside frame.\n");
3985 for (j = 0; j < 2; j++) {
3988 for (i = 0; i < 16; i++) {
3990 if (j < h->list_count && i < h->ref_count[j] &&
4009 for (i = 0; i < 16; i++)
4012 ref2frm[18 + 1] = -1;
4013 for (i = 16; i < 48; i++)
4014 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
4024 "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",
4065 int mb_type,
int top_xy,
4068 int left_type[LEFT_MBS],
4069 int mb_xy,
int list)
4076 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
4077 const int b8_xy = 4 * top_xy + 2;
4080 ref_cache[0 - 1 * 8] =
4081 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
4082 ref_cache[2 - 1 * 8] =
4083 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
4092 const int b8_xy = 4 * left_xy[
LTOP] + 1;
4099 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
4100 ref_cache[-1 + 16] =
4101 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
4109 ref_cache[-1 + 16] =
4127 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
4128 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
4129 AV_WN32A(&ref_cache[0 * 8], ref01);
4130 AV_WN32A(&ref_cache[1 * 8], ref01);
4131 AV_WN32A(&ref_cache[2 * 8], ref23);
4132 AV_WN32A(&ref_cache[3 * 8], ref23);
4137 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
4138 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
4139 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
4140 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
4150 const int mb_xy = h->
mb_xy;
4161 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
4166 if (left_mb_field_flag != curr_mb_field_flag)
4169 if (curr_mb_field_flag)
4172 if (left_mb_field_flag != curr_mb_field_flag)
4186 if (qp <= qp_thresh &&
4187 (left_xy[
LTOP] < 0 ||
4193 if ((left_xy[
LTOP] < 0 ||
4208 left_type[
LTOP] = left_type[
LBOT] = 0;
4213 left_type[
LTOP] = left_type[
LBOT] = 0;
4223 top_type, left_type, mb_xy, 0);
4226 top_type, left_type, mb_xy, 1);
4230 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
4231 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
4232 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
4233 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
4238 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
4241 if (left_type[
LTOP]) {
4243 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
4244 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
4245 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
4246 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
4253 nnz_cache[4 + 8 * 0] =
4254 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
4255 nnz_cache[6 + 8 * 0] =
4256 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
4259 nnz_cache[3 + 8 * 1] =
4260 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
4263 nnz_cache[3 + 8 * 3] =
4264 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
4268 nnz_cache[
scan8[0]] =
4269 nnz_cache[scan8[1]] =
4270 nnz_cache[scan8[2]] =
4271 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
4273 nnz_cache[scan8[0 + 4]] =
4274 nnz_cache[scan8[1 + 4]] =
4275 nnz_cache[scan8[2 + 4]] =
4276 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
4278 nnz_cache[scan8[0 + 8]] =
4279 nnz_cache[scan8[1 + 8]] =
4280 nnz_cache[scan8[2 + 8]] =
4281 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
4283 nnz_cache[scan8[0 + 12]] =
4284 nnz_cache[scan8[1 + 12]] =
4285 nnz_cache[scan8[2 + 12]] =
4286 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
4295 uint8_t *dest_y, *dest_cb, *dest_cr;
4296 int linesize, uvlinesize, mb_x, mb_y;
4303 for (mb_x = start_x; mb_x < end_x; mb_x++)
4304 for (mb_y = end_mb_y -
FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
4318 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
4320 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4323 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
4348 linesize, uvlinesize);
4351 dest_cr, linesize, uvlinesize);
4383 if ((top + height) >= pic_height)
4384 height += deblock_border;
4385 top -= deblock_border;
4388 if (top >= pic_height || (top + height) < 0)
4391 height =
FFMIN(height, pic_height - top);
4407 int endx,
int endy,
int status)
4419 int lf_x_start = h->
mb_x;
4475 if (h->
mb_x >= lf_x_start)
4483 "error while decoding MB %d %d, bytestream (%td)\n",
4493 h->
mb_x = lf_x_start = 0;
4508 if (h->
mb_x > lf_x_start)
4532 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
4540 h->
mb_x = lf_x_start = 0;
4577 if (h->
mb_x > lf_x_start)
4607 if (context_count == 1) {
4611 for (i = 1; i < context_count; i++) {
4620 NULL, context_count,
sizeof(
void *));
4629 for (i = 1; i < context_count; i++)
4640 int parse_extradata)
4648 int nals_needed = 0;
4651 int first_slice = 0;
4667 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
4669 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
4673 for (; pass <= 1; pass++) {
4676 next_avc = h->
is_avc ? 0 : buf_size;
4686 if (buf_index >= next_avc) {
4691 nalsize = (nalsize << 8) | buf[buf_index++];
4692 if (nalsize <= 0 || nalsize > buf_size - buf_index) {
4694 "AVC: nal size %d\n", nalsize);
4697 next_avc = buf_index + nalsize;
4700 for (; buf_index + 3 < next_avc; buf_index++)
4702 if (buf[buf_index] == 0 &&
4703 buf[buf_index + 1] == 0 &&
4704 buf[buf_index + 2] == 1)
4707 if (buf_index + 3 >= buf_size) {
4708 buf_index = buf_size;
4713 if (buf_index >= next_avc)
4720 &consumed, next_avc - buf_index);
4721 if (ptr == NULL || dst_length < 0) {
4725 i = buf_index + consumed;
4727 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
4728 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
4732 while(dst_length > 0 && ptr[dst_length - 1] == 0)
4734 bit_length = !dst_length ? 0
4741 if (h->
is_avc && (nalsize != consumed) && nalsize)
4743 "AVC: Consumed only %d bytes instead of %d\n",
4746 buf_index += consumed;
4757 nals_needed = nal_index;
4764 nals_needed = nal_index;
4788 if (parse_extradata) {
4796 "Ignoring NAL %d in global header/extradata\n",
4810 "Invalid mix of idr and non-idr slices\n");
4873 &buf[buf_index - consumed],
4881 sizeof(start_code));
4883 &buf[buf_index - consumed],
4930 "SPS decoding failure, trying again with the complete NAL\n");
4932 av_assert0(next_avc - buf_index + consumed == nalsize);
4933 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
4936 8*(next_avc - buf_index + consumed - 1));
4966 else if (err == 1) {
4988 return (ret < 0) ? ret : buf_index;
4998 if (pos + 10 > buf_size)
5017 for (i = 0; i < 3; i++) {
5022 dst->
data[i] += off;
5031 int buf_size = avpkt->
size;
5042 if (buf_size == 0) {
5074 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
5075 int cnt= buf[5]&0x1f;
5079 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
5088 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
5108 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
5136 assert(pict->
data[0] || !*got_frame);
5222 #if CONFIG_H264_VDPAU_DECODER
5223 AVCodec ff_h264_vdpau_decoder = {
5224 .
name =
"h264_vdpau",
5225 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
#define AV_PIX_FMT_YUV444P12
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free
Picture default_ref_list[2][32]
base reference list for all slices of a coded picture
#define FF_BUG_AUTODETECT
autodetection
#define PICT_BOTTOM_FIELD
void ff_h264_direct_dist_scale_factor(H264Context *const h)
#define AV_PIX_FMT_GBR24P
int video_signal_type_present_flag
void(* h264_idct_add)(uint8_t *dst, int16_t *block, int stride)
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.
int ff_thread_can_start_frame(AVCodecContext *avctx)
int ff_h264_decode_seq_parameter_set(H264Context *h)
Decode SPS.
discard all frames except keyframes
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
uint8_t * edge_emu_buffer
#define CONFIG_SVQ3_DECODER
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).
#define MAX_PICTURE_COUNT
unsigned int top_samples_available
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.
#define CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
#define AVERROR_PATCHWELCOME
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)
static int shift(int a, int b)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
GetBitContext * intra_gb_ptr
This structure describes decoded (raw) audio or video data.
#define FF_PROFILE_H264_CAVLC_444
void(* pred8x8l_add[2])(uint8_t *pix, int16_t *block, ptrdiff_t stride)
static void copy_parameter_set(void **to, void **from, int count, int size)
static const AVClass h264_class
void(* emulated_edge_mc)(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride, 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...
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
the normal 2^n-1 "JPEG" YUV ranges
int coded_width
Bitstream width / height, may be different from width/height e.g.
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.
uint8_t field_scan8x8_q0[64]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int sync
did we had a keyframe or recovery point
int chroma_qp_index_offset[2]
const uint8_t * bytestream_end
static av_cold int init(AVCodecContext *avctx)
H264ChromaContext h264chroma
#define FF_PROFILE_H264_CONSTRAINED
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
int luma_weight_flag[2]
7.4.3.2 luma_weight_lX_flag
#define FF_PROFILE_H264_BASELINE
MMCO mmco[MAX_MMCO_COUNT]
memory management control operations buffer.
void ff_er_frame_end(ERContext *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 void init_dequant_tables(H264Context *h)
int bitstream_restriction_flag
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int repeat_pict
When decoding, this signals how much the picture must be delayed.
int needs_realloc
Picture needs to be reallocated (eg due to a frame size change)
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
#define AV_PIX_FMT_GBRP10
static void unref_picture(H264Context *h, Picture *pic)
#define VP_START
< current MB is the first after a resync marker
AVBufferPool * mb_type_pool
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
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...
static void release_unused_pictures(H264Context *h, int remove_current)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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 av_always_inline void fill_filter_caches_inter(H264Context *h, int mb_type, int top_xy, int left_xy[LEFT_MBS], int top_type, int left_type[LEFT_MBS], int mb_xy, int list)
AVBufferPool * ref_index_pool
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end w...
static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
uint8_t zigzag_scan8x8_cavlc[64]
av_cold void ff_h264chroma_init(H264ChromaContext *c, int bit_depth)
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.
void ff_h264_decode_init_vlc(void)
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...
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
4: bottom field, top field, in that order
static int get_lowest_part_list_y(H264Context *h, Picture *pic, int n, int height, int y_offset, int list)
#define FF_PROFILE_H264_EXTENDED
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)
void(* h264_add_pixels4_clear)(uint8_t *dst, int16_t *block, int stride)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
void ff_h264_init_cabac_states(H264Context *h)
#define USES_LIST(a, list)
does this mb use listX, note does not work if subMBs
void ff_vdpau_h264_picture_complete(H264Context *h)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
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)
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
static const uint8_t div6[QP_MAX_NUM+1]
void(* pred16x16_add[3])(uint8_t *pix, const int *block_offset, int16_t *block, ptrdiff_t stride)
enum AVDiscard skip_frame
Skip decoding for selected frames.
#define FF_PROFILE_H264_HIGH_422_INTRA
int ff_h264_decode_ref_pic_list_reordering(H264Context *h)
static const uint8_t golomb_to_pict_type[5]
BYTE int const BYTE * srcp
int ref_poc[2][2][32]
h264 POCs of the frames/fields used as reference (FIXME need per slice)
void(* h264_idct_add16)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 *8])
unsigned int crop_top
frame_cropping_rect_top_offset
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)
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 ...
int deblocking_filter_parameters_present
deblocking_filter_parameters_present_flag
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint32_t(*[6] dequant4_coeff)[16]
#define CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries...
av_cold void ff_h264qpel_init(H264QpelContext *c, int bit_depth)
const char * av_default_item_name(void *ctx)
Return the context name.
int ref_count[2][2]
number of entries in ref_poc (FIXME need per slice)
int prev_frame_num_offset
for POC type 2
unsigned int crop_left
frame_cropping_rect_left_offset
int offset_for_non_ref_pic
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void ff_h264_reset_sei(H264Context *h)
Reset SEI values at the beginning of the frame.
int gaps_in_frame_num_allowed_flag
int luma_weight[48][2][2]
int bit_depth_chroma
bit_depth_chroma_minus8 + 8
enum AVColorPrimaries color_primaries
static const uint8_t offset[511][2]
static av_cold int end(AVCodecContext *avctx)
static int find_unused_picture(H264Context *h)
Multithreading support functions.
Picture ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
#define CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
int cabac
entropy_coding_mode_flag
qpel_mc_func(* qpel_put)[16]
#define LUMA_DC_BLOCK_INDEX
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
unsigned int crop_right
frame_cropping_rect_right_offset
const char * name
Name of the codec implementation.
unsigned int last_ref_count[2]
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
void ff_h264_fill_mbaff_ref_list(H264Context *h)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int transform_bypass
qpprime_y_zero_transform_bypass_flag
void(* h264_add_pixels8_clear)(uint8_t *dst, int16_t *block, int stride)
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.
struct AVCodecInternal * internal
Private context used for internal data.
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
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_LOG_VERBOSE
Detailed information.
AVBufferRef * mb_type_buf
#define SLICE_FLAG_CODED_ORDER
draw_horiz_band() is called in coded order instead of display
int interlaced_frame
The content of the picture is interlaced.
#define MAX_DELAYED_PIC_COUNT
#define AV_NUM_DATA_POINTERS
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
void(* pred4x4[9+3+3])(uint8_t *src, const uint8_t *topright, ptrdiff_t stride)
Picture * next_output_pic
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int luma_log2_weight_denom
qpel_mc_func avg_h264_qpel_pixels_tab[4][16]
#define FF_PROFILE_H264_HIGH
static int h264_set_parameter_from_sps(H264Context *h)
int chroma_weight[48][2][2][2]
static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
int last_pocs[MAX_DELAYED_PIC_COUNT]
static void init_dequant4_coeff_table(H264Context *h)
static int pic_is_unused(H264Context *h, Picture *pic)
#define AV_PIX_FMT_YUV422P14
H.264 / AVC / MPEG4 part10 codec.
static int get_bits_left(GetBitContext *gb)
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
int mb_aff
mb_adaptive_frame_field_flag
enum AVColorTransferCharacteristic color_trc
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...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int16_t mb_luma_dc[3][16 *2]
static enum AVPixelFormat h264_hwaccel_pixfmt_list_jpeg_420[]
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static int decode_slice_header(H264Context *h, H264Context *h0)
Decode a slice header.
static const uint8_t field_scan8x8_cavlc[64+1]
static int get_consumed_bytes(int pos, int buf_size)
Return the number of bytes consumed for building the current frame.
int poc_type
pic_order_cnt_type
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
static const uint8_t dequant8_coeff_init_scan[16]
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)
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
ParseContext parse_context
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.
#define AV_PIX_FMT_YUV444P14
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
GetBitContext * inter_gb_ptr
#define ALZHEIMER_DC_L0T_PRED8x8
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
int active_thread_type
Which multithreading methods are in use by the codec.
#define FF_PROFILE_H264_HIGH_10_INTRA
int mb_field_decoding_flag
#define AV_PIX_FMT_YUV420P12
int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
static void flush_dpb(AVCodecContext *avctx)
static int h264_slice_header_init(H264Context *, int)
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void(* h264_idct8_add)(uint8_t *dst, int16_t *block, int stride)
static const AVOption h264_options[]
void(* decode_mb)(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
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...
struct Picture * next_pic
int direct_spatial_mv_pred
static int h264_frame_start(H264Context *h)
void(* h264_luma_dc_dequant_idct)(int16_t *output, int16_t *input, int qmul)
int weighted_pred
weighted_pred_flag
#define FF_DEBUG_STARTCODE
int overread_index
the index into ParseContext.buffer of the overread bytes
static void predict_field_decoding_flag(H264Context *h)
void ff_init_cabac_states(void)
int ff_h264_decode_mb_cavlc(H264Context *h)
Decode a macroblock.
av_cold void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, int chroma_format_idc)
Set the intra prediction function pointers.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
int valid_recovery_point
Are the SEI recovery points looking valid.
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
static void er_add_slice(H264Context *h, int startx, int starty, int endx, int endy, int status)
static int output_frame(H264Context *h, AVFrame *dst, Picture *srcp)
Libavcodec external API header.
AVPixelFormat
Pixel format.
qpel_mc_func put_h264_qpel_pixels_tab[4][16]
int delta_pic_order_always_zero_flag
#define CODEC_FLAG_LOW_DELAY
Force low delay.
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 offset_for_top_to_bottom_field
#define IN_RANGE(a, b, size)
#define FIELD_OR_MBAFF_PICTURE(h)
int priv_data_size
Size of HW accelerator private data.
uint8_t zigzag_scan8x8[64]
#define AV_PIX_FMT_GBRP12
static const uint8_t scan8[16 *3+3]
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int crop
frame_cropping_flag
uint8_t * error_status_table
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstre...
AVBufferRef * hwaccel_priv_buf
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
#define CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
int ff_pred_weight_table(H264Context *h)
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]
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void copy_picture_range(Picture **to, Picture **from, int count, H264Context *new_base, H264Context *old_base)
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
void ff_svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc)
useful rectangle filling function
#define FF_ARRAY_ELEMS(a)
int refs
number of reference frames
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
unsigned int left_samples_available
AVBufferRef * motion_val_buf[2]
static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
#define FF_PROFILE_H264_HIGH_444_INTRA
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band...
int ref_frame_count
num_ref_frames
enum AVPictureType pict_type
Picture type of the frame.
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)
struct Picture * last_pic
int frame_num_offset
for POC type 2
uint8_t * data
The data buffer.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int overread
the number of bytes which where irreversibly read from the next frame
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
uint8_t field_scan8x8_cavlc[64]
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
int colour_description_present_flag
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static const AVClass h264_vdpau_class
int width
picture width / height.
#define AV_PIX_FMT_YUV422P12
#define FF_PROFILE_H264_HIGH_10
int16_t(*[2] motion_val)[2]
void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
int long_ref_count
number of actual long term references
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void(* h264_idct_dc_add)(uint8_t *dst, int16_t *block, int stride)
static const uint8_t field_scan8x8[64+1]
static void implicit_weight_table(H264Context *h, int field)
Initialize implicit_weight table.
void * hwaccel_picture_private
hardware accelerator private data
static av_always_inline int dctcoef_get(int16_t *mb, int high_bit_depth, int index)
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.
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length)
Decode PPS.
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)
int direct_8x8_inference_flag
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.
void(* pred4x4_add[2])(uint8_t *pix, int16_t *block, ptrdiff_t stride)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice)
#define FF_PROFILE_UNKNOWN
static int decode_slice(struct AVCodecContext *avctx, void *arg)
int ff_set_ref_count(H264Context *h)
unsigned int topright_samples_available
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)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
static void loop_filter(H264Context *h, int start_x, int end_x)
uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]
#define PART_NOT_AVAILABLE
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static void flush(AVCodecContext *avctx)
static const uint8_t dequant8_coeff_init[6][6]
static const uint8_t field_scan[16+1]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int dequant_coeff_pps
reinit tables when pps changes
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
int pic_order_present
pic_order_present_flag
SPS * sps_buffers[MAX_SPS_COUNT]
static const int8_t mv[256][2]
uint8_t zigzag_scan_q0[16]
struct H264Context * thread_context[MAX_THREADS]
int chroma_log2_weight_denom
int bit_depth_luma
luma bit depth from sps to detect changes
static void flush_change(H264Context *h)
short offset_for_ref_frame[256]
int chroma_format_idc
chroma format from sps to detect changes
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int timing_info_present_flag
AVBufferRef * qscale_table_buf
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).
int mbaff
h264 1 -> MBAFF frame 0-> not MBAFF
void ff_print_debug_info2(AVCodecContext *avctx, Picture *p, AVFrame *pict, uint8_t *mbskip_table, int *low_delay, int mb_width, int mb_height, int mb_stride, int quarter_sample)
Print debugging info for the given picture.
int coded_picture_number
picture number in bitstream order
#define AV_LOG_INFO
Standard information.
uint8_t zigzag_scan8x8_q0[64]
int sync
has been decoded after a keyframe
H264 / AVC / MPEG4 part10 codec data table
static const uint8_t zigzag_scan8x8_cavlc[64+1]
typedef void(RENAME(mix_any_func_type))
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)
static const uint8_t zigzag_scan[16+1]
int prev_frame_num
frame_num of the last pic for POC type 1/2
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)
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
#define FF_PROFILE_H264_HIGH_422
int ff_h264_decode_sei(H264Context *h)
Decode SEI.
void avpriv_color_frame(AVFrame *frame, const int color[4])
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int implicit_weight[48][48][2]
int max_contexts
Max number of threads / contexts.
int recovery_frame
recovery_frame is the frame_num at which the next frame should be fully constructed.
main external API structure.
static void close(AVCodecParserContext *s)
#define FF_THREAD_FRAME
Decode more than one frame at once.
uint8_t * visualization_buffer[3]
temporary buffer vor MV visualization
#define AV_EF_EXPLODE
abort decoding on minor error detection
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...
void(* qpel_mc_func)(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
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.
int16_t mb[16 *48 *2]
as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
#define AV_PIX_FMT_YUV444P9
static void init_dequant8_coeff_table(H264Context *h)
uint32_t state
contains the last few bytes in MSB order
void(* pred16x16[4+3+2])(uint8_t *src, ptrdiff_t stride)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
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
BYTE int const BYTE int int int height
void ff_vdpau_h264_set_reference_frames(H264Context *h)
int slice_flags
slice flags
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
void(* h264_idct8_add4)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 *8])
Describe the class of an AVClass context structure.
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static void idct_add(uint8_t *dest, int line_size, int16_t *block)
uint32_t(*[6] dequant8_coeff)[64]
static av_cold int h264_decode_end(AVCodecContext *avctx)
void av_buffer_pool_uninit(AVBufferPool **pool)
Mark the pool as being available for freeing.
int qp_thresh
QP threshold to skip loopfilter.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
#define AV_PIX_FMT_GBRP14
A reference counted buffer type.
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 AV_PIX_FMT_YUV420P9
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, int first_slice)
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 ff_vdpau_h264_picture_start(H264Context *h)
void(* h264_weight_func)(uint8_t *block, int stride, int height, int log2_denom, int weight, int offset)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int16_t mb_padding[256 *2]
as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too lar...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
int allocate_progress
Whether to allocate progress for frame threading.
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
6: bottom field, top field, bottom field repeated, in that order
static int init_dimensions(H264Context *h)
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
int16_t slice_row[MAX_SLICES]
to detect when MAX_SLICES is too low
static const uint8_t start_code[]
void ff_h264_draw_horiz_band(H264Context *h, int y, int height)
void(* h264_idct8_dc_add)(uint8_t *dst, int16_t *block, int stride)
int block_offset[2 *(16 *3)]
block_offset[ 0..23] for frame macroblocks block_offset[24..47] for field macroblocks ...
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int field_poc[2]
h264 top/bottom POC
#define FF_DEBUG_PICT_INFO
int transform_8x8_mode
transform_8x8_mode_flag
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(* qpel_avg)[16]
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)
static void reinit(Jpeg2000EncoderContext *s)
void(* h264_chroma_mc_func)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x, int y)
HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the b...
hardware decoding through VDA
static const uint8_t dequant4_coeff_init[6][3]
#define CONFIG_ERROR_RESILIENCE
static void idr(H264Context *h)
instantaneous decoder refresh.
static int field_end(H264Context *h, int in_setup)
discard all non reference
AVBufferPool * qscale_table_pool
static enum AVPixelFormat h264_hwaccel_pixfmt_list_420[]
#define AV_PIX_FMT_YUV422P9
int mb_height
pic_height_in_map_units_minus1 + 1
AVBufferPool * motion_val_pool
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
common internal api header.
const uint8_t ff_zigzag_direct[64]
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
#define FF_PROFILE_H264_HIGH_444
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
ptrdiff_t mb_linesize
may be equal to s->linesize or s->linesize * 2, for mbaff
AVDictionary * metadata
metadata.
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
#define AV_PIX_FMT_YUV444P10
uint16_t * slice_table_base
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
H.264 / AVC / MPEG4 part10 motion vector predicion.
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG2 field pics)
const char * ff_h264_sei_stereo_mode(H264Context *h)
Get stereo_mode string from the h264 frame_packing_arrangement.
static int execute_decode_slices(H264Context *h, int context_count)
Call decode_slice() for each context.
#define AV_PIX_FMT_YUV420P14
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
int cur_chroma_format_idc
#define FF_PROFILE_H264_MAIN
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
int sei_ct_type
Bit set of clock types for fields/frames in picture timing SEI message.
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
static av_always_inline void dctcoef_set(int16_t *mb, int high_bit_depth, int index, int value)
int bit_depth_luma
bit_depth_luma_minus8 + 8
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
#define CONFIG_H264_VDPAU_DECODER
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
uint8_t zigzag_scan8x8_cavlc_q0[64]
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)
#define AVERROR_INVALIDDATA
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.
void(* h264_idct_add16intra)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 *8])
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]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
struct AVHWAccel * hwaccel
Hardware accelerator in use.
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
uint8_t(*[2] top_borders)[(16 *3)*2]
static int fill_filter_caches(H264Context *h, int mb_type)
int pic_id
h264 pic_num (short -> no wrap version of pic_num, pic_num & max_pic_num; long -> long_pic_num) ...
int key_frame
1 -> keyframe, 0-> not
enum AVPictureType pict_type
#define AV_PIX_FMT_YUV420P10
int current_slice
current slice number, used to initialize slice_num of each thread/context
static const uint8_t * align_get_bits(GetBitContext *s)
int mb_width
pic_width_in_mbs_minus1 + 1
uint8_t field_scan8x8_cavlc_q0[64]
static void * av_mallocz_array(size_t nmemb, size_t size)
static void free_tables(H264Context *h, int free_rbsp)
int ff_h264_fill_default_ref_list(H264Context *h)
Fill the default_ref_list.
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
void ff_er_frame_start(ERContext *s)
uint8_t field_scan8x8[64]
#define AV_PIX_FMT_YUV422P10
the normal 219*2^(n-8) "MPEG" YUV ranges
static int init_thread_copy(AVCodecContext *avctx)
#define copy_fields(to, from, start_field, end_field)
int chroma_weight_flag[2]
7.4.3.2 chroma_weight_lX_flag
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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...
static int init_table_pools(H264Context *h)
static int ref_picture(H264Context *h, Picture *dst, Picture *src)
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
static int alloc_scratch_buffers(H264Context *h, int linesize)
uint8_t field_scan_q0[16]
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
static int alloc_picture(H264Context *h, Picture *pic)
uint8_t(* non_zero_count)[48]
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
This structure stores compressed data.
int sei_recovery_frame_cnt
recovery_frame_cnt from SEI message
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define FF_PROFILE_H264_INTRA
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void(* pred8x8l[9+3])(uint8_t *src, int topleft, int topright, ptrdiff_t stride)
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
unsigned int rbsp_buffer_size[2]
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Context Adaptive Binary Arithmetic Coder.
int8_t ref_cache[2][5 *8]
AVBufferRef * ref_index_buf[2]
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int short_ref_count
number of actual short term references
static const AVProfile profiles[]
enum AVColorSpace colorspace