Bug 1797755 - Part 5: Use a single initial mark stack size regardless of whether...
[gecko.git] / third_party / aom / test / monochrome_test.cc
blobebccba584234d3c1dc6dca41294e65c30b9a578c
1 /*
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.
12 #include <climits>
13 #include <vector>
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/video_source.h"
19 #include "test/util.h"
21 namespace {
23 class MonochromeTest
24 : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
25 public ::libaom_test::EncoderTest {
26 protected:
27 MonochromeTest() : EncoderTest(GET_PARAM(0)), frame0_psnr_y_(0.) {}
29 virtual ~MonochromeTest() {}
31 virtual void SetUp() {
32 InitializeConfig();
33 SetMode(GET_PARAM(1));
36 virtual void DecompressedFrameHook(const aom_image_t &img,
37 aom_codec_pts_t pts) {
38 (void)pts;
40 // Get value of top-left corner pixel of U plane
41 int chroma_value = img.planes[AOM_PLANE_U][0];
43 bool is_chroma_constant =
44 ComparePlaneToValue(img, AOM_PLANE_U, chroma_value) &&
45 ComparePlaneToValue(img, AOM_PLANE_V, chroma_value);
47 // Chroma planes should be constant
48 EXPECT_TRUE(is_chroma_constant);
50 // Monochrome flag on image should be set
51 EXPECT_EQ(img.monochrome, 1);
53 chroma_value_list_.push_back(chroma_value);
56 // Returns true if all pixels on the plane are equal to value, and returns
57 // false otherwise.
58 bool ComparePlaneToValue(const aom_image_t &img, const int plane,
59 const int value) {
60 const int w = aom_img_plane_width(&img, plane);
61 const int h = aom_img_plane_height(&img, plane);
62 const uint8_t *const buf = img.planes[plane];
63 const int stride = img.stride[plane];
65 for (int r = 0; r < h; ++r) {
66 for (int c = 0; c < w; ++c) {
67 if (buf[r * stride + c] != value) return false;
70 return true;
73 virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
74 // Check that the initial Y PSNR value is 'high enough', and check that
75 // subsequent Y PSNR values are 'close' to this initial value.
76 if (frame0_psnr_y_ == 0.) {
77 frame0_psnr_y_ = pkt->data.psnr.psnr[1];
78 EXPECT_GT(frame0_psnr_y_, 29.);
80 EXPECT_NEAR(pkt->data.psnr.psnr[1], frame0_psnr_y_, 2.5);
83 std::vector<int> chroma_value_list_;
84 double frame0_psnr_y_;
87 TEST_P(MonochromeTest, TestMonochromeEncoding) {
88 ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
89 30, 1, 0, 5);
91 init_flags_ = AOM_CODEC_USE_PSNR;
93 cfg_.g_w = 352;
94 cfg_.g_h = 288;
96 cfg_.rc_buf_initial_sz = 500;
97 cfg_.rc_buf_optimal_sz = 600;
98 cfg_.rc_buf_sz = 1000;
99 cfg_.rc_min_quantizer = 2;
100 cfg_.rc_max_quantizer = 56;
101 cfg_.rc_undershoot_pct = 50;
102 cfg_.rc_overshoot_pct = 50;
103 cfg_.rc_end_usage = AOM_CBR;
104 cfg_.kf_mode = AOM_KF_AUTO;
105 cfg_.g_lag_in_frames = 1;
106 cfg_.kf_min_dist = cfg_.kf_max_dist = 3000;
107 // Enable dropped frames.
108 cfg_.rc_dropframe_thresh = 1;
109 // Disable error_resilience mode.
110 cfg_.g_error_resilient = 0;
111 // Run at low bitrate.
112 cfg_.rc_target_bitrate = 40;
113 // Set monochrome encoding flag
114 cfg_.monochrome = 1;
116 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
118 // Check that the chroma planes are equal across all frames
119 std::vector<int>::const_iterator iter = chroma_value_list_.begin();
120 int initial_chroma_value = *iter;
121 for (; iter != chroma_value_list_.end(); ++iter) {
122 // Check that all decoded frames have the same constant chroma planes.
123 EXPECT_EQ(*iter, initial_chroma_value);
127 AV1_INSTANTIATE_TEST_CASE(MonochromeTest,
128 ::testing::Values(::libaom_test::kTwoPassGood));
130 } // namespace