Undo changes to aom_fast9_detect_nonmax prototype

Undo the change to the aom_fast9_detect_nonmax() function prototype in
https://aomedia-review.googlesource.com/c/aom/+/181161.

third_party/fastfeat is used by libaom and libavm. In Google's internal
repository, third_party/fastfeat is a separate component shared by
libaom and libavm. So it is better to avoid changing the fastfeat API.

Change aom_fast9_detect_nonmax() to signal memory allocation failure by
setting the output argument *ret_num_corners to -1. This change doesn't
require any change to libavm because libavm treats all *ret_num_corners
values less than or equal to 0 in the same way.

Bug: aomedia:3276
Change-Id: I810fbdd1eb44bd022e3bcf95e9b5eb14a7ef53bf
diff --git a/aom_dsp/flow_estimation/corner_detect.c b/aom_dsp/flow_estimation/corner_detect.c
index 43b5255..8a6f7cb 100644
--- a/aom_dsp/flow_estimation/corner_detect.c
+++ b/aom_dsp/flow_estimation/corner_detect.c
@@ -47,19 +47,16 @@
 
   int *scores = NULL;
   int num_corners;
-  bool mem_alloc_failed = false;
-  xy *const frame_corners_xy =
-      aom_fast9_detect_nonmax(buf, width, height, stride, FAST_BARRIER, &scores,
-                              &num_corners, &mem_alloc_failed);
-  if (mem_alloc_failed) return false;
+  xy *const frame_corners_xy = aom_fast9_detect_nonmax(
+      buf, width, height, stride, FAST_BARRIER, &scores, &num_corners);
+  if (num_corners < 0) return false;
 
-  if (num_corners <= 0) {
-    // Some error occured, so no corners are available
-    corners->num_corners = 0;
-  } else if (num_corners <= MAX_CORNERS) {
+  if (num_corners <= MAX_CORNERS) {
     // Use all detected corners
-    memcpy(corners->corners, frame_corners_xy,
-           sizeof(*frame_corners_xy) * num_corners);
+    if (num_corners != 0) {
+      memcpy(corners->corners, frame_corners_xy,
+             sizeof(*frame_corners_xy) * num_corners);
+    }
     corners->num_corners = num_corners;
   } else {
     // There are more than MAX_CORNERS corners avilable, so pick out a subset
diff --git a/third_party/fastfeat/README.libaom b/third_party/fastfeat/README.libaom
index dbcfae1..556d8b6 100644
--- a/third_party/fastfeat/README.libaom
+++ b/third_party/fastfeat/README.libaom
@@ -41,4 +41,4 @@
 Add error checking
 Add output argument to hold the scores of the detected features
 Add assertion and rewrite comparisons to appease the scan-build static analyzer
-Add output argument to signal memory allocation failure
+Set output argument *ret_num_corners to -1 to signal memory allocation failure
diff --git a/third_party/fastfeat/fast.c b/third_party/fastfeat/fast.c
index 2bf1096..c475b4c 100644
--- a/third_party/fastfeat/fast.c
+++ b/third_party/fastfeat/fast.c
@@ -34,7 +34,7 @@
 
 
 xy* aom_fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b,
-                            int** ret_scores, int* ret_num_corners, bool* mem_alloc_failed)
+                            int** ret_scores, int* ret_num_corners)
 {
   xy* corners;
   int num_corners;
@@ -42,13 +42,22 @@
   xy* nonmax;
 
   corners = aom_fast9_detect(im, xsize, ysize, stride, b, &num_corners);
-  if (!corners) {
-    *mem_alloc_failed = true;
+  if(!corners)
+  {
+    // Memory allocation failure
+    *ret_num_corners = -1;
     return NULL;
   }
+  // num_corners may be zero.
   scores = aom_fast9_score(im, stride, corners, num_corners, b);
+  if(!scores && num_corners > 0)
+  {
+    // Memory allocation failure
+    free(corners);
+    *ret_num_corners = -1;
+    return NULL;
+  }
   nonmax = aom_nonmax_suppression(corners, scores, num_corners, ret_scores, ret_num_corners);
-  if (!nonmax && num_corners > 0) *mem_alloc_failed = true;
 
   free(corners);
   free(scores);
diff --git a/third_party/fastfeat/fast.h b/third_party/fastfeat/fast.h
index 7e3e155..228ba85 100644
--- a/third_party/fastfeat/fast.h
+++ b/third_party/fastfeat/fast.h
@@ -31,19 +31,22 @@
 // clang-format off
 #ifndef FAST_H
 #define FAST_H
-#include <stdbool.h>
 
 typedef struct { int x, y; } xy;
 typedef unsigned char byte;
 
 int aom_fast9_corner_score(const byte* p, const int pixel[], int bstart);
 
+// Returns NULL on memory allocation failure.
 xy* aom_fast9_detect(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);
 
+// If num_corners > 0, returns NULL on memory allocation failure.
 int* aom_fast9_score(const byte* i, int stride, const xy* corners, int num_corners, int b);
 
+// Sets *ret_num_corners to -1 (and returns NULL) on memory allocation failure.
+// Sets *ret_num_corners to 0 if nothing went wrong but no corners were found.
 xy* aom_fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b,
-                            int** ret_scores, int* ret_num_corners, bool* mem_alloc_failed);
+                            int** ret_scores, int* ret_num_corners);
 
 xy* aom_nonmax_suppression(const xy* corners, const int* scores, int num_corners,
                            int** ret_scores, int* ret_num_nonmax);
diff --git a/third_party/fastfeat/nonmax.c b/third_party/fastfeat/nonmax.c
index cc0ada7..a6f7da0 100644
--- a/third_party/fastfeat/nonmax.c
+++ b/third_party/fastfeat/nonmax.c
@@ -53,9 +53,10 @@
   int point_below = 0;
 
   *ret_scores = 0;
-  *ret_num_nonmax = 0;
+  *ret_num_nonmax = -1;
   if(!(corners && scores) || num_corners < 1)
   {
+    *ret_num_nonmax = 0;
     return 0;
   }