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/video_source.h"
19 #include "test/util.h"
24 : public ::libaom_test::CodecTestWithParam
<libaom_test::TestMode
>,
25 public ::libaom_test::EncoderTest
{
27 MonochromeTest() : EncoderTest(GET_PARAM(0)), frame0_psnr_y_(0.) {}
29 virtual ~MonochromeTest() {}
31 virtual void SetUp() {
33 SetMode(GET_PARAM(1));
36 virtual void DecompressedFrameHook(const aom_image_t
&img
,
37 aom_codec_pts_t 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
58 bool ComparePlaneToValue(const aom_image_t
&img
, const int plane
,
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;
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,
91 init_flags_
= AOM_CODEC_USE_PSNR
;
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
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
));