comparison mpegvideo_common.h @ 6658:7ecd59aa5757 libavcodec

Unroll codepath Patch by strites: strites gmail com Original thread: [FFmpeg-devel] [PATCH] Patch cleanup for MPEG 1 & 2 optimizations Date: 04/06/2008 11:32 PM
author benoit
date Mon, 21 Apr 2008 08:30:54 +0000
parents bd5c42ff9e27
children 4866b892ecbe
comparison
equal deleted inserted replaced
6657:2574def95b50 6658:7ecd59aa5757
235 src += s->linesize; 235 src += s->linesize;
236 pix_op[dxy](dest, src, stride, h); 236 pix_op[dxy](dest, src, stride, h);
237 return emu; 237 return emu;
238 } 238 }
239 239
240 /* apply one mpeg motion vector to the three components */
241 static av_always_inline 240 static av_always_inline
242 void mpeg_motion(MpegEncContext *s, 241 void mpeg_motion_internal(MpegEncContext *s,
243 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, 242 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
244 int field_based, int bottom_field, int field_select, 243 int field_based, int bottom_field, int field_select,
245 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], 244 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
246 int motion_x, int motion_y, int h) 245 int motion_x, int motion_y, int h, int is_mpeg12)
247 { 246 {
248 uint8_t *ptr_y, *ptr_cb, *ptr_cr; 247 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
249 int dxy, uvdxy, mx, my, src_x, src_y, 248 int dxy, uvdxy, mx, my, src_x, src_y,
250 uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; 249 uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
251 250
263 262
264 dxy = ((motion_y & 1) << 1) | (motion_x & 1); 263 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
265 src_x = s->mb_x* 16 + (motion_x >> 1); 264 src_x = s->mb_x* 16 + (motion_x >> 1);
266 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); 265 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
267 266
268 if (s->out_format == FMT_H263) { 267 if (!is_mpeg12 && s->out_format == FMT_H263) {
269 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ 268 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
270 mx = (motion_x>>1)|(motion_x&1); 269 mx = (motion_x>>1)|(motion_x&1);
271 my = motion_y >>1; 270 my = motion_y >>1;
272 uvdxy = ((my & 1) << 1) | (mx & 1); 271 uvdxy = ((my & 1) << 1) | (mx & 1);
273 uvsrc_x = s->mb_x* 8 + (mx >> 1); 272 uvsrc_x = s->mb_x* 8 + (mx >> 1);
275 }else{ 274 }else{
276 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); 275 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
277 uvsrc_x = src_x>>1; 276 uvsrc_x = src_x>>1;
278 uvsrc_y = src_y>>1; 277 uvsrc_y = src_y>>1;
279 } 278 }
280 }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 279 }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261
281 mx = motion_x / 4; 280 mx = motion_x / 4;
282 my = motion_y / 4; 281 my = motion_y / 4;
283 uvdxy = 0; 282 uvdxy = 0;
284 uvsrc_x = s->mb_x*8 + mx; 283 uvsrc_x = s->mb_x*8 + mx;
285 uvsrc_y = s->mb_y*8 + my; 284 uvsrc_y = s->mb_y*8 + my;
310 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; 309 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
311 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; 310 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
312 311
313 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 312 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
314 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ 313 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
315 if(s->codec_id == CODEC_ID_MPEG2VIDEO || 314 if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO ||
316 s->codec_id == CODEC_ID_MPEG1VIDEO){ 315 s->codec_id == CODEC_ID_MPEG1VIDEO){
317 av_log(s->avctx,AV_LOG_DEBUG, 316 av_log(s->avctx,AV_LOG_DEBUG,
318 "MPEG motion vector out of boundary\n"); 317 "MPEG motion vector out of boundary\n");
319 return ; 318 return ;
320 } 319 }
358 pix_op[s->chroma_x_shift][uvdxy] 357 pix_op[s->chroma_x_shift][uvdxy]
359 (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); 358 (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
360 pix_op[s->chroma_x_shift][uvdxy] 359 pix_op[s->chroma_x_shift][uvdxy]
361 (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); 360 (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
362 } 361 }
363 if((ENABLE_H261_ENCODER || ENABLE_H261_DECODER) && 362 if(!is_mpeg12 && (ENABLE_H261_ENCODER || ENABLE_H261_DECODER) &&
364 s->out_format == FMT_H261){ 363 s->out_format == FMT_H261){
365 ff_h261_loop_filter(s); 364 ff_h261_loop_filter(s);
366 } 365 }
366 }
367 /* apply one mpeg motion vector to the three components */
368 static av_always_inline
369 void mpeg_motion(MpegEncContext *s,
370 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
371 int field_based, int bottom_field, int field_select,
372 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
373 int motion_x, int motion_y, int h)
374 {
375 #ifndef CONFIG_SMALL
376 if(s->out_format == FMT_MPEG1)
377 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
378 bottom_field, field_select, ref_picture, pix_op,
379 motion_x, motion_y, h, 1);
380 else
381 #endif
382 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
383 bottom_field, field_select, ref_picture, pix_op,
384 motion_x, motion_y, h, 0);
367 } 385 }
368 386
369 //FIXME move to dsputil, avg variant, 16x16 version 387 //FIXME move to dsputil, avg variant, 16x16 version
370 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ 388 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
371 int x; 389 int x;
615 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture 633 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
616 * @param pic_op halfpel motion compensation function (average or put normally) 634 * @param pic_op halfpel motion compensation function (average or put normally)
617 * @param pic_op qpel motion compensation function (average or put normally) 635 * @param pic_op qpel motion compensation function (average or put normally)
618 * the motion vectors are taken from s->mv and the MV type from s->mv_type 636 * the motion vectors are taken from s->mv and the MV type from s->mv_type
619 */ 637 */
620 static inline void MPV_motion(MpegEncContext *s, 638 static inline void MPV_motion_internal(MpegEncContext *s,
621 uint8_t *dest_y, uint8_t *dest_cb, 639 uint8_t *dest_y, uint8_t *dest_cb,
622 uint8_t *dest_cr, int dir, 640 uint8_t *dest_cr, int dir,
623 uint8_t **ref_picture, 641 uint8_t **ref_picture,
624 op_pixels_func (*pix_op)[4], 642 op_pixels_func (*pix_op)[4],
625 qpel_mc_func (*qpix_op)[16]) 643 qpel_mc_func (*qpix_op)[16], int is_mpeg12)
626 { 644 {
627 int dxy, mx, my, src_x, src_y, motion_x, motion_y; 645 int dxy, mx, my, src_x, src_y, motion_x, motion_y;
628 int mb_x, mb_y, i; 646 int mb_x, mb_y, i;
629 uint8_t *ptr, *dest; 647 uint8_t *ptr, *dest;
630 648
631 mb_x = s->mb_x; 649 mb_x = s->mb_x;
632 mb_y = s->mb_y; 650 mb_y = s->mb_y;
633 651
634 prefetch_motion(s, ref_picture, dir); 652 prefetch_motion(s, ref_picture, dir);
635 653
636 if(s->obmc && s->pict_type != FF_B_TYPE){ 654 if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){
637 int16_t mv_cache[4][4][2]; 655 int16_t mv_cache[4][4][2];
638 const int xy= s->mb_x + s->mb_y*s->mb_stride; 656 const int xy= s->mb_x + s->mb_y*s->mb_stride;
639 const int mot_stride= s->b8_stride; 657 const int mot_stride= s->b8_stride;
640 const int mot_xy= mb_x*2 + mb_y*2*mot_stride; 658 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
641 659
702 ref_picture); 720 ref_picture);
703 }else{ 721 }else{
704 gmc_motion(s, dest_y, dest_cb, dest_cr, 722 gmc_motion(s, dest_y, dest_cb, dest_cr,
705 ref_picture); 723 ref_picture);
706 } 724 }
707 }else if(s->quarter_sample){ 725 }else if(!is_mpeg12 && s->quarter_sample){
708 qpel_motion(s, dest_y, dest_cb, dest_cr, 726 qpel_motion(s, dest_y, dest_cb, dest_cr,
709 0, 0, 0, 727 0, 0, 0,
710 ref_picture, pix_op, qpix_op, 728 ref_picture, pix_op, qpix_op,
711 s->mv[dir][0][0], s->mv[dir][0][1], 16); 729 s->mv[dir][0][0], s->mv[dir][0][1], 16);
712 }else if(ENABLE_WMV2 && s->mspel){ 730 }else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){
713 ff_mspel_motion(s, dest_y, dest_cb, dest_cr, 731 ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
714 ref_picture, pix_op, 732 ref_picture, pix_op,
715 s->mv[dir][0][0], s->mv[dir][0][1], 16); 733 s->mv[dir][0][0], s->mv[dir][0][1], 16);
716 }else 734 }else
717 { 735 {
720 ref_picture, pix_op, 738 ref_picture, pix_op,
721 s->mv[dir][0][0], s->mv[dir][0][1], 16); 739 s->mv[dir][0][0], s->mv[dir][0][1], 16);
722 } 740 }
723 break; 741 break;
724 case MV_TYPE_8X8: 742 case MV_TYPE_8X8:
743 if (!is_mpeg12) {
725 mx = 0; 744 mx = 0;
726 my = 0; 745 my = 0;
727 if(s->quarter_sample){ 746 if(s->quarter_sample){
728 for(i=0;i<4;i++) { 747 for(i=0;i<4;i++) {
729 motion_x = s->mv[dir][i][0]; 748 motion_x = s->mv[dir][i][0];
773 } 792 }
774 } 793 }
775 794
776 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) 795 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
777 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); 796 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
797 }
778 break; 798 break;
779 case MV_TYPE_FIELD: 799 case MV_TYPE_FIELD:
780 if (s->picture_structure == PICT_FRAME) { 800 if (s->picture_structure == PICT_FRAME) {
781 if(s->quarter_sample){ 801 if(!is_mpeg12 && s->quarter_sample){
782 for(i=0; i<2; i++){ 802 for(i=0; i<2; i++){
783 qpel_motion(s, dest_y, dest_cb, dest_cr, 803 qpel_motion(s, dest_y, dest_cb, dest_cr,
784 1, i, s->field_select[dir][i], 804 1, i, s->field_select[dir][i],
785 ref_picture, pix_op, qpix_op, 805 ref_picture, pix_op, qpix_op,
786 s->mv[dir][i][0], s->mv[dir][i][1], 8); 806 s->mv[dir][i][0], s->mv[dir][i][1], 8);
860 break; 880 break;
861 default: assert(0); 881 default: assert(0);
862 } 882 }
863 } 883 }
864 884
885 static inline void MPV_motion(MpegEncContext *s,
886 uint8_t *dest_y, uint8_t *dest_cb,
887 uint8_t *dest_cr, int dir,
888 uint8_t **ref_picture,
889 op_pixels_func (*pix_op)[4],
890 qpel_mc_func (*qpix_op)[16])
891 {
892 #ifndef CONFIG_SMALL
893 if(s->out_format == FMT_MPEG1)
894 MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
895 ref_picture, pix_op, qpix_op, 1);
896 else
897 #endif
898 MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
899 ref_picture, pix_op, qpix_op, 0);
900 }
865 #endif /* FFMPEG_MPEGVIDEO_COMMON_H */ 901 #endif /* FFMPEG_MPEGVIDEO_COMMON_H */