xref: /aosp_15_r20/external/libaom/aom_dsp/flow_estimation/corner_detect.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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_AOM_DSP_FLOW_ESTIMATION_CORNER_DETECT_H_
13 #define AOM_AOM_DSP_FLOW_ESTIMATION_CORNER_DETECT_H_
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdbool.h>
18 #include <memory.h>
19 
20 #include "aom_dsp/pyramid.h"
21 #include "aom_util/aom_pthread.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define MAX_CORNERS 4096
28 
29 typedef struct corner_list {
30 #if CONFIG_MULTITHREAD
31   // Mutex which is used to prevent the corner list from being computed twice
32   // at the same time
33   //
34   // Semantics:
35   // * This mutex must be held whenever reading or writing the `valid` flag
36   //
37   // * This mutex must also be held while computing the image pyramid,
38   //   to ensure that only one thread may do so at a time.
39   //
40   // * However, once you have read the valid flag and seen a true value,
41   //   it is safe to drop the mutex and read from the remaining fields.
42   //   This is because, once the image pyramid is computed, its contents
43   //   will not be changed until the parent frame buffer is recycled,
44   //   which will not happen until there are no more outstanding references
45   //   to the frame buffer.
46   pthread_mutex_t mutex;
47 #endif  // CONFIG_MULTITHREAD
48   // Flag indicating whether the corner list contains valid data
49   bool valid;
50   // Number of corners found
51   int num_corners;
52   // (x, y) coordinates of each corner
53   int corners[2 * MAX_CORNERS];
54 } CornerList;
55 
56 size_t av1_get_corner_list_size(void);
57 
58 CornerList *av1_alloc_corner_list(void);
59 
60 bool av1_compute_corner_list(const YV12_BUFFER_CONFIG *frame, int bit_depth,
61                              int downsample_level, CornerList *corners);
62 
63 #ifndef NDEBUG
64 // Check if a corner list has already been computed.
65 // This is mostly a debug helper - as it is necessary to hold corners->mutex
66 // while reading the valid flag, we cannot just write:
67 //   assert(corners->valid);
68 // This function allows the check to be correctly written as:
69 //   assert(aom_is_corner_list_valid(corners));
70 bool aom_is_corner_list_valid(CornerList *corners);
71 #endif
72 
73 void av1_invalidate_corner_list(CornerList *corners);
74 
75 void av1_free_corner_list(CornerList *corners);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif  // AOM_AOM_DSP_FLOW_ESTIMATION_CORNER_DETECT_H_
82