23 #define UNCHECKED_BITSTREAM_READER 1
40 #define SPRITE_TRAJ_VLC_BITS 6
42 #define MB_TYPE_B_VLC_BITS 4
63 int16_t *ac_val, *ac_val1;
75 if (s->
mb_x == 0 || s->
qscale == qscale_table[xy] ||
78 for (i = 1; i < 8; i++)
82 for (i = 1; i < 8; i++)
90 if (s->
mb_y == 0 || s->
qscale == qscale_table[xy] ||
93 for (i = 1; i < 8; i++)
97 for (i = 1; i < 8; i++)
103 for (i = 1; i < 8; i++)
107 for (i = 1; i < 8; i++)
135 v |= 0x7F >> (7 - (bits_count & 7));
148 for (len = 0; len < 32; len++)
175 int min_ab, i, w2, h2, w3, h3;
176 int sprite_ref[4][2];
177 int virtual_ref[2][2];
180 const int vop_ref[4][2] = { { 0, 0 }, { s->
width, 0 },
182 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
184 if (w <= 0 || h <= 0)
209 while ((1 << alpha) < w)
211 while ((1 << beta) < h)
218 sprite_ref[0][0] = a * vop_ref[0][0] + d[0][0];
219 sprite_ref[0][1] = a * vop_ref[0][1] + d[0][1];
220 sprite_ref[1][0] = a * vop_ref[1][0] + d[0][0] + d[1][0];
221 sprite_ref[1][1] = a * vop_ref[1][1] + d[0][1] + d[1][1];
222 sprite_ref[2][0] = a * vop_ref[2][0] + d[0][0] + d[2][0];
223 sprite_ref[2][1] = a * vop_ref[2][1] + d[0][1] + d[2][1];
225 sprite_ref[0][0] = (a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
226 sprite_ref[0][1] = (a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
227 sprite_ref[1][0] = (a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
228 sprite_ref[1][1] = (a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
229 sprite_ref[2][0] = (a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
230 sprite_ref[2][1] = (a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
240 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
242 (r * sprite_ref[0][0] - 16 * vop_ref[0][0]) +
243 w2 * (r * sprite_ref[1][0] - 16 * vop_ref[1][0])), w);
244 virtual_ref[0][1] = 16 * vop_ref[0][1] +
246 (r * sprite_ref[0][1] - 16 * vop_ref[0][1]) +
247 w2 * (r * sprite_ref[1][1] - 16 * vop_ref[1][1])), w);
248 virtual_ref[1][0] = 16 * vop_ref[0][0] +
249 ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][0] - 16 * vop_ref[0][0]) +
250 h2 * (r * sprite_ref[2][0] - 16 * vop_ref[2][0])), h);
251 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
252 ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][1] - 16 * vop_ref[0][1]) +
253 h2 * (r * sprite_ref[2][1] - 16 * vop_ref[2][1])), h);
269 s->
sprite_offset[0][0] = sprite_ref[0][0] - a * vop_ref[0][0];
270 s->
sprite_offset[0][1] = sprite_ref[0][1] - a * vop_ref[0][1];
271 s->
sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
272 a * (vop_ref[0][0] / 2);
273 s->
sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
274 a * (vop_ref[0][1] / 2);
283 s->
sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + rho)) +
284 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
286 (r * sprite_ref[0][1] - virtual_ref[0][1]) *
287 (-vop_ref[0][1]) + (1 << (alpha + rho - 1));
288 s->
sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + rho)) +
289 (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
291 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
292 (-vop_ref[0][1]) + (1 << (alpha + rho - 1));
293 s->
sprite_offset[1][0] = ((-r * sprite_ref[0][0] + virtual_ref[0][0]) *
294 (-2 * vop_ref[0][0] + 1) +
295 (r * sprite_ref[0][1] - virtual_ref[0][1]) *
296 (-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
297 sprite_ref[0][0] - 16 * w2 + (1 << (alpha + rho + 1)));
298 s->
sprite_offset[1][1] = ((-r * sprite_ref[0][1] + virtual_ref[0][1]) *
299 (-2 * vop_ref[0][0] + 1) +
300 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
301 (-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
302 sprite_ref[0][1] - 16 * w2 + (1 << (alpha + rho + 1)));
303 s->
sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
304 s->
sprite_delta[0][1] = (+r * sprite_ref[0][1] - virtual_ref[0][1]);
305 s->
sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]);
306 s->
sprite_delta[1][1] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
312 min_ab =
FFMIN(alpha, beta);
315 s->
sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + beta + rho - min_ab)) +
316 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
317 h3 * (-vop_ref[0][0]) +
318 (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
319 w3 * (-vop_ref[0][1]) +
320 (1 << (alpha + beta + rho - min_ab - 1));
321 s->
sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + beta + rho - min_ab)) +
322 (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
323 h3 * (-vop_ref[0][0]) +
324 (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
325 w3 * (-vop_ref[0][1]) +
326 (1 << (alpha + beta + rho - min_ab - 1));
327 s->
sprite_offset[1][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
328 h3 * (-2 * vop_ref[0][0] + 1) +
329 (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
330 w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
331 r * sprite_ref[0][0] - 16 * w2 * h3 +
332 (1 << (alpha + beta + rho - min_ab + 1));
333 s->
sprite_offset[1][1] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
334 h3 * (-2 * vop_ref[0][0] + 1) +
335 (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
336 w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
337 r * sprite_ref[0][1] - 16 * w2 * h3 +
338 (1 << (alpha + beta + rho - min_ab + 1));
339 s->
sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3;
340 s->
sprite_delta[0][1] = (-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3;
341 s->
sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3;
342 s->
sprite_delta[1][1] = (-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3;
367 for (i = 0; i < 2; i++) {
400 int header_extension = 0, mb_num,
len;
406 for (len = 0; len < 32; len++)
421 if (mb_num >= s->
mb_num) {
423 "illegal mb_num in video packet (%d %d) \n", mb_num, s->
mb_num);
439 if (header_extension) {
445 check_marker(&s->
gb,
"before time_increment in video packed header");
447 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
468 "Error, video packet header damaged (f_code=0)\n");
474 "Error, video packet header damaged (b_code=0)\n");
492 int x,
y, mb_v, sum, dx, dy,
shift;
509 dy -= 1 << (shift + a + 1);
511 dx -= 1 << (shift + a + 1);
515 for (y = 0; y < 16; y++) {
520 for (x = 0; x < 16; x++) {
551 if (code < 0 || code > 9 ) {
564 level =
get_bits(&s->
gb, code - 1) + (1 << (code - 1));
566 level = -
get_bits(&s->
gb, code - 1) - (1 << (code - 1));
593 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
619 "mcbpc corrupted at %d %d\n", s->
mb_x, s->
mb_y);
634 for (i = 0; i < 6; i++) {
639 "DC corrupted at %d %d\n", s->
mb_x, s->
mb_y);
648 int mx, my, pred_x, pred_y,
bits;
658 if (bits & 0x10000) {
676 mot_val[0 + stride] =
677 mot_val[2 + stride] = mx;
680 mot_val[1 + stride] =
681 mot_val[3 + stride] = my;
691 "mcbpc corrupted at %d %d\n", s->
mb_x, s->
mb_y);
706 mot_val[0 + stride] =
707 mot_val[2 + stride] = 0;
710 mot_val[1 + stride] =
711 mot_val[3 + stride] = 0;
723 if ((cbpc & 16) == 0) {
747 mot_val[0 + stride] =
748 mot_val[2 + stride] = mx;
751 mot_val[1 + stride] =
752 mot_val[3 + stride] = my;
757 for (i = 0; i < 4; i++) {
786 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
805 "cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
820 "I cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
828 for (i = 0; i < 6; i++) {
833 "DC corrupted at %d %d\n", s->
mb_x, s->
mb_y);
852 "P cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
865 if (mb_num >= mb_count)
904 "marker missing after first I partition at %d %d\n",
913 "marker missing after first P partition at %d %d\n",
940 int n,
int coded,
int intra,
int rvlc)
943 int level, i, last,
run, qmul, qadd;
983 if (dc_pred_dir == 0)
1014 qadd = (s->
qscale - 1) | 1;
1031 "1. marker bit missing in rvlc esc\n");
1044 "2. marker bit missing in rvlc esc\n");
1058 level = level * qmul + qadd;
1070 cache ^= 0xC0000000;
1072 if (cache & 0x80000000) {
1073 if (cache & 0x40000000) {
1088 "1. marker bit missing in 3. esc\n");
1099 "2. marker bit missing in 3. esc\n");
1108 if (s->error_recognition >= FF_ER_COMPLIANT) {
1109 const int abs_level=
FFABS(level);
1111 const int run1= run - rl->
max_run[last][abs_level] - 1;
1112 if (abs_level <= rl->max_level[last][run]) {
1116 if (s->error_recognition > FF_ER_COMPLIANT) {
1117 if (abs_level <= rl->max_level[last][run]*2) {
1121 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1130 level = level * qmul + qadd;
1132 level = level * qmul - qadd;
1134 if ((
unsigned)(level + 2048) > 4095) {
1136 if (level > 2560 || level < -2560) {
1138 "|level| overflow in 3. esc, qp=%d\n",
1143 level = level < 0 ? -2048 : 2047;
1153 i += run + rl->
max_run[run >> 7][level / qmul] + 1;
1162 level = level + rl->
max_level[run >> 7][(run - 1) & 63] * qmul;
1172 tprintf(s->
avctx,
"dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
1177 "ac-tex damaged at %d %d\n", s->
mb_x, s->
mb_y);
1181 block[scan_table[i]] =
level;
1185 block[scan_table[i]] =
level;
1227 for (i = 0; i < 4; i++) {
1235 for (i = 0; i < 6; i++)
1268 for (i = 0; i < 6; i++) {
1271 "texture corrupted at %d %d %d\n",
1298 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1300 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1311 for (i = 0; i < 6; i++)
1339 "mcbpc damaged at %d %d\n", s->
mb_x, s->
mb_y);
1342 }
while (cbpc == 20);
1357 cbp = (cbpc & 3) | (cbpy << 2);
1365 if ((cbpc & 16) == 0) {
1374 s->
mv[0][0][0] = mx;
1375 s->
mv[0][0][1] = my;
1388 for (i = 0; i < 2; i++) {
1397 s->
mv[0][i][0] = mx;
1398 s->
mv[0][i][1] = my;
1414 s->
mv[0][0][0] = mx;
1415 s->
mv[0][0][1] = my;
1420 for (i = 0; i < 4; i++) {
1429 s->
mv[0][i][0] = mx;
1430 s->
mv[0][i][1] = my;
1444 for (i = 0; i < 2; i++) {
1459 for (i = 0; i < 6; i++)
1529 s->
mv[0][0][0] = mx;
1532 s->
mv[0][0][1] = my;
1542 s->
mv[1][0][0] = mx;
1545 s->
mv[1][0][1] = my;
1553 for (i = 0; i < 2; i++) {
1557 s->
mv[0][i][0] = mx;
1558 s->
last_mv[0][i][1] = (s->
mv[0][i][1] = my) * 2;
1565 for (i = 0; i < 2; i++) {
1569 s->
mv[1][i][0] = mx;
1570 s->
last_mv[1][i][1] = (s->
mv[1][i][1] = my) * 2;
1594 "I cbpc damaged at %d %d\n", s->
mb_x, s->
mb_y);
1597 }
while (cbpc == 8);
1612 "I cbpy damaged at %d %d\n", s->
mb_x, s->
mb_y);
1615 cbp = (cbpc & 3) | (cbpy << 2);
1627 for (i = 0; i < 6; i++) {
1636 for (i = 0; i < 6; i++) {
1671 int hours, minutes, seconds;
1683 s->
time_base = seconds + 60*(minutes + 60*hours);
1728 int chroma_format =
get_bits(gb, 2);
1790 if (width && height &&
1805 "MPEG4 OBMC not supported (very likely buggy encoder)\n");
1828 "%d sprite_warping_points\n",
1860 for (i = 0; i < 64; i++) {
1874 for (i = 0; i < 64; i++) {
1887 for (; i < 64; i++) {
1897 for (i = 0; i < 64; i++) {
1910 for (; i < 64; i++) {
1932 int estimation_method =
get_bits(gb, 2);
1933 if (estimation_method < 2) {
1948 if (!
check_marker(gb,
"in complexity estimation part 1")) {
1966 if (!
check_marker(gb,
"in complexity estimation part 2")) {
1970 if (estimation_method == 1) {
1976 "Invalid Complexity estimation method %d\n",
1992 if (vo_ver_id != 1) {
2001 "reduced resolution VOP not supported\n");
2010 int h_sampling_factor_n;
2011 int h_sampling_factor_m;
2012 int v_sampling_factor_n;
2013 int v_sampling_factor_m;
2018 h_sampling_factor_n =
get_bits(gb, 5);
2019 h_sampling_factor_m =
get_bits(gb, 5);
2020 v_sampling_factor_n =
get_bits(gb, 5);
2021 v_sampling_factor_m =
get_bits(gb, 5);
2024 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2025 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2061 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
2072 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
2074 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
2081 "wasteful way to store B-frames ('packed B-frames'). "
2082 "Consider using a tool like VirtualDub or avidemux to fix it.\n");
2088 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
2090 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
2092 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
2094 build = (ver << 16) + (ver2 << 8) + ver3;
2097 if (strcmp(buf,
"ffmpeg") == 0)
2104 e = sscanf(buf,
"XviD%d", &build);
2161 #define SET_QPEL_FUNC(postfix1, postfix2) \
2162 s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
2163 s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
2164 s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
2208 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
2212 if (CONFIG_MPEG4_DECODER && ctx->
xvid_build >= 0 &&
2226 int time_incr, time_increment;
2251 "hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2404 "sprite_brightness_change not supported\n");
2413 "Error, header damaged or not MPEG4 header (qscale=0)\n");
2421 "Error, header damaged or not MPEG4 header (f_code=0)\n");
2432 "Error, header damaged or not MPEG4 header (b_code=0)\n");
2441 "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64
" tincr:%d\n",
2462 int load_backward_shape =
get_bits1(gb);
2463 if (load_backward_shape)
2465 "load backward shape isn't supported\n");
2476 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2502 unsigned startcode,
v;
2526 startcode = ((startcode << 8) | v) & 0xffffffff;
2528 if ((startcode & 0xFFFFFF00) != 0x100)
2533 if (startcode <= 0x11F)
2535 else if (startcode <= 0x12F)
2537 else if (startcode <= 0x13F)
2539 else if (startcode <= 0x15F)
2541 else if (startcode <= 0x1AF)
2543 else if (startcode == 0x1B0)
2545 else if (startcode == 0x1B1)
2547 else if (startcode == 0x1B2)
2549 else if (startcode == 0x1B3)
2551 else if (startcode == 0x1B4)
2553 else if (startcode == 0x1B5)
2555 else if (startcode == 0x1B6)
2557 else if (startcode == 0x1B7)
2559 else if (startcode == 0x1B8)
2561 else if (startcode == 0x1B9)
2563 else if (startcode == 0x1BA)
2565 else if (startcode == 0x1BB)
2567 else if (startcode == 0x1BC)
2569 else if (startcode == 0x1BD)
2571 else if (startcode == 0x1BE)
2573 else if (startcode == 0x1BF)
2575 else if (startcode == 0x1C0)
2577 else if (startcode == 0x1C1)
2579 else if (startcode == 0x1C2)
2581 else if (startcode == 0x1C3)
2583 else if (startcode <= 0x1C5)
2585 else if (startcode <= 0x1FF)
2590 if (startcode >= 0x120 && startcode <= 0x12F) {
2616 static int done = 0;
2651 int startcode_found = 0;
2653 if (buf_size - current_pos > 7) {
2656 for (i = current_pos; i < buf_size - 4; i++)
2661 buf[i + 3] == 0xB6) {
2662 startcode_found = !(buf[i + 4] & 0x40);
2667 if (startcode_found) {
2670 buf_size - current_pos);
2674 buf_size - current_pos);
2696 if (CONFIG_MPEG4_DECODER && !init && s1->
xvid_build >= 0)
2756 "MPEG4 Video Decoder",
2783 #if CONFIG_MPEG4_VDPAU_DECODER
2784 static const AVClass mpeg4_vdpau_class = {
2785 "MPEG4 Video VDPAU Decoder",
2791 AVCodec ff_mpeg4_vdpau_decoder = {
2792 .
name =
"mpeg4_vdpau",
2804 .priv_class = &mpeg4_vdpau_class,