00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064
00065 #include "config.h"
00066 #include "tmndec.h"
00067 #include "global.h"
00068
00069
00070 static void getpicturehdr _ANSI_ARGS_ ((void));
00071
00072
00073
00074
00075 int getheader ()
00076 {
00077 unsigned int code, gob;
00078
00079
00080 startcode ();
00081 code = getbits (PSC_LENGTH);
00082 gob = getbits (5);
00083 if (gob == SE_CODE)
00084 return 0;
00085 if (gob == 0)
00086 {
00087 getpicturehdr ();
00088 if (syntax_arith_coding)
00089 decoder_reset ();
00090 }
00091 return gob + 1;
00092 }
00093
00094
00095
00096
00097 void startcode ()
00098 {
00099
00100 while (showbits (PSC_LENGTH) != 1l)
00101 flushbits (1);
00102 }
00103
00104
00105
00106 static void getpicturehdr ()
00107 {
00108 int pos, pei, tmp;
00109 int TRPI = 0;
00110 int BCI = 0;
00111 int clock_conversion_code = 0;
00112 int clock_divisor = 0;
00113 int extended_temporal_reference = 0;
00114
00115 UFEP = 0;
00116
00117 pos = ld->bitcnt;
00118
00119 temp_ref = getbits (8);
00120
00121 if (trd < 0)
00122 trd += 256;
00123
00124 tmp = getbits (1);
00125
00126 tmp = getbits (1);
00127
00128 tmp = getbits (1);
00129
00130 if (tmp)
00131 {
00132 exit (-1);
00133 }
00134
00135 tmp = getbits (1);
00136
00137 tmp = getbits (1);
00138
00139 tmp = getbits (3);
00140
00141 if (tmp == 0)
00142 {
00143 exit (-1);
00144 }
00145
00146 if (tmp == EXTENDED_PTYPE)
00147 {
00148 plus_type = 1;
00149 UFEP = getbits (3);
00150
00151 if (UFEP == 1)
00152 {
00153 source_format = getbits (3);
00154
00155
00156 optional_custom_PCF = getbits (1);
00157
00158 if (optional_custom_PCF)
00159 {
00160 exit (-1);
00161 }
00162 mv_outside_frame = getbits (1);
00163
00164 long_vectors = (mv_outside_frame ? 1 : 0);
00165 syntax_arith_coding = getbits (1);
00166
00167 adv_pred_mode = getbits (1);
00168
00169 mv_outside_frame = (adv_pred_mode ? 1 : mv_outside_frame);
00170 overlapping_MC = (adv_pred_mode ? 1 : 0);
00171 use_4mv = (adv_pred_mode ? 1 : 0);
00172 pb_frame = 0;
00173 advanced_intra_coding = getbits (1);
00174
00175 deblocking_filter_mode = getbits (1);
00176
00177 mv_outside_frame = (deblocking_filter_mode ? 1 : mv_outside_frame);
00178 use_4mv = (deblocking_filter_mode ? 1 : use_4mv);
00179
00180 slice_structured_mode = getbits (1);
00181
00182 if (slice_structured_mode)
00183 {
00184 exit (-1);
00185 }
00186 reference_picture_selection_mode = getbits (1);
00187
00188 independently_segmented_decoding_mode = getbits (1);
00189
00190 if (independently_segmented_decoding_mode)
00191 {
00192 exit (-1);
00193 }
00194 alternative_inter_VLC_mode = getbits (1);
00195
00196 modified_quantization_mode = getbits (1);
00197
00198 tmp = getbits (4);
00199
00200 if (tmp != 8)
00201 {
00202 exit (-1);
00203 }
00204 }
00205 if ((UFEP == 1) || (UFEP == 0))
00206 {
00207 if (UFEP == 0)
00208 {
00209 if (scalability_mode >= 3)
00210 {
00211 horizontal_size = lines[base_source_format];
00212 vertical_size = pels[base_source_format];
00213
00214 mb_width = horizontal_size / 16;
00215 mb_height = vertical_size / 16;
00216
00217
00218
00219
00220
00221 ref_coded_picture_width = coded_picture_width = horizontal_size;
00222 ref_coded_picture_height = coded_picture_height = vertical_size;
00223 ref_chrom_width = chrom_width = coded_picture_width >> 1;
00224 ref_chrom_height = chrom_height = coded_picture_height >> 1;
00225
00226 source_format = base_source_format;
00227 }
00228 }
00229
00230
00231
00232 pict_type = getbits (3);
00233
00234 if (pict_type == PCT_IPB)
00235 pb_frame = IM_PB_FRAMES;
00236 else
00237 pb_frame = 0;
00238
00239 if (PCT_B == pict_type)
00240 {
00241 true_B_frame = ON;
00242
00243
00244 mv_outside_frame = 1;
00245 true_b_trb = temp_ref - prev_non_disposable_temp_ref;
00246 if (true_b_trb < 0)
00247 true_b_trb += 256;
00248 } else
00249 {
00250 true_B_frame = OFF;
00251 prev_non_disposable_temp_ref = next_non_disposable_temp_ref;
00252 next_non_disposable_temp_ref = temp_ref;
00253 trd = temp_ref - prev_non_disposable_temp_ref;
00254 if (trd < 0)
00255 trd += 256;
00256 }
00257
00258 reference_picture_resampling_mode = getbits (1);
00259
00260 if (reference_picture_resampling_mode)
00261 {
00262 exit (-1);
00263 }
00264 reduced_resolution_update_mode = getbits (1);
00265
00266 if (reduced_resolution_update_mode)
00267 {
00268 exit (-1);
00269 }
00270 rtype = getbits (1);
00271
00272
00273 tmp = getbits (3);
00274
00275 if (tmp != 1)
00276 {
00277 if (!quiet)
00278 exit (-1);
00279 }
00280 } else
00281 {
00282
00283 exit (-1);
00284 }
00285
00286 tmp = getbits (1);
00287
00288 if (tmp)
00289 {
00290 exit (-1);
00291 }
00292
00293 if (UFEP && (source_format == SF_CUSTOM))
00294 {
00295
00296 CP_PAR_code = getbits (4);
00297 if (CP_PAR_code != PAR_CIF)
00298 {
00299 exit(-1);
00300 }
00301 tmp=getbits (9);
00302 horizontal_size = (tmp + 1 ) * 4;
00303 tmp = getbits (1);
00304 if (!tmp)
00305 {
00306 exit (-1);
00307 }
00308 tmp = getbits (9);
00309 vertical_size = tmp * 4;
00310 if ((horizontal_size%16) || (vertical_size%16))
00311 {
00312 exit (-1);
00313 }
00314
00315 if (CP_PAR_code == EXTENDED_PAR)
00316 {
00317 PAR_width = getbits (8);
00318 PAR_height = getbits (8);
00319 }
00320 }
00321
00322 if (source_format != SF_CUSTOM)
00323 {
00324 horizontal_size = lines[source_format];
00325 vertical_size = pels[source_format];
00326
00327 }
00328 mb_width = horizontal_size / 16;
00329 mb_height = vertical_size / 16;
00330
00331
00332
00333
00334
00335 ref_coded_picture_width = coded_picture_width;
00336 coded_picture_width = horizontal_size;
00337
00338 ref_coded_picture_height = coded_picture_height;
00339 coded_picture_height = vertical_size;
00340
00341 ref_chrom_width = chrom_width;
00342 chrom_width = coded_picture_width >> 1;
00343
00344 ref_chrom_height = chrom_height;
00345 chrom_height = coded_picture_height >> 1;
00346
00347 if (optional_custom_PCF)
00348 {
00349 if (UFEP)
00350 {
00351 clock_conversion_code = getbits (1);
00352 clock_divisor = getbits (7);
00353 CP_clock_frequency = (int) (1800 / ((float) clock_divisor * (8 + clock_conversion_code)) * 1000);
00354 }
00355
00356 extended_temporal_reference = getbits (2);
00357 temp_ref = extended_temporal_reference << 8 + temp_ref;
00358
00359 if (PCT_B == pict_type)
00360 {
00361 true_b_trb = temp_ref - prev_non_disposable_temp_ref;
00362 } else
00363 {
00364 trd = temp_ref - prev_non_disposable_temp_ref;
00365 }
00366
00367 if (trd < 0)
00368 trd += 1024;
00369 }
00370 if (UFEP && long_vectors)
00371 {
00372 if (getbits(1))
00373 {
00374 unlimited_unrestricted_motion_vectors = 0;
00375 }
00376 else
00377 {
00378 flushbits(1);
00379 unlimited_unrestricted_motion_vectors = 1;
00380 }
00381 }
00382 if (UFEP && slice_structured_mode)
00383 {
00384 SSS_rectangular_slices = getbits (1);
00385 SSS_arbitary_slice_ordering = getbits (1);
00386
00387 }
00388
00389 if ((pict_type == PCT_B) || (pict_type == PCT_EI) || (pict_type == PCT_EP))
00390 {
00391
00392 enhancement_layer_num = getbits (4);
00393 if (UFEP)
00394 {
00395 reference_layer_number = getbits (4);
00396 }
00397 if (1 != enhancement_layer_num)
00398 {
00399 if (source_format != base_source_format)
00400 {
00401 if (source_format != SF_CUSTOM)
00402 {
00403 scalability_mode = SPATIAL_SCALABILITY_HV;
00404 }
00405 else if (coded_picture_width != ref_coded_picture_width)
00406 {
00407 scalability_mode = SPATIAL_SCALABILITY_H;
00408 }
00409 else
00410 {
00411 scalability_mode = SPATIAL_SCALABILITY_V;
00412 }
00413 }
00414 else
00415 {
00416 scalability_mode = SNR_SCALABILITY;
00417 }
00418 }
00419 }
00420 else
00421 {
00422 enhancement_layer_num = reference_layer_number = 1;
00423 }
00424
00425 if (reference_picture_selection_mode)
00426 {
00427 if (UFEP)
00428 {
00429 MF_of_reference_picture_selection = getbits (3);
00430 }
00431 TRPI = getbits (1);
00432 if (TRPI)
00433 {
00434
00435
00436 temporal_reference_for_prediction = getbits (10);
00437 }
00438 if (showbits (1))
00439 {
00440
00441
00442 flushbits (1);
00443 exit (-1);
00444 }
00445 else
00446 {
00447
00448 BCI = getbits (2);
00449 }
00450 }
00451 if (reference_picture_resampling_mode)
00452 {
00453
00454 exit (-1);
00455 }
00456 pic_quant = getbits (5);
00457 quant = pic_quant;
00458
00459 }
00460 else
00461 {
00462 plus_type = 0;
00463 rtype = 0;
00464 source_format = tmp;
00465 enhancement_layer_num = reference_layer_number = 1;
00466
00467 horizontal_size = lines[source_format];
00468 vertical_size = pels[source_format];
00469
00470 mb_width = horizontal_size / 16;
00471 mb_height = vertical_size / 16;
00472
00473
00474
00475
00476
00477 ref_coded_picture_width = coded_picture_width = horizontal_size;
00478 ref_coded_picture_height = coded_picture_height = vertical_size;
00479 ref_chrom_width = chrom_width = coded_picture_width >> 1;
00480 ref_chrom_height = chrom_height = coded_picture_height >> 1;
00481
00482 true_B_frame = OFF;
00483 prev_non_disposable_temp_ref = next_non_disposable_temp_ref;
00484 next_non_disposable_temp_ref = temp_ref;
00485 trd = temp_ref - prev_non_disposable_temp_ref;
00486 if (trd < 0)
00487 trd += 256;
00488
00489 pict_type = getbits (1);
00490 mv_outside_frame = getbits (1);
00491 long_vectors = (mv_outside_frame ? 1 : 0);
00492 syntax_arith_coding = getbits (1);
00493 adv_pred_mode = getbits (1);
00494 mv_outside_frame = (adv_pred_mode ? 1 : mv_outside_frame);
00495 overlapping_MC = (adv_pred_mode ? 1 : 0);
00496 use_4mv = (adv_pred_mode ? 1 : 0);
00497 pb_frame = getbits (1);
00498
00499 pic_quant = getbits (5);
00500 quant = pic_quant;
00501
00502
00503 tmp = getbits (1);
00504 if (tmp)
00505 {
00506 exit (-1);
00507 }
00508 }
00509
00510 if (pb_frame)
00511 {
00512 if (optional_custom_PCF)
00513 {
00514 trb = getbits (5);
00515 } else
00516 {
00517 trb = getbits (3);
00518 }
00519
00520 bquant = getbits (2);
00521 } else
00522 {
00523 trb = 0;
00524 }
00525
00526 #ifdef USE_TIME
00527 if (framerate > 0 && trd > 0)
00528 doframerate (0);
00529 #endif
00530
00531 pei = getbits (1);
00532
00533 pspare:
00534 if (pei)
00535 {
00536
00537 getbits (8);
00538 pei = getbits (1);
00539 if (pei)
00540 goto pspare;
00541 }
00542 }
00543
00544
00545
00546 void getgobheader()
00547 {
00548 int BCI = 0;
00549
00550
00551 gfid = getbits (2);
00552
00553
00554
00555
00556
00557 if (gfid != pgfid && newgob)
00558 {
00559 if (pict_type == PCT_INTRA)
00560 pict_type = PCT_INTER;
00561 else if (pict_type == PCT_INTER)
00562 pict_type = PCT_INTRA;
00563 }
00564
00565 quant = getbits (5);
00566
00567 if (reference_picture_selection_mode)
00568 {
00569 TRI = getbits (1);
00570 if (TRI)
00571 {
00572
00573 temp_ref = optional_custom_PCF?getbits (10):getbits(8);
00574 }
00575
00576 TRPI = getbits (1);
00577 if (TRPI)
00578 {
00579
00580 temporal_reference_for_prediction = getbits (10);
00581 }
00582 if (showbits (1))
00583 {
00584
00585
00586 flushbits (1);
00587 exit (-1);
00588 }
00589 else
00590 {
00591
00592 BCI = getbits (2);
00593 }
00594 }
00595 pgfid = gfid;
00596 }
00597 void initoptions ()
00598 {
00599 mv_outside_frame = 0;
00600 syntax_arith_coding = 0;
00601 adv_pred_mode = 0;
00602 pb_frame = 0;
00603 long_vectors = 0;
00604
00605 plus_type = 0;
00606 optional_custom_PCF = 0;
00607 advanced_intra_coding = 0;
00608 deblocking_filter_mode = 0;
00609 slice_structured_mode = 0;
00610 reference_picture_selection_mode = 0;
00611 independently_segmented_decoding_mode = 0;
00612 alternative_inter_VLC_mode = 0;
00613 modified_quantization_mode = 0;
00614 reduced_resolution_update_mode = 0;
00615 reference_picture_resampling_mode = 0;
00616 rtype = 0;
00617 }