Mercurial > libavcodec.hg
comparison h264.c @ 2396:7e360068b653 libavcodec
implement B_DIRECT and B_SKIP macroblock types.
fix reference list sorting for B-frames.
fix mv caching for mixed list B-blocks.
author | lorenm |
---|---|
date | Wed, 29 Dec 2004 04:17:52 +0000 |
parents | 81516be6d0e4 |
children | 46898a9fd6dc |
comparison
equal
deleted
inserted
replaced
2395:81516be6d0e4 | 2396:7e360068b653 |
---|---|
268 int slice_beta_offset; | 268 int slice_beta_offset; |
269 | 269 |
270 int redundant_pic_count; | 270 int redundant_pic_count; |
271 | 271 |
272 int direct_spatial_mv_pred; | 272 int direct_spatial_mv_pred; |
273 int dist_scale_factor[16]; | |
273 | 274 |
274 /** | 275 /** |
275 * num_ref_idx_l0/1_active_minus1 + 1 | 276 * num_ref_idx_l0/1_active_minus1 + 1 |
276 */ | 277 */ |
277 int ref_count[2];// FIXME split for AFF | 278 int ref_count[2];// FIXME split for AFF |
312 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ | 313 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ |
313 uint8_t *chroma_pred_mode_table; | 314 uint8_t *chroma_pred_mode_table; |
314 int last_qscale_diff; | 315 int last_qscale_diff; |
315 int16_t (*mvd_table[2])[2]; | 316 int16_t (*mvd_table[2])[2]; |
316 int16_t mvd_cache[2][5*8][2]; | 317 int16_t mvd_cache[2][5*8][2]; |
318 uint8_t *direct_table; | |
319 uint8_t direct_cache[5*8]; | |
317 | 320 |
318 }H264Context; | 321 }H264Context; |
319 | 322 |
320 static VLC coeff_token_vlc[4]; | 323 static VLC coeff_token_vlc[4]; |
321 static VLC chroma_dc_coeff_token_vlc; | 324 static VLC chroma_dc_coeff_token_vlc; |
560 h->non_zero_count_cache[0+8*2]= | 563 h->non_zero_count_cache[0+8*2]= |
561 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; | 564 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
562 } | 565 } |
563 | 566 |
564 #if 1 | 567 #if 1 |
565 if(IS_INTER(mb_type)){ | 568 //FIXME direct mb can skip much of this |
569 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ | |
566 int list; | 570 int list; |
567 for(list=0; list<2; list++){ | 571 for(list=0; list<2; list++){ |
568 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){ | 572 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list) && !IS_DIRECT(mb_type)){ |
569 /*if(!h->mv_cache_clean[list]){ | 573 /*if(!h->mv_cache_clean[list]){ |
570 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? | 574 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? |
571 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); | 575 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); |
572 h->mv_cache_clean[list]= 1; | 576 h->mv_cache_clean[list]= 1; |
573 }*/ | 577 }*/ |
574 continue; //FIXME direct mode ... | 578 continue; |
575 } | 579 } |
576 h->mv_cache_clean[list]= 0; | 580 h->mv_cache_clean[list]= 0; |
577 | 581 |
578 if(IS_INTER(topleft_type)){ | 582 if(IS_INTER(topleft_type)){ |
579 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; | 583 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; |
694 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= | 698 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= |
695 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= | 699 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= |
696 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) | 700 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) |
697 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= | 701 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= |
698 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; | 702 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; |
699 } | 703 |
700 } | 704 if(h->slice_type == B_TYPE){ |
701 //FIXME | 705 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); |
706 | |
707 if(IS_DIRECT(top_type)){ | |
708 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; | |
709 }else if(IS_8X8(top_type)){ | |
710 int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; | |
711 h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; | |
712 h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; | |
713 }else{ | |
714 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0; | |
715 } | |
716 | |
717 //FIXME interlacing | |
718 if(IS_DIRECT(left_type[0])){ | |
719 h->direct_cache[scan8[0] - 1 + 0*8]= | |
720 h->direct_cache[scan8[0] - 1 + 2*8]= 1; | |
721 }else if(IS_8X8(left_type[0])){ | |
722 int b8_xy = h->mb2b8_xy[left_xy[0]] + 1; | |
723 h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[b8_xy]; | |
724 h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[b8_xy + h->b8_stride]; | |
725 }else{ | |
726 h->direct_cache[scan8[0] - 1 + 0*8]= | |
727 h->direct_cache[scan8[0] - 1 + 2*8]= 0; | |
728 } | |
729 } | |
730 } | |
731 } | |
702 } | 732 } |
703 #endif | 733 #endif |
704 } | 734 } |
705 | 735 |
706 static inline void write_back_intra_pred_mode(H264Context *h){ | 736 static inline void write_back_intra_pred_mode(H264Context *h){ |
995 pred_motion(h, 0, 4, 0, 0, mx, my); | 1025 pred_motion(h, 0, 4, 0, 0, mx, my); |
996 | 1026 |
997 return; | 1027 return; |
998 } | 1028 } |
999 | 1029 |
1030 static inline void direct_dist_scale_factor(H264Context * const h){ | |
1031 const int poc = h->s.current_picture_ptr->poc; | |
1032 const int poc1 = h->ref_list[1][0].poc; | |
1033 int i; | |
1034 for(i=0; i<h->ref_count[0]; i++){ | |
1035 int poc0 = h->ref_list[0][i].poc; | |
1036 int td = clip(poc1 - poc0, -128, 127); | |
1037 if(td == 0 /* FIXME || pic0 is a long-term ref */){ | |
1038 h->dist_scale_factor[i] = 256; | |
1039 }else{ | |
1040 int tb = clip(poc - poc0, -128, 127); | |
1041 int tx = (16384 + (ABS(td) >> 1)) / td; | |
1042 h->dist_scale_factor[i] = clip((tb*tx + 32) >> 6, -1024, 1023); | |
1043 } | |
1044 } | |
1045 } | |
1046 | |
1047 static inline void pred_direct_motion(H264Context * const h, int *mb_type){ | |
1048 MpegEncContext * const s = &h->s; | |
1049 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |
1050 const int b8_xy = 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
1051 const int b4_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
1052 const int mb_type_col = h->ref_list[1][0].mb_type[mb_xy]; | |
1053 const int16_t (*l1mv0)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[0][b4_xy]; | |
1054 const int8_t *l1ref0 = &h->ref_list[1][0].ref_index[0][b8_xy]; | |
1055 const int is_b8x8 = IS_8X8(*mb_type); | |
1056 int sub_mb_type; | |
1057 int i8, i4; | |
1058 | |
1059 if(IS_8X8(mb_type_col) && !h->sps.direct_8x8_inference_flag){ | |
1060 /* FIXME save sub mb types from previous frames (or derive from MVs) | |
1061 * so we know exactly what block size to use */ | |
1062 sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | |
1063 *mb_type = MB_TYPE_8x8; | |
1064 }else if(!is_b8x8 && (IS_16X16(mb_type_col) || IS_INTRA(mb_type_col))){ | |
1065 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
1066 *mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */ | |
1067 }else{ | |
1068 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
1069 *mb_type = MB_TYPE_8x8; | |
1070 } | |
1071 if(!is_b8x8) | |
1072 *mb_type |= MB_TYPE_DIRECT2; | |
1073 | |
1074 if(h->direct_spatial_mv_pred){ | |
1075 int ref[2]; | |
1076 int mv[2][2]; | |
1077 int list; | |
1078 | |
1079 /* ref = min(neighbors) */ | |
1080 for(list=0; list<2; list++){ | |
1081 int refa = h->ref_cache[list][scan8[0] - 1]; | |
1082 int refb = h->ref_cache[list][scan8[0] - 8]; | |
1083 int refc = h->ref_cache[list][scan8[0] - 8 + 4]; | |
1084 if(refc == -2) | |
1085 refc = h->ref_cache[list][scan8[0] - 8 - 1]; | |
1086 ref[list] = refa; | |
1087 if(ref[list] < 0 || (refb < ref[list] && refb >= 0)) | |
1088 ref[list] = refb; | |
1089 if(ref[list] < 0 || (refc < ref[list] && refc >= 0)) | |
1090 ref[list] = refc; | |
1091 if(ref[list] < 0) | |
1092 ref[list] = -1; | |
1093 } | |
1094 | |
1095 if(ref[0] < 0 && ref[1] < 0){ | |
1096 ref[0] = ref[1] = 0; | |
1097 mv[0][0] = mv[0][1] = | |
1098 mv[1][0] = mv[1][1] = 0; | |
1099 }else{ | |
1100 for(list=0; list<2; list++){ | |
1101 if(ref[list] >= 0) | |
1102 pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]); | |
1103 else | |
1104 mv[list][0] = mv[list][1] = 0; | |
1105 } | |
1106 } | |
1107 | |
1108 if(ref[1] < 0){ | |
1109 *mb_type &= ~MB_TYPE_P0L1; | |
1110 sub_mb_type &= ~MB_TYPE_P0L1; | |
1111 }else if(ref[0] < 0){ | |
1112 *mb_type &= ~MB_TYPE_P0L0; | |
1113 sub_mb_type &= ~MB_TYPE_P0L0; | |
1114 } | |
1115 | |
1116 if(IS_16X16(*mb_type)){ | |
1117 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref[0], 1); | |
1118 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, ref[1], 1); | |
1119 if(!IS_INTRA(mb_type_col) && l1ref0[0] == 0 && | |
1120 ABS(l1mv0[0][0]) <= 1 && ABS(l1mv0[0][1]) <= 1){ | |
1121 if(ref[0] > 0) | |
1122 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1123 else | |
1124 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
1125 if(ref[1] > 0) | |
1126 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1127 else | |
1128 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
1129 }else{ | |
1130 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1131 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1132 } | |
1133 }else{ | |
1134 for(i8=0; i8<4; i8++){ | |
1135 const int x8 = i8&1; | |
1136 const int y8 = i8>>1; | |
1137 | |
1138 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
1139 continue; | |
1140 h->sub_mb_type[i8] = sub_mb_type; | |
1141 | |
1142 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1143 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1144 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref[0], 1); | |
1145 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, ref[1], 1); | |
1146 | |
1147 /* col_zero_flag */ | |
1148 if(!IS_INTRA(mb_type_col) && l1ref0[x8 + y8*h->b8_stride] == 0){ | |
1149 for(i4=0; i4<4; i4++){ | |
1150 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
1151 if(ABS(mv_col[0]) <= 1 && ABS(mv_col[1]) <= 1){ | |
1152 if(ref[0] == 0) | |
1153 *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0; | |
1154 if(ref[1] == 0) | |
1155 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0; | |
1156 } | |
1157 } | |
1158 } | |
1159 } | |
1160 } | |
1161 }else{ /* direct temporal mv pred */ | |
1162 /* FIXME assumes that L1ref0 used the same ref lists as current frame */ | |
1163 if(IS_16X16(*mb_type)){ | |
1164 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
1165 if(IS_INTRA(mb_type_col)){ | |
1166 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
1167 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
1168 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
1169 }else{ | |
1170 const int ref0 = l1ref0[0]; | |
1171 const int dist_scale_factor = h->dist_scale_factor[ref0]; | |
1172 const int16_t *mv_col = l1mv0[0]; | |
1173 int mv_l0[2]; | |
1174 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
1175 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
1176 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref0, 1); | |
1177 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0],mv_l0[1]), 4); | |
1178 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]), 4); | |
1179 } | |
1180 }else{ | |
1181 for(i8=0; i8<4; i8++){ | |
1182 const int x8 = i8&1; | |
1183 const int y8 = i8>>1; | |
1184 int ref0, dist_scale_factor; | |
1185 | |
1186 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
1187 continue; | |
1188 h->sub_mb_type[i8] = sub_mb_type; | |
1189 if(IS_INTRA(mb_type_col)){ | |
1190 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1191 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1192 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); | |
1193 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); | |
1194 continue; | |
1195 } | |
1196 | |
1197 ref0 = l1ref0[x8 + y8*h->b8_stride]; | |
1198 dist_scale_factor = h->dist_scale_factor[ref0]; | |
1199 | |
1200 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); | |
1201 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1202 for(i4=0; i4<4; i4++){ | |
1203 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
1204 int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]]; | |
1205 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
1206 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
1207 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = | |
1208 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]); | |
1209 } | |
1210 } | |
1211 } | |
1212 } | |
1213 } | |
1214 | |
1000 static inline void write_back_motion(H264Context *h, int mb_type){ | 1215 static inline void write_back_motion(H264Context *h, int mb_type){ |
1001 MpegEncContext * const s = &h->s; | 1216 MpegEncContext * const s = &h->s; |
1002 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | 1217 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; |
1003 const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; | 1218 const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; |
1004 int list; | 1219 int list; |
1020 } | 1235 } |
1021 for(y=0; y<2; y++){ | 1236 for(y=0; y<2; y++){ |
1022 *(uint16_t*)&s->current_picture.ref_index[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101; | 1237 *(uint16_t*)&s->current_picture.ref_index[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101; |
1023 } | 1238 } |
1024 } | 1239 } |
1025 continue; //FIXME direct mode ... | 1240 continue; |
1026 } | 1241 } |
1027 | 1242 |
1028 for(y=0; y<4; y++){ | 1243 for(y=0; y<4; y++){ |
1029 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y]; | 1244 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y]; |
1030 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y]; | 1245 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y]; |
1036 } | 1251 } |
1037 } | 1252 } |
1038 for(y=0; y<2; y++){ | 1253 for(y=0; y<2; y++){ |
1039 s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y]; | 1254 s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y]; |
1040 s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y]; | 1255 s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y]; |
1256 } | |
1257 } | |
1258 | |
1259 if(h->slice_type == B_TYPE && h->pps.cabac){ | |
1260 if(IS_8X8(mb_type)){ | |
1261 h->direct_table[b8_xy+1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0; | |
1262 h->direct_table[b8_xy+0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0; | |
1263 h->direct_table[b8_xy+1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; | |
1041 } | 1264 } |
1042 } | 1265 } |
1043 } | 1266 } |
1044 | 1267 |
1045 /** | 1268 /** |
2163 av_freep(&h->intra4x4_pred_mode); | 2386 av_freep(&h->intra4x4_pred_mode); |
2164 av_freep(&h->chroma_pred_mode_table); | 2387 av_freep(&h->chroma_pred_mode_table); |
2165 av_freep(&h->cbp_table); | 2388 av_freep(&h->cbp_table); |
2166 av_freep(&h->mvd_table[0]); | 2389 av_freep(&h->mvd_table[0]); |
2167 av_freep(&h->mvd_table[1]); | 2390 av_freep(&h->mvd_table[1]); |
2391 av_freep(&h->direct_table); | |
2168 av_freep(&h->non_zero_count); | 2392 av_freep(&h->non_zero_count); |
2169 av_freep(&h->slice_table_base); | 2393 av_freep(&h->slice_table_base); |
2170 av_freep(&h->top_border); | 2394 av_freep(&h->top_border); |
2171 h->slice_table= NULL; | 2395 h->slice_table= NULL; |
2172 | 2396 |
2192 | 2416 |
2193 if( h->pps.cabac ) { | 2417 if( h->pps.cabac ) { |
2194 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) | 2418 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) |
2195 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); | 2419 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); |
2196 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); | 2420 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); |
2421 CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); | |
2197 } | 2422 } |
2198 | 2423 |
2199 memset(h->slice_table_base, -1, big_mb_num * sizeof(uint8_t)); | 2424 memset(h->slice_table_base, -1, big_mb_num * sizeof(uint8_t)); |
2200 h->slice_table= h->slice_table_base + s->mb_stride + 1; | 2425 h->slice_table= h->slice_table_base + s->mb_stride + 1; |
2201 | 2426 |
2539 | 2764 |
2540 for(list=0; list<2; list++){ | 2765 for(list=0; list<2; list++){ |
2541 int index=0; | 2766 int index=0; |
2542 | 2767 |
2543 for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++){ | 2768 for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++){ |
2544 const int i2= list ? h->short_ref_count - i - 1 : i; | 2769 const int i2= list ? i : h->short_ref_count - i - 1; |
2545 const int poc= sorted_short_ref[i2].poc; | 2770 const int poc= sorted_short_ref[i2].poc; |
2546 | 2771 |
2547 if(sorted_short_ref[i2].reference != 3) continue; //FIXME refernce field shit | 2772 if(sorted_short_ref[i2].reference != 3) continue; //FIXME refernce field shit |
2548 | 2773 |
2549 if((list==1 && poc > current_poc) || (list==0 && poc < current_poc)){ | 2774 if((list==1 && poc > current_poc) || (list==0 && poc < current_poc)){ |
2661 } | 2886 } |
2662 } | 2887 } |
2663 | 2888 |
2664 if(h->slice_type!=B_TYPE) break; | 2889 if(h->slice_type!=B_TYPE) break; |
2665 } | 2890 } |
2891 | |
2892 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) | |
2893 direct_dist_scale_factor(h); | |
2666 return 0; | 2894 return 0; |
2667 } | 2895 } |
2668 | 2896 |
2669 static int pred_weight_table(H264Context *h){ | 2897 static int pred_weight_table(H264Context *h){ |
2670 MpegEncContext * const s = &h->s; | 2898 MpegEncContext * const s = &h->s; |
3367 } | 3595 } |
3368 return 0; | 3596 return 0; |
3369 } | 3597 } |
3370 | 3598 |
3371 /** | 3599 /** |
3600 * decodes a P_SKIP or B_SKIP macroblock | |
3601 */ | |
3602 static void decode_mb_skip(H264Context *h){ | |
3603 MpegEncContext * const s = &h->s; | |
3604 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | |
3605 int mb_type; | |
3606 | |
3607 memset(h->non_zero_count[mb_xy], 0, 16); | |
3608 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui | |
3609 | |
3610 if( h->slice_type == B_TYPE ) | |
3611 { | |
3612 // just for fill_caches. pred_direct_motion will set the real mb_type | |
3613 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; | |
3614 //FIXME mbaff | |
3615 | |
3616 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
3617 pred_direct_motion(h, &mb_type); | |
3618 if(h->pps.cabac){ | |
3619 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
3620 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
3621 } | |
3622 } | |
3623 else | |
3624 { | |
3625 int mx, my; | |
3626 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; | |
3627 | |
3628 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
3629 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
3630 } | |
3631 if(h->mb_field_decoding_flag) | |
3632 mb_type|= MB_TYPE_INTERLACED; | |
3633 | |
3634 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
3635 pred_pskip_motion(h, &mx, &my); | |
3636 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
3637 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | |
3638 if(h->pps.cabac) | |
3639 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
3640 } | |
3641 | |
3642 write_back_motion(h, mb_type); | |
3643 s->current_picture.mb_type[mb_xy]= mb_type|MB_TYPE_SKIP; | |
3644 s->current_picture.qscale_table[mb_xy]= s->qscale; | |
3645 h->slice_table[ mb_xy ]= h->slice_num; | |
3646 h->prev_mb_skiped= 1; | |
3647 } | |
3648 | |
3649 /** | |
3372 * decodes a macroblock | 3650 * decodes a macroblock |
3373 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed | 3651 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed |
3374 */ | 3652 */ |
3375 static int decode_mb_cavlc(H264Context *h){ | 3653 static int decode_mb_cavlc(H264Context *h){ |
3376 MpegEncContext * const s = &h->s; | 3654 MpegEncContext * const s = &h->s; |
3385 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ | 3663 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ |
3386 if(s->mb_skip_run==-1) | 3664 if(s->mb_skip_run==-1) |
3387 s->mb_skip_run= get_ue_golomb(&s->gb); | 3665 s->mb_skip_run= get_ue_golomb(&s->gb); |
3388 | 3666 |
3389 if (s->mb_skip_run--) { | 3667 if (s->mb_skip_run--) { |
3390 int mx, my; | 3668 decode_mb_skip(h); |
3391 /* skip mb */ | |
3392 //FIXME b frame | |
3393 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0; | |
3394 | |
3395 memset(h->non_zero_count[mb_xy], 0, 16); | |
3396 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui | |
3397 | |
3398 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
3399 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
3400 } | |
3401 | |
3402 if(h->mb_field_decoding_flag) | |
3403 mb_type|= MB_TYPE_INTERLACED; | |
3404 | |
3405 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
3406 pred_pskip_motion(h, &mx, &my); | |
3407 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
3408 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | |
3409 write_back_motion(h, mb_type); | |
3410 | |
3411 s->current_picture.mb_type[mb_xy]= mb_type; //FIXME SKIP type | |
3412 s->current_picture.qscale_table[mb_xy]= s->qscale; | |
3413 h->slice_table[ mb_xy ]= h->slice_num; | |
3414 | |
3415 h->prev_mb_skiped= 1; | |
3416 return 0; | 3669 return 0; |
3417 } | 3670 } |
3418 } | 3671 } |
3419 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ | 3672 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ |
3420 if((s->mb_y&1)==0) | 3673 if((s->mb_y&1)==0) |
3547 return -1; | 3800 return -1; |
3548 } | 3801 } |
3549 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | 3802 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
3550 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; | 3803 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
3551 } | 3804 } |
3805 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) | |
3806 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) | |
3807 pred_direct_motion(h, &mb_type); | |
3552 }else{ | 3808 }else{ |
3553 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? | 3809 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? |
3554 for(i=0; i<4; i++){ | 3810 for(i=0; i<4; i++){ |
3555 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | 3811 h->sub_mb_type[i]= get_ue_golomb(&s->gb); |
3556 if(h->sub_mb_type[i] >=4){ | 3812 if(h->sub_mb_type[i] >=4){ |
3564 | 3820 |
3565 for(list=0; list<2; list++){ | 3821 for(list=0; list<2; list++){ |
3566 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | 3822 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; |
3567 if(ref_count == 0) continue; | 3823 if(ref_count == 0) continue; |
3568 for(i=0; i<4; i++){ | 3824 for(i=0; i<4; i++){ |
3569 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | 3825 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
3826 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
3570 ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? | 3827 ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? |
3571 }else{ | 3828 }else{ |
3572 //FIXME | 3829 //FIXME |
3573 ref[list][i] = -1; | 3830 ref[list][i] = -1; |
3574 } | 3831 } |
3578 for(list=0; list<2; list++){ | 3835 for(list=0; list<2; list++){ |
3579 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | 3836 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; |
3580 if(ref_count == 0) continue; | 3837 if(ref_count == 0) continue; |
3581 | 3838 |
3582 for(i=0; i<4; i++){ | 3839 for(i=0; i<4; i++){ |
3840 if(IS_DIRECT(h->sub_mb_type[i])) continue; | |
3583 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= | 3841 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= |
3584 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; | 3842 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; |
3585 | 3843 |
3586 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | 3844 if(IS_DIR(h->sub_mb_type[i], 0, list)){ |
3587 const int sub_mb_type= h->sub_mb_type[i]; | 3845 const int sub_mb_type= h->sub_mb_type[i]; |
3588 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; | 3846 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; |
3589 for(j=0; j<sub_partition_count[i]; j++){ | 3847 for(j=0; j<sub_partition_count[i]; j++){ |
3590 int mx, my; | 3848 int mx, my; |
3591 const int index= 4*i + block_width*j; | 3849 const int index= 4*i + block_width*j; |
3617 p[0] = p[1]= | 3875 p[0] = p[1]= |
3618 p[8] = p[9]= 0; | 3876 p[8] = p[9]= 0; |
3619 } | 3877 } |
3620 } | 3878 } |
3621 } | 3879 } |
3622 }else if(!IS_DIRECT(mb_type)){ | 3880 }else if(IS_DIRECT(mb_type)){ |
3881 pred_direct_motion(h, &mb_type); | |
3882 s->current_picture.mb_type[mb_xy]= mb_type; | |
3883 }else{ | |
3623 int list, mx, my, i; | 3884 int list, mx, my, i; |
3624 //FIXME we should set ref_idx_l? to 0 if we use that later ... | 3885 //FIXME we should set ref_idx_l? to 0 if we use that later ... |
3625 if(IS_16X16(mb_type)){ | 3886 if(IS_16X16(mb_type)){ |
3626 for(list=0; list<2; list++){ | 3887 for(list=0; list<2; list++){ |
3627 if(h->ref_count[list]>0){ | 3888 if(h->ref_count[list]>0){ |
3647 if(h->ref_count[list]>0){ | 3908 if(h->ref_count[list]>0){ |
3648 for(i=0; i<2; i++){ | 3909 for(i=0; i<2; i++){ |
3649 if(IS_DIR(mb_type, i, list)){ | 3910 if(IS_DIR(mb_type, i, list)){ |
3650 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | 3911 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); |
3651 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); | 3912 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); |
3652 } | 3913 }else // needed only for mixed refs (e.g. B_L0_L1_16x8) |
3914 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | |
3653 } | 3915 } |
3654 } | 3916 } |
3655 } | 3917 } |
3656 for(list=0; list<2; list++){ | 3918 for(list=0; list<2; list++){ |
3657 for(i=0; i<2; i++){ | 3919 for(i=0; i<2; i++){ |
3660 mx += get_se_golomb(&s->gb); | 3922 mx += get_se_golomb(&s->gb); |
3661 my += get_se_golomb(&s->gb); | 3923 my += get_se_golomb(&s->gb); |
3662 tprintf("final mv:%d %d\n", mx, my); | 3924 tprintf("final mv:%d %d\n", mx, my); |
3663 | 3925 |
3664 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); | 3926 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
3665 } | 3927 }else |
3928 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
3666 } | 3929 } |
3667 } | 3930 } |
3668 }else{ | 3931 }else{ |
3669 assert(IS_8X16(mb_type)); | 3932 assert(IS_8X16(mb_type)); |
3670 for(list=0; list<2; list++){ | 3933 for(list=0; list<2; list++){ |
3671 if(h->ref_count[list]>0){ | 3934 if(h->ref_count[list]>0){ |
3672 for(i=0; i<2; i++){ | 3935 for(i=0; i<2; i++){ |
3673 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | 3936 if(IS_DIR(mb_type, i, list)){ //FIXME optimize |
3674 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | 3937 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); |
3675 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); | 3938 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); |
3676 } | 3939 }else // needed only for mixed refs |
3940 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
3677 } | 3941 } |
3678 } | 3942 } |
3679 } | 3943 } |
3680 for(list=0; list<2; list++){ | 3944 for(list=0; list<2; list++){ |
3681 for(i=0; i<2; i++){ | 3945 for(i=0; i<2; i++){ |
3684 mx += get_se_golomb(&s->gb); | 3948 mx += get_se_golomb(&s->gb); |
3685 my += get_se_golomb(&s->gb); | 3949 my += get_se_golomb(&s->gb); |
3686 tprintf("final mv:%d %d\n", mx, my); | 3950 tprintf("final mv:%d %d\n", mx, my); |
3687 | 3951 |
3688 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); | 3952 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
3689 } | 3953 }else |
3954 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
3690 } | 3955 } |
3691 } | 3956 } |
3692 } | 3957 } |
3693 } | 3958 } |
3694 | 3959 |
4107 int refa = h->ref_cache[list][scan8[n] - 1]; | 4372 int refa = h->ref_cache[list][scan8[n] - 1]; |
4108 int refb = h->ref_cache[list][scan8[n] - 8]; | 4373 int refb = h->ref_cache[list][scan8[n] - 8]; |
4109 int ref = 0; | 4374 int ref = 0; |
4110 int ctx = 0; | 4375 int ctx = 0; |
4111 | 4376 |
4112 if( refa > 0 ) | 4377 if( h->slice_type == B_TYPE) { |
4113 ctx++; | 4378 if( refa > 0 && !h->direct_cache[scan8[n] - 1] ) |
4114 if( refb > 0 ) | 4379 ctx++; |
4115 ctx += 2; | 4380 if( refb > 0 && !h->direct_cache[scan8[n] - 8] ) |
4381 ctx += 2; | |
4382 } else { | |
4383 if( refa > 0 ) | |
4384 ctx++; | |
4385 if( refb > 0 ) | |
4386 ctx += 2; | |
4387 } | |
4116 | 4388 |
4117 while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { | 4389 while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { |
4118 ref++; | 4390 ref++; |
4119 if( ctx < 4 ) | 4391 if( ctx < 4 ) |
4120 ctx = 4; | 4392 ctx = 4; |
4312 } | 4584 } |
4313 | 4585 |
4314 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { | 4586 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { |
4315 /* read skip flags */ | 4587 /* read skip flags */ |
4316 if( decode_cabac_mb_skip( h ) ) { | 4588 if( decode_cabac_mb_skip( h ) ) { |
4317 int mx, my; | 4589 decode_mb_skip(h); |
4318 | 4590 |
4319 //FIXME b frame | |
4320 /* skip mb */ | |
4321 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; | |
4322 | |
4323 memset(h->non_zero_count[mb_xy], 0, 16); | |
4324 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui | |
4325 #if 0 | |
4326 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
4327 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
4328 } | |
4329 if(h->mb_field_decoding_flag) | |
4330 mb_type|= MB_TYPE_INTERLACED; | |
4331 #endif | |
4332 | |
4333 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
4334 pred_pskip_motion(h, &mx, &my); | |
4335 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
4336 fill_rectangle( h->mvd_cache[0][scan8[0]], 4, 4, 8, pack16to32(0,0), 4); | |
4337 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | |
4338 write_back_motion(h, mb_type); | |
4339 | |
4340 s->current_picture.mb_type[mb_xy]= mb_type; //FIXME SKIP type | |
4341 s->current_picture.qscale_table[mb_xy]= s->qscale; | |
4342 h->slice_table[ mb_xy ]= h->slice_num; | |
4343 h->cbp_table[mb_xy] = 0; | 4591 h->cbp_table[mb_xy] = 0; |
4344 h->chroma_pred_mode_table[mb_xy] = 0; | 4592 h->chroma_pred_mode_table[mb_xy] = 0; |
4345 h->last_qscale_diff = 0; | 4593 h->last_qscale_diff = 0; |
4346 | |
4347 h->prev_mb_skiped= 1; | |
4348 | 4594 |
4349 return 0; | 4595 return 0; |
4350 | 4596 |
4351 } | 4597 } |
4352 } | 4598 } |
4428 for( i = 0; i < 4; i++ ) { | 4674 for( i = 0; i < 4; i++ ) { |
4429 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); | 4675 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); |
4430 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | 4676 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
4431 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; | 4677 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
4432 } | 4678 } |
4679 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) | |
4680 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) { | |
4681 pred_direct_motion(h, &mb_type); | |
4682 if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) { | |
4683 for( i = 0; i < 4; i++ ) | |
4684 if( IS_DIRECT(h->sub_mb_type[i]) ) | |
4685 fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, 1, 1 ); | |
4686 } | |
4687 } | |
4433 } else { | 4688 } else { |
4434 for( i = 0; i < 4; i++ ) { | 4689 for( i = 0; i < 4; i++ ) { |
4435 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); | 4690 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); |
4436 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | 4691 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
4437 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | 4692 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
4439 } | 4694 } |
4440 | 4695 |
4441 for( list = 0; list < 2; list++ ) { | 4696 for( list = 0; list < 2; list++ ) { |
4442 if( h->ref_count[list] > 0 ) { | 4697 if( h->ref_count[list] > 0 ) { |
4443 for( i = 0; i < 4; i++ ) { | 4698 for( i = 0; i < 4; i++ ) { |
4444 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | 4699 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
4700 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
4445 if( h->ref_count[list] > 1 ) | 4701 if( h->ref_count[list] > 1 ) |
4446 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); | 4702 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); |
4447 else | 4703 else |
4448 ref[list][i] = 0; | 4704 ref[list][i] = 0; |
4449 } else { | 4705 } else { |
4455 } | 4711 } |
4456 } | 4712 } |
4457 | 4713 |
4458 for(list=0; list<2; list++){ | 4714 for(list=0; list<2; list++){ |
4459 for(i=0; i<4; i++){ | 4715 for(i=0; i<4; i++){ |
4716 if(IS_DIRECT(h->sub_mb_type[i])){ | |
4717 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); | |
4718 continue; | |
4719 } | |
4460 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; | 4720 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; |
4461 | 4721 |
4462 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | 4722 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ |
4463 const int sub_mb_type= h->sub_mb_type[i]; | 4723 const int sub_mb_type= h->sub_mb_type[i]; |
4464 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; | 4724 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; |
4511 p[0] = p[1] = p[8] = p[9] = 0; | 4771 p[0] = p[1] = p[8] = p[9] = 0; |
4512 pd[0]= pd[1]= pd[8]= pd[9]= 0; | 4772 pd[0]= pd[1]= pd[8]= pd[9]= 0; |
4513 } | 4773 } |
4514 } | 4774 } |
4515 } | 4775 } |
4516 } else if( !IS_DIRECT(mb_type) ) { | 4776 } else if( IS_DIRECT(mb_type) ) { |
4777 pred_direct_motion(h, &mb_type); | |
4778 s->current_picture.mb_type[mb_xy]= mb_type; | |
4779 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
4780 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
4781 } else { | |
4517 int list, mx, my, i, mpx, mpy; | 4782 int list, mx, my, i, mpx, mpy; |
4518 if(IS_16X16(mb_type)){ | 4783 if(IS_16X16(mb_type)){ |
4519 for(list=0; list<2; list++){ | 4784 for(list=0; list<2; list++){ |
4520 if(IS_DIR(mb_type, 0, list)){ | 4785 if(IS_DIR(mb_type, 0, list)){ |
4521 if(h->ref_count[list] > 0 ){ | 4786 if(h->ref_count[list] > 0 ){ |
4542 if(h->ref_count[list]>0){ | 4807 if(h->ref_count[list]>0){ |
4543 for(i=0; i<2; i++){ | 4808 for(i=0; i<2; i++){ |
4544 if(IS_DIR(mb_type, i, list)){ | 4809 if(IS_DIR(mb_type, i, list)){ |
4545 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; | 4810 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; |
4546 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); | 4811 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); |
4547 } | 4812 }else |
4813 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | |
4548 } | 4814 } |
4549 } | 4815 } |
4550 } | 4816 } |
4551 for(list=0; list<2; list++){ | 4817 for(list=0; list<2; list++){ |
4552 for(i=0; i<2; i++){ | 4818 for(i=0; i<2; i++){ |
4556 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); | 4822 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); |
4557 tprintf("final mv:%d %d\n", mx, my); | 4823 tprintf("final mv:%d %d\n", mx, my); |
4558 | 4824 |
4559 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); | 4825 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); |
4560 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); | 4826 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
4827 }else{ // needed only for mixed refs | |
4828 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
4829 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
4561 } | 4830 } |
4562 } | 4831 } |
4563 } | 4832 } |
4564 }else{ | 4833 }else{ |
4565 assert(IS_8X16(mb_type)); | 4834 assert(IS_8X16(mb_type)); |
4567 if(h->ref_count[list]>0){ | 4836 if(h->ref_count[list]>0){ |
4568 for(i=0; i<2; i++){ | 4837 for(i=0; i<2; i++){ |
4569 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | 4838 if(IS_DIR(mb_type, i, list)){ //FIXME optimize |
4570 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; | 4839 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; |
4571 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); | 4840 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); |
4572 } | 4841 }else |
4842 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
4573 } | 4843 } |
4574 } | 4844 } |
4575 } | 4845 } |
4576 for(list=0; list<2; list++){ | 4846 for(list=0; list<2; list++){ |
4577 for(i=0; i<2; i++){ | 4847 for(i=0; i<2; i++){ |
4581 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); | 4851 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); |
4582 | 4852 |
4583 tprintf("final mv:%d %d\n", mx, my); | 4853 tprintf("final mv:%d %d\n", mx, my); |
4584 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); | 4854 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); |
4585 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); | 4855 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
4856 }else{ // needed only for mixed refs | |
4857 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
4858 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
4586 } | 4859 } |
4587 } | 4860 } |
4588 } | 4861 } |
4589 } | 4862 } |
4590 } | 4863 } |