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) { \
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)
312 memcpy(dst, src, length);
319 while (si + 2 < length) {
321 if (src[si + 2] > 3) {
322 dst[di++] = src[si++];
323 dst[di++] = src[si++];
324 }
else if (src[si] == 0 && src[si + 1] == 0) {
325 if (src[si + 2] == 3) {
334 dst[di++] = src[si++];
337 dst[di++] = src[si++];
360 for (r = 1; r < 9; r++) {
392 if (free_rbsp && h->
DPB) {
436 row_mb_num * 8 *
sizeof(
uint8_t), fail)
438 big_mb_num * 48 *
sizeof(
uint8_t), fail)
442 big_mb_num *
sizeof(uint16_t), fail)
444 big_mb_num *
sizeof(
uint8_t), fail)
446 16 * row_mb_num *
sizeof(
uint8_t), fail);
448 16 * row_mb_num *
sizeof(
uint8_t), fail);
450 4 * big_mb_num *
sizeof(
uint8_t), fail);
452 big_mb_num *
sizeof(
uint8_t), fail)
459 big_mb_num *
sizeof(uint32_t), fail);
461 big_mb_num *
sizeof(uint32_t), fail);
465 const int b_xy = 4 * x + 4 * y * h->
b_stride;
500 int yc_size = y_size + 2 * c_size;
515 if (CONFIG_ERROR_RESILIENCE) {
539 mb_array_size *
sizeof(
uint8_t), fail);
553 for (i = 0; i < yc_size; i++)
564 int parse_extradata);
571 if (!buf || size <= 0)
576 const unsigned char *p =
buf;
582 "avcC %d too short\n", size);
589 cnt = *(p + 5) & 0x1f;
591 for (i = 0; i < cnt; i++) {
593 if(nalsize > size - (p-buf))
598 "Decoding sps %d from avcC failed\n", i);
605 for (i = 0; i < cnt; i++) {
607 if(nalsize > size - (p-buf))
612 "Decoding pps %d from avcC failed\n", i);
652 if (CONFIG_ERROR_RESILIENCE)
748 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 == NULL || 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 == NULL || 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",
1572 "Invalid mix of idr and non-idr slices\n");
1630 if (CONFIG_H264_VDPAU_DECODER &&
1638 &buf[buf_index - consumed],
1642 }
else if (CONFIG_H264_VDPAU_DECODER &&
1646 sizeof(start_code));
1648 &buf[buf_index - consumed],
1657 "Decoding in chunks is not supported for "
1658 "partitioned slices.\n");
1709 "SPS decoding failure, trying again with the complete NAL\n");
1711 av_assert0(next_avc - buf_index + consumed == nalsize);
1712 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
1715 8*(next_avc - buf_index + consumed - 1));
1763 if (context_count) {
1777 return (ret < 0) ? ret : buf_index;
1787 if (pos + 10 > buf_size)
1814 dst->
data[i] += off;
1823 int buf_size = avpkt->
size;
1837 if (buf_size == 0) {
1869 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1870 int cnt= buf[5]&0x1f;
1874 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
1883 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
1903 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1927 if (CONFIG_MPEGVIDEO) {
1938 assert(pict->
buf[0] || !*got_frame);
2024 #if CONFIG_H264_VDPAU_DECODER
2025 AVCodec ff_h264_vdpau_decoder = {
2026 .
name =
"h264_vdpau",
2027 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),