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_dsp/flow_estimation/flow_estimation.h" 17 #include "aom_scale/yv12config.h" 18 #include "aom_util/aom_thread.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #define RANSAC_NUM_MOTIONS 1 25 #define GM_REFINEMENT_COUNT 5 26 #define MAX_DIRECTIONS 2 27 28 // The structure holds a valid reference frame type and its temporal distance 29 // from the source frame. 30 typedef struct { 31 int distance; 32 MV_REFERENCE_FRAME frame; 33 } FrameDistPair; 34 35 typedef struct { 36 // Array of structure which holds the global motion parameters for a given 37 // motion model. params_by_motion[i] holds the parameters for a given motion 38 // model for the ith ransac motion. 39 MotionModel params_by_motion[RANSAC_NUM_MOTIONS]; 40 41 // Pointer to hold inliers from motion model. 42 uint8_t *segment_map; 43 } GlobalMotionThreadData; 44 45 typedef struct { 46 // Holds the mapping of each thread to past/future direction. 47 // thread_id_to_dir[i] indicates the direction id (past - 0/future - 1) 48 // assigned to the ith thread. 49 int8_t thread_id_to_dir[MAX_NUM_THREADS]; 50 51 // A flag which holds the early exit status based on the speed feature 52 // 'prune_ref_frame_for_gm_search'. early_exit[i] will be set if the speed 53 // feature based early exit happens in the direction 'i'. 54 int8_t early_exit[MAX_DIRECTIONS]; 55 56 // Counter for the next reference frame to be processed. 57 // next_frame_to_process[i] will hold the count of next reference frame to be 58 // processed in the direction 'i'. 59 int8_t next_frame_to_process[MAX_DIRECTIONS]; 60 } JobInfo; 61 62 typedef struct { 63 // Data related to assigning jobs for global motion multi-threading. 64 JobInfo job_info; 65 66 // Data specific to each worker in global motion multi-threading. 67 // thread_data[i] stores the thread specific data for worker 'i'. 68 GlobalMotionThreadData *thread_data; 69 70 #if CONFIG_MULTITHREAD 71 // Mutex lock used while dispatching jobs. 72 pthread_mutex_t *mutex_; 73 #endif 74 75 // Width and height for which segment_map is allocated for each thread. 76 int allocated_width; 77 int allocated_height; 78 79 // Number of workers for which thread_data is allocated. 80 int8_t allocated_workers; 81 } AV1GlobalMotionSync; 82 83 void av1_convert_model_to_params(const double *params, 84 WarpedMotionParams *model); 85 86 // TODO(sarahparker) These need to be retuned for speed 0 and 1 to 87 // maximize gains from segmented error metric 88 static const double erroradv_tr = 0.65; 89 static const double erroradv_prod_tr = 20000; 90 91 int av1_is_enough_erroradvantage(double best_erroradvantage, int params_cost); 92 93 void av1_compute_feature_segmentation_map(uint8_t *segment_map, int width, 94 int height, int *inliers, 95 int num_inliers); 96 97 // Returns the error between the result of applying motion 'wm' to the frame 98 // described by 'ref' and the frame described by 'dst'. 99 int64_t av1_warp_error(WarpedMotionParams *wm, int use_hbd, int bd, 100 const uint8_t *ref, int width, int height, int stride, 101 uint8_t *dst, int p_col, int p_row, int p_width, 102 int p_height, int p_stride, int subsampling_x, 103 int subsampling_y, int64_t best_error, 104 uint8_t *segment_map, int segment_map_stride); 105 106 // Returns the av1_warp_error between "dst" and the result of applying the 107 // motion params that result from fine-tuning "wm" to "ref". Note that "wm" is 108 // modified in place. 109 int64_t av1_refine_integerized_param( 110 WarpedMotionParams *wm, TransformationType wmtype, int use_hbd, int bd, 111 uint8_t *ref, int r_width, int r_height, int r_stride, uint8_t *dst, 112 int d_width, int d_height, int d_stride, int n_refinements, 113 int64_t best_frame_error, uint8_t *segment_map, int segment_map_stride, 114 int64_t erroradv_threshold); 115 116 #ifdef __cplusplus 117 } // extern "C" 118 #endif 119 #endif // AOM_AV1_ENCODER_GLOBAL_MOTION_H_ 120