📄 cavlc.c.svn-base
字号:
switch( h->sh.i_type ) { case SLICE_TYPE_I: i_mb_i_offset = 0; break; case SLICE_TYPE_P: i_mb_i_offset = 5; break; case SLICE_TYPE_B: i_mb_i_offset = 23; break; default: x264_log(h, X264_LOG_ERROR, "internal error or slice unsupported\n" ); return; } /* Write: - type - prediction - mv */ if( i_mb_type == I_PCM ) { /* Untested */ bs_write_ue( s, i_mb_i_offset + 25 ); bs_align_0( s ); /* Luma */ for( i = 0; i < 16*16; i++ ) { const int x = 16 * h->mb.i_mb_x + (i % 16); const int y = 16 * h->mb.i_mb_y + (i / 16); bs_write( s, 8, h->fenc->plane[0][y*h->mb.pic.i_stride[0]+x] ); } /* Cb */ for( i = 0; i < 8*8; i++ ) { const int x = 8 * h->mb.i_mb_x + (i % 8); const int y = 8 * h->mb.i_mb_y + (i / 8); bs_write( s, 8, h->fenc->plane[1][y*h->mb.pic.i_stride[1]+x] ); } /* Cr */ for( i = 0; i < 8*8; i++ ) { const int x = 8 * h->mb.i_mb_x + (i % 8); const int y = 8 * h->mb.i_mb_y + (i / 8); bs_write( s, 8, h->fenc->plane[2][y*h->mb.pic.i_stride[2]+x] ); } return; } else if( i_mb_type == I_4x4 ) { bs_write_ue( s, i_mb_i_offset + 0 ); /* Prediction: Luma */ for( i = 0; i < 16; i++ ) { int i_pred = x264_mb_predict_intra4x4_mode( h, i ); int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]]; if( i_pred == i_mode) { bs_write1( s, 1 ); /* b_prev_intra4x4_pred_mode */ } else { bs_write1( s, 0 ); /* b_prev_intra4x4_pred_mode */ if( i_mode < i_pred ) { bs_write( s, 3, i_mode ); } else { bs_write( s, 3, i_mode - 1 ); } } } bs_write_ue( s, h->mb.i_chroma_pred_mode ); } else if( i_mb_type == I_16x16 ) { bs_write_ue( s, i_mb_i_offset + 1 + h->mb.i_intra16x16_pred_mode + h->mb.i_cbp_chroma * 4 + ( h->mb.i_cbp_luma == 0 ? 0 : 12 ) ); bs_write_ue( s, h->mb.i_chroma_pred_mode ); } else if( i_mb_type == P_L0 ) { int mvp[2]; if( h->mb.i_partition == D_16x16 ) { bs_write_ue( s, 0 ); if( h->sh.i_num_ref_idx_l0_active > 1 ) { bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] ); } x264_mb_predict_mv( h, 0, 0, 4, mvp ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][1] - mvp[1] ); } else if( h->mb.i_partition == D_16x8 ) { bs_write_ue( s, 1 ); if( h->sh.i_num_ref_idx_l0_active > 1 ) { bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] ); bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[8]] ); } x264_mb_predict_mv( h, 0, 0, 4, mvp ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][1] - mvp[1] ); x264_mb_predict_mv( h, 0, 8, 4, mvp ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[8]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[8]][1] - mvp[1] ); } else if( h->mb.i_partition == D_8x16 ) { bs_write_ue( s, 2 ); if( h->sh.i_num_ref_idx_l0_active > 1 ) { bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] ); bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4]] ); } x264_mb_predict_mv( h, 0, 0, 2, mvp ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][1] - mvp[1] ); x264_mb_predict_mv( h, 0, 4, 2, mvp ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[4]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[0][x264_scan8[4]][1] - mvp[1] ); } } else if( i_mb_type == P_8x8 ) { int b_sub_ref0; if( h->mb.cache.ref[0][x264_scan8[0]] == 0 && h->mb.cache.ref[0][x264_scan8[4]] == 0 && h->mb.cache.ref[0][x264_scan8[8]] == 0 && h->mb.cache.ref[0][x264_scan8[12]] == 0 ) { bs_write_ue( s, 4 ); b_sub_ref0 = 0; } else { bs_write_ue( s, 3 ); b_sub_ref0 = 1; } /* sub mb type */ for( i = 0; i < 4; i++ ) { bs_write_ue( s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i] ] ); } /* ref0 */ if( h->sh.i_num_ref_idx_l0_active > 1 && b_sub_ref0 ) { bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] ); bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4]] ); bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[8]] ); bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[12]] ); } x264_sub_mb_mv_write_cavlc( h, s, 0 ); } else if( i_mb_type == B_8x8 ) { bs_write_ue( s, 22 ); /* sub mb type */ for( i = 0; i < 4; i++ ) { bs_write_ue( s, sub_mb_type_b_to_golomb[ h->mb.i_sub_partition[i] ] ); } /* ref */ for( i = 0; i < 4; i++ ) { if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] ) { bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[i*4]] ); } } for( i = 0; i < 4; i++ ) { if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] ) { bs_write_te( s, h->sh.i_num_ref_idx_l1_active - 1, h->mb.cache.ref[1][x264_scan8[i*4]] ); } } /* mvd */ x264_sub_mb_mv_write_cavlc( h, s, 0 ); x264_sub_mb_mv_write_cavlc( h, s, 1 ); } else if( i_mb_type != B_DIRECT ) { /* All B mode */ /* Motion Vector */ int i_list; int mvp[2]; int b_list[2][2]; /* init ref list utilisations */ for( i = 0; i < 2; i++ ) { b_list[0][i] = x264_mb_type_list0_table[i_mb_type][i]; b_list[1][i] = x264_mb_type_list1_table[i_mb_type][i]; } bs_write_ue( s, mb_type_b_to_golomb[ h->mb.i_partition - D_16x8 ][ i_mb_type - B_L0_L0 ] ); for( i_list = 0; i_list < 2; i_list++ ) { const int i_ref_max = i_list == 0 ? h->sh.i_num_ref_idx_l0_active : h->sh.i_num_ref_idx_l1_active; if( i_ref_max > 1 ) { switch( h->mb.i_partition ) { case D_16x16: if( b_list[i_list][0] ) bs_write_te( s, i_ref_max - 1, h->mb.cache.ref[i_list][x264_scan8[0]] ); break; case D_16x8: if( b_list[i_list][0] ) bs_write_te( s, i_ref_max - 1, h->mb.cache.ref[i_list][x264_scan8[0]] ); if( b_list[i_list][1] ) bs_write_te( s, i_ref_max - 1, h->mb.cache.ref[i_list][x264_scan8[8]] ); break; case D_8x16: if( b_list[i_list][0] ) bs_write_te( s, i_ref_max - 1, h->mb.cache.ref[i_list][x264_scan8[0]] ); if( b_list[i_list][1] ) bs_write_te( s, i_ref_max - 1, h->mb.cache.ref[i_list][x264_scan8[4]] ); break; } } } for( i_list = 0; i_list < 2; i_list++ ) { switch( h->mb.i_partition ) { case D_16x16: if( b_list[i_list][0] ) { x264_mb_predict_mv( h, i_list, 0, 4, mvp ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][1] - mvp[1] ); } break; case D_16x8: if( b_list[i_list][0] ) { x264_mb_predict_mv( h, i_list, 0, 4, mvp ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][1] - mvp[1] ); } if( b_list[i_list][1] ) { x264_mb_predict_mv( h, i_list, 8, 4, mvp ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[8]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[8]][1] - mvp[1] ); } break; case D_8x16: if( b_list[i_list][0] ) { x264_mb_predict_mv( h, i_list, 0, 2, mvp ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[0]][1] - mvp[1] ); } if( b_list[i_list][1] ) { x264_mb_predict_mv( h, i_list, 4, 2, mvp ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[4]][0] - mvp[0] ); bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[4]][1] - mvp[1] ); } break; } } } else if( i_mb_type == B_DIRECT ) { bs_write_ue( s, 0 ); } else { x264_log(h, X264_LOG_ERROR, "invalid/unhandled mb_type\n" ); return; } i_mb_pos_tex = bs_pos( s ); h->stat.frame.i_hdr_bits += i_mb_pos_tex - i_mb_pos_start; /* Coded block patern */ if( i_mb_type == I_4x4 ) { bs_write_ue( s, intra4x4_cbp_to_golomb[( h->mb.i_cbp_chroma << 4 )|h->mb.i_cbp_luma] ); } else if( i_mb_type != I_16x16 ) { bs_write_ue( s, inter_cbp_to_golomb[( h->mb.i_cbp_chroma << 4 )|h->mb.i_cbp_luma] ); } /* write residual */ if( i_mb_type == I_16x16 ) { bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp ); /* DC Luma */ block_residual_write_cavlc( h, s, BLOCK_INDEX_LUMA_DC , h->dct.luma16x16_dc, 16 ); if( h->mb.i_cbp_luma != 0 ) { /* AC Luma */ for( i = 0; i < 16; i++ ) { block_residual_write_cavlc( h, s, i, h->dct.block[i].residual_ac, 15 ); } } } else if( h->mb.i_cbp_luma != 0 || h->mb.i_cbp_chroma != 0 ) { bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp ); for( i = 0; i < 16; i++ ) { if( h->mb.i_cbp_luma & ( 1 << ( i / 4 ) ) ) { block_residual_write_cavlc( h, s, i, h->dct.block[i].luma4x4, 16 ); } } } if( h->mb.i_cbp_chroma != 0 ) { /* Chroma DC residual present */ block_residual_write_cavlc( h, s, BLOCK_INDEX_CHROMA_DC, h->dct.chroma_dc[0], 4 ); block_residual_write_cavlc( h, s, BLOCK_INDEX_CHROMA_DC, h->dct.chroma_dc[1], 4 ); if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */ { for( i = 0; i < 8; i++ ) { block_residual_write_cavlc( h, s, 16 + i, h->dct.block[16+i].residual_ac, 15 ); } } } if( IS_INTRA( i_mb_type ) ) h->stat.frame.i_itex_bits += bs_pos(s) - i_mb_pos_tex; else h->stat.frame.i_ptex_bits += bs_pos(s) - i_mb_pos_tex;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -