23 #define UNCHECKED_BITSTREAM_READER 1
37 #define SPRITE_TRAJ_VLC_BITS 6
39 #define MB_TYPE_B_VLC_BITS 4
60 int16_t *ac_val, *ac_val1;
72 if (s->
mb_x == 0 || s->
qscale == qscale_table[xy] ||
75 for (i = 1; i < 8; i++)
79 for (i = 1; i < 8; i++)
87 if (s->
mb_y == 0 || s->
qscale == qscale_table[xy] ||
90 for (i = 1; i < 8; i++)
94 for (i = 1; i < 8; i++)
100 for (i = 1; i < 8; i++)
104 for (i = 1; i < 8; i++)
132 v |= 0x7F >> (7 - (bits_count & 7));
145 for (len = 0; len < 32; len++)
172 int min_ab, i, w2, h2, w3, h3;
173 int sprite_ref[4][2];
174 int virtual_ref[2][2];
177 const int vop_ref[4][2] = { { 0, 0 }, { s->
width, 0 },
179 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
181 if (w <= 0 || h <= 0)
206 while ((1 << alpha) < w)
208 while ((1 << beta) < h)
215 sprite_ref[0][0] = a * vop_ref[0][0] + d[0][0];
216 sprite_ref[0][1] = a * vop_ref[0][1] + d[0][1];
217 sprite_ref[1][0] = a * vop_ref[1][0] + d[0][0] + d[1][0];
218 sprite_ref[1][1] = a * vop_ref[1][1] + d[0][1] + d[1][1];
219 sprite_ref[2][0] = a * vop_ref[2][0] + d[0][0] + d[2][0];
220 sprite_ref[2][1] = a * vop_ref[2][1] + d[0][1] + d[2][1];
222 sprite_ref[0][0] = (a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
223 sprite_ref[0][1] = (a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
224 sprite_ref[1][0] = (a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
225 sprite_ref[1][1] = (a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
226 sprite_ref[2][0] = (a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
227 sprite_ref[2][1] = (a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
237 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
239 (r * sprite_ref[0][0] - 16 * vop_ref[0][0]) +
240 w2 * (r * sprite_ref[1][0] - 16 * vop_ref[1][0])), w);
241 virtual_ref[0][1] = 16 * vop_ref[0][1] +
243 (r * sprite_ref[0][1] - 16 * vop_ref[0][1]) +
244 w2 * (r * sprite_ref[1][1] - 16 * vop_ref[1][1])), w);
245 virtual_ref[1][0] = 16 * vop_ref[0][0] +
246 ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][0] - 16 * vop_ref[0][0]) +
247 h2 * (r * sprite_ref[2][0] - 16 * vop_ref[2][0])), h);
248 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
249 ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][1] - 16 * vop_ref[0][1]) +
250 h2 * (r * sprite_ref[2][1] - 16 * vop_ref[2][1])), h);
266 s->
sprite_offset[0][0] = sprite_ref[0][0] - a * vop_ref[0][0];
267 s->
sprite_offset[0][1] = sprite_ref[0][1] - a * vop_ref[0][1];
268 s->
sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
269 a * (vop_ref[0][0] / 2);
270 s->
sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
271 a * (vop_ref[0][1] / 2);
280 s->
sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + rho)) +
281 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
283 (r * sprite_ref[0][1] - virtual_ref[0][1]) *
284 (-vop_ref[0][1]) + (1 << (alpha + rho - 1));
285 s->
sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + rho)) +
286 (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
288 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
289 (-vop_ref[0][1]) + (1 << (alpha + rho - 1));
290 s->
sprite_offset[1][0] = ((-r * sprite_ref[0][0] + virtual_ref[0][0]) *
291 (-2 * vop_ref[0][0] + 1) +
292 (r * sprite_ref[0][1] - virtual_ref[0][1]) *
293 (-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
294 sprite_ref[0][0] - 16 * w2 + (1 << (alpha + rho + 1)));
295 s->
sprite_offset[1][1] = ((-r * sprite_ref[0][1] + virtual_ref[0][1]) *
296 (-2 * vop_ref[0][0] + 1) +
297 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
298 (-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
299 sprite_ref[0][1] - 16 * w2 + (1 << (alpha + rho + 1)));
300 s->
sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
301 s->
sprite_delta[0][1] = (+r * sprite_ref[0][1] - virtual_ref[0][1]);
302 s->
sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]);
303 s->
sprite_delta[1][1] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
309 min_ab =
FFMIN(alpha, beta);
312 s->
sprite_offset[0][0] = (sprite_ref[0][0] << (alpha + beta + rho - min_ab)) +
313 (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
314 h3 * (-vop_ref[0][0]) +
315 (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
316 w3 * (-vop_ref[0][1]) +
317 (1 << (alpha + beta + rho - min_ab - 1));
318 s->
sprite_offset[0][1] = (sprite_ref[0][1] << (alpha + beta + rho - min_ab)) +
319 (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
320 h3 * (-vop_ref[0][0]) +
321 (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
322 w3 * (-vop_ref[0][1]) +
323 (1 << (alpha + beta + rho - min_ab - 1));
324 s->
sprite_offset[1][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) *
325 h3 * (-2 * vop_ref[0][0] + 1) +
326 (-r * sprite_ref[0][0] + virtual_ref[1][0]) *
327 w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
328 r * sprite_ref[0][0] - 16 * w2 * h3 +
329 (1 << (alpha + beta + rho - min_ab + 1));
330 s->
sprite_offset[1][1] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) *
331 h3 * (-2 * vop_ref[0][0] + 1) +
332 (-r * sprite_ref[0][1] + virtual_ref[1][1]) *
333 w3 * (-2 * vop_ref[0][1] + 1) + 2 * w2 * h3 *
334 r * sprite_ref[0][1] - 16 * w2 * h3 +
335 (1 << (alpha + beta + rho - min_ab + 1));
336 s->
sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3;
337 s->
sprite_delta[0][1] = (-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3;
338 s->
sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3;
339 s->
sprite_delta[1][1] = (-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3;
364 for (i = 0; i < 2; i++) {
397 int header_extension = 0, mb_num,
len;
403 for (len = 0; len < 32; len++)
418 if (mb_num >= s->
mb_num) {
420 "illegal mb_num in video packet (%d %d) \n", mb_num, s->
mb_num);
436 if (header_extension) {
442 check_marker(&s->
gb,
"before time_increment in video packed header");
444 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
465 "Error, video packet header damaged (f_code=0)\n");
471 "Error, video packet header damaged (b_code=0)\n");
489 int x,
y, mb_v, sum, dx, dy,
shift;
506 dy -= 1 << (shift + a + 1);
508 dx -= 1 << (shift + a + 1);
512 for (y = 0; y < 16; y++) {
517 for (x = 0; x < 16; x++) {
548 if (code < 0 || code > 9 ) {
561 level =
get_bits(&s->
gb, code - 1) + (1 << (code - 1));
563 level = -
get_bits(&s->
gb, code - 1) - (1 << (code - 1));
590 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
616 "cbpc corrupted at %d %d\n", s->
mb_x, s->
mb_y);
631 for (i = 0; i < 6; i++) {
636 "DC corrupted at %d %d\n", s->
mb_x, s->
mb_y);
645 int mx, my, pred_x, pred_y,
bits;
655 if (bits & 0x10000) {
673 mot_val[0 + stride] =
674 mot_val[2 + stride] = mx;
677 mot_val[1 + stride] =
678 mot_val[3 + stride] = my;
688 "cbpc corrupted at %d %d\n", s->
mb_x, s->
mb_y);
703 mot_val[0 + stride] =
704 mot_val[2 + stride] = 0;
707 mot_val[1 + stride] =
708 mot_val[3 + stride] = 0;
720 if ((cbpc & 16) == 0) {
744 mot_val[0 + stride] =
745 mot_val[2 + stride] = mx;
748 mot_val[1 + stride] =
749 mot_val[3 + stride] = my;
754 for (i = 0; i < 4; i++) {
783 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
802 "cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
817 "I cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
825 for (i = 0; i < 6; i++) {
830 "DC corrupted at %d %d\n", s->
mb_x, s->
mb_y);
849 "P cbpy corrupted at %d %d\n", s->
mb_x, s->
mb_y);
862 if (mb_num >= mb_count)
901 "marker missing after first I partition at %d %d\n",
910 "marker missing after first P partition at %d %d\n",
937 int n,
int coded,
int intra,
int rvlc)
940 int level, i, last,
run, qmul, qadd;
980 if (dc_pred_dir == 0)
1011 qadd = (s->
qscale - 1) | 1;
1028 "1. marker bit missing in rvlc esc\n");
1041 "2. marker bit missing in rvlc esc\n");
1055 level = level * qmul + qadd;
1067 cache ^= 0xC0000000;
1069 if (cache & 0x80000000) {
1070 if (cache & 0x40000000) {
1085 "1. marker bit missing in 3. esc\n");
1095 "2. marker bit missing in 3. esc\n");
1103 if (s->error_recognition >= FF_ER_COMPLIANT) {
1104 const int abs_level=
FFABS(level);
1106 const int run1= run - rl->
max_run[last][abs_level] - 1;
1107 if (abs_level <= rl->max_level[last][run]) {
1111 if (s->error_recognition > FF_ER_COMPLIANT) {
1112 if (abs_level <= rl->max_level[last][run]*2) {
1116 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1125 level = level * qmul + qadd;
1127 level = level * qmul - qadd;
1129 if ((
unsigned)(level + 2048) > 4095) {
1131 if (level > 2560 || level < -2560) {
1133 "|level| overflow in 3. esc, qp=%d\n",
1138 level = level < 0 ? -2048 : 2047;
1148 i += run + rl->
max_run[run >> 7][level / qmul] + 1;
1157 level = level + rl->
max_level[run >> 7][(run - 1) & 63] * qmul;
1171 "ac-tex damaged at %d %d\n", s->
mb_x, s->
mb_y);
1175 block[scan_table[i]] =
level;
1179 block[scan_table[i]] =
level;
1221 for (i = 0; i < 4; i++) {
1229 for (i = 0; i < 6; i++)
1262 for (i = 0; i < 6; i++) {
1265 "texture corrupted at %d %d %d\n",
1292 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1294 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1305 for (i = 0; i < 6; i++)
1333 "cbpc damaged at %d %d\n", s->
mb_x, s->
mb_y);
1336 }
while (cbpc == 20);
1351 cbp = (cbpc & 3) | (cbpy << 2);
1359 if ((cbpc & 16) == 0) {
1368 s->
mv[0][0][0] = mx;
1369 s->
mv[0][0][1] = my;
1382 for (i = 0; i < 2; i++) {
1391 s->
mv[0][i][0] = mx;
1392 s->
mv[0][i][1] = my;
1408 s->
mv[0][0][0] = mx;
1409 s->
mv[0][0][1] = my;
1414 for (i = 0; i < 4; i++) {
1423 s->
mv[0][i][0] = mx;
1424 s->
mv[0][i][1] = my;
1438 for (i = 0; i < 2; i++) {
1453 for (i = 0; i < 6; i++)
1523 s->
mv[0][0][0] = mx;
1526 s->
mv[0][0][1] = my;
1536 s->
mv[1][0][0] = mx;
1539 s->
mv[1][0][1] = my;
1547 for (i = 0; i < 2; i++) {
1551 s->
mv[0][i][0] = mx;
1552 s->
last_mv[0][i][1] = (s->
mv[0][i][1] = my) * 2;
1559 for (i = 0; i < 2; i++) {
1563 s->
mv[1][i][0] = mx;
1564 s->
last_mv[1][i][1] = (s->
mv[1][i][1] = my) * 2;
1588 "I cbpc damaged at %d %d\n", s->
mb_x, s->
mb_y);
1591 }
while (cbpc == 8);
1606 "I cbpy damaged at %d %d\n", s->
mb_x, s->
mb_y);
1609 cbp = (cbpc & 3) | (cbpy << 2);
1621 for (i = 0; i < 6; i++) {
1630 for (i = 0; i < 6; i++) {
1665 int hours, minutes, seconds;
1677 s->
time_base = seconds + 60*(minutes + 60*hours);
1722 int chroma_format =
get_bits(gb, 2);
1784 if (width && height &&
1799 "MPEG4 OBMC not supported (very likely buggy encoder)\n");
1822 "%d sprite_warping_points\n",
1854 for (i = 0; i < 64; i++) {
1868 for (i = 0; i < 64; i++) {
1881 for (; i < 64; i++) {
1891 for (i = 0; i < 64; i++) {
1904 for (; i < 64; i++) {
1926 int estimation_method =
get_bits(gb, 2);
1927 if (estimation_method < 2) {
1942 if (!
check_marker(gb,
"in complexity estimation part 1")) {
1960 if (!
check_marker(gb,
"in complexity estimation part 2")) {
1964 if (estimation_method == 1) {
1970 "Invalid Complexity estimation method %d\n",
1986 if (vo_ver_id != 1) {
1995 "reduced resolution VOP not supported\n");
2004 int h_sampling_factor_n;
2005 int h_sampling_factor_m;
2006 int v_sampling_factor_n;
2007 int v_sampling_factor_m;
2012 h_sampling_factor_n =
get_bits(gb, 5);
2013 h_sampling_factor_m =
get_bits(gb, 5);
2014 v_sampling_factor_n =
get_bits(gb, 5);
2015 v_sampling_factor_m =
get_bits(gb, 5);
2018 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2019 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2055 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
2066 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
2068 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
2075 "wasteful way to store B-frames ('packed B-frames'). "
2076 "Consider using a tool like VirtualDub or avidemux to fix it.\n");
2082 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
2084 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
2086 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
2088 build = (ver << 16) + (ver2 << 8) + ver3;
2091 if (strcmp(buf,
"ffmpeg") == 0)
2098 e = sscanf(buf,
"XviD%d", &build);
2155 #define SET_QPEL_FUNC(postfix1, postfix2) \
2156 s->dsp.put_ ## postfix1 = ff_put_ ## postfix2; \
2157 s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
2158 s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
2202 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
2221 int time_incr, time_increment;
2246 "hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2399 "sprite_brightness_change not supported\n");
2408 "Error, header damaged or not MPEG4 header (qscale=0)\n");
2416 "Error, header damaged or not MPEG4 header (f_code=0)\n");
2427 "Error, header damaged or not MPEG4 header (b_code=0)\n");
2436 "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",
2457 int load_backward_shape =
get_bits1(gb);
2458 if (load_backward_shape)
2460 "load backward shape isn't supported\n");
2471 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2497 unsigned startcode,
v;
2521 startcode = ((startcode << 8) | v) & 0xffffffff;
2523 if ((startcode & 0xFFFFFF00) != 0x100)
2528 if (startcode <= 0x11F)
2530 else if (startcode <= 0x12F)
2532 else if (startcode <= 0x13F)
2534 else if (startcode <= 0x15F)
2536 else if (startcode <= 0x1AF)
2538 else if (startcode == 0x1B0)
2540 else if (startcode == 0x1B1)
2542 else if (startcode == 0x1B2)
2544 else if (startcode == 0x1B3)
2546 else if (startcode == 0x1B4)
2548 else if (startcode == 0x1B5)
2550 else if (startcode == 0x1B6)
2552 else if (startcode == 0x1B7)
2554 else if (startcode == 0x1B8)
2556 else if (startcode == 0x1B9)
2558 else if (startcode == 0x1BA)
2560 else if (startcode == 0x1BB)
2562 else if (startcode == 0x1BC)
2564 else if (startcode == 0x1BD)
2566 else if (startcode == 0x1BE)
2568 else if (startcode == 0x1BF)
2570 else if (startcode == 0x1C0)
2572 else if (startcode == 0x1C1)
2574 else if (startcode == 0x1C2)
2576 else if (startcode == 0x1C3)
2578 else if (startcode <= 0x1C5)
2580 else if (startcode <= 0x1FF)
2585 if (startcode >= 0x120 && startcode <= 0x12F) {
2611 static int done = 0;
2646 int startcode_found = 0;
2648 if (buf_size - current_pos > 7) {
2651 for (i = current_pos; i < buf_size - 4; i++)
2656 buf[i + 3] == 0xB6) {
2657 startcode_found = !(buf[i + 4] & 0x40);
2662 if (startcode_found) {
2665 buf_size - current_pos);
2669 buf_size - current_pos);
2747 "MPEG4 Video Decoder",
2754 "MPEG4 Video VDPAU Decoder",
2781 #if CONFIG_MPEG4_VDPAU_DECODER
2782 AVCodec ff_mpeg4_vdpau_decoder = {
2783 .
name =
"mpeg4_vdpau",