comparison h263.c @ 2017:f089d25c82f0 libavcodec

motion estimation for SVQ1
author michael
date Wed, 12 May 2004 02:03:24 +0000
parents ec6bfd8d92fc
children 9629c1180d5f
comparison
equal deleted inserted replaced
2016:f8ef6f664234 2017:f089d25c82f0
54 #define CBPC_B_VLC_BITS 3 54 #define CBPC_B_VLC_BITS 3
55 55
56 #ifdef CONFIG_ENCODERS 56 #ifdef CONFIG_ENCODERS
57 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, 57 static void h263_encode_block(MpegEncContext * s, DCTELEM * block,
58 int n); 58 int n);
59 static void h263_encode_motion(MpegEncContext * s, int val, int fcode);
60 static void h263p_encode_umotion(MpegEncContext * s, int val); 59 static void h263p_encode_umotion(MpegEncContext * s, int val);
61 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, 60 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block,
62 int n, int dc, uint8_t *scan_table, 61 int n, int dc, uint8_t *scan_table,
63 PutBitContext *dc_pb, PutBitContext *ac_pb); 62 PutBitContext *dc_pb, PutBitContext *ac_pb);
64 #endif 63 #endif
849 s->misc_bits+= get_bits_diff(s); 848 s->misc_bits+= get_bits_diff(s);
850 } 849 }
851 850
852 if(mb_type == 0){ 851 if(mb_type == 0){
853 assert(s->mv_dir & MV_DIRECT); 852 assert(s->mv_dir & MV_DIRECT);
854 h263_encode_motion(s, motion_x, 1); 853 ff_h263_encode_motion(s, motion_x, 1);
855 h263_encode_motion(s, motion_y, 1); 854 ff_h263_encode_motion(s, motion_y, 1);
856 s->b_count++; 855 s->b_count++;
857 s->f_count++; 856 s->f_count++;
858 }else{ 857 }else{
859 assert(mb_type > 0 && mb_type < 4); 858 assert(mb_type > 0 && mb_type < 4);
860 if(s->mv_type != MV_TYPE_FIELD){ 859 if(s->mv_type != MV_TYPE_FIELD){
861 if(s->mv_dir & MV_DIR_FORWARD){ 860 if(s->mv_dir & MV_DIR_FORWARD){
862 h263_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); 861 ff_h263_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
863 h263_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); 862 ff_h263_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
864 s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0]; 863 s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0];
865 s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1]; 864 s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1];
866 s->f_count++; 865 s->f_count++;
867 } 866 }
868 if(s->mv_dir & MV_DIR_BACKWARD){ 867 if(s->mv_dir & MV_DIR_BACKWARD){
869 h263_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code); 868 ff_h263_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
870 h263_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); 869 ff_h263_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
871 s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0]; 870 s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0];
872 s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1]; 871 s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1];
873 s->b_count++; 872 s->b_count++;
874 } 873 }
875 }else{ 874 }else{
881 put_bits(&s->pb, 1, s->field_select[1][0]); 880 put_bits(&s->pb, 1, s->field_select[1][0]);
882 put_bits(&s->pb, 1, s->field_select[1][1]); 881 put_bits(&s->pb, 1, s->field_select[1][1]);
883 } 882 }
884 if(s->mv_dir & MV_DIR_FORWARD){ 883 if(s->mv_dir & MV_DIR_FORWARD){
885 for(i=0; i<2; i++){ 884 for(i=0; i<2; i++){
886 h263_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); 885 ff_h263_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
887 h263_encode_motion(s, s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code); 886 ff_h263_encode_motion(s, s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code);
888 s->last_mv[0][i][0]= s->mv[0][i][0]; 887 s->last_mv[0][i][0]= s->mv[0][i][0];
889 s->last_mv[0][i][1]= s->mv[0][i][1]*2; 888 s->last_mv[0][i][1]= s->mv[0][i][1]*2;
890 } 889 }
891 s->f_count++; 890 s->f_count++;
892 } 891 }
893 if(s->mv_dir & MV_DIR_BACKWARD){ 892 if(s->mv_dir & MV_DIR_BACKWARD){
894 for(i=0; i<2; i++){ 893 for(i=0; i<2; i++){
895 h263_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code); 894 ff_h263_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code);
896 h263_encode_motion(s, s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code); 895 ff_h263_encode_motion(s, s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code);
897 s->last_mv[1][i][0]= s->mv[1][i][0]; 896 s->last_mv[1][i][0]= s->mv[1][i][0];
898 s->last_mv[1][i][1]= s->mv[1][i][1]*2; 897 s->last_mv[1][i][1]= s->mv[1][i][1]*2;
899 } 898 }
900 s->b_count++; 899 s->b_count++;
901 } 900 }
991 } 990 }
992 991
993 /* motion vectors: 16x16 mode */ 992 /* motion vectors: 16x16 mode */
994 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); 993 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
995 994
996 h263_encode_motion(s, motion_x - pred_x, s->f_code); 995 ff_h263_encode_motion(s, motion_x - pred_x, s->f_code);
997 h263_encode_motion(s, motion_y - pred_y, s->f_code); 996 ff_h263_encode_motion(s, motion_y - pred_y, s->f_code);
998 }else if(s->mv_type==MV_TYPE_FIELD){ 997 }else if(s->mv_type==MV_TYPE_FIELD){
999 if(s->dquant) cbpc+= 8; 998 if(s->dquant) cbpc+= 8;
1000 put_bits(&s->pb, 999 put_bits(&s->pb,
1001 inter_MCBPC_bits[cbpc], 1000 inter_MCBPC_bits[cbpc],
1002 inter_MCBPC_code[cbpc]); 1001 inter_MCBPC_code[cbpc]);
1019 pred_y /=2; 1018 pred_y /=2;
1020 1019
1021 put_bits(&s->pb, 1, s->field_select[0][0]); 1020 put_bits(&s->pb, 1, s->field_select[0][0]);
1022 put_bits(&s->pb, 1, s->field_select[0][1]); 1021 put_bits(&s->pb, 1, s->field_select[0][1]);
1023 1022
1024 h263_encode_motion(s, s->mv[0][0][0] - pred_x, s->f_code); 1023 ff_h263_encode_motion(s, s->mv[0][0][0] - pred_x, s->f_code);
1025 h263_encode_motion(s, s->mv[0][0][1] - pred_y, s->f_code); 1024 ff_h263_encode_motion(s, s->mv[0][0][1] - pred_y, s->f_code);
1026 h263_encode_motion(s, s->mv[0][1][0] - pred_x, s->f_code); 1025 ff_h263_encode_motion(s, s->mv[0][1][0] - pred_x, s->f_code);
1027 h263_encode_motion(s, s->mv[0][1][1] - pred_y, s->f_code); 1026 ff_h263_encode_motion(s, s->mv[0][1][1] - pred_y, s->f_code);
1028 }else{ 1027 }else{
1029 assert(s->mv_type==MV_TYPE_8X8); 1028 assert(s->mv_type==MV_TYPE_8X8);
1030 put_bits(&s->pb, 1029 put_bits(&s->pb,
1031 inter_MCBPC_bits[cbpc+16], 1030 inter_MCBPC_bits[cbpc+16],
1032 inter_MCBPC_code[cbpc+16]); 1031 inter_MCBPC_code[cbpc+16]);
1043 1042
1044 for(i=0; i<4; i++){ 1043 for(i=0; i<4; i++){
1045 /* motion vectors: 8x8 mode*/ 1044 /* motion vectors: 8x8 mode*/
1046 h263_pred_motion(s, i, 0, &pred_x, &pred_y); 1045 h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1047 1046
1048 h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code); 1047 ff_h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code);
1049 h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); 1048 ff_h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
1050 } 1049 }
1051 } 1050 }
1052 1051
1053 if(interleaved_stats){ 1052 if(interleaved_stats){
1054 s->mv_bits+= get_bits_diff(s); 1053 s->mv_bits+= get_bits_diff(s);
1184 1183
1185 /* motion vectors: 16x16 mode */ 1184 /* motion vectors: 16x16 mode */
1186 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); 1185 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1187 1186
1188 if (!s->umvplus) { 1187 if (!s->umvplus) {
1189 h263_encode_motion(s, motion_x - pred_x, 1); 1188 ff_h263_encode_motion(s, motion_x - pred_x, 1);
1190 h263_encode_motion(s, motion_y - pred_y, 1); 1189 ff_h263_encode_motion(s, motion_y - pred_y, 1);
1191 } 1190 }
1192 else { 1191 else {
1193 h263p_encode_umotion(s, motion_x - pred_x); 1192 h263p_encode_umotion(s, motion_x - pred_x);
1194 h263p_encode_umotion(s, motion_y - pred_y); 1193 h263p_encode_umotion(s, motion_y - pred_y);
1195 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) 1194 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
1213 h263_pred_motion(s, i, 0, &pred_x, &pred_y); 1212 h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1214 1213
1215 motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; 1214 motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
1216 motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; 1215 motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
1217 if (!s->umvplus) { 1216 if (!s->umvplus) {
1218 h263_encode_motion(s, motion_x - pred_x, 1); 1217 ff_h263_encode_motion(s, motion_x - pred_x, 1);
1219 h263_encode_motion(s, motion_y - pred_y, 1); 1218 ff_h263_encode_motion(s, motion_y - pred_y, 1);
1220 } 1219 }
1221 else { 1220 else {
1222 h263p_encode_umotion(s, motion_x - pred_x); 1221 h263p_encode_umotion(s, motion_x - pred_x);
1223 h263p_encode_umotion(s, motion_y - pred_y); 1222 h263p_encode_umotion(s, motion_y - pred_y);
1224 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) 1223 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
1617 } 1616 }
1618 return *mot_val; 1617 return *mot_val;
1619 } 1618 }
1620 1619
1621 #ifdef CONFIG_ENCODERS 1620 #ifdef CONFIG_ENCODERS
1622 static void h263_encode_motion(MpegEncContext * s, int val, int f_code) 1621 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
1623 { 1622 {
1624 int range, l, bit_size, sign, code, bits; 1623 int range, l, bit_size, sign, code, bits;
1625 1624
1626 if (val == 0) { 1625 if (val == 0) {
1627 /* zero vector */ 1626 /* zero vector */