1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #ifndef AOM_AV1_ENCODER_GLOBAL_MOTION_H_ 13 #define AOM_AV1_ENCODER_GLOBAL_MOTION_H_ 14 15 #include "aom/aom_integer.h" 16 #include "aom_scale/yv12config.h" 17 #include "av1/common/mv.h" 18 #include "av1/common/warped_motion.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #define MAX_CORNERS 4096 25 #define RANSAC_NUM_MOTIONS 1 26 #define GM_REFINEMENT_COUNT 5 27 28 typedef enum { 29 GLOBAL_MOTION_FEATURE_BASED, 30 GLOBAL_MOTION_DISFLOW_BASED, 31 } GlobalMotionEstimationType; 32 33 unsigned char *av1_downconvert_frame(YV12_BUFFER_CONFIG *frm, int bit_depth); 34 35 typedef struct { 36 double params[MAX_PARAMDIM - 1]; 37 int *inliers; 38 int num_inliers; 39 } MotionModel; 40 41 void av1_convert_model_to_params(const double *params, 42 WarpedMotionParams *model); 43 44 // TODO(sarahparker) These need to be retuned for speed 0 and 1 to 45 // maximize gains from segmented error metric 46 static const double erroradv_tr[] = { 0.65, 0.60, 0.65 }; 47 static const double erroradv_prod_tr[] = { 20000, 18000, 16000 }; 48 49 int av1_is_enough_erroradvantage(double best_erroradvantage, int params_cost, 50 int erroradv_type); 51 52 void av1_compute_feature_segmentation_map(uint8_t *segment_map, int width, 53 int height, int *inliers, 54 int num_inliers); 55 56 // Returns the error between the result of applying motion 'wm' to the frame 57 // described by 'ref' and the frame described by 'dst'. 58 int64_t av1_warp_error(WarpedMotionParams *wm, int use_hbd, int bd, 59 const uint8_t *ref, int width, int height, int stride, 60 uint8_t *dst, int p_col, int p_row, int p_width, 61 int p_height, int p_stride, int subsampling_x, 62 int subsampling_y, int64_t best_error, 63 uint8_t *segment_map, int segment_map_stride); 64 65 // Returns the av1_warp_error between "dst" and the result of applying the 66 // motion params that result from fine-tuning "wm" to "ref". Note that "wm" is 67 // modified in place. 68 int64_t av1_refine_integerized_param( 69 WarpedMotionParams *wm, TransformationType wmtype, int use_hbd, int bd, 70 uint8_t *ref, int r_width, int r_height, int r_stride, uint8_t *dst, 71 int d_width, int d_height, int d_stride, int n_refinements, 72 int64_t best_frame_error, uint8_t *segment_map, int segment_map_stride, 73 int64_t erroradv_threshold); 74 75 /* 76 Computes "num_motions" candidate global motion parameters between two frames. 77 The array "params_by_motion" should be length 8 * "num_motions". The ordering 78 of each set of parameters is best described by the homography: 79 80 [x' (m2 m3 m0 [x 81 z . y' = m4 m5 m1 * y 82 1] m6 m7 1) 1] 83 84 where m{i} represents the ith value in any given set of parameters. 85 86 "num_inliers" should be length "num_motions", and will be populated with the 87 number of inlier feature points for each motion. Params for which the 88 num_inliers entry is 0 should be ignored by the caller. 89 */ 90 int av1_compute_global_motion(TransformationType type, 91 unsigned char *frm_buffer, int frm_width, 92 int frm_height, int frm_stride, int *frm_corners, 93 int num_frm_corners, YV12_BUFFER_CONFIG *ref, 94 int bit_depth, 95 GlobalMotionEstimationType gm_estimation_type, 96 int *num_inliers_by_motion, 97 MotionModel *params_by_motion, int num_motions); 98 #ifdef __cplusplus 99 } // extern "C" 100 #endif 101 #endif // AOM_AV1_ENCODER_GLOBAL_MOTION_H_ 102