28 #define UNCHECKED_BITSTREAM_READER 1
64 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
130 offset[2] = (y >> vshift) * src->
linesize[1];
147 static const int8_t top[12] = {
150 static const int8_t left[12] = {
156 for (i = 0; i < 4; i++) {
160 "top block unavailable for requested intra4x4 mode %d at %d %d\n",
170 static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
171 for (i = 0; i < 4; i++)
176 "left block unavailable for requested intra4x4 mode %d at %d %d\n",
199 "out of range intra chroma pred mode at %d %d\n",
208 "top block unavailable for requested intra mode at %d %d\n",
218 "left block unavailable for requested intra mode at %d %d\n",
234 int *dst_length,
int *consumed,
int length)
247 #define STARTCODE_TEST \
248 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
249 if (src[i + 2] != 3 && src[i + 2] != 0) { \
256 #if HAVE_FAST_UNALIGNED
257 #define FIND_FIRST_ZERO \
258 if (i > 0 && !src[i]) \
264 for (i = 0; i + 1 <
length; i += 9) {
266 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
267 0x8000800080008080ULL))
274 for (i = 0; i + 1 <
length; i += 5) {
276 (
AV_RN32A(src + i) - 0x01000101U)) &
285 for (i = 0; i + 1 <
length; i += 2) {
288 if (i > 0 && src[i - 1] == 0)
309 memcpy(dst, src, length);
316 while (si + 2 < length) {
318 if (src[si + 2] > 3) {
319 dst[di++] = src[si++];
320 dst[di++] = src[si++];
321 }
else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {
322 if (src[si + 2] == 3) {
331 dst[di++] = src[si++];
334 dst[di++] = src[si++];
357 for (r = 1; r < 9; r++) {
389 if (free_rbsp && h->
DPB) {
434 row_mb_num, 8 *
sizeof(
uint8_t), fail)
436 big_mb_num * 48 *
sizeof(
uint8_t), fail)
440 big_mb_num *
sizeof(uint16_t), fail)
442 big_mb_num *
sizeof(
uint8_t), fail)
444 row_mb_num, 16 *
sizeof(
uint8_t), fail);
446 row_mb_num, 16 *
sizeof(
uint8_t), fail);
448 4 * big_mb_num *
sizeof(
uint8_t), fail);
450 big_mb_num *
sizeof(
uint8_t), fail)
457 big_mb_num *
sizeof(uint32_t), fail);
459 big_mb_num *
sizeof(uint32_t), fail);
463 const int b_xy = 4 * x + 4 * y * h->
b_stride;
498 int yc_size = y_size + 2 * c_size;
513 if (CONFIG_ERROR_RESILIENCE) {
528 (h->
mb_num + 1) *
sizeof(
int), fail);
538 mb_array_size *
sizeof(
uint8_t), fail);
549 yc_size *
sizeof(int16_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);
747 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;
1006 for (list = 0; list < 2; list++) {
1009 for (i = 0; i < h->
ref_count[list]; i++) {
1010 int luma_weight_flag, chroma_weight_flag;
1013 if (luma_weight_flag) {
1028 if (chroma_weight_flag) {
1030 for (j = 0; j < 2; j++) {
1041 for (j = 0; j < 2; j++) {
1145 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
1156 expected_delta_per_poc_cycle = 0;
1161 if (abs_frame_num > 0) {
1165 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
1166 for (i = 0; i <= frame_num_in_poc_cycle; i++)
1174 field_poc[0] = expectedpoc + h->
delta_poc[0];
1190 pic_field_poc[0] = field_poc[0];
1192 pic_field_poc[1] = field_poc[1];
1193 *pic_poc =
FFMIN(pic_field_poc[0], pic_field_poc[1]);
1232 "Reenabling low delay requires a codec flush.\n");
1246 "VDPAU decoding does not support video colorspace.\n");
1274 int ref_count[2], list_count;
1275 int num_ref_idx_active_override_flag;
1287 num_ref_idx_active_override_flag =
get_bits1(&h->
gb);
1289 if (num_ref_idx_active_override_flag) {
1298 if (ref_count[0]-1 > max[0] || ref_count[1]-1 > max[1]){
1299 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]);
1311 ref_count[0] = ref_count[1] = 0;
1329 const uint8_t *ptr,
int dst_length,
1330 int i,
int next_avc)
1333 buf[i] == 0x00 && buf[i + 1] == 0x00 &&
1334 buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
1338 while (dst_length > 0 && ptr[dst_length - 1] == 0)
1349 int next_avc = h->
is_avc ? 0 : buf_size;
1352 int nals_needed = 0;
1353 int first_slice = 0;
1357 int dst_length, bit_length, consumed;
1360 if (buf_index >= next_avc) {
1364 next_avc = buf_index + nalsize;
1367 if (buf_index >= buf_size)
1369 if (buf_index >= next_avc)
1374 next_avc - buf_index);
1376 if (!ptr || dst_length < 0)
1379 buf_index += consumed;
1382 buf_index, next_avc);
1392 nals_needed = nal_index;
1401 nals_needed = nal_index;
1411 int parse_extradata)
1416 unsigned context_count;
1418 int nals_needed = 0;
1436 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
1438 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
1448 next_avc = h->
is_avc ? 0 : buf_size;
1458 if (buf_index >= next_avc) {
1462 next_avc = buf_index + nalsize;
1465 if (buf_index >= buf_size)
1467 if (buf_index >= next_avc)
1474 &consumed, next_avc - buf_index);
1475 if (!ptr || dst_length < 0) {
1481 buf_index + consumed, next_avc);
1485 "NAL %d/%d at %d/%d length %d\n",
1488 if (h->
is_avc && (nalsize != consumed) && nalsize)
1490 "AVC: Consumed only %d bytes instead of %d\n",
1493 buf_index += consumed;
1508 if (parse_extradata) {
1516 "Ignoring NAL %d in global header/extradata\n",
1528 if ((ptr[0] & 0xFC) == 0x98) {
1536 "Invalid mix of idr and non-idr slices\n");
1593 if (CONFIG_H264_VDPAU_DECODER &&
1601 &buf[buf_index - consumed],
1605 }
else if (CONFIG_H264_VDPAU_DECODER &&
1609 sizeof(start_code));
1611 &buf[buf_index - consumed],
1634 "SPS decoding failure, trying again with the complete NAL\n");
1636 av_assert0(next_avc - buf_index + consumed == nalsize);
1637 if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
1640 8*(next_avc - buf_index + consumed - 1));
1688 if (context_count) {
1702 return (ret < 0) ? ret : buf_index;
1712 if (pos + 10 > buf_size)
1739 dst->
data[i] += off;
1746 int cnt= buf[5]&0x1f;
1750 if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
1759 if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
1770 int buf_size = avpkt->
size;
1783 if (buf_size == 0) {
1821 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1837 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1870 for (p = 0; p<4; p++) {
1884 if (CONFIG_MPEGVIDEO) {
1977 #if CONFIG_H264_VDPAU_DECODER
1978 static const AVClass h264_vdpau_class = {
1985 AVCodec ff_h264_vdpau_decoder = {
1986 .
name =
"h264_vdpau",
1987 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
1999 .priv_class = &h264_vdpau_class,