comparison vp3.c @ 1240:c95ff60bc1a1 libavcodec

fix motion vector decoding bug and reinstate interframes
author tmmm
date Sun, 11 May 2003 04:47:45 +0000
parents fe46bd7c64d4
children a02df1ba6c7f
comparison
equal deleted inserted replaced
1239:fe46bd7c64d4 1240:c95ff60bc1a1
45 * Debugging Variables 45 * Debugging Variables
46 * 46 *
47 * Define one or more of the following compile-time variables to 1 to obtain 47 * Define one or more of the following compile-time variables to 1 to obtain
48 * elaborate information about certain aspects of the decoding process. 48 * elaborate information about certain aspects of the decoding process.
49 * 49 *
50 * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode)
50 * DEBUG_VP3: high-level decoding flow 51 * DEBUG_VP3: high-level decoding flow
51 * DEBUG_INIT: initialization parameters 52 * DEBUG_INIT: initialization parameters
52 * DEBUG_DEQUANTIZERS: display how the dequanization tables are built 53 * DEBUG_DEQUANTIZERS: display how the dequanization tables are built
53 * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding 54 * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding
54 * DEBUG_MODES: unpacking the coding modes for individual fragments 55 * DEBUG_MODES: unpacking the coding modes for individual fragments
56 * DEBUG_TOKEN: display exhaustive information about each DCT token 57 * DEBUG_TOKEN: display exhaustive information about each DCT token
57 * DEBUG_VLC: display the VLCs as they are extracted from the stream 58 * DEBUG_VLC: display the VLCs as they are extracted from the stream
58 * DEBUG_DC_PRED: display the process of reversing DC prediction 59 * DEBUG_DC_PRED: display the process of reversing DC prediction
59 * DEBUG_IDCT: show every detail of the IDCT process 60 * DEBUG_IDCT: show every detail of the IDCT process
60 */ 61 */
62
63 #define KEYFRAMES_ONLY 0
61 64
62 #define DEBUG_VP3 0 65 #define DEBUG_VP3 0
63 #define DEBUG_INIT 0 66 #define DEBUG_INIT 0
64 #define DEBUG_DEQUANTIZERS 0 67 #define DEBUG_DEQUANTIZERS 0
65 #define DEBUG_BLOCK_CODING 0 68 #define DEBUG_BLOCK_CODING 0
275 278
276 /* This table contains macroblock_count * 6 entries. Each set of 6 279 /* This table contains macroblock_count * 6 entries. Each set of 6
277 * numbers corresponds to the fragment indices 0..5 which comprise 280 * numbers corresponds to the fragment indices 0..5 which comprise
278 * the macroblock (4 Y fragments and 2 C fragments). */ 281 * the macroblock (4 Y fragments and 2 C fragments). */
279 int *macroblock_fragments; 282 int *macroblock_fragments;
280 /* This is an array of flags indicating whether a particular 283 /* This is an array of that indicates how a particular
281 * macroblock is coded. */ 284 * macroblock is coded. */
282 unsigned char *macroblock_coded; 285 unsigned char *macroblock_coding;
283 286
284 int first_coded_y_fragment; 287 int first_coded_y_fragment;
285 int first_coded_c_fragment; 288 int first_coded_c_fragment;
286 int last_coded_y_fragment; 289 int last_coded_y_fragment;
287 int last_coded_c_fragment; 290 int last_coded_c_fragment;
476 hilbert = hilbert_walk_mb; 479 hilbert = hilbert_walk_mb;
477 mapping_index = 0; 480 mapping_index = 0;
478 current_macroblock = -1; 481 current_macroblock = -1;
479 for (i = 0; i < s->u_superblock_start; i++) { 482 for (i = 0; i < s->u_superblock_start; i++) {
480 483
481 if (current_width >= right_edge) { 484 if (current_width >= right_edge - 1) {
482 /* reset width and move to next superblock row */ 485 /* reset width and move to next superblock row */
483 current_width = 0; 486 current_width = -1;
484 current_height += 2; 487 current_height += 2;
485 488
486 /* macroblock is now at the start of a new superblock row */ 489 /* macroblock is now at the start of a new superblock row */
487 current_macroblock += superblock_row_inc; 490 current_macroblock += superblock_row_inc;
488 } 491 }
495 498
496 /* check if the macroblock is in bounds */ 499 /* check if the macroblock is in bounds */
497 if ((current_width < right_edge) && 500 if ((current_width < right_edge) &&
498 (current_height < bottom_edge)) { 501 (current_height < bottom_edge)) {
499 s->superblock_macroblocks[mapping_index] = current_macroblock; 502 s->superblock_macroblocks[mapping_index] = current_macroblock;
500 debug_init(" mapping macroblock %d to superblock %d, position %d\n", 503 debug_init(" mapping macroblock %d to superblock %d, position %d (%d/%d x %d/%d)\n",
501 s->superblock_macroblocks[mapping_index], i, j); 504 s->superblock_macroblocks[mapping_index], i, j,
505 current_width, right_edge, current_height, bottom_edge);
502 } else { 506 } else {
503 s->superblock_macroblocks[mapping_index] = -1; 507 s->superblock_macroblocks[mapping_index] = -1;
504 debug_init(" superblock %d, position %d has no macroblock\n", 508 debug_init(" superblock %d, position %d has no macroblock (%d/%d x %d/%d)\n",
505 i, j); 509 i, j,
510 current_width, right_edge, current_height, bottom_edge);
506 } 511 }
507 512
508 mapping_index++; 513 mapping_index++;
509 } 514 }
510 } 515 }
1216 /* figure out which fragments are coded; iterate through each 1221 /* figure out which fragments are coded; iterate through each
1217 * superblock (all planes) */ 1222 * superblock (all planes) */
1218 s->coded_fragment_list_index = 0; 1223 s->coded_fragment_list_index = 0;
1219 s->first_coded_y_fragment = s->first_coded_c_fragment = 0; 1224 s->first_coded_y_fragment = s->first_coded_c_fragment = 0;
1220 s->last_coded_y_fragment = s->last_coded_c_fragment = -1; 1225 s->last_coded_y_fragment = s->last_coded_c_fragment = -1;
1221 memset(s->macroblock_coded, 0, s->macroblock_count); 1226 memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
1222 for (i = 0; i < s->superblock_count; i++) { 1227 for (i = 0; i < s->superblock_count; i++) {
1223 1228
1224 /* iterate through all 16 fragments in a superblock */ 1229 /* iterate through all 16 fragments in a superblock */
1225 for (j = 0; j < 16; j++) { 1230 for (j = 0; j < 16; j++) {
1226 1231
1257 (s->last_coded_y_fragment == -1)) { 1262 (s->last_coded_y_fragment == -1)) {
1258 s->first_coded_c_fragment = s->coded_fragment_list_index; 1263 s->first_coded_c_fragment = s->coded_fragment_list_index;
1259 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; 1264 s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
1260 } 1265 }
1261 s->coded_fragment_list_index++; 1266 s->coded_fragment_list_index++;
1262 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; 1267 s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV;
1263 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n", 1268 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
1264 i, current_fragment); 1269 i, current_fragment);
1265 } else { 1270 } else {
1266 /* not coded; copy this fragment from the prior frame */ 1271 /* not coded; copy this fragment from the prior frame */
1267 s->all_fragments[current_fragment].coding_method = 1272 s->all_fragments[current_fragment].coding_method =
1284 (s->last_coded_y_fragment == -1)) { 1289 (s->last_coded_y_fragment == -1)) {
1285 s->first_coded_c_fragment = s->coded_fragment_list_index; 1290 s->first_coded_c_fragment = s->coded_fragment_list_index;
1286 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; 1291 s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
1287 } 1292 }
1288 s->coded_fragment_list_index++; 1293 s->coded_fragment_list_index++;
1289 s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1; 1294 s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV;
1290 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n", 1295 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
1291 i, current_fragment); 1296 i, current_fragment);
1292 } 1297 }
1293 } 1298 }
1294 } 1299 }
1351 for (i = 0; i < s->u_superblock_start; i++) { 1356 for (i = 0; i < s->u_superblock_start; i++) {
1352 1357
1353 for (j = 0; j < 4; j++) { 1358 for (j = 0; j < 4; j++) {
1354 current_macroblock = s->superblock_macroblocks[i * 4 + j]; 1359 current_macroblock = s->superblock_macroblocks[i * 4 + j];
1355 if ((current_macroblock == -1) || 1360 if ((current_macroblock == -1) ||
1356 (!s->macroblock_coded[current_macroblock])) 1361 (s->macroblock_coding[current_macroblock] == MODE_COPY))
1357 continue; 1362 continue;
1358 if (current_macroblock >= s->macroblock_count) { 1363 if (current_macroblock >= s->macroblock_count) {
1359 printf (" vp3:unpack_modes(): bad macroblock number (%d >= %d)\n", 1364 printf (" vp3:unpack_modes(): bad macroblock number (%d >= %d)\n",
1360 current_macroblock, s->macroblock_count); 1365 current_macroblock, s->macroblock_count);
1361 return 1; 1366 return 1;
1365 if (scheme == 7) 1370 if (scheme == 7)
1366 coding_mode = get_bits(gb, 3); 1371 coding_mode = get_bits(gb, 3);
1367 else 1372 else
1368 coding_mode = ModeAlphabet[scheme][get_mode_code(gb)]; 1373 coding_mode = ModeAlphabet[scheme][get_mode_code(gb)];
1369 1374
1375 s->macroblock_coding[current_macroblock] = coding_mode;
1370 for (k = 0; k < 6; k++) { 1376 for (k = 0; k < 6; k++) {
1371 current_fragment = 1377 current_fragment =
1372 s->macroblock_fragments[current_macroblock * 6 + k]; 1378 s->macroblock_fragments[current_macroblock * 6 + k];
1373 if (current_fragment == -1) 1379 if (current_fragment == -1)
1374 continue; 1380 continue;
1479 for (i = 0; i < s->u_superblock_start; i++) { 1485 for (i = 0; i < s->u_superblock_start; i++) {
1480 1486
1481 for (j = 0; j < 4; j++) { 1487 for (j = 0; j < 4; j++) {
1482 current_macroblock = s->superblock_macroblocks[i * 4 + j]; 1488 current_macroblock = s->superblock_macroblocks[i * 4 + j];
1483 if ((current_macroblock == -1) || 1489 if ((current_macroblock == -1) ||
1484 (!s->macroblock_coded[current_macroblock])) 1490 (s->macroblock_coding[current_macroblock] == MODE_COPY))
1485 continue; 1491 continue;
1486 if (current_macroblock >= s->macroblock_count) { 1492 if (current_macroblock >= s->macroblock_count) {
1487 printf (" vp3:unpack_vectors(): bad macroblock number (%d >= %d)\n", 1493 printf (" vp3:unpack_vectors(): bad macroblock number (%d >= %d)\n",
1488 current_macroblock, s->macroblock_count); 1494 current_macroblock, s->macroblock_count);
1489 return 1; 1495 return 1;
1493 if (current_fragment >= s->fragment_count) { 1499 if (current_fragment >= s->fragment_count) {
1494 printf (" vp3:unpack_vectors(): bad fragment number (%d >= %d\n", 1500 printf (" vp3:unpack_vectors(): bad fragment number (%d >= %d\n",
1495 current_fragment, s->fragment_count); 1501 current_fragment, s->fragment_count);
1496 return 1; 1502 return 1;
1497 } 1503 }
1498 switch (s->all_fragments[current_fragment].coding_method) { 1504 switch (s->macroblock_coding[current_macroblock]) {
1499 1505
1500 case MODE_INTER_PLUS_MV: 1506 case MODE_INTER_PLUS_MV:
1501 case MODE_GOLDEN_MV: 1507 case MODE_GOLDEN_MV:
1502 /* all 6 fragments use the same motion vector */ 1508 /* all 6 fragments use the same motion vector */
1503 if (coding_mode == 0) { 1509 if (coding_mode == 0) {
2337 s->pixel_addresses_inited = 0; 2343 s->pixel_addresses_inited = 0;
2338 2344
2339 /* init VLC tables */ 2345 /* init VLC tables */
2340 for (i = 0; i < 16; i++) { 2346 for (i = 0; i < 16; i++) {
2341 2347
2342 /* Dc histograms */ 2348 /* DC histograms */
2343 init_vlc(&s->dc_vlc[i], 5, 32, 2349 init_vlc(&s->dc_vlc[i], 5, 32,
2344 &dc_bias[i][0][1], 4, 2, 2350 &dc_bias[i][0][1], 4, 2,
2345 &dc_bias[i][0][0], 4, 2); 2351 &dc_bias[i][0][0], 4, 2);
2346 2352
2347 /* group 1 AC histograms */ 2353 /* group 1 AC histograms */
2363 init_vlc(&s->ac_vlc_4[i], 5, 32, 2369 init_vlc(&s->ac_vlc_4[i], 5, 32,
2364 &ac_bias_3[i][0][1], 4, 2, 2370 &ac_bias_3[i][0][1], 4, 2,
2365 &ac_bias_3[i][0][0], 4, 2); 2371 &ac_bias_3[i][0][0], 4, 2);
2366 } 2372 }
2367 2373
2368 /* build quantization table */ 2374 /* build quantization zigzag table */
2369 for (i = 0; i < 64; i++) 2375 for (i = 0; i < 64; i++)
2370 zigzag_index[dezigzag_index[i]] = i; 2376 zigzag_index[dezigzag_index[i]] = i;
2371 2377
2372 /* work out the block mapping tables */ 2378 /* work out the block mapping tables */
2373 s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); 2379 s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
2374 s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int)); 2380 s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int));
2375 s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int)); 2381 s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int));
2376 s->macroblock_coded = av_malloc(s->macroblock_count + 1); 2382 s->macroblock_coding = av_malloc(s->macroblock_count + 1);
2377 init_block_mapping(s); 2383 init_block_mapping(s);
2378 2384
2379 for (i = 0; i < 3; i++) { 2385 for (i = 0; i < 3; i++) {
2380 s->current_frame.data[i] = NULL; 2386 s->current_frame.data[i] = NULL;
2381 s->last_frame.data[i] = NULL; 2387 s->last_frame.data[i] = NULL;
2449 } else 2455 } else
2450 debug_vp3("\n"); 2456 debug_vp3("\n");
2451 2457
2452 init_frame(s, &gb); 2458 init_frame(s, &gb);
2453 2459
2454 #define KEYFRAMES_ONLY 1
2455 #if KEYFRAMES_ONLY 2460 #if KEYFRAMES_ONLY
2456 if (!s->keyframe) { 2461 if (!s->keyframe) {
2457 2462
2458 memcpy(s->current_frame.data[0], s->golden_frame.data[0], 2463 memcpy(s->current_frame.data[0], s->golden_frame.data[0],
2459 s->current_frame.linesize[0] * s->height); 2464 s->current_frame.linesize[0] * s->height);
2513 av_free(s->all_fragments); 2518 av_free(s->all_fragments);
2514 av_free(s->coded_fragment_list); 2519 av_free(s->coded_fragment_list);
2515 av_free(s->superblock_fragments); 2520 av_free(s->superblock_fragments);
2516 av_free(s->superblock_macroblocks); 2521 av_free(s->superblock_macroblocks);
2517 av_free(s->macroblock_fragments); 2522 av_free(s->macroblock_fragments);
2518 av_free(s->macroblock_coded); 2523 av_free(s->macroblock_coding);
2519 2524
2520 /* release all frames */ 2525 /* release all frames */
2521 if (s->golden_frame.data[0]) 2526 if (s->golden_frame.data[0])
2522 avctx->release_buffer(avctx, &s->golden_frame); 2527 avctx->release_buffer(avctx, &s->golden_frame);
2523 if (s->last_frame.data[0]) 2528 if (s->last_frame.data[0])