You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.5KB

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