Mercurial > libavcodec.hg
comparison cavs.c @ 3403:fc0eb7836ccb libavcodec
cleanup macroblock layer: merged decode of skipped MBs
with non-skipped
author | stefang |
---|---|
date | Mon, 03 Jul 2006 18:43:45 +0000 |
parents | 34d3e497e310 |
children | f5f2d05b54ac |
comparison
equal
deleted
inserted
replaced
3402:34d3e497e310 | 3403:fc0eb7836ccb |
---|---|
572 mvP->y = by; | 572 mvP->y = by; |
573 } | 573 } |
574 } | 574 } |
575 | 575 |
576 static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw, | 576 static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw, |
577 vector_t *pmv_bw, vector_t *col_mv) { | 577 vector_t *col_mv) { |
578 vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS; | |
578 int den = h->direct_den[col_mv->ref]; | 579 int den = h->direct_den[col_mv->ref]; |
579 int m = col_mv->x >> 31; | 580 int m = col_mv->x >> 31; |
580 | 581 |
581 pmv_fw->dist = h->dist[1]; | 582 pmv_fw->dist = h->dist[1]; |
582 pmv_bw->dist = h->dist[0]; | 583 pmv_bw->dist = h->dist[0]; |
860 } | 861 } |
861 } | 862 } |
862 return 1; | 863 return 1; |
863 } | 864 } |
864 | 865 |
865 static void decode_mb_i(AVSContext *h, int is_i_pic) { | 866 static void decode_mb_i(AVSContext *h) { |
866 GetBitContext *gb = &h->s.gb; | 867 GetBitContext *gb = &h->s.gb; |
867 int block, pred_mode_uv; | 868 int block, pred_mode_uv; |
868 uint8_t top[18]; | 869 uint8_t top[18]; |
869 uint8_t left[18]; | 870 uint8_t left[18]; |
870 uint8_t *d; | 871 uint8_t *d; |
872 | |
873 init_mb(h); | |
871 | 874 |
872 /* get intra prediction modes from stream */ | 875 /* get intra prediction modes from stream */ |
873 for(block=0;block<4;block++) { | 876 for(block=0;block<4;block++) { |
874 int nA,nB,predpred; | 877 int nA,nB,predpred; |
875 int pos = scan3x3[block]; | 878 int pos = scan3x3[block]; |
911 modify_pred(top_modifier_l, &h->pred_mode_Y[5] ); | 914 modify_pred(top_modifier_l, &h->pred_mode_Y[5] ); |
912 modify_pred(top_modifier_c, &pred_mode_uv ); | 915 modify_pred(top_modifier_c, &pred_mode_uv ); |
913 } | 916 } |
914 | 917 |
915 /* get coded block pattern */ | 918 /* get coded block pattern */ |
916 if(is_i_pic) | 919 if(h->pic_type == FF_I_TYPE) |
917 h->cbp = cbp_tab[get_ue_golomb(gb)][0]; | 920 h->cbp = cbp_tab[get_ue_golomb(gb)][0]; |
918 if(h->cbp && !h->qp_fixed) | 921 if(h->cbp && !h->qp_fixed) |
919 h->qp += get_se_golomb(gb); //qp_delta | 922 h->qp += get_se_golomb(gb); //qp_delta |
920 | 923 |
921 /* luma intra prediction interleaved with residual decode/transform/add */ | 924 /* luma intra prediction interleaved with residual decode/transform/add */ |
958 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); | 961 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); |
959 if(h->pic_type != FF_B_TYPE) | 962 if(h->pic_type != FF_B_TYPE) |
960 *h->col_type = I_8X8; | 963 *h->col_type = I_8X8; |
961 } | 964 } |
962 | 965 |
963 static void mb_skip_p(AVSContext *h) { | |
964 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0); | |
965 inter_pred(h); | |
966 store_mvs(h); | |
967 filter_mb(h,P_SKIP); | |
968 *h->col_type = P_SKIP; | |
969 } | |
970 | |
971 | |
972 static void mb_skip_b(AVSContext *h) { | |
973 int i; | |
974 | |
975 if(!(*h->col_type)) { | |
976 /* intra MB at co-location, do in-plane prediction */ | |
977 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1); | |
978 mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0); | |
979 } else { | |
980 /* direct prediction from co-located P MB, block-wise */ | |
981 for(i=0;i<4;i++) | |
982 mv_pred_direct(h,&h->mv[mv_scan[i]], | |
983 &h->mv[mv_scan[i]+MV_BWD_OFFS], | |
984 &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + i]); | |
985 } | |
986 } | |
987 | |
988 static void decode_mb_p(AVSContext *h, enum mb_t mb_type) { | 966 static void decode_mb_p(AVSContext *h, enum mb_t mb_type) { |
989 GetBitContext *gb = &h->s.gb; | 967 GetBitContext *gb = &h->s.gb; |
990 int ref[4]; | 968 int ref[4]; |
991 | 969 |
970 init_mb(h); | |
992 switch(mb_type) { | 971 switch(mb_type) { |
993 case P_SKIP: | 972 case P_SKIP: |
994 mb_skip_p(h); | 973 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0); |
995 return; | 974 break; |
996 case P_16X16: | 975 case P_16X16: |
997 ref[0] = h->ref_flag ? 0 : get_bits1(gb); | 976 ref[0] = h->ref_flag ? 0 : get_bits1(gb); |
998 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]); | 977 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]); |
999 break; | 978 break; |
1000 case P_16X8: | 979 case P_16X8: |
1019 mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]); | 998 mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]); |
1020 mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]); | 999 mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]); |
1021 } | 1000 } |
1022 inter_pred(h); | 1001 inter_pred(h); |
1023 store_mvs(h); | 1002 store_mvs(h); |
1024 decode_residual_inter(h); | 1003 if(mb_type != P_SKIP) |
1004 decode_residual_inter(h); | |
1025 filter_mb(h,mb_type); | 1005 filter_mb(h,mb_type); |
1026 *h->col_type = mb_type; | 1006 *h->col_type = mb_type; |
1027 } | 1007 } |
1028 | 1008 |
1029 static void decode_mb_b(AVSContext *h, enum mb_t mb_type) { | 1009 static void decode_mb_b(AVSContext *h, enum mb_t mb_type) { |
1030 int block; | 1010 int block; |
1031 enum sub_mb_t sub_type[4]; | 1011 enum sub_mb_t sub_type[4]; |
1032 int flags; | 1012 int flags; |
1013 | |
1014 init_mb(h); | |
1033 | 1015 |
1034 /* reset all MVs */ | 1016 /* reset all MVs */ |
1035 h->mv[MV_FWD_X0] = dir_mv; | 1017 h->mv[MV_FWD_X0] = dir_mv; |
1036 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); | 1018 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); |
1037 h->mv[MV_BWD_X0] = dir_mv; | 1019 h->mv[MV_BWD_X0] = dir_mv; |
1038 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); | 1020 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); |
1039 switch(mb_type) { | 1021 switch(mb_type) { |
1040 case B_SKIP: | 1022 case B_SKIP: |
1041 mb_skip_b(h); | |
1042 inter_pred(h); | |
1043 filter_mb(h,B_SKIP); | |
1044 return; | |
1045 case B_DIRECT: | 1023 case B_DIRECT: |
1046 mb_skip_b(h); | 1024 if(!(*h->col_type)) { |
1025 /* intra MB at co-location, do in-plane prediction */ | |
1026 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1); | |
1027 mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0); | |
1028 } else | |
1029 /* direct prediction from co-located P MB, block-wise */ | |
1030 for(block=0;block<4;block++) | |
1031 mv_pred_direct(h,&h->mv[mv_scan[block]], | |
1032 &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]); | |
1047 break; | 1033 break; |
1048 case B_FWD_16X16: | 1034 case B_FWD_16X16: |
1049 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); | 1035 mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); |
1050 break; | 1036 break; |
1051 case B_SYM_16X16: | 1037 case B_SYM_16X16: |
1068 mv_pred(h, mv_scan[block]+MV_BWD_OFFS, | 1054 mv_pred(h, mv_scan[block]+MV_BWD_OFFS, |
1069 mv_scan[block]-3+MV_BWD_OFFS, | 1055 mv_scan[block]-3+MV_BWD_OFFS, |
1070 MV_PRED_BSKIP, BLK_8X8, 0); | 1056 MV_PRED_BSKIP, BLK_8X8, 0); |
1071 } else | 1057 } else |
1072 mv_pred_direct(h,&h->mv[mv_scan[block]], | 1058 mv_pred_direct(h,&h->mv[mv_scan[block]], |
1073 &h->mv[mv_scan[block]+MV_BWD_OFFS], | |
1074 &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]); | 1059 &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]); |
1075 break; | 1060 break; |
1076 case B_SUB_FWD: | 1061 case B_SUB_FWD: |
1077 mv_pred(h, mv_scan[block], mv_scan[block]-3, | 1062 mv_pred(h, mv_scan[block], mv_scan[block]-3, |
1078 MV_PRED_MEDIAN, BLK_8X8, 1); | 1063 MV_PRED_MEDIAN, BLK_8X8, 1); |
1129 if(flags & BWD1) | 1114 if(flags & BWD1) |
1130 mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0); | 1115 mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0); |
1131 } | 1116 } |
1132 } | 1117 } |
1133 inter_pred(h); | 1118 inter_pred(h); |
1134 decode_residual_inter(h); | 1119 if(mb_type != B_SKIP) |
1120 decode_residual_inter(h); | |
1135 filter_mb(h,mb_type); | 1121 filter_mb(h,mb_type); |
1136 } | 1122 } |
1137 | 1123 |
1138 /***************************************************************************** | 1124 /***************************************************************************** |
1139 * | 1125 * |
1197 h->flags = 0; | 1183 h->flags = 0; |
1198 } | 1184 } |
1199 | 1185 |
1200 static int decode_pic(AVSContext *h) { | 1186 static int decode_pic(AVSContext *h) { |
1201 MpegEncContext *s = &h->s; | 1187 MpegEncContext *s = &h->s; |
1202 int i,skip_count; | 1188 int skip_count; |
1203 enum mb_t mb_type; | 1189 enum mb_t mb_type; |
1204 | 1190 |
1205 if (!s->context_initialized) { | 1191 if (!s->context_initialized) { |
1206 if (MPV_common_init(s) < 0) | 1192 if (MPV_common_init(s) < 0) |
1207 return -1; | 1193 return -1; |
1271 h->alpha_offset = h->beta_offset = 0; | 1257 h->alpha_offset = h->beta_offset = 0; |
1272 } | 1258 } |
1273 check_for_slice(h); | 1259 check_for_slice(h); |
1274 if(h->pic_type == FF_I_TYPE) { | 1260 if(h->pic_type == FF_I_TYPE) { |
1275 do { | 1261 do { |
1276 init_mb(h); | 1262 decode_mb_i(h); |
1277 decode_mb_i(h,1); | |
1278 } while(next_mb(h)); | 1263 } while(next_mb(h)); |
1279 } else if(h->pic_type == FF_P_TYPE) { | 1264 } else if(h->pic_type == FF_P_TYPE) { |
1280 do { | 1265 do { |
1281 if(h->skip_mode_flag) { | 1266 if(h->skip_mode_flag) { |
1282 skip_count = get_ue_golomb(&s->gb); | 1267 skip_count = get_ue_golomb(&s->gb); |
1283 for(i=0;i<skip_count;i++) { | 1268 while(skip_count--) { |
1284 init_mb(h); | 1269 decode_mb_p(h,P_SKIP); |
1285 mb_skip_p(h); | |
1286 if(!next_mb(h)) | 1270 if(!next_mb(h)) |
1287 goto done; | 1271 goto done; |
1288 } | 1272 } |
1289 mb_type = get_ue_golomb(&s->gb) + P_16X16; | 1273 mb_type = get_ue_golomb(&s->gb) + P_16X16; |
1290 } else | 1274 } else |
1291 mb_type = get_ue_golomb(&s->gb) + P_SKIP; | 1275 mb_type = get_ue_golomb(&s->gb) + P_SKIP; |
1292 init_mb(h); | |
1293 if(mb_type > P_8X8) { | 1276 if(mb_type > P_8X8) { |
1294 h->cbp = cbp_tab[mb_type - P_8X8 - 1][0]; | 1277 h->cbp = cbp_tab[mb_type - P_8X8 - 1][0]; |
1295 decode_mb_i(h,0); | 1278 decode_mb_i(h); |
1296 } else | 1279 } else |
1297 decode_mb_p(h,mb_type); | 1280 decode_mb_p(h,mb_type); |
1298 } while(next_mb(h)); | 1281 } while(next_mb(h)); |
1299 } else { /* FF_B_TYPE */ | 1282 } else { /* FF_B_TYPE */ |
1300 do { | 1283 do { |
1301 if(h->skip_mode_flag) { | 1284 if(h->skip_mode_flag) { |
1302 skip_count = get_ue_golomb(&s->gb); | 1285 skip_count = get_ue_golomb(&s->gb); |
1303 for(i=0;i<skip_count;i++) { | 1286 while(skip_count--) { |
1304 init_mb(h); | 1287 decode_mb_b(h,B_SKIP); |
1305 mb_skip_b(h); | |
1306 inter_pred(h); | |
1307 filter_mb(h,B_SKIP); | |
1308 if(!next_mb(h)) | 1288 if(!next_mb(h)) |
1309 goto done; | 1289 goto done; |
1310 } | 1290 } |
1311 mb_type = get_ue_golomb(&s->gb) + B_DIRECT; | 1291 mb_type = get_ue_golomb(&s->gb) + B_DIRECT; |
1312 } else | 1292 } else |
1313 mb_type = get_ue_golomb(&s->gb) + B_SKIP; | 1293 mb_type = get_ue_golomb(&s->gb) + B_SKIP; |
1314 init_mb(h); | 1294 init_mb(h); |
1315 if(mb_type > B_8X8) { | 1295 if(mb_type > B_8X8) { |
1316 h->cbp = cbp_tab[mb_type - B_8X8 - 1][0]; | 1296 h->cbp = cbp_tab[mb_type - B_8X8 - 1][0]; |
1317 decode_mb_i(h,0); | 1297 decode_mb_i(h); |
1318 } else | 1298 } else |
1319 decode_mb_b(h,mb_type); | 1299 decode_mb_b(h,mb_type); |
1320 } while(next_mb(h)); | 1300 } while(next_mb(h)); |
1321 } | 1301 } |
1322 done: | 1302 done: |