blob: eec1a16971b937a34de10f77e07791da96f6e09f [file] [log] [blame]
John Koleszar522d4bf2013-03-05 12:23:34 -08001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar522d4bf2013-03-05 12:23:34 -08003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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 Koleszar522d4bf2013-03-05 12:23:34 -080012#include <climits>
Sebastien Alaiwan4fe940a2017-06-23 17:42:31 +020013#include <vector>
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
John Koleszar522d4bf2013-03-05 12:23:34 -080015#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
20namespace {
21
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040022const int kTestMode = 0;
Alex Converseed2a00f2016-11-30 16:15:01 -080023const int kTileCols = 1;
24const int kTileRows = 2;
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040025
Alex Converseed2a00f2016-11-30 16:15:01 -080026typedef std::tr1::tuple<libaom_test::TestMode, int, int> SuperframeTestParam;
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040027
clang-format3a826f12016-08-11 17:46:05 -070028class SuperframeTest
Sebastien Alaiwan4322bc12017-06-05 10:18:28 +020029 : public ::libaom_test::CodecTestWithParam<SuperframeTestParam>,
30 public ::libaom_test::EncoderTest {
John Koleszar522d4bf2013-03-05 12:23:34 -080031 protected:
Sebastien Alaiwan4fe940a2017-06-23 17:42:31 +020032 SuperframeTest() : EncoderTest(GET_PARAM(0)), last_sf_pts_(0) {}
Alex Converse6207a382014-03-12 14:51:42 -070033 virtual ~SuperframeTest() {}
John Koleszar522d4bf2013-03-05 12:23:34 -080034
35 virtual void SetUp() {
36 InitializeConfig();
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040037 const SuperframeTestParam input = GET_PARAM(1);
Yaowu Xuc27fc142016-08-22 16:08:15 -070038 const libaom_test::TestMode mode = std::tr1::get<kTestMode>(input);
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040039 SetMode(mode);
John Koleszar522d4bf2013-03-05 12:23:34 -080040 sf_count_ = 0;
41 sf_count_max_ = INT_MAX;
Geza Lorecba70d292016-05-03 18:25:01 +010042 n_tile_cols_ = std::tr1::get<kTileCols>(input);
43 n_tile_rows_ = std::tr1::get<kTileRows>(input);
John Koleszar522d4bf2013-03-05 12:23:34 -080044 }
45
Yaowu Xuc27fc142016-08-22 16:08:15 -070046 virtual void PreEncodeFrameHook(libaom_test::VideoSource *video,
47 libaom_test::Encoder *encoder) {
John Koleszar522d4bf2013-03-05 12:23:34 -080048 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -070049 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 Lei9b02b0e2017-01-30 15:52:20 -080053#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -080054#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 Lei7386eda2016-12-08 21:08:31 -080058 encoder->Control(AV1E_SET_TILE_LOOPFILTER, 0);
Lei7bb501d2017-12-13 15:10:34 -080059#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -080060#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
John Koleszar522d4bf2013-03-05 12:23:34 -080061 }
62 }
63
Yaowu Xuf883b422016-08-30 14:01:10 -070064 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 Koleszar522d4bf2013-03-05 12:23:34 -080067
clang-format3a826f12016-08-11 17:46:05 -070068 const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
Sebastien Alaiwane4c6fc12017-06-21 16:43:22 +020069 const uint8_t marker = buffer[0];
John Koleszar522d4bf2013-03-05 12:23:34 -080070 const int frames = (marker & 0x7) + 1;
71 const int mag = ((marker >> 3) & 3) + 1;
Alex Converseed2a00f2016-11-30 16:15:01 -080072 const unsigned int index_sz = 2 + mag * (frames - 1);
clang-format3a826f12016-08-11 17:46:05 -070073 if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
Sebastien Alaiwane4c6fc12017-06-21 16:43:22 +020074 buffer[index_sz - 1] == marker) {
John Koleszar522d4bf2013-03-05 12:23:34 -080075 // frame is a superframe. strip off the index.
Sebastien Alaiwan4fe940a2017-06-23 17:42:31 +020076 modified_buf_.resize(pkt->data.frame.sz - index_sz);
77 memcpy(&modified_buf_[0], (uint8_t *)pkt->data.frame.buf + index_sz,
Sebastien Alaiwane4c6fc12017-06-21 16:43:22 +020078 pkt->data.frame.sz - index_sz);
John Koleszar522d4bf2013-03-05 12:23:34 -080079 modified_pkt_ = *pkt;
Sebastien Alaiwan4fe940a2017-06-23 17:42:31 +020080 modified_pkt_.data.frame.buf = &modified_buf_[0];
John Koleszar522d4bf2013-03-05 12:23:34 -080081 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-format3a826f12016-08-11 17:46:05 -070089 abort_ |=
90 sf_count_ > sf_count_max_ && pkt->data.frame.pts - last_sf_pts_ >= 5;
John Koleszar522d4bf2013-03-05 12:23:34 -080091 return pkt;
92 }
93
94 int sf_count_;
95 int sf_count_max_;
Yaowu Xuf883b422016-08-30 14:01:10 -070096 aom_codec_cx_pkt_t modified_pkt_;
Sebastien Alaiwan4fe940a2017-06-23 17:42:31 +020097 std::vector<uint8_t> modified_buf_;
Yaowu Xuf883b422016-08-30 14:01:10 -070098 aom_codec_pts_t last_sf_pts_;
Geza Lorecba70d292016-05-03 18:25:01 +010099
100 private:
101 int n_tile_cols_;
102 int n_tile_rows_;
John Koleszar522d4bf2013-03-05 12:23:34 -0800103};
104
105TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) {
106 sf_count_max_ = 0; // early exit on successful test.
107 cfg_.g_lag_in_frames = 25;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700108#if CONFIG_EXT_TILE
109 cfg_.large_scale_tile = 1;
110#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700111 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
John Koleszar522d4bf2013-03-05 12:23:34 -0800112 30, 1, 0, 40);
113 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Zoe Liu1aa674b2016-06-15 15:39:51 -0700114 // 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 Koleszar522d4bf2013-03-05 12:23:34 -0800117}
118
Nathan E. Egged526d0a2016-12-15 12:13:34 -0500119// 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 Lorecba70d292016-05-03 18:25:01 +0100121#if CONFIG_EXT_TILE
122// Single tile does not work with ANS (see comment above).
Geza Lorecba70d292016-05-03 18:25:01 +0100123const int tile_col_values[] = { 1, 2 };
Geza Lorecba70d292016-05-03 18:25:01 +0100124const int tile_row_values[] = { 1, 2, 32 };
Yaowu Xuf883b422016-08-30 14:01:10 -0700125AV1_INSTANTIATE_TEST_CASE(
clang-format3a826f12016-08-11 17:46:05 -0700126 SuperframeTest,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127 ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood),
clang-format3a826f12016-08-11 17:46:05 -0700128 ::testing::ValuesIn(tile_col_values),
129 ::testing::ValuesIn(tile_row_values)));
Geza Lorecba70d292016-05-03 18:25:01 +0100130#endif // CONFIG_EXT_TILE
John Koleszar522d4bf2013-03-05 12:23:34 -0800131} // namespace