📄 ldecod.c
字号:
{
snprintf(errortext, ET_SIZE, "Error open file %s for appending",string);
error(errortext, 500);
}
else // Create header to new file
{
fprintf(p_log," ------------------------------------------------------------------------------------------\n");
fprintf(p_log,"| Decoder statistics. This file is made first time, later runs are appended |\n");
fprintf(p_log," ------------------------------------------------------------------------------------------ \n");
fprintf(p_log,"| Date | Time | Sequence |#Img|Format|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");
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);
snprintf(string, OUTSTRING_SIZE,"%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);
}
/*!
************************************************************************
* \brief
* Allocates the slice structure along with its dependent
* data structures
*
* \par Input:
* Input Parameters struct inp_par *inp, struct img_par *img
************************************************************************
*/
void malloc_slice(struct inp_par *inp, struct img_par *img)
{
int i;
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)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext,100);
}
img->currentSlice->rmpni_buffer=NULL;
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;
case PAR_DP_3:
error("Data Partitioning Mode 3 in 26L-Format not supported",1);
break;
default:
error("Data Partitioning Mode not supported!",1);
break;
}
currSlice->partArr = (DataPartition *) calloc(1, sizeof(DataPartition));
if (currSlice->partArr == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
dataPart = currSlice->partArr;
dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
if (dataPart->bitstream == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));
if (dataPart->bitstream->streamBuffer == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for bitstream buffer in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
return;
case PAR_OF_RTP:
img->currentSlice = (Slice *) calloc(1, sizeof(Slice));
if ( (currSlice = img->currentSlice) == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
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;
case PAR_DP_3:
currSlice->max_part_nr = 3;
break;
default:
error("Data Partitioning Mode not supported!",1);
break;
}
currSlice->partArr = (DataPartition *) calloc(3, sizeof(DataPartition));
if (currSlice->partArr == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
for (i=0; i<3; i++) // loop over all data partitions
{
dataPart = &(currSlice->partArr[i]);
dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
if (dataPart->bitstream == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));
if (dataPart->bitstream->streamBuffer == NULL)
{
snprintf(errortext, ET_SIZE, "Memory allocation for bitstream buffer in NAL-mode %d failed", inp->of_mode);
error(errortext, 100);
}
}
return;
default:
snprintf(errortext, ET_SIZE, "Output File Mode %d not supported", inp->of_mode);
error(errortext, 600);
}
}
/*!
************************************************************************
* \brief
* Memory frees of the Slice structure and of its dependent
* data structures
*
* \par Input:
* Input Parameters struct inp_par *inp, struct img_par *img
************************************************************************
*/
void free_slice(struct inp_par *inp, struct img_par *img)
{
int i;
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;
case PAR_OF_RTP:
// RTP File Format.
// Here, mallocSLice is always called with 3 partitions, although sometimes only one is used
for (i=0; i<3; i++) // loop over all data partitions
{
dataPart = &(currSlice->partArr[i]);
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:
snprintf(errortext, ET_SIZE, "Output File Mode %d not supported", inp->of_mode);
error(errortext, 400);
}
}
/*!
************************************************************************
* \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;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no;
#endif
#ifdef _ADAPT_LAST_GROUP_
if ((last_P_no = (int*)malloc(img->buf_cycle*sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: last_P_no");
#endif
// allocate memory for encoding frame buffers: imgY, imgUV
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
alloc_mref(img);
// allocate memory for imgY_prev
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
memory_size += get_mem2Dint(&refFrArr, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
// 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 for loop_filter
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("init_global_buffers: img->mb_data");
if(img->UseConstrainedIntraPred)
{
if(((img->intra_mb) = (int *) calloc(img->width/MB_BLOCK_SIZE * img->height/MB_BLOCK_SIZE,sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: img->intra_mb");
}
memory_size += get_mem3Dint(&(img->mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem2Dint(&(img->ipredmode),img->width/BLOCK_SIZE +2 , img->height/BLOCK_SIZE +2);
memory_size += get_mem3Dint(&(img->dfMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->dbMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem2Dint(&(img->fw_refFrArr),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&(img->bw_refFrArr),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
memory_size += get_mem3Dint(&(img->fw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->bw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
return (memory_size);
}
/*!
************************************************************************
* \brief
* Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int init_global_buffers()
*
* \par Input:
* Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* \par Output:
* none
*
************************************************************************
*/
void free_global_buffers(struct inp_par *inp, struct img_par *img)
{
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no;
free (last_P_no);
#endif
free_mem2D(imgY);
free_mem3D(imgUV,2);
free_mem2D(imgY_prev);
free_mem3D(imgUV_prev,2);
// free multiple ref frame buffers
free (mref);
free (mcef);
free_mem2Dint(refFrArr);
free_mem2D (imgY_ref);
free_mem3D (imgUV_ref,2);
free_mem2D (imgY_tmp);
free_mem3D (imgUV_tmp,2);
// free mem, allocated for structure img
if (img->mb_data != NULL) free(img->mb_data);
if(img->UseConstrainedIntraPred)
if (img->intra_mb != NULL) free(img->intra_mb);
free_mem3Dint(img->mv,img->width/BLOCK_SIZE + 4);
free_mem2Dint (img->ipredmode);
free_mem3Dint(img->dfMV,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dbMV,img->width/BLOCK_SIZE + 4);
free_mem2Dint(img->fw_refFrArr);
free_mem2Dint(img->bw_refFrArr);
free_mem3Dint(img->fw_mv,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->bw_mv,img->width/BLOCK_SIZE + 4);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -