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 "gtest/gtest.h"
13*77c1e3ccSAndroid Build Coastguard Worker
14*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/seg_common.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/decoder/decodemv.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/bitstream.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
18*77c1e3ccSAndroid Build Coastguard Worker
19*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom;
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker namespace {
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker struct Segment {
24*77c1e3ccSAndroid Build Coastguard Worker int id;
25*77c1e3ccSAndroid Build Coastguard Worker int pred;
26*77c1e3ccSAndroid Build Coastguard Worker int last_id;
27*77c1e3ccSAndroid Build Coastguard Worker };
28*77c1e3ccSAndroid Build Coastguard Worker
GenerateSegment(int seed)29*77c1e3ccSAndroid Build Coastguard Worker Segment GenerateSegment(int seed) {
30*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd_(seed);
31*77c1e3ccSAndroid Build Coastguard Worker
32*77c1e3ccSAndroid Build Coastguard Worker Segment segment;
33*77c1e3ccSAndroid Build Coastguard Worker const int last_segid = rnd_.PseudoUniform(MAX_SEGMENTS);
34*77c1e3ccSAndroid Build Coastguard Worker segment.last_id = last_segid;
35*77c1e3ccSAndroid Build Coastguard Worker segment.pred = rnd_.PseudoUniform(MAX_SEGMENTS);
36*77c1e3ccSAndroid Build Coastguard Worker segment.id = rnd_.PseudoUniform(last_segid + 1);
37*77c1e3ccSAndroid Build Coastguard Worker
38*77c1e3ccSAndroid Build Coastguard Worker return segment;
39*77c1e3ccSAndroid Build Coastguard Worker }
40*77c1e3ccSAndroid Build Coastguard Worker
41*77c1e3ccSAndroid Build Coastguard Worker // Try to reveal a mismatch between segment binarization and debinarization
TEST(SegmentBinarizationSync,SearchForBinarizationMismatch)42*77c1e3ccSAndroid Build Coastguard Worker TEST(SegmentBinarizationSync, SearchForBinarizationMismatch) {
43*77c1e3ccSAndroid Build Coastguard Worker const int count_tests = 1000;
44*77c1e3ccSAndroid Build Coastguard Worker const int seed_init = 4321;
45*77c1e3ccSAndroid Build Coastguard Worker
46*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < count_tests; ++i) {
47*77c1e3ccSAndroid Build Coastguard Worker const Segment seg = GenerateSegment(seed_init + i);
48*77c1e3ccSAndroid Build Coastguard Worker
49*77c1e3ccSAndroid Build Coastguard Worker const int max_segid = seg.last_id + 1;
50*77c1e3ccSAndroid Build Coastguard Worker const int seg_diff = av1_neg_interleave(seg.id, seg.pred, max_segid);
51*77c1e3ccSAndroid Build Coastguard Worker const int decoded_segid =
52*77c1e3ccSAndroid Build Coastguard Worker av1_neg_deinterleave(seg_diff, seg.pred, max_segid);
53*77c1e3ccSAndroid Build Coastguard Worker
54*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(decoded_segid, seg.id);
55*77c1e3ccSAndroid Build Coastguard Worker }
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker
58*77c1e3ccSAndroid Build Coastguard Worker } // namespace
59