📄 mbuffer.c
字号:
}
}
/*!
************************************************************************
* \brief
* remove short term frame from buffer
*
* \param shortID
* short term ID
*
************************************************************************
*/
void remove_short_term(int shortID)
{
int i,j;
Frame *f;
for (i=0;i<fb->short_used;i++)
{
if ((fb->picbuf_short[i]->picID)==shortID)
{
fb->picbuf_short[i]->used=0;
fb->picbuf_short[i]->lt_picID=-1;
fb->picbuf_short[i]->picID=-1;
fb->short_used--;
if (i<fb->short_used)
{
f=fb->picbuf_short[i];
for (j=i;j<fb->short_used-1;j++);
fb->picbuf_short[j]=fb->picbuf_short[j+1];
fb->picbuf_short[fb->short_used-1]=f;
}
}
}
}
/*!
************************************************************************
* \brief
* (re)-allocate memory for mref pointer structure
************************************************************************
*/
void alloc_mref(ImageParameters *img)
{
if (mref)
free (mref);
if((mref = (byte***)calloc(fb->short_size+fb->long_size,sizeof(byte**))) == NULL)
no_mem_exit("alloc_mref: mref");
if (mcef)
free (mcef);
if((mcef = (byte****)calloc(fb->short_size+fb->long_size,sizeof(byte***))) == NULL)
no_mem_exit("alloc_mref: mcef");
}
/*!
************************************************************************
* \brief
* init mref pointer structure
************************************************************************
*/
void init_mref(ImageParameters *img)
{
int i,j;
for (i=0,j=0;i<fb->short_used;i++)
{
mref[j]=fb->picbuf_short[i]->mref;
mcef[j]=fb->picbuf_short[i]->mcef;
j++;
}
for (i=0;i<fb->long_size;i++)
{
mref[j]=fb->picbuf_long[i]->mref;
mcef[j]=fb->picbuf_long[i]->mcef;
j++;
}
}
/*!
************************************************************************
* \brief
* process RMPNI command list
************************************************************************
*/
void reorder_mref(ImageParameters *img)
{
RMPNIbuffer_t *r;
int pnp = img->pn;
int pnq;
int index,i;
int size;
int islong=0;
int found=0;
Frame **fr;
Frame *f;
// if nothing to do update mref and return
if (img->currentSlice->rmpni_buffer==NULL)
{
init_mref(img);
return;
}
// We have to do the reordering with complete frame structures
// so we need a temporary frame buffer of ordered references
size=fb->short_used+fb->long_used;
if ((fr=(Frame**)calloc(size,sizeof (Frame*)))==NULL) no_mem_exit("init_frame_buffers: fb->picbuf_long");
for (i=0;i<fb->short_used;i++)
{
fr[i]=fb->picbuf_short[i];
fr[i]->islong=0;
}
for (i=0;i<fb->long_used;i++)
{
fr[i+fb->short_used]=fb->picbuf_long[i];
fr[i+fb->short_used]->islong=1;
}
r=img->currentSlice->rmpni_buffer;
while (r)
{
switch (r->RMPNI)
{
case 0:
// ADPN correspondig to negative difference
if ((pnp-r->Data)<0)
pnq=pnp-r->Data+fb->short_size;
else
pnq=pnp-r->Data;
islong=0;
break;
case 1:
// ADPN correspondig to positive difference
if ((pnp+r->Data)>fb->short_size-1)
pnq=pnp+r->Data-fb->short_size;
else
pnq=pnp+r->Data;
islong=0;
break;
case 2:
// LPIR specifying long term index
pnq=r->Data;
islong=1;
break;
case 3:
return;
break;
}
// now scan the frame buffer for the needed frame
found=0;
i=0;
while ((!found)&&(i<size))
{
if (((!islong)&&(!fr[i]->islong) && (fr[i]->picID==pnq)) ||
((islong)&&(fr[i]->islong) && (fr[i]->lt_picID==pnq)))
{
found=1;
index=i;
}
i++;
}
if (!found) error ("tried to remap non-existent picture",400);
// now do the actual reordering
/* cycle frame buffer */
f=fr[index];
for (i=index-1;i>=0;i--)
{
fr[i+1]=fr[i];
}
fr[0]=f;
// set the picture number prediction correctly
pnp=pnq;
img->currentSlice->rmpni_buffer=r->Next;
free (r);
r=img->currentSlice->rmpni_buffer;
}
// at last init mref and mcef from temporary structure
for (i=0;i<size;i++)
{
mref[i]=fr[i]->mref;
mcef[i]=fr[i]->mcef;
}
// free temporary memory
free (fr);
}
/*!
************************************************************************
* \brief
* mark all frames except last decoded unused
************************************************************************
*/
void reset_buffers()
{
int i;
/* mark short term pictures unused */
for (i=1;i<fb->short_used;i++)
fb->picbuf_short[i]->used=0;
fb->short_used=1;
/* mark short term pictures unused */
for (i=0;i<fb->long_used;i++)
fb->picbuf_short[i]->used=0;
fb->long_used=0;
}
/*!
************************************************************************
* \brief
* calculate the short term picture ID from DPN
************************************************************************
*/
int get_short_ID(int DPN, ImageParameters *img)
{
if ((img->pn-DPN)<0)
return (img->pn-DPN+img->buf_cycle);
else
return (img->pn-DPN);
}
/*!
************************************************************************
* \brief
* store reconstructed frame in multiple reference buffer
************************************************************************
*/
void copy2fb(ImageParameters *img)
{
int i,j,uv;
Frame *f;
MMCObuffer_t *tmp_mmco;
/* delete frames with same short term ID */
remove_short_term(img->pn);
/* cycle frame buffer */
f=fb->picbuf_short[fb->short_size-1];
for (i=fb->short_size-2;i>=0;i--)
fb->picbuf_short[i+1]=fb->picbuf_short[i];
fb->picbuf_short[0]=f;
fb->picbuf_short[0]->used=1;
fb->picbuf_short[0]->picID=img->pn;
fb->picbuf_short[0]->lt_picID=-1;
(fb->short_used)++;
if (fb->short_used>fb->short_size)
fb->short_used=fb->short_size;
for (j=0; j < img->height; j++)
for (i=0; i < img->width; i++)
fb->picbuf_short[0]->mref[j][i]=imgY[j][i];
for (uv=0; uv < 2; uv++)
for (i=0; i < img->width_cr; i++)
for (j=0; j < img->height_cr; j++)
fb->picbuf_short[0]->mcef[uv][j][i]=imgUV[uv][j][i];// just copy 1/1 pix, interpolate "online"
// MMCO will be done after storing the decoded frame
while (img->mmco_buffer)
{
tmp_mmco=img->mmco_buffer;
switch (tmp_mmco->MMCO)
{
case 1: // Mark Short-Term Picture as "Unused"
remove_short_term(get_short_ID(tmp_mmco->DPN,img));
break;
case 2: // Mark Long-Term Picture as "Unused"
remove_long_term(tmp_mmco->LPIN);
break;
case 3: // Assign a Long-Term Index to a Picture
assign_long_term_id(get_short_ID(tmp_mmco->DPN,img),tmp_mmco->LPIN,img);
break;
case 4: // Specify the Maximum Long-Term Picture Index
init_long_term_buffer(tmp_mmco->MLIP1-1,img);
break;
case 5: // Reset
reset_buffers();
break;
}
img->mmco_buffer=tmp_mmco->Next;
free (tmp_mmco);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -