John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
| 11 | |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 12 | #include <climits> |
| 13 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 14 | #include "test/codec_factory.h" |
| 15 | #include "test/encode_test_driver.h" |
| 16 | #include "test/i420_video_source.h" |
| 17 | #include "test/util.h" |
| 18 | |
| 19 | namespace { |
| 20 | |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 21 | const int kTestMode = 0; |
| 22 | const int kSuperframeSyntax = 1; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 23 | const int kTileCols = 2; |
| 24 | const int kTileRows = 3; |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 25 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | typedef std::tr1::tuple<libaom_test::TestMode, int, int, int> |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 27 | SuperframeTestParam; |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 28 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 29 | class SuperframeTest |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | : public ::libaom_test::EncoderTest, |
| 31 | public ::libaom_test::CodecTestWithParam<SuperframeTestParam> { |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 32 | protected: |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 33 | SuperframeTest() |
| 34 | : EncoderTest(GET_PARAM(0)), modified_buf_(NULL), last_sf_pts_(0) {} |
Alex Converse | 6207a38 | 2014-03-12 14:51:42 -0700 | [diff] [blame] | 35 | virtual ~SuperframeTest() {} |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 36 | |
| 37 | virtual void SetUp() { |
| 38 | InitializeConfig(); |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 39 | const SuperframeTestParam input = GET_PARAM(1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | const libaom_test::TestMode mode = std::tr1::get<kTestMode>(input); |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 41 | const int syntax = std::tr1::get<kSuperframeSyntax>(input); |
| 42 | SetMode(mode); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 43 | sf_count_ = 0; |
| 44 | sf_count_max_ = INT_MAX; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | is_av1_style_superframe_ = syntax; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 46 | n_tile_cols_ = std::tr1::get<kTileCols>(input); |
| 47 | n_tile_rows_ = std::tr1::get<kTileRows>(input); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 48 | } |
| 49 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 50 | virtual void TearDown() { delete[] modified_buf_; } |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 51 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 53 | libaom_test::Encoder *encoder) { |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 54 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 55 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 56 | encoder->Control(AOME_SET_CPUUSED, 2); |
| 57 | encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_); |
| 58 | encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | virtual const aom_codec_cx_pkt_t *MutateEncoderOutputHook( |
| 63 | const aom_codec_cx_pkt_t *pkt) { |
| 64 | if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return pkt; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 65 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 66 | const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 67 | const uint8_t marker = buffer[pkt->data.frame.sz - 1]; |
| 68 | const int frames = (marker & 0x7) + 1; |
| 69 | const int mag = ((marker >> 3) & 3) + 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | const unsigned int index_sz = 2 + mag * (frames - is_av1_style_superframe_); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 71 | if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz && |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 72 | buffer[pkt->data.frame.sz - index_sz] == marker) { |
| 73 | // frame is a superframe. strip off the index. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 74 | if (modified_buf_) delete[] modified_buf_; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 75 | modified_buf_ = new uint8_t[pkt->data.frame.sz - index_sz]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 76 | memcpy(modified_buf_, pkt->data.frame.buf, pkt->data.frame.sz - index_sz); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 77 | modified_pkt_ = *pkt; |
| 78 | modified_pkt_.data.frame.buf = modified_buf_; |
| 79 | modified_pkt_.data.frame.sz -= index_sz; |
| 80 | |
| 81 | sf_count_++; |
| 82 | last_sf_pts_ = pkt->data.frame.pts; |
| 83 | return &modified_pkt_; |
| 84 | } |
| 85 | |
| 86 | // Make sure we do a few frames after the last SF |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 87 | abort_ |= |
| 88 | sf_count_ > sf_count_max_ && pkt->data.frame.pts - last_sf_pts_ >= 5; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 89 | return pkt; |
| 90 | } |
| 91 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | int is_av1_style_superframe_; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 93 | int sf_count_; |
| 94 | int sf_count_max_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | aom_codec_cx_pkt_t modified_pkt_; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 96 | uint8_t *modified_buf_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | aom_codec_pts_t last_sf_pts_; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 98 | |
| 99 | private: |
| 100 | int n_tile_cols_; |
| 101 | int n_tile_rows_; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) { |
| 105 | sf_count_max_ = 0; // early exit on successful test. |
| 106 | cfg_.g_lag_in_frames = 25; |
| 107 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 108 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 109 | 30, 1, 0, 40); |
| 110 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Zoe Liu | e7869b7 | 2016-07-18 11:28:31 -0700 | [diff] [blame] | 111 | #if CONFIG_EXT_REFS |
Zoe Liu | 1aa674b | 2016-06-15 15:39:51 -0700 | [diff] [blame] | 112 | // NOTE: The use of BWDREF_FRAME will enable the coding of more non-show |
| 113 | // frames besides ALTREF_FRAME. |
| 114 | EXPECT_GE(sf_count_, 1); |
| 115 | #else |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 116 | EXPECT_EQ(sf_count_, 1); |
Zoe Liu | e7869b7 | 2016-07-18 11:28:31 -0700 | [diff] [blame] | 117 | #endif // CONFIG_EXT_REFS |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Alex Converse | c3688e3 | 2016-04-12 18:33:07 -0700 | [diff] [blame] | 120 | // The superframe index is currently mandatory with ANS due to the decoder |
| 121 | // starting at the end of the buffer. |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 122 | #if CONFIG_EXT_TILE |
| 123 | // Single tile does not work with ANS (see comment above). |
| 124 | #if CONFIG_ANS |
| 125 | const int tile_col_values[] = { 1, 2 }; |
| 126 | #else |
| 127 | const int tile_col_values[] = { 1, 2, 32 }; |
| 128 | #endif |
| 129 | const int tile_row_values[] = { 1, 2, 32 }; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | AV1_INSTANTIATE_TEST_CASE( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 131 | SuperframeTest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood), |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 133 | ::testing::Values(1), |
| 134 | ::testing::ValuesIn(tile_col_values), |
| 135 | ::testing::ValuesIn(tile_row_values))); |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 136 | #else |
Yaowu Xu | 15c1aa6 | 2016-10-28 17:08:28 -0700 | [diff] [blame] | 137 | #if !CONFIG_ANS && !CONFIG_DAALA_EC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 138 | AV1_INSTANTIATE_TEST_CASE( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 139 | SuperframeTest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood), |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 141 | ::testing::Values(1), ::testing::Values(0), |
| 142 | ::testing::Values(0))); |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 143 | #endif // !CONFIG_ANS |
| 144 | #endif // CONFIG_EXT_TILE |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 145 | } // namespace |