Mercurial > libavcodec.hg
comparison h263.c @ 3247:ac7bfc9bf1a4 libavcodec
2x faster ff_mpeg4_set_direct_mv
author | lorenm |
---|---|
date | Mon, 03 Apr 2006 07:52:24 +0000 |
parents | 198f8b01424d |
children | 183e3eb0824a |
comparison
equal
deleted
inserted
replaced
3246:219afc0c4a80 | 3247:ac7bfc9bf1a4 |
---|---|
550 } | 550 } |
551 } | 551 } |
552 } | 552 } |
553 | 553 |
554 #endif //CONFIG_ENCODERS | 554 #endif //CONFIG_ENCODERS |
555 | |
556 static void ff_mpeg4_init_direct_mv(MpegEncContext *s){ | |
557 //FIXME table is stored in MpegEncContext for thread-safety, | |
558 // but a static array would be faster | |
559 static const int tab_size = sizeof(s->direct_scale_mv[0])/sizeof(int16_t); | |
560 static const int tab_bias = (tab_size/2); | |
561 int i; | |
562 for(i=0; i<tab_size; i++){ | |
563 s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time; | |
564 s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time; | |
565 } | |
566 } | |
567 | |
568 static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){ | |
569 static const int tab_size = sizeof(s->direct_scale_mv[0])/sizeof(int16_t); | |
570 static const int tab_bias = (tab_size/2); | |
571 int xy= s->block_index[i]; | |
572 uint16_t time_pp= s->pp_time; | |
573 uint16_t time_pb= s->pb_time; | |
574 int p_mx, p_my; | |
575 | |
576 p_mx= s->next_picture.motion_val[0][xy][0]; | |
577 if((unsigned)(p_mx + tab_bias) < tab_size){ | |
578 s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx; | |
579 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
580 : s->direct_scale_mv[1][p_mx + tab_bias]; | |
581 }else{ | |
582 s->mv[0][i][0] = p_mx*time_pb/time_pp + mx; | |
583 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
584 : p_mx*(time_pb - time_pp)/time_pp; | |
585 } | |
586 p_my= s->next_picture.motion_val[0][xy][1]; | |
587 if((unsigned)(p_my + tab_bias) < tab_size){ | |
588 s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my; | |
589 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
590 : s->direct_scale_mv[1][p_my + tab_bias]; | |
591 }else{ | |
592 s->mv[0][i][1] = p_my*time_pb/time_pp + my; | |
593 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
594 : p_my*(time_pb - time_pp)/time_pp; | |
595 } | |
596 } | |
597 | |
555 /** | 598 /** |
556 * | 599 * |
557 * @return the mb_type | 600 * @return the mb_type |
558 */ | 601 */ |
559 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ | 602 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ |
560 const int mb_index= s->mb_x + s->mb_y*s->mb_stride; | 603 const int mb_index= s->mb_x + s->mb_y*s->mb_stride; |
561 const int colocated_mb_type= s->next_picture.mb_type[mb_index]; | 604 const int colocated_mb_type= s->next_picture.mb_type[mb_index]; |
562 int xy= s->block_index[0]; | |
563 uint16_t time_pp= s->pp_time; | 605 uint16_t time_pp= s->pp_time; |
564 uint16_t time_pb= s->pb_time; | 606 uint16_t time_pb= s->pb_time; |
565 int i; | 607 int i; |
566 | 608 |
567 //FIXME avoid divides | 609 //FIXME avoid divides |
610 // try special case with shifts for 1 and 3 B-frames? | |
568 | 611 |
569 if(IS_8X8(colocated_mb_type)){ | 612 if(IS_8X8(colocated_mb_type)){ |
570 s->mv_type = MV_TYPE_8X8; | 613 s->mv_type = MV_TYPE_8X8; |
571 for(i=0; i<4; i++){ | 614 for(i=0; i<4; i++){ |
572 xy= s->block_index[i]; | 615 ff_mpeg4_set_one_direct_mv(s, mx, my, i); |
573 s->mv[0][i][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx; | |
574 s->mv[0][i][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my; | |
575 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->next_picture.motion_val[0][xy][0] | |
576 : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; | |
577 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->next_picture.motion_val[0][xy][1] | |
578 : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; | |
579 } | 616 } |
580 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; | 617 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; |
581 } else if(IS_INTERLACED(colocated_mb_type)){ | 618 } else if(IS_INTERLACED(colocated_mb_type)){ |
582 s->mv_type = MV_TYPE_FIELD; | 619 s->mv_type = MV_TYPE_FIELD; |
583 for(i=0; i<2; i++){ | 620 for(i=0; i<2; i++){ |
598 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] | 635 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] |
599 : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; | 636 : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; |
600 } | 637 } |
601 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; | 638 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; |
602 }else{ | 639 }else{ |
603 s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx; | 640 ff_mpeg4_set_one_direct_mv(s, mx, my, 0); |
604 s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my; | 641 s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0]; |
605 s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->next_picture.motion_val[0][xy][0] | 642 s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1]; |
606 : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; | 643 s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0]; |
607 s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->next_picture.motion_val[0][xy][1] | 644 s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1]; |
608 : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; | |
609 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) | 645 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) |
610 s->mv_type= MV_TYPE_16X16; | 646 s->mv_type= MV_TYPE_16X16; |
611 else | 647 else |
612 s->mv_type= MV_TYPE_8X8; | 648 s->mv_type= MV_TYPE_8X8; |
613 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line | 649 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line |
2217 time_mod= s->time%s->avctx->time_base.den; | 2253 time_mod= s->time%s->avctx->time_base.den; |
2218 | 2254 |
2219 if(s->pict_type==B_TYPE){ | 2255 if(s->pict_type==B_TYPE){ |
2220 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); | 2256 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); |
2221 assert(s->pb_time > 0 && s->pb_time < s->pp_time); | 2257 assert(s->pb_time > 0 && s->pb_time < s->pp_time); |
2258 ff_mpeg4_init_direct_mv(s); | |
2222 }else{ | 2259 }else{ |
2223 s->last_time_base= s->time_base; | 2260 s->last_time_base= s->time_base; |
2224 s->time_base= time_div; | 2261 s->time_base= time_div; |
2225 s->pp_time= s->time - s->last_non_b_time; | 2262 s->pp_time= s->time - s->last_non_b_time; |
2226 s->last_non_b_time= s->time; | 2263 s->last_non_b_time= s->time; |
5849 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); | 5886 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); |
5850 if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ | 5887 if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ |
5851 // printf("messed up order, maybe after seeking? skipping current b frame\n"); | 5888 // printf("messed up order, maybe after seeking? skipping current b frame\n"); |
5852 return FRAME_SKIPPED; | 5889 return FRAME_SKIPPED; |
5853 } | 5890 } |
5891 ff_mpeg4_init_direct_mv(s); | |
5854 | 5892 |
5855 if(s->t_frame==0) s->t_frame= s->pb_time; | 5893 if(s->t_frame==0) s->t_frame= s->pb_time; |
5856 if(s->t_frame==0) s->t_frame=1; // 1/0 protection | 5894 if(s->t_frame==0) s->t_frame=1; // 1/0 protection |
5857 s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame) | 5895 s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame) |
5858 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; | 5896 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; |