00001
00045 #include "contributors.h"
00046
00047 #include <sys/stat.h>
00048
00049 #include "global.h"
00050 #include "image.h"
00051 #include "memalloc.h"
00052 #include "mc_prediction.h"
00053 #include "mbuffer.h"
00054 #include "leaky_bucket.h"
00055 #include "fmo.h"
00056 #include "output.h"
00057 #include "cabac.h"
00058 #include "parset.h"
00059 #include "sei.h"
00060 #include "erc_api.h"
00061 #include "quant.h"
00062 #include "block.h"
00063 #include "nalu.h"
00064
00065 #define JM "15 (FRExt)"
00066 #define VERSION "15.1"
00067 #define EXT_VERSION "(FRExt)"
00068
00069 #define LOGFILE "log.dec"
00070 #define DATADECFILE "dataDec.txt"
00071 #define TRACEFILE "trace_dec.txt"
00072
00073 extern objectBuffer_t *erc_object_list;
00074 extern ercVariables_t *erc_errorVar;
00075 extern ColocatedParams *Co_located;
00076 extern ColocatedParams *Co_located_JV[MAX_PLANE];
00077
00078
00079
00080
00081
00082
00083
00084
00085 extern StorablePicture* dec_picture;
00086
00087 struct inp_par *params;
00088 struct snr_par *snr;
00089 ImageParameters *img;
00090
00091 int global_init_done = 0;
00092
00099 void JMDecHelpExit (void)
00100 {
00101 fprintf( stderr, "\n ldecod [-h] {[defdec.cfg] | {[-p pocScale][-i bitstream.264]...[-o output.yuv] [-r reference.yuv] [-uv]}}\n\n"
00102 "## Parameters\n\n"
00103
00104 "## Options\n"
00105 " -h : prints function usage\n"
00106 " : parse <defdec.cfg> for decoder operation.\n"
00107 " -i : Input file name. \n"
00108 " -o : Output file name. If not specified default output is set as test_dec.yuv\n\n"
00109 " -r : Reference file name. If not specified default output is set as test_rec.yuv\n\n"
00110 " -p : Poc Scale. \n"
00111 " -uv : write chroma components for monochrome streams(4:2:0)\n"
00112 " -lp : By default the deblocking filter for High Intra-Only profile is off \n\t regardless of the flags in the bitstream. In the presence of\n\t this option, the loop filter usage will then be determined \n\t by the flags and parameters in the bitstream.\n\n"
00113
00114 "## Supported video file formats\n"
00115 " Input : .264 -> H.264 bitstream files. \n"
00116 " Output: .yuv -> RAW file. Format depends on bitstream information. \n\n"
00117
00118 "## Examples of usage:\n"
00119 " ldecod\n"
00120 " ldecod -h\n"
00121 " ldecod default.cfg\n"
00122 " ldecod -i bitstream.264 -o output.yuv -r reference.yuv\n");
00123
00124 exit(-1);
00125 }
00126
00127
00128 void Configure(int ac, char *av[])
00129 {
00130 int CLcount;
00131 char *config_filename=NULL;
00132 CLcount = 1;
00133
00134
00135 strcpy(params->infile,"test.264");
00136 strcpy(params->outfile,"test_dec.yuv");
00137 strcpy(params->reffile,"test_rec.yuv");
00138 params->FileFormat = PAR_OF_ANNEXB;
00139 params->ref_offset=0;
00140 params->poc_scale=2;
00141 params->silent = FALSE;
00142 params->intra_profile_deblocking = 0;
00143
00144 #ifdef _LEAKYBUCKET_
00145 params->R_decoder=500000;
00146 params->B_decoder=104000;
00147 params->F_decoder=73000;
00148 strcpy(params->LeakyBucketParamFile,"leakybucketparam.cfg");
00149 #endif
00150
00151 if (ac==2)
00152 {
00153 if (0 == strncmp (av[1], "-h", 2))
00154 {
00155 JMDecHelpExit();
00156 }
00157 else if (0 == strncmp (av[1], "-s", 2))
00158 {
00159 params->silent = TRUE;
00160 }
00161 else
00162 {
00163 config_filename=av[1];
00164 init_conf(params, av[1]);
00165 }
00166 CLcount=2;
00167 }
00168
00169 if (ac>=3)
00170 {
00171 if (0 == strncmp (av[1], "-i", 2))
00172 {
00173 strcpy(params->infile,av[2]);
00174 CLcount = 3;
00175 }
00176 if (0 == strncmp (av[1], "-h", 2))
00177 {
00178 JMDecHelpExit();
00179 }
00180 if (0 == strncmp (av[1], "-s", 2))
00181 {
00182 params->silent = TRUE;
00183 }
00184 }
00185
00186
00187
00188 while (CLcount < ac)
00189 {
00190 if (0 == strncmp (av[CLcount], "-h", 2))
00191 {
00192 JMDecHelpExit();
00193 }
00194 else if (0 == strncmp (av[CLcount], "-s", 2))
00195 {
00196 params->silent = TRUE;
00197 CLcount ++;
00198 }
00199 else if (0 == strncmp (av[CLcount], "-i", 2))
00200 {
00201 strcpy(params->infile,av[CLcount+1]);
00202 CLcount += 2;
00203 }
00204 else if (0 == strncmp (av[CLcount], "-o", 2))
00205 {
00206 strcpy(params->outfile,av[CLcount+1]);
00207 CLcount += 2;
00208 }
00209 else if (0 == strncmp (av[CLcount], "-r", 2))
00210 {
00211 strcpy(params->reffile,av[CLcount+1]);
00212 CLcount += 2;
00213 }
00214 else if (0 == strncmp (av[CLcount], "-p", 2))
00215 {
00216 sscanf (av[CLcount+1], "%d", ¶ms->poc_scale);
00217 CLcount += 2;
00218 }
00219 else if (0 == strncmp (av[CLcount], "-uv", 3))
00220 {
00221 params->write_uv = 1;
00222 CLcount ++;
00223 }
00224 else if (0 == strncmp (av[CLcount], "-lp", 3))
00225 {
00226 params->intra_profile_deblocking = 1;
00227 CLcount ++;
00228 }
00229 else
00230 {
00231 snprintf(errortext, ET_SIZE, "Invalid syntax. Use ldecod -h for proper usage");
00232 error(errortext, 300);
00233 }
00234 }
00235
00236 #if TRACE
00237 if ((p_trace=fopen(TRACEFILE,"w"))==0)
00238 {
00239 snprintf(errortext, ET_SIZE, "Error open file %s!",TRACEFILE);
00240 error(errortext,500);
00241 }
00242 #endif
00243
00244 if ((p_out=open(params->outfile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1)
00245 {
00246 snprintf(errortext, ET_SIZE, "Error open file %s ",params->outfile);
00247 error(errortext,500);
00248 }
00249
00250 fprintf(stdout,"----------------------------- JM %s %s -----------------------------\n", VERSION, EXT_VERSION);
00251 fprintf(stdout," Decoder config file : %s \n",config_filename);
00252 fprintf(stdout,"--------------------------------------------------------------------------\n");
00253 fprintf(stdout," Input H.264 bitstream : %s \n",params->infile);
00254 fprintf(stdout," Output decoded YUV : %s \n",params->outfile);
00255 fprintf(stdout," Output status file : %s \n",LOGFILE);
00256 if ((p_ref=open(params->reffile,OPENFLAGS_READ))==-1)
00257 {
00258 fprintf(stdout," Input reference file : %s does not exist \n",params->reffile);
00259 fprintf(stdout," SNR values are not available\n");
00260 }
00261 else
00262 fprintf(stdout," Input reference file : %s \n",params->reffile);
00263
00264 fprintf(stdout,"--------------------------------------------------------------------------\n");
00265 #ifdef _LEAKYBUCKET_
00266 fprintf(stdout," Rate_decoder : %8ld \n",params->R_decoder);
00267 fprintf(stdout," B_decoder : %8ld \n",params->B_decoder);
00268 fprintf(stdout," F_decoder : %8ld \n",params->F_decoder);
00269 fprintf(stdout," LeakyBucketParamFile: %s \n",params->LeakyBucketParamFile);
00270 calc_buffer(params);
00271 fprintf(stdout,"--------------------------------------------------------------------------\n");
00272 #endif
00273 if (!params->silent)
00274 {
00275 fprintf(stdout,"POC must = frame# or field# for SNRs to be correct\n");
00276 fprintf(stdout,"--------------------------------------------------------------------------\n");
00277 fprintf(stdout," Frame POC Pic# QP SnrY SnrU SnrV Y:U:V Time(ms)\n");
00278 fprintf(stdout,"--------------------------------------------------------------------------\n");
00279 }
00280
00281 }
00282
00291 static void alloc_img( ImageParameters **img)
00292 {
00293 if ((*img = (ImageParameters *) calloc(1, sizeof(ImageParameters)))==NULL)
00294 no_mem_exit("alloc_img: img");
00295
00296 get_mem3Dpel(&((*img)->mb_pred), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00297 get_mem3Dpel(&((*img)->mb_rec ), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00298 get_mem3Dint(&((*img)->mb_rres), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00299 get_mem3Dint(&((*img)->cof ), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00300
00301
00302 allocate_block_mem();
00303 allocate_pred_mem();
00304 }
00305
00314 static void free_img( ImageParameters *img)
00315 {
00316 free_pred_mem();
00317 free_block_mem();
00318
00319 free_mem3Dint(img->cof );
00320 free_mem3Dint(img->mb_rres);
00321 free_mem3Dpel(img->mb_rec );
00322 free_mem3Dpel(img->mb_pred);
00323 free (img);
00324 }
00331 int main(int argc, char **argv)
00332 {
00333 int i;
00334 int nplane;
00335
00336
00337 if ((params = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: params");
00338 if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr");
00339
00340
00341 alloc_img(&img);
00342
00343 Configure (argc, argv);
00344
00345 initBitsFile(params->FileFormat);
00346
00347 bitsfile.OpenBitsFile(params->infile);
00348
00349
00350 malloc_slice(params, img);
00351 init_old_slice(&old_slice);
00352
00353 init(img);
00354
00355 dec_picture = NULL;
00356
00357 dpb.init_done = 0;
00358 g_nFrame = 0;
00359
00360 init_out_buffer();
00361
00362
00363 Bframe_ctr = snr->frame_ctr = 0;
00364
00365
00366 tot_time = 0;
00367
00368
00369 for(i=0;i<17;i++)
00370 {
00371 ref_flag[i] = 1;
00372 }
00373
00374 while (decode_one_frame(img, params, snr) != EOS)
00375 ;
00376
00377 report(params, img, snr);
00378 free_slice(img);
00379 FmoFinit();
00380 free_global_buffers();
00381
00382 flush_dpb();
00383
00384 #if (PAIR_FIELDS_IN_OUTPUT)
00385 flush_pending_output(p_out);
00386 #endif
00387
00388 bitsfile.CloseBitsFile();
00389
00390 close(p_out);
00391 if (p_ref!=-1)
00392 close(p_ref);
00393
00394 #if TRACE
00395 fclose(p_trace);
00396 #endif
00397
00398 ercClose(erc_errorVar);
00399
00400 CleanUpPPS();
00401
00402 free_dpb();
00403 uninit_out_buffer();
00404 if( IS_INDEPENDENT(img) )
00405 {
00406 for( nplane = 0; nplane < MAX_PLANE; nplane++ )
00407 {
00408 free_colocated(Co_located_JV[nplane]);
00409 }
00410 }
00411 else
00412 {
00413 free_colocated(Co_located);
00414 }
00415 free (params);
00416 free (snr);
00417 free_img (img);
00418
00419 return 0;
00420 }
00421
00422
00429 void init(ImageParameters *img)
00430 {
00431 img->oldFrameSizeInMbs = -1;
00432
00433 imgY_ref = NULL;
00434 imgUV_ref = NULL;
00435
00436 img->recovery_point = 0;
00437 img->recovery_point_found = 0;
00438 img->recovery_poc = 0x7fffffff;
00439
00440 img->idr_psnr_number = params->ref_offset;
00441 img->psnr_number=0;
00442
00443 img->number = 0;
00444 img->type = I_SLICE;
00445
00446 img->dec_ref_pic_marking_buffer = NULL;
00447
00448 #if (ENABLE_OUTPUT_TONEMAPPING)
00449 init_tone_mapping_sei();
00450 #endif
00451 }
00452
00459 void init_frext(ImageParameters *img)
00460 {
00461
00462 img->bitdepth_luma_qp_scale = 6 * (img->bitdepth_luma - 8);
00463 if(img->bitdepth_luma > img->bitdepth_chroma || active_sps->chroma_format_idc == YUV400)
00464 img->pic_unit_bitsize_on_disk = (img->bitdepth_luma > 8)? 16:8;
00465 else
00466 img->pic_unit_bitsize_on_disk = (img->bitdepth_chroma > 8)? 16:8;
00467 img->dc_pred_value_comp[0] = 1<<(img->bitdepth_luma - 1);
00468 img->max_imgpel_value_comp[0] = (1<<img->bitdepth_luma) - 1;
00469 img->mb_size[0][0] = img->mb_size[0][1] = MB_BLOCK_SIZE;
00470
00471 if (active_sps->chroma_format_idc != YUV400)
00472 {
00473
00474 img->bitdepth_chroma_qp_scale = 6 * (img->bitdepth_chroma - 8);
00475 img->dc_pred_value_comp[1] = (1 << (img->bitdepth_chroma - 1));
00476 img->dc_pred_value_comp[2] = img->dc_pred_value_comp[1];
00477 img->max_imgpel_value_comp[1] = (1 << img->bitdepth_chroma) - 1;
00478 img->max_imgpel_value_comp[2] = (1 << img->bitdepth_chroma) - 1;
00479 img->num_blk8x8_uv = (1 << active_sps->chroma_format_idc) & (~(0x1));
00480 img->num_uv_blocks = (img->num_blk8x8_uv >> 1);
00481 img->num_cdc_coeff = (img->num_blk8x8_uv << 1);
00482 img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422)? 8 : 16;
00483 img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = (active_sps->chroma_format_idc==YUV444 || active_sps->chroma_format_idc==YUV422)? 16 : 8;
00484 }
00485 else
00486 {
00487 img->bitdepth_chroma_qp_scale = 0;
00488 img->max_imgpel_value_comp[1] = 0;
00489 img->max_imgpel_value_comp[2] = 0;
00490 img->num_blk8x8_uv = 0;
00491 img->num_uv_blocks = 0;
00492 img->num_cdc_coeff = 0;
00493 img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = 0;
00494 img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = 0;
00495 }
00496 img->mb_size_blk[0][0] = img->mb_size_blk[0][1] = img->mb_size[0][0] >> 2;
00497 img->mb_size_blk[1][0] = img->mb_size_blk[2][0] = img->mb_size[1][0] >> 2;
00498 img->mb_size_blk[1][1] = img->mb_size_blk[2][1] = img->mb_size[1][1] >> 2;
00499
00500 img->mb_size_shift[0][0] = img->mb_size_shift[0][1] = CeilLog2_sf (img->mb_size[0][0]);
00501 img->mb_size_shift[1][0] = img->mb_size_shift[2][0] = CeilLog2_sf (img->mb_size[1][0]);
00502 img->mb_size_shift[1][1] = img->mb_size_shift[2][1] = CeilLog2_sf (img->mb_size[1][1]);
00503
00504 init_qp_process(img);
00505 }
00506
00513 inline static void conf_read_check (int val, int expected)
00514 {
00515 if (val != expected)
00516 {
00517 error ("init_conf: error reading from config file", 500);
00518 }
00519 }
00520
00533 void init_conf(struct inp_par *inp, char *config_filename)
00534 {
00535 FILE *fd;
00536 int NAL_mode;
00537
00538
00539 long int temp;
00540 char tempval[100];
00541
00542
00543 if((fd=fopen(config_filename,"r")) == NULL)
00544 {
00545 snprintf(errortext, ET_SIZE, "Error: Control file %s not found\n",config_filename);
00546 error(errortext, 300);
00547 }
00548
00549 conf_read_check (fscanf(fd,"%s",inp->infile), 1);
00550 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00551
00552 conf_read_check (fscanf(fd,"%s",inp->outfile), 1);
00553 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00554
00555 conf_read_check (fscanf(fd,"%s",inp->reffile), 1);
00556 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00557
00558 conf_read_check (fscanf(fd,"%d",&(inp->write_uv)), 1);
00559 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00560
00561 conf_read_check (fscanf(fd,"%d",&(NAL_mode)), 1);
00562 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00563
00564 switch(NAL_mode)
00565 {
00566 case 0:
00567 inp->FileFormat = PAR_OF_ANNEXB;
00568 break;
00569 case 1:
00570 inp->FileFormat = PAR_OF_RTP;
00571 break;
00572 default:
00573 snprintf(errortext, ET_SIZE, "NAL mode %i is not supported", NAL_mode);
00574 error(errortext,400);
00575 }
00576
00577 conf_read_check (fscanf(fd,"%d,",&inp->ref_offset), 1);
00578 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00579
00580 conf_read_check (fscanf(fd,"%d,",&inp->poc_scale), 1);
00581 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00582
00583
00584 if (inp->poc_scale < 1 || inp->poc_scale > 10)
00585 {
00586 snprintf(errortext, ET_SIZE, "Poc Scale is %d. It has to be within range 1 to 10",inp->poc_scale);
00587 error(errortext,1);
00588 }
00589
00590 inp->write_uv=1;
00591
00592
00593 img->conceal_mode = inp->conceal_mode = 0;
00594 img->ref_poc_gap = inp->ref_poc_gap = 2;
00595 img->poc_gap = inp->poc_gap = 2;
00596
00597 #ifdef _LEAKYBUCKET_
00598 conf_read_check (fscanf(fd,"%ld,",&inp->R_decoder), 1);
00599 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00600 conf_read_check (fscanf(fd,"%ld,",&inp->B_decoder), 1);
00601 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00602 conf_read_check (fscanf(fd,"%ld,",&inp->F_decoder), 1);
00603 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00604 conf_read_check (fscanf(fd,"%s",inp->LeakyBucketParamFile), 1);
00605 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00606 #endif
00607
00608
00609
00610
00611 #ifndef _LEAKYBUCKET_
00612 conf_read_check (fscanf(fd,"%ld,",&temp), 1);
00613 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00614 conf_read_check (fscanf(fd,"%ld,",&temp), 1);
00615 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00616 conf_read_check (fscanf(fd,"%ld,",&temp), 1);
00617 conf_read_check (fscanf(fd, "%*[^\n]"), 0);
00618 conf_read_check (fscanf(fd,"%s",tempval), 1);
00619 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00620 #endif
00621
00622 conf_read_check (fscanf(fd,"%d",&inp->conceal_mode), 1);
00623 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00624 img->conceal_mode = inp->conceal_mode;
00625 conf_read_check (fscanf(fd,"%d",&inp->ref_poc_gap), 1);
00626 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00627 img->ref_poc_gap = inp->ref_poc_gap;
00628 conf_read_check (fscanf(fd,"%d",&inp->poc_gap), 1);
00629 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00630 img->poc_gap = inp->poc_gap;
00631 conf_read_check (fscanf(fd,"%d,",&inp->silent), 1);
00632 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00633 conf_read_check (fscanf(fd,"%d,",&inp->intra_profile_deblocking), 1);
00634 conf_read_check (fscanf(fd,"%*[^\n]"), 0);
00635
00636 fclose (fd);
00637 }
00638
00653 void report(struct inp_par *inp, ImageParameters *img, struct snr_par *snr)
00654 {
00655 #define OUTSTRING_SIZE 255
00656 char string[OUTSTRING_SIZE];
00657 FILE *p_log;
00658 char yuv_formats[4][4]= { {"400"}, {"420"}, {"422"}, {"444"} };
00659
00660 #ifndef WIN32
00661 time_t now;
00662 struct tm *l_time;
00663 #else
00664 char timebuf[128];
00665 #endif
00666
00667
00668 tot_time = timenorm(tot_time);
00669
00670 if (params->silent == FALSE)
00671 {
00672 fprintf(stdout,"-------------------- Average SNR all frames ------------------------------\n");
00673 fprintf(stdout," SNR Y(dB) : %5.2f\n",snr->snra[0]);
00674 fprintf(stdout," SNR U(dB) : %5.2f\n",snr->snra[1]);
00675 fprintf(stdout," SNR V(dB) : %5.2f\n",snr->snra[2]);
00676 fprintf(stdout," Total decoding time : %.3f sec (%.3f fps)\n",tot_time*0.001,(snr->frame_ctr ) * 1000.0 / tot_time);
00677 fprintf(stdout,"--------------------------------------------------------------------------\n");
00678 fprintf(stdout," Exit JM %s decoder, ver %s ",JM, VERSION);
00679 fprintf(stdout,"\n");
00680 }
00681 else
00682 {
00683 fprintf(stdout,"\n----------------------- Decoding Completed -------------------------------\n");
00684 fprintf(stdout," Total decoding time : %.3f sec (%.3f fps)\n",tot_time*0.001, (snr->frame_ctr) * 1000.0 / tot_time);
00685 fprintf(stdout,"--------------------------------------------------------------------------\n");
00686 fprintf(stdout," Exit JM %s decoder, ver %s ",JM, VERSION);
00687 fprintf(stdout,"\n");
00688 }
00689
00690
00691
00692 snprintf(string, OUTSTRING_SIZE, "%s", LOGFILE);
00693
00694 if ((p_log=fopen(string,"r"))==0)
00695 {
00696 if ((p_log=fopen(string,"a"))==0)
00697 {
00698 snprintf(errortext, ET_SIZE, "Error open file %s for appending",string);
00699 error(errortext, 500);
00700 }
00701 else
00702 {
00703 fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n");
00704 fprintf(p_log,"| Decoder statistics. This file is made first time, later runs are appended |\n");
00705 fprintf(p_log," ------------------------------------------------------------------------------------------------------------------- \n");
00706 fprintf(p_log,"| ver | Date | Time | Sequence |#Img| Format | YUV |Coding|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");
00707 fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n");
00708 }
00709 }
00710 else
00711 {
00712 fclose(p_log);
00713 p_log=fopen(string,"a");
00714 }
00715
00716 fprintf(p_log,"|%s/%-4s", VERSION, EXT_VERSION);
00717
00718 #ifdef WIN32
00719 _strdate( timebuf );
00720 fprintf(p_log,"| %1.5s |",timebuf );
00721
00722 _strtime( timebuf);
00723 fprintf(p_log," % 1.5s |",timebuf);
00724 #else
00725 now = time ((time_t *) NULL);
00726 time (&now);
00727 l_time = localtime (&now);
00728 strftime (string, sizeof string, "%d-%b-%Y", l_time);
00729 fprintf(p_log,"| %1.5s |",string );
00730
00731 strftime (string, sizeof string, "%H:%M:%S", l_time);
00732 fprintf(p_log,"| %1.5s |",string );
00733 #endif
00734
00735 fprintf(p_log,"%20.20s|",inp->infile);
00736
00737 fprintf(p_log,"%3d |",img->number);
00738 fprintf(p_log,"%4dx%-4d|", img->width, img->height);
00739 fprintf(p_log," %s |", &(yuv_formats[img->yuv_format][0]));
00740
00741 if (active_pps)
00742 {
00743 if (active_pps->entropy_coding_mode_flag == UVLC)
00744 fprintf(p_log," CAVLC|");
00745 else
00746 fprintf(p_log," CABAC|");
00747 }
00748
00749 fprintf(p_log,"%6.3f|",snr->snr1[0]);
00750 fprintf(p_log,"%6.3f|",snr->snr1[1]);
00751 fprintf(p_log,"%6.3f|",snr->snr1[2]);
00752 fprintf(p_log,"%6.3f|",snr->snra[0]);
00753 fprintf(p_log,"%6.3f|",snr->snra[1]);
00754 fprintf(p_log,"%6.3f|",snr->snra[2]);
00755 fprintf(p_log,"\n");
00756 fclose(p_log);
00757
00758 snprintf(string, OUTSTRING_SIZE,"%s", DATADECFILE);
00759 p_log=fopen(string,"a");
00760
00761 if(Bframe_ctr != 0)
00762 {
00763 fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
00764 "%2.2f %2.2f %2.2f %5d "
00765 "%2.2f %2.2f %2.2f %5d %.3f\n",
00766 img->number, 0, img->qp,
00767 snr->snr1[0],
00768 snr->snr1[1],
00769 snr->snr1[2],
00770 0,
00771 0.0,
00772 0.0,
00773 0.0,
00774 0,
00775 snr->snra[0],
00776 snr->snra[1],
00777 snr->snra[2],
00778 0,
00779 (double)0.001*tot_time/(img->number+Bframe_ctr-1));
00780 }
00781 else
00782 {
00783 fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
00784 "%2.2f %2.2f %2.2f %5d "
00785 "%2.2f %2.2f %2.2f %5d %.3f\n",
00786 img->number, 0, img->qp,
00787 snr->snr1[0],
00788 snr->snr1[1],
00789 snr->snr1[2],
00790 0,
00791 0.0,
00792 0.0,
00793 0.0,
00794 0,
00795 snr->snra[0],
00796 snr->snra[1],
00797 snr->snra[2],
00798 0,
00799 (double)0.001*tot_time/img->number);
00800 }
00801 fclose(p_log);
00802 }
00803
00818 DataPartition *AllocPartition(int n)
00819 {
00820 DataPartition *partArr, *dataPart;
00821 int i;
00822
00823 partArr = (DataPartition *) calloc(n, sizeof(DataPartition));
00824 if (partArr == NULL)
00825 {
00826 snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Data Partition failed");
00827 error(errortext, 100);
00828 }
00829
00830 for (i=0; i<n; i++)
00831 {
00832 dataPart = &(partArr[i]);
00833 dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
00834 if (dataPart->bitstream == NULL)
00835 {
00836 snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Bitstream failed");
00837 error(errortext, 100);
00838 }
00839 dataPart->bitstream->streamBuffer = (byte *) calloc(MAX_CODED_FRAME_SIZE, sizeof(byte));
00840 if (dataPart->bitstream->streamBuffer == NULL)
00841 {
00842 snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for streamBuffer failed");
00843 error(errortext, 100);
00844 }
00845 }
00846 return partArr;
00847 }
00848
00849
00850
00851
00869 void FreePartition (DataPartition *dp, int n)
00870 {
00871 int i;
00872
00873 assert (dp != NULL);
00874 assert (dp->bitstream != NULL);
00875 assert (dp->bitstream->streamBuffer != NULL);
00876 for (i=0; i<n; i++)
00877 {
00878 free (dp[i].bitstream->streamBuffer);
00879 free (dp[i].bitstream);
00880 }
00881 free (dp);
00882 }
00883
00884
00895 void malloc_slice(struct inp_par *inp, ImageParameters *img)
00896 {
00897 Slice *currSlice;
00898
00899 img->currentSlice = (Slice *) calloc(1, sizeof(Slice));
00900 if ( (currSlice = img->currentSlice) == NULL)
00901 {
00902 snprintf(errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", inp->FileFormat);
00903 error(errortext,100);
00904 }
00905
00907
00908 if (1)
00909 {
00910
00911 currSlice->mot_ctx = create_contexts_MotionInfo();
00912 currSlice->tex_ctx = create_contexts_TextureInfo();
00913 }
00914
00915 currSlice->max_part_nr = 3;
00916 currSlice->partArr = AllocPartition(currSlice->max_part_nr);
00917 }
00918
00919
00930 void free_slice(ImageParameters *img)
00931 {
00932 Slice *currSlice = img->currentSlice;
00933
00934 FreePartition (currSlice->partArr, 3);
00935
00936 if (1)
00937 {
00938
00939 delete_contexts_MotionInfo(currSlice->mot_ctx);
00940 delete_contexts_TextureInfo(currSlice->tex_ctx);
00941 }
00942 free(img->currentSlice);
00943
00944 currSlice = NULL;
00945 }
00946
00961 int init_global_buffers(void)
00962 {
00963 int memory_size=0;
00964 int i;
00965
00966 if (global_init_done)
00967 {
00968 free_global_buffers();
00969 }
00970
00971
00972 memory_size += get_mem2Dpel(&imgY_ref, img->height, img->width);
00973
00974 if (active_sps->chroma_format_idc != YUV400)
00975 memory_size += get_mem3Dpel(&imgUV_ref, 2, img->height_cr, img->width_cr);
00976 else
00977 imgUV_ref=NULL;
00978
00979
00980 if( IS_INDEPENDENT(img) )
00981 {
00982 for( i=0; i<MAX_PLANE; i++ )
00983 {
00984 if(((img->mb_data_JV[i]) = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
00985 no_mem_exit("init_global_buffers: img->mb_data");
00986 }
00987 img->mb_data = NULL;
00988 }
00989 else
00990 {
00991 if(((img->mb_data) = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
00992 no_mem_exit("init_global_buffers: img->mb_data");
00993 }
00994
00995 if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL)
00996 no_mem_exit("init_global_buffers: img->intra_block");
00997
00998 memory_size += get_mem2Dint(&PicPos,img->FrameSizeInMbs + 1,2);
00999
01000 for (i = 0; i < (int) img->FrameSizeInMbs + 1;i++)
01001 {
01002 PicPos[i][0] = (i % img->PicWidthInMbs);
01003 PicPos[i][1] = (i / img->PicWidthInMbs);
01004 }
01005
01006 memory_size += get_mem2D(&(img->ipredmode), 4*img->FrameHeightInMbs, 4*img->PicWidthInMbs);
01007
01008 memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3);
01009 memory_size += get_mem3Dint(&(img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3);
01010 memory_size += get_mem4Dint(&(img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3);
01011
01012
01013 memory_size += get_mem4D(&(img->nz_coeff), img->FrameSizeInMbs, 3, BLOCK_SIZE, BLOCK_SIZE);
01014
01015 memory_size += get_mem2Dint(&(img->siblock), img->FrameHeightInMbs, img->PicWidthInMbs);
01016
01017 global_init_done = 1;
01018
01019 img->oldFrameSizeInMbs = img->FrameSizeInMbs;
01020
01021 return (memory_size);
01022 }
01023
01039 void free_global_buffers(void)
01040 {
01041 free_mem2Dpel (imgY_ref);
01042 if (imgUV_ref)
01043 free_mem3Dpel (imgUV_ref);
01044
01045
01046 free_mem4D(img->nz_coeff);
01047
01048 free_mem2Dint(img->siblock);
01049
01050
01051 if (img->mb_data != NULL)
01052 free(img->mb_data);
01053
01054 free_mem2Dint(PicPos);
01055
01056 free (img->intra_block);
01057 free_mem2D(img->ipredmode);
01058
01059 free_mem3Dint(img->wp_weight);
01060 free_mem3Dint(img->wp_offset);
01061 free_mem4Dint(img->wbp_weight);
01062
01063 free_qp_matrices();
01064
01065 global_init_done = 0;
01066
01067 }
01068