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",
220 "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 const uint8_t *ptr,
int dst_length,
1335 int i,
int next_avc)
1338 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
1339 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
1343 while (dst_length > 0 && ptr[dst_length - 1] == 0)
1354 int next_avc = h->
is_avc ? 0 : buf_size;
1357 int nals_needed = 0;
1358 int first_slice = 0;
1362 int dst_length, bit_length, consumed;
1365 if (buf_index >= next_avc) {
1369 next_avc = buf_index + nalsize;
1372 if (buf_index >= buf_size)
1374 if (buf_index >= next_avc)
1379 next_avc - buf_index);
1381 if (!ptr || dst_length < 0)
1384 buf_index += consumed;
1387 buf_index, next_avc);
1397 nals_needed = nal_index;
1406 nals_needed = nal_index;
1416 int parse_extradata)
1421 unsigned context_count;
1423 int nals_needed = 0;
1441 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
1443 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
1453 next_avc = h->
is_avc ? 0 : buf_size;
1463 if (buf_index >= next_avc) {
1467 next_avc = buf_index + nalsize;
1470 if (buf_index >= buf_size)
1472 if (buf_index >= next_avc)
1479 &consumed, next_avc - buf_index);
1480 if (!ptr || dst_length < 0) {
1486 buf_index + consumed, next_avc);
1490 "NAL %d/%d at %d/%d length %d\n",
1493 if (h->
is_avc && (nalsize != consumed) && nalsize)
1495 "AVC: Consumed only %d bytes instead of %d\n",
1498 buf_index += consumed;
1508 || nals_needed >= nal_index)
1513 if (parse_extradata) {
1521 "Ignoring NAL %d in global header/extradata\n",
1533 if ((ptr[0] & 0xFC) == 0x98) {
1541 "Invalid mix of idr and non-idr slices\n");
1599 if (CONFIG_H264_VDPAU_DECODER &&
1607 &buf[buf_index - consumed],
1611 }
else if (CONFIG_H264_VDPAU_DECODER &&
1615 sizeof(start_code));
1617 &buf[buf_index - consumed],
1626 "Decoding in chunks is not supported for "
1627 "partitioned slices.\n");
1678 "SPS decoding failure, trying again with the complete NAL\n");
1680 av_assert0(next_avc - buf_index + consumed == nalsize);
1681 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
1684 8*(next_avc - buf_index + consumed - 1));
1732 if (context_count) {
1746 return (ret < 0) ? ret : buf_index;
1756 if (pos + 10 > buf_size)
1783 dst->
data[i] += off;
1790 int cnt= buf[5]&0x1f;
1794 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
1803 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
1814 int buf_size = avpkt->
size;
1828 if (buf_size == 0) {
1866 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1882 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1906 if (CONFIG_MPEGVIDEO) {
1917 assert(pict->
buf[0] || !*got_frame);
1996 #if CONFIG_H264_VDPAU_DECODER
1997 static const AVClass h264_vdpau_class = {
2004 AVCodec ff_h264_vdpau_decoder = {
2005 .
name =
"h264_vdpau",
2006 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
2018 .priv_class = &h264_vdpau_class,