📄 decoder.c
字号:
if (dx == 1) {
result = (result + max(0, min(255, (tmp_res[2]+16)/32)))/2;
}
else {
result = (result + max(0, min(255, (tmp_res[3]+16)/32)))/2;
}
}
else {
result = 0;
pres_y = dy == 1 ? y_pos : y_pos+1;
pres_y = max(0,min(maxold_y,pres_y));
for(x=-2;x<4;x++) {
pres_x = max(0,min(maxold_x,x_pos+x));
result += imY[pres_y][pres_x]*COEF[x+2];
}
result1 = max(0, min(255, (result+16)/32));
result = 0;
pres_x = dx == 1 ? x_pos : x_pos+1;
pres_x = max(0,min(maxold_x,pres_x));
for(y=-2;y<4;y++) {
pres_y = max(0,min(maxold_y,y_pos+y));
result += imY[pres_y][pres_x]*COEF[y+2];
}
result2 = max(0, min(255, (result+16)/32));
result = (result1+result2)/2;
}
}
return result;
}
/*!
*************************************************************************************
* \brief
* Performs the simulation of the packet losses, calls the error concealment funcs
* and copies the decoded images to the reference frame buffers of the decoders
*
*************************************************************************************
*/
void UpdateDecoders()
{
int k;
for (k=0; k<input->NoOfDecoders; k++)
{
Build_Status_Map(status_map); // simulates the packet losses
Error_Concealment(decY_best[k], status_map, decref[k]); // for the moment error concealment is just a "copy"
// Move decoded frames to reference buffers: (at the decoders this is done
// without interpolation (upsampling) - upsampling is done while decoding
DecOneForthPix(decY_best[k], decref[k]);
}
}
/*!
*************************************************************************************
* \brief
* Copies one (reconstructed) image to the respective reference frame buffer
*
* \note
* This is used at the "many decoders in the encoder"
* \param dY
* The reconstructed image
* \param dref
* The reference buffer
*************************************************************************************
*/
void DecOneForthPix(byte **dY, byte ***dref)
{
int j, ref=img->number%img->buf_cycle;
for (j=0; j<img->height; j++)
memcpy(dref[ref][j], dY[j], img->width);
}
/*!
*************************************************************************************
* \brief
* Gives the prediction residue for this MB.
*
* \param mode
* The encoding mode of this MB.
*************************************************************************************
*/
void compute_residue(int mode)
{
int i,j;
if (mode == MBMODE_INTRA16x16) /* Intra 16 MB*/
for (i=0; i<MB_BLOCK_SIZE; i++)
for (j=0; j<MB_BLOCK_SIZE; j++)
resY[j][i] = imgY[img->pix_y+j][img->pix_x+i]-img->mprr_2[mode][j][i]; /* SOS: Is this correct? or maybe mprr_2[][i][j] ??*/
else
for (i=0; i<MB_BLOCK_SIZE; i++) /* Inter MB */
for (j=0; j<MB_BLOCK_SIZE; j++)
resY[j][i] = imgY[img->pix_y+j][img->pix_x+i]-img->mpr[i][j];
}
/*!
*************************************************************************************
* \brief
* Builds a random status map showing whether each MB is received or lost, based
* on the packet loss rate and the slice structure.
*
* \param s_map
* The status map to be filled
*************************************************************************************
*/
void Build_Status_Map(byte **s_map)
{
int i,j,slice=-1,mb=0,jj,ii,packet_lost=0;
static int packet = 0;
static int fehler = 0;
jj = img->height/MB_BLOCK_SIZE;
ii = img->width/MB_BLOCK_SIZE;
for (j=0 ; j<jj; j++)
for (i=0 ; i<ii; i++)
{
if (!input->slice_mode || img->mb_data[mb].slice_nr != slice) /* new slice */
{
packet_lost=0;
if ((double)rand()/(double)RAND_MAX*100 < input->LossRateC)
packet_lost += 3;
if ((double)rand()/(double)RAND_MAX*100 < input->LossRateB)
packet_lost += 2;
if ((double)rand()/(double)RAND_MAX*100 < input->LossRateA)
packet_lost=1;
slice++;
}
if (!packet_lost)
s_map[j][i]=0; //! Packet OK
else
{
s_map[j][i]=packet_lost;
if(input->partition_mode == 0)
s_map[j][i]=1;
}
mb++;
}
}
/*!
*************************************************************************************
* \brief
* Performs some sort of error concealment for the areas that are lost according
* to the status_map
*
* \param inY
* Error concealment is performed on this frame imY[][]
* \param s_map
* The status map shows which areas are lost.
* \param refY
* The set of reference frames - may be used for the error concealment.
*************************************************************************************
*/
void Error_Concealment(byte **inY, byte **s_map, byte ***refY)
{
int mb_y, mb_x, mb_h, mb_w;
mb_h = img->height/MB_BLOCK_SIZE;
mb_w = img->width/MB_BLOCK_SIZE;
for (mb_y=0; mb_y < mb_h; mb_y++)
for (mb_x=0; mb_x < mb_w; mb_x++)
if (s_map[mb_y][mb_x])
Conceal_Error(inY, mb_y, mb_x, refY, s_map);
}
/*!
*************************************************************************************
* \brief
* Copies a certain MB (mb_y,mb_x) of the frame inY[][] from the previous frame.
* For the time there is no better EC...
*************************************************************************************
*/
void Conceal_Error(byte **inY, int mb_y, int mb_x, byte ***refY, byte **s_map)
{
int i,j,block_x, block_y;
int ref_inx = (img->number-1)%img->no_multpred;
int pos_y = mb_y*MB_BLOCK_SIZE, pos_x = mb_x*MB_BLOCK_SIZE;
int mv[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE];
int resY[MB_BLOCK_SIZE][MB_BLOCK_SIZE];
int inter = (dec_mb_mode[mb_x][mb_y] >= MBMODE_INTER16x16 && dec_mb_mode[mb_x][mb_y] <= MBMODE_INTER4x4 && img->type!=B_IMG);
switch(s_map[mb_y][mb_x])
{
case 1: //! whole slice lost (at least partition A lost)
if (img->number)
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = refY[ref_inx][pos_y+j][pos_x+i];
}
else
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = 127;
}
break;
case 5: //! partition B and partition C lost
//! Copy motion vectors
for (block_y=0; block_y<BLOCK_MULTIPLE; block_y++)
for (block_x=0; block_x<BLOCK_MULTIPLE; block_x++)
for (i=0;i<2;i++)
mv[i][block_y][block_x]=tmp_mv[i][mb_y*BLOCK_SIZE+block_y][mb_x*BLOCK_SIZE+block_x+4];
//! Residuum ist set to zero
for(i=0;i<MB_BLOCK_SIZE;i++)
for(j=0;j<MB_BLOCK_SIZE;j++)
resY[j][i]=0;
//! not first frame
if (img->number)
{
//! if copy mb
if (dec_mb_mode[mb_x][mb_y]==MBMODE_COPY)
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = refY[ref_inx][pos_y+j][pos_x+i];
}
//! if inter mb
else if (inter)
{
for (block_y = mb_y*BLOCK_SIZE ; block_y < (mb_y*BLOCK_SIZE + BLOCK_MULTIPLE) ; block_y++)
for (block_x = mb_x*BLOCK_SIZE ; block_x < (mb_x*BLOCK_SIZE + BLOCK_MULTIPLE) ; block_x++)
{
Get_Reference_Block(refY[ref_inx],
block_y, block_x,
mv[0][block_y - mb_y*BLOCK_SIZE][block_x - mb_x*BLOCK_SIZE],
mv[1][block_y - mb_y*BLOCK_SIZE][block_x - mb_x*BLOCK_SIZE],
RefBlock);
for (j=0;j<BLOCK_SIZE;j++)
for (i=0;i<BLOCK_SIZE;i++)
{
inY[block_y*BLOCK_SIZE + j][block_x*BLOCK_SIZE + i] = RefBlock[j][i];
}
}
}
else //intra; up to now only copy mb, may integrate nokia EC
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = refY[ref_inx][pos_y+j][pos_x+i];
}
}
else //! first frame; up to now set value to grey, may integrate nokia EC
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = 127;
}
break;
case 3: //! Partition C lost
if(img->number)
{
//! Copy motion vectors
for (block_y=0; block_y<BLOCK_MULTIPLE; block_y++)
for (block_x=0; block_x<BLOCK_MULTIPLE; block_x++)
for (i=0;i<2;i++)
mv[i][block_y][block_x]=tmp_mv[i][mb_y*BLOCK_SIZE+block_y][mb_x*BLOCK_SIZE+block_x+4];
//! Residuum ist set to zero
for(i=0;i<MB_BLOCK_SIZE;i++)
for(j=0;j<MB_BLOCK_SIZE;j++)
resY[j][i]=0;
//! if copy mb
if (dec_mb_mode[mb_x][mb_y]==MBMODE_COPY)
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = refY[ref_inx][pos_y+j][pos_x+i];
}
//! if inter mb
else if (inter)
{
for (block_y = mb_y*BLOCK_SIZE ; block_y < (mb_y*BLOCK_SIZE + BLOCK_MULTIPLE) ; block_y++)
for (block_x = mb_x*BLOCK_SIZE ; block_x < (mb_x*BLOCK_SIZE + BLOCK_MULTIPLE) ; block_x++)
{
Get_Reference_Block(refY[ref_inx],
block_y, block_x,
mv[0][block_y - mb_y*BLOCK_SIZE][block_x - mb_x*BLOCK_SIZE],
mv[1][block_y - mb_y*BLOCK_SIZE][block_x - mb_x*BLOCK_SIZE],
RefBlock);
for (j=0;j<BLOCK_SIZE;j++)
for (i=0;i<BLOCK_SIZE;i++)
{
inY[block_y*BLOCK_SIZE + j][block_x*BLOCK_SIZE + i] = RefBlock[j][i];
}
}
}
}
break;
case 2: //! Partition B lost
if(img->number)
{
if(!inter)
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = refY[ref_inx][pos_y+j][pos_x+i];
}
}
else //! first frame; up to now set value to grey, may integrate nokia EC
{
for (j=0;j<MB_BLOCK_SIZE;j++)
for (i=0;i<MB_BLOCK_SIZE;i++)
inY[pos_y+j][pos_x+i] = 127;
}
break;
} //! End Switch
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -