Mercurial > libavcodec.hg
comparison h263.c @ 262:7d941b8c4e84 libavcodec
mpeg4 b-frames :)
create slightly more correct headers & add "ffmpeg" user-data section
author | michaelni |
---|---|
date | Tue, 12 Mar 2002 22:54:25 +0000 |
parents | db20b987c32d |
children | 126edd7d2803 |
comparison
equal
deleted
inserted
replaced
261:d6521bbbab5e | 262:7d941b8c4e84 |
---|---|
33 int n); | 33 int n); |
34 static void h263_encode_motion(MpegEncContext * s, int val); | 34 static void h263_encode_motion(MpegEncContext * s, int val); |
35 static void h263p_encode_umotion(MpegEncContext * s, int val); | 35 static void h263p_encode_umotion(MpegEncContext * s, int val); |
36 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, | 36 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, |
37 int n); | 37 int n); |
38 static int h263_decode_motion(MpegEncContext * s, int pred); | 38 static int h263_decode_motion(MpegEncContext * s, int pred, int fcode); |
39 static int h263p_decode_umotion(MpegEncContext * s, int pred); | 39 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
40 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, | 40 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
41 int n, int coded); | 41 int n, int coded); |
42 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | 42 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
43 int n, int coded); | 43 int n, int coded); |
419 *py = mid_pred(A[1], B[1], C[1]); | 419 *py = mid_pred(A[1], B[1], C[1]); |
420 } | 420 } |
421 return mot_val; | 421 return mot_val; |
422 } | 422 } |
423 | 423 |
424 | |
425 static void h263_encode_motion(MpegEncContext * s, int val) | 424 static void h263_encode_motion(MpegEncContext * s, int val) |
426 { | 425 { |
427 int range, l, m, bit_size, sign, code, bits; | 426 int range, l, m, bit_size, sign, code, bits; |
428 | 427 |
429 if (val == 0) { | 428 if (val == 0) { |
569 } | 568 } |
570 } | 569 } |
571 | 570 |
572 /***************************************************/ | 571 /***************************************************/ |
573 | 572 |
573 static void mpeg4_stuffing(PutBitContext * pbc) | |
574 { | |
575 int length; | |
576 put_bits(pbc, 1, 0); | |
577 length= (-get_bit_count(pbc))&7; | |
578 put_bits(pbc, length, (1<<length)-1); | |
579 } | |
580 | |
581 static void put_string(PutBitContext * pbc, char *s) | |
582 { | |
583 while(*s){ | |
584 put_bits(pbc, 8, *s); | |
585 s++; | |
586 } | |
587 put_bits(pbc, 8, 0); | |
588 } | |
589 | |
574 /* write mpeg4 VOP header */ | 590 /* write mpeg4 VOP header */ |
575 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) | 591 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) |
576 { | 592 { |
577 align_put_bits(&s->pb); | 593 mpeg4_stuffing(&s->pb); |
578 | 594 put_bits(&s->pb, 16, 0); |
595 put_bits(&s->pb, 16, 0x1B2); /* user_data */ | |
596 put_string(&s->pb, "ffmpeg"); //FIXME append some version ... | |
597 | |
598 mpeg4_stuffing(&s->pb); | |
579 put_bits(&s->pb, 16, 0); /* vop header */ | 599 put_bits(&s->pb, 16, 0); /* vop header */ |
580 put_bits(&s->pb, 16, 0x1B6); /* vop header */ | 600 put_bits(&s->pb, 16, 0x1B6); /* vop header */ |
581 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ | 601 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
582 /* XXX: time base + 1 not always correct */ | 602 /* XXX: time base + 1 not always correct */ |
583 put_bits(&s->pb, 1, 1); | 603 put_bits(&s->pb, 1, 1); |
837 static VLC inter_MCBPC_vlc; | 857 static VLC inter_MCBPC_vlc; |
838 static VLC cbpy_vlc; | 858 static VLC cbpy_vlc; |
839 static VLC mv_vlc; | 859 static VLC mv_vlc; |
840 static VLC dc_lum, dc_chrom; | 860 static VLC dc_lum, dc_chrom; |
841 static VLC sprite_trajectory; | 861 static VLC sprite_trajectory; |
862 static VLC mb_type_b_vlc; | |
842 | 863 |
843 void init_rl(RLTable *rl) | 864 void init_rl(RLTable *rl) |
844 { | 865 { |
845 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; | 866 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; |
846 UINT8 index_run[MAX_RUN+1]; | 867 UINT8 index_run[MAX_RUN+1]; |
920 &DCtab_chrom[0][1], 2, 1, | 941 &DCtab_chrom[0][1], 2, 1, |
921 &DCtab_chrom[0][0], 2, 1); | 942 &DCtab_chrom[0][0], 2, 1); |
922 init_vlc(&sprite_trajectory, 9, 15, | 943 init_vlc(&sprite_trajectory, 9, 15, |
923 &sprite_trajectory_tab[0][1], 4, 2, | 944 &sprite_trajectory_tab[0][1], 4, 2, |
924 &sprite_trajectory_tab[0][0], 4, 2); | 945 &sprite_trajectory_tab[0][0], 4, 2); |
946 init_vlc(&mb_type_b_vlc, 4, 4, | |
947 &mb_type_b_tab[0][1], 2, 1, | |
948 &mb_type_b_tab[0][0], 2, 1); | |
925 } | 949 } |
926 } | 950 } |
927 | 951 |
928 int h263_decode_gob_header(MpegEncContext *s) | 952 int h263_decode_gob_header(MpegEncContext *s) |
929 { | 953 { |
995 else if (cbpc == 20) | 1019 else if (cbpc == 20) |
996 fprintf(stderr, "Stuffing !"); | 1020 fprintf(stderr, "Stuffing !"); |
997 | 1021 |
998 dquant = cbpc & 8; | 1022 dquant = cbpc & 8; |
999 s->mb_intra = ((cbpc & 4) != 0); | 1023 s->mb_intra = ((cbpc & 4) != 0); |
1000 } else { | 1024 if (s->mb_intra) goto intra; |
1001 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | 1025 |
1002 if (cbpc < 0) | |
1003 return -1; | |
1004 dquant = cbpc & 4; | |
1005 s->mb_intra = 1; | |
1006 } | |
1007 | |
1008 if (!s->mb_intra) { | |
1009 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) | 1026 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) |
1010 s->mcsel= get_bits1(&s->gb); | 1027 s->mcsel= get_bits1(&s->gb); |
1011 else s->mcsel= 0; | 1028 else s->mcsel= 0; |
1012 cbpy = get_vlc(&s->gb, &cbpy_vlc); | 1029 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
1013 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); | 1030 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); |
1024 s->mv_type = MV_TYPE_16X16; | 1041 s->mv_type = MV_TYPE_16X16; |
1025 h263_pred_motion(s, 0, &pred_x, &pred_y); | 1042 h263_pred_motion(s, 0, &pred_x, &pred_y); |
1026 if (s->umvplus_dec) | 1043 if (s->umvplus_dec) |
1027 mx = h263p_decode_umotion(s, pred_x); | 1044 mx = h263p_decode_umotion(s, pred_x); |
1028 else if(!s->mcsel) | 1045 else if(!s->mcsel) |
1029 mx = h263_decode_motion(s, pred_x); | 1046 mx = h263_decode_motion(s, pred_x, s->f_code); |
1030 else { | 1047 else { |
1031 const int a= s->sprite_warping_accuracy; | 1048 const int a= s->sprite_warping_accuracy; |
1032 // int l = (1 << (s->f_code - 1)) * 32; | 1049 // int l = (1 << (s->f_code - 1)) * 32; |
1033 mx= RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | 1050 mx= RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); |
1034 // if (mx < -l) mx= -l; | 1051 // if (mx < -l) mx= -l; |
1038 return -1; | 1055 return -1; |
1039 | 1056 |
1040 if (s->umvplus_dec) | 1057 if (s->umvplus_dec) |
1041 my = h263p_decode_umotion(s, pred_y); | 1058 my = h263p_decode_umotion(s, pred_y); |
1042 else if(!s->mcsel) | 1059 else if(!s->mcsel) |
1043 my = h263_decode_motion(s, pred_y); | 1060 my = h263_decode_motion(s, pred_y, s->f_code); |
1044 else{ | 1061 else{ |
1045 const int a= s->sprite_warping_accuracy; | 1062 const int a= s->sprite_warping_accuracy; |
1046 // int l = (1 << (s->f_code - 1)) * 32; | 1063 // int l = (1 << (s->f_code - 1)) * 32; |
1047 my= RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | 1064 my= RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); |
1048 // if (my < -l) my= -l; | 1065 // if (my < -l) my= -l; |
1063 for(i=0;i<4;i++) { | 1080 for(i=0;i<4;i++) { |
1064 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); | 1081 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); |
1065 if (s->umvplus_dec) | 1082 if (s->umvplus_dec) |
1066 mx = h263p_decode_umotion(s, pred_x); | 1083 mx = h263p_decode_umotion(s, pred_x); |
1067 else | 1084 else |
1068 mx = h263_decode_motion(s, pred_x); | 1085 mx = h263_decode_motion(s, pred_x, s->f_code); |
1069 if (mx >= 0xffff) | 1086 if (mx >= 0xffff) |
1070 return -1; | 1087 return -1; |
1071 | 1088 |
1072 if (s->umvplus_dec) | 1089 if (s->umvplus_dec) |
1073 my = h263p_decode_umotion(s, pred_y); | 1090 my = h263p_decode_umotion(s, pred_y); |
1074 else | 1091 else |
1075 my = h263_decode_motion(s, pred_y); | 1092 my = h263_decode_motion(s, pred_y, s->f_code); |
1076 if (my >= 0xffff) | 1093 if (my >= 0xffff) |
1077 return -1; | 1094 return -1; |
1078 s->mv[0][i][0] = mx; | 1095 s->mv[0][i][0] = mx; |
1079 s->mv[0][i][1] = my; | 1096 s->mv[0][i][1] = my; |
1080 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) | 1097 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
1081 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 1098 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
1082 mot_val[0] = mx; | 1099 mot_val[0] = mx; |
1083 mot_val[1] = my; | 1100 mot_val[1] = my; |
1084 } | 1101 } |
1085 } | 1102 } |
1086 } else { | 1103 } else if(s->pict_type==B_TYPE) { |
1104 int modb1; // first bit of modb | |
1105 int modb2; // second bit of modb | |
1106 int mb_type; | |
1107 int time_pp; | |
1108 int time_pb; | |
1109 int xy; | |
1110 | |
1111 s->mb_intra = 0; //B-frames never contain intra blocks | |
1112 s->mcsel=0; // ... true gmc blocks | |
1113 | |
1114 if(s->mb_x==0){ | |
1115 s->last_mv[0][0][0]= | |
1116 s->last_mv[0][0][1]= | |
1117 s->last_mv[1][0][0]= | |
1118 s->last_mv[1][0][1]= 0; | |
1119 } | |
1120 | |
1121 /* if we skipped it in the future P Frame than skip it now too */ | |
1122 s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC | |
1123 | |
1124 if(s->mb_skiped){ | |
1125 /* skip mb */ | |
1126 for(i=0;i<6;i++) | |
1127 s->block_last_index[i] = -1; | |
1128 | |
1129 s->mv_dir = MV_DIR_FORWARD; | |
1130 s->mv_type = MV_TYPE_16X16; | |
1131 s->mv[0][0][0] = 0; | |
1132 s->mv[0][0][1] = 0; | |
1133 s->mv[1][0][0] = 0; | |
1134 s->mv[1][0][1] = 0; | |
1135 s->last_mv[0][0][0]= | |
1136 s->last_mv[0][0][1]= | |
1137 s->last_mv[1][0][0]= | |
1138 s->last_mv[1][0][1]= 0; | |
1139 s->mb_skiped = 1; | |
1140 return 0; | |
1141 } | |
1142 | |
1143 modb1= get_bits1(&s->gb); | |
1144 if(modb1==0){ | |
1145 modb2= get_bits1(&s->gb); | |
1146 mb_type= get_vlc(&s->gb, &mb_type_b_vlc); | |
1147 if(modb2==0) cbp= get_bits(&s->gb, 6); | |
1148 else cbp=0; | |
1149 if (mb_type && cbp) { | |
1150 if(get_bits1(&s->gb)){ | |
1151 s->qscale +=get_bits1(&s->gb)*4 - 2; | |
1152 if (s->qscale < 1) | |
1153 s->qscale = 1; | |
1154 else if (s->qscale > 31) | |
1155 s->qscale = 31; | |
1156 } | |
1157 } | |
1158 }else{ | |
1159 mb_type=4; //like 0 but no vectors coded | |
1160 cbp=0; | |
1161 } | |
1162 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here | |
1163 mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my | |
1164 switch(mb_type) | |
1165 { | |
1166 case 0: | |
1167 mx = h263_decode_motion(s, 0, 1); | |
1168 my = h263_decode_motion(s, 0, 1); | |
1169 case 4: | |
1170 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
1171 xy= (2*s->mb_width + 2)*(2*s->mb_y + 1) + 2*s->mb_x + 1; | |
1172 time_pp= s->last_non_b_time[0] - s->last_non_b_time[1]; | |
1173 time_pb= s->time - s->last_non_b_time[1]; | |
1174 //if(time_pp>3000 )printf("%d %d ", time_pp, time_pb); | |
1175 //FIXME 4MV | |
1176 //FIXME avoid divides | |
1177 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
1178 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
1179 s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] | |
1180 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
1181 s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] | |
1182 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
1183 /* s->mv[0][0][0] = | |
1184 s->mv[0][0][1] = | |
1185 s->mv[1][0][0] = | |
1186 s->mv[1][0][1] = 1000;*/ | |
1187 break; | |
1188 case 1: | |
1189 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
1190 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1191 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1192 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1193 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1194 | |
1195 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1196 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1197 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1198 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1199 break; | |
1200 case 2: | |
1201 s->mv_dir = MV_DIR_BACKWARD; | |
1202 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
1203 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
1204 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
1205 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
1206 break; | |
1207 case 3: | |
1208 s->mv_dir = MV_DIR_FORWARD; | |
1209 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
1210 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
1211 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
1212 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
1213 break; | |
1214 default: return -1; | |
1215 } | |
1216 } else { /* I-Frame */ | |
1217 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | |
1218 if (cbpc < 0) | |
1219 return -1; | |
1220 dquant = cbpc & 4; | |
1221 s->mb_intra = 1; | |
1222 intra: | |
1087 s->ac_pred = 0; | 1223 s->ac_pred = 0; |
1088 if (s->h263_pred || s->h263_aic) { | 1224 if (s->h263_pred || s->h263_aic) { |
1089 s->ac_pred = get_bits1(&s->gb); | 1225 s->ac_pred = get_bits1(&s->gb); |
1090 if (s->ac_pred && s->h263_aic) | 1226 if (s->ac_pred && s->h263_aic) |
1091 s->h263_aic_dir = get_bits1(&s->gb); | 1227 s->h263_aic_dir = get_bits1(&s->gb); |
1118 } | 1254 } |
1119 } | 1255 } |
1120 return 0; | 1256 return 0; |
1121 } | 1257 } |
1122 | 1258 |
1123 static int h263_decode_motion(MpegEncContext * s, int pred) | 1259 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
1124 { | 1260 { |
1125 int code, val, sign, shift, l, m; | 1261 int code, val, sign, shift, l, m; |
1126 | 1262 |
1127 code = get_vlc(&s->gb, &mv_vlc); | 1263 code = get_vlc(&s->gb, &mv_vlc); |
1128 if (code < 0) | 1264 if (code < 0) |
1129 return 0xffff; | 1265 return 0xffff; |
1130 | 1266 |
1131 if (code == 0) | 1267 if (code == 0) |
1132 return pred; | 1268 return pred; |
1133 sign = get_bits1(&s->gb); | 1269 sign = get_bits1(&s->gb); |
1134 shift = s->f_code - 1; | 1270 shift = f_code - 1; |
1135 val = (code - 1) << shift; | 1271 val = (code - 1) << shift; |
1136 if (shift > 0) | 1272 if (shift > 0) |
1137 val |= get_bits(&s->gb, shift); | 1273 val |= get_bits(&s->gb, shift); |
1138 val++; | 1274 val++; |
1139 if (sign) | 1275 if (sign) |
1140 val = -val; | 1276 val = -val; |
1141 val += pred; | 1277 val += pred; |
1142 | 1278 |
1143 /* modulo decoding */ | 1279 /* modulo decoding */ |
1144 if (!s->h263_long_vectors) { | 1280 if (!s->h263_long_vectors) { |
1145 l = (1 << (s->f_code - 1)) * 32; | 1281 l = (1 << (f_code - 1)) * 32; |
1146 m = 2 * l; | 1282 m = 2 * l; |
1147 if (val < -l) { | 1283 if (val < -l) { |
1148 val += m; | 1284 val += m; |
1149 } else if (val >= l) { | 1285 } else if (val >= l) { |
1150 val -= m; | 1286 val -= m; |
1575 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' | 1711 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' |
1576 w2= 1<<alpha; | 1712 w2= 1<<alpha; |
1577 h2= 1<<beta; | 1713 h2= 1<<beta; |
1578 | 1714 |
1579 // Note, the 4th point isnt used for GMC | 1715 // Note, the 4th point isnt used for GMC |
1580 /* | 1716 if(s->divx_version==500 && s->divx_build==413){ |
1581 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); | 1717 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; |
1582 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); | 1718 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; |
1583 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); | 1719 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; |
1584 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); | 1720 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; |
1585 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); | 1721 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; |
1586 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); | 1722 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; |
1587 */ | 1723 } else { |
1588 //FIXME DIVX5 vs. mpeg4 ? | 1724 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); |
1589 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | 1725 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); |
1590 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | 1726 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); |
1591 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | 1727 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); |
1592 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | 1728 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); |
1593 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | 1729 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); |
1594 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | 1730 } |
1595 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); | 1731 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); |
1596 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ | 1732 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ |
1597 | 1733 |
1598 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) | 1734 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) |
1599 // perhaps it should be reordered to be more readable ... | 1735 // perhaps it should be reordered to be more readable ... |
1713 s->real_sprite_warping_points=1; | 1849 s->real_sprite_warping_points=1; |
1714 } | 1850 } |
1715 else | 1851 else |
1716 s->real_sprite_warping_points= s->num_sprite_warping_points; | 1852 s->real_sprite_warping_points= s->num_sprite_warping_points; |
1717 | 1853 |
1718 //FIXME convert stuff if accurace != 3 | |
1719 } | 1854 } |
1720 | 1855 |
1721 /* decode mpeg4 VOP header */ | 1856 /* decode mpeg4 VOP header */ |
1722 int mpeg4_decode_picture_header(MpegEncContext * s) | 1857 int mpeg4_decode_picture_header(MpegEncContext * s) |
1723 { | 1858 { |
1739 if (state == 0) | 1874 if (state == 0) |
1740 return -1; | 1875 return -1; |
1741 } | 1876 } |
1742 //printf("startcode %X %d\n", startcode, get_bits_count(&s->gb)); | 1877 //printf("startcode %X %d\n", startcode, get_bits_count(&s->gb)); |
1743 if (startcode == 0x120) { // Video Object Layer | 1878 if (startcode == 0x120) { // Video Object Layer |
1744 int time_increment_resolution, width, height, vo_ver_id; | 1879 int width, height, vo_ver_id; |
1745 | 1880 |
1746 /* vol header */ | 1881 /* vol header */ |
1747 skip_bits(&s->gb, 1); /* random access */ | 1882 skip_bits(&s->gb, 1); /* random access */ |
1748 skip_bits(&s->gb, 8); /* vo_type */ | 1883 skip_bits(&s->gb, 8); /* vo_type */ |
1749 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ | 1884 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
1768 skip_bits(&s->gb, 4); //video_object_layer_shape_extension | 1903 skip_bits(&s->gb, 4); //video_object_layer_shape_extension |
1769 } | 1904 } |
1770 | 1905 |
1771 skip_bits1(&s->gb); /* marker */ | 1906 skip_bits1(&s->gb); /* marker */ |
1772 | 1907 |
1773 time_increment_resolution = get_bits(&s->gb, 16); | 1908 s->time_increment_resolution = get_bits(&s->gb, 16); |
1774 s->time_increment_bits = av_log2(time_increment_resolution - 1) + 1; | 1909 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; |
1775 if (s->time_increment_bits < 1) | 1910 if (s->time_increment_bits < 1) |
1776 s->time_increment_bits = 1; | 1911 s->time_increment_bits = 1; |
1777 skip_bits1(&s->gb); /* marker */ | 1912 skip_bits1(&s->gb); /* marker */ |
1778 | 1913 |
1779 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ | 1914 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
1897 } else if (startcode != 0x1b6) { //VOP | 2032 } else if (startcode != 0x1b6) { //VOP |
1898 goto redo; | 2033 goto redo; |
1899 } | 2034 } |
1900 | 2035 |
1901 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ | 2036 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ |
1902 if(s->pict_type == B_TYPE) | |
1903 { | |
1904 printf("B-VOP\n"); | |
1905 return -1; | |
1906 } | |
1907 | 2037 |
1908 /* XXX: parse time base */ | 2038 time_incr=0; |
1909 time_incr = 0; | |
1910 while (get_bits1(&s->gb) != 0) | 2039 while (get_bits1(&s->gb) != 0) |
1911 time_incr++; | 2040 time_incr++; |
1912 | 2041 |
1913 skip_bits1(&s->gb); /* marker */ | 2042 skip_bits1(&s->gb); /* marker */ |
1914 skip_bits(&s->gb, s->time_increment_bits); | 2043 s->time_increment= get_bits(&s->gb, s->time_increment_bits); |
2044 if(s->pict_type!=B_TYPE){ | |
2045 s->time_base+= time_incr; | |
2046 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
2047 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
2048 }else{ | |
2049 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
2050 s->time+= s->time_increment; | |
2051 } | |
1915 skip_bits1(&s->gb); /* marker */ | 2052 skip_bits1(&s->gb); /* marker */ |
1916 /* vop coded */ | 2053 /* vop coded */ |
1917 if (get_bits1(&s->gb) != 1) | 2054 if (get_bits1(&s->gb) != 1) |
1918 goto redo; | 2055 goto redo; |
1919 | 2056 //printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base, |
2057 //s->time, s->last_non_b_time[0], s->last_non_b_time[1]); | |
1920 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE | 2058 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE |
1921 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { | 2059 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
1922 /* rounding type for motion estimation */ | 2060 /* rounding type for motion estimation */ |
1923 s->no_rounding = get_bits1(&s->gb); | 2061 s->no_rounding = get_bits1(&s->gb); |
1924 } else { | 2062 } else { |
1965 movies */ | 2103 movies */ |
1966 s->qscale = get_bits(&s->gb, 5); | 2104 s->qscale = get_bits(&s->gb, 5); |
1967 | 2105 |
1968 if (s->pict_type != I_TYPE) { | 2106 if (s->pict_type != I_TYPE) { |
1969 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | 2107 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ |
2108 //printf("f-code %d\n", s->f_code); | |
1970 } | 2109 } |
1971 if (s->pict_type == B_TYPE) { | 2110 if (s->pict_type == B_TYPE) { |
1972 s->b_code = get_bits(&s->gb, 3); | 2111 s->b_code = get_bits(&s->gb, 3); |
2112 //printf("b-code %d\n", s->b_code); | |
1973 } | 2113 } |
1974 //printf("quant:%d fcode:%d\n", s->qscale, s->f_code); | 2114 //printf("quant:%d fcode:%d\n", s->qscale, s->f_code); |
1975 if(!s->scalability){ | 2115 if(!s->scalability){ |
1976 if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) { | 2116 if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) { |
1977 skip_bits1(&s->gb); // vop shape coding type | 2117 skip_bits1(&s->gb); // vop shape coding type |