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> |
Sebastien Alaiwan | 4fe940a | 2017-06-23 17:42:31 +0200 | [diff] [blame] | 13 | #include <vector> |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 15 | #include "test/codec_factory.h" |
| 16 | #include "test/encode_test_driver.h" |
| 17 | #include "test/i420_video_source.h" |
| 18 | #include "test/util.h" |
| 19 | |
| 20 | namespace { |
| 21 | |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 22 | const int kTestMode = 0; |
Alex Converse | ed2a00f | 2016-11-30 16:15:01 -0800 | [diff] [blame] | 23 | const int kTileCols = 1; |
| 24 | const int kTileRows = 2; |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 25 | |
Alex Converse | ed2a00f | 2016-11-30 16:15:01 -0800 | [diff] [blame] | 26 | typedef std::tr1::tuple<libaom_test::TestMode, int, int> SuperframeTestParam; |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 27 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 28 | class SuperframeTest |
Sebastien Alaiwan | 4322bc1 | 2017-06-05 10:18:28 +0200 | [diff] [blame] | 29 | : public ::libaom_test::CodecTestWithParam<SuperframeTestParam>, |
| 30 | public ::libaom_test::EncoderTest { |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 31 | protected: |
Sebastien Alaiwan | 4fe940a | 2017-06-23 17:42:31 +0200 | [diff] [blame] | 32 | SuperframeTest() : EncoderTest(GET_PARAM(0)), last_sf_pts_(0) {} |
Alex Converse | 6207a38 | 2014-03-12 14:51:42 -0700 | [diff] [blame] | 33 | virtual ~SuperframeTest() {} |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 34 | |
| 35 | virtual void SetUp() { |
| 36 | InitializeConfig(); |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 37 | const SuperframeTestParam input = GET_PARAM(1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | const libaom_test::TestMode mode = std::tr1::get<kTestMode>(input); |
Ronald S. Bultje | aa11256 | 2015-10-21 10:24:49 -0400 | [diff] [blame] | 39 | SetMode(mode); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 40 | sf_count_ = 0; |
| 41 | sf_count_max_ = INT_MAX; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 42 | n_tile_cols_ = std::tr1::get<kTileCols>(input); |
| 43 | n_tile_rows_ = std::tr1::get<kTileRows>(input); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | virtual void PreEncodeFrameHook(libaom_test::VideoSource *video, |
| 47 | libaom_test::Encoder *encoder) { |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 48 | if (video->frame() == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 50 | encoder->Control(AOME_SET_CPUUSED, 2); |
| 51 | encoder->Control(AV1E_SET_TILE_COLUMNS, n_tile_cols_); |
| 52 | encoder->Control(AV1E_SET_TILE_ROWS, n_tile_rows_); |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 53 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 54 | #if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
| 55 | encoder->Control(AV1E_SET_TILE_LOOPFILTER_V, 0); |
| 56 | encoder->Control(AV1E_SET_TILE_LOOPFILTER_H, 0); |
| 57 | #else |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 58 | encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0); |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 59 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 60 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | virtual const aom_codec_cx_pkt_t *MutateEncoderOutputHook( |
| 65 | const aom_codec_cx_pkt_t *pkt) { |
| 66 | if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return pkt; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 67 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 68 | const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf); |
Sebastien Alaiwan | e4c6fc1 | 2017-06-21 16:43:22 +0200 | [diff] [blame] | 69 | const uint8_t marker = buffer[0]; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 70 | const int frames = (marker & 0x7) + 1; |
| 71 | const int mag = ((marker >> 3) & 3) + 1; |
Alex Converse | ed2a00f | 2016-11-30 16:15:01 -0800 | [diff] [blame] | 72 | const unsigned int index_sz = 2 + mag * (frames - 1); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 73 | if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz && |
Sebastien Alaiwan | e4c6fc1 | 2017-06-21 16:43:22 +0200 | [diff] [blame] | 74 | buffer[index_sz - 1] == marker) { |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 75 | // frame is a superframe. strip off the index. |
Sebastien Alaiwan | 4fe940a | 2017-06-23 17:42:31 +0200 | [diff] [blame] | 76 | modified_buf_.resize(pkt->data.frame.sz - index_sz); |
| 77 | memcpy(&modified_buf_[0], (uint8_t *)pkt->data.frame.buf + index_sz, |
Sebastien Alaiwan | e4c6fc1 | 2017-06-21 16:43:22 +0200 | [diff] [blame] | 78 | pkt->data.frame.sz - index_sz); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 79 | modified_pkt_ = *pkt; |
Sebastien Alaiwan | 4fe940a | 2017-06-23 17:42:31 +0200 | [diff] [blame] | 80 | modified_pkt_.data.frame.buf = &modified_buf_[0]; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 81 | modified_pkt_.data.frame.sz -= index_sz; |
| 82 | |
| 83 | sf_count_++; |
| 84 | last_sf_pts_ = pkt->data.frame.pts; |
| 85 | return &modified_pkt_; |
| 86 | } |
| 87 | |
| 88 | // Make sure we do a few frames after the last SF |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 89 | abort_ |= |
| 90 | 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] | 91 | return pkt; |
| 92 | } |
| 93 | |
| 94 | int sf_count_; |
| 95 | int sf_count_max_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | aom_codec_cx_pkt_t modified_pkt_; |
Sebastien Alaiwan | 4fe940a | 2017-06-23 17:42:31 +0200 | [diff] [blame] | 97 | std::vector<uint8_t> modified_buf_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 98 | aom_codec_pts_t last_sf_pts_; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | int n_tile_cols_; |
| 102 | int n_tile_rows_; |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) { |
| 106 | sf_count_max_ = 0; // early exit on successful test. |
| 107 | cfg_.g_lag_in_frames = 25; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 108 | #if CONFIG_EXT_TILE |
| 109 | cfg_.large_scale_tile = 1; |
| 110 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 111 | ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 112 | 30, 1, 0, 40); |
| 113 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
Zoe Liu | 1aa674b | 2016-06-15 15:39:51 -0700 | [diff] [blame] | 114 | // NOTE: The use of BWDREF_FRAME will enable the coding of more non-show |
| 115 | // frames besides ALTREF_FRAME. |
| 116 | EXPECT_GE(sf_count_, 1); |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Nathan E. Egge | d526d0a | 2016-12-15 12:13:34 -0500 | [diff] [blame] | 119 | // The superframe index is currently mandatory with both ANS and DAALA_EC due |
| 120 | // to the decoder starting at the end of the buffer. |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 121 | #if CONFIG_EXT_TILE |
| 122 | // Single tile does not work with ANS (see comment above). |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 123 | const int tile_col_values[] = { 1, 2 }; |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 124 | const int tile_row_values[] = { 1, 2, 32 }; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | AV1_INSTANTIATE_TEST_CASE( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 126 | SuperframeTest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 127 | ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood), |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 128 | ::testing::ValuesIn(tile_col_values), |
| 129 | ::testing::ValuesIn(tile_row_values))); |
Geza Lore | cba70d29 | 2016-05-03 18:25:01 +0100 | [diff] [blame] | 130 | #endif // CONFIG_EXT_TILE |
John Koleszar | 522d4bf | 2013-03-05 12:23:34 -0800 | [diff] [blame] | 131 | } // namespace |