/*! ************************************************************************ * \brief * Dynamic memory allocation of frame size related global buffers * buffers are defined in global.h, allocated memory must be freed in * void free_global_buffers() * * \par Input: * Input Parameters struct inp_par *inp, Image Parameters struct img_par *img * * \par Output: * Number of allocated bytes *********************************************************************** */ int init_global_buffers() { int memory_size=0; if (global_init_done) { free_global_buffers(); } // allocate memory for reference frame in find_snr memory_size += get_mem2D(&imgY_ref, img->height, img->width); memory_size += get_mem3D(&imgUV_ref, 2, img->height_cr, img->width_cr); // allocate memory in structure img if(((img->mb_data) = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: img->mb_data"); if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode), 4*img->PicWidthInMbs , 4*img->FrameHeightInMbs); memory_size += get_mem2Dint(&(img->field_anchor),4*img->FrameHeightInMbs, 4*img->PicWidthInMbs); memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 6); memory_size += get_mem2Dint(&(img->siblock),img->PicWidthInMbs , img->FrameHeightInMbs); global_init_done = 1; img->oldFrameSizeInMbs = img->FrameSizeInMbs; return (memory_size); }
/*! ************************************************************************ * \brief * Dynamic memory allocation of frame size related global buffers * buffers are defined in global.h, allocated memory must be freed in * void free_global_buffers() * * \par Input: * Input Parameters struct inp_par *inp, Image Parameters struct img_par *img * * \par Output: * Number of allocated bytes *********************************************************************** */ int init_global_buffers(struct inp_par *inp, struct img_par *img) { int memory_size=0; if (global_init_done) { free_global_buffers(inp, img); } if (img->structure != FRAME) { img->height *= 2; // set height to frame (twice of field) for normal variables img->height_cr *= 2; // set height to frame (twice of field) for normal variables } // allocate memory for reference frame in find_snr memory_size += get_mem2D(&imgY_ref, img->height, img->width); memory_size += get_mem3D(&imgUV_ref, 2, img->height_cr, img->width_cr); // allocate memory in structure img #ifndef STATIC_ALLOC if(((img->mb_data) = (Macroblock *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: img->mb_data"); if(((img->intra_block) = (int*)calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode),img->width/BLOCK_SIZE , img->height/BLOCK_SIZE); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 6); memory_size += get_mem2Dint(&(img->siblock),img->width/MB_BLOCK_SIZE , img->height/MB_BLOCK_SIZE); #else // ipredmode memory_size += (1920/BLOCK_SIZE) * (1088/BLOCK_SIZE) * sizeof(int); // CAVLC mem // nz_coeff memory_size += (1920/MB_BLOCK_SIZE) * (1088/MB_BLOCK_SIZE) * 4 * 6 * sizeof(int); // siblock memory_size += (176/MB_BLOCK_SIZE) * (144/MB_BLOCK_SIZE) * sizeof(int); #endif memory_size += get_mem2Dint(&(img->field_anchor),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE); memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(img->wp_offset), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(img->wbp_weight), 2, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); if (img->structure != FRAME) { img->height /= 2; // reset height for normal variables img->height_cr /= 2; // reset height for normal variables } global_init_done = 1; return (memory_size); }
//int ldecod(/*int argc, char **argv*/) //int ldecod(char * cfg_file) //int ldecod(char * cfg_file, unsigned char * bitstream) //int ldecod(char * cfg_file, unsigned char * bitstream, unsigned int length) int ldecod(unsigned char * bitstream, unsigned int length) #endif { // allocate memory for the structures if (Frame_cnt == 0) { if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); } // Read Configuration File /* if (argc != 2) { snprintf(errortext, ET_SIZE, "Usage: %s <config.dat> \n\t<config.dat> defines decoder parameters",argv[0]); error(errortext, 300); } */ Bitstream_leng = length; //init_conf(input, cfg_file);// read cfg & init init_conf2(input);// read cfg & init g_new_frame=1; switch (input->FileFormat) { case 0: //OpenBitstreamFile (input->infile);//Load bitsteam: master_read() OpenBitstreamFile2 (bitstream);//Load bitsteam: master_read() break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); dec_picture = NULL; dpb.init_done = 0; // init_dpb(input); init_out_buffer(); img->idr_psnr_number=0; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->tr_old = -1; // WYK: Oct. 8, 2001, for detection of a new frame img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=0; // time for total decoding session tot_time = 0; #ifdef ESLSC tb_hls_cavld_p = (tb_hls_cavld*)tb; #endif // one clock cycle for one frame //printf("[%d]",Frame_cnt); //cout<< "-->start_time:"<<sc_time_stamp() << endl; while (decode_one_frame(img, input, snr) != EOS) { //flush_one_dpb();//cylin num_pending_frame++; if(!flag_start_dump_frame){ //cout<< sc_time_stamp() <<"\t"<<" ldecode().event_dump_one_frame_req.notify"<<endl; flag_start_dump_frame = 1; event_dump_one_frame_req.notify(5*CLK_CYCLES, CLK_UNIT);//CYLin:define in "global.h" } } //if(flag_start_dump_frame && num_pending_frame >= FRAME_BUFFER_SIZE) if(num_pending_frame >= FRAME_BUFFER_SIZE) wait(event_dump_one_frame_end);//CYLin:waiting pre-frame __report(input, img, snr); if(Frame_cnt == 60) { //if(flag_start_dump_frame) while(num_pending_frame){ wait(event_dump_one_frame_end);//CYLin:waiting pre-frame } free_slice(input,img); FmoFinit(); free_global_buffers(input, img); //printf("******** flush_dpb() ***********\n");//cylin.debug flush_dpb(); //CloseBitstreamFile(); CloseBitstreamFile2(); // fclose(p_out); // fclose(p_out2); if (p_ref) fclose(p_ref); #if TRACE fclose(p_trace); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free (input); free (snr); free (img); } //while( !kbhit() ); return 0; }
/*! *********************************************************************** * \brief * main function for TML decoder *********************************************************************** */ int main(int argc, char **argv) { // allocate memory for the structures if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); // Read Configuration File if (argc != 2) { snprintf(errortext, ET_SIZE, "Usage: %s <config.dat> \n\t<config.dat> defines decoder parameters",argv[0]); error(errortext, 300); } init_conf(input, argv[1]); init_old_slice(); switch (input->FileFormat) { case 0: OpenBitstreamFile (input->infile); break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); dec_picture = NULL; dpb.init_done = 0; g_nFrame = 0; // init_dpb(input); init_out_buffer(); img->idr_psnr_number=input->ref_offset; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=0; // time for total decoding session tot_time = 0; while (decode_one_frame(img, input, snr) != EOS) ; report(input, img, snr); free_slice(input,img); FmoFinit(); free_global_buffers(); flush_dpb(); #ifdef PAIR_FIELDS_IN_OUTPUT flush_pending_output(p_out); #endif CloseBitstreamFile(); fclose(p_out); // fclose(p_out2); if (p_ref) fclose(p_ref); #if TRACE fclose(p_trace); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free_collocated(Co_located); free (input); free (snr); free (img); //while( !kbhit() ); return 0; }
/*! ************************************************************************ * \brief * Dynamic memory allocation of frame size related global buffers * buffers are defined in global.h, allocated memory must be freed in * void free_global_buffers() * * \par Input: * Input Parameters struct inp_par *inp, Image Parameters struct img_par *img * * \par Output: * Number of allocated bytes *********************************************************************** */ int init_global_buffers() { int memory_size=0; int quad_range, i; if (global_init_done) { free_global_buffers(); } // allocate memory for reference frame in find_snr memory_size += get_mem2Dpel(&imgY_ref, img->height, img->width); if (active_sps->chroma_format_idc != YUV400) memory_size += get_mem3Dpel(&imgUV_ref, 2, img->height_cr, img->width_cr); else imgUV_ref=NULL; // allocate memory in structure img if(((img->mb_data) = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: img->mb_data"); if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode), 4*img->PicWidthInMbs , 4*img->FrameHeightInMbs); memory_size += get_mem2Dint(&(img->field_anchor),4*img->FrameHeightInMbs, 4*img->PicWidthInMbs); memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 4 + img->num_blk8x8_uv); memory_size += get_mem2Dint(&(img->siblock),img->PicWidthInMbs , img->FrameHeightInMbs); if(img->max_imgpel_value > img->max_imgpel_value_uv || active_sps->chroma_format_idc == YUV400) quad_range = (img->max_imgpel_value + 1) * 2; else quad_range = (img->max_imgpel_value_uv + 1) * 2; if ((img->quad = (int*)calloc (quad_range, sizeof(int))) == NULL) no_mem_exit ("init_img: img->quad"); for (i=0; i < quad_range/2; ++i) { img->quad[i]=i*i; } #ifdef ADAPTIVE_FILTER memory_size += get_mem2Ddouble (&tmp_coef, 21, 16); #endif #ifdef ADAPTIVE_LOOP_FILTER memory_size += InitALFGlobalBuffers(); #endif global_init_done = 1; img->oldFrameSizeInMbs = img->FrameSizeInMbs; return (memory_size); }
/*! *********************************************************************** * \brief * main function for TML decoder *********************************************************************** */ int main2(int argc, char **argv) { int i; // allocate memory for the structures if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); Configure (argc, argv); init_old_slice(); switch (input->FileFormat) { case 0: OpenBitstreamFile (input->infile); break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); #ifdef ADAPTIVE_FILTER InitAdaptiveFilter(); #endif #ifdef MV_COMPETITION init_MV_Competition(); #endif dec_picture = NULL; dpb.init_done = 0; g_nFrame = 0; init_out_buffer(); img->idr_psnr_number=input->ref_offset; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=snr->frame_ctr=0; // time for total decoding session tot_time = 0; // reference flag initialization for(i=0; i<17; i++) { ref_flag[i]=1; } while (decode_one_frame(img, input, snr) != EOS) ; report(input, img, snr); free_slice(input,img); FmoFinit(); free_global_buffers(); flush_dpb(); #ifdef PAIR_FIELDS_IN_OUTPUT flush_pending_output(p_out); #endif CloseBitstreamFile(); close(p_out); // fclose(p_out2); if (p_ref!=-1) close(p_ref); #if TRACE fclose(p_trace); #endif #ifdef MV_COMPETITION close_MV_Competition(); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free_colocated(Co_located); free (input); free (snr); free (img); //while( !kbhit() ); return 0; }