📄 mbuffer.c
字号:
pic_mem_idx++;
//fprintf(fpic_mem, "Picture to be decoded is a ");
switch(dec_picture->structure)
{
case FRAME:
//fprintf(fpic_mem, "Frame: FrameNum(%d), POC(%d,%d)\n", img->frame_num, img->toppoc, img->bottompoc);
break;
case TOP_FIELD:
//fprintf(fpic_mem, "Top_Field: FrameNum(%d), POC(%d)\n", img->frame_num, img->toppoc);
break;
default:
//fprintf(fpic_mem, "Bottom_Field: FrameNum(%d), POC(%d)\n", img->frame_num, img->bottompoc);
break;
}
if (structure == FRAME)
{
dpb.memory_used[pic_mem_idx] = 1;
dpb.memory_used[pic_mem_idx + 1] = 1;
dpb.memory_used_poc[pic_mem_idx] = img->toppoc;
dpb.memory_used_poc[pic_mem_idx+1] = img->bottompoc;
memory_operation[memory_operation_size].action = OCCUPY;
memory_operation[memory_operation_size].memory_start = pic_mem_idx;
memory_operation[memory_operation_size].frame_field = IS_FRAME;
memory_operation_size++;
//fprintf(fpic_mem, "occupy mem[%d,%d] for frame, POC(%d,%d)\n", pic_mem_idx, pic_mem_idx+1, img->toppoc, img->bottompoc);
}
else
{
dpb.memory_used[pic_mem_idx] = 1;
dpb.memory_used_poc[pic_mem_idx] = (structure == TOP_FIELD ? img->toppoc : img->bottompoc);
memory_operation[memory_operation_size].action = OCCUPY;
memory_operation[memory_operation_size].memory_start = pic_mem_idx;
memory_operation[memory_operation_size].frame_field = IS_FIELD;
memory_operation_size++;
//fprintf(fpic_mem, "occupy mem[%d] for field, POC(%d)\n", pic_mem_idx, (structure == TOP_FIELD ? img->toppoc : img->bottompoc));
}
return pic_mem_idx;
}
/*!
************************************************************************
* \brief
* Allocate memory for a stored picture.
*
* \param structure
* picture structure
* \param size_x
* horizontal luma size
* \param size_y
* vertical luma size
* \param size_x_cr
* horizontal chroma size
* \param size_y_cr
* vertical chroma size
*
* \return
* the allocated StorablePicture structure
************************************************************************
*/
StorablePicture* alloc_storable_picture(PictureStructure structure, int size_x, int size_y, int size_x_cr, int size_y_cr)
{
StorablePicture *s;
//printf ("Allocating (%s) picture (x=%d, y=%d, x_cr=%d, y_cr=%d)\n", (type == FRAME)?"FRAME":(type == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", size_x, size_y, size_x_cr, size_y_cr);
s = calloc (1, sizeof(StorablePicture));
if (NULL==s)
no_mem_exit("alloc_storable_picture: s");
if (structure!=FRAME)
{
size_y /= 2;
size_y_cr /= 2;
}
s->PicSizeInMbs = (size_x*size_y)/256;
s->pic_mem_idx = -2;
// s->imgUV = NULL;
// get_mem2Dpel (&(s->imgY), size_y, size_x);
// if (active_sps->chroma_format_idc != YUV400)
// get_mem3Dpel (&(s->imgUV), 2, size_y_cr, size_x_cr);
//
// s->mb_field = calloc (s->PicSizeInMbs, sizeof(int));
// if (NULL==s->mb_field)
// no_mem_exit("alloc_storable_picture: s->mb_field");
//
// get_mem2Dshort (&(s->slice_id), size_y / MB_BLOCK_SIZE, size_x / MB_BLOCK_SIZE);
//
// get_mem3D ((byte****)(&(s->ref_idx)) , 2, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE);
// get_mem3Dint64 (&(s->ref_pic_id), 6, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE);
// get_mem3Dint64 (&(s->ref_id) , 6, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE);
// get_mem4Dshort (&(s->mv) , 2, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE, 2);
//
// get_mem2D (&(s->moving_block), size_y / BLOCK_SIZE, size_x / BLOCK_SIZE);
// get_mem2D (&(s->field_frame) , size_y / BLOCK_SIZE, size_x / BLOCK_SIZE);
s->pic_num=0;
s->frame_num=0;
s->long_term_frame_idx=0;
s->long_term_pic_num=0;
s->used_for_reference=0;
s->is_long_term=0;
s->non_existing=0;
s->is_output = 0;
s->max_slice_id = 0;
s->structure=structure;
s->size_x = size_x;
s->size_y = size_y;
s->size_x_cr = size_x_cr;
s->size_y_cr = size_y_cr;
s->size_x_m1 = size_x - 1;
s->size_y_m1 = size_y - 1;
s->size_x_cr_m1 = size_x_cr - 1;
s->size_y_cr_m1 = size_y_cr - 1;
// s->top_field = NULL;
// s->bottom_field = NULL;
// s->frame = NULL;
s->top_field = no_reference_picture;
s->bottom_field = no_reference_picture;
s->frame = no_reference_picture;
s->dec_ref_pic_marking_buffer = NULL;
s->coded_frame = 0;
s->MbaffFrameFlag = 0;
s->top_poc = s->bottom_poc = s->poc = 0;
s->seiHasTone_mapping = 0;
return s;
}
/*!
************************************************************************
* \brief
* Free frame store memory.
*
* \param f
* FrameStore to be freed
*
************************************************************************
*/
void free_frame_store(FrameStore* f)
{
if (f)
{
if (f->frame)
{
free_storable_picture(f->frame);
f->frame=NULL;
// mark corresponding fields' memory as released.
if (f->top_field)
{
if (f->top_field->pic_mem_idx >= 0)
{
f->top_field->pic_mem_idx = -2;
}
}
if (f->bottom_field)
{
if (f->bottom_field->pic_mem_idx >= 0)
{
f->bottom_field->pic_mem_idx = -1;
}
}
}
if (f->top_field)
{
free_storable_picture(f->top_field);
f->top_field=NULL;
}
if (f->bottom_field)
{
free_storable_picture(f->bottom_field);
f->bottom_field=NULL;
}
free(f);
}
}
extern FILE *fpic_mem;
/*!
************************************************************************
* \brief
* Free picture memory.
*
* \param p
* Picture to be freed
*
************************************************************************
*/
void free_storable_picture(StorablePicture* p)
{
if (p)
{
// if (p->ref_idx)
// {
// free_mem3D ((byte***)p->ref_idx, 2);
// p->ref_idx = NULL;
// }
//
// if (p->ref_pic_id)
// {
// free_mem3Dint64 (p->ref_pic_id, 6);
// p->ref_pic_id = NULL;
// }
// if (p->ref_id)
// {
// free_mem3Dint64 (p->ref_id, 6);
// p->ref_id = NULL;
// }
// if (p->mv)
// {
// free_mem4Dshort (p->mv, 2, p->size_y / BLOCK_SIZE);
// p->mv = NULL;
// }
//
// if (p->moving_block)
// {
// free_mem2D (p->moving_block);
// p->moving_block=NULL;
// }
//
// if (p->field_frame)
// {
// free_mem2D (p->field_frame);
// p->field_frame=NULL;
// }
//
//
// if (p->imgY)
// {
// free_mem2Dpel (p->imgY);
// p->imgY=NULL;
// }
// if (p->imgUV)
// {
// free_mem3Dpel (p->imgUV, 2);
// p->imgUV=NULL;
// }
//
// if (p->mb_field)
// {
// free(p->mb_field);
// p->mb_field=NULL;
// }
//
// if (p->slice_id)
// {
// free_mem2Dshort(p->slice_id);
// p->slice_id=NULL;
// }
// release the occupied memory.
if (p->pic_mem_idx >= 0)
{
if (p->structure == FRAME)
{
dpb.memory_used[p->pic_mem_idx] = 0;
dpb.memory_used[p->pic_mem_idx+1] = 0;
dpb.memory_used_poc[p->pic_mem_idx] = -1;
dpb.memory_used_poc[p->pic_mem_idx+1] = -1;
memory_operation[memory_operation_size].action = RELEASE;
memory_operation[memory_operation_size].memory_start = p->pic_mem_idx;
memory_operation[memory_operation_size].frame_field = IS_FRAME;
memory_operation_size++;
//fprintf(fpic_mem, "release mem[%d, %d] for frame, POC(%d, %d)\n", p->pic_mem_idx, p->pic_mem_idx+1, p->top_poc, p->bottom_poc);
}
else
{
dpb.memory_used[p->pic_mem_idx] = 0;
dpb.memory_used_poc[p->pic_mem_idx] = -1;
memory_operation[memory_operation_size].action = RELEASE;
memory_operation[memory_operation_size].memory_start = p->pic_mem_idx;
memory_operation[memory_operation_size].frame_field = IS_FIELD;
memory_operation_size++;
//fprintf(fpic_mem, "release mem[%d] for field, POC(%d)\n\n", p->pic_mem_idx, p->structure == TOP_FIELD ? p->top_poc : p->bottom_poc);
}
}
if (p->seiHasTone_mapping)
free(p->tone_mapping_lut);
free(p);
p = NULL;
}
}
/*!
************************************************************************
* \brief
* mark FrameStore unused for reference
*
************************************************************************
*/
static void unmark_for_reference(FrameStore* fs)
{
if (fs->is_used & 1)
{
if (fs->top_field)
{
fs->top_field->used_for_reference = 0;
}
}
if (fs->is_used & 2)
{
if (fs->bottom_field)
{
fs->bottom_field->used_for_reference = 0;
}
}
if (fs->is_used == 3)
{
if (fs->top_field && fs->bottom_field)
{
fs->top_field->used_for_reference = 0;
fs->bottom_field->used_for_reference = 0;
}
fs->frame->used_for_reference = 0;
}
fs->is_reference = 0;
// if(fs->frame)
// {
// if (fs->frame->ref_pic_id)
// {
// free_mem3Dint64 (fs->frame->ref_pic_id, 6);
// fs->frame->ref_pic_id = NULL;
// }
// if (fs->frame->ref_id)
// {
// free_mem3Dint64 (fs->frame->ref_id, 6);
// fs->frame->ref_id = NULL;
// }
// }
// if (fs->top_field)
// {
// if (fs->top_field->ref_pic_id)
// {
// free_mem3Dint64 (fs->top_field->ref_pic_id, 6);
// fs->top_field->ref_pic_id = NULL;
// }
// if (fs->top_field->ref_id)
// {
// free_mem3Dint64 (fs->top_field->ref_id, 6);
// fs->top_field->ref_id = NULL;
// }
// }
// if (fs->bottom_field)
// {
// if (fs->bottom_field->ref_pic_id)
// {
// free_mem3Dint64 (fs->bottom_field->ref_pic_id, 6);
// fs->bottom_field->ref_pic_id = NULL;
// }
// if (fs->bottom_field->ref_id)
// {
// free_mem3Dint64 (fs->bottom_field->ref_id, 6);
// fs->bottom_field->ref_id = NULL;
// }
// }
}
/*!
************************************************************************
* \brief
* mark FrameStore unused for reference and reset long term flags
*
************************************************************************
*/
static void unmark_for_long_term_reference(FrameStore* fs)
{
if (fs->is_used & 1)
{
if (fs->top_field)
{
fs->top_field->used_for_reference = 0;
fs->top_field->is_long_term = 0;
}
}
if (fs->is_used & 2)
{
if (fs->bottom_field)
{
fs->bottom_field->used_for_reference = 0;
fs->bottom_field->is_long_term = 0;
}
}
if (fs->is_used == 3)
{
if (fs->top_field && fs->bottom_field)
{
fs->top_field->used_for_reference = 0;
fs->top_field->is_long_term = 0;
fs->bottom_field->used_for_reference = 0;
fs->bottom_field->is_long_term = 0;
}
fs->frame->used_for_reference = 0;
fs->frame->is_long_term = 0;
}
fs->is_reference = 0;
fs->is_long_term = 0;
}
/*!
************************************************************************
* \brief
* compares two stored pictures by picture number for qsort in descending order
*
************************************************************************
*/
static int compare_pic_by_pic_num_desc( const void *arg1, const void *arg2 )
{
if ( (*(StorablePicture**)arg1)->pic_num < (*(StorablePicture**)arg2)->pic_num)
return 1;
if ( (*(StorablePicture**)arg1)->pic_num > (*(StorablePicture**)arg2)->pic_num)
return -1;
else
return 0;
}
/*!
************************************************************************
* \brief
* compares two stored pictures by picture number for qsort in descending order
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -