xref: /aosp_15_r20/external/libaom/av1/encoder/global_motion_facade.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2020, 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_FACADE_H_
13 #define AOM_AV1_ENCODER_GLOBAL_MOTION_FACADE_H_
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 struct yv12_buffer_config;
19 struct AV1_COMP;
20 
21 // Allocates memory for members of GlobalMotionData.
gm_alloc_data(AV1_COMP * cpi,GlobalMotionData * gm_data)22 static inline void gm_alloc_data(AV1_COMP *cpi, GlobalMotionData *gm_data) {
23   AV1_COMMON *cm = &cpi->common;
24   GlobalMotionInfo *gm_info = &cpi->gm_info;
25 
26   CHECK_MEM_ERROR(cm, gm_data->segment_map,
27                   aom_malloc(sizeof(*gm_data->segment_map) *
28                              gm_info->segment_map_w * gm_info->segment_map_h));
29 
30   av1_zero_array(gm_data->motion_models, RANSAC_NUM_MOTIONS);
31   for (int m = 0; m < RANSAC_NUM_MOTIONS; m++) {
32     CHECK_MEM_ERROR(cm, gm_data->motion_models[m].inliers,
33                     aom_malloc(sizeof(*gm_data->motion_models[m].inliers) * 2 *
34                                MAX_CORNERS));
35   }
36 }
37 
38 // Deallocates the memory allocated for members of GlobalMotionData.
gm_dealloc_data(GlobalMotionData * gm_data)39 static inline void gm_dealloc_data(GlobalMotionData *gm_data) {
40   aom_free(gm_data->segment_map);
41   gm_data->segment_map = NULL;
42   for (int m = 0; m < RANSAC_NUM_MOTIONS; m++) {
43     aom_free(gm_data->motion_models[m].inliers);
44     gm_data->motion_models[m].inliers = NULL;
45   }
46 }
47 
48 void av1_compute_gm_for_valid_ref_frames(
49     AV1_COMP *cpi, struct aom_internal_error_info *error_info,
50     YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES], int frame,
51     MotionModel *motion_models, uint8_t *segment_map, int segment_map_w,
52     int segment_map_h);
53 void av1_compute_global_motion_facade(struct AV1_COMP *cpi);
54 #ifdef __cplusplus
55 }  // extern "C"
56 #endif
57 
58 #endif  // AOM_AV1_ENCODER_GLOBAL_MOTION_FACADE_H_
59