Mercurial > libavcodec.hg
comparison mpegvideo.c @ 481:29a7e17d19dd libavcodec
optimizing MPV_decode_mb
author | michaelni |
---|---|
date | Wed, 05 Jun 2002 23:43:56 +0000 |
parents | 055d9ac1584d |
children | 20108840b0e5 |
comparison
equal
deleted
inserted
replaced
480:a7cbee351b55 | 481:29a7e17d19dd |
---|---|
1108 | 1108 |
1109 /* add block[] to dest[] */ | 1109 /* add block[] to dest[] */ |
1110 static inline void add_dct(MpegEncContext *s, | 1110 static inline void add_dct(MpegEncContext *s, |
1111 DCTELEM *block, int i, UINT8 *dest, int line_size) | 1111 DCTELEM *block, int i, UINT8 *dest, int line_size) |
1112 { | 1112 { |
1113 /* skip dequant / idct if we are really late ;) */ | |
1114 if(s->hurry_up>1) return; | |
1115 | |
1116 if (s->block_last_index[i] >= 0) { | 1113 if (s->block_last_index[i] >= 0) { |
1117 if (!s->mpeg2) | 1114 ff_idct_add (dest, line_size, block); |
1118 if(s->encoding || (!s->h263_msmpeg4)) | 1115 } |
1119 s->dct_unquantize(s, block, i, s->qscale); | 1116 } |
1117 | |
1118 static inline void add_dequant_dct(MpegEncContext *s, | |
1119 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1120 { | |
1121 if (s->block_last_index[i] >= 0) { | |
1122 s->dct_unquantize(s, block, i, s->qscale); | |
1120 | 1123 |
1121 ff_idct_add (dest, line_size, block); | 1124 ff_idct_add (dest, line_size, block); |
1122 } | 1125 } |
1123 } | 1126 } |
1124 | 1127 |
1166 s->interlaced_dct : true if interlaced dct used (mpeg2) | 1169 s->interlaced_dct : true if interlaced dct used (mpeg2) |
1167 */ | 1170 */ |
1168 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | 1171 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
1169 { | 1172 { |
1170 int mb_x, mb_y; | 1173 int mb_x, mb_y; |
1171 int dct_linesize, dct_offset; | 1174 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
1172 op_pixels_func *op_pix; | |
1173 qpel_mc_func *op_qpix; | |
1174 | 1175 |
1175 mb_x = s->mb_x; | 1176 mb_x = s->mb_x; |
1176 mb_y = s->mb_y; | 1177 mb_y = s->mb_y; |
1177 | 1178 |
1178 #ifdef FF_POSTPROCESS | 1179 #ifdef FF_POSTPROCESS |
1184 #endif | 1185 #endif |
1185 | 1186 |
1186 /* update DC predictors for P macroblocks */ | 1187 /* update DC predictors for P macroblocks */ |
1187 if (!s->mb_intra) { | 1188 if (!s->mb_intra) { |
1188 if (s->h263_pred || s->h263_aic) { | 1189 if (s->h263_pred || s->h263_aic) { |
1189 if(s->mbintra_table[mb_x + mb_y*s->mb_width]) | 1190 if(s->mbintra_table[mb_xy]) |
1190 ff_clean_intra_table_entries(s); | 1191 ff_clean_intra_table_entries(s); |
1191 } else { | 1192 } else { |
1192 s->last_dc[0] = | 1193 s->last_dc[0] = |
1193 s->last_dc[1] = | 1194 s->last_dc[1] = |
1194 s->last_dc[2] = 128 << s->intra_dc_precision; | 1195 s->last_dc[2] = 128 << s->intra_dc_precision; |
1195 } | 1196 } |
1196 } | 1197 } |
1197 else if (s->h263_pred || s->h263_aic) | 1198 else if (s->h263_pred || s->h263_aic) |
1198 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | 1199 s->mbintra_table[mb_xy]=1; |
1199 | 1200 |
1200 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ | 1201 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
1201 if (s->out_format == FMT_H263) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here | 1202 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
1202 if(s->pict_type!=B_TYPE){ | 1203 int motion_x, motion_y; |
1203 int xy, wrap, motion_x, motion_y; | |
1204 | 1204 |
1205 wrap = 2 * s->mb_width + 2; | 1205 const int wrap = s->block_wrap[0]; |
1206 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; | 1206 const int xy = s->block_index[0]; |
1207 if (s->mb_intra) { | 1207 if (s->mb_intra) { |
1208 motion_x = 0; | 1208 motion_x = 0; |
1209 motion_y = 0; | 1209 motion_y = 0; |
1210 goto motion_init; | 1210 goto motion_init; |
1211 } else if (s->mv_type == MV_TYPE_16X16) { | 1211 } else if (s->mv_type == MV_TYPE_16X16) { |
1220 s->motion_val[xy + wrap][0] = motion_x; | 1220 s->motion_val[xy + wrap][0] = motion_x; |
1221 s->motion_val[xy + wrap][1] = motion_y; | 1221 s->motion_val[xy + wrap][1] = motion_y; |
1222 s->motion_val[xy + 1 + wrap][0] = motion_x; | 1222 s->motion_val[xy + 1 + wrap][0] = motion_x; |
1223 s->motion_val[xy + 1 + wrap][1] = motion_y; | 1223 s->motion_val[xy + 1 + wrap][1] = motion_y; |
1224 } | 1224 } |
1225 } | |
1226 } | 1225 } |
1227 | 1226 |
1228 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { | 1227 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
1229 UINT8 *dest_y, *dest_cb, *dest_cr; | 1228 UINT8 *dest_y, *dest_cb, *dest_cr; |
1230 UINT8 *mbskip_ptr; | 1229 int dct_linesize, dct_offset; |
1230 op_pixels_func *op_pix; | |
1231 qpel_mc_func *op_qpix; | |
1231 | 1232 |
1232 /* avoid copy if macroblock skipped in last frame too | 1233 /* avoid copy if macroblock skipped in last frame too |
1233 dont touch it for B-frames as they need the skip info from the next p-frame */ | 1234 dont touch it for B-frames as they need the skip info from the next p-frame */ |
1234 if (s->pict_type != B_TYPE) { | 1235 if (s->pict_type != B_TYPE) { |
1235 mbskip_ptr = &s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; | 1236 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; |
1236 if (s->mb_skiped) { | 1237 if (s->mb_skiped) { |
1237 s->mb_skiped = 0; | 1238 s->mb_skiped = 0; |
1238 /* if previous was skipped too, then nothing to do ! | 1239 /* if previous was skipped too, then nothing to do ! |
1239 skip only during decoding as we might trash the buffers during encoding a bit */ | 1240 skip only during decoding as we might trash the buffers during encoding a bit */ |
1240 if (*mbskip_ptr != 0 && !s->encoding) | 1241 if (*mbskip_ptr != 0 && !s->encoding) |
1256 dct_linesize = s->linesize; | 1257 dct_linesize = s->linesize; |
1257 dct_offset = s->linesize * 8; | 1258 dct_offset = s->linesize * 8; |
1258 } | 1259 } |
1259 | 1260 |
1260 if (!s->mb_intra) { | 1261 if (!s->mb_intra) { |
1261 const int xy= s->mb_y * s->mb_width + s->mb_x; | |
1262 /* motion handling */ | 1262 /* motion handling */ |
1263 /* decoding or more than one mb_type (MC was allready done otherwise) */ | 1263 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
1264 if((!s->encoding) || (s->mb_type[xy]&(s->mb_type[xy]-1))){ | 1264 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
1265 if ((!s->no_rounding) || s->pict_type==B_TYPE){ | 1265 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
1266 op_pix = put_pixels_tab; | 1266 op_pix = put_pixels_tab; |
1267 op_qpix= qpel_mc_rnd_tab; | 1267 op_qpix= qpel_mc_rnd_tab; |
1268 }else{ | 1268 }else{ |
1269 op_pix = put_no_rnd_pixels_tab; | 1269 op_pix = put_no_rnd_pixels_tab; |
1280 if (s->mv_dir & MV_DIR_BACKWARD) { | 1280 if (s->mv_dir & MV_DIR_BACKWARD) { |
1281 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | 1281 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); |
1282 } | 1282 } |
1283 } | 1283 } |
1284 | 1284 |
1285 /* skip dequant / idct if we are really late ;) */ | |
1286 if(s->hurry_up>1) goto the_end; | |
1287 | |
1285 /* add dct residue */ | 1288 /* add dct residue */ |
1286 add_dct(s, block[0], 0, dest_y, dct_linesize); | 1289 if(!s->mpeg2 && (s->encoding || (!s->h263_msmpeg4))){ |
1287 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | 1290 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
1288 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | 1291 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); |
1289 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | 1292 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); |
1290 | 1293 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); |
1291 add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); | 1294 |
1292 add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | 1295 add_dequant_dct(s, block[4], 4, dest_cb, s->linesize >> 1); |
1296 add_dequant_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
1297 } else { | |
1298 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
1299 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1300 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1301 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
1302 | |
1303 add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); | |
1304 add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
1305 } | |
1293 } else { | 1306 } else { |
1294 /* dct only in intra block */ | 1307 /* dct only in intra block */ |
1295 put_dct(s, block[0], 0, dest_y, dct_linesize); | 1308 put_dct(s, block[0], 0, dest_y, dct_linesize); |
1296 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | 1309 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); |
1297 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | 1310 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); |