xref: /aosp_15_r20/external/libaom/test/wiener_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
13*77c1e3ccSAndroid Build Coastguard Worker #include <utility>
14*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/register_state_check.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
21*77c1e3ccSAndroid Build Coastguard Worker 
22*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_dsp_rtcd.h"
24*77c1e3ccSAndroid Build Coastguard Worker 
25*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_integer.h"
26*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/aom_timer.h"
27*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/pickrst.h"
28*77c1e3ccSAndroid Build Coastguard Worker 
29*77c1e3ccSAndroid Build Coastguard Worker #define MAX_WIENER_BLOCK 384
30*77c1e3ccSAndroid Build Coastguard Worker #define MAX_DATA_BLOCK (MAX_WIENER_BLOCK + WIENER_WIN)
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker // 8-bit-depth tests
33*77c1e3ccSAndroid Build Coastguard Worker namespace wiener_lowbd {
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker // C implementation of the algorithm implmented by the SIMD code.
36*77c1e3ccSAndroid Build Coastguard Worker // This is a little more efficient than the version in av1_compute_stats_c().
compute_stats_win_opt_c(int wiener_win,const uint8_t * dgd,const uint8_t * src,int16_t * d,int16_t * s,int h_start,int h_end,int v_start,int v_end,int dgd_stride,int src_stride,int64_t * M,int64_t * H,int use_downsampled_wiener_stats)37*77c1e3ccSAndroid Build Coastguard Worker static void compute_stats_win_opt_c(int wiener_win, const uint8_t *dgd,
38*77c1e3ccSAndroid Build Coastguard Worker                                     const uint8_t *src, int16_t *d, int16_t *s,
39*77c1e3ccSAndroid Build Coastguard Worker                                     int h_start, int h_end, int v_start,
40*77c1e3ccSAndroid Build Coastguard Worker                                     int v_end, int dgd_stride, int src_stride,
41*77c1e3ccSAndroid Build Coastguard Worker                                     int64_t *M, int64_t *H,
42*77c1e3ccSAndroid Build Coastguard Worker                                     int use_downsampled_wiener_stats) {
43*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_TRUE(wiener_win == WIENER_WIN || wiener_win == WIENER_WIN_CHROMA);
44*77c1e3ccSAndroid Build Coastguard Worker   (void)d;
45*77c1e3ccSAndroid Build Coastguard Worker   (void)s;
46*77c1e3ccSAndroid Build Coastguard Worker   int i, j, k, l, m, n;
47*77c1e3ccSAndroid Build Coastguard Worker   const int pixel_count = (h_end - h_start) * (v_end - v_start);
48*77c1e3ccSAndroid Build Coastguard Worker   const int wiener_win2 = wiener_win * wiener_win;
49*77c1e3ccSAndroid Build Coastguard Worker   const int wiener_halfwin = (wiener_win >> 1);
50*77c1e3ccSAndroid Build Coastguard Worker   uint8_t avg = find_average(dgd, h_start, h_end, v_start, v_end, dgd_stride);
51*77c1e3ccSAndroid Build Coastguard Worker   int downsample_factor =
52*77c1e3ccSAndroid Build Coastguard Worker       use_downsampled_wiener_stats ? WIENER_STATS_DOWNSAMPLE_FACTOR : 1;
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int64_t> > M_int(wiener_win,
55*77c1e3ccSAndroid Build Coastguard Worker                                            std::vector<int64_t>(wiener_win, 0));
56*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int64_t> > H_int(
57*77c1e3ccSAndroid Build Coastguard Worker       wiener_win * wiener_win, std::vector<int64_t>(wiener_win * 8, 0));
58*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int32_t> > sumY(wiener_win,
59*77c1e3ccSAndroid Build Coastguard Worker                                           std::vector<int32_t>(wiener_win, 0));
60*77c1e3ccSAndroid Build Coastguard Worker   int32_t sumX = 0;
61*77c1e3ccSAndroid Build Coastguard Worker   const uint8_t *dgd_win = dgd - wiener_halfwin * dgd_stride - wiener_halfwin;
62*77c1e3ccSAndroid Build Coastguard Worker 
63*77c1e3ccSAndroid Build Coastguard Worker   // Main loop handles two pixels at a time
64*77c1e3ccSAndroid Build Coastguard Worker   // We can assume that h_start is even, since it will always be aligned to
65*77c1e3ccSAndroid Build Coastguard Worker   // a tile edge + some number of restoration units, and both of those will
66*77c1e3ccSAndroid Build Coastguard Worker   // be 64-pixel aligned.
67*77c1e3ccSAndroid Build Coastguard Worker   // However, at the edge of the image, h_end may be odd, so we need to handle
68*77c1e3ccSAndroid Build Coastguard Worker   // that case correctly.
69*77c1e3ccSAndroid Build Coastguard Worker   assert(h_start % 2 == 0);
70*77c1e3ccSAndroid Build Coastguard Worker   for (i = v_start; i < v_end; i = i + downsample_factor) {
71*77c1e3ccSAndroid Build Coastguard Worker     if (use_downsampled_wiener_stats &&
72*77c1e3ccSAndroid Build Coastguard Worker         (v_end - i < WIENER_STATS_DOWNSAMPLE_FACTOR)) {
73*77c1e3ccSAndroid Build Coastguard Worker       downsample_factor = v_end - i;
74*77c1e3ccSAndroid Build Coastguard Worker     }
75*77c1e3ccSAndroid Build Coastguard Worker     int32_t sumX_row_i32 = 0;
76*77c1e3ccSAndroid Build Coastguard Worker     std::vector<std::vector<int32_t> > sumY_row(
77*77c1e3ccSAndroid Build Coastguard Worker         wiener_win, std::vector<int32_t>(wiener_win, 0));
78*77c1e3ccSAndroid Build Coastguard Worker     std::vector<std::vector<int32_t> > M_row_i32(
79*77c1e3ccSAndroid Build Coastguard Worker         wiener_win, std::vector<int32_t>(wiener_win, 0));
80*77c1e3ccSAndroid Build Coastguard Worker     std::vector<std::vector<int32_t> > H_row_i32(
81*77c1e3ccSAndroid Build Coastguard Worker         wiener_win * wiener_win, std::vector<int32_t>(wiener_win * 8, 0));
82*77c1e3ccSAndroid Build Coastguard Worker     const int h_end_even = h_end & ~1;
83*77c1e3ccSAndroid Build Coastguard Worker     const int has_odd_pixel = h_end & 1;
84*77c1e3ccSAndroid Build Coastguard Worker     for (j = h_start; j < h_end_even; j += 2) {
85*77c1e3ccSAndroid Build Coastguard Worker       const uint8_t X1 = src[i * src_stride + j];
86*77c1e3ccSAndroid Build Coastguard Worker       const uint8_t X2 = src[i * src_stride + j + 1];
87*77c1e3ccSAndroid Build Coastguard Worker       sumX_row_i32 += X1 + X2;
88*77c1e3ccSAndroid Build Coastguard Worker 
89*77c1e3ccSAndroid Build Coastguard Worker       const uint8_t *dgd_ij = dgd_win + i * dgd_stride + j;
90*77c1e3ccSAndroid Build Coastguard Worker       for (k = 0; k < wiener_win; k++) {
91*77c1e3ccSAndroid Build Coastguard Worker         for (l = 0; l < wiener_win; l++) {
92*77c1e3ccSAndroid Build Coastguard Worker           const uint8_t *dgd_ijkl = dgd_ij + k * dgd_stride + l;
93*77c1e3ccSAndroid Build Coastguard Worker           int32_t *H_int_temp = &H_row_i32[(l * wiener_win + k)][0];
94*77c1e3ccSAndroid Build Coastguard Worker           const uint8_t D1 = dgd_ijkl[0];
95*77c1e3ccSAndroid Build Coastguard Worker           const uint8_t D2 = dgd_ijkl[1];
96*77c1e3ccSAndroid Build Coastguard Worker           sumY_row[k][l] += D1 + D2;
97*77c1e3ccSAndroid Build Coastguard Worker           M_row_i32[l][k] += D1 * X1 + D2 * X2;
98*77c1e3ccSAndroid Build Coastguard Worker           for (m = 0; m < wiener_win; m++) {
99*77c1e3ccSAndroid Build Coastguard Worker             for (n = 0; n < wiener_win; n++) {
100*77c1e3ccSAndroid Build Coastguard Worker               H_int_temp[m * 8 + n] += D1 * dgd_ij[n + dgd_stride * m] +
101*77c1e3ccSAndroid Build Coastguard Worker                                        D2 * dgd_ij[n + dgd_stride * m + 1];
102*77c1e3ccSAndroid Build Coastguard Worker             }
103*77c1e3ccSAndroid Build Coastguard Worker           }
104*77c1e3ccSAndroid Build Coastguard Worker         }
105*77c1e3ccSAndroid Build Coastguard Worker       }
106*77c1e3ccSAndroid Build Coastguard Worker     }
107*77c1e3ccSAndroid Build Coastguard Worker     // If the width is odd, add in the final pixel
108*77c1e3ccSAndroid Build Coastguard Worker     if (has_odd_pixel) {
109*77c1e3ccSAndroid Build Coastguard Worker       const uint8_t X1 = src[i * src_stride + j];
110*77c1e3ccSAndroid Build Coastguard Worker       sumX_row_i32 += X1;
111*77c1e3ccSAndroid Build Coastguard Worker 
112*77c1e3ccSAndroid Build Coastguard Worker       const uint8_t *dgd_ij = dgd_win + i * dgd_stride + j;
113*77c1e3ccSAndroid Build Coastguard Worker       for (k = 0; k < wiener_win; k++) {
114*77c1e3ccSAndroid Build Coastguard Worker         for (l = 0; l < wiener_win; l++) {
115*77c1e3ccSAndroid Build Coastguard Worker           const uint8_t *dgd_ijkl = dgd_ij + k * dgd_stride + l;
116*77c1e3ccSAndroid Build Coastguard Worker           int32_t *H_int_temp = &H_row_i32[(l * wiener_win + k)][0];
117*77c1e3ccSAndroid Build Coastguard Worker           const uint8_t D1 = dgd_ijkl[0];
118*77c1e3ccSAndroid Build Coastguard Worker           sumY_row[k][l] += D1;
119*77c1e3ccSAndroid Build Coastguard Worker           M_row_i32[l][k] += D1 * X1;
120*77c1e3ccSAndroid Build Coastguard Worker           for (m = 0; m < wiener_win; m++) {
121*77c1e3ccSAndroid Build Coastguard Worker             for (n = 0; n < wiener_win; n++) {
122*77c1e3ccSAndroid Build Coastguard Worker               H_int_temp[m * 8 + n] += D1 * dgd_ij[n + dgd_stride * m];
123*77c1e3ccSAndroid Build Coastguard Worker             }
124*77c1e3ccSAndroid Build Coastguard Worker           }
125*77c1e3ccSAndroid Build Coastguard Worker         }
126*77c1e3ccSAndroid Build Coastguard Worker       }
127*77c1e3ccSAndroid Build Coastguard Worker     }
128*77c1e3ccSAndroid Build Coastguard Worker 
129*77c1e3ccSAndroid Build Coastguard Worker     sumX += sumX_row_i32 * downsample_factor;
130*77c1e3ccSAndroid Build Coastguard Worker     // Scale M matrix based on the downsampling factor
131*77c1e3ccSAndroid Build Coastguard Worker     for (k = 0; k < wiener_win; ++k) {
132*77c1e3ccSAndroid Build Coastguard Worker       for (l = 0; l < wiener_win; ++l) {
133*77c1e3ccSAndroid Build Coastguard Worker         sumY[k][l] += sumY_row[k][l] * downsample_factor;
134*77c1e3ccSAndroid Build Coastguard Worker         M_int[k][l] += (int64_t)M_row_i32[k][l] * downsample_factor;
135*77c1e3ccSAndroid Build Coastguard Worker       }
136*77c1e3ccSAndroid Build Coastguard Worker     }
137*77c1e3ccSAndroid Build Coastguard Worker     // Scale H matrix based on the downsampling factor
138*77c1e3ccSAndroid Build Coastguard Worker     for (k = 0; k < wiener_win * wiener_win; ++k) {
139*77c1e3ccSAndroid Build Coastguard Worker       for (l = 0; l < wiener_win * 8; ++l) {
140*77c1e3ccSAndroid Build Coastguard Worker         H_int[k][l] += (int64_t)H_row_i32[k][l] * downsample_factor;
141*77c1e3ccSAndroid Build Coastguard Worker       }
142*77c1e3ccSAndroid Build Coastguard Worker     }
143*77c1e3ccSAndroid Build Coastguard Worker   }
144*77c1e3ccSAndroid Build Coastguard Worker 
145*77c1e3ccSAndroid Build Coastguard Worker   const int64_t avg_square_sum = (int64_t)avg * (int64_t)avg * pixel_count;
146*77c1e3ccSAndroid Build Coastguard Worker   for (k = 0; k < wiener_win; k++) {
147*77c1e3ccSAndroid Build Coastguard Worker     for (l = 0; l < wiener_win; l++) {
148*77c1e3ccSAndroid Build Coastguard Worker       M[l * wiener_win + k] =
149*77c1e3ccSAndroid Build Coastguard Worker           M_int[l][k] + avg_square_sum - (int64_t)avg * (sumX + sumY[k][l]);
150*77c1e3ccSAndroid Build Coastguard Worker       for (m = 0; m < wiener_win; m++) {
151*77c1e3ccSAndroid Build Coastguard Worker         for (n = 0; n < wiener_win; n++) {
152*77c1e3ccSAndroid Build Coastguard Worker           H[(l * wiener_win + k) * wiener_win2 + m * wiener_win + n] =
153*77c1e3ccSAndroid Build Coastguard Worker               H_int[(l * wiener_win + k)][n * 8 + m] + avg_square_sum -
154*77c1e3ccSAndroid Build Coastguard Worker               (int64_t)avg * (sumY[k][l] + sumY[n][m]);
155*77c1e3ccSAndroid Build Coastguard Worker         }
156*77c1e3ccSAndroid Build Coastguard Worker       }
157*77c1e3ccSAndroid Build Coastguard Worker     }
158*77c1e3ccSAndroid Build Coastguard Worker   }
159*77c1e3ccSAndroid Build Coastguard Worker }
160*77c1e3ccSAndroid Build Coastguard Worker 
compute_stats_opt_c(int wiener_win,const uint8_t * dgd,const uint8_t * src,int16_t * d,int16_t * s,int h_start,int h_end,int v_start,int v_end,int dgd_stride,int src_stride,int64_t * M,int64_t * H,int use_downsampled_wiener_stats)161*77c1e3ccSAndroid Build Coastguard Worker static void compute_stats_opt_c(int wiener_win, const uint8_t *dgd,
162*77c1e3ccSAndroid Build Coastguard Worker                                 const uint8_t *src, int16_t *d, int16_t *s,
163*77c1e3ccSAndroid Build Coastguard Worker                                 int h_start, int h_end, int v_start, int v_end,
164*77c1e3ccSAndroid Build Coastguard Worker                                 int dgd_stride, int src_stride, int64_t *M,
165*77c1e3ccSAndroid Build Coastguard Worker                                 int64_t *H, int use_downsampled_wiener_stats) {
166*77c1e3ccSAndroid Build Coastguard Worker   if (wiener_win == WIENER_WIN || wiener_win == WIENER_WIN_CHROMA) {
167*77c1e3ccSAndroid Build Coastguard Worker     compute_stats_win_opt_c(wiener_win, dgd, src, d, s, h_start, h_end, v_start,
168*77c1e3ccSAndroid Build Coastguard Worker                             v_end, dgd_stride, src_stride, M, H,
169*77c1e3ccSAndroid Build Coastguard Worker                             use_downsampled_wiener_stats);
170*77c1e3ccSAndroid Build Coastguard Worker   } else {
171*77c1e3ccSAndroid Build Coastguard Worker     av1_compute_stats_c(wiener_win, dgd, src, d, s, h_start, h_end, v_start,
172*77c1e3ccSAndroid Build Coastguard Worker                         v_end, dgd_stride, src_stride, M, H,
173*77c1e3ccSAndroid Build Coastguard Worker                         use_downsampled_wiener_stats);
174*77c1e3ccSAndroid Build Coastguard Worker   }
175*77c1e3ccSAndroid Build Coastguard Worker }
176*77c1e3ccSAndroid Build Coastguard Worker 
177*77c1e3ccSAndroid Build Coastguard Worker static const int kIterations = 100;
178*77c1e3ccSAndroid Build Coastguard Worker typedef void (*compute_stats_Func)(int wiener_win, const uint8_t *dgd,
179*77c1e3ccSAndroid Build Coastguard Worker                                    const uint8_t *src, int16_t *dgd_avg,
180*77c1e3ccSAndroid Build Coastguard Worker                                    int16_t *src_avg, int h_start, int h_end,
181*77c1e3ccSAndroid Build Coastguard Worker                                    int v_start, int v_end, int dgd_stride,
182*77c1e3ccSAndroid Build Coastguard Worker                                    int src_stride, int64_t *M, int64_t *H,
183*77c1e3ccSAndroid Build Coastguard Worker                                    int use_downsampled_wiener_stats);
184*77c1e3ccSAndroid Build Coastguard Worker 
185*77c1e3ccSAndroid Build Coastguard Worker ////////////////////////////////////////////////////////////////////////////////
186*77c1e3ccSAndroid Build Coastguard Worker // 8 bit
187*77c1e3ccSAndroid Build Coastguard Worker ////////////////////////////////////////////////////////////////////////////////
188*77c1e3ccSAndroid Build Coastguard Worker 
189*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<const compute_stats_Func> WienerTestParam;
190*77c1e3ccSAndroid Build Coastguard Worker 
191*77c1e3ccSAndroid Build Coastguard Worker class WienerTest : public ::testing::TestWithParam<WienerTestParam> {
192*77c1e3ccSAndroid Build Coastguard Worker  public:
SetUp()193*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
194*77c1e3ccSAndroid Build Coastguard Worker     src_buf = (uint8_t *)aom_memalign(
195*77c1e3ccSAndroid Build Coastguard Worker         32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
196*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(src_buf, nullptr);
197*77c1e3ccSAndroid Build Coastguard Worker     dgd_buf = (uint8_t *)aom_memalign(
198*77c1e3ccSAndroid Build Coastguard Worker         32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
199*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(dgd_buf, nullptr);
200*77c1e3ccSAndroid Build Coastguard Worker     const int buf_size =
201*77c1e3ccSAndroid Build Coastguard Worker         sizeof(*buf) * 6 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX;
202*77c1e3ccSAndroid Build Coastguard Worker     buf = (int16_t *)aom_memalign(32, buf_size);
203*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(buf, nullptr);
204*77c1e3ccSAndroid Build Coastguard Worker     memset(buf, 0, buf_size);
205*77c1e3ccSAndroid Build Coastguard Worker     target_func_ = GET_PARAM(0);
206*77c1e3ccSAndroid Build Coastguard Worker   }
TearDown()207*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
208*77c1e3ccSAndroid Build Coastguard Worker     aom_free(src_buf);
209*77c1e3ccSAndroid Build Coastguard Worker     aom_free(dgd_buf);
210*77c1e3ccSAndroid Build Coastguard Worker     aom_free(buf);
211*77c1e3ccSAndroid Build Coastguard Worker   }
212*77c1e3ccSAndroid Build Coastguard Worker   void RunWienerTest(const int32_t wiener_win, int32_t run_times);
213*77c1e3ccSAndroid Build Coastguard Worker   void RunWienerTest_ExtremeValues(const int32_t wiener_win);
214*77c1e3ccSAndroid Build Coastguard Worker 
215*77c1e3ccSAndroid Build Coastguard Worker  private:
216*77c1e3ccSAndroid Build Coastguard Worker   compute_stats_Func target_func_;
217*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rng_;
218*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *src_buf;
219*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *dgd_buf;
220*77c1e3ccSAndroid Build Coastguard Worker   int16_t *buf;
221*77c1e3ccSAndroid Build Coastguard Worker };
222*77c1e3ccSAndroid Build Coastguard Worker 
RunWienerTest(const int32_t wiener_win,int32_t run_times)223*77c1e3ccSAndroid Build Coastguard Worker void WienerTest::RunWienerTest(const int32_t wiener_win, int32_t run_times) {
224*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_halfwin = wiener_win >> 1;
225*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_win2 = wiener_win * wiener_win;
226*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
227*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
228*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
229*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_test[WIENER_WIN2 * WIENER_WIN2]);
230*77c1e3ccSAndroid Build Coastguard Worker   // Note(rachelbarker):
231*77c1e3ccSAndroid Build Coastguard Worker   // The SIMD code requires `h_start` to be even, but can otherwise
232*77c1e3ccSAndroid Build Coastguard Worker   // deal with any values of `h_end`, `v_start`, `v_end`. We cover this
233*77c1e3ccSAndroid Build Coastguard Worker   // entire range, even though (at the time of writing) `h_start` and `v_start`
234*77c1e3ccSAndroid Build Coastguard Worker   // will always be multiples of 64 when called from non-test code.
235*77c1e3ccSAndroid Build Coastguard Worker   // If in future any new requirements are added, these lines will
236*77c1e3ccSAndroid Build Coastguard Worker   // need changing.
237*77c1e3ccSAndroid Build Coastguard Worker   int h_start = (rng_.Rand16() % (MAX_WIENER_BLOCK / 2)) & ~1;
238*77c1e3ccSAndroid Build Coastguard Worker   int h_end = run_times != 1 ? 256 : (rng_.Rand16() % MAX_WIENER_BLOCK);
239*77c1e3ccSAndroid Build Coastguard Worker   if (h_start > h_end) std::swap(h_start, h_end);
240*77c1e3ccSAndroid Build Coastguard Worker   int v_start = rng_.Rand16() % (MAX_WIENER_BLOCK / 2);
241*77c1e3ccSAndroid Build Coastguard Worker   int v_end = run_times != 1 ? 256 : (rng_.Rand16() % MAX_WIENER_BLOCK);
242*77c1e3ccSAndroid Build Coastguard Worker   if (v_start > v_end) std::swap(v_start, v_end);
243*77c1e3ccSAndroid Build Coastguard Worker   const int dgd_stride = h_end;
244*77c1e3ccSAndroid Build Coastguard Worker   const int src_stride = MAX_DATA_BLOCK;
245*77c1e3ccSAndroid Build Coastguard Worker   const int iters = run_times == 1 ? kIterations : 2;
246*77c1e3ccSAndroid Build Coastguard Worker   const int max_value_downsample_stats = 1;
247*77c1e3ccSAndroid Build Coastguard Worker   int16_t *dgd_avg = buf;
248*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_avg =
249*77c1e3ccSAndroid Build Coastguard Worker       buf + (3 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX);
250*77c1e3ccSAndroid Build Coastguard Worker 
251*77c1e3ccSAndroid Build Coastguard Worker   for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
252*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
253*77c1e3ccSAndroid Build Coastguard Worker       dgd_buf[i] = rng_.Rand8();
254*77c1e3ccSAndroid Build Coastguard Worker       src_buf[i] = rng_.Rand8();
255*77c1e3ccSAndroid Build Coastguard Worker     }
256*77c1e3ccSAndroid Build Coastguard Worker     uint8_t *dgd = dgd_buf + wiener_halfwin * MAX_DATA_BLOCK + wiener_halfwin;
257*77c1e3ccSAndroid Build Coastguard Worker     uint8_t *src = src_buf;
258*77c1e3ccSAndroid Build Coastguard Worker     for (int use_downsampled_stats = 0;
259*77c1e3ccSAndroid Build Coastguard Worker          use_downsampled_stats <= max_value_downsample_stats;
260*77c1e3ccSAndroid Build Coastguard Worker          use_downsampled_stats++) {
261*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer timer;
262*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_start(&timer);
263*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < run_times; ++i) {
264*77c1e3ccSAndroid Build Coastguard Worker         av1_compute_stats_c(wiener_win, dgd, src, dgd_avg, src_avg, h_start,
265*77c1e3ccSAndroid Build Coastguard Worker                             h_end, v_start, v_end, dgd_stride, src_stride,
266*77c1e3ccSAndroid Build Coastguard Worker                             M_ref, H_ref, use_downsampled_stats);
267*77c1e3ccSAndroid Build Coastguard Worker       }
268*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_mark(&timer);
269*77c1e3ccSAndroid Build Coastguard Worker       const double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer));
270*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_start(&timer);
271*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < run_times; ++i) {
272*77c1e3ccSAndroid Build Coastguard Worker         target_func_(wiener_win, dgd, src, dgd_avg, src_avg, h_start, h_end,
273*77c1e3ccSAndroid Build Coastguard Worker                      v_start, v_end, dgd_stride, src_stride, M_test, H_test,
274*77c1e3ccSAndroid Build Coastguard Worker                      use_downsampled_stats);
275*77c1e3ccSAndroid Build Coastguard Worker       }
276*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_mark(&timer);
277*77c1e3ccSAndroid Build Coastguard Worker       const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer));
278*77c1e3ccSAndroid Build Coastguard Worker       if (run_times > 10) {
279*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d %3dx%-3d:%7.2f/%7.2fns", wiener_win, h_end, v_end, time1,
280*77c1e3ccSAndroid Build Coastguard Worker                time2);
281*77c1e3ccSAndroid Build Coastguard Worker         printf("(%3.2f)\n", time1 / time2);
282*77c1e3ccSAndroid Build Coastguard Worker       }
283*77c1e3ccSAndroid Build Coastguard Worker       int failed = 0;
284*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < wiener_win2; ++i) {
285*77c1e3ccSAndroid Build Coastguard Worker         if (M_ref[i] != M_test[i]) {
286*77c1e3ccSAndroid Build Coastguard Worker           failed = 1;
287*77c1e3ccSAndroid Build Coastguard Worker           printf("win %d M iter %d [%4d] ref %6" PRId64 " test %6" PRId64 " \n",
288*77c1e3ccSAndroid Build Coastguard Worker                  wiener_win, iter, i, M_ref[i], M_test[i]);
289*77c1e3ccSAndroid Build Coastguard Worker           break;
290*77c1e3ccSAndroid Build Coastguard Worker         }
291*77c1e3ccSAndroid Build Coastguard Worker       }
292*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
293*77c1e3ccSAndroid Build Coastguard Worker         if (H_ref[i] != H_test[i]) {
294*77c1e3ccSAndroid Build Coastguard Worker           failed = 1;
295*77c1e3ccSAndroid Build Coastguard Worker           printf("win %d H iter %d [%4d] ref %6" PRId64 " test %6" PRId64 " \n",
296*77c1e3ccSAndroid Build Coastguard Worker                  wiener_win, iter, i, H_ref[i], H_test[i]);
297*77c1e3ccSAndroid Build Coastguard Worker           break;
298*77c1e3ccSAndroid Build Coastguard Worker         }
299*77c1e3ccSAndroid Build Coastguard Worker       }
300*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(failed, 0);
301*77c1e3ccSAndroid Build Coastguard Worker     }
302*77c1e3ccSAndroid Build Coastguard Worker   }
303*77c1e3ccSAndroid Build Coastguard Worker }
304*77c1e3ccSAndroid Build Coastguard Worker 
RunWienerTest_ExtremeValues(const int32_t wiener_win)305*77c1e3ccSAndroid Build Coastguard Worker void WienerTest::RunWienerTest_ExtremeValues(const int32_t wiener_win) {
306*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_halfwin = wiener_win >> 1;
307*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_win2 = wiener_win * wiener_win;
308*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
309*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
310*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
311*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_test[WIENER_WIN2 * WIENER_WIN2]);
312*77c1e3ccSAndroid Build Coastguard Worker   const int h_start = 16;
313*77c1e3ccSAndroid Build Coastguard Worker   const int h_end = MAX_WIENER_BLOCK;
314*77c1e3ccSAndroid Build Coastguard Worker   const int v_start = 16;
315*77c1e3ccSAndroid Build Coastguard Worker   const int v_end = MAX_WIENER_BLOCK;
316*77c1e3ccSAndroid Build Coastguard Worker   const int dgd_stride = h_end;
317*77c1e3ccSAndroid Build Coastguard Worker   const int src_stride = MAX_DATA_BLOCK;
318*77c1e3ccSAndroid Build Coastguard Worker   const int iters = 1;
319*77c1e3ccSAndroid Build Coastguard Worker   const int max_value_downsample_stats = 1;
320*77c1e3ccSAndroid Build Coastguard Worker   int16_t *dgd_avg = buf;
321*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_avg =
322*77c1e3ccSAndroid Build Coastguard Worker       buf + (3 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX);
323*77c1e3ccSAndroid Build Coastguard Worker 
324*77c1e3ccSAndroid Build Coastguard Worker   for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
325*77c1e3ccSAndroid Build Coastguard Worker     // Fill with alternating extreme values to maximize difference with
326*77c1e3ccSAndroid Build Coastguard Worker     // the average.
327*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
328*77c1e3ccSAndroid Build Coastguard Worker       dgd_buf[i] = i & 1 ? 255 : 0;
329*77c1e3ccSAndroid Build Coastguard Worker       src_buf[i] = i & 1 ? 255 : 0;
330*77c1e3ccSAndroid Build Coastguard Worker     }
331*77c1e3ccSAndroid Build Coastguard Worker     uint8_t *dgd = dgd_buf + wiener_halfwin * MAX_DATA_BLOCK + wiener_halfwin;
332*77c1e3ccSAndroid Build Coastguard Worker     uint8_t *src = src_buf;
333*77c1e3ccSAndroid Build Coastguard Worker     for (int use_downsampled_stats = 0;
334*77c1e3ccSAndroid Build Coastguard Worker          use_downsampled_stats <= max_value_downsample_stats;
335*77c1e3ccSAndroid Build Coastguard Worker          use_downsampled_stats++) {
336*77c1e3ccSAndroid Build Coastguard Worker       av1_compute_stats_c(wiener_win, dgd, src, dgd_avg, src_avg, h_start,
337*77c1e3ccSAndroid Build Coastguard Worker                           h_end, v_start, v_end, dgd_stride, src_stride, M_ref,
338*77c1e3ccSAndroid Build Coastguard Worker                           H_ref, use_downsampled_stats);
339*77c1e3ccSAndroid Build Coastguard Worker 
340*77c1e3ccSAndroid Build Coastguard Worker       target_func_(wiener_win, dgd, src, dgd_avg, src_avg, h_start, h_end,
341*77c1e3ccSAndroid Build Coastguard Worker                    v_start, v_end, dgd_stride, src_stride, M_test, H_test,
342*77c1e3ccSAndroid Build Coastguard Worker                    use_downsampled_stats);
343*77c1e3ccSAndroid Build Coastguard Worker 
344*77c1e3ccSAndroid Build Coastguard Worker       int failed = 0;
345*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < wiener_win2; ++i) {
346*77c1e3ccSAndroid Build Coastguard Worker         if (M_ref[i] != M_test[i]) {
347*77c1e3ccSAndroid Build Coastguard Worker           failed = 1;
348*77c1e3ccSAndroid Build Coastguard Worker           printf("win %d M iter %d [%4d] ref %6" PRId64 " test %6" PRId64 " \n",
349*77c1e3ccSAndroid Build Coastguard Worker                  wiener_win, iter, i, M_ref[i], M_test[i]);
350*77c1e3ccSAndroid Build Coastguard Worker           break;
351*77c1e3ccSAndroid Build Coastguard Worker         }
352*77c1e3ccSAndroid Build Coastguard Worker       }
353*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
354*77c1e3ccSAndroid Build Coastguard Worker         if (H_ref[i] != H_test[i]) {
355*77c1e3ccSAndroid Build Coastguard Worker           failed = 1;
356*77c1e3ccSAndroid Build Coastguard Worker           printf("win %d H iter %d [%4d] ref %6" PRId64 " test %6" PRId64 " \n",
357*77c1e3ccSAndroid Build Coastguard Worker                  wiener_win, iter, i, H_ref[i], H_test[i]);
358*77c1e3ccSAndroid Build Coastguard Worker           break;
359*77c1e3ccSAndroid Build Coastguard Worker         }
360*77c1e3ccSAndroid Build Coastguard Worker       }
361*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(failed, 0);
362*77c1e3ccSAndroid Build Coastguard Worker     }
363*77c1e3ccSAndroid Build Coastguard Worker   }
364*77c1e3ccSAndroid Build Coastguard Worker }
365*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTest,RandomValues)366*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTest, RandomValues) {
367*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 1);
368*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 1);
369*77c1e3ccSAndroid Build Coastguard Worker }
370*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTest,ExtremeValues)371*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTest, ExtremeValues) {
372*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN);
373*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA);
374*77c1e3ccSAndroid Build Coastguard Worker }
375*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTest,DISABLED_Speed)376*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTest, DISABLED_Speed) {
377*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 200);
378*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 200);
379*77c1e3ccSAndroid Build Coastguard Worker }
380*77c1e3ccSAndroid Build Coastguard Worker 
381*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(C, WienerTest, ::testing::Values(compute_stats_opt_c));
382*77c1e3ccSAndroid Build Coastguard Worker 
383*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE4_1
384*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSE4_1, WienerTest,
385*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_sse4_1));
386*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SSE4_1
387*77c1e3ccSAndroid Build Coastguard Worker 
388*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
389*77c1e3ccSAndroid Build Coastguard Worker 
390*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(AVX2, WienerTest,
391*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_avx2));
392*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_AVX2
393*77c1e3ccSAndroid Build Coastguard Worker 
394*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
395*77c1e3ccSAndroid Build Coastguard Worker 
396*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(NEON, WienerTest,
397*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_neon));
398*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_NEON
399*77c1e3ccSAndroid Build Coastguard Worker 
400*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SVE
401*77c1e3ccSAndroid Build Coastguard Worker 
402*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SVE, WienerTest,
403*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_sve));
404*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SVE
405*77c1e3ccSAndroid Build Coastguard Worker 
406*77c1e3ccSAndroid Build Coastguard Worker }  // namespace wiener_lowbd
407*77c1e3ccSAndroid Build Coastguard Worker 
408*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
409*77c1e3ccSAndroid Build Coastguard Worker // High bit-depth tests:
410*77c1e3ccSAndroid Build Coastguard Worker namespace wiener_highbd {
411*77c1e3ccSAndroid Build Coastguard Worker 
compute_stats_highbd_win_opt_c(int wiener_win,const uint8_t * dgd8,const uint8_t * src8,int h_start,int h_end,int v_start,int v_end,int dgd_stride,int src_stride,int64_t * M,int64_t * H,aom_bit_depth_t bit_depth)412*77c1e3ccSAndroid Build Coastguard Worker static void compute_stats_highbd_win_opt_c(int wiener_win, const uint8_t *dgd8,
413*77c1e3ccSAndroid Build Coastguard Worker                                            const uint8_t *src8, int h_start,
414*77c1e3ccSAndroid Build Coastguard Worker                                            int h_end, int v_start, int v_end,
415*77c1e3ccSAndroid Build Coastguard Worker                                            int dgd_stride, int src_stride,
416*77c1e3ccSAndroid Build Coastguard Worker                                            int64_t *M, int64_t *H,
417*77c1e3ccSAndroid Build Coastguard Worker                                            aom_bit_depth_t bit_depth) {
418*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_TRUE(wiener_win == WIENER_WIN || wiener_win == WIENER_WIN_CHROMA);
419*77c1e3ccSAndroid Build Coastguard Worker   int i, j, k, l, m, n;
420*77c1e3ccSAndroid Build Coastguard Worker   const int pixel_count = (h_end - h_start) * (v_end - v_start);
421*77c1e3ccSAndroid Build Coastguard Worker   const int wiener_win2 = wiener_win * wiener_win;
422*77c1e3ccSAndroid Build Coastguard Worker   const int wiener_halfwin = (wiener_win >> 1);
423*77c1e3ccSAndroid Build Coastguard Worker   const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
424*77c1e3ccSAndroid Build Coastguard Worker   const uint16_t *dgd = CONVERT_TO_SHORTPTR(dgd8);
425*77c1e3ccSAndroid Build Coastguard Worker   const uint16_t avg =
426*77c1e3ccSAndroid Build Coastguard Worker       find_average_highbd(dgd, h_start, h_end, v_start, v_end, dgd_stride);
427*77c1e3ccSAndroid Build Coastguard Worker 
428*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int64_t> > M_int(wiener_win,
429*77c1e3ccSAndroid Build Coastguard Worker                                            std::vector<int64_t>(wiener_win, 0));
430*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int64_t> > H_int(
431*77c1e3ccSAndroid Build Coastguard Worker       wiener_win * wiener_win, std::vector<int64_t>(wiener_win * 8, 0));
432*77c1e3ccSAndroid Build Coastguard Worker   std::vector<std::vector<int32_t> > sumY(wiener_win,
433*77c1e3ccSAndroid Build Coastguard Worker                                           std::vector<int32_t>(wiener_win, 0));
434*77c1e3ccSAndroid Build Coastguard Worker 
435*77c1e3ccSAndroid Build Coastguard Worker   memset(M, 0, sizeof(*M) * wiener_win2);
436*77c1e3ccSAndroid Build Coastguard Worker   memset(H, 0, sizeof(*H) * wiener_win2 * wiener_win2);
437*77c1e3ccSAndroid Build Coastguard Worker 
438*77c1e3ccSAndroid Build Coastguard Worker   int64_t sumX = 0;
439*77c1e3ccSAndroid Build Coastguard Worker   const uint16_t *dgd_win = dgd - wiener_halfwin * dgd_stride - wiener_halfwin;
440*77c1e3ccSAndroid Build Coastguard Worker 
441*77c1e3ccSAndroid Build Coastguard Worker   // Main loop handles two pixels at a time
442*77c1e3ccSAndroid Build Coastguard Worker   // We can assume that h_start is even, since it will always be aligned to
443*77c1e3ccSAndroid Build Coastguard Worker   // a tile edge + some number of restoration units, and both of those will
444*77c1e3ccSAndroid Build Coastguard Worker   // be 64-pixel aligned.
445*77c1e3ccSAndroid Build Coastguard Worker   // However, at the edge of the image, h_end may be odd, so we need to handle
446*77c1e3ccSAndroid Build Coastguard Worker   // that case correctly.
447*77c1e3ccSAndroid Build Coastguard Worker   assert(h_start % 2 == 0);
448*77c1e3ccSAndroid Build Coastguard Worker   for (i = v_start; i < v_end; i++) {
449*77c1e3ccSAndroid Build Coastguard Worker     const int h_end_even = h_end & ~1;
450*77c1e3ccSAndroid Build Coastguard Worker     const int has_odd_pixel = h_end & 1;
451*77c1e3ccSAndroid Build Coastguard Worker     for (j = h_start; j < h_end_even; j += 2) {
452*77c1e3ccSAndroid Build Coastguard Worker       const uint16_t X1 = src[i * src_stride + j];
453*77c1e3ccSAndroid Build Coastguard Worker       const uint16_t X2 = src[i * src_stride + j + 1];
454*77c1e3ccSAndroid Build Coastguard Worker       sumX += X1 + X2;
455*77c1e3ccSAndroid Build Coastguard Worker 
456*77c1e3ccSAndroid Build Coastguard Worker       const uint16_t *dgd_ij = dgd_win + i * dgd_stride + j;
457*77c1e3ccSAndroid Build Coastguard Worker       for (k = 0; k < wiener_win; k++) {
458*77c1e3ccSAndroid Build Coastguard Worker         for (l = 0; l < wiener_win; l++) {
459*77c1e3ccSAndroid Build Coastguard Worker           const uint16_t *dgd_ijkl = dgd_ij + k * dgd_stride + l;
460*77c1e3ccSAndroid Build Coastguard Worker           int64_t *H_int_temp = &H_int[(l * wiener_win + k)][0];
461*77c1e3ccSAndroid Build Coastguard Worker           const uint16_t D1 = dgd_ijkl[0];
462*77c1e3ccSAndroid Build Coastguard Worker           const uint16_t D2 = dgd_ijkl[1];
463*77c1e3ccSAndroid Build Coastguard Worker           sumY[k][l] += D1 + D2;
464*77c1e3ccSAndroid Build Coastguard Worker           M_int[l][k] += D1 * X1 + D2 * X2;
465*77c1e3ccSAndroid Build Coastguard Worker           for (m = 0; m < wiener_win; m++) {
466*77c1e3ccSAndroid Build Coastguard Worker             for (n = 0; n < wiener_win; n++) {
467*77c1e3ccSAndroid Build Coastguard Worker               H_int_temp[m * 8 + n] += D1 * dgd_ij[n + dgd_stride * m] +
468*77c1e3ccSAndroid Build Coastguard Worker                                        D2 * dgd_ij[n + dgd_stride * m + 1];
469*77c1e3ccSAndroid Build Coastguard Worker             }
470*77c1e3ccSAndroid Build Coastguard Worker           }
471*77c1e3ccSAndroid Build Coastguard Worker         }
472*77c1e3ccSAndroid Build Coastguard Worker       }
473*77c1e3ccSAndroid Build Coastguard Worker     }
474*77c1e3ccSAndroid Build Coastguard Worker     // If the width is odd, add in the final pixel
475*77c1e3ccSAndroid Build Coastguard Worker     if (has_odd_pixel) {
476*77c1e3ccSAndroid Build Coastguard Worker       const uint16_t X1 = src[i * src_stride + j];
477*77c1e3ccSAndroid Build Coastguard Worker       sumX += X1;
478*77c1e3ccSAndroid Build Coastguard Worker 
479*77c1e3ccSAndroid Build Coastguard Worker       const uint16_t *dgd_ij = dgd_win + i * dgd_stride + j;
480*77c1e3ccSAndroid Build Coastguard Worker       for (k = 0; k < wiener_win; k++) {
481*77c1e3ccSAndroid Build Coastguard Worker         for (l = 0; l < wiener_win; l++) {
482*77c1e3ccSAndroid Build Coastguard Worker           const uint16_t *dgd_ijkl = dgd_ij + k * dgd_stride + l;
483*77c1e3ccSAndroid Build Coastguard Worker           int64_t *H_int_temp = &H_int[(l * wiener_win + k)][0];
484*77c1e3ccSAndroid Build Coastguard Worker           const uint16_t D1 = dgd_ijkl[0];
485*77c1e3ccSAndroid Build Coastguard Worker           sumY[k][l] += D1;
486*77c1e3ccSAndroid Build Coastguard Worker           M_int[l][k] += D1 * X1;
487*77c1e3ccSAndroid Build Coastguard Worker           for (m = 0; m < wiener_win; m++) {
488*77c1e3ccSAndroid Build Coastguard Worker             for (n = 0; n < wiener_win; n++) {
489*77c1e3ccSAndroid Build Coastguard Worker               H_int_temp[m * 8 + n] += D1 * dgd_ij[n + dgd_stride * m];
490*77c1e3ccSAndroid Build Coastguard Worker             }
491*77c1e3ccSAndroid Build Coastguard Worker           }
492*77c1e3ccSAndroid Build Coastguard Worker         }
493*77c1e3ccSAndroid Build Coastguard Worker       }
494*77c1e3ccSAndroid Build Coastguard Worker     }
495*77c1e3ccSAndroid Build Coastguard Worker   }
496*77c1e3ccSAndroid Build Coastguard Worker 
497*77c1e3ccSAndroid Build Coastguard Worker   uint8_t bit_depth_divider = 1;
498*77c1e3ccSAndroid Build Coastguard Worker   if (bit_depth == AOM_BITS_12)
499*77c1e3ccSAndroid Build Coastguard Worker     bit_depth_divider = 16;
500*77c1e3ccSAndroid Build Coastguard Worker   else if (bit_depth == AOM_BITS_10)
501*77c1e3ccSAndroid Build Coastguard Worker     bit_depth_divider = 4;
502*77c1e3ccSAndroid Build Coastguard Worker 
503*77c1e3ccSAndroid Build Coastguard Worker   const int64_t avg_square_sum = (int64_t)avg * (int64_t)avg * pixel_count;
504*77c1e3ccSAndroid Build Coastguard Worker   for (k = 0; k < wiener_win; k++) {
505*77c1e3ccSAndroid Build Coastguard Worker     for (l = 0; l < wiener_win; l++) {
506*77c1e3ccSAndroid Build Coastguard Worker       M[l * wiener_win + k] =
507*77c1e3ccSAndroid Build Coastguard Worker           (M_int[l][k] +
508*77c1e3ccSAndroid Build Coastguard Worker            (avg_square_sum - (int64_t)avg * (sumX + sumY[k][l]))) /
509*77c1e3ccSAndroid Build Coastguard Worker           bit_depth_divider;
510*77c1e3ccSAndroid Build Coastguard Worker       for (m = 0; m < wiener_win; m++) {
511*77c1e3ccSAndroid Build Coastguard Worker         for (n = 0; n < wiener_win; n++) {
512*77c1e3ccSAndroid Build Coastguard Worker           H[(l * wiener_win + k) * wiener_win2 + m * wiener_win + n] =
513*77c1e3ccSAndroid Build Coastguard Worker               (H_int[(l * wiener_win + k)][n * 8 + m] +
514*77c1e3ccSAndroid Build Coastguard Worker                (avg_square_sum - (int64_t)avg * (sumY[k][l] + sumY[n][m]))) /
515*77c1e3ccSAndroid Build Coastguard Worker               bit_depth_divider;
516*77c1e3ccSAndroid Build Coastguard Worker         }
517*77c1e3ccSAndroid Build Coastguard Worker       }
518*77c1e3ccSAndroid Build Coastguard Worker     }
519*77c1e3ccSAndroid Build Coastguard Worker   }
520*77c1e3ccSAndroid Build Coastguard Worker }
521*77c1e3ccSAndroid Build Coastguard Worker 
compute_stats_highbd_opt_c(int wiener_win,const uint8_t * dgd,const uint8_t * src,int16_t * d,int16_t * s,int h_start,int h_end,int v_start,int v_end,int dgd_stride,int src_stride,int64_t * M,int64_t * H,aom_bit_depth_t bit_depth)522*77c1e3ccSAndroid Build Coastguard Worker static void compute_stats_highbd_opt_c(int wiener_win, const uint8_t *dgd,
523*77c1e3ccSAndroid Build Coastguard Worker                                        const uint8_t *src, int16_t *d,
524*77c1e3ccSAndroid Build Coastguard Worker                                        int16_t *s, int h_start, int h_end,
525*77c1e3ccSAndroid Build Coastguard Worker                                        int v_start, int v_end, int dgd_stride,
526*77c1e3ccSAndroid Build Coastguard Worker                                        int src_stride, int64_t *M, int64_t *H,
527*77c1e3ccSAndroid Build Coastguard Worker                                        aom_bit_depth_t bit_depth) {
528*77c1e3ccSAndroid Build Coastguard Worker   if (wiener_win == WIENER_WIN || wiener_win == WIENER_WIN_CHROMA) {
529*77c1e3ccSAndroid Build Coastguard Worker     compute_stats_highbd_win_opt_c(wiener_win, dgd, src, h_start, h_end,
530*77c1e3ccSAndroid Build Coastguard Worker                                    v_start, v_end, dgd_stride, src_stride, M, H,
531*77c1e3ccSAndroid Build Coastguard Worker                                    bit_depth);
532*77c1e3ccSAndroid Build Coastguard Worker   } else {
533*77c1e3ccSAndroid Build Coastguard Worker     av1_compute_stats_highbd_c(wiener_win, dgd, src, d, s, h_start, h_end,
534*77c1e3ccSAndroid Build Coastguard Worker                                v_start, v_end, dgd_stride, src_stride, M, H,
535*77c1e3ccSAndroid Build Coastguard Worker                                bit_depth);
536*77c1e3ccSAndroid Build Coastguard Worker   }
537*77c1e3ccSAndroid Build Coastguard Worker }
538*77c1e3ccSAndroid Build Coastguard Worker 
539*77c1e3ccSAndroid Build Coastguard Worker static const int kIterations = 100;
540*77c1e3ccSAndroid Build Coastguard Worker typedef void (*compute_stats_Func)(int wiener_win, const uint8_t *dgd,
541*77c1e3ccSAndroid Build Coastguard Worker                                    const uint8_t *src, int16_t *d, int16_t *s,
542*77c1e3ccSAndroid Build Coastguard Worker                                    int h_start, int h_end, int v_start,
543*77c1e3ccSAndroid Build Coastguard Worker                                    int v_end, int dgd_stride, int src_stride,
544*77c1e3ccSAndroid Build Coastguard Worker                                    int64_t *M, int64_t *H,
545*77c1e3ccSAndroid Build Coastguard Worker                                    aom_bit_depth_t bit_depth);
546*77c1e3ccSAndroid Build Coastguard Worker 
547*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<const compute_stats_Func> WienerTestParam;
548*77c1e3ccSAndroid Build Coastguard Worker 
549*77c1e3ccSAndroid Build Coastguard Worker class WienerTestHighbd : public ::testing::TestWithParam<WienerTestParam> {
550*77c1e3ccSAndroid Build Coastguard Worker  public:
SetUp()551*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
552*77c1e3ccSAndroid Build Coastguard Worker     src_buf = (uint16_t *)aom_memalign(
553*77c1e3ccSAndroid Build Coastguard Worker         32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*src_buf));
554*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(src_buf, nullptr);
555*77c1e3ccSAndroid Build Coastguard Worker     dgd_buf = (uint16_t *)aom_memalign(
556*77c1e3ccSAndroid Build Coastguard Worker         32, MAX_DATA_BLOCK * MAX_DATA_BLOCK * sizeof(*dgd_buf));
557*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(dgd_buf, nullptr);
558*77c1e3ccSAndroid Build Coastguard Worker     const size_t buf_size =
559*77c1e3ccSAndroid Build Coastguard Worker         sizeof(*buf) * 6 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX;
560*77c1e3ccSAndroid Build Coastguard Worker     buf = (int16_t *)aom_memalign(32, buf_size);
561*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(buf, nullptr);
562*77c1e3ccSAndroid Build Coastguard Worker     memset(buf, 0, buf_size);
563*77c1e3ccSAndroid Build Coastguard Worker     target_func_ = GET_PARAM(0);
564*77c1e3ccSAndroid Build Coastguard Worker   }
TearDown()565*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
566*77c1e3ccSAndroid Build Coastguard Worker     aom_free(src_buf);
567*77c1e3ccSAndroid Build Coastguard Worker     aom_free(dgd_buf);
568*77c1e3ccSAndroid Build Coastguard Worker     aom_free(buf);
569*77c1e3ccSAndroid Build Coastguard Worker   }
570*77c1e3ccSAndroid Build Coastguard Worker   void RunWienerTest(const int32_t wiener_win, int32_t run_times,
571*77c1e3ccSAndroid Build Coastguard Worker                      aom_bit_depth_t bit_depth);
572*77c1e3ccSAndroid Build Coastguard Worker   void RunWienerTest_ExtremeValues(const int32_t wiener_win,
573*77c1e3ccSAndroid Build Coastguard Worker                                    aom_bit_depth_t bit_depth);
574*77c1e3ccSAndroid Build Coastguard Worker 
575*77c1e3ccSAndroid Build Coastguard Worker   void RunWienerTest_Overflow32bTest(const int32_t wiener_win,
576*77c1e3ccSAndroid Build Coastguard Worker                                      aom_bit_depth_t bit_depth);
577*77c1e3ccSAndroid Build Coastguard Worker 
578*77c1e3ccSAndroid Build Coastguard Worker  private:
579*77c1e3ccSAndroid Build Coastguard Worker   compute_stats_Func target_func_;
580*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rng_;
581*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *src_buf;
582*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *dgd_buf;
583*77c1e3ccSAndroid Build Coastguard Worker   int16_t *buf;
584*77c1e3ccSAndroid Build Coastguard Worker };
585*77c1e3ccSAndroid Build Coastguard Worker 
RunWienerTest(const int32_t wiener_win,int32_t run_times,aom_bit_depth_t bit_depth)586*77c1e3ccSAndroid Build Coastguard Worker void WienerTestHighbd::RunWienerTest(const int32_t wiener_win,
587*77c1e3ccSAndroid Build Coastguard Worker                                      int32_t run_times,
588*77c1e3ccSAndroid Build Coastguard Worker                                      aom_bit_depth_t bit_depth) {
589*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_halfwin = wiener_win >> 1;
590*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_win2 = wiener_win * wiener_win;
591*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
592*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
593*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
594*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_test[WIENER_WIN2 * WIENER_WIN2]);
595*77c1e3ccSAndroid Build Coastguard Worker   // Note(rachelbarker):
596*77c1e3ccSAndroid Build Coastguard Worker   // The SIMD code requires `h_start` to be even, but can otherwise
597*77c1e3ccSAndroid Build Coastguard Worker   // deal with any values of `h_end`, `v_start`, `v_end`. We cover this
598*77c1e3ccSAndroid Build Coastguard Worker   // entire range, even though (at the time of writing) `h_start` and `v_start`
599*77c1e3ccSAndroid Build Coastguard Worker   // will always be multiples of 64 when called from non-test code.
600*77c1e3ccSAndroid Build Coastguard Worker   // If in future any new requirements are added, these lines will
601*77c1e3ccSAndroid Build Coastguard Worker   // need changing.
602*77c1e3ccSAndroid Build Coastguard Worker   int h_start = (rng_.Rand16() % (MAX_WIENER_BLOCK / 2)) & ~1;
603*77c1e3ccSAndroid Build Coastguard Worker   int h_end = run_times != 1 ? 256 : (rng_.Rand16() % MAX_WIENER_BLOCK);
604*77c1e3ccSAndroid Build Coastguard Worker   if (h_start > h_end) std::swap(h_start, h_end);
605*77c1e3ccSAndroid Build Coastguard Worker   int v_start = rng_.Rand16() % (MAX_WIENER_BLOCK / 2);
606*77c1e3ccSAndroid Build Coastguard Worker   int v_end = run_times != 1 ? 256 : (rng_.Rand16() % MAX_WIENER_BLOCK);
607*77c1e3ccSAndroid Build Coastguard Worker   if (v_start > v_end) std::swap(v_start, v_end);
608*77c1e3ccSAndroid Build Coastguard Worker   const int dgd_stride = h_end;
609*77c1e3ccSAndroid Build Coastguard Worker   const int src_stride = MAX_DATA_BLOCK;
610*77c1e3ccSAndroid Build Coastguard Worker   const int iters = run_times == 1 ? kIterations : 2;
611*77c1e3ccSAndroid Build Coastguard Worker   int16_t *dgd_avg = buf;
612*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_avg =
613*77c1e3ccSAndroid Build Coastguard Worker       buf + (3 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX);
614*77c1e3ccSAndroid Build Coastguard Worker   for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
615*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
616*77c1e3ccSAndroid Build Coastguard Worker       dgd_buf[i] = rng_.Rand16() % (1 << bit_depth);
617*77c1e3ccSAndroid Build Coastguard Worker       src_buf[i] = rng_.Rand16() % (1 << bit_depth);
618*77c1e3ccSAndroid Build Coastguard Worker     }
619*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *dgd8 = CONVERT_TO_BYTEPTR(
620*77c1e3ccSAndroid Build Coastguard Worker         dgd_buf + wiener_halfwin * MAX_DATA_BLOCK + wiener_halfwin);
621*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *src8 = CONVERT_TO_BYTEPTR(src_buf);
622*77c1e3ccSAndroid Build Coastguard Worker 
623*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
624*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
625*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < run_times; ++i) {
626*77c1e3ccSAndroid Build Coastguard Worker       av1_compute_stats_highbd_c(wiener_win, dgd8, src8, dgd_avg, src_avg,
627*77c1e3ccSAndroid Build Coastguard Worker                                  h_start, h_end, v_start, v_end, dgd_stride,
628*77c1e3ccSAndroid Build Coastguard Worker                                  src_stride, M_ref, H_ref, bit_depth);
629*77c1e3ccSAndroid Build Coastguard Worker     }
630*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
631*77c1e3ccSAndroid Build Coastguard Worker     const double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer));
632*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
633*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < run_times; ++i) {
634*77c1e3ccSAndroid Build Coastguard Worker       target_func_(wiener_win, dgd8, src8, dgd_avg, src_avg, h_start, h_end,
635*77c1e3ccSAndroid Build Coastguard Worker                    v_start, v_end, dgd_stride, src_stride, M_test, H_test,
636*77c1e3ccSAndroid Build Coastguard Worker                    bit_depth);
637*77c1e3ccSAndroid Build Coastguard Worker     }
638*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
639*77c1e3ccSAndroid Build Coastguard Worker     const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer));
640*77c1e3ccSAndroid Build Coastguard Worker     if (run_times > 10) {
641*77c1e3ccSAndroid Build Coastguard Worker       printf("win %d bd %d %3dx%-3d:%7.2f/%7.2fns", wiener_win, bit_depth,
642*77c1e3ccSAndroid Build Coastguard Worker              h_end, v_end, time1, time2);
643*77c1e3ccSAndroid Build Coastguard Worker       printf("(%3.2f)\n", time1 / time2);
644*77c1e3ccSAndroid Build Coastguard Worker     }
645*77c1e3ccSAndroid Build Coastguard Worker     int failed = 0;
646*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2; ++i) {
647*77c1e3ccSAndroid Build Coastguard Worker       if (M_ref[i] != M_test[i]) {
648*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
649*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d M iter %d [%4d] ref %6" PRId64 " test %6" PRId64
650*77c1e3ccSAndroid Build Coastguard Worker                " \n",
651*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, M_ref[i], M_test[i]);
652*77c1e3ccSAndroid Build Coastguard Worker         break;
653*77c1e3ccSAndroid Build Coastguard Worker       }
654*77c1e3ccSAndroid Build Coastguard Worker     }
655*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
656*77c1e3ccSAndroid Build Coastguard Worker       if (H_ref[i] != H_test[i]) {
657*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
658*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d H iter %d [%4d] ref %6" PRId64 " test %6" PRId64
659*77c1e3ccSAndroid Build Coastguard Worker                " \n",
660*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, H_ref[i], H_test[i]);
661*77c1e3ccSAndroid Build Coastguard Worker         break;
662*77c1e3ccSAndroid Build Coastguard Worker       }
663*77c1e3ccSAndroid Build Coastguard Worker     }
664*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(failed, 0);
665*77c1e3ccSAndroid Build Coastguard Worker   }
666*77c1e3ccSAndroid Build Coastguard Worker }
667*77c1e3ccSAndroid Build Coastguard Worker 
RunWienerTest_ExtremeValues(const int32_t wiener_win,aom_bit_depth_t bit_depth)668*77c1e3ccSAndroid Build Coastguard Worker void WienerTestHighbd::RunWienerTest_ExtremeValues(const int32_t wiener_win,
669*77c1e3ccSAndroid Build Coastguard Worker                                                    aom_bit_depth_t bit_depth) {
670*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_halfwin = wiener_win >> 1;
671*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_win2 = wiener_win * wiener_win;
672*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
673*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
674*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
675*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_test[WIENER_WIN2 * WIENER_WIN2]);
676*77c1e3ccSAndroid Build Coastguard Worker   const int h_start = 16;
677*77c1e3ccSAndroid Build Coastguard Worker   const int h_end = MAX_WIENER_BLOCK;
678*77c1e3ccSAndroid Build Coastguard Worker   const int v_start = 16;
679*77c1e3ccSAndroid Build Coastguard Worker   const int v_end = MAX_WIENER_BLOCK;
680*77c1e3ccSAndroid Build Coastguard Worker   const int dgd_stride = h_end;
681*77c1e3ccSAndroid Build Coastguard Worker   const int src_stride = MAX_DATA_BLOCK;
682*77c1e3ccSAndroid Build Coastguard Worker   const int iters = 1;
683*77c1e3ccSAndroid Build Coastguard Worker   int16_t *dgd_avg = buf;
684*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_avg =
685*77c1e3ccSAndroid Build Coastguard Worker       buf + (3 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX);
686*77c1e3ccSAndroid Build Coastguard Worker   for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
687*77c1e3ccSAndroid Build Coastguard Worker     // Fill with alternating extreme values to maximize difference with
688*77c1e3ccSAndroid Build Coastguard Worker     // the average.
689*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
690*77c1e3ccSAndroid Build Coastguard Worker       dgd_buf[i] = i & 1 ? ((uint16_t)1 << bit_depth) - 1 : 0;
691*77c1e3ccSAndroid Build Coastguard Worker       src_buf[i] = i & 1 ? ((uint16_t)1 << bit_depth) - 1 : 0;
692*77c1e3ccSAndroid Build Coastguard Worker     }
693*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *dgd8 = CONVERT_TO_BYTEPTR(
694*77c1e3ccSAndroid Build Coastguard Worker         dgd_buf + wiener_halfwin * MAX_DATA_BLOCK + wiener_halfwin);
695*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *src8 = CONVERT_TO_BYTEPTR(src_buf);
696*77c1e3ccSAndroid Build Coastguard Worker 
697*77c1e3ccSAndroid Build Coastguard Worker     av1_compute_stats_highbd_c(wiener_win, dgd8, src8, dgd_avg, src_avg,
698*77c1e3ccSAndroid Build Coastguard Worker                                h_start, h_end, v_start, v_end, dgd_stride,
699*77c1e3ccSAndroid Build Coastguard Worker                                src_stride, M_ref, H_ref, bit_depth);
700*77c1e3ccSAndroid Build Coastguard Worker 
701*77c1e3ccSAndroid Build Coastguard Worker     target_func_(wiener_win, dgd8, src8, dgd_avg, src_avg, h_start, h_end,
702*77c1e3ccSAndroid Build Coastguard Worker                  v_start, v_end, dgd_stride, src_stride, M_test, H_test,
703*77c1e3ccSAndroid Build Coastguard Worker                  bit_depth);
704*77c1e3ccSAndroid Build Coastguard Worker 
705*77c1e3ccSAndroid Build Coastguard Worker     int failed = 0;
706*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2; ++i) {
707*77c1e3ccSAndroid Build Coastguard Worker       if (M_ref[i] != M_test[i]) {
708*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
709*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d M iter %d [%4d] ref %6" PRId64 " test %6" PRId64
710*77c1e3ccSAndroid Build Coastguard Worker                " \n",
711*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, M_ref[i], M_test[i]);
712*77c1e3ccSAndroid Build Coastguard Worker         break;
713*77c1e3ccSAndroid Build Coastguard Worker       }
714*77c1e3ccSAndroid Build Coastguard Worker     }
715*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
716*77c1e3ccSAndroid Build Coastguard Worker       if (H_ref[i] != H_test[i]) {
717*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
718*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d H iter %d [%4d] ref %6" PRId64 " test %6" PRId64
719*77c1e3ccSAndroid Build Coastguard Worker                " \n",
720*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, H_ref[i], H_test[i]);
721*77c1e3ccSAndroid Build Coastguard Worker         break;
722*77c1e3ccSAndroid Build Coastguard Worker       }
723*77c1e3ccSAndroid Build Coastguard Worker     }
724*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(failed, 0);
725*77c1e3ccSAndroid Build Coastguard Worker   }
726*77c1e3ccSAndroid Build Coastguard Worker }
727*77c1e3ccSAndroid Build Coastguard Worker 
RunWienerTest_Overflow32bTest(const int32_t wiener_win,aom_bit_depth_t bit_depth)728*77c1e3ccSAndroid Build Coastguard Worker void WienerTestHighbd::RunWienerTest_Overflow32bTest(
729*77c1e3ccSAndroid Build Coastguard Worker     const int32_t wiener_win, aom_bit_depth_t bit_depth) {
730*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_halfwin = wiener_win >> 1;
731*77c1e3ccSAndroid Build Coastguard Worker   const int32_t wiener_win2 = wiener_win * wiener_win;
732*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_ref[WIENER_WIN2]);
733*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_ref[WIENER_WIN2 * WIENER_WIN2]);
734*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, M_test[WIENER_WIN2]);
735*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int64_t, H_test[WIENER_WIN2 * WIENER_WIN2]);
736*77c1e3ccSAndroid Build Coastguard Worker   const int h_start = 16;
737*77c1e3ccSAndroid Build Coastguard Worker   const int h_end = MAX_WIENER_BLOCK;
738*77c1e3ccSAndroid Build Coastguard Worker   const int v_start = 16;
739*77c1e3ccSAndroid Build Coastguard Worker   const int v_end = MAX_WIENER_BLOCK;
740*77c1e3ccSAndroid Build Coastguard Worker   const int dgd_stride = h_end;
741*77c1e3ccSAndroid Build Coastguard Worker   const int src_stride = MAX_DATA_BLOCK;
742*77c1e3ccSAndroid Build Coastguard Worker   const int iters = 1;
743*77c1e3ccSAndroid Build Coastguard Worker   int16_t *dgd_avg = buf;
744*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_avg =
745*77c1e3ccSAndroid Build Coastguard Worker       buf + (3 * RESTORATION_UNITSIZE_MAX * RESTORATION_UNITSIZE_MAX);
746*77c1e3ccSAndroid Build Coastguard Worker   for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
747*77c1e3ccSAndroid Build Coastguard Worker     // Fill src and dgd such that the intermediate values for M and H will at
748*77c1e3ccSAndroid Build Coastguard Worker     // some point overflow a signed 32-bit value.
749*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
750*77c1e3ccSAndroid Build Coastguard Worker       dgd_buf[i] = ((uint16_t)1 << bit_depth) - 1;
751*77c1e3ccSAndroid Build Coastguard Worker       src_buf[i] = 0;
752*77c1e3ccSAndroid Build Coastguard Worker     }
753*77c1e3ccSAndroid Build Coastguard Worker 
754*77c1e3ccSAndroid Build Coastguard Worker     memset(dgd_buf, 0, MAX_DATA_BLOCK * 30 * sizeof(dgd_buf));
755*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *dgd8 = CONVERT_TO_BYTEPTR(
756*77c1e3ccSAndroid Build Coastguard Worker         dgd_buf + wiener_halfwin * MAX_DATA_BLOCK + wiener_halfwin);
757*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *src8 = CONVERT_TO_BYTEPTR(src_buf);
758*77c1e3ccSAndroid Build Coastguard Worker 
759*77c1e3ccSAndroid Build Coastguard Worker     av1_compute_stats_highbd_c(wiener_win, dgd8, src8, dgd_avg, src_avg,
760*77c1e3ccSAndroid Build Coastguard Worker                                h_start, h_end, v_start, v_end, dgd_stride,
761*77c1e3ccSAndroid Build Coastguard Worker                                src_stride, M_ref, H_ref, bit_depth);
762*77c1e3ccSAndroid Build Coastguard Worker 
763*77c1e3ccSAndroid Build Coastguard Worker     target_func_(wiener_win, dgd8, src8, dgd_avg, src_avg, h_start, h_end,
764*77c1e3ccSAndroid Build Coastguard Worker                  v_start, v_end, dgd_stride, src_stride, M_test, H_test,
765*77c1e3ccSAndroid Build Coastguard Worker                  bit_depth);
766*77c1e3ccSAndroid Build Coastguard Worker 
767*77c1e3ccSAndroid Build Coastguard Worker     int failed = 0;
768*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2; ++i) {
769*77c1e3ccSAndroid Build Coastguard Worker       if (M_ref[i] != M_test[i]) {
770*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
771*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d M iter %d [%4d] ref %6" PRId64 " test %6" PRId64
772*77c1e3ccSAndroid Build Coastguard Worker                " \n",
773*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, M_ref[i], M_test[i]);
774*77c1e3ccSAndroid Build Coastguard Worker         break;
775*77c1e3ccSAndroid Build Coastguard Worker       }
776*77c1e3ccSAndroid Build Coastguard Worker     }
777*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < wiener_win2 * wiener_win2; ++i) {
778*77c1e3ccSAndroid Build Coastguard Worker       if (H_ref[i] != H_test[i]) {
779*77c1e3ccSAndroid Build Coastguard Worker         failed = 1;
780*77c1e3ccSAndroid Build Coastguard Worker         printf("win %d bd %d H iter %d [%4d] ref %6" PRId64 " test %6" PRId64
781*77c1e3ccSAndroid Build Coastguard Worker                " \n",
782*77c1e3ccSAndroid Build Coastguard Worker                wiener_win, bit_depth, iter, i, H_ref[i], H_test[i]);
783*77c1e3ccSAndroid Build Coastguard Worker         break;
784*77c1e3ccSAndroid Build Coastguard Worker       }
785*77c1e3ccSAndroid Build Coastguard Worker     }
786*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(failed, 0);
787*77c1e3ccSAndroid Build Coastguard Worker   }
788*77c1e3ccSAndroid Build Coastguard Worker }
789*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTestHighbd,RandomValues)790*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTestHighbd, RandomValues) {
791*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 1, AOM_BITS_8);
792*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_8);
793*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 1, AOM_BITS_10);
794*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_10);
795*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 1, AOM_BITS_12);
796*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 1, AOM_BITS_12);
797*77c1e3ccSAndroid Build Coastguard Worker }
798*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTestHighbd,ExtremeValues)799*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTestHighbd, ExtremeValues) {
800*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_8);
801*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_8);
802*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_10);
803*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_10);
804*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN, AOM_BITS_12);
805*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_ExtremeValues(WIENER_WIN_CHROMA, AOM_BITS_12);
806*77c1e3ccSAndroid Build Coastguard Worker }
807*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(WienerTestHighbd,Overflow32bTest)808*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTestHighbd, Overflow32bTest) {
809*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN, AOM_BITS_8);
810*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN_CHROMA, AOM_BITS_8);
811*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN, AOM_BITS_10);
812*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN_CHROMA, AOM_BITS_10);
813*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN, AOM_BITS_12);
814*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest_Overflow32bTest(WIENER_WIN_CHROMA, AOM_BITS_12);
815*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(WienerTestHighbd,DISABLED_Speed)816*77c1e3ccSAndroid Build Coastguard Worker TEST_P(WienerTestHighbd, DISABLED_Speed) {
817*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 200, AOM_BITS_8);
818*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_8);
819*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 200, AOM_BITS_10);
820*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_10);
821*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN, 200, AOM_BITS_12);
822*77c1e3ccSAndroid Build Coastguard Worker   RunWienerTest(WIENER_WIN_CHROMA, 200, AOM_BITS_12);
823*77c1e3ccSAndroid Build Coastguard Worker }
824*77c1e3ccSAndroid Build Coastguard Worker 
825*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(C, WienerTestHighbd,
826*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(compute_stats_highbd_opt_c));
827*77c1e3ccSAndroid Build Coastguard Worker 
828*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE4_1
829*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSE4_1, WienerTestHighbd,
830*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_highbd_sse4_1));
831*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SSE4_1
832*77c1e3ccSAndroid Build Coastguard Worker 
833*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
834*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(AVX2, WienerTestHighbd,
835*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_highbd_avx2));
836*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_AVX2
837*77c1e3ccSAndroid Build Coastguard Worker 
838*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
839*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(NEON, WienerTestHighbd,
840*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_highbd_neon));
841*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_NEON
842*77c1e3ccSAndroid Build Coastguard Worker 
843*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SVE
844*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SVE, WienerTestHighbd,
845*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_compute_stats_highbd_sve));
846*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SVE
847*77c1e3ccSAndroid Build Coastguard Worker 
848*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/274668506: signed integer overflow in
849*77c1e3ccSAndroid Build Coastguard Worker // update_a_sep_sym().
850*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 10bitSignedIntegerOverflowInUpdateASepSym) {
851*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 427;
852*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 1;
853*77c1e3ccSAndroid Build Coastguard Worker   std::vector<uint16_t> buffer(3 * kWidth * kHeight);
854*77c1e3ccSAndroid Build Coastguard Worker   // The values in the buffer alternate between 0 and 1023.
855*77c1e3ccSAndroid Build Coastguard Worker   uint16_t value = 0;
856*77c1e3ccSAndroid Build Coastguard Worker   for (size_t i = 0; i < buffer.size(); ++i) {
857*77c1e3ccSAndroid Build Coastguard Worker     buffer[i] = value;
858*77c1e3ccSAndroid Build Coastguard Worker     value = 1023 - value;
859*77c1e3ccSAndroid Build Coastguard Worker   }
860*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data = reinterpret_cast<unsigned char *>(buffer.data());
861*77c1e3ccSAndroid Build Coastguard Worker 
862*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
863*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(
864*77c1e3ccSAndroid Build Coastguard Worker       aom_img_wrap(&img, AOM_IMG_FMT_I44416, kWidth, kHeight, 1, img_data),
865*77c1e3ccSAndroid Build Coastguard Worker       &img);
866*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
867*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
868*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
869*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
870*77c1e3ccSAndroid Build Coastguard Worker 
871*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
872*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
873*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_ALL_INTRA),
874*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
875*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
876*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 1;
877*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_10;
878*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 10;
879*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
880*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
881*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_limit = 1;
882*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
883*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_mode = AOM_KF_DISABLED;
884*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_max_dist = 0;
885*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 61;
886*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 2;
887*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 20;
888*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
889*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH),
890*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
891*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 11), AOM_CODEC_OK);
892*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_ROW_MT, 1), AOM_CODEC_OK);
893*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 4), AOM_CODEC_OK);
894*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, 3), AOM_CODEC_OK);
895*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE),
896*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
897*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SKIP_POSTPROC_FILTERING, 1),
898*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
899*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM),
900*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
901*77c1e3ccSAndroid Build Coastguard Worker 
902*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
903*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
904*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
905*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
906*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
907*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
908*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
909*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
910*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
911*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
912*77c1e3ccSAndroid Build Coastguard Worker 
913*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
914*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, nullptr, 0, 1, 0), AOM_CODEC_OK);
915*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
916*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
917*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
918*77c1e3ccSAndroid Build Coastguard Worker 
919*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
920*77c1e3ccSAndroid Build Coastguard Worker }
921*77c1e3ccSAndroid Build Coastguard Worker 
922*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/281219978: signed integer overflow in
923*77c1e3ccSAndroid Build Coastguard Worker // update_b_sep_sym().
924*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 12bitSignedIntegerOverflowInUpdateBSepSym) {
925*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 311;
926*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
927*77c1e3ccSAndroid Build Coastguard Worker   static const uint16_t buffer[3 * kWidth * kHeight] = {
928*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
929*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 2156, 2513, 2211, 4095, 4095, 0, 2538, 0, 0, 0, 0, 4095, 0, 258,
930*77c1e3ccSAndroid Build Coastguard Worker     941, 4095, 907, 0, 0, 2325, 2485, 2408, 4095, 1513, 0, 3644, 2080, 4095,
931*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2135, 0, 2461, 4095, 0, 4095, 4095, 0, 1987, 0, 3629, 0, 4095,
932*77c1e3ccSAndroid Build Coastguard Worker     3918, 4095, 0, 4095, 4095, 4095, 0, 1065, 0, 2072, 3597, 102, 0, 534, 0, 0,
933*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 0, 4095, 0, 4095, 0, 4095, 0, 3611, 0, 1139, 4095, 0, 0, 0, 0,
934*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 0, 0, 0, 4095, 4095, 4095, 0, 0, 0, 3070, 3224, 0, 0, 4095,
935*77c1e3ccSAndroid Build Coastguard Worker     4051, 4095, 0, 4095, 3712, 0, 1465, 4095, 1699, 4095, 4095, 0, 0, 0, 3885,
936*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 0, 4095, 1686, 4095, 4095, 4095, 4095, 1330, 0, 0, 0, 4095, 0,
937*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 3919, 4095, 781, 2371, 2055, 4095, 912, 3710, 0, 2045, 0, 4095,
938*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 1811, 0, 1298, 1115, 0, 3327, 0, 0, 4095, 0, 253, 2386, 4095,
939*77c1e3ccSAndroid Build Coastguard Worker     1791, 3657, 1444, 0, 4095, 1918, 4095, 4095, 0, 4095, 305, 1587, 0, 4095, 0,
940*77c1e3ccSAndroid Build Coastguard Worker     3759, 0, 0, 4095, 2387, 4095, 4095, 0, 0, 4095, 4095, 0, 1015, 4095, 0, 768,
941*77c1e3ccSAndroid Build Coastguard Worker     2598, 1667, 130, 4095, 0, 0, 435, 4095, 3683, 4095, 0, 4095, 4095, 1888,
942*77c1e3ccSAndroid Build Coastguard Worker     2828, 4095, 3349, 0, 4095, 4095, 4095, 4095, 0, 4095, 0, 0, 4095, 0, 2491,
943*77c1e3ccSAndroid Build Coastguard Worker     1598, 0, 0, 383, 3712, 4095, 0, 0, 4095, 760, 4095, 4095, 4095, 2030, 4095,
944*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 3236, 0, 1040, 0, 0, 4095, 0, 0, 4095, 4095, 4095, 0, 0, 1043, 3897,
945*77c1e3ccSAndroid Build Coastguard Worker     2446, 233, 1589, 427, 4095, 4095, 4095, 4095, 0, 1656, 3786, 4095, 0, 840,
946*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 1429, 4095, 0, 4095, 2734, 4095, 0, 2431, 1801, 278, 0, 4095, 0,
947*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 420, 0, 0, 746, 0, 0, 3281, 3006, 4095, 4095, 0, 0, 0, 3605,
948*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 4095, 4095, 4095, 4095, 2660, 496, 4095, 0, 0, 0, 0, 4095, 0,
949*77c1e3ccSAndroid Build Coastguard Worker     1317, 4095, 4095, 510, 1919, 0, 3893, 0, 4095, 4095, 4095, 4095, 4095, 2071,
950*77c1e3ccSAndroid Build Coastguard Worker     2006, 0, 3316, 4095, 0, 0, 4095, 852, 2982, 0, 2073, 0, 2728, 1499, 4095,
951*77c1e3ccSAndroid Build Coastguard Worker     852, 361, 3137, 4095, 4095, 1502, 1575, 0, 4095, 0, 0, 0, 0, 1585, 4095, 0,
952*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 3188, 3244, 4095, 2958, 4095, 4095, 0, 4095, 4095, 4095, 1706,
953*77c1e3ccSAndroid Build Coastguard Worker     2896, 4095, 1788, 730, 1146, 4095, 0, 0, 4095, 0, 0, 0, 2791, 3613, 2175,
954*77c1e3ccSAndroid Build Coastguard Worker     2925, 0, 0, 0, 0, 0, 1279, 4095, 4095, 0, 4095, 0, 0, 2336, 0, 3462, 4095,
955*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 1997, 2328, 2860, 0, 4095, 4095, 3241, 4095, 4095, 4095, 4095,
956*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 118, 0, 4095, 4095, 4095, 0, 3734, 0, 0, 0, 4095, 1952, 4095,
957*77c1e3ccSAndroid Build Coastguard Worker     413, 4095, 1183, 4095, 0, 4095, 0, 0, 4095, 4095, 4095, 3805, 0, 1398, 0,
958*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 0, 4095, 4095, 4095, 2802, 3658, 4095, 4095, 0, 0, 0, 4095, 0,
959*77c1e3ccSAndroid Build Coastguard Worker     897, 0, 4095, 2163, 0, 0, 0, 4095, 1440, 2487, 4095, 4095, 0, 4095, 4095,
960*77c1e3ccSAndroid Build Coastguard Worker     4095, 2808, 0, 1999, 0, 0, 4095, 4095, 4095, 1563, 124, 2179, 754, 0, 0,
961*77c1e3ccSAndroid Build Coastguard Worker     2407, 2798, 0, 4095, 4095, 0, 0, 1929, 0, 0, 0, 1387, 4095, 4095, 0, 0,
962*77c1e3ccSAndroid Build Coastguard Worker     3911, 562, 4095, 0, 4095, 2639, 2673, 4095, 4095, 0, 0, 4095, 4095, 0, 4095,
963*77c1e3ccSAndroid Build Coastguard Worker     4095, 901, 0, 321, 3961, 4095, 0, 4095, 4095, 4095, 0, 0, 0, 0, 3035, 3713,
964*77c1e3ccSAndroid Build Coastguard Worker     3441, 0, 4095, 0, 0, 854, 1544, 3963, 1968, 4095, 0, 0, 0, 0, 2897, 4095, 0,
965*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 235, 1011, 4095, 0, 3452, 4095, 4095, 0, 0, 4095, 4095, 4095,
966*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 3312, 0, 3064, 4095, 3981, 4095, 4095, 4095, 4095, 4095, 0, 791,
967*77c1e3ccSAndroid Build Coastguard Worker     3243, 4095, 799, 0, 0, 0, 523, 2117, 3776, 0, 4095, 3311, 0, 543, 4095,
968*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 0, 4095, 4095, 4095, 4095, 0, 0, 4095, 4095, 225, 0, 1195,
969*77c1e3ccSAndroid Build Coastguard Worker     3070, 1210, 4095, 0, 4095, 498, 782, 0, 0, 4095, 4095, 4095, 4095, 4095,
970*77c1e3ccSAndroid Build Coastguard Worker     1456, 4095, 3898, 1472, 4095, 4095, 0, 4095, 4026, 0, 0, 2354, 1554, 0,
971*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2986, 0, 1053, 1228, 0, 0, 4095, 4095, 0, 0, 4095, 0, 0, 4095, 0,
972*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 606, 0, 4095, 3563, 4095, 2016, 4095, 0, 0, 4095, 0, 4095, 4095, 4095,
973*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 929, 0, 0, 4095, 0, 3069, 4095, 0, 2687, 4095, 4095, 4095, 2015,
974*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 4095, 0, 0, 2860, 3668, 0, 0, 4095, 2523, 2104, 0, 0,
975*77c1e3ccSAndroid Build Coastguard Worker     3063, 4095, 3674, 4095, 0, 2762, 0, 4095, 2582, 3473, 930, 0, 1012, 108, 38,
976*77c1e3ccSAndroid Build Coastguard Worker     4095, 1148, 3568, 4036, 4095, 4095, 0, 1120, 1873, 3028, 4095, 515, 1902,
977*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 815, 4095, 1548, 0, 1073, 3919, 4095, 2374, 0, 3126, 4095, 2268, 0,
978*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 4095, 425, 4095, 0, 0, 4095, 4095, 2710, 4095, 2067, 4095, 4095, 2201,
979*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 4095, 4095, 2933, 0, 417, 2801, 4095, 4095, 3274, 0, 2870,
980*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 0, 973, 0, 0, 3129, 4095, 0, 0, 0, 4095, 4095, 4095, 0, 242,
981*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 0, 0, 0, 0, 987, 0, 2426, 4045, 2780, 0, 4095, 3762, 3361,
982*77c1e3ccSAndroid Build Coastguard Worker     3095, 4095, 596, 1072, 4071, 4095, 4095, 0, 0, 81, 0, 1001, 1683, 4095,
983*77c1e3ccSAndroid Build Coastguard Worker     4095, 3105, 2673, 0, 3300, 104, 4030, 0, 2615, 4095, 4095, 0, 4095, 1830,
984*77c1e3ccSAndroid Build Coastguard Worker     3917, 4095, 4095, 4095, 0, 4095, 3637, 0, 4095, 4095, 3677, 4095, 4095, 0,
985*77c1e3ccSAndroid Build Coastguard Worker     880, 4095, 4095, 0, 2797, 0, 0, 0, 0, 3225, 4095, 4095, 1925, 2885, 1879, 0,
986*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 0, 0, 2974, 559, 0, 0, 0, 699, 997, 1491, 423, 4012, 0, 2315,
987*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 4095, 0, 836, 4095, 0, 4095, 0, 1752, 0, 0, 0, 4095, 4095, 0, 0,
988*77c1e3ccSAndroid Build Coastguard Worker     51, 4095, 350, 0, 2143, 2588, 0, 4095, 0, 4095, 0, 2757, 2370, 4095, 668,
989*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 0, 3652, 3890, 0, 4095, 0, 4095, 4095, 4095, 4095, 4095,
990*77c1e3ccSAndroid Build Coastguard Worker     // U plane:
991*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 1465, 0, 588, 4095, 0, 4095, 4095, 4095, 0, 2167, 4095, 4095,
992*77c1e3ccSAndroid Build Coastguard Worker     918, 3223, 4095, 4095, 0, 696, 4095, 4095, 0, 0, 594, 4095, 2935, 0, 0, 0,
993*77c1e3ccSAndroid Build Coastguard Worker     2036, 4095, 0, 2492, 4095, 4095, 0, 0, 0, 3883, 0, 4095, 483, 4095, 4095,
994*77c1e3ccSAndroid Build Coastguard Worker     324, 923, 0, 3079, 0, 4095, 4095, 810, 0, 3371, 4095, 4095, 0, 4095, 2756,
995*77c1e3ccSAndroid Build Coastguard Worker     0, 723, 0, 3338, 1084, 0, 4095, 4095, 3764, 0, 4095, 4095, 4095, 2323, 0,
996*77c1e3ccSAndroid Build Coastguard Worker     3693, 682, 0, 0, 909, 4095, 2348, 4095, 4095, 4095, 1509, 4095, 0, 4095,
997*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 3977, 3652, 1580, 637, 4095, 0, 593, 4095, 1199, 1773,
998*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 3447, 0, 0, 4095, 3873, 0, 0, 2094, 0, 1195, 0, 3892,
999*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 729, 4095, 0, 0, 4095, 449, 4095, 4095, 2900, 0, 4095, 0, 2114,
1000*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 1174, 995, 2933, 360, 0, 1970, 0, 4095, 1208, 0, 4095, 0,
1001*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 4095, 0, 4095, 0, 0, 0, 1976, 0, 0, 921, 4095, 4095, 192,
1002*77c1e3ccSAndroid Build Coastguard Worker     1006, 0, 0, 2725, 4095, 0, 2813, 0, 0, 2375, 4095, 1982, 0, 2725, 4095,
1003*77c1e3ccSAndroid Build Coastguard Worker     1225, 3566, 4095, 0, 344, 863, 2747, 0, 4095, 4095, 1928, 4095, 4095, 0,
1004*77c1e3ccSAndroid Build Coastguard Worker     3640, 0, 1744, 3191, 4095, 4095, 0, 4095, 4095, 4095, 0, 0, 748, 4095, 0,
1005*77c1e3ccSAndroid Build Coastguard Worker     2609, 0, 0, 0, 0, 0, 3508, 4095, 4095, 2463, 0, 4095, 0, 4095, 4095, 4095,
1006*77c1e3ccSAndroid Build Coastguard Worker     3175, 419, 2193, 0, 0, 4095, 0, 0, 4095, 4051, 2159, 4095, 4095, 2262, 379,
1007*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 3399, 4095, 4095, 4095, 3769, 2510, 4054, 3336, 730, 3968, 0, 0,
1008*77c1e3ccSAndroid Build Coastguard Worker     3354, 0, 1822, 0, 4095, 0, 3847, 3823, 3262, 0, 0, 2936, 0, 4095, 4095,
1009*77c1e3ccSAndroid Build Coastguard Worker     2120, 0, 3147, 0, 2838, 3480, 474, 1194, 4095, 4095, 2820, 4095, 0, 4095,
1010*77c1e3ccSAndroid Build Coastguard Worker     1882, 4095, 1085, 0, 4095, 2234, 3371, 4095, 0, 4095, 0, 0, 0, 2586, 4095,
1011*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 3818, 1401, 2273, 4095, 0, 4095, 0, 3907, 4095, 4095,
1012*77c1e3ccSAndroid Build Coastguard Worker     694, 0, 4066, 4095, 0, 0, 4095, 2116, 4095, 4095, 4095, 4095, 4095, 0, 2821,
1013*77c1e3ccSAndroid Build Coastguard Worker     29, 0, 0, 663, 1711, 652, 1271, 4095, 4095, 2401, 3726, 4095, 3453, 1803,
1014*77c1e3ccSAndroid Build Coastguard Worker     3614, 0, 4095, 3439, 4095, 0, 4095, 0, 816, 0, 0, 4095, 4095, 2635, 0, 1918,
1015*77c1e3ccSAndroid Build Coastguard Worker     0, 2663, 381, 0, 0, 3670, 0, 4095, 3065, 965, 4095, 4095, 4095, 2993, 4095,
1016*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 973, 4095, 0, 4095, 4095, 0, 3071, 0, 2777, 4095, 4095, 0,
1017*77c1e3ccSAndroid Build Coastguard Worker     3996, 4095, 1637, 0, 4095, 67, 3784, 0, 0, 4095, 2603, 579, 4095, 4095,
1018*77c1e3ccSAndroid Build Coastguard Worker     2854, 4095, 3016, 0, 4095, 0, 0, 4095, 4095, 4095, 4095, 3998, 3023, 4095,
1019*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 0, 4095, 4095, 4095, 4095, 0, 0, 2623, 1308, 55, 4095, 0, 0,
1020*77c1e3ccSAndroid Build Coastguard Worker     2554, 2311, 0, 4095, 4095, 4095, 1134, 2112, 0, 4095, 4095, 0, 4095, 0, 645,
1021*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 4095, 0, 909, 0, 0, 1719, 4095, 0, 3542, 0, 575, 0, 4095, 4095, 4095,
1022*77c1e3ccSAndroid Build Coastguard Worker     3428, 1172, 481, 1521, 4095, 3199, 1265, 4095, 3518, 4017, 4095, 760, 2042,
1023*77c1e3ccSAndroid Build Coastguard Worker     3986, 0, 4095, 42, 4095, 0, 4095, 4095, 4095, 4095, 2235, 346, 3865, 0,
1024*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 4095, 4095, 845, 4095, 0, 2826, 4095, 4095, 0, 0,
1025*77c1e3ccSAndroid Build Coastguard Worker     335, 1614, 1465, 0, 4095, 4095, 0, 2771, 4095, 0, 2810, 4095, 4095, 0, 1254,
1026*77c1e3ccSAndroid Build Coastguard Worker     4095, 2589, 4095, 4095, 2252, 0, 0, 0, 4095, 0, 73, 4095, 4095, 0, 1341, 0,
1027*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 4095, 0, 0, 2645, 1985, 492, 914, 3996, 4095, 4095, 4095, 0, 2383,
1028*77c1e3ccSAndroid Build Coastguard Worker     2556, 433, 0, 4095, 1094, 4095, 4095, 642, 4095, 1722, 0, 3460, 4095, 4095,
1029*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 154, 4095, 92, 4095, 0, 0, 0, 4095, 0, 4095, 4095, 444,
1030*77c1e3ccSAndroid Build Coastguard Worker     0, 2925, 0, 0, 0, 0, 1628, 0, 4095, 1731, 2418, 697, 4095, 0, 2513, 4095, 0,
1031*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 4095, 0, 2510, 4095, 3850, 0, 0, 4095, 2480, 4095,
1032*77c1e3ccSAndroid Build Coastguard Worker     4095, 2661, 4095, 0, 4095, 0, 0, 4095, 4095, 847, 4095, 4095, 3257, 443, 0,
1033*77c1e3ccSAndroid Build Coastguard Worker     67, 0, 0, 0, 4095, 0, 0, 3073, 4095, 0, 4095, 0, 4095, 0, 4095, 1224, 4095,
1034*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 4095, 958, 0, 4095, 0, 2327, 684, 0, 0, 0, 0, 4095, 4095, 0,
1035*77c1e3ccSAndroid Build Coastguard Worker     3693, 795, 4095, 0, 621, 1592, 2314, 4095, 0, 928, 1897, 4095, 4095, 0,
1036*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 4095, 2619, 4095, 0, 4095, 0, 0, 4095, 2485, 4095, 4095, 0, 435,
1037*77c1e3ccSAndroid Build Coastguard Worker     4095, 1818, 4095, 4095, 0, 0, 0, 4095, 4095, 4095, 4095, 0, 1671, 4095,
1038*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2617, 0, 2572, 0, 0, 4095, 3471, 0, 0, 4095, 2719, 3979, 1307, 0,
1039*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 1794, 642, 447, 913, 4095, 3927, 0, 2686, 0, 0, 4095, 0, 857, 0,
1040*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 567, 2385, 0, 0, 4095, 893, 0, 289, 0, 0, 0, 4095, 4095, 2566,
1041*77c1e3ccSAndroid Build Coastguard Worker     0, 1913, 0, 2350, 1033, 2764, 0, 4095, 0, 4095, 0, 0, 0, 0, 4095, 3952,
1042*77c1e3ccSAndroid Build Coastguard Worker     3969, 0, 3476, 0, 4095, 4095, 393, 0, 2613, 0, 0, 1422, 0, 3359, 491, 3263,
1043*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 0, 4095, 697, 3601, 4095, 0, 4095, 4095, 0, 4095, 0, 0, 4095,
1044*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 4095, 4095, 2506, 0, 0, 1403, 0, 3836, 3976, 0, 4095, 4095, 4095,
1045*77c1e3ccSAndroid Build Coastguard Worker     2497, 4095, 4095, 4095, 4095, 0, 4095, 3317, 4095, 4095, 4095, 0, 0, 1131,
1046*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 4095, 0, 0, 4095, 0, 0, 2988, 4095, 4095, 2711, 2487, 1335, 0, 0,
1047*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 261, 4095, 86, 0, 0, 1138, 4095, 0, 0, 4095, 4095, 0, 0, 0, 334, 0,
1048*77c1e3ccSAndroid Build Coastguard Worker     2395, 3297, 4095, 1698, 4095, 1791, 1341, 0, 3559, 0, 4095, 0, 2056, 3238,
1049*77c1e3ccSAndroid Build Coastguard Worker     3310, 4095, 4095, 779, 2129, 2849, 4095, 2622, 1051, 0, 0, 1282, 4095, 1246,
1050*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 3696, 4095, 556, 0, 0, 3463, 2658, 3572, 4095, 3982, 4095, 4095, 0, 0,
1051*77c1e3ccSAndroid Build Coastguard Worker     4053, 4095, 4095, 4095, 2162, 2567, 1621, 4095, 4095, 1522, 293, 4095, 0, 0,
1052*77c1e3ccSAndroid Build Coastguard Worker     1976, 4095, 3089, 4095, 0, 0, 0, 0, 3650,
1053*77c1e3ccSAndroid Build Coastguard Worker     // V plane:
1054*77c1e3ccSAndroid Build Coastguard Worker     0, 1892, 4095, 1995, 0, 0, 0, 2208, 1152, 1794, 4095, 4095, 89, 3333, 4095,
1055*77c1e3ccSAndroid Build Coastguard Worker     2478, 4095, 2505, 4095, 0, 2664, 4095, 1984, 0, 1144, 4095, 0, 4095, 0,
1056*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 0, 2404, 1727, 4095, 4095, 0, 1326, 2033, 0, 4095, 0, 4095,
1057*77c1e3ccSAndroid Build Coastguard Worker     3022, 0, 4095, 0, 1980, 4095, 0, 2284, 4095, 0, 3422, 0, 4095, 2171, 3155,
1058*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 0, 636, 0, 0, 4095, 3264, 3862, 0, 2164, 0, 0, 3879, 3886, 0,
1059*77c1e3ccSAndroid Build Coastguard Worker     225, 0, 0, 4095, 0, 1956, 523, 464, 738, 0, 1545, 0, 2829, 4095, 4095, 4095,
1060*77c1e3ccSAndroid Build Coastguard Worker     799, 4095, 358, 4095, 0, 0, 953, 0, 0, 2081, 4095, 1604, 4095, 2086, 0, 954,
1061*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 2393, 2413, 4095, 4095, 0, 3583, 4095, 4095, 2995, 4095, 0, 4095,
1062*77c1e3ccSAndroid Build Coastguard Worker     4095, 3501, 4095, 247, 4095, 0, 0, 0, 4095, 1303, 3382, 1059, 4095, 0, 543,
1063*77c1e3ccSAndroid Build Coastguard Worker     1276, 1801, 0, 0, 0, 2928, 0, 4095, 3931, 70, 0, 0, 3992, 4095, 1278, 1930,
1064*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 4095, 3894, 0, 0, 0, 0, 4095, 0, 0, 0, 0, 0, 0, 4095, 4095,
1065*77c1e3ccSAndroid Build Coastguard Worker     4095, 1098, 4095, 2059, 0, 380, 3166, 0, 4095, 2215, 0, 0, 2846, 0, 0, 2614,
1066*77c1e3ccSAndroid Build Coastguard Worker     528, 4095, 0, 4095, 2371, 0, 4095, 0, 0, 0, 0, 4095, 3133, 4095, 4095, 0,
1067*77c1e3ccSAndroid Build Coastguard Worker     4095, 1283, 3821, 1772, 0, 0, 4095, 4095, 4095, 890, 3475, 4095, 4095, 133,
1068*77c1e3ccSAndroid Build Coastguard Worker     3292, 1819, 4095, 4095, 4095, 0, 0, 4095, 702, 4095, 0, 0, 0, 4095, 0, 2137,
1069*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 0, 0, 4095, 4095, 1555, 2435, 2778, 4095, 0, 4095,
1070*77c1e3ccSAndroid Build Coastguard Worker     3825, 0, 3736, 3054, 0, 0, 4095, 4095, 4095, 0, 0, 0, 0, 371, 4095, 4095, 0,
1071*77c1e3ccSAndroid Build Coastguard Worker     0, 1565, 4095, 2731, 4095, 0, 756, 925, 0, 0, 0, 4095, 775, 1379, 4095,
1072*77c1e3ccSAndroid Build Coastguard Worker     1439, 0, 0, 0, 2680, 0, 0, 4095, 1280, 4095, 0, 0, 4095, 4095, 0, 3088, 0,
1073*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 0, 1526, 4095, 2314, 4095, 4095, 0, 4095, 288, 0, 205,
1074*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0, 1247, 2014, 0, 1530, 1985, 0, 0, 4095, 3195, 0, 4095,
1075*77c1e3ccSAndroid Build Coastguard Worker     4, 2397, 4095, 4095, 4095, 0, 4095, 4095, 4095, 0, 0, 0, 0, 0, 4031, 928,
1076*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 0, 4095, 4095, 4095, 1966, 4095, 2299, 1215, 4095, 0, 4095, 1335,
1077*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 1991, 4095, 0, 4095, 114, 0, 0, 0, 2123, 2639, 4095, 3323, 4095,
1078*77c1e3ccSAndroid Build Coastguard Worker     4095, 418, 209, 0, 0, 4095, 4095, 4095, 4095, 963, 0, 0, 0, 4095, 2505, 0,
1079*77c1e3ccSAndroid Build Coastguard Worker     3627, 0, 311, 3748, 2047, 4095, 2791, 0, 3643, 1852, 0, 0, 4095, 0, 2179, 0,
1080*77c1e3ccSAndroid Build Coastguard Worker     4095, 2678, 0, 0, 0, 2342, 4095, 4095, 0, 0, 4095, 0, 0, 0, 0, 1076, 0, 0,
1081*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2370, 0, 3530, 0, 0, 0, 0, 0, 4095, 0, 0, 0, 3474, 1201, 0, 379,
1082*77c1e3ccSAndroid Build Coastguard Worker     699, 4095, 777, 4095, 0, 4095, 4095, 0, 1213, 1762, 4095, 4095, 4095, 0,
1083*77c1e3ccSAndroid Build Coastguard Worker     4095, 1090, 1233, 0, 4095, 0, 4095, 0, 0, 0, 2845, 3385, 2718, 0, 0, 2975,
1084*77c1e3ccSAndroid Build Coastguard Worker     3630, 0, 4095, 4095, 4095, 4095, 3261, 243, 0, 4095, 0, 0, 3836, 4095, 4095,
1085*77c1e3ccSAndroid Build Coastguard Worker     4095, 963, 0, 0, 2526, 0, 4095, 4000, 4095, 2069, 0, 0, 4095, 0, 4095, 1421,
1086*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 4095, 4095, 0, 4095, 0, 4095, 4095, 1537, 4095, 3201, 0, 0,
1087*77c1e3ccSAndroid Build Coastguard Worker     4095, 2719, 4095, 0, 4095, 4095, 4095, 0, 4095, 0, 4095, 2300, 0, 2876, 0,
1088*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 3235, 497, 635, 0, 1480, 4095, 0, 3067, 3979, 3741, 0,
1089*77c1e3ccSAndroid Build Coastguard Worker     3059, 1214, 4095, 4095, 2197, 0, 4095, 4095, 2734, 0, 4095, 4095, 3364,
1090*77c1e3ccSAndroid Build Coastguard Worker     2369, 4095, 303, 4095, 0, 4095, 4095, 3472, 1733, 4095, 4095, 4095, 0, 55,
1091*77c1e3ccSAndroid Build Coastguard Worker     0, 10, 1378, 1169, 4095, 0, 0, 688, 3613, 0, 4095, 2832, 867, 4095, 4095,
1092*77c1e3ccSAndroid Build Coastguard Worker     3514, 4095, 0, 4095, 4095, 2458, 3506, 0, 1920, 0, 1762, 1178, 2549, 4095,
1093*77c1e3ccSAndroid Build Coastguard Worker     3967, 4095, 0, 2975, 1282, 0, 377, 846, 3434, 97, 0, 0, 1616, 3526, 136,
1094*77c1e3ccSAndroid Build Coastguard Worker     1888, 0, 147, 334, 4095, 0, 4095, 0, 4095, 1106, 4095, 0, 4095, 3280, 4095,
1095*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2849, 3528, 0, 4095, 4095, 0, 2306, 0, 3412, 0, 4095, 4095, 4095,
1096*77c1e3ccSAndroid Build Coastguard Worker     4048, 2273, 0, 4095, 4095, 4095, 0, 4095, 3031, 4095, 4095, 4095, 0, 3382,
1097*77c1e3ccSAndroid Build Coastguard Worker     3812, 2315, 4095, 0, 0, 0, 432, 4095, 3606, 0, 4, 2847, 4095, 0, 4095, 0, 0,
1098*77c1e3ccSAndroid Build Coastguard Worker     2616, 4095, 4095, 0, 4095, 0, 3394, 4095, 3976, 3119, 0, 0, 0, 0, 4046,
1099*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 3331, 4095, 2127, 0, 4095, 0, 0, 0, 4095, 4095, 4095, 0, 4095,
1100*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 2068, 0, 0, 3882, 2967, 0, 1745, 4095, 2112, 478, 0, 4095, 0,
1101*77c1e3ccSAndroid Build Coastguard Worker     199, 4095, 4095, 3542, 4095, 2634, 4095, 4095, 1235, 4095, 4095, 167, 1553,
1102*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 2649, 0, 3383, 0, 4095, 2803, 4095, 0, 4095, 0, 785, 4095, 0, 4095,
1103*77c1e3ccSAndroid Build Coastguard Worker     1743, 4095, 0, 3945, 0, 4095, 1894, 4095, 3973, 4095, 0, 0, 4095, 0, 0,
1104*77c1e3ccSAndroid Build Coastguard Worker     4095, 318, 4095, 4095, 4095, 0, 261, 4095, 4095, 2125, 2690, 4095, 0, 4095,
1105*77c1e3ccSAndroid Build Coastguard Worker     3863, 1740, 4095, 0, 2899, 1509, 0, 0, 0, 2780, 4095, 1897, 2104, 4095,
1106*77c1e3ccSAndroid Build Coastguard Worker     1708, 284, 4095, 0, 4095, 3382, 4095, 4095, 483, 0, 0, 0, 3099, 0, 4095, 0,
1107*77c1e3ccSAndroid Build Coastguard Worker     926, 4095, 2062, 1931, 2121, 0, 4095, 0, 2485, 1535, 4095, 4095, 3662, 4095,
1108*77c1e3ccSAndroid Build Coastguard Worker     2419, 2487, 0, 4095, 4095, 4095, 0, 0, 4095, 0, 0, 2029, 0, 3008, 2338, 0,
1109*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 3854, 0, 4095, 0, 0, 1315, 0, 0, 0, 0, 3492, 0, 1445, 0, 11, 4095,
1110*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 873, 0, 4095, 0, 4095, 2654, 3040, 0, 0, 0, 4095, 0, 68, 4095, 0, 0,
1111*77c1e3ccSAndroid Build Coastguard Worker     990, 0, 828, 1015, 88, 3606, 0, 2875, 4095, 0, 3117, 411, 0, 0, 2859, 0, 0,
1112*77c1e3ccSAndroid Build Coastguard Worker     4095, 3480, 25, 4095, 4095, 4095, 0, 0, 0, 4095, 4095, 4095, 4095, 1724, 0,
1113*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 3635, 1063, 3728, 4095, 4095, 2025, 3715, 0, 0, 0, 3722, 0, 1648, 0,
1114*77c1e3ccSAndroid Build Coastguard Worker     4095, 3579, 0, 0, 0, 4095, 4095, 0, 4095
1115*77c1e3ccSAndroid Build Coastguard Worker   };
1116*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
1117*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(buffer));
1118*77c1e3ccSAndroid Build Coastguard Worker 
1119*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1120*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(
1121*77c1e3ccSAndroid Build Coastguard Worker       aom_img_wrap(&img, AOM_IMG_FMT_I44416, kWidth, kHeight, 1, img_data),
1122*77c1e3ccSAndroid Build Coastguard Worker       &img);
1123*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1124*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1125*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1126*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1127*77c1e3ccSAndroid Build Coastguard Worker 
1128*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1129*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1130*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_ALL_INTRA),
1131*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1132*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1133*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 2;
1134*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_12;
1135*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 12;
1136*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1137*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1138*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_limit = 1;
1139*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
1140*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_mode = AOM_KF_DISABLED;
1141*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_max_dist = 0;
1142*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 34;
1143*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 8;
1144*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 20;
1145*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1146*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH),
1147*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1148*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 14), AOM_CODEC_OK);
1149*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_ROW_MT, 1), AOM_CODEC_OK);
1150*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 4), AOM_CODEC_OK);
1151*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_COLUMNS, 4), AOM_CODEC_OK);
1152*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, 0), AOM_CODEC_OK);
1153*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE),
1154*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1155*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SKIP_POSTPROC_FILTERING, 1),
1156*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1157*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM),
1158*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1159*77c1e3ccSAndroid Build Coastguard Worker 
1160*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1161*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
1162*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1163*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1164*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1165*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1166*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1167*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1168*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1169*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1170*77c1e3ccSAndroid Build Coastguard Worker 
1171*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1172*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, nullptr, 0, 1, 0), AOM_CODEC_OK);
1173*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1174*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1175*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1176*77c1e3ccSAndroid Build Coastguard Worker 
1177*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
1178*77c1e3ccSAndroid Build Coastguard Worker }
1179*77c1e3ccSAndroid Build Coastguard Worker 
1180*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces crbug.com/oss-fuzz/66474: signed integer overflow in
1181*77c1e3ccSAndroid Build Coastguard Worker // update_b_sep_sym().
1182*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 12bitSignedIntegerOverflowInUpdateBSepSym2) {
1183*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 510;
1184*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1185*77c1e3ccSAndroid Build Coastguard Worker   static const uint16_t buffer[kWidth * kHeight] = {
1186*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1187*77c1e3ccSAndroid Build Coastguard Worker     2136, 4095, 0,    0,    0,    4095, 4095, 0,    4095, 4095, 329,  0,
1188*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 2587, 0,    0,    0,    4095, 0,    0,    0,    0,
1189*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 878,  0,    4095, 0,    4095, 1474, 0,    573,  0,
1190*77c1e3ccSAndroid Build Coastguard Worker     2401, 0,    1663, 4095, 0,    9,    3381, 0,    1084, 0,    270,  0,
1191*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 3992, 4095, 2047, 0,    0,    0,    4095, 41,   0,
1192*77c1e3ccSAndroid Build Coastguard Worker     2726, 279,  0,    0,    4095, 0,    0,    1437, 0,    4095, 4095, 0,
1193*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    4095, 1683, 183,  3976, 3052, 0,    4095, 0,    0,    0,
1194*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 1882, 4095, 0,    4095, 83,   4095, 0,    4095, 0,    0,
1195*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    0,    1637, 4095, 0,    4095, 0,    4095, 4095, 4095,
1196*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 197,  4095, 563,  0,    3696, 3073, 3670, 0,    4095, 4095,
1197*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    4095, 0,    0,    0,    0,    4095, 4095, 0,    0,
1198*77c1e3ccSAndroid Build Coastguard Worker     0,    3539, 3468, 0,    2856, 3880, 0,    0,    1350, 2358, 4095, 802,
1199*77c1e3ccSAndroid Build Coastguard Worker     4051, 0,    4095, 4095, 4095, 1677, 4095, 1135, 0,    4095, 0,    0,
1200*77c1e3ccSAndroid Build Coastguard Worker     0,    618,  4095, 4095, 4095, 0,    2080, 4095, 0,    0,    1917, 0,
1201*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 1937, 2835, 4095, 4095, 4095, 4095, 0,    4095, 4095, 3938,
1202*77c1e3ccSAndroid Build Coastguard Worker     1707, 0,    0,    0,    4095, 448,  4095, 0,    1000, 2481, 3408, 0,
1203*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 0,    3176, 0,    4095, 0,    4095, 4095, 4095, 0,    160,
1204*77c1e3ccSAndroid Build Coastguard Worker     222,  1134, 4095, 4095, 0,    3539, 4095, 569,  3364, 0,    4095, 3687,
1205*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 0,    0,    473,  0,    0,    4095, 298,  0,    3126, 4095,
1206*77c1e3ccSAndroid Build Coastguard Worker     3854, 424,  0,    0,    4095, 3893, 0,    0,    175,  2774, 0,    4095,
1207*77c1e3ccSAndroid Build Coastguard Worker     0,    2661, 950,  4095, 0,    1553, 0,    4095, 0,    4095, 4095, 2767,
1208*77c1e3ccSAndroid Build Coastguard Worker     3630, 799,  255,  0,    4095, 0,    0,    4095, 2375, 0,    0,    0,
1209*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 4095, 0,    0,    0,    1404, 4095, 4095, 4095, 4095, 2317,
1210*77c1e3ccSAndroid Build Coastguard Worker     4095, 1227, 2205, 775,  0,    4095, 0,    0,    797,  1125, 736,  1773,
1211*77c1e3ccSAndroid Build Coastguard Worker     2996, 4095, 2822, 4095, 4095, 0,    0,    0,    919,  0,    968,  3426,
1212*77c1e3ccSAndroid Build Coastguard Worker     2702, 2613, 3647, 0,    0,    4095, 4095, 129,  4095, 0,    0,    4095,
1213*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    3632, 0,    3275, 123,  4095, 1566, 0,    0,    0,    1609,
1214*77c1e3ccSAndroid Build Coastguard Worker     0,    1466, 4095, 577,  4095, 4095, 0,    4095, 1103, 1103, 4095, 0,
1215*77c1e3ccSAndroid Build Coastguard Worker     1909, 0,    4095, 0,    4095, 4095, 227,  0,    4095, 2168, 4095, 374,
1216*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0,    0,    0,    4095, 2066, 4095, 4095, 1475, 0,
1217*77c1e3ccSAndroid Build Coastguard Worker     1959, 673,  4095, 0,    4095, 4095, 4095, 1142, 0,    464,  1819, 2033,
1218*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    2212, 4095, 4095, 3961, 0,    4095, 0,    2838, 0,    4095,
1219*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 0,    3796, 3379, 2208, 0,    4095, 4095, 1943, 478,
1220*77c1e3ccSAndroid Build Coastguard Worker     3573, 4095, 1763, 0,    0,    4095, 4095, 4095, 4095, 2061, 3346, 4095,
1221*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    4095, 0,    4095, 4095, 4095, 3738, 4095, 4095, 0,    4095,
1222*77c1e3ccSAndroid Build Coastguard Worker     0,    425,  0,    0,    0,    927,  0,    0,    1814, 966,  4095, 0,
1223*77c1e3ccSAndroid Build Coastguard Worker     0,    3185, 570,  3883, 2932, 0,    1413, 4095, 4095, 4095, 4095, 2477,
1224*77c1e3ccSAndroid Build Coastguard Worker     2270, 4095, 2531, 4095, 1936, 3110, 99,   3936, 4095, 1315, 4095, 0,
1225*77c1e3ccSAndroid Build Coastguard Worker     4095, 3564, 4095, 0,    0,    2797, 4095, 0,    1598, 0,    0,    3064,
1226*77c1e3ccSAndroid Build Coastguard Worker     3526, 4095, 4095, 0,    3473, 3661, 0,    2388, 0,    4095, 639,  4095,
1227*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 2390, 3715, 4095, 0,    0,    0,    740,  4095, 1432, 0,
1228*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    4057, 0,    0,    757,  4095, 4095, 0,    1437, 0,    0,
1229*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    0,    0,    0,    0,    272,  4095, 4095, 4095, 2175, 4058,
1230*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 4095, 4095, 3959, 3535, 0,    4095, 0,    0,    4095, 4095,
1231*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    0,    4095, 4095, 4095, 3440, 3811, 0,    4095, 4095,
1232*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    4095, 3193, 3674, 2819, 4095, 4095, 4048, 0,    0,
1233*77c1e3ccSAndroid Build Coastguard Worker     4037, 4095, 3110, 4095, 1003, 0,    3650, 4095, 4095, 3154, 0,    1274,
1234*77c1e3ccSAndroid Build Coastguard Worker     2192, 4095, 0,    4095, 0,    2814, 981,  370,  1407, 0,    4095, 1518,
1235*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    0,    0,    0,    4095, 1577, 0,    4095, 0,    2607, 4095,
1236*77c1e3ccSAndroid Build Coastguard Worker     3583, 0,    0,    4095, 1983, 1498, 4095, 4095, 2645, 4095, 4095, 3480,
1237*77c1e3ccSAndroid Build Coastguard Worker     2587, 4095, 0,    0,    0,    0,    4095, 0,    4095, 4095, 0,    284,
1238*77c1e3ccSAndroid Build Coastguard Worker     3973, 0,    0,    3677, 2463, 4095, 1338, 0,    4095, 0,    0,    4095,
1239*77c1e3ccSAndroid Build Coastguard Worker     212,  2000, 4095, 4095, 0,    4095, 3780, 2039, 4095, 2453, 4095, 2050,
1240*77c1e3ccSAndroid Build Coastguard Worker     2660, 1,    3839, 5,    1,    505,  809,  2907, 0,    0,    0,    1421,
1241*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    0,    4095, 4095, 4095, 552,  0,    0,    4095, 3056, 0,
1242*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    0,    4095, 0,    3386, 0,    0,    0,    4095, 0,
1243*77c1e3ccSAndroid Build Coastguard Worker     0,    3404, 2702, 3534, 4095, 3562, 0,    4095, 4095, 150,  4095, 0,
1244*77c1e3ccSAndroid Build Coastguard Worker     0,    3599, 4095, 4095, 0,    0,    0,    4095, 4095, 2093, 4095, 3753,
1245*77c1e3ccSAndroid Build Coastguard Worker     3754, 4095, 0,    4095, 2733, 4095, 4095, 0,    0,    4095, 0,    0,
1246*77c1e3ccSAndroid Build Coastguard Worker     0,    1496, 4095, 2366, 2936, 2494, 4095, 744,  1173, 4095, 0,    0,
1247*77c1e3ccSAndroid Build Coastguard Worker     0,    1966, 4095, 4095, 0,    178,  3254, 4095, 4095, 995,  4095, 2083,
1248*77c1e3ccSAndroid Build Coastguard Worker     0,    2639, 4095, 3422, 4095, 4095, 4095, 0,    842,  4095, 4095, 552,
1249*77c1e3ccSAndroid Build Coastguard Worker     3681, 4095, 0,    1075, 2631, 554,  0,    0,    4095, 0,    0,    0,
1250*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    0,    0,    2234, 0,    1098, 4095, 3164, 4095, 0,
1251*77c1e3ccSAndroid Build Coastguard Worker     2748, 0,    0,    0,    4095, 4095, 4095, 1724, 891,  3496, 3964, 4095,
1252*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1923, 4095, 4095, 4095, 3118, 0,    0,    0,    4095, 4095,
1253*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    3856, 4095, 0,    0,    4095, 4095, 2647, 0,    2089, 4095,
1254*77c1e3ccSAndroid Build Coastguard Worker     471,  0,    4095, 0,    0,    0,    4095, 0,    1263, 2969, 289,  0,
1255*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 289,  0,    0,    2965, 0,    0,    3280, 2279, 4091, 5,
1256*77c1e3ccSAndroid Build Coastguard Worker     512,  1776, 4,    2046, 3994, 1,    4095, 898,  4095, 0,    0,    0,
1257*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 0,    4095, 4095, 1930, 0,    0,    3725, 4095, 4095, 0,
1258*77c1e3ccSAndroid Build Coastguard Worker     2593, 4095, 0,    4095, 984,  0,    4095, 2388, 0,    0,    4095, 4095,
1259*77c1e3ccSAndroid Build Coastguard Worker     3341, 4095, 0,    2787, 0,    831,  2978, 4095, 0,    0,    0,    4095,
1260*77c1e3ccSAndroid Build Coastguard Worker     1624, 4095, 1054, 1039, 0,    89,   3565, 0,    4095, 468,  0,    4095,
1261*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 4095, 0,    3907, 0,    0,    0,    0,    0,    0,
1262*77c1e3ccSAndroid Build Coastguard Worker     4095, 1898, 2178, 4095, 0,    3708, 2825, 0,    4095, 0,    4095, 4095,
1263*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    811,  1078, 0,    4095, 0,    3478, 0,    0,    1127, 0,
1264*77c1e3ccSAndroid Build Coastguard Worker     504,  4095, 4095, 2006, 4095, 0,    2666, 1172, 4095, 4095, 4095, 4095,
1265*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    199,  4095, 0,    2355, 2650, 2961, 0,    0,    0,    4095,
1266*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 0,    4095, 1477, 0,    0,    1946, 0,    3352, 1988,
1267*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    2321, 4095, 0,    4095, 3367, 0,    0,    4095, 4095, 1946,
1268*77c1e3ccSAndroid Build Coastguard Worker     0,    4034, 0,    0,    4095, 4095, 0,    0,    0,    0,    4095, 973,
1269*77c1e3ccSAndroid Build Coastguard Worker     1734, 3966, 4095, 0,    3780, 1242, 0,    4095, 1301, 0,    1513, 4095,
1270*77c1e3ccSAndroid Build Coastguard Worker     1079, 4095, 0,    0,    1316, 4095, 4095, 675,  2713, 2006, 4095, 4095,
1271*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    4095, 4095, 0,    3542, 4095, 0,    2365, 130,  4095, 2919,
1272*77c1e3ccSAndroid Build Coastguard Worker     0,    4095, 3434, 0,    905,  4095, 673,  4095, 4095, 0,    3923, 293,
1273*77c1e3ccSAndroid Build Coastguard Worker     4095, 213,  4095, 4095, 1334, 4095, 0,    3317, 0,    0,    0,    4095,
1274*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 2598, 2010, 0,    0,    3507, 0,    0,    0,    489,  0,
1275*77c1e3ccSAndroid Build Coastguard Worker     0,    1782, 2681, 3303, 4095, 4095, 1955, 4095, 4095, 4095, 203,  1973,
1276*77c1e3ccSAndroid Build Coastguard Worker     4095, 4020, 0,    4095, 1538, 0,    373,  1934, 4095, 0,    4095, 2244,
1277*77c1e3ccSAndroid Build Coastguard Worker     4095, 1936, 4095, 640,  0,    4095, 0,    0,    0,    3653, 4095, 1966,
1278*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 0,    4095, 843,  0,    4095, 4095, 4095, 1646,
1279*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    0,    4095, 4095, 4095, 2164, 0,    0,    0,    2141, 4095,
1280*77c1e3ccSAndroid Build Coastguard Worker     0,    903,  4095, 4095, 0,    624,  4095, 792,  0,    0,    0,    0,
1281*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    4095, 0,    4095, 4095, 2466, 0,    3631, 0,    4095,
1282*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    941,  4095, 4095, 1609, 4095, 4095, 0,    0,    2398,
1283*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 2579, 0,    4020, 3485, 0,    0,    4095, 0,    4095, 0,
1284*77c1e3ccSAndroid Build Coastguard Worker     3158, 2355, 0,    4095, 4095, 4095, 0,    0,    4095, 0,    0,    4095,
1285*77c1e3ccSAndroid Build Coastguard Worker     475,  2272, 1010, 0,    0,    4095, 0,    0,    4095, 841,  4095, 4095,
1286*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    4095, 0,    1046, 4095, 1738, 708,  4095, 0,    4095,
1287*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 4095, 0,    4095, 4095, 0,    0,    0,    4032, 0,
1288*77c1e3ccSAndroid Build Coastguard Worker     2679, 0,    1564, 0,    0,    0,    659,  1915, 4095, 3682, 0,    3660,
1289*77c1e3ccSAndroid Build Coastguard Worker     4095, 723,  1383, 2499, 1353, 4095, 0,    3898, 2322, 3798, 4095, 0,
1290*77c1e3ccSAndroid Build Coastguard Worker     444,  2277, 3729, 4095, 4095, 4095, 3054, 387,  3309, 4048, 3793, 2842,
1291*77c1e3ccSAndroid Build Coastguard Worker     2087, 0,    3274, 2454, 518,  0,    4095, 0,    4095, 4095, 3358, 4095,
1292*77c1e3ccSAndroid Build Coastguard Worker     2083, 2105, 0,    0,    0,    1125, 2636, 0,    0,    0,    0,    736,
1293*77c1e3ccSAndroid Build Coastguard Worker     0,    349,  0,    4095, 2031, 4095, 992,  0,    4095, 3284, 4095, 214,
1294*77c1e3ccSAndroid Build Coastguard Worker     3692, 4010, 402,  0,    0,    3776, 4095, 4095, 4095, 4095, 803,  2095,
1295*77c1e3ccSAndroid Build Coastguard Worker     3864, 4095, 3323, 0,    0,    361,  1634, 0,    983,  0,    1181, 4095,
1296*77c1e3ccSAndroid Build Coastguard Worker     1791, 4095, 367,  792,  4095, 4095, 3315, 3149, 4095, 62,   4095, 1791,
1297*77c1e3ccSAndroid Build Coastguard Worker     3708, 2030, 4095, 1237, 0,    4095, 4095, 0,    0,    0,    0,    4095,
1298*77c1e3ccSAndroid Build Coastguard Worker     1902, 2257, 4095, 4095, 0,    0,    2929, 4095, 0,    4095, 2356, 4095,
1299*77c1e3ccSAndroid Build Coastguard Worker     2877, 1296, 4095, 0,    0,    0,    1310, 1968, 820,  4095, 4095, 4095,
1300*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    0,    4095, 4095, 4095, 2897, 1787, 2218, 0,    129,
1301*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0,    4095, 2331, 4095, 4095, 3192, 4095, 1744, 755,  0,
1302*77c1e3ccSAndroid Build Coastguard Worker     1905, 0,    4095, 4095, 4095, 0,    0,    4095, 4095, 4095, 0,    0,
1303*77c1e3ccSAndroid Build Coastguard Worker     0,    1467, 266,  1719, 4095, 729,  4095, 4095, 2647, 3543, 3388, 3326,
1304*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 4095, 4095, 1416, 4095, 2131, 810,  0,    0,    4095,
1305*77c1e3ccSAndroid Build Coastguard Worker     4095, 1250, 0,    0,    4095, 2722, 1493, 4095, 0,    4095, 0,    2895,
1306*77c1e3ccSAndroid Build Coastguard Worker     0,    3847, 0,    2078, 0,    0,    0,    4095, 4095, 4095, 4095, 0,
1307*77c1e3ccSAndroid Build Coastguard Worker     4095, 2651, 4095, 4095, 351,  2675, 4095, 0,    858,  0,    0,    0,
1308*77c1e3ccSAndroid Build Coastguard Worker     816,  4095, 0,    4095, 0,    3842, 1990, 593,  0,    0,    3992, 4095,
1309*77c1e3ccSAndroid Build Coastguard Worker     4095, 0,    4095, 1314, 4095, 4095, 1864, 2561, 4095, 1339, 0,    4095,
1310*77c1e3ccSAndroid Build Coastguard Worker     2201, 4095, 0,    1403, 0,    0,    4095, 4095, 4095, 0,    0,    0,
1311*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    577,  4095, 995,  2534, 827,  1431, 4095, 4095, 778,
1312*77c1e3ccSAndroid Build Coastguard Worker     1405, 0,    0,    4095, 0,    4095, 1327, 4095, 0,    2725, 3351, 3937,
1313*77c1e3ccSAndroid Build Coastguard Worker     741,  0,    2690, 2849, 4095, 4095, 2151, 0,    4095, 0,    4095, 4095,
1314*77c1e3ccSAndroid Build Coastguard Worker     4095, 1342, 142,  1920, 1007, 2001
1315*77c1e3ccSAndroid Build Coastguard Worker   };
1316*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
1317*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(buffer));
1318*77c1e3ccSAndroid Build Coastguard Worker 
1319*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1320*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I42016, kWidth, kHeight, 1,
1321*77c1e3ccSAndroid Build Coastguard Worker                                img_data));
1322*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1323*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1324*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1325*77c1e3ccSAndroid Build Coastguard Worker   img.monochrome = 1;
1326*77c1e3ccSAndroid Build Coastguard Worker   img.csp = AOM_CSP_UNKNOWN;
1327*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1328*77c1e3ccSAndroid Build Coastguard Worker   img.planes[1] = img.planes[2] = nullptr;
1329*77c1e3ccSAndroid Build Coastguard Worker   img.stride[1] = img.stride[2] = 0;
1330*77c1e3ccSAndroid Build Coastguard Worker 
1331*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1332*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1333*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1334*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_GOOD_QUALITY));
1335*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1336*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 2;
1337*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_12;
1338*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 12;
1339*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1340*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1341*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
1342*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 53;
1343*77c1e3ccSAndroid Build Coastguard Worker   cfg.monochrome = 1;
1344*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 22;
1345*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 30;
1346*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1347*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1348*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH));
1349*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 26));
1350*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 3));
1351*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 6));
1352*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1353*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE));
1354*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1355*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM));
1356*77c1e3ccSAndroid Build Coastguard Worker 
1357*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1358*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1359*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1360*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1361*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1362*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1363*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1364*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1365*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1366*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1367*77c1e3ccSAndroid Build Coastguard Worker 
1368*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1369*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1370*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_encode(&enc, &img, 0, 1, AOM_EFLAG_FORCE_KF));
1371*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1372*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1373*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1374*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1375*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1376*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1377*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1378*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1379*77c1e3ccSAndroid Build Coastguard Worker 
1380*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1381*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1382*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1383*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1384*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1385*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1386*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1387*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1388*77c1e3ccSAndroid Build Coastguard Worker 
1389*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1390*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1391*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1392*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1393*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1394*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1395*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1396*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1397*77c1e3ccSAndroid Build Coastguard Worker 
1398*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1399*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1400*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1401*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1402*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1403*77c1e3ccSAndroid Build Coastguard Worker 
1404*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1405*77c1e3ccSAndroid Build Coastguard Worker }
1406*77c1e3ccSAndroid Build Coastguard Worker 
1407*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/272139363: signed integer overflow in
1408*77c1e3ccSAndroid Build Coastguard Worker // update_b_sep_sym().
1409*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 10bitSignedIntegerOverflowInUpdateBSepSym) {
1410*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 34;
1411*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1412*77c1e3ccSAndroid Build Coastguard Worker   static const uint16_t buffer[3 * kWidth * kHeight] = {
1413*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1414*77c1e3ccSAndroid Build Coastguard Worker     61, 765, 674, 188, 367, 944, 153, 275, 906, 433, 154, 51, 8, 855, 186, 154,
1415*77c1e3ccSAndroid Build Coastguard Worker     392, 0, 634, 3, 690, 1023, 1023, 1023, 1023, 1023, 1023, 8, 1, 64, 426, 0,
1416*77c1e3ccSAndroid Build Coastguard Worker     100, 344, 944, 816, 816, 33, 1023, 1023, 1023, 1023, 295, 1023, 1023, 1023,
1417*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 1015, 1023, 231, 1020, 254, 439, 439, 894, 439, 150, 1019,
1418*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 385, 320, 575,
1419*77c1e3ccSAndroid Build Coastguard Worker     682, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 511, 699, 987, 3, 140,
1420*77c1e3ccSAndroid Build Coastguard Worker     661, 120, 33, 143, 0, 0, 0, 3, 40, 625, 585, 16, 579, 160, 867,
1421*77c1e3ccSAndroid Build Coastguard Worker     // U plane:
1422*77c1e3ccSAndroid Build Coastguard Worker     739, 646, 13, 603, 7, 328, 91, 32, 488, 870, 330, 330, 330, 330, 330, 330,
1423*77c1e3ccSAndroid Build Coastguard Worker     109, 330, 330, 330, 3, 545, 945, 249, 35, 561, 801, 32, 931, 639, 801, 91,
1424*77c1e3ccSAndroid Build Coastguard Worker     1023, 827, 844, 948, 631, 894, 854, 601, 432, 504, 85, 1, 0, 0, 89, 89, 0,
1425*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 0, 0, 432, 801, 382, 4, 0, 0, 2, 89, 89, 89, 89, 89, 89, 384, 0, 0,
1426*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 0, 0, 1023, 1019, 1, 3, 691, 575, 691, 691, 691, 691, 691, 691,
1427*77c1e3ccSAndroid Build Coastguard Worker     691, 691, 691, 691, 691, 84, 527, 4, 485, 8, 682, 698, 340, 1015, 706,
1428*77c1e3ccSAndroid Build Coastguard Worker     // V plane:
1429*77c1e3ccSAndroid Build Coastguard Worker     49, 10, 28, 1023, 1023, 1023, 0, 32, 32, 872, 114, 1003, 1023, 57, 477, 999,
1430*77c1e3ccSAndroid Build Coastguard Worker     1023, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309,
1431*77c1e3ccSAndroid Build Coastguard Worker     9, 418, 418, 418, 418, 418, 418, 0, 0, 0, 1023, 4, 5, 0, 0, 1023, 0, 0, 0,
1432*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 64, 0, 155, 709, 3, 331, 807, 633, 1023,
1433*77c1e3ccSAndroid Build Coastguard Worker     1018, 646, 886, 991, 692, 915, 294, 0, 35, 2, 0, 471, 643, 770, 346, 176,
1434*77c1e3ccSAndroid Build Coastguard Worker     32, 329, 322, 302, 61, 765, 674, 188, 367, 944, 153, 275, 906, 433, 154
1435*77c1e3ccSAndroid Build Coastguard Worker   };
1436*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
1437*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(buffer));
1438*77c1e3ccSAndroid Build Coastguard Worker 
1439*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1440*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I44416, kWidth, kHeight, 1,
1441*77c1e3ccSAndroid Build Coastguard Worker                                img_data));
1442*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1443*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1444*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1445*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1446*77c1e3ccSAndroid Build Coastguard Worker 
1447*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1448*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1449*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1450*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_ALL_INTRA));
1451*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1452*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 1;
1453*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_10;
1454*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 10;
1455*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1456*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1457*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_limit = 1;
1458*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
1459*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_mode = AOM_KF_DISABLED;
1460*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_max_dist = 0;
1461*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 3;
1462*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 54;
1463*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1464*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1465*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH));
1466*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 28));
1467*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_COLUMNS, 3));
1468*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 0));
1469*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1470*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE));
1471*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1472*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_SKIP_POSTPROC_FILTERING, 1));
1473*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1474*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM));
1475*77c1e3ccSAndroid Build Coastguard Worker 
1476*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1477*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1478*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1479*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1480*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1481*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1482*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1483*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1484*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1485*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1486*77c1e3ccSAndroid Build Coastguard Worker 
1487*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1488*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1489*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1490*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1491*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1492*77c1e3ccSAndroid Build Coastguard Worker 
1493*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1494*77c1e3ccSAndroid Build Coastguard Worker }
1495*77c1e3ccSAndroid Build Coastguard Worker 
1496*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/319140742: signed integer overflow in
1497*77c1e3ccSAndroid Build Coastguard Worker // update_b_sep_sym().
1498*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 10bitSignedIntegerOverflowInUpdateBSepSym2) {
1499*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 326;
1500*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1501*77c1e3ccSAndroid Build Coastguard Worker   static const uint16_t buffer[kWidth * kHeight] = {
1502*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1503*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    1023, 1023, 0,    623,  0,    0,    1023, 1023, 0,
1504*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    523,  1023, 2,    0,    0,    863,  1023, 1023, 409,
1505*77c1e3ccSAndroid Build Coastguard Worker     7,    1023, 0,    409,  1023, 0,    579,  1023, 1023, 1023, 0,    0,
1506*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 446,  1023, 1023, 0,    0,    1023, 0,    0,    829,  1023,
1507*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 939,  0,    0,    23,   1022, 990,  1023, 0,    0,    4,
1508*77c1e3ccSAndroid Build Coastguard Worker     0,    299,  0,    0,    1023, 1023, 629,  688,  1023, 1023, 266,  1023,
1509*77c1e3ccSAndroid Build Coastguard Worker     865,  0,    413,  0,    267,  0,    0,    69,   1023, 866,  1023, 885,
1510*77c1e3ccSAndroid Build Coastguard Worker     0,    762,  330,  382,  0,    1023, 1023, 734,  504,  899,  119,  0,
1511*77c1e3ccSAndroid Build Coastguard Worker     378,  1011, 0,    0,    1023, 364,  0,    1023, 1023, 462,  1023, 0,
1512*77c1e3ccSAndroid Build Coastguard Worker     504,  1023, 1023, 0,    695,  1023, 57,   1023, 1023, 362,  0,    0,
1513*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1023, 1023, 387,  12,   929,  1023, 0,    194,  1023, 0,
1514*77c1e3ccSAndroid Build Coastguard Worker     1023, 505,  0,    1023, 1023, 1023, 1023, 1023, 0,    0,    676,  0,
1515*77c1e3ccSAndroid Build Coastguard Worker     6,    683,  70,   0,    0,    1023, 226,  1023, 320,  758,  0,    0,
1516*77c1e3ccSAndroid Build Coastguard Worker     648,  1023, 867,  550,  630,  960,  1023, 1023, 1023, 0,    0,    822,
1517*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    1023, 1011, 1023, 1023, 0,    0,    15,   30,   0,
1518*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    0,    0,    84,   954,  1023, 933,  416,  333,  323,
1519*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1023, 355,  1023, 176,  1023, 1023, 886,  87,   1023, 0,
1520*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 562,  0,    1023, 1023, 354,  0,    0,    1023, 0,
1521*77c1e3ccSAndroid Build Coastguard Worker     86,   0,    0,    1023, 0,    1023, 192,  0,    1023, 0,    1023, 0,
1522*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    735,  1023, 1023, 1023, 0,    372,  988,  131,  1023, 1023,
1523*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 1023, 1023, 1023, 970,  1023, 1023, 248,  757,  665,  330,
1524*77c1e3ccSAndroid Build Coastguard Worker     223,  273,  0,    274,  1023, 0,    1023, 613,  786,  1023, 792,  0,
1525*77c1e3ccSAndroid Build Coastguard Worker     390,  282,  0,    1023, 0,    1023, 0,    1023, 1023, 1023, 614,  993,
1526*77c1e3ccSAndroid Build Coastguard Worker     135,  737,  662,  0,    1023, 524,  970,  1023, 0,    906,  1023, 1023,
1527*77c1e3ccSAndroid Build Coastguard Worker     959,  1023, 1023, 1023, 1023, 836,  838,  0,    0,    0,    0,    0,
1528*77c1e3ccSAndroid Build Coastguard Worker     1023, 917,  492,  290,  1023, 1023, 817,  1023, 0,    0,    588,  410,
1529*77c1e3ccSAndroid Build Coastguard Worker     419,  0,    1023, 1023, 178,  0,    0,    563,  775,  977,  1023, 1023,
1530*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 0,    370,  434,  1023, 963,  587,  0,    0,    1023, 1023,
1531*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 1023, 619,  0,    1023, 352,  1023, 0,    0,    0,
1532*77c1e3ccSAndroid Build Coastguard Worker     133,  557,  36,   1023, 1023, 1023, 0,    469,  1023, 1023, 0,    900,
1533*77c1e3ccSAndroid Build Coastguard Worker     59,   841,  1023, 886,  0,    193,  126,  263,  119,  629,  0,    1023,
1534*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 0,    0,    478,  0,    1023, 63,   1023, 0,    0,    0,
1535*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    0,    1023, 888,  1023, 905,  646,  0,    0,    1023,
1536*77c1e3ccSAndroid Build Coastguard Worker     752,  1023, 1023, 0,    1023, 0,    0,    648,  1023, 0,    0,    838,
1537*77c1e3ccSAndroid Build Coastguard Worker     0,    321,  1023, 475,  0,    215,  867,  1023, 0,    1023, 1023, 624,
1538*77c1e3ccSAndroid Build Coastguard Worker     417,  1023, 426,  0,    0,    960,  1020, 839,  687,  1023, 161,  1023,
1539*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 968,  0,    95,   430,  0,    132,  1023, 1023, 113,
1540*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 1023, 606,  1023, 0,    0,    31,   1023, 1023, 0,    180,
1541*77c1e3ccSAndroid Build Coastguard Worker     140,  654,  1023, 1023, 1023, 1023, 1023, 779,  1023, 0,    0,    1023,
1542*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    1023, 0,    0,    1023, 963,  723,  536,  1023, 0,
1543*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    337,  812,  0,    0,    0,    428,  48,   0,    321,  205,
1544*77c1e3ccSAndroid Build Coastguard Worker     0,    587,  799,  272,  5,    1023, 322,  0,    761,  0,    749,  1023,
1545*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1023, 1023, 1023, 1023, 242,  402,  98,   0,    1023, 884,
1546*77c1e3ccSAndroid Build Coastguard Worker     219,  1023, 0,    1023, 0,    0,    0,    106,  1023, 0,    1023, 414,
1547*77c1e3ccSAndroid Build Coastguard Worker     1023, 0,    1023, 619,  0,    0,    973,  854,  82,   1023, 1023, 1023,
1548*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 1023, 0,    0,    588,  433,  0,    0,    961,  0,    0,
1549*77c1e3ccSAndroid Build Coastguard Worker     0,    917,  859,  461,  455,  68,   1023, 409,  1023, 821,  1023, 487,
1550*77c1e3ccSAndroid Build Coastguard Worker     1023, 0,    717,  0,    613,  0,    0,    840,  932,  782,  1023, 1023,
1551*77c1e3ccSAndroid Build Coastguard Worker     576,  1023, 0,    1023, 1023, 187,  876,  162,  0,    1023, 1023, 946,
1552*77c1e3ccSAndroid Build Coastguard Worker     873,  0,    0,    953,  0,    537,  0,    0,    1023, 193,  807,  756,
1553*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1023, 732,  1023, 1023, 1023, 0,    0,    1023, 1023, 1023,
1554*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 119,  0,    0,    90,   1023, 0,    1023, 0,    0,    0,
1555*77c1e3ccSAndroid Build Coastguard Worker     1023, 366,  1023, 655,  0,    58,   1023, 1023, 8,    1023, 1023, 24,
1556*77c1e3ccSAndroid Build Coastguard Worker     1023, 103,  0,    0,    1023, 919,  1023, 566,  1023, 0,    0,    480,
1557*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    0,    807,  0,    1023, 0,    273,  412,  632,  1023,
1558*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 10,   633,  1023, 692,  978,  0,    0,    1023, 1023, 1023,
1559*77c1e3ccSAndroid Build Coastguard Worker     25,   494,  215,  0,    148,  1023, 840,  118,  1023, 1023, 999,  1023,
1560*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    0,    1023, 435,  894,  0,    1023, 1023, 168,  1023,
1561*77c1e3ccSAndroid Build Coastguard Worker     1023, 211,  1023, 1023, 656,  1023, 0,    0,    0,    744,  238,  1023,
1562*77c1e3ccSAndroid Build Coastguard Worker     0,    196,  907,  0,    0,    0,    838,  726,  1023, 1023, 1023, 0,
1563*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    1023, 0,    1023, 1023, 1023, 0,    1023, 0,    0,    0,
1564*77c1e3ccSAndroid Build Coastguard Worker     323,  1023, 1023, 0,    1023, 0,    0,    925,  582,  1023, 0,    685,
1565*77c1e3ccSAndroid Build Coastguard Worker     1023, 661,  464,  0,    0,    0,    1023, 0,    807,  0,    1023, 1023,
1566*77c1e3ccSAndroid Build Coastguard Worker     1023, 100,  0,    1023, 302,  1023, 1023, 1023, 616,  0,    1023, 0,
1567*77c1e3ccSAndroid Build Coastguard Worker     0,    377,  1023, 1023, 1023, 0,    1023, 555,  1023, 784,  0,    0,
1568*77c1e3ccSAndroid Build Coastguard Worker     1023, 0,    0,    1023, 755,  0,    839,  1023, 0,    0,    0,    1023,
1569*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    1023, 413,  0,    1023, 1023, 384,  0,    823,  797,
1570*77c1e3ccSAndroid Build Coastguard Worker     1023, 0,    1023, 0,    0,    1023, 1023, 1023, 1023, 0,    1023, 39,
1571*77c1e3ccSAndroid Build Coastguard Worker     0,    473,  299,  0,    0,    1023, 567,  1023, 1023, 0,    0,    1023,
1572*77c1e3ccSAndroid Build Coastguard Worker     650,  1023, 41,   1023, 0,    1023, 0,    1023, 0,    1023, 0,    0,
1573*77c1e3ccSAndroid Build Coastguard Worker     444,  1023, 23,   0,    503,  97,   0,    1023, 0,    890,  59,   578,
1574*77c1e3ccSAndroid Build Coastguard Worker     0,    201,  1023, 672,  1023, 593,  1023, 599,  213,  1023, 1023, 1023,
1575*77c1e3ccSAndroid Build Coastguard Worker     986,  1023, 335,  1023, 457,  0,    888,  1023, 1023, 97,   308,  259,
1576*77c1e3ccSAndroid Build Coastguard Worker     813,  1023, 1023, 1023, 0,    1023, 798,  907,  105,  0,    1023, 0,
1577*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 0,    970,  518,  0,    635,  0,    634,  329,  1023, 430,
1578*77c1e3ccSAndroid Build Coastguard Worker     0,    17,   1023, 1023, 1023, 0,    0,    407,  1023, 1023, 0,    1023,
1579*77c1e3ccSAndroid Build Coastguard Worker     0,    0,    0,    0,    1023, 1023, 1023, 402,  1023, 0,    0,    101,
1580*77c1e3ccSAndroid Build Coastguard Worker     1023, 1023, 1023, 1023, 1023, 1023, 425,  791,  1023, 1023, 961,  0,
1581*77c1e3ccSAndroid Build Coastguard Worker     0,    1023, 474,  1023, 1023, 1023, 1023, 468,  1023, 1023, 0,    1023,
1582*77c1e3ccSAndroid Build Coastguard Worker     215,  0,    1023, 1023, 334,  463,  286,  1023, 0,    1023, 0,    1023,
1583*77c1e3ccSAndroid Build Coastguard Worker     270,  401,  0,    0,    1023, 0,    794,  0,    0,    0,    1023, 0,
1584*77c1e3ccSAndroid Build Coastguard Worker     1023, 172,  317,  905,  950,  0
1585*77c1e3ccSAndroid Build Coastguard Worker   };
1586*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
1587*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(buffer));
1588*77c1e3ccSAndroid Build Coastguard Worker 
1589*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1590*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I42016, kWidth, kHeight, 1,
1591*77c1e3ccSAndroid Build Coastguard Worker                                img_data));
1592*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1593*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1594*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1595*77c1e3ccSAndroid Build Coastguard Worker   img.monochrome = 1;
1596*77c1e3ccSAndroid Build Coastguard Worker   img.csp = AOM_CSP_UNKNOWN;
1597*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1598*77c1e3ccSAndroid Build Coastguard Worker   img.planes[1] = img.planes[2] = nullptr;
1599*77c1e3ccSAndroid Build Coastguard Worker   img.stride[1] = img.stride[2] = 0;
1600*77c1e3ccSAndroid Build Coastguard Worker 
1601*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1602*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1603*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1604*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_GOOD_QUALITY));
1605*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1606*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 0;
1607*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_10;
1608*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 10;
1609*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1610*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1611*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 6;
1612*77c1e3ccSAndroid Build Coastguard Worker   cfg.monochrome = 1;
1613*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 54;
1614*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 62;
1615*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1616*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1617*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH));
1618*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 58));
1619*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 1));
1620*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 6));
1621*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1622*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE));
1623*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1624*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM));
1625*77c1e3ccSAndroid Build Coastguard Worker 
1626*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1627*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1628*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1629*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1630*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(pkt, nullptr);
1631*77c1e3ccSAndroid Build Coastguard Worker 
1632*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1633*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1634*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1635*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1636*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1637*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1638*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1639*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1640*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1641*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1642*77c1e3ccSAndroid Build Coastguard Worker 
1643*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1644*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1645*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1646*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1647*77c1e3ccSAndroid Build Coastguard Worker 
1648*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1649*77c1e3ccSAndroid Build Coastguard Worker }
1650*77c1e3ccSAndroid Build Coastguard Worker 
1651*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/277121724: signed integer overflow in
1652*77c1e3ccSAndroid Build Coastguard Worker // update_b_sep_sym().
1653*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 8bitSignedIntegerOverflowInUpdateBSepSym) {
1654*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 198;
1655*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1656*77c1e3ccSAndroid Build Coastguard Worker   // 8-bit YUV 4:2:2
1657*77c1e3ccSAndroid Build Coastguard Worker   static const unsigned char buffer[2 * kWidth * kHeight] = {
1658*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1659*77c1e3ccSAndroid Build Coastguard Worker     35, 225, 56, 91, 8, 142, 137, 143, 224, 49, 217, 57, 202, 163, 159, 246,
1660*77c1e3ccSAndroid Build Coastguard Worker     232, 134, 135, 14, 76, 101, 239, 88, 186, 159, 118, 23, 114, 20, 108, 41,
1661*77c1e3ccSAndroid Build Coastguard Worker     72, 17, 58, 242, 45, 146, 230, 14, 135, 140, 34, 61, 189, 181, 222, 71, 98,
1662*77c1e3ccSAndroid Build Coastguard Worker     221, 5, 199, 244, 85, 229, 163, 105, 87, 144, 105, 64, 150, 36, 233, 235, 1,
1663*77c1e3ccSAndroid Build Coastguard Worker     179, 190, 50, 222, 176, 109, 166, 18, 80, 129, 45, 9, 218, 144, 234, 10,
1664*77c1e3ccSAndroid Build Coastguard Worker     148, 117, 37, 10, 232, 139, 206, 92, 208, 247, 128, 79, 202, 79, 212, 89,
1665*77c1e3ccSAndroid Build Coastguard Worker     185, 152, 206, 182, 83, 105, 21, 86, 150, 84, 21, 165, 34, 251, 174, 240,
1666*77c1e3ccSAndroid Build Coastguard Worker     172, 155, 254, 85, 98, 25, 96, 78, 230, 253, 36, 19, 247, 155, 112, 216,
1667*77c1e3ccSAndroid Build Coastguard Worker     166, 114, 229, 118, 197, 149, 186, 194, 128, 45, 219, 26, 36, 77, 110, 45,
1668*77c1e3ccSAndroid Build Coastguard Worker     252, 238, 183, 161, 171, 96, 232, 108, 73, 61, 243, 58, 155, 38, 91, 209,
1669*77c1e3ccSAndroid Build Coastguard Worker     187, 206, 16, 165, 236, 145, 69, 126, 102, 10, 4, 43, 191, 106, 193, 240,
1670*77c1e3ccSAndroid Build Coastguard Worker     132, 226, 38, 78, 7, 152, 101, 255, 254, 39, 33, 86, 35, 247, 199, 179, 239,
1671*77c1e3ccSAndroid Build Coastguard Worker     198, 165, 58, 190, 171, 226, 94, 158, 21, 190, 151, 75, 176, 11, 53, 199,
1672*77c1e3ccSAndroid Build Coastguard Worker     87, 91, 1, 226, 20, 117, 96, 75, 192, 101, 200, 125, 106, 233, 176, 63, 204,
1673*77c1e3ccSAndroid Build Coastguard Worker     114, 16, 31, 222, 15, 14, 71, 2, 25, 47, 100, 174, 26, 209, 138, 138, 211,
1674*77c1e3ccSAndroid Build Coastguard Worker     147, 164, 204, 9, 104, 135, 250, 9, 201, 88, 218, 71, 251, 61, 199, 0, 34,
1675*77c1e3ccSAndroid Build Coastguard Worker     59, 115, 228, 161, 100, 132, 50, 4, 117, 100, 191, 126, 53, 28, 193, 42,
1676*77c1e3ccSAndroid Build Coastguard Worker     155, 206, 79, 80, 117, 11, 3, 253, 181, 181, 138, 239, 107, 142, 216, 57,
1677*77c1e3ccSAndroid Build Coastguard Worker     202, 126, 229, 250, 60, 62, 150, 128, 95, 32, 251, 207, 236, 208, 247, 183,
1678*77c1e3ccSAndroid Build Coastguard Worker     59, 19, 117, 40, 106, 87, 140, 57, 109, 190, 51, 105, 226, 116, 156, 3, 35,
1679*77c1e3ccSAndroid Build Coastguard Worker     86, 255, 138, 52, 211, 245, 76, 83, 109, 113, 77, 106, 77, 18, 56, 235, 158,
1680*77c1e3ccSAndroid Build Coastguard Worker     24, 53, 151, 104, 152, 21, 15, 46, 163, 144, 217, 168, 154, 44, 80, 25, 11,
1681*77c1e3ccSAndroid Build Coastguard Worker     37, 100, 235, 145, 154, 113, 0, 140, 153, 80, 64, 19, 121, 185, 144, 43,
1682*77c1e3ccSAndroid Build Coastguard Worker     206, 16, 16, 72, 189, 175, 231, 177, 40, 177, 206, 116, 4, 82, 43, 244, 237,
1683*77c1e3ccSAndroid Build Coastguard Worker     22, 252, 71, 194, 106, 4, 112, 0, 108, 137, 126, 80, 122, 142, 43, 205, 22,
1684*77c1e3ccSAndroid Build Coastguard Worker     209, 217, 165, 32, 208, 100, 70, 3, 120, 159, 203, 7, 233, 152, 37, 96, 212,
1685*77c1e3ccSAndroid Build Coastguard Worker     177, 1, 133, 218, 161, 172, 202, 192, 186, 114, 150, 121, 177, 227, 175, 64,
1686*77c1e3ccSAndroid Build Coastguard Worker     127, 153, 113, 91, 198, 0, 111, 227, 226, 218, 71, 62, 5, 43, 128, 27, 3,
1687*77c1e3ccSAndroid Build Coastguard Worker     82, 5, 10, 68, 153, 215, 181, 138, 246, 224, 170, 1, 241, 191, 181, 151,
1688*77c1e3ccSAndroid Build Coastguard Worker     167, 14, 80, 45, 4, 252, 29, 66, 125, 58, 225, 253, 255, 248, 224, 40, 24,
1689*77c1e3ccSAndroid Build Coastguard Worker     236, 46, 11, 219, 154, 134, 12, 76, 72, 97, 239, 50, 39, 85, 182, 55, 219,
1690*77c1e3ccSAndroid Build Coastguard Worker     19, 109, 81, 119, 125, 206, 159, 239, 67, 193, 180, 132, 80, 127, 2, 169,
1691*77c1e3ccSAndroid Build Coastguard Worker     99, 53, 47, 5, 100, 174, 151, 124, 246, 202, 93, 82, 65, 53, 214, 238, 32,
1692*77c1e3ccSAndroid Build Coastguard Worker     218, 15, 254, 153, 95, 79, 189, 67, 233, 47, 83, 48, 125, 144, 206, 82, 69,
1693*77c1e3ccSAndroid Build Coastguard Worker     186, 112, 134, 244, 96, 21, 143, 187, 248, 8, 224, 161, 227, 185, 236, 6,
1694*77c1e3ccSAndroid Build Coastguard Worker     175, 237, 169, 154, 89, 143, 106, 205, 26, 47, 155, 42, 28, 162, 7, 8, 45,
1695*77c1e3ccSAndroid Build Coastguard Worker     // U plane:
1696*77c1e3ccSAndroid Build Coastguard Worker     55, 165, 203, 139, 152, 208, 36, 177, 61, 49, 129, 211, 140, 71, 253, 250,
1697*77c1e3ccSAndroid Build Coastguard Worker     120, 167, 238, 67, 255, 223, 104, 32, 240, 179, 28, 41, 86, 84, 61, 243,
1698*77c1e3ccSAndroid Build Coastguard Worker     169, 212, 201, 0, 9, 236, 89, 194, 204, 75, 228, 250, 27, 81, 137, 29, 255,
1699*77c1e3ccSAndroid Build Coastguard Worker     131, 194, 241, 76, 133, 186, 135, 212, 197, 150, 145, 203, 96, 86, 231, 91,
1700*77c1e3ccSAndroid Build Coastguard Worker     119, 197, 67, 226, 2, 118, 66, 181, 86, 219, 86, 132, 137, 156, 161, 221,
1701*77c1e3ccSAndroid Build Coastguard Worker     18, 55, 170, 35, 206, 201, 193, 38, 63, 229, 29, 110, 96, 14, 135, 229, 99,
1702*77c1e3ccSAndroid Build Coastguard Worker     106, 108, 167, 110, 50, 32, 144, 113, 48, 29, 57, 29, 20, 199, 145, 245, 9,
1703*77c1e3ccSAndroid Build Coastguard Worker     183, 88, 174, 114, 237, 29, 40, 99, 117, 233, 6, 51, 227, 2, 28, 76, 149,
1704*77c1e3ccSAndroid Build Coastguard Worker     190, 23, 240, 73, 113, 10, 73, 240, 105, 220, 129, 26, 144, 214, 34, 4, 24,
1705*77c1e3ccSAndroid Build Coastguard Worker     219, 24, 156, 198, 214, 244, 143, 106, 255, 204, 93, 2, 88, 107, 211, 241,
1706*77c1e3ccSAndroid Build Coastguard Worker     242, 86, 189, 219, 164, 132, 149, 32, 228, 219, 60, 202, 218, 189, 34, 250,
1707*77c1e3ccSAndroid Build Coastguard Worker     160, 158, 36, 212, 212, 41, 233, 61, 92, 121, 170, 220, 192, 232, 255, 124,
1708*77c1e3ccSAndroid Build Coastguard Worker     249, 231, 55, 196, 219, 196, 62, 238, 187, 76, 33, 138, 67, 82, 159, 169,
1709*77c1e3ccSAndroid Build Coastguard Worker     196, 66, 196, 110, 194, 64, 35, 205, 64, 218, 12, 41, 188, 195, 244, 178,
1710*77c1e3ccSAndroid Build Coastguard Worker     17, 80, 8, 149, 39, 110, 146, 164, 162, 215, 227, 107, 103, 47, 52, 95, 3,
1711*77c1e3ccSAndroid Build Coastguard Worker     181, 90, 255, 80, 83, 206, 66, 153, 112, 72, 109, 235, 69, 105, 57, 75, 145,
1712*77c1e3ccSAndroid Build Coastguard Worker     186, 16, 87, 73, 61, 98, 197, 237, 17, 32, 207, 220, 246, 188, 46, 73, 121,
1713*77c1e3ccSAndroid Build Coastguard Worker     84, 252, 164, 111, 21, 98, 13, 170, 174, 170, 231, 77, 10, 113, 9, 217, 11,
1714*77c1e3ccSAndroid Build Coastguard Worker     // V plane:
1715*77c1e3ccSAndroid Build Coastguard Worker     124, 94, 69, 212, 107, 223, 228, 96, 56, 2, 158, 49, 251, 217, 143, 107,
1716*77c1e3ccSAndroid Build Coastguard Worker     113, 17, 84, 169, 208, 43, 28, 37, 176, 54, 235, 150, 135, 135, 221, 94, 50,
1717*77c1e3ccSAndroid Build Coastguard Worker     131, 251, 78, 38, 254, 129, 200, 207, 55, 111, 110, 144, 109, 228, 65, 70,
1718*77c1e3ccSAndroid Build Coastguard Worker     39, 170, 5, 208, 151, 87, 86, 255, 74, 155, 153, 250, 15, 35, 33, 201, 226,
1719*77c1e3ccSAndroid Build Coastguard Worker     117, 119, 220, 238, 133, 229, 69, 122, 160, 114, 245, 182, 13, 65, 2, 228,
1720*77c1e3ccSAndroid Build Coastguard Worker     205, 174, 128, 248, 4, 139, 178, 227, 204, 243, 249, 253, 119, 253, 107,
1721*77c1e3ccSAndroid Build Coastguard Worker     234, 39, 15, 173, 47, 93, 12, 222, 238, 30, 121, 124, 167, 27, 40, 215, 84,
1722*77c1e3ccSAndroid Build Coastguard Worker     172, 130, 66, 43, 165, 55, 225, 79, 84, 153, 59, 110, 64, 176, 54, 123, 82,
1723*77c1e3ccSAndroid Build Coastguard Worker     128, 189, 150, 52, 202, 102, 133, 199, 197, 253, 180, 221, 127, 144, 124,
1724*77c1e3ccSAndroid Build Coastguard Worker     255, 224, 52, 149, 88, 166, 39, 38, 78, 114, 44, 242, 233, 40, 132, 142,
1725*77c1e3ccSAndroid Build Coastguard Worker     152, 213, 112, 244, 221, 7, 52, 206, 246, 51, 182, 160, 247, 154, 183, 209,
1726*77c1e3ccSAndroid Build Coastguard Worker     81, 70, 56, 186, 63, 182, 2, 82, 202, 178, 233, 52, 198, 241, 175, 38, 165,
1727*77c1e3ccSAndroid Build Coastguard Worker     9, 231, 150, 114, 43, 159, 200, 42, 173, 217, 25, 233, 214, 210, 50, 43,
1728*77c1e3ccSAndroid Build Coastguard Worker     159, 231, 102, 241, 246, 77, 76, 115, 77, 81, 114, 194, 182, 236, 0, 236,
1729*77c1e3ccSAndroid Build Coastguard Worker     198, 197, 180, 176, 148, 48, 177, 106, 180, 150, 158, 237, 130, 242, 109,
1730*77c1e3ccSAndroid Build Coastguard Worker     174, 247, 57, 230, 184, 64, 245, 251, 123, 169, 122, 156, 125, 123, 104,
1731*77c1e3ccSAndroid Build Coastguard Worker     238, 1, 235, 187, 53, 67, 38, 50, 139, 123, 149, 111, 72, 80, 17, 175, 186,
1732*77c1e3ccSAndroid Build Coastguard Worker     98, 153, 247, 97, 218, 141, 38, 0, 171, 254, 180, 81, 233, 71, 156, 48, 14,
1733*77c1e3ccSAndroid Build Coastguard Worker     62, 210, 161, 124, 203, 92
1734*77c1e3ccSAndroid Build Coastguard Worker   };
1735*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data = const_cast<unsigned char *>(buffer);
1736*77c1e3ccSAndroid Build Coastguard Worker 
1737*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1738*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_img_wrap(&img, AOM_IMG_FMT_I422, kWidth, kHeight, 1, img_data),
1739*77c1e3ccSAndroid Build Coastguard Worker             &img);
1740*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1741*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1742*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1743*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1744*77c1e3ccSAndroid Build Coastguard Worker 
1745*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1746*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1747*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_ALL_INTRA),
1748*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1749*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1750*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 2;
1751*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_8;
1752*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 8;
1753*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1754*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1755*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_limit = 1;
1756*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
1757*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_mode = AOM_KF_DISABLED;
1758*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_max_dist = 0;
1759*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 43;
1760*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 30;
1761*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 50;
1762*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1763*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_init(&enc, iface, &cfg, 0), AOM_CODEC_OK);
1764*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 40), AOM_CODEC_OK);
1765*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_ROW_MT, 1), AOM_CODEC_OK);
1766*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 4), AOM_CODEC_OK);
1767*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_COLUMNS, 1), AOM_CODEC_OK);
1768*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, 2), AOM_CODEC_OK);
1769*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE),
1770*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1771*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SKIP_POSTPROC_FILTERING, 1),
1772*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1773*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM),
1774*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1775*77c1e3ccSAndroid Build Coastguard Worker 
1776*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1777*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
1778*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1779*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1780*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1781*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1782*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1783*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1784*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1785*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1786*77c1e3ccSAndroid Build Coastguard Worker 
1787*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1788*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, nullptr, 0, 1, 0), AOM_CODEC_OK);
1789*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1790*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1791*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1792*77c1e3ccSAndroid Build Coastguard Worker 
1793*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
1794*77c1e3ccSAndroid Build Coastguard Worker }
1795*77c1e3ccSAndroid Build Coastguard Worker 
1796*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces crbug.com/oss-fuzz/68195: signed integer overflow in
1797*77c1e3ccSAndroid Build Coastguard Worker // linsolve_wiener().
1798*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 8bitSignedIntegerOverflowInLinsolveWiener) {
1799*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 4;
1800*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1801*77c1e3ccSAndroid Build Coastguard Worker   constexpr unsigned char kBuffer[kWidth * kHeight] = {
1802*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1803*77c1e3ccSAndroid Build Coastguard Worker     50, 167, 190, 194, 27, 29, 204, 182, 133, 239, 64, 179,
1804*77c1e3ccSAndroid Build Coastguard Worker   };
1805*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data = const_cast<unsigned char *>(kBuffer);
1806*77c1e3ccSAndroid Build Coastguard Worker 
1807*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1808*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(&img,
1809*77c1e3ccSAndroid Build Coastguard Worker             aom_img_wrap(&img, AOM_IMG_FMT_I420, kWidth, kHeight, 1, img_data));
1810*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1811*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1812*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1813*77c1e3ccSAndroid Build Coastguard Worker   img.monochrome = 1;
1814*77c1e3ccSAndroid Build Coastguard Worker   img.csp = AOM_CSP_UNKNOWN;
1815*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1816*77c1e3ccSAndroid Build Coastguard Worker   img.planes[1] = img.planes[2] = nullptr;
1817*77c1e3ccSAndroid Build Coastguard Worker   img.stride[1] = img.stride[2] = 0;
1818*77c1e3ccSAndroid Build Coastguard Worker 
1819*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1820*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1821*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1822*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_GOOD_QUALITY));
1823*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1824*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 0;
1825*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_8;
1826*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 8;
1827*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1828*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1829*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 32;
1830*77c1e3ccSAndroid Build Coastguard Worker   cfg.monochrome = 1;
1831*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 50;
1832*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 57;
1833*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1834*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
1835*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 53));
1836*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 1));
1837*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_COLUMNS, 1));
1838*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 6));
1839*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1840*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE));
1841*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
1842*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM));
1843*77c1e3ccSAndroid Build Coastguard Worker 
1844*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1845*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1846*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1847*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1848*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(pkt, nullptr);
1849*77c1e3ccSAndroid Build Coastguard Worker 
1850*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1851*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1852*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1853*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1854*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1855*77c1e3ccSAndroid Build Coastguard Worker 
1856*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1857*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1858*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1859*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1860*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1861*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1862*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1863*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1864*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1865*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1866*77c1e3ccSAndroid Build Coastguard Worker 
1867*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1868*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1869*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1870*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1871*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1872*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1873*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x0.
1874*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u);
1875*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1876*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1877*77c1e3ccSAndroid Build Coastguard Worker 
1878*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1879*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
1880*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1881*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1882*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1883*77c1e3ccSAndroid Build Coastguard Worker 
1884*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1885*77c1e3ccSAndroid Build Coastguard Worker }
1886*77c1e3ccSAndroid Build Coastguard Worker 
1887*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/259173819: signed integer overflow in
1888*77c1e3ccSAndroid Build Coastguard Worker // linsolve_wiener().
1889*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 10bitSignedIntegerOverflowInLinsolveWiener) {
1890*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 3;
1891*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1892*77c1e3ccSAndroid Build Coastguard Worker   static const uint16_t buffer[3 * kWidth * kHeight] = {
1893*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1894*77c1e3ccSAndroid Build Coastguard Worker     81, 81, 1023, 1020, 81, 1023, 81, 128, 0,
1895*77c1e3ccSAndroid Build Coastguard Worker     // U plane:
1896*77c1e3ccSAndroid Build Coastguard Worker     273, 273, 273, 273, 273, 273, 273, 273, 273,
1897*77c1e3ccSAndroid Build Coastguard Worker     // V plane:
1898*77c1e3ccSAndroid Build Coastguard Worker     273, 273, 273, 273, 273, 273, 516, 81, 81
1899*77c1e3ccSAndroid Build Coastguard Worker   };
1900*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
1901*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(buffer));
1902*77c1e3ccSAndroid Build Coastguard Worker 
1903*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
1904*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(
1905*77c1e3ccSAndroid Build Coastguard Worker       aom_img_wrap(&img, AOM_IMG_FMT_I44416, kWidth, kHeight, 1, img_data),
1906*77c1e3ccSAndroid Build Coastguard Worker       &img);
1907*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
1908*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
1909*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
1910*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
1911*77c1e3ccSAndroid Build Coastguard Worker 
1912*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
1913*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
1914*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_ALL_INTRA),
1915*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1916*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
1917*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 1;
1918*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_10;
1919*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 10;
1920*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
1921*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
1922*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_limit = 1;
1923*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
1924*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_mode = AOM_KF_DISABLED;
1925*77c1e3ccSAndroid Build Coastguard Worker   cfg.kf_max_dist = 0;
1926*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 21;
1927*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 16;
1928*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 54;
1929*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
1930*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH),
1931*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1932*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 35), AOM_CODEC_OK);
1933*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_ROW_MT, 1), AOM_CODEC_OK);
1934*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 2), AOM_CODEC_OK);
1935*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_TILE_COLUMNS, 5), AOM_CODEC_OK);
1936*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_CPUUSED, 1), AOM_CODEC_OK);
1937*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE),
1938*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1939*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SKIP_POSTPROC_FILTERING, 1),
1940*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1941*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM),
1942*77c1e3ccSAndroid Build Coastguard Worker             AOM_CODEC_OK);
1943*77c1e3ccSAndroid Build Coastguard Worker 
1944*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
1945*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
1946*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
1947*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
1948*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
1949*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
1950*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
1951*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
1952*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1953*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1954*77c1e3ccSAndroid Build Coastguard Worker 
1955*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
1956*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, nullptr, 0, 1, 0), AOM_CODEC_OK);
1957*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
1958*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
1959*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
1960*77c1e3ccSAndroid Build Coastguard Worker 
1961*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
1962*77c1e3ccSAndroid Build Coastguard Worker }
1963*77c1e3ccSAndroid Build Coastguard Worker 
1964*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces b/330639949: signed integer overflow in
1965*77c1e3ccSAndroid Build Coastguard Worker // linsolve_wiener().
1966*77c1e3ccSAndroid Build Coastguard Worker TEST(SearchWienerTest, 12bitSignedIntegerOverflowInLinsolveWiener) {
1967*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kWidth = 173;
1968*77c1e3ccSAndroid Build Coastguard Worker   constexpr int kHeight = 3;
1969*77c1e3ccSAndroid Build Coastguard Worker   // Since the image format is YUV 4:2:0, aom_img_wrap() expects the buffer is
1970*77c1e3ccSAndroid Build Coastguard Worker   // allocated with width and height aligned to a multiple of 2. Align the
1971*77c1e3ccSAndroid Build Coastguard Worker   // width to a multiple of 2 so that the stride set by aom_img_wrap() is
1972*77c1e3ccSAndroid Build Coastguard Worker   // correct. It is not necessary to align the height to a multiple of 2
1973*77c1e3ccSAndroid Build Coastguard Worker   // because aom_codec_encode() will only read cfg.g_h rows.
1974*77c1e3ccSAndroid Build Coastguard Worker   static constexpr uint16_t kBuffer[(kWidth + 1) * kHeight] = {
1975*77c1e3ccSAndroid Build Coastguard Worker     // Y plane:
1976*77c1e3ccSAndroid Build Coastguard Worker     // Row:
1977*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 369, 0, 4095, 873, 4095, 4095, 0, 571, 4023, 0, 1028, 58, 556, 0, 0,
1978*77c1e3ccSAndroid Build Coastguard Worker     1875, 16, 1043, 4095, 0, 1671, 1990, 0, 4095, 2932, 3117, 4095, 0, 0, 0,
1979*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 4095, 4095, 508, 4095, 0, 0, 4095, 4095, 4095, 0,
1980*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 197, 4095, 1475, 1127, 4095, 0, 1570, 1881, 4095, 1215, 4095,
1981*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 1918, 4095, 0, 4095, 3415, 0, 732, 122, 1087, 0, 0, 0, 0, 0, 1012,
1982*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 4095, 0, 0, 4095, 1931, 4095, 0, 4095, 4095, 4095, 4095, 570,
1983*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 2954, 0, 0, 0, 1925, 3802, 0, 4095, 55, 0, 4095, 760, 4095,
1984*77c1e3ccSAndroid Build Coastguard Worker     0, 3313, 4095, 4095, 4095, 0, 218, 799, 4095, 0, 4095, 2455, 4095, 0, 0,
1985*77c1e3ccSAndroid Build Coastguard Worker     611, 4095, 3060, 1669, 0, 0, 4095, 3589, 3903, 0, 3427, 1903, 0, 4095, 3789,
1986*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 107, 2064, 4095, 2764, 4095, 0, 0, 0, 3498, 0, 0, 1336, 4095,
1987*77c1e3ccSAndroid Build Coastguard Worker     4095, 3480, 0, 545, 673, 4095, 0, 4095, 4095, 3175, 4095, 1623, 4095, 0,
1988*77c1e3ccSAndroid Build Coastguard Worker     540, 4095, 4095, 14, 429, 0, 0,
1989*77c1e3ccSAndroid Build Coastguard Worker     // Row:
1990*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 4095, 0, 1703, 3003, 968, 1313, 4095, 613, 4095, 3918, 112, 4095,
1991*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 2211, 88, 4051, 1203, 2005, 4095, 4095, 0, 2106, 0, 4095, 0, 4095,
1992*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 0, 3261, 0, 4095, 0, 1184, 4095, 4095, 818, 4095, 0, 4095, 1292,
1993*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 4095, 0, 4095, 4095, 0, 0, 346, 906, 974, 4095, 4095, 4095,
1994*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 4095, 3225, 2547, 4095, 0, 0, 2705, 2933, 4095, 0, 0, 3579, 0,
1995*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 1872, 4095, 298, 2961, 0, 0, 2805, 0, 0, 1210, 3773, 0,
1996*77c1e3ccSAndroid Build Coastguard Worker     1208, 3347, 0, 4095, 0, 0, 0, 4034, 4095, 0, 0, 4095, 0, 0, 0, 3302, 0, 0,
1997*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 0, 4095, 4095, 0, 2609, 4095, 0, 1831, 4095, 0, 2463, 4095, 4095,
1998*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 752, 4095, 4095, 41, 1829, 2975, 227, 2505, 2719, 1059, 4071,
1999*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 3859, 0, 0, 0, 0, 4095, 2423, 4095, 4095, 4095, 4095, 4095,
2000*77c1e3ccSAndroid Build Coastguard Worker     1466, 0, 0, 4095, 121, 0, 0, 4095, 0, 0, 3328, 4095, 4095, 0, 1172, 0, 2938,
2001*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 0, 0, 4095, 1821, 0,
2002*77c1e3ccSAndroid Build Coastguard Worker     // Row:
2003*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 3487, 4095, 0, 0, 0, 3367, 4095, 4095, 1139, 4095,
2004*77c1e3ccSAndroid Build Coastguard Worker     4095, 169, 1300, 1840, 4095, 3508, 4095, 618, 4095, 4095, 4095, 53, 4095,
2005*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4055, 0, 0, 0, 4095, 4095, 0, 0, 0, 0, 1919, 2415, 1485,
2006*77c1e3ccSAndroid Build Coastguard Worker     458, 4095, 4095, 3176, 4095, 0, 0, 4095, 4095, 617, 3631, 4095, 4095, 0, 0,
2007*77c1e3ccSAndroid Build Coastguard Worker     3983, 4095, 4095, 681, 1685, 4095, 4095, 0, 1783, 25, 4095, 0, 0, 4095,
2008*77c1e3ccSAndroid Build Coastguard Worker     4095, 0, 2075, 0, 4095, 4095, 4095, 0, 773, 3407, 0, 4095, 4095, 0, 0, 4095,
2009*77c1e3ccSAndroid Build Coastguard Worker     4095, 4095, 4095, 4095, 0, 0, 0, 0, 4095, 0, 1804, 0, 0, 3169, 3576, 502, 0,
2010*77c1e3ccSAndroid Build Coastguard Worker     0, 4095, 0, 4095, 0, 4095, 4095, 4095, 0, 4095, 779, 0, 4095, 0, 0, 0, 4095,
2011*77c1e3ccSAndroid Build Coastguard Worker     0, 0, 4095, 4095, 4095, 4095, 0, 0, 4095, 4095, 2134, 4095, 4020, 2990,
2012*77c1e3ccSAndroid Build Coastguard Worker     3949, 4095, 4095, 4095, 4095, 4095, 0, 4095, 4095, 2829, 4095, 4095, 4095,
2013*77c1e3ccSAndroid Build Coastguard Worker     0, 197, 2328, 3745, 0, 3412, 190, 4095, 4095, 4095, 2809, 3953, 0, 4095,
2014*77c1e3ccSAndroid Build Coastguard Worker     1502, 2514, 3866, 0, 0, 4095, 4095, 1878, 129, 4095, 0
2015*77c1e3ccSAndroid Build Coastguard Worker   };
2016*77c1e3ccSAndroid Build Coastguard Worker   unsigned char *img_data =
2017*77c1e3ccSAndroid Build Coastguard Worker       reinterpret_cast<unsigned char *>(const_cast<uint16_t *>(kBuffer));
2018*77c1e3ccSAndroid Build Coastguard Worker 
2019*77c1e3ccSAndroid Build Coastguard Worker   aom_image_t img;
2020*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I42016, kWidth, kHeight, 1,
2021*77c1e3ccSAndroid Build Coastguard Worker                                img_data));
2022*77c1e3ccSAndroid Build Coastguard Worker   img.cp = AOM_CICP_CP_UNSPECIFIED;
2023*77c1e3ccSAndroid Build Coastguard Worker   img.tc = AOM_CICP_TC_UNSPECIFIED;
2024*77c1e3ccSAndroid Build Coastguard Worker   img.mc = AOM_CICP_MC_UNSPECIFIED;
2025*77c1e3ccSAndroid Build Coastguard Worker   img.monochrome = 1;
2026*77c1e3ccSAndroid Build Coastguard Worker   img.csp = AOM_CSP_UNKNOWN;
2027*77c1e3ccSAndroid Build Coastguard Worker   img.range = AOM_CR_FULL_RANGE;
2028*77c1e3ccSAndroid Build Coastguard Worker   img.planes[1] = img.planes[2] = nullptr;
2029*77c1e3ccSAndroid Build Coastguard Worker   img.stride[1] = img.stride[2] = 0;
2030*77c1e3ccSAndroid Build Coastguard Worker 
2031*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *iface = aom_codec_av1_cx();
2032*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg;
2033*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
2034*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_GOOD_QUALITY));
2035*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_end_usage = AOM_Q;
2036*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_profile = 2;
2037*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_bit_depth = AOM_BITS_12;
2038*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_input_bit_depth = 12;
2039*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_w = kWidth;
2040*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_h = kHeight;
2041*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_lag_in_frames = 0;
2042*77c1e3ccSAndroid Build Coastguard Worker   cfg.g_threads = 18;
2043*77c1e3ccSAndroid Build Coastguard Worker   cfg.monochrome = 1;
2044*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_min_quantizer = 0;
2045*77c1e3ccSAndroid Build Coastguard Worker   cfg.rc_max_quantizer = 51;
2046*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t enc;
2047*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
2048*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_enc_init(&enc, iface, &cfg, AOM_CODEC_USE_HIGHBITDEPTH));
2049*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 25));
2050*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AV1E_SET_TILE_ROWS, 4));
2051*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 6));
2052*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
2053*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE));
2054*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK,
2055*77c1e3ccSAndroid Build Coastguard Worker             aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM));
2056*77c1e3ccSAndroid Build Coastguard Worker 
2057*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
2058*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
2059*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter = nullptr;
2060*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter);
2061*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
2062*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
2063*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x1f0011.
2064*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
2065*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2066*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
2067*77c1e3ccSAndroid Build Coastguard Worker 
2068*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
2069*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
2070*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
2071*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2072*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
2073*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
2074*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x20000.
2075*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u);
2076*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2077*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
2078*77c1e3ccSAndroid Build Coastguard Worker 
2079*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
2080*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
2081*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
2082*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2083*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
2084*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
2085*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x20000.
2086*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u);
2087*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2088*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
2089*77c1e3ccSAndroid Build Coastguard Worker 
2090*77c1e3ccSAndroid Build Coastguard Worker   // Encode frame
2091*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(aom_codec_encode(&enc, &img, 0, 1, 0), AOM_CODEC_OK);
2092*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
2093*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2094*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pkt, nullptr);
2095*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT);
2096*77c1e3ccSAndroid Build Coastguard Worker   // pkt->data.frame.flags is 0x20000.
2097*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u);
2098*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2099*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
2100*77c1e3ccSAndroid Build Coastguard Worker 
2101*77c1e3ccSAndroid Build Coastguard Worker   // Flush encoder
2102*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0));
2103*77c1e3ccSAndroid Build Coastguard Worker   iter = nullptr;
2104*77c1e3ccSAndroid Build Coastguard Worker   pkt = aom_codec_get_cx_data(&enc, &iter);
2105*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(pkt, nullptr);
2106*77c1e3ccSAndroid Build Coastguard Worker 
2107*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
2108*77c1e3ccSAndroid Build Coastguard Worker }
2109*77c1e3ccSAndroid Build Coastguard Worker 
2110*77c1e3ccSAndroid Build Coastguard Worker }  // namespace wiener_highbd
2111*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
2112