28 #define UNCHECKED_BITSTREAM_READER 1
66 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
132 offset[2] = (y >> vshift) * src->
linesize[1];
149 static const int8_t top[12] = {
152 static const int8_t left[12] = {
158 for (i = 0; i < 4; i++) {
162 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
172 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
173 for (i = 0; i < 4; i++)
178 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
201 "out of range intra chroma pred mode at %d %d\n",
210 "top block unavailable for requested intra mode at %d %d\n",
226 "left block unavailable for requested intra mode at %d %d\n",
236 int *dst_length,
int *consumed,
int length)
249 #define STARTCODE_TEST \
250 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
251 if (src[i + 2] != 3 && src[i + 2] != 0) { \
258 #if HAVE_FAST_UNALIGNED
259 #define FIND_FIRST_ZERO \
260 if (i > 0 && !src[i]) \
266 for (i = 0; i + 1 <
length; i += 9) {
268 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
269 0x8000800080008080ULL))
276 for (i = 0; i + 1 <
length; i += 5) {
278 (
AV_RN32A(src + i) - 0x01000101U)) &
287 for (i = 0; i + 1 <
length; i += 2) {
290 if (i > 0 && src[i - 1] == 0)
311 memcpy(dst, src, length);
318 while (si + 2 < length) {
320 if (src[si + 2] > 3) {
321 dst[di++] = src[si++];
322 dst[di++] = src[si++];
323 }
else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {
324 if (src[si + 2] == 3) {
333 dst[di++] = src[si++];
336 dst[di++] = src[si++];
359 for (r = 1; r < 9; r++) {
391 if (free_rbsp && h->
DPB) {
435 row_mb_num, 8 *
sizeof(
uint8_t), fail)
437 big_mb_num * 48 *
sizeof(
uint8_t), fail)
441 big_mb_num *
sizeof(uint16_t), fail)
443 big_mb_num *
sizeof(
uint8_t), fail)
445 row_mb_num, 16 *
sizeof(
uint8_t), fail);
447 row_mb_num, 16 *
sizeof(
uint8_t), fail);
449 4 * big_mb_num *
sizeof(
uint8_t), fail);
451 big_mb_num *
sizeof(
uint8_t), fail)
458 big_mb_num *
sizeof(uint32_t), fail);
460 big_mb_num *
sizeof(uint32_t), fail);
464 const int b_xy = 4 * x + 4 * y * h->
b_stride;
499 int yc_size = y_size + 2 * c_size;
514 if (CONFIG_ERROR_RESILIENCE) {
530 (h->
mb_num + 1) *
sizeof(
int), fail);
540 mb_array_size *
sizeof(
uint8_t), fail);
551 yc_size *
sizeof(int16_t), fail);
555 for (i = 0; i < yc_size; i++)
566 int parse_extradata);
573 if (!buf || size <= 0)
578 const unsigned char *p =
buf;
584 "avcC %d too short\n", size);
591 cnt = *(p + 5) & 0x1f;
593 for (i = 0; i < cnt; i++) {
595 if(nalsize > size - (p-buf))
600 "Decoding sps %d from avcC failed\n", i);
607 for (i = 0; i < cnt; i++) {
609 if(nalsize > size - (p-buf))
614 "Decoding pps %d from avcC failed\n", i);
654 if (CONFIG_ERROR_RESILIENCE)
750 int i, pics, out_of_order, out_idx;
903 for (i = 0; 1; i++) {
915 out_of_order =
FFMAX(out_of_order, 1);
986 int luma_def, chroma_def;
996 for (list = 0; list < 2; list++) {
999 for (i = 0; i < h->
ref_count[list]; i++) {
1000 int luma_weight_flag, chroma_weight_flag;
1003 if (luma_weight_flag) {
1018 if (chroma_weight_flag) {
1020 for (j = 0; j < 2; j++) {
1031 for (j = 0; j < 2; j++) {
1148 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
1159 expected_delta_per_poc_cycle = 0;
1164 if (abs_frame_num > 0) {
1168 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
1169 for (i = 0; i <= frame_num_in_poc_cycle; i++)
1177 field_poc[0] = expectedpoc + h->
delta_poc[0];
1193 pic_field_poc[0] = field_poc[0];
1195 pic_field_poc[1] = field_poc[1];
1196 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
1235 "Reenabling low delay requires a codec flush.\n");
1249 "VDPAU decoding does not support video colorspace.\n");
1265 if (CONFIG_ERROR_RESILIENCE)
1279 int ref_count[2], list_count;
1280 int num_ref_idx_active_override_flag;
1292 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
1294 if (num_ref_idx_active_override_flag) {
1303 if (ref_count[0]-1 > max[0] || ref_count[1]-1 > max[1]){
1304 av_log(h->
avctx,
AV_LOG_ERROR,
"reference overflow %u > %u or %u > %u\n", ref_count[0]-1, max[0], ref_count[1]-1, max[1]);
1316 ref_count[0] = ref_count[1] = 0;
1334 int buf_index,
int next_avc)
1337 for (; buf_index + 3 < next_avc; buf_index++)
1339 if (buf[buf_index] == 0 &&
1340 buf[buf_index + 1] == 0 &&
1341 buf[buf_index + 2] == 1)
1346 if (buf_index >= buf_size)
1353 int buf_size,
int *buf_index)
1361 nalsize = (nalsize << 8) | buf[(*buf_index)++];
1362 if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
1364 "AVC: nal size %d\n", nalsize);
1371 const uint8_t *ptr,
int dst_length,
1372 int i,
int next_avc)
1375 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
1376 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
1380 while (dst_length > 0 && ptr[dst_length - 1] == 0)
1391 int next_avc = h->
is_avc ? 0 : buf_size;
1394 int nals_needed = 0;
1395 int first_slice = 0;
1399 int dst_length, bit_length, consumed;
1402 if (buf_index >= next_avc) {
1406 next_avc = buf_index + nalsize;
1409 if (buf_index >= buf_size)
1411 if (buf_index >= next_avc)
1416 next_avc - buf_index);
1418 if (!ptr || dst_length < 0)
1421 buf_index += consumed;
1424 buf_index, next_avc);
1434 nals_needed = nal_index;
1443 nals_needed = nal_index;
1453 int parse_extradata)
1458 unsigned context_count;
1460 int nals_needed = 0;
1478 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
1480 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
1490 next_avc = h->
is_avc ? 0 : buf_size;
1500 if (buf_index >= next_avc) {
1504 next_avc = buf_index + nalsize;
1507 if (buf_index >= buf_size)
1509 if (buf_index >= next_avc)
1516 &consumed, next_avc - buf_index);
1517 if (!ptr || dst_length < 0) {
1523 buf_index + consumed, next_avc);
1527 "NAL %d/%d at %d/%d length %d\n",
1530 if (h->
is_avc && (nalsize != consumed) && nalsize)
1532 "AVC: Consumed only %d bytes instead of %d\n",
1535 buf_index += consumed;
1545 || nals_needed >= nal_index)
1550 if (parse_extradata) {
1558 "Ignoring NAL %d in global header/extradata\n",
1570 if ((ptr[0] & 0xFC) == 0x98) {
1578 "Invalid mix of idr and non-idr slices\n");
1636 if (CONFIG_H264_VDPAU_DECODER &&
1644 &buf[buf_index - consumed],
1648 }
else if (CONFIG_H264_VDPAU_DECODER &&
1652 sizeof(start_code));
1654 &buf[buf_index - consumed],
1663 "Decoding in chunks is not supported for "
1664 "partitioned slices.\n");
1715 "SPS decoding failure, trying again with the complete NAL\n");
1717 av_assert0(next_avc - buf_index + consumed == nalsize);
1718 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
1721 8*(next_avc - buf_index + consumed - 1));
1769 if (context_count) {
1783 return (ret < 0) ? ret : buf_index;
1793 if (pos + 10 > buf_size)
1820 dst->
data[i] += off;
1827 int cnt= buf[5]&0x1f;
1831 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
1840 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
1851 int buf_size = avpkt->
size;
1865 if (buf_size == 0) {
1903 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1919 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1943 if (CONFIG_MPEGVIDEO) {
1954 assert(pict->
buf[0] || !*got_frame);
2033 #if CONFIG_H264_VDPAU_DECODER
2034 static const AVClass h264_vdpau_class = {
2041 AVCodec ff_h264_vdpau_decoder = {
2042 .
name =
"h264_vdpau",
2043 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
2055 .priv_class = &h264_vdpau_class,