00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "internal.h"
00029 #include "dsputil.h"
00030 #include "avcodec.h"
00031 #include "mpegvideo.h"
00032 #include "h264.h"
00033 #include "rectangle.h"
00034 #include "thread.h"
00035
00036
00037 #include <assert.h>
00038
00039
00040 static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
00041 int poc0 = h->ref_list[0][i].poc;
00042 int td = av_clip(poc1 - poc0, -128, 127);
00043 if(td == 0 || h->ref_list[0][i].long_ref){
00044 return 256;
00045 }else{
00046 int tb = av_clip(poc - poc0, -128, 127);
00047 int tx = (16384 + (FFABS(td) >> 1)) / td;
00048 return av_clip((tb*tx + 32) >> 6, -1024, 1023);
00049 }
00050 }
00051
00052 void ff_h264_direct_dist_scale_factor(H264Context * const h){
00053 MpegEncContext * const s = &h->s;
00054 const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
00055 const int poc1 = h->ref_list[1][0].poc;
00056 int i, field;
00057 for(field=0; field<2; field++){
00058 const int poc = h->s.current_picture_ptr->field_poc[field];
00059 const int poc1 = h->ref_list[1][0].field_poc[field];
00060 for(i=0; i < 2*h->ref_count[0]; i++)
00061 h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
00062 }
00063
00064 for(i=0; i<h->ref_count[0]; i++){
00065 h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
00066 }
00067 }
00068
00069 static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
00070 MpegEncContext * const s = &h->s;
00071 Picture * const ref1 = &h->ref_list[1][0];
00072 int j, old_ref, rfield;
00073 int start= mbafi ? 16 : 0;
00074 int end = mbafi ? 16+2*h->ref_count[0] : h->ref_count[0];
00075 int interl= mbafi || s->picture_structure != PICT_FRAME;
00076
00077
00078 memset(map[list], 0, sizeof(map[list]));
00079
00080 for(rfield=0; rfield<2; rfield++){
00081 for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
00082 int poc = ref1->ref_poc[colfield][list][old_ref];
00083
00084 if (!interl)
00085 poc |= 3;
00086 else if( interl && (poc&3) == 3)
00087 poc= (poc&~3) + rfield + 1;
00088
00089 for(j=start; j<end; j++){
00090 if(4*h->ref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){
00091 int cur_ref= mbafi ? (j-16)^field : j;
00092 if(ref1->mbaff)
00093 map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
00094 if(rfield == field || !interl)
00095 map[list][old_ref] = cur_ref;
00096 break;
00097 }
00098 }
00099 }
00100 }
00101 }
00102
00103 void ff_h264_direct_ref_list_init(H264Context * const h){
00104 MpegEncContext * const s = &h->s;
00105 Picture * const ref1 = &h->ref_list[1][0];
00106 Picture * const cur = s->current_picture_ptr;
00107 int list, j, field;
00108 int sidx= (s->picture_structure&1)^1;
00109 int ref1sidx= (ref1->reference&1)^1;
00110
00111 for(list=0; list<2; list++){
00112 cur->ref_count[sidx][list] = h->ref_count[list];
00113 for(j=0; j<h->ref_count[list]; j++)
00114 cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
00115 }
00116
00117 if(s->picture_structure == PICT_FRAME){
00118 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
00119 memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0]));
00120 }
00121
00122 cur->mbaff= FRAME_MBAFF;
00123
00124 h->col_fieldoff= 0;
00125 if(s->picture_structure == PICT_FRAME){
00126 int cur_poc = s->current_picture_ptr->poc;
00127 int *col_poc = h->ref_list[1]->field_poc;
00128 h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
00129 ref1sidx=sidx= h->col_parity;
00130 }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){
00131 h->col_fieldoff= 2*(h->ref_list[1][0].reference) - 3;
00132 }
00133
00134 if(cur->pict_type != AV_PICTURE_TYPE_B || h->direct_spatial_mv_pred)
00135 return;
00136
00137 for(list=0; list<2; list++){
00138 fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
00139 if(FRAME_MBAFF)
00140 for(field=0; field<2; field++)
00141 fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
00142 }
00143 }
00144
00145 static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y)
00146 {
00147 int ref_field = ref->reference - 1;
00148 int ref_field_picture = ref->field_picture;
00149 int ref_height = 16*h->s.mb_height >> ref_field_picture;
00150
00151 if(!HAVE_PTHREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME))
00152 return;
00153
00154
00155
00156
00157 ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1),
00158 ref_field_picture && ref_field);
00159 }
00160
00161 static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
00162 MpegEncContext * const s = &h->s;
00163 int b8_stride = 2;
00164 int b4_stride = h->b_stride;
00165 int mb_xy = h->mb_xy, mb_y = s->mb_y;
00166 int mb_type_col[2];
00167 const int16_t (*l1mv0)[2], (*l1mv1)[2];
00168 const int8_t *l1ref0, *l1ref1;
00169 const int is_b8x8 = IS_8X8(*mb_type);
00170 unsigned int sub_mb_type= MB_TYPE_L0L1;
00171 int i8, i4;
00172 int ref[2];
00173 int mv[2];
00174 int list;
00175
00176 assert(h->ref_list[1][0].reference&3);
00177
00178 await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
00179
00180 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
00181
00182
00183
00184 for(list=0; list<2; list++){
00185 int left_ref = h->ref_cache[list][scan8[0] - 1];
00186 int top_ref = h->ref_cache[list][scan8[0] - 8];
00187 int refc = h->ref_cache[list][scan8[0] - 8 + 4];
00188 const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4];
00189 if(refc == PART_NOT_AVAILABLE){
00190 refc = h->ref_cache[list][scan8[0] - 8 - 1];
00191 C = h-> mv_cache[list][scan8[0] - 8 - 1];
00192 }
00193 ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc);
00194 if(ref[list] >= 0){
00195
00196 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
00197 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
00198
00199 int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);
00200 if(match_count > 1){
00201 mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]),
00202 mid_pred(A[1], B[1], C[1]) );
00203 }else {
00204 assert(match_count==1);
00205 if(left_ref==ref[list]){
00206 mv[list]= AV_RN32A(A);
00207 }else if(top_ref==ref[list]){
00208 mv[list]= AV_RN32A(B);
00209 }else{
00210 mv[list]= AV_RN32A(C);
00211 }
00212 }
00213 }else{
00214 int mask= ~(MB_TYPE_L0 << (2*list));
00215 mv[list] = 0;
00216 ref[list] = -1;
00217 if(!is_b8x8)
00218 *mb_type &= mask;
00219 sub_mb_type &= mask;
00220 }
00221 }
00222 if(ref[0] < 0 && ref[1] < 0){
00223 ref[0] = ref[1] = 0;
00224 if(!is_b8x8)
00225 *mb_type |= MB_TYPE_L0L1;
00226 sub_mb_type |= MB_TYPE_L0L1;
00227 }
00228
00229 if(!(is_b8x8|mv[0]|mv[1])){
00230 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
00231 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
00232 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
00233 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
00234 *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
00235 return;
00236 }
00237
00238 if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){
00239 if(!IS_INTERLACED(*mb_type)){
00240 mb_y = (s->mb_y&~1) + h->col_parity;
00241 mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
00242 b8_stride = 0;
00243 }else{
00244 mb_y += h->col_fieldoff;
00245 mb_xy += s->mb_stride*h->col_fieldoff;
00246 }
00247 goto single_col;
00248 }else{
00249 if(IS_INTERLACED(*mb_type)){
00250 mb_y = s->mb_y&~1;
00251 mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
00252 mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
00253 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
00254 b8_stride = 2+4*s->mb_stride;
00255 b4_stride *= 6;
00256 if(IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])){
00257 mb_type_col[0] &= ~MB_TYPE_INTERLACED;
00258 mb_type_col[1] &= ~MB_TYPE_INTERLACED;
00259 }
00260
00261 sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
00262 if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
00263 && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
00264 && !is_b8x8){
00265 *mb_type |= MB_TYPE_16x8 |MB_TYPE_DIRECT2;
00266 }else{
00267 *mb_type |= MB_TYPE_8x8;
00268 }
00269 }else{
00270 single_col:
00271 mb_type_col[0] =
00272 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
00273
00274 sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
00275 if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
00276 *mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
00277 }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){
00278 *mb_type |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));
00279 }else{
00280 if(!h->sps.direct_8x8_inference_flag){
00281
00282
00283 sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16);
00284 }
00285 *mb_type |= MB_TYPE_8x8;
00286 }
00287 }
00288 }
00289
00290 await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
00291
00292 l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
00293 l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
00294 l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
00295 l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy];
00296 if(!b8_stride){
00297 if(s->mb_y&1){
00298 l1ref0 += 2;
00299 l1ref1 += 2;
00300 l1mv0 += 2*b4_stride;
00301 l1mv1 += 2*b4_stride;
00302 }
00303 }
00304
00305
00306 if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
00307 int n=0;
00308 for(i8=0; i8<4; i8++){
00309 int x8 = i8&1;
00310 int y8 = i8>>1;
00311 int xy8 = x8+y8*b8_stride;
00312 int xy4 = 3*x8+y8*b4_stride;
00313 int a,b;
00314
00315 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
00316 continue;
00317 h->sub_mb_type[i8] = sub_mb_type;
00318
00319 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
00320 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
00321 if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref
00322 && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
00323 || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
00324 a=b=0;
00325 if(ref[0] > 0)
00326 a= mv[0];
00327 if(ref[1] > 0)
00328 b= mv[1];
00329 n++;
00330 }else{
00331 a= mv[0];
00332 b= mv[1];
00333 }
00334 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
00335 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
00336 }
00337 if(!is_b8x8 && !(n&3))
00338 *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
00339 }else if(IS_16X16(*mb_type)){
00340 int a,b;
00341
00342 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
00343 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
00344 if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref
00345 && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
00346 || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
00347 && h->x264_build>33U))){
00348 a=b=0;
00349 if(ref[0] > 0)
00350 a= mv[0];
00351 if(ref[1] > 0)
00352 b= mv[1];
00353 }else{
00354 a= mv[0];
00355 b= mv[1];
00356 }
00357 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
00358 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
00359 }else{
00360 int n=0;
00361 for(i8=0; i8<4; i8++){
00362 const int x8 = i8&1;
00363 const int y8 = i8>>1;
00364
00365 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
00366 continue;
00367 h->sub_mb_type[i8] = sub_mb_type;
00368
00369 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4);
00370 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4);
00371 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
00372 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
00373
00374 assert(b8_stride==2);
00375
00376 if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[i8] == 0
00377 || (l1ref0[i8] < 0 && l1ref1[i8] == 0
00378 && h->x264_build>33U))){
00379 const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1;
00380 if(IS_SUB_8X8(sub_mb_type)){
00381 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
00382 if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
00383 if(ref[0] == 0)
00384 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
00385 if(ref[1] == 0)
00386 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
00387 n+=4;
00388 }
00389 }else{
00390 int m=0;
00391 for(i4=0; i4<4; i4++){
00392 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
00393 if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
00394 if(ref[0] == 0)
00395 AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]);
00396 if(ref[1] == 0)
00397 AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]);
00398 m++;
00399 }
00400 }
00401 if(!(m&3))
00402 h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8;
00403 n+=m;
00404 }
00405 }
00406 }
00407 if(!is_b8x8 && !(n&15))
00408 *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
00409 }
00410 }
00411
00412 static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
00413 MpegEncContext * const s = &h->s;
00414 int b8_stride = 2;
00415 int b4_stride = h->b_stride;
00416 int mb_xy = h->mb_xy, mb_y = s->mb_y;
00417 int mb_type_col[2];
00418 const int16_t (*l1mv0)[2], (*l1mv1)[2];
00419 const int8_t *l1ref0, *l1ref1;
00420 const int is_b8x8 = IS_8X8(*mb_type);
00421 unsigned int sub_mb_type;
00422 int i8, i4;
00423
00424 assert(h->ref_list[1][0].reference&3);
00425
00426 await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
00427
00428 if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){
00429 if(!IS_INTERLACED(*mb_type)){
00430 mb_y = (s->mb_y&~1) + h->col_parity;
00431 mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
00432 b8_stride = 0;
00433 }else{
00434 mb_y += h->col_fieldoff;
00435 mb_xy += s->mb_stride*h->col_fieldoff;
00436 }
00437 goto single_col;
00438 }else{
00439 if(IS_INTERLACED(*mb_type)){
00440 mb_y = s->mb_y&~1;
00441 mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
00442 mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
00443 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
00444 b8_stride = 2+4*s->mb_stride;
00445 b4_stride *= 6;
00446
00447 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
00448
00449 if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
00450 && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
00451 && !is_b8x8){
00452 *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2;
00453 }else{
00454 *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
00455 }
00456 }else{
00457 single_col:
00458 mb_type_col[0] =
00459 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
00460
00461 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
00462 if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
00463 *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
00464 }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){
00465 *mb_type |= MB_TYPE_L0L1|MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));
00466 }else{
00467 if(!h->sps.direct_8x8_inference_flag){
00468
00469
00470 sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2;
00471 }
00472 *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
00473 }
00474 }
00475 }
00476
00477 await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
00478
00479 l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
00480 l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
00481 l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
00482 l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy];
00483 if(!b8_stride){
00484 if(s->mb_y&1){
00485 l1ref0 += 2;
00486 l1ref1 += 2;
00487 l1mv0 += 2*b4_stride;
00488 l1mv1 += 2*b4_stride;
00489 }
00490 }
00491
00492 {
00493 const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
00494 const int *dist_scale_factor = h->dist_scale_factor;
00495 int ref_offset;
00496
00497 if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
00498 map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
00499 map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
00500 dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
00501 }
00502 ref_offset = (h->ref_list[1][0].mbaff<<4) & (mb_type_col[0]>>3);
00503
00504 if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
00505 int y_shift = 2*!IS_INTERLACED(*mb_type);
00506 assert(h->sps.direct_8x8_inference_flag);
00507
00508 for(i8=0; i8<4; i8++){
00509 const int x8 = i8&1;
00510 const int y8 = i8>>1;
00511 int ref0, scale;
00512 const int16_t (*l1mv)[2]= l1mv0;
00513
00514 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
00515 continue;
00516 h->sub_mb_type[i8] = sub_mb_type;
00517
00518 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
00519 if(IS_INTRA(mb_type_col[y8])){
00520 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
00521 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
00522 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
00523 continue;
00524 }
00525
00526 ref0 = l1ref0[x8 + y8*b8_stride];
00527 if(ref0 >= 0)
00528 ref0 = map_col_to_list0[0][ref0 + ref_offset];
00529 else{
00530 ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
00531 l1mv= l1mv1;
00532 }
00533 scale = dist_scale_factor[ref0];
00534 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
00535
00536 {
00537 const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
00538 int my_col = (mv_col[1]<<y_shift)/2;
00539 int mx = (scale * mv_col[0] + 128) >> 8;
00540 int my = (scale * my_col + 128) >> 8;
00541 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
00542 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
00543 }
00544 }
00545 return;
00546 }
00547
00548
00549
00550 if(IS_16X16(*mb_type)){
00551 int ref, mv0, mv1;
00552
00553 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
00554 if(IS_INTRA(mb_type_col[0])){
00555 ref=mv0=mv1=0;
00556 }else{
00557 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
00558 : map_col_to_list0[1][l1ref1[0] + ref_offset];
00559 const int scale = dist_scale_factor[ref0];
00560 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
00561 int mv_l0[2];
00562 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
00563 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
00564 ref= ref0;
00565 mv0= pack16to32(mv_l0[0],mv_l0[1]);
00566 mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
00567 }
00568 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
00569 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
00570 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
00571 }else{
00572 for(i8=0; i8<4; i8++){
00573 const int x8 = i8&1;
00574 const int y8 = i8>>1;
00575 int ref0, scale;
00576 const int16_t (*l1mv)[2]= l1mv0;
00577
00578 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
00579 continue;
00580 h->sub_mb_type[i8] = sub_mb_type;
00581 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
00582 if(IS_INTRA(mb_type_col[0])){
00583 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
00584 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
00585 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
00586 continue;
00587 }
00588
00589 assert(b8_stride == 2);
00590 ref0 = l1ref0[i8];
00591 if(ref0 >= 0)
00592 ref0 = map_col_to_list0[0][ref0 + ref_offset];
00593 else{
00594 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
00595 l1mv= l1mv1;
00596 }
00597 scale = dist_scale_factor[ref0];
00598
00599 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
00600 if(IS_SUB_8X8(sub_mb_type)){
00601 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
00602 int mx = (scale * mv_col[0] + 128) >> 8;
00603 int my = (scale * mv_col[1] + 128) >> 8;
00604 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
00605 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
00606 }else
00607 for(i4=0; i4<4; i4++){
00608 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
00609 int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
00610 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
00611 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
00612 AV_WN32A(h->mv_cache[1][scan8[i8*4+i4]],
00613 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]));
00614 }
00615 }
00616 }
00617 }
00618 }
00619
00620 void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
00621 if(h->direct_spatial_mv_pred){
00622 pred_spatial_direct_motion(h, mb_type);
00623 }else{
00624 pred_temp_direct_motion(h, mb_type);
00625 }
00626 }