2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
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"
22 const int kTestMode
= 0;
23 const int kTileCols
= 1;
24 const int kTileRows
= 2;
26 typedef std::tr1::tuple
<libaom_test::TestMode
, int, int> SuperframeTestParam
;
29 : public ::libaom_test::CodecTestWithParam
<SuperframeTestParam
>,
30 public ::libaom_test::EncoderTest
{
32 SuperframeTest() : EncoderTest(GET_PARAM(0)), last_sf_pts_(0) {}
33 virtual ~SuperframeTest() {}
35 virtual void SetUp() {
37 const SuperframeTestParam input
= GET_PARAM(1);
38 const libaom_test::TestMode mode
= std::tr1::get
<kTestMode
>(input
);
41 sf_count_max_
= INT_MAX
;
42 n_tile_cols_
= std::tr1::get
<kTileCols
>(input
);
43 n_tile_rows_
= std::tr1::get
<kTileRows
>(input
);
46 virtual void PreEncodeFrameHook(libaom_test::VideoSource
*video
,
47 libaom_test::Encoder
*encoder
) {
48 if (video
->frame() == 1) {
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_
);
53 #if CONFIG_LOOPFILTERING_ACROSS_TILES
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);
58 encoder
->Control(AV1E_SET_TILE_LOOPFILTER
, 0);
59 #endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
60 #endif // CONFIG_LOOPFILTERING_ACROSS_TILES
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
;
68 const uint8_t *buffer
= reinterpret_cast<uint8_t *>(pkt
->data
.frame
.buf
);
69 const uint8_t marker
= buffer
[0];
70 const int frames
= (marker
& 0x7) + 1;
71 const int mag
= ((marker
>> 3) & 3) + 1;
72 const unsigned int index_sz
= 2 + mag
* (frames
- 1);
73 if ((marker
& 0xe0) == 0xc0 && pkt
->data
.frame
.sz
>= index_sz
&&
74 buffer
[index_sz
- 1] == marker
) {
75 // frame is a superframe. strip off the index.
76 modified_buf_
.resize(pkt
->data
.frame
.sz
- index_sz
);
77 memcpy(&modified_buf_
[0], (uint8_t *)pkt
->data
.frame
.buf
+ index_sz
,
78 pkt
->data
.frame
.sz
- index_sz
);
80 modified_pkt_
.data
.frame
.buf
= &modified_buf_
[0];
81 modified_pkt_
.data
.frame
.sz
-= index_sz
;
84 last_sf_pts_
= pkt
->data
.frame
.pts
;
85 return &modified_pkt_
;
88 // Make sure we do a few frames after the last SF
90 sf_count_
> sf_count_max_
&& pkt
->data
.frame
.pts
- last_sf_pts_
>= 5;
96 aom_codec_cx_pkt_t modified_pkt_
;
97 std::vector
<uint8_t> modified_buf_
;
98 aom_codec_pts_t last_sf_pts_
;
105 TEST_P(SuperframeTest
, TestSuperframeIndexIsOptional
) {
106 sf_count_max_
= 0; // early exit on successful test.
107 cfg_
.g_lag_in_frames
= 25;
109 cfg_
.large_scale_tile
= 1;
110 #endif // CONFIG_EXT_TILE
111 ::libaom_test::I420VideoSource
video("hantro_collage_w352h288.yuv", 352, 288,
113 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
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);
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.
122 // Single tile does not work with ANS (see comment above).
123 const int tile_col_values
[] = { 1, 2 };
124 const int tile_row_values
[] = { 1, 2, 32 };
125 AV1_INSTANTIATE_TEST_CASE(
127 ::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood
),
128 ::testing::ValuesIn(tile_col_values
),
129 ::testing::ValuesIn(tile_row_values
)));
130 #endif // CONFIG_EXT_TILE