comparison motion_est_template.c @ 1799:95612d423fde libavcodec

multithreaded/SMP motion estimation multithreaded/SMP encoding for MPEG1/MPEG2/MPEG4/H263 all pthread specific code is in pthread.c to try it, run configure --enable-pthreads and ffmpeg ... -threads <num> the internal thread API is a simple AVCodecContext.execute() callback which executes a given function pointer with different arguments and returns after finishing all, that way no mutexes or other thread-mess is needed outside pthread.c
author michael
date Fri, 13 Feb 2004 17:54:10 +0000
parents 07a484280a82
children e039d79185c2
comparison
equal deleted inserted replaced
1798:a3da4b429984 1799:95612d423fde
555 }\ 555 }\
556 } 556 }
557 557
558 #define CHECK_CLIPED_MV(ax,ay)\ 558 #define CHECK_CLIPED_MV(ax,ay)\
559 {\ 559 {\
560 const int x= FFMAX(xmin, FFMIN(ax, xmax));\ 560 const int x= ax;\
561 const int y= FFMAX(ymin, FFMIN(ay, ymax));\ 561 const int y= ay;\
562 CHECK_MV(x, y)\ 562 const int x2= FFMAX(xmin, FFMIN(x, xmax));\
563 const int y2= FFMAX(ymin, FFMIN(y, ymax));\
564 CHECK_MV(x2, y2)\
563 } 565 }
564 566
565 #define CHECK_MV_DIR(x,y,new_dir)\ 567 #define CHECK_MV_DIR(x,y,new_dir)\
566 {\ 568 {\
567 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\ 569 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
910 CMP(dmin, 0, 0, size); 912 CMP(dmin, 0, 0, size);
911 map[0]= map_generation; 913 map[0]= map_generation;
912 score_map[0]= dmin; 914 score_map[0]= dmin;
913 915
914 /* first line */ 916 /* first line */
915 if (s->mb_y == 0) { 917 if (s->first_slice_line) {
916 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) 918 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
917 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 919 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
918 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) 920 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
919 }else{ 921 }else{
920 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1] 922 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
936 } 938 }
937 if(dmin>256*4){ 939 if(dmin>256*4){
938 if(s->me.pre_pass){ 940 if(s->me.pre_pass){
939 CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16, 941 CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
940 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16) 942 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
941 CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 943 if(!s->first_slice_line)
942 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) 944 CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
945 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
943 }else{ 946 }else{
944 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 947 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
945 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) 948 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
946 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 949 if(s->end_mb_y == s->mb_height || s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
947 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) 950 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
951 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
948 } 952 }
949 } 953 }
950 954
951 if(s->avctx->last_predictor_count){ 955 if(s->avctx->last_predictor_count){
952 const int count= s->avctx->last_predictor_count; 956 const int count= s->avctx->last_predictor_count;
1022 map_generation= update_map_generation(s); 1026 map_generation= update_map_generation(s);
1023 1027
1024 dmin = 1000000; 1028 dmin = 1000000;
1025 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 1029 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
1026 /* first line */ 1030 /* first line */
1027 if (s->mb_y == 0/* && block<2*/) { 1031 if (s->first_slice_line) {
1028 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) 1032 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
1029 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 1033 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
1030 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) 1034 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
1031 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift) 1035 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
1032 }else{ 1036 }else{
1042 } 1046 }
1043 } 1047 }
1044 if(dmin>64*4){ 1048 if(dmin>64*4){
1045 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 1049 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
1046 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) 1050 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
1047 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 1051 if(s->end_mb_y == s->mb_height || s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
1048 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) 1052 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1053 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
1049 } 1054 }
1050 1055
1051 if(s->me.dia_size==-1) 1056 if(s->me.dia_size==-1)
1052 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, 1057 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
1053 pred_x, pred_y, penalty_factor, 1058 pred_x, pred_y, penalty_factor,
1100 map_generation= update_map_generation(s); 1105 map_generation= update_map_generation(s);
1101 1106
1102 dmin = 1000000; 1107 dmin = 1000000;
1103 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 1108 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
1104 /* first line */ 1109 /* first line */
1105 if (s->mb_y == 0) { 1110 if (s->first_slice_line) {
1106 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) 1111 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
1107 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 1112 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
1108 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) 1113 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
1109 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift) 1114 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
1110 }else{ 1115 }else{
1120 } 1125 }
1121 } 1126 }
1122 if(dmin>64*4){ 1127 if(dmin>64*4){
1123 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 1128 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
1124 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) 1129 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
1125 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 1130 if(s->end_mb_y == s->mb_height || s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
1126 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) 1131 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1132 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
1127 } 1133 }
1128 1134
1129 if(s->me.dia_size==-1) 1135 if(s->me.dia_size==-1)
1130 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, 1136 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
1131 pred_x, pred_y, penalty_factor, 1137 pred_x, pred_y, penalty_factor,