blob: 94f4be93409106e77e5ed755072969ee4a2178d4 [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>
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
19namespace {
20
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040021const int kTestMode = 0;
22const int kSuperframeSyntax = 1;
Geza Lorecba70d292016-05-03 18:25:01 +010023const int kTileCols = 2;
24const int kTileRows = 3;
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040025
Yaowu Xuc27fc142016-08-22 16:08:15 -070026typedef std::tr1::tuple<libaom_test::TestMode, int, int, int>
clang-format3a826f12016-08-11 17:46:05 -070027 SuperframeTestParam;
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040028
clang-format3a826f12016-08-11 17:46:05 -070029class SuperframeTest
Yaowu Xuc27fc142016-08-22 16:08:15 -070030 : public ::libaom_test::EncoderTest,
31 public ::libaom_test::CodecTestWithParam<SuperframeTestParam> {
John Koleszar522d4bf2013-03-05 12:23:34 -080032 protected:
clang-format3a826f12016-08-11 17:46:05 -070033 SuperframeTest()
34 : EncoderTest(GET_PARAM(0)), modified_buf_(NULL), last_sf_pts_(0) {}
Alex Converse6207a382014-03-12 14:51:42 -070035 virtual ~SuperframeTest() {}
John Koleszar522d4bf2013-03-05 12:23:34 -080036
37 virtual void SetUp() {
38 InitializeConfig();
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040039 const SuperframeTestParam input = GET_PARAM(1);
Yaowu Xuc27fc142016-08-22 16:08:15 -070040 const libaom_test::TestMode mode = std::tr1::get<kTestMode>(input);
Ronald S. Bultjeaa112562015-10-21 10:24:49 -040041 const int syntax = std::tr1::get<kSuperframeSyntax>(input);
42 SetMode(mode);
John Koleszar522d4bf2013-03-05 12:23:34 -080043 sf_count_ = 0;
44 sf_count_max_ = INT_MAX;
Yaowu Xuf883b422016-08-30 14:01:10 -070045 is_av1_style_superframe_ = syntax;
Geza Lorecba70d292016-05-03 18:25:01 +010046 n_tile_cols_ = std::tr1::get<kTileCols>(input);
47 n_tile_rows_ = std::tr1::get<kTileRows>(input);
John Koleszar522d4bf2013-03-05 12:23:34 -080048 }
49
clang-format3a826f12016-08-11 17:46:05 -070050 virtual void TearDown() { delete[] modified_buf_; }
John Koleszar522d4bf2013-03-05 12:23:34 -080051
Yaowu Xuc27fc142016-08-22 16:08:15 -070052 virtual void PreEncodeFrameHook(libaom_test::VideoSource *video,
53 libaom_test::Encoder *encoder) {
John Koleszar522d4bf2013-03-05 12:23:34 -080054 if (video->frame() == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -070055 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 Koleszar522d4bf2013-03-05 12:23:34 -080059 }
60 }
61
Yaowu Xuf883b422016-08-30 14:01:10 -070062 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 Koleszar522d4bf2013-03-05 12:23:34 -080065
clang-format3a826f12016-08-11 17:46:05 -070066 const uint8_t *buffer = reinterpret_cast<uint8_t *>(pkt->data.frame.buf);
John Koleszar522d4bf2013-03-05 12:23:34 -080067 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 Xuf883b422016-08-30 14:01:10 -070070 const unsigned int index_sz = 2 + mag * (frames - is_av1_style_superframe_);
clang-format3a826f12016-08-11 17:46:05 -070071 if ((marker & 0xe0) == 0xc0 && pkt->data.frame.sz >= index_sz &&
John Koleszar522d4bf2013-03-05 12:23:34 -080072 buffer[pkt->data.frame.sz - index_sz] == marker) {
73 // frame is a superframe. strip off the index.
clang-format3a826f12016-08-11 17:46:05 -070074 if (modified_buf_) delete[] modified_buf_;
John Koleszar522d4bf2013-03-05 12:23:34 -080075 modified_buf_ = new uint8_t[pkt->data.frame.sz - index_sz];
clang-format3a826f12016-08-11 17:46:05 -070076 memcpy(modified_buf_, pkt->data.frame.buf, pkt->data.frame.sz - index_sz);
John Koleszar522d4bf2013-03-05 12:23:34 -080077 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-format3a826f12016-08-11 17:46:05 -070087 abort_ |=
88 sf_count_ > sf_count_max_ && pkt->data.frame.pts - last_sf_pts_ >= 5;
John Koleszar522d4bf2013-03-05 12:23:34 -080089 return pkt;
90 }
91
Yaowu Xuf883b422016-08-30 14:01:10 -070092 int is_av1_style_superframe_;
John Koleszar522d4bf2013-03-05 12:23:34 -080093 int sf_count_;
94 int sf_count_max_;
Yaowu Xuf883b422016-08-30 14:01:10 -070095 aom_codec_cx_pkt_t modified_pkt_;
John Koleszar522d4bf2013-03-05 12:23:34 -080096 uint8_t *modified_buf_;
Yaowu Xuf883b422016-08-30 14:01:10 -070097 aom_codec_pts_t last_sf_pts_;
Geza Lorecba70d292016-05-03 18:25:01 +010098
99 private:
100 int n_tile_cols_;
101 int n_tile_rows_;
John Koleszar522d4bf2013-03-05 12:23:34 -0800102};
103
104TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) {
105 sf_count_max_ = 0; // early exit on successful test.
106 cfg_.g_lag_in_frames = 25;
107
Yaowu Xuc27fc142016-08-22 16:08:15 -0700108 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
John Koleszar522d4bf2013-03-05 12:23:34 -0800109 30, 1, 0, 40);
110 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
Zoe Liue7869b72016-07-18 11:28:31 -0700111#if CONFIG_EXT_REFS
Zoe Liu1aa674b2016-06-15 15:39:51 -0700112 // 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 Koleszar522d4bf2013-03-05 12:23:34 -0800116 EXPECT_EQ(sf_count_, 1);
Zoe Liue7869b72016-07-18 11:28:31 -0700117#endif // CONFIG_EXT_REFS
John Koleszar522d4bf2013-03-05 12:23:34 -0800118}
119
Alex Conversec3688e32016-04-12 18:33:07 -0700120// The superframe index is currently mandatory with ANS due to the decoder
121// starting at the end of the buffer.
Geza Lorecba70d292016-05-03 18:25:01 +0100122#if CONFIG_EXT_TILE
123// Single tile does not work with ANS (see comment above).
124#if CONFIG_ANS
125const int tile_col_values[] = { 1, 2 };
126#else
127const int tile_col_values[] = { 1, 2, 32 };
128#endif
129const int tile_row_values[] = { 1, 2, 32 };
Yaowu Xuf883b422016-08-30 14:01:10 -0700130AV1_INSTANTIATE_TEST_CASE(
clang-format3a826f12016-08-11 17:46:05 -0700131 SuperframeTest,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700132 ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood),
clang-format3a826f12016-08-11 17:46:05 -0700133 ::testing::Values(1),
134 ::testing::ValuesIn(tile_col_values),
135 ::testing::ValuesIn(tile_row_values)));
Geza Lorecba70d292016-05-03 18:25:01 +0100136#else
Yaowu Xu15c1aa62016-10-28 17:08:28 -0700137#if !CONFIG_ANS && !CONFIG_DAALA_EC
Yaowu Xuf883b422016-08-30 14:01:10 -0700138AV1_INSTANTIATE_TEST_CASE(
clang-format3a826f12016-08-11 17:46:05 -0700139 SuperframeTest,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700140 ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood),
clang-format3a826f12016-08-11 17:46:05 -0700141 ::testing::Values(1), ::testing::Values(0),
142 ::testing::Values(0)));
Geza Lorecba70d292016-05-03 18:25:01 +0100143#endif // !CONFIG_ANS
144#endif // CONFIG_EXT_TILE
John Koleszar522d4bf2013-03-05 12:23:34 -0800145} // namespace