OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <math.h> |
| 12 #include <stdlib.h> |
| 13 #include <string.h> |
| 14 |
| 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 16 |
| 17 extern "C" { |
| 18 #include "vp9/encoder/vp9_boolhuff.h" |
| 19 #include "vp9/decoder/vp9_dboolhuff.h" |
| 20 } |
| 21 |
| 22 #include "acm_random.h" |
| 23 #include "vpx/vpx_integer.h" |
| 24 |
| 25 using libvpx_test::ACMRandom; |
| 26 |
| 27 namespace { |
| 28 const int num_tests = 10; |
| 29 } // namespace |
| 30 |
| 31 TEST(VP9, TestBitIO) { |
| 32 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 33 for (int n = 0; n < num_tests; ++n) { |
| 34 for (int method = 0; method <= 7; ++method) { // we generate various proba |
| 35 const int bits_to_test = 1000; |
| 36 uint8_t probas[bits_to_test]; |
| 37 |
| 38 for (int i = 0; i < bits_to_test; ++i) { |
| 39 const int parity = i & 1; |
| 40 probas[i] = |
| 41 (method == 0) ? 0 : (method == 1) ? 255 : |
| 42 (method == 2) ? 128 : |
| 43 (method == 3) ? rnd.Rand8() : |
| 44 (method == 4) ? (parity ? 0 : 255) : |
| 45 // alternate between low and high proba: |
| 46 (method == 5) ? (parity ? rnd(128) : 255 - rnd(128)) : |
| 47 (method == 6) ? |
| 48 (parity ? rnd(64) : 255 - rnd(64)) : |
| 49 (parity ? rnd(32) : 255 - rnd(32)); |
| 50 } |
| 51 for (int bit_method = 0; bit_method <= 3; ++bit_method) { |
| 52 const int random_seed = 6432; |
| 53 const int buffer_size = 10000; |
| 54 ACMRandom bit_rnd(random_seed); |
| 55 BOOL_CODER bw; |
| 56 uint8_t bw_buffer[buffer_size]; |
| 57 vp9_start_encode(&bw, bw_buffer); |
| 58 |
| 59 int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0; |
| 60 for (int i = 0; i < bits_to_test; ++i) { |
| 61 if (bit_method == 2) { |
| 62 bit = (i & 1); |
| 63 } else if (bit_method == 3) { |
| 64 bit = bit_rnd(2); |
| 65 } |
| 66 encode_bool(&bw, bit, static_cast<int>(probas[i])); |
| 67 } |
| 68 |
| 69 vp9_stop_encode(&bw); |
| 70 |
| 71 BOOL_DECODER br; |
| 72 vp9_start_decode(&br, bw_buffer, buffer_size); |
| 73 bit_rnd.Reset(random_seed); |
| 74 for (int i = 0; i < bits_to_test; ++i) { |
| 75 if (bit_method == 2) { |
| 76 bit = (i & 1); |
| 77 } else if (bit_method == 3) { |
| 78 bit = bit_rnd(2); |
| 79 } |
| 80 GTEST_ASSERT_EQ(decode_bool(&br, probas[i]), bit) |
| 81 << "pos: " << i << " / " << bits_to_test |
| 82 << " bit_method: " << bit_method |
| 83 << " method: " << method; |
| 84 } |
| 85 } |
| 86 } |
| 87 } |
| 88 } |
OLD | NEW |