📄 h264.c
字号:
return mode;}/** * gets the predicted intra4x4 prediction mode. */static inline int pred_intra_mode(H264Context *h, int n){ const int index8= scan8[n]; const int left= h->intra4x4_pred_mode_cache[index8 - 1]; const int top = h->intra4x4_pred_mode_cache[index8 - 8]; const int min= FFMIN(left, top); tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min); if(min<0) return DC_PRED; else return min;}static inline void write_back_non_zero_count(H264Context *h){ MpegEncContext * const s = &h->s; const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[7+8*1]; h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[7+8*2]; h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[7+8*3]; h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4]; h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[4+8*4]; h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[5+8*4]; h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[6+8*4]; h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[1+8*2]; h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2]; h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[2+8*1]; h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[1+8*5]; h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5]; h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[2+8*4]; if(FRAME_MBAFF){ // store all luma nnzs, for deblocking int v = 0, i; for(i=0; i<16; i++) v += (!!h->non_zero_count_cache[scan8[i]]) << i; *(uint16_t*)&h->non_zero_count[mb_xy][14] = v; }}/** * gets the predicted number of non zero coefficients. * @param n block index */static inline int pred_non_zero_count(H264Context *h, int n){ const int index8= scan8[n]; const int left= h->non_zero_count_cache[index8 - 1]; const int top = h->non_zero_count_cache[index8 - 8]; int i= left + top; if(i<64) i= (i+1)>>1; tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); return i&31;}static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; MpegEncContext *s = &h->s; /* there is no consistent mapping of mvs to neighboring locations that will * make mbaff happy, so we can't move all this logic to fill_caches */ if(FRAME_MBAFF){ const uint32_t *mb_types = s->current_picture_ptr->mb_type; const int16_t *mv; *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0; *C = h->mv_cache[list][scan8[0]-2]; if(!MB_FIELD && (s->mb_y&1) && i < scan8[0]+8 && topright_ref != PART_NOT_AVAILABLE){ int topright_xy = s->mb_x + (s->mb_y-1)*s->mb_stride + (i == scan8[0]+3); if(IS_INTERLACED(mb_types[topright_xy])){#define SET_DIAG_MV(MV_OP, REF_OP, X4, Y4)\ const int x4 = X4, y4 = Y4;\ const int mb_type = mb_types[(x4>>2)+(y4>>2)*s->mb_stride];\ if(!USES_LIST(mb_type,list))\ return LIST_NOT_USED;\ mv = s->current_picture_ptr->motion_val[list][x4 + y4*h->b_stride];\ h->mv_cache[list][scan8[0]-2][0] = mv[0];\ h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\ return s->current_picture_ptr->ref_index[list][(x4>>1) + (y4>>1)*h->b8_stride] REF_OP; SET_DIAG_MV(*2, >>1, s->mb_x*4+(i&7)-4+part_width, s->mb_y*4-1); } } if(topright_ref == PART_NOT_AVAILABLE && ((s->mb_y&1) || i >= scan8[0]+8) && (i&7)==4 && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){ if(!MB_FIELD && IS_INTERLACED(mb_types[h->left_mb_xy[0]])){ SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1); } if(MB_FIELD && !IS_INTERLACED(mb_types[h->left_mb_xy[0]]) && i >= scan8[0]+8){ // leftshift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's ok. SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); } }#undef SET_DIAG_MV } if(topright_ref != PART_NOT_AVAILABLE){ *C= h->mv_cache[list][ i - 8 + part_width ]; return topright_ref; }else{ tprintf(s->avctx, "topright MV not available\n"); *C= h->mv_cache[list][ i - 8 - 1 ]; return h->ref_cache[list][ i - 8 - 1 ]; }}/** * gets the predicted MV. * @param n the block index * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) * @param mx the x component of the predicted motion vector * @param my the y component of the predicted motion vector */static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ const int index8= scan8[n]; const int top_ref= h->ref_cache[list][ index8 - 8 ]; const int left_ref= h->ref_cache[list][ index8 - 1 ]; const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; const int16_t * C; int diagonal_ref, match_count; assert(part_width==1 || part_width==2 || part_width==4);/* mv_cache B . . A T T T T U . . L . . , . U . . L . . . . U . . L . . , . . . . L . . . .*/ diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); if(match_count > 1){ //most common *mx= mid_pred(A[0], B[0], C[0]); *my= mid_pred(A[1], B[1], C[1]); }else if(match_count==1){ if(left_ref==ref){ *mx= A[0]; *my= A[1]; }else if(top_ref==ref){ *mx= B[0]; *my= B[1]; }else{ *mx= C[0]; *my= C[1]; } }else{ if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ *mx= A[0]; *my= A[1]; }else{ *mx= mid_pred(A[0], B[0], C[0]); *my= mid_pred(A[1], B[1], C[1]); } } tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);}/** * gets the directionally predicted 16x8 MV. * @param n the block index * @param mx the x component of the predicted motion vector * @param my the y component of the predicted motion vector */static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ if(n==0){ const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); if(top_ref == ref){ *mx= B[0]; *my= B[1]; return; } }else{ const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); if(left_ref == ref){ *mx= A[0]; *my= A[1]; return; } } //RARE pred_motion(h, n, 4, list, ref, mx, my);}/** * gets the directionally predicted 8x16 MV. * @param n the block index * @param mx the x component of the predicted motion vector * @param my the y component of the predicted motion vector */static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ if(n==0){ const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); if(left_ref == ref){ *mx= A[0]; *my= A[1]; return; } }else{ const int16_t * C; int diagonal_ref; diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); if(diagonal_ref == ref){ *mx= C[0]; *my= C[1]; return; } } //RARE pred_motion(h, n, 2, list, ref, mx, my);}static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ *mx = *my = 0; return; } pred_motion(h, 0, 4, 0, 0, mx, my); return;}static inline void direct_dist_scale_factor(H264Context * const h){ const int poc = h->s.current_picture_ptr->poc; const int poc1 = h->ref_list[1][0].poc; int i; for(i=0; i<h->ref_count[0]; i++){ int poc0 = h->ref_list[0][i].poc; int td = av_clip(poc1 - poc0, -128, 127); if(td == 0 /* FIXME || pic0 is a long-term ref */){ h->dist_scale_factor[i] = 256; }else{ int tb = av_clip(poc - poc0, -128, 127); int tx = (16384 + (FFABS(td) >> 1)) / td; h->dist_scale_factor[i] = av_clip((tb*tx + 32) >> 6, -1024, 1023); } } if(FRAME_MBAFF){ for(i=0; i<h->ref_count[0]; i++){ h->dist_scale_factor_field[2*i] = h->dist_scale_factor_field[2*i+1] = h->dist_scale_factor[i]; } }}static inline void direct_ref_list_init(H264Context * const h){ MpegEncContext * const s = &h->s; Picture * const ref1 = &h->ref_list[1][0]; Picture * const cur = s->current_picture_ptr; int list, i, j; if(cur->pict_type == I_TYPE) cur->ref_count[0] = 0; if(cur->pict_type != B_TYPE) cur->ref_count[1] = 0; for(list=0; list<2; list++){ cur->ref_count[list] = h->ref_count[list]; for(j=0; j<h->ref_count[list]; j++) cur->ref_poc[list][j] = h->ref_list[list][j].poc; } if(cur->pict_type != B_TYPE || h->direct_spatial_mv_pred) return; for(list=0; list<2; list++){ for(i=0; i<ref1->ref_count[list]; i++){ const int poc = ref1->ref_poc[list][i]; h->map_col_to_list0[list][i] = 0; /* bogus; fills in for missing frames */ for(j=0; j<h->ref_count[list]; j++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -