motion_est.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Motion estimation
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_MOTION_EST_H
  21. #define AVCODEC_MOTION_EST_H
  22. #include <stdint.h>
  23. #include "avcodec.h"
  24. #include "hpeldsp.h"
  25. #include "qpeldsp.h"
  26. struct MpegEncContext;
  27. #if ARCH_IA64 // Limit static arrays to avoid gcc failing "short data segment overflowed"
  28. #define MAX_MV 1024
  29. #else
  30. #define MAX_MV 4096
  31. #endif
  32. #define MAX_DMV (2*MAX_MV)
  33. #define ME_MAP_SIZE 64
  34. #define FF_ME_ZERO 0
  35. #define FF_ME_EPZS 1
  36. #define FF_ME_XONE 2
  37. /**
  38. * Motion estimation context.
  39. */
  40. typedef struct MotionEstContext {
  41. AVCodecContext *avctx;
  42. int skip; ///< set if ME is skipped for the current MB
  43. int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
  44. int direct_basis_mv[4][2];
  45. uint8_t *scratchpad; /**< data area for the ME algo, so that
  46. * the ME does not need to malloc/free. */
  47. uint8_t *best_mb;
  48. uint8_t *temp_mb[2];
  49. uint8_t *temp;
  50. int best_bits;
  51. uint32_t *map; ///< map to avoid duplicate evaluations
  52. uint32_t *score_map; ///< map to store the scores
  53. unsigned map_generation;
  54. int pre_penalty_factor;
  55. int penalty_factor; /**< an estimate of the bits required to
  56. * code a given mv value, e.g. (1,0) takes
  57. * more bits than (0,0). We have to
  58. * estimate whether any reduction in
  59. * residual is worth the extra bits. */
  60. int sub_penalty_factor;
  61. int mb_penalty_factor;
  62. int flags;
  63. int sub_flags;
  64. int mb_flags;
  65. int pre_pass; ///< = 1 for the pre pass
  66. int dia_size;
  67. int xmin;
  68. int xmax;
  69. int ymin;
  70. int ymax;
  71. int pred_x;
  72. int pred_y;
  73. uint8_t *src[4][4];
  74. uint8_t *ref[4][4];
  75. int stride;
  76. int uvstride;
  77. /* temp variables for picture complexity calculation */
  78. int64_t mc_mb_var_sum_temp;
  79. int64_t mb_var_sum_temp;
  80. int scene_change_score;
  81. op_pixels_func(*hpel_put)[4];
  82. op_pixels_func(*hpel_avg)[4];
  83. qpel_mc_func(*qpel_put)[16];
  84. qpel_mc_func(*qpel_avg)[16];
  85. uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
  86. uint8_t *current_mv_penalty;
  87. int (*sub_motion_search)(struct MpegEncContext *s,
  88. int *mx_ptr, int *my_ptr, int dmin,
  89. int src_index, int ref_index,
  90. int size, int h);
  91. } MotionEstContext;
  92. static inline int ff_h263_round_chroma(int x)
  93. {
  94. //FIXME static or not?
  95. static const uint8_t h263_chroma_roundtab[16] = {
  96. // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  97. 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
  98. };
  99. return h263_chroma_roundtab[x & 0xf] + (x >> 3);
  100. }
  101. int ff_init_me(struct MpegEncContext *s);
  102. void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
  103. void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
  104. int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s,
  105. int mb_x, int mb_y);
  106. int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
  107. int P[10][2], int src_index, int ref_index,
  108. int16_t (*last_mv)[2], int ref_mv_scale, int size,
  109. int h);
  110. int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
  111. int ref_index, int size, int h, int add_rate);
  112. int ff_get_best_fcode(struct MpegEncContext *s,
  113. int16_t (*mv_table)[2], int type);
  114. void ff_fix_long_p_mvs(struct MpegEncContext *s, int type);
  115. void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
  116. int field_select, int16_t (*mv_table)[2], int f_code,
  117. int type, int truncate);
  118. #endif /* AVCODEC_MOTION_EST_H */