?? ldecod.c
字號:
fprintf(p_log," ------------------------------------------------------------------------------------------\n");
}
}
else
p_log=fopen("log.dec","a"); /* File exist,just open for appending */
#ifdef WIN32
_strdate( timebuf );
fprintf(p_log,"| %1.5s |",timebuf );
_strtime( timebuf);
fprintf(p_log," % 1.5s |",timebuf);
#else
now = time ((time_t *) NULL); /* Get the system time and put it into 'now' as 'calender time' */
time (&now);
l_time = localtime (&now);
strftime (string, sizeof string, "%d-%b-%Y", l_time);
fprintf(p_log,"| %1.5s |",string );
strftime (string, sizeof string, "%H:%M:%S", l_time);
fprintf(p_log,"| %1.5s |",string );
#endif
fprintf(p_log,"%20.20s|",inp->infile);
fprintf(p_log,"%3d |",img->number);
fprintf(p_log,"%6.3f|",snr->snr_y1);
fprintf(p_log,"%6.3f|",snr->snr_u1);
fprintf(p_log,"%6.3f|",snr->snr_v1);
fprintf(p_log,"%6.3f|",snr->snr_ya);
fprintf(p_log,"%6.3f|",snr->snr_ua);
fprintf(p_log,"%6.3f|\n",snr->snr_va);
fclose(p_log);
sprintf(string,"%s", DATADECFILE);
p_log=fopen(string,"a");
if(Bframe_ctr != 0) // B picture used
{
fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d %.3f\n",
img->number, 0, img->qp,
snr->snr_y1,
snr->snr_u1,
snr->snr_v1,
0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
0,
(double)0.001*tot_time/(img->number+Bframe_ctr-1));
}
else
{
fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d %.3f\n",
img->number, 0, img->qp,
snr->snr_y1,
snr->snr_u1,
snr->snr_v1,
0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
0,
(double)0.001*tot_time/img->number);
}
fclose(p_log);
}
/************************************************************************
*
* Name : void malloc_slice()
*
* Description: Allocates the slice structure along with its dependent
* data structures
*
* Input : Input Parameters struct inp_par *inp, struct img_par *img
*
************************************************************************/
void malloc_slice(struct inp_par *inp, struct img_par *img)
{
DataPartition *dataPart;
Slice *currSlice;
const int buffer_size = MAX_CODED_FRAME_SIZE; /* picture size unknown at this time, this value is to check */
switch(inp->of_mode) /* init depending on NAL mode */
{
case PAR_OF_26L:
/* Current File Format */
img->currentSlice = (Slice *) calloc(1, sizeof(Slice));
if ( (currSlice = img->currentSlice) == NULL)
{
fprintf(stderr, "Memory allocation for Slice datastruct in NAL-mode %d failed", inp->of_mode);
exit(1);
}
if (inp->symbol_mode == CABAC)
{
/* create all context models */
currSlice->mot_ctx = create_contexts_MotionInfo();
currSlice->tex_ctx = create_contexts_TextureInfo();
}
switch(inp->partition_mode)
{
case PAR_DP_1:
currSlice->max_part_nr = 1;
break;
default:
error("Data Partitioning Mode not supported!");
break;
}
currSlice->partArr = (DataPartition *) calloc(1, sizeof(DataPartition));
if (currSlice->partArr == NULL)
{
fprintf(stderr, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", inp->of_mode);
exit(1);
}
dataPart = currSlice->partArr;
dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
if (dataPart->bitstream == NULL)
{
fprintf(stderr, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", inp->of_mode);
exit(1);
}
dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));
if (dataPart->bitstream->streamBuffer == NULL)
{
fprintf(stderr, "Memory allocation for bitstream buffer in NAL-mode %d failed", inp->of_mode);
exit(1);
}
return;
default:
fprintf(stderr, "Output File Mode %d not supported", inp->of_mode);
exit(1);
}
}
/************************************************************************
*
* Name : void free_slice()
*
* Description: Memory frees of the Slice structure and of its dependent
* data structures
*
* Input : Input Parameters struct inp_par *inp, struct img_par *img
*
************************************************************************/
void free_slice(struct inp_par *inp, struct img_par *img)
{
DataPartition *dataPart;
Slice *currSlice = img->currentSlice;
switch(inp->of_mode) /* init depending on NAL mode */
{
case PAR_OF_26L:
/* Current File Format */
dataPart = currSlice->partArr; /* only one active data partition */
if (dataPart->bitstream->streamBuffer != NULL)
free(dataPart->bitstream->streamBuffer);
if (dataPart->bitstream != NULL)
free(dataPart->bitstream);
if (currSlice->partArr != NULL)
free(currSlice->partArr);
if (inp->symbol_mode == CABAC)
{
/* delete all context models */
delete_contexts_MotionInfo(currSlice->mot_ctx);
delete_contexts_TextureInfo(currSlice->tex_ctx);
}
if (currSlice != NULL)
free(img->currentSlice);
break;
default:
fprintf(stderr, "Output File Mode %d not supported", inp->of_mode);
exit(1);
}
}
/************************************************************************
*
* Name : int get_mem4global_buffers(struct inp_par *inp, struct img_par *img)
*
* Description: Dynamic memory allocation of frame size related global buffers
* buffers are defined in global.h, allocated memory must be freed in
* void free_mem4global_buffers()
*
* Input : Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* Output : Number of allocated bytes
*
************************************************************************/
int get_mem4global_buffers(struct inp_par *inp, struct img_par *img)
{
int j,memory_size=0;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no;
#endif
img->buf_cycle = inp->buf_cycle+1;
#ifdef _ADAPT_LAST_GROUP_
if ((last_P_no = (int*)malloc(img->buf_cycle*sizeof(int))) == NULL) no_mem_exit(1);
#endif
/* allocate memory for encoding frame buffers: imgY, imgUV*/
/* byte imgY[288][352]; */
/* byte imgUV[2][144][176]; */
memory_size += get_mem2D(&imgY, img->height, img->width);
memory_size += get_mem3D(&imgUV, 2, img->height_cr, img->width_cr);
/* allocate memory for multiple ref. frame buffers: mref, mcref*/
/* rows and cols for croma component mcef[ref][croma][4x][4y] are switched */
/* compared to luma mref[ref][4y][4x] for whatever reason */
/* number of reference frames increased by one for next P-frame*/
memory_size += get_mem3D(&mref, img->buf_cycle+1, img->height, img->width);
if((mcef = (byte****)calloc(img->buf_cycle+1,sizeof(byte***))) == NULL) no_mem_exit(1);
for(j=0;j<img->buf_cycle+1;j++)
memory_size += get_mem3D(&(mcef[j]), 2, img->height_cr*2, img->width_cr*2);
/* allocate memory for B-frame coding (last upsampled P-frame): mref_P, mcref_P*/
/*byte mref[1152][1408]; */ /* 1/4 pix luma */
/*byte mcef[2][352][288]; */ /* pix chroma */
/* memory_size += get_mem2D(&mref_P, img->height*4, img->width*4);
memory_size += get_mem3D(&mcef_P, 2, img->height_cr*2, img->width_cr*2);
*/
/* allocate memory for mref_P_small B pictures */
/* byte mref_P_small[288][352]; */
/* memory_size += get_mem2D(&mref_P_small, img->height, img->width);
*/
/* allocate memory for imgY_prev */
/* byte imgY_prev[288][352]; */
/* byte imgUV_prev[2][144][176]; */
memory_size += get_mem2D(&imgY_prev, img->height, img->width);
memory_size += get_mem3D(&imgUV_prev, 2, img->height_cr, img->width_cr);
/* allocate memory for reference frames of each block: refFrArr*/
/* int refFrArr[72][88]; */
memory_size += get_mem2Dint(&refFrArr, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
/* allocate memory for filter strength for 4x4 lums and croma blocks:loopb, loopc*/
/*byte loopb[92][76]; i.e.[x][y]*/
/*byte loopc[48][40]; */
memory_size += get_mem2D(&loopb, img->width/BLOCK_SIZE+4, img->height/BLOCK_SIZE+4);
memory_size += get_mem2D(&loopc, img->width_cr/BLOCK_SIZE+4, img->height_cr/BLOCK_SIZE+4);
/* allocate memory for reference frame in find_snr */
//byte imgY_ref[288][352];
//byte imgUV_ref[2][144][176];
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 for loop_filter */
// byte imgY_tmp[288][352]; /* temp luma image */
// byte imgUV_tmp[2][144][176]; /* temp chroma image */
memory_size += get_mem2D(&imgY_tmp, img->height, img->width);
memory_size += get_mem3D(&imgUV_tmp, 2, img->height_cr, img->width_cr);
/* allocate memory in structure img */
if(((img->mb_data) = (Macroblock *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL)
no_mem_exit(1);
if(((img->slice_numbers) = (int *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(int))) == NULL)
no_mem_exit(1);
// img => int mv[92][72][3]
memory_size += get_mem3Dint(&(img->mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// img => int ipredmode[90][74]
memory_size += get_mem2Dint(&(img->ipredmode),img->width/BLOCK_SIZE +2 , img->height/BLOCK_SIZE +2);
// int dfMV[92][72][3];
memory_size += get_mem3Dint(&(img->dfMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int dbMV[92][72][3];
memory_size += get_mem3Dint(&(img->dbMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int fw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->fw_refFrArr),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int bw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->bw_refFrArr),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int fw_mv[92][72][3];
memory_size += get_mem3Dint(&(img->fw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int bw_mv[92][72][3];
memory_size += get_mem3Dint(&(img->bw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
return (memory_size);
}
/************************************************************************
*
* Name : void free_mem4global_buffers(struct inp_par *inp, struct img_par *img)
*
* Description: Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int get_mem4global_buffers()
*
* Input : Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* Output : none
*
************************************************************************/
void free_mem4global_buffers(struct inp_par *inp, struct img_par *img)
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -