1 
2 #ifndef __SCHRO_MOTIONEST_H__
3 #define __SCHRO_MOTIONEST_H__
4 
5 #include <schroedinger/schroencoder.h>
6 
7 SCHRO_BEGIN_DECLS
8 
9 typedef struct _SchroMotionEst SchroMotionEst;
10 typedef struct _SchroRoughME SchroRoughME;
11 typedef struct _SchroBlock SchroBlock;
12 
13 /* supports hierarchical block-matching motion estimation */
14 typedef struct _SchroHierBm SchroHierBm;
15 /* supports motion estimation */
16 typedef struct _SchroMe SchroMe;
17 
18 #ifdef SCHRO_ENABLE_UNSTABLE_API
19 
20 #define SCHRO_MAX_HIER_LEVELS 8
21 
22 struct _SchroHierBm {
23   int                ref_count;
24   int                ref;
25   int                hierarchy_levels;
26   SchroParams*       params;
27   SchroFrame**       downsampled_src;
28   SchroFrame**       downsampled_ref;
29   SchroMotionField** downsampled_mf;
30   schro_bool         use_chroma;
31 };
32 
33 struct _SchroMotionEst {
34   SchroEncoderFrame *encoder_frame;
35   SchroParams *params;
36 
37   double lambda;
38 
39   SchroFrame *downsampled_src0[SCHRO_MAX_HIER_LEVELS];
40   SchroFrame *downsampled_src1[SCHRO_MAX_HIER_LEVELS];
41 
42   SchroMotion *motion;
43 
44   int scan_distance;
45 
46   int badblocks;
47   double hier_score;
48 };
49 
50 struct _SchroRoughME {
51   SchroEncoderFrame *encoder_frame;
52   SchroEncoderFrame *ref_frame;
53 
54   SchroMotionField *motion_fields[SCHRO_MAX_HIER_LEVELS];
55 };
56 
57 struct _SchroBlock {
58   int valid;
59   int error;
60   int entropy;
61 
62   double score;
63 
64   SchroMotionVector mv[4][4];
65 };
66 
67 SchroMotionEst *schro_motionest_new (SchroEncoderFrame *frame);
68 void schro_motionest_free (SchroMotionEst *me);
69 
70 SchroRoughME * schro_rough_me_new (SchroEncoderFrame *frame, SchroEncoderFrame *ref);
71 void schro_rough_me_free (SchroRoughME *rme);
72 void schro_rough_me_heirarchical_scan (SchroRoughME *rme);
73 void schro_rough_me_heirarchical_scan_nohint (SchroRoughME *rme, int shift,
74     int distance);
75 void schro_rough_me_heirarchical_scan_hint (SchroRoughME *rme, int shift,
76     int distance);
77 
78 void schro_encoder_hierarchical_block_matching (SchroEncoderFrame* frame);
79 
80 void schro_encoder_motion_predict_rough (SchroEncoderFrame *frame);
81 void schro_encoder_motion_predict_pel (SchroEncoderFrame *frame);
82 void schro_encoder_motion_predict_subpel (SchroEncoderFrame *frame);
83 void schro_encoder_motion_predict_subpel_deep (SchroMe *me);
84 
85 void schro_encoder_global_estimation (SchroEncoderFrame *frame);
86 
87 SchroMotionField * schro_motion_field_new (int x_num_blocks, int y_num_blocks);
88 void schro_motion_field_free (SchroMotionField *field);
89 void schro_motion_field_scan (SchroMotionField *field, SchroParams *params, SchroFrame *frame, SchroFrame *ref, int dist);
90 void schro_motion_field_inherit (SchroMotionField *field, SchroMotionField *parent);
91 void schro_motion_field_copy (SchroMotionField *field, SchroMotionField *parent);
92 void schro_motion_field_set (SchroMotionField *field, int split, int pred_mode);
93 
94 int schro_frame_get_metric (SchroFrame *frame1, int x1, int y1,
95     SchroFrame *frame2, int x2, int y2);
96 void schro_motion_field_lshift (SchroMotionField *mf, int n);
97 
98 int schro_motion_estimate_entropy (SchroMotion *motion);
99 int schro_motion_block_estimate_entropy (SchroMotion *motion, int i, int j);
100 int schro_motion_superblock_estimate_entropy (SchroMotion *motion, int i, int j);
101 int schro_motion_superblock_try_estimate_entropy (SchroMotion *motion, int i,
102     int j, SchroBlock *block);
103 int schro_motionest_superblock_get_metric (SchroMotionEst *me,
104     SchroBlock *block, int i, int j);
105 void schro_motion_copy_from (SchroMotion *motion, int i, int j, SchroBlock *block);
106 void schro_motion_copy_to (SchroMotion *motion, int i, int j, SchroBlock *block);
107 
108 void schro_block_fixup (SchroBlock *block);
109 int schro_block_check (SchroBlock *block);
110 
111 /* SchroHierBm *interface */
112 SchroHierBm *schro_hbm_new ( SchroEncoderFrame* frame, int ref_number );
113 SchroHierBm *schro_hbm_ref ( SchroHierBm *schro_hbm );
114 void schro_hbm_unref ( SchroHierBm* schro_hbm );
115 
116 void schro_hbm_scan ( SchroHierBm *schro_hbm );
117 void schro_hierarchical_bm_scan_hint ( SchroHierBm *schro_hbm, int shift, int h_range );
118 
119 SchroMotionField* schro_hbm_best_mf ( SchroHierBm *schro_hbm );
120 SchroMotionField* schro_hbm_motion_field ( SchroHierBm *schro_hbm, int level);
121 
122 /* SchroMe interface */
123 SchroMe *schro_me_new (SchroEncoderFrame* framer );
124 void schro_me_free (SchroMe* me );
125 
126 SchroFrame* schro_me_src (SchroMe *me );
127 SchroUpsampledFrame* schro_me_ref (SchroMe *me, int ref_number );
128 
129 SchroMotionField* schro_me_subpel_mf ( SchroMe *me, int ref_number );
130 void schro_me_set_subpel_mf ( SchroMe *me, SchroMotionField* mf, int ref_number );
131 SchroMotionField* schro_me_split2_mf ( SchroMe *me, int ref_number );
132 void schro_me_set_split2_mf ( SchroMe *me, SchroMotionField* mf, int ref_number );
133 SchroMotionField* schro_me_split1_mf ( SchroMe *me, int ref_number );
134 void schro_me_set_split1_mf ( SchroMe *me, SchroMotionField* mf, int ref_number );
135 SchroMotionField* schro_me_split0_mf ( SchroMe *me, int ref_number );
136 void schro_me_set_split0_mf ( SchroMe *me, SchroMotionField* mf, int ref_number );
137 
138 SchroHierBm *schro_me_hbm (SchroMe *me, int ref_number);
139 
140 void schro_me_set_lambda ( SchroMe *me, double lambda );
141 double schro_me_lambda ( SchroMe *me );
142 SchroParams* schro_me_params ( SchroMe *me );
143 SchroMotion* schro_me_motion ( SchroMe *me );
144 void schro_me_set_motion ( SchroMe *me, SchroMotion* motion );
145 void schro_me_set_mc_error ( SchroMe *me, double mc_err );
146 double schro_me_mc_error ( SchroMe *me );
147 void schro_me_set_badblock_ratio ( SchroMe *me, double badblocks_ratio );
148 double schro_me_badblocks_ratio ( SchroMe *me );
149 void schro_me_set_dcblock_ratio ( SchroMe *me, double dcblock_ratio );
150 double schro_me_dcblock_ratio ( SchroMe *me );
151 void schro_mode_decision (SchroMe *me);
152 
153 void schro_motion_calculate_stats (SchroMotion *motion, SchroEncoderFrame *frame);
154 
155 void schro_motionest_superblock_phasecorr1 (SchroMotionEst *me, int ref,
156     SchroBlock *block, int i, int j);
157 void schro_motionest_superblock_global (SchroMotionEst *me, int ref,
158     SchroBlock *block, int i, int j);
159 
160 #endif
161 
162 SCHRO_END_DECLS
163 
164 #endif
165 
166