📄 cabac.c
字号:
int bframe=(img->type==B_SLICE);
MotionInfoContexts *ctx = (img->currentSlice)->mot_ctx;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
if (bframe)
{
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (currMB->mb_available_up->skip_flag==0 ? 1 : 0);
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (currMB->mb_available_left->skip_flag==0 ? 1 : 0);
act_ctx = 7 + a + b;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][act_ctx]) == 1)
se->value1 = se->value2 = 0;
else
se->value1 = se->value2 = 1;
}
else
{
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (( (currMB->mb_available_up)->skip_flag == 0) ? 1 : 0 );
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (( (currMB->mb_available_left)->skip_flag == 0) ? 1 : 0 );
act_ctx = a + b;
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][act_ctx]) == 1)
se->value1 = 0;
else
se->value1 = 1;
}
#if TRACE
fprintf(p_trace, "@%d %s\t\t%d\t%d %d\n",symbolCount++, se->tracestring, se->value1,a,b);
fflush(p_trace);
#endif
if (!se->value1)
{
last_dquant=0;
}
return;
}
/*!
***************************************************************************
* \brief
* This function is used to arithmetically decode the macroblock
* intra_pred_size flag info of a given MB.
***************************************************************************
*/
void readMB_transform_size_flag_CABAC( SyntaxElement *se,
struct inp_par *inp,
struct img_par *img,
DecodingEnvironmentPtr dep_dp)
{
int a, b;
int act_ctx = 0;
int act_sym;
MotionInfoContexts *ctx = (img->currentSlice)->mot_ctx;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
if (currMB->mb_available_up == NULL)
b = 0;
else
b = currMB->mb_available_up->luma_transform_size_8x8_flag;
if (currMB->mb_available_left == NULL)
a = 0;
else
a = currMB->mb_available_left->luma_transform_size_8x8_flag;
act_ctx = a + b;
act_sym = biari_decode_symbol(dep_dp, ctx->transform_size_contexts + act_ctx );
se->value1 = act_sym;
#if TRACE
fprintf(p_trace, "@%d %s\t\t%d\t%d %d\n",symbolCount++, se->tracestring, se->value1,a,b);
fflush(p_trace);
#endif
}
/*!
************************************************************************
* \brief
* This function is used to arithmetically decode the macroblock
* type info of a given MB.
************************************************************************
*/
void readMB_typeInfo_CABAC( SyntaxElement *se,
struct inp_par *inp,
struct img_par *img,
DecodingEnvironmentPtr dep_dp)
{
int a, b;
int act_ctx;
int act_sym;
int bframe=(img->type==B_SLICE);
int mode_sym;
int ct = 0;
int curr_mb_type;
MotionInfoContexts *ctx = (img->currentSlice)->mot_ctx;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
if(img->type == I_SLICE) // INTRA-frame
{
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (((currMB->mb_available_up)->mb_type != I4MB && currMB->mb_available_up->mb_type != I8MB) ? 1 : 0 );
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (((currMB->mb_available_left)->mb_type != I4MB && currMB->mb_available_left->mb_type != I8MB) ? 1 : 0 );
act_ctx = a + b;
act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx);
se->context = act_ctx; // store context
if (act_sym==0) // 4x4 Intra
{
curr_mb_type = act_sym;
}
else // 16x16 Intra
{
mode_sym = biari_decode_final(dep_dp);
if(mode_sym == 1)
{
curr_mb_type = 25;
}
else
{
act_sym = 1;
act_ctx = 4;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); // decoding of AC/no AC
act_sym += mode_sym*12;
act_ctx = 5;
// decoding of cbp: 0,1,2
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
if (mode_sym!=0)
{
act_ctx=6;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym+=4;
if (mode_sym!=0)
act_sym+=4;
}
// decoding of I pred-mode: 0,1,2,3
act_ctx = 7;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym += mode_sym*2;
act_ctx = 8;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym += mode_sym;
curr_mb_type = act_sym;
}
}
}
else if(img->type == SI_SLICE) // SI-frame
{
// special ctx's for SI4MB
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (( (currMB->mb_available_up)->mb_type != SI4MB) ? 1 : 0 );
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (( (currMB->mb_available_left)->mb_type != SI4MB) ? 1 : 0 );
act_ctx = a + b;
act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx);
se->context = act_ctx; // store context
if (act_sym==0) // SI 4x4 Intra
{
curr_mb_type = 0;
}
else // analog INTRA_IMG
{
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (( (currMB->mb_available_up)->mb_type != I4MB) ? 1 : 0 );
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (( (currMB->mb_available_left)->mb_type != I4MB) ? 1 : 0 );
act_ctx = a + b;
act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx);
se->context = act_ctx; // store context
if (act_sym==0) // 4x4 Intra
{
curr_mb_type = 1;
}
else // 16x16 Intra
{
mode_sym = biari_decode_final(dep_dp);
if( mode_sym==1 )
{
curr_mb_type = 26;
}
else
{
act_sym = 2;
act_ctx = 4;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); // decoding of AC/no AC
act_sym += mode_sym*12;
act_ctx = 5;
// decoding of cbp: 0,1,2
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
if (mode_sym!=0)
{
act_ctx=6;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym+=4;
if (mode_sym!=0)
act_sym+=4;
}
// decoding of I pred-mode: 0,1,2,3
act_ctx = 7;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym += mode_sym*2;
act_ctx = 8;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx );
act_sym += mode_sym;
curr_mb_type = act_sym;
}
}
}
}
else
{
if (bframe)
{
ct = 1;
if (currMB->mb_available_up == NULL)
b = 0;
else
b = (( (currMB->mb_available_up)->mb_type != 0) ? 1 : 0 );
if (currMB->mb_available_left == NULL)
a = 0;
else
a = (( (currMB->mb_available_left)->mb_type != 0) ? 1 : 0 );
act_ctx = a + b;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][act_ctx]))
{
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][4]))
{
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][5]))
{
act_sym=12;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=8;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=4;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=2;
if (act_sym==24) act_sym=11;
else if (act_sym==26) act_sym=22;
else
{
if (act_sym==22) act_sym=23;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=1;
}
}
else
{
act_sym=3;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=4;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=2;
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym+=1;
}
}
else
{
if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][6])) act_sym=2;
else act_sym=1;
}
}
else
{
act_sym = 0;
}
}
else // P-frame
{
{
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][4] ))
{
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][7] )) act_sym = 7;
else act_sym = 6;
}
else
{
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][5] ))
{
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][7] )) act_sym = 2;
else act_sym = 3;
}
else
{
if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][6] )) act_sym = 4;
else act_sym = 1;
}
}
}
}
if (act_sym<=6 || (((img->type == B_SLICE)?1:0) && act_sym<=23))
{
curr_mb_type = act_sym;
}
else // additional info for 16x16 Intra-mode
{
mode_sym = biari_decode_final(dep_dp);
if( mode_sym==1 )
{
if(bframe) // B frame
curr_mb_type = 48;
else // P frame
curr_mb_type = 31;
}
else
{
act_ctx = 8;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx ); // decoding of AC/no AC
act_sym += mode_sym*12;
// decoding of cbp: 0,1,2
act_ctx = 9;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx );
if (mode_sym != 0)
{
act_sym+=4;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx );
if (mode_sym != 0)
act_sym+=4;
}
// decoding of I pred-mode: 0,1,2,3
act_ctx = 10;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx );
act_sym += mode_sym*2;
mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx );
act_sym += mode_sym;
curr_mb_type = act_sym;
}
}
}
se->value1 = curr_mb_type;
// if (curr_mb_type >= 23) printf(" stopx");
#if TRACE
fprintf(p_trace, "@%d %s\t\t\t%d\n",symbolCount++, se->tracestring, se->value1);
fflush(p_trace);
#endif
}
/*!
************************************************************************
* \brief
* This function is used to arithmetically decode a pair of
* intra prediction modes of a given MB.
************************************************************************
*/
void readIntraPredMode_CABAC( SyntaxElement *se,
struct inp_par *inp,
struct img_par *img,
DecodingEnvironmentPtr dep_dp)
{
TextureInfoContexts *ctx = img->currentSlice->tex_ctx;
int act_sym;
// use_most_probable_mode
act_sym = biari_decode_symbol(dep_dp, ctx->ipr_contexts);
// remaining_mode_selector
if (act_sym == 1)
se->value1 = -1;
else
{
se->value1 = 0;
se->value1 |= (biari_decode_symbol(dep_dp, ctx->ipr_contexts+1) );
se->value1 |= (biari_decode_symbol(dep_dp, ctx->ipr_contexts+1) << 1);
se->value1 |= (biari_decode_symbol(dep_dp, ctx->ipr_contexts+1) << 2);
}
#if TRACE
fprintf(p_trace, "@%d %s\t\t\t%d\n",symbolCount++, se->tracestring, se->value1);
fflush(p_trace);
#endif
}
/*!
************************************************************************
* \brief
* This function is used to arithmetically decode the reference
* parameter of a given MB.
************************************************************************
*/
void readRefFrame_CABAC( SyntaxElement *se,
struct inp_par *inp,
struct img_par *img,
DecodingEnvironmentPtr dep_dp)
{
MotionInfoContexts *ctx = img->currentSlice->mot_ctx;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int addctx = 0;
int a, b;
int act_ctx;
int act_sym;
char** refframe_array = dec_picture->ref_idx[se->value2];
int b8a, b8b;
PixelPos block_a, block_b;
getLuma4x4Neighbour(img->current_mb_nr, img->subblock_x, img->subblock_y, -1, 0, &block_a);
getLuma4x4Neighbour(img->current_mb_nr, img->subblock_x, img->subblock_y, 0, -1, &block_b);
b8a=((block_a.x/2)%2)+2*((block_a.y/2)%2);
b8b=((block_b.x/2)%2)+2*((block_b.y/2)%2);
if (!block_b.available)
b=0;
else if ( (img->mb_data[block_b.mb_addr].mb_type==IPCM) || IS_DIRECT(&img->mb_data[block_b.mb_addr]) || (img->mb_data[block_b.mb_addr].b8mode[b8b]==0 && img->mb_data[block_b.mb_addr].b8pdir[b8b]==2))
b=0;
else
{
if (img->MbaffFrameFlag && (currMB->mb_field == 0) && (img->mb_data[block_b.mb_addr].mb_field == 1))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -