xref: /aosp_15_r20/external/libaom/test/still_picture_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2020, Alliance for Open Media. All rights reserved.
3  *
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 
12 #include "gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/i420_video_source.h"
16 #include "test/util.h"
17 
18 namespace {
19 
20 // This class is used to test the presence of still picture feature.
21 class StillPicturePresenceTest
22     : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
23       public ::libaom_test::EncoderTest {
24  protected:
StillPicturePresenceTest()25   StillPicturePresenceTest()
26       : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
27         enable_full_header_(GET_PARAM(2)) {
28     still_picture_coding_violated_ = false;
29   }
30   ~StillPicturePresenceTest() override = default;
31 
SetUp()32   void SetUp() override {
33     InitializeConfig(encoding_mode_);
34     const aom_rational timebase = { 1, 30 };
35     cfg_.g_timebase = timebase;
36     cfg_.rc_end_usage = AOM_Q;
37     cfg_.g_threads = 1;
38     cfg_.full_still_picture_hdr = enable_full_header_;
39     cfg_.g_limit = 1;
40   }
41 
DoDecode() const42   bool DoDecode() const override { return true; }
43 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)44   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
45                           ::libaom_test::Encoder *encoder) override {
46     if (video->frame() == 0) {
47       encoder->Control(AOME_SET_CPUUSED, 5);
48       encoder->Control(AV1E_SET_FORCE_VIDEO_MODE, 0);
49     }
50   }
51 
HandleDecodeResult(const aom_codec_err_t res_dec,libaom_test::Decoder * decoder)52   bool HandleDecodeResult(const aom_codec_err_t res_dec,
53                           libaom_test::Decoder *decoder) override {
54     EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
55     if (AOM_CODEC_OK == res_dec) {
56       aom_codec_ctx_t *ctx_dec = decoder->GetDecoder();
57       AOM_CODEC_CONTROL_TYPECHECKED(ctx_dec, AOMD_GET_STILL_PICTURE,
58                                     &still_pic_info_);
59       if (still_pic_info_.is_still_picture != 1) {
60         still_picture_coding_violated_ = true;
61       }
62       if (still_pic_info_.is_reduced_still_picture_hdr == enable_full_header_) {
63         /* If full_still_picture_header is enabled in encoder config but
64          * bitstream contains reduced_still_picture_header set, then set
65          * still_picture_coding_violated_ to true.
66          * Similarly, if full_still_picture_header is disabled in encoder config
67          * but bitstream contains reduced_still_picture_header not set, then set
68          * still_picture_coding_violated_ to true.
69          */
70         still_picture_coding_violated_ = true;
71       }
72     }
73     return AOM_CODEC_OK == res_dec;
74   }
75 
76   ::libaom_test::TestMode encoding_mode_;
77   bool still_picture_coding_violated_;
78   int enable_full_header_;
79   aom_still_picture_info still_pic_info_;
80   aom_rc_mode end_usage_check_;
81 };
82 
TEST_P(StillPicturePresenceTest,StillPictureEncodePresenceTest)83 TEST_P(StillPicturePresenceTest, StillPictureEncodePresenceTest) {
84   libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
85                                      cfg_.g_timebase.den, cfg_.g_timebase.num,
86                                      0, 1);
87   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
88   ASSERT_EQ(still_picture_coding_violated_, false);
89 }
90 
91 AV1_INSTANTIATE_TEST_SUITE(StillPicturePresenceTest,
92                            ::testing::Values(::libaom_test::kOnePassGood,
93                                              ::libaom_test::kTwoPassGood),
94                            ::testing::Values(1, 0));
95 }  // namespace
96