📄 t264enc.c
字号:
}
T264_cabac_mb_mvd( t, 0, 0, 4, 2 );
T264_cabac_mb_mvd( t, 0, 8, 4, 2 );
}
else if( t->mb.mb_part == MB_8x16 )
{
if( t->ps.num_ref_idx_l0_active_minus1 > 0 )
{
T264_cabac_mb_ref( t, 0, 0 );
T264_cabac_mb_ref( t, 0, 4 );
}
T264_cabac_mb_mvd( t, 0, 0, 2, 4 );
T264_cabac_mb_mvd( t, 0, 4, 2, 4 );
}
else /* 8x8 */
{
/* sub mb type */
T264_cabac_mb_sub_p_partition( t, t->mb.submb_part[0] );
T264_cabac_mb_sub_p_partition( t, t->mb.submb_part[2] );
T264_cabac_mb_sub_p_partition( t, t->mb.submb_part[8] );
T264_cabac_mb_sub_p_partition( t, t->mb.submb_part[10] );
/* ref 0 */
if( t->ps.num_ref_idx_l0_active_minus1 > 0 )
{
T264_cabac_mb_ref( t, 0, 0 );
T264_cabac_mb_ref( t, 0, 4 );
T264_cabac_mb_ref( t, 0, 8 );
T264_cabac_mb_ref( t, 0, 12 );
}
for( i = 0; i < 4; i++ )
{
switch( t->mb.submb_part[luma_index[i<<2]] )
{
case MB_8x8:
T264_cabac_mb_mvd( t, 0, 4*i, 2, 2 );
break;
case MB_8x4:
T264_cabac_mb_mvd( t, 0, 4*i+0, 2, 1 );
T264_cabac_mb_mvd( t, 0, 4*i+2, 2, 1 );
break;
case MB_4x8:
T264_cabac_mb_mvd( t, 0, 4*i+0, 1, 2 );
T264_cabac_mb_mvd( t, 0, 4*i+1, 1, 2 );
break;
case MB_4x4:
T264_cabac_mb_mvd( t, 0, 4*i+0, 1, 1 );
T264_cabac_mb_mvd( t, 0, 4*i+1, 1, 1 );
T264_cabac_mb_mvd( t, 0, 4*i+2, 1, 1 );
T264_cabac_mb_mvd( t, 0, 4*i+3, 1, 1 );
break;
}
}
}
}
else if( i_mb_type == B_MODE )
{
if((t->mb.mb_part==MB_16x16&&t->mb.is_copy!=1) || (t->mb.mb_part==MB_16x8) || (t->mb.mb_part==MB_8x16))
{
/* to be changed here*/
/* All B mode */
int i_list;
int b_list[2][2];
const int i_partition = t->mb.mb_part;
int b_part_mode, part_mode0, part_mode1;
static const int b_part_mode_map[3][3] = {
{ B_L0_L0, B_L0_L1, B_L0_BI },
{ B_L1_L0, B_L1_L1, B_L1_BI },
{ B_BI_L0, B_BI_L1, B_BI_BI }
};
switch(t->mb.mb_part)
{
case MB_16x16:
part_mode0 = t->mb.mb_part2[0] - B_L0_16x16;
b_part_mode = b_part_mode_map[part_mode0][part_mode0];
break;
case MB_16x8:
part_mode0 = t->mb.mb_part2[0] - B_L0_16x8;
part_mode1 = t->mb.mb_part2[1] - B_L0_16x8;
b_part_mode = b_part_mode_map[part_mode0][part_mode1];
break;
case MB_8x16:
part_mode0 = t->mb.mb_part2[0] - B_L0_8x16;
part_mode1 = t->mb.mb_part2[1] - B_L0_8x16;
b_part_mode = b_part_mode_map[part_mode0][part_mode1];
break;
}
/* init ref list utilisations */
for( i = 0; i < 2; i++ )
{
b_list[0][i] = T264_mb_type_list0_table[b_part_mode][i];
b_list[1][i] = T264_mb_type_list1_table[b_part_mode][i];
}
for( i_list = 0; i_list < 2; i_list++ )
{
const int i_ref_max = i_list == 0 ? t->ps.num_ref_idx_l0_active_minus1+1 : t->ps.num_ref_idx_l1_active_minus1+1;
if( i_ref_max > 1 )
{
if( t->mb.mb_part == MB_16x16 )
{
if( b_list[i_list][0] ) T264_cabac_mb_ref( t, i_list, 0 );
}
else if( t->mb.mb_part == MB_16x8 )
{
if( b_list[i_list][0] ) T264_cabac_mb_ref( t, i_list, 0 );
if( b_list[i_list][1] ) T264_cabac_mb_ref( t, i_list, 8 );
}
else if( t->mb.mb_part == MB_8x16 )
{
if( b_list[i_list][0] ) T264_cabac_mb_ref( t, i_list, 0 );
if( b_list[i_list][1] ) T264_cabac_mb_ref( t, i_list, 4 );
}
}
}
for( i_list = 0; i_list < 2; i_list++ )
{
if( t->mb.mb_part == MB_16x16 )
{
if( b_list[i_list][0] ) T264_cabac_mb_mvd( t, i_list, 0, 4, 4 );
}
else if( t->mb.mb_part == MB_16x8 )
{
if( b_list[i_list][0] ) T264_cabac_mb_mvd( t, i_list, 0, 4, 2 );
if( b_list[i_list][1] ) T264_cabac_mb_mvd( t, i_list, 8, 4, 2 );
}
else if( t->mb.mb_part == MB_8x16 )
{
if( b_list[i_list][0] ) T264_cabac_mb_mvd( t, i_list, 0, 2, 4 );
if( b_list[i_list][1] ) T264_cabac_mb_mvd( t, i_list, 4, 2, 4 );
}
}
}
else if(t->mb.mb_part==MB_16x16 && t->mb.is_copy)
{
}
else /* B8x8 */
{
/* TODO */
int i_list;
/* sub mb type */
T264_cabac_mb_sub_b_partition( t, t->mb.submb_part[0] );
T264_cabac_mb_sub_b_partition( t, t->mb.submb_part[2] );
T264_cabac_mb_sub_b_partition( t, t->mb.submb_part[8] );
T264_cabac_mb_sub_b_partition( t, t->mb.submb_part[10] );
/* ref */
for( i_list = 0; i_list < 2; i_list++ )
{
if( ( i_list ? t->ps.num_ref_idx_l1_active_minus1 : t->ps.num_ref_idx_l0_active_minus1 ) == 0 )
continue;
for( i = 0; i < 4; i++ )
{
int sub_part = t->mb.submb_part[luma_index[i<<2]]-B_DIRECT_8x8;
if( T264_mb_partition_listX_table[sub_part][i_list] == 1 )
{
T264_cabac_mb_ref( t, i_list, 4*i );
}
}
}
T264_cabac_mb8x8_mvd( t, 0 );
T264_cabac_mb8x8_mvd( t, 1 );
}
}
i_mb_pos_tex = BitstreamPos( s );
if( i_mb_type != I_16x16 )
{
T264_cabac_mb_cbp_luma( t );
T264_cabac_mb_cbp_chroma( t );
}
if( t->mb.cbp_y > 0 || t->mb.cbp_c > 0 || i_mb_type == I_16x16 )
{
T264_cabac_mb_qp_delta( t );
/* write residual */
if( i_mb_type == I_16x16 )
{
/* DC Luma */
block_residual_write_cabac( t, 0, 0, t->mb.dc4x4_z, 16 );
if( t->mb.cbp_y != 0 )
{
/* AC Luma */
for( i = 0; i < 16; i++ )
{
block_residual_write_cabac( t, 1, i, &(t->mb.dct_y_z[i][1]), 15 );
}
}
}
else
{
if(t->frame_num == 1)
t->frame_num = 1;
for( i = 0; i < 16; i++ )
{
if( t->mb.cbp_y & ( 1 << ( i / 4 ) ) )
{
block_residual_write_cabac( t, 2, i, &(t->mb.dct_y_z[i][0]), 16 );
}
}
}
if( t->mb.cbp_c&0x03 ) /* Chroma DC residual present */
{
block_residual_write_cabac( t, 3, 0, &(t->mb.dc2x2_z[0][0]), 4 );
block_residual_write_cabac( t, 3, 1, &(t->mb.dc2x2_z[1][0]), 4 );
}
if( t->mb.cbp_c&0x02 ) /* Chroma AC residual present */
{
for( i = 0; i < 8; i++ )
{
block_residual_write_cabac( t, 4, i, &(t->mb.dct_uv_z[i>>2][i&0x03][1]), 15);
}
}
}
/*
if( IS_INTRA( i_mb_type ) )
t->stat.frame.i_itex_bits += bs_pos(s) - i_mb_pos_tex;
else
t->stat.frame.i_ptex_bits += bs_pos(s) - i_mb_pos_tex;
*/
}
/*****************************************************************************
*
* T264 AVC CODEC
*
* Copyright(C) 2004-2005 llcc <lcgate1@yahoo.com.cn>
* 2004-2005 visionany <visionany@yahoo.com.cn>
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************/
#include "config.h"
#include "stdio.h"
#ifndef CHIP_DM642
#include "memory.h"
#endif
#include "T264.h"
#include "utility.h"
#include "intra.h"
#include "cavlc.h"
#include "inter.h"
#include "inter_b.h"
#include "interpolate.h"
#include "estimation.h"
#include "deblock.h"
#include "ratecontrol.h"
#include "stat.h"
#ifndef CHIP_DM642
#include "sse2.h"
#endif
#include "math.h"
#include "dct.h"
#include "predict.h"
#include "bitstream.h"
#include "rbsp.h"
#include "assert.h"
#include "typedecision.h"
//for CABAC
#include "cabac_engine.h"
//#include "cabac.h"
const int32_t chroma_qp[] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29,
29, 30, 31, 32, 32, 33, 34, 34, 35, 35,
36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 39
};
//! convert from H.263 QP to H.26L quant given by: quant=pow(2,QP/6)
static const int32_t qp_cost[52]=
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 4, 4, 4, 5, 6,
6, 7, 8, 9,10,11,13,14,
16,18,20,23,25,29,32,36,
40,45,51,57,64,72,81,91
};
void
T264_mb_load_context(T264_t* t, int32_t mb_y, int32_t mb_x)
{
int32_t qpc;
int32_t i, j;
t->mb.mb_x = mb_x;
t->mb.mb_y = mb_y;
t->mb.mb_xy = t->mb.mb_y * t->mb_stride + t->mb.mb_x;
t->mb.mb_neighbour = 0;
if (mb_x != 0)
t->mb.mb_neighbour |= MB_LEFT;
if (mb_y != 0)
{
t->mb.mb_neighbour |= MB_TOP;
//if (mb_x != t->mb_stride - 1) //just tell MB is not the top-most
t->mb.mb_neighbour |= MB_TOPRIGHT;
}
t->mb.src_y = t->cur.Y[0] + (mb_y << 4) * t->stride + (mb_x << 4);
t->mb.dst_y = t->rec->Y[0] + (mb_y << 4) * t->edged_stride + (mb_x << 4);
t->mb.src_u = t->cur.U + (mb_y << 3) * t->stride_uv + (mb_x << 3);
t->mb.dst_u = t->rec->U + (mb_y << 3) * t->edged_stride_uv + (mb_x << 3);
t->mb.src_v = t->cur.V + (mb_y << 3) * t->stride_uv + (mb_x << 3);
t->mb.dst_v = t->rec->V + (mb_y << 3) * t->edged_stride_uv + (mb_x << 3);
t->mb.mb_qp_delta = 0;
/* t->ps.chroma_qp_index_offset maybe modify in ratecontrol */
qpc = clip3(t->ps.chroma_qp_index_offset + t->qp_y, 0, 51);
t->qp_uv = chroma_qp[qpc];
t->mb.lambda = qp_cost[t->qp_y];
t->mb.context = &t->rec->mb[t->mb.mb_xy];
/*for CABAC, init the mvd_ref */
memset(&(t->mb.mvd_ref[0][0][0]), 0, sizeof(t->mb.mvd_ref));
#define INITINVALIDVEC(vec) vec.refno = -2; vec.x = vec.y = 0;
INITINVALIDVEC(t->mb.vec_ref[0].vec[0]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4].vec[0]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 8].vec[0]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 16].vec[0]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 24].vec[0]);
INITINVALIDVEC(t->mb.vec_ref[0].vec[1]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4].vec[1]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 8].vec[1]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 16].vec[1]);
INITINVALIDVEC(t->mb.vec_ref[IPM_LUMA - 8 + 4 + 24].vec[1]);
t->mb.vec_ref[0].part = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4].part = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 8].part = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 16].part = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 24].part = -1;
t->mb.vec_ref[0].subpart = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4].subpart = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 8].subpart = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 16].subpart = -1;
t->mb.vec_ref[IPM_LUMA - 8 + 4 + 24].subpart = -1;
memset(t->mb.submb_part, -1, sizeof(uint8_t) * 16);//t->mb.submb_part));
t->mb.mb_part = -1;
for(i = 0 ; i < 2 ; i ++)
{
for(j = 0 ; j < 16 ; j ++)
{
INITINVALIDVEC(t->mb.vec[i][j]);
}
}
t->mb.sad_ref[0] = t->mb.sad_ref[1] = t->mb.sad_ref[2] = 0;
//intra_4x4 prediction modes and non-zero counts
if( mb_y > 0 )
{
int16_t top_xy = t->mb.mb_xy - t->mb_stride;
/* intra 4x4 pred mode layout
? x x x x
x
x
x
x
*/
t->mb.i4x4_pred_mode_ref[IPM_LUMA - 8 + 0] = t->rec->mb[top_xy].mode_i4x4[10];
t->mb.i4x4_pred_mode_ref[IPM_LUMA - 8 + 1] = t->rec->mb[top_xy].mode_i4x4[11];
t->mb.i4x4_pred_mode_ref[IPM_LUMA - 8 + 2] = t->rec->mb[top_xy].mode_i4x4[14];
t->mb.i4x4_pred_mode_ref[IPM_LUMA - 8 + 3] = t->rec->mb[top_xy].mode_i4x4[15];
t->mb.vec_ref[IPM_LUMA - 8 + 0].vec[0] = t->rec->mb[top_xy].vec[0][12];
t->mb.vec_ref[IPM_LUMA - 8 + 1].vec[0] = t->rec->mb[top_xy].vec[0][13];
t->mb.vec_ref[IPM_LUMA - 8 + 2].vec[0] = t->rec->mb[top_xy].vec[0][14];
t->mb.vec_ref[IPM_LUMA - 8 + 3].vec[0] = t->rec->mb[top_xy].vec[0][15];
t->mb.vec_ref[IPM_LUMA - 8 + 0].vec[1] = t->rec->mb[top_xy].vec[1][12];
t->mb.vec_ref[IPM_LUMA - 8 + 1].vec[1] = t->rec->mb[top_xy].vec[1][13];
t->mb.vec_ref[IPM_LUMA - 8 + 2].vec[1] = t->rec->mb[top_xy].vec[1][14];
t->mb.vec_ref[IPM_LUMA - 8 + 3].vec[1] = t->rec->mb[top_xy].vec[1][15];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -