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