📄 ldecod.c
字号:
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_IFF:
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_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 i,j;
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 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_block) = (int**)calloc((j=(img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE)),sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: img->intra_block");
for (i=0; i<j; i++)
{
if ((img->intra_block[i] = (int*)calloc(4, sizeof(int))) == NULL)
no_mem_exit ("init_global_buffers: img->intra_block");
}
}
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)
{
int i,j;
#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 mem, allocated for structure img
if (img->mb_data != NULL) free(img->mb_data);
if(img->UseConstrainedIntraPred)
{
j = (img->width/16)*(img->height/16);
for (i=0; i<j; i++)
{
free (img->intra_block[i]);
}
free (img->intra_block);
}
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 + -