Mercurial > libavcodec.hg
comparison h263.c @ 10824:82d006235248 libavcodec
Move 3 direct MV related functions that i left out from h263.c to mpeg4video.c.
author | michael |
---|---|
date | Fri, 08 Jan 2010 19:59:51 +0000 |
parents | 514dc1c87b2e |
children | d0657e337f91 |
comparison
equal
deleted
inserted
replaced
10823:d87e8f2c5c91 | 10824:82d006235248 |
---|---|
338 } | 338 } |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 #endif //CONFIG_ENCODERS | 342 #endif //CONFIG_ENCODERS |
343 | |
344 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0])) | |
345 #define tab_bias (tab_size/2) | |
346 | |
347 //used by mpeg4 and rv10 decoder | |
348 void ff_mpeg4_init_direct_mv(MpegEncContext *s){ | |
349 int i; | |
350 for(i=0; i<tab_size; i++){ | |
351 s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time; | |
352 s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time; | |
353 } | |
354 } | |
355 | |
356 static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){ | |
357 int xy= s->block_index[i]; | |
358 uint16_t time_pp= s->pp_time; | |
359 uint16_t time_pb= s->pb_time; | |
360 int p_mx, p_my; | |
361 | |
362 p_mx= s->next_picture.motion_val[0][xy][0]; | |
363 if((unsigned)(p_mx + tab_bias) < tab_size){ | |
364 s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx; | |
365 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
366 : s->direct_scale_mv[1][p_mx + tab_bias]; | |
367 }else{ | |
368 s->mv[0][i][0] = p_mx*time_pb/time_pp + mx; | |
369 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
370 : p_mx*(time_pb - time_pp)/time_pp; | |
371 } | |
372 p_my= s->next_picture.motion_val[0][xy][1]; | |
373 if((unsigned)(p_my + tab_bias) < tab_size){ | |
374 s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my; | |
375 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
376 : s->direct_scale_mv[1][p_my + tab_bias]; | |
377 }else{ | |
378 s->mv[0][i][1] = p_my*time_pb/time_pp + my; | |
379 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
380 : p_my*(time_pb - time_pp)/time_pp; | |
381 } | |
382 } | |
383 | |
384 #undef tab_size | |
385 #undef tab_bias | |
386 | |
387 /** | |
388 * | |
389 * @return the mb_type | |
390 */ | |
391 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ | |
392 const int mb_index= s->mb_x + s->mb_y*s->mb_stride; | |
393 const int colocated_mb_type= s->next_picture.mb_type[mb_index]; | |
394 uint16_t time_pp; | |
395 uint16_t time_pb; | |
396 int i; | |
397 | |
398 //FIXME avoid divides | |
399 // try special case with shifts for 1 and 3 B-frames? | |
400 | |
401 if(IS_8X8(colocated_mb_type)){ | |
402 s->mv_type = MV_TYPE_8X8; | |
403 for(i=0; i<4; i++){ | |
404 ff_mpeg4_set_one_direct_mv(s, mx, my, i); | |
405 } | |
406 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; | |
407 } else if(IS_INTERLACED(colocated_mb_type)){ | |
408 s->mv_type = MV_TYPE_FIELD; | |
409 for(i=0; i<2; i++){ | |
410 int field_select= s->next_picture.ref_index[0][s->block_index[2*i]]; | |
411 s->field_select[0][i]= field_select; | |
412 s->field_select[1][i]= i; | |
413 if(s->top_field_first){ | |
414 time_pp= s->pp_field_time - field_select + i; | |
415 time_pb= s->pb_field_time - field_select + i; | |
416 }else{ | |
417 time_pp= s->pp_field_time + field_select - i; | |
418 time_pb= s->pb_field_time + field_select - i; | |
419 } | |
420 s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx; | |
421 s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my; | |
422 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0] | |
423 : s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp; | |
424 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] | |
425 : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; | |
426 } | |
427 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; | |
428 }else{ | |
429 ff_mpeg4_set_one_direct_mv(s, mx, my, 0); | |
430 s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0]; | |
431 s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1]; | |
432 s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0]; | |
433 s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1]; | |
434 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) | |
435 s->mv_type= MV_TYPE_16X16; | |
436 else | |
437 s->mv_type= MV_TYPE_8X8; | |
438 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line | |
439 } | |
440 } | |
441 | 343 |
442 void ff_h263_update_motion_val(MpegEncContext * s){ | 344 void ff_h263_update_motion_val(MpegEncContext * s){ |
443 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | 345 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; |
444 //FIXME a lot of that is only needed for !low_delay | 346 //FIXME a lot of that is only needed for !low_delay |
445 const int wrap = s->b8_stride; | 347 const int wrap = s->b8_stride; |