roi_map_test.cc (5479B)
1 /* 2 * Copyright (c) 2016, 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 <climits> 13 #include <cstring> 14 #include <vector> 15 16 #include "gtest/gtest.h" 17 18 #include "aom/aomcx.h" 19 #include "aom/aom_encoder.h" 20 21 #include "test/codec_factory.h" 22 #include "test/encode_test_driver.h" 23 #include "test/i420_video_source.h" 24 #include "test/util.h" 25 26 namespace { 27 28 enum { kSkip = 0, kDeltaQ = 1, kDeltaLF = 2, kReference = 3 }; 29 30 // Params: test mode, speed, aq_mode and screen_content mode. 31 class ROIMapTest 32 : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int, 33 int, int>, 34 public ::libaom_test::EncoderTest { 35 protected: 36 static const int kWidth = 640; 37 static const int kHeight = 480; 38 39 ROIMapTest() : EncoderTest(GET_PARAM(0)) {} 40 ~ROIMapTest() override = default; 41 42 void SetUp() override { 43 InitializeConfig(GET_PARAM(1)); 44 cpu_used_ = GET_PARAM(2); 45 aq_mode_ = GET_PARAM(3); 46 screen_mode_ = GET_PARAM(4); 47 } 48 49 void PreEncodeFrameHook(::libaom_test::VideoSource *video, 50 ::libaom_test::Encoder *encoder) override { 51 if (video->frame() == 0) { 52 encoder->Control(AOME_SET_CPUUSED, cpu_used_); 53 encoder->Control(AV1E_SET_ALLOW_WARPED_MOTION, 0); 54 encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0); 55 encoder->Control(AV1E_SET_ENABLE_OBMC, 0); 56 encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0); 57 encoder->Control(AV1E_SET_DELTAQ_MODE, 0); 58 encoder->Control(AV1E_SET_DELTALF_MODE, 0); 59 encoder->Control(AV1E_SET_AQ_MODE, aq_mode_ ? 3 : 0); 60 encoder->Control(AV1E_SET_TUNE_CONTENT, screen_mode_); 61 if (screen_mode_) encoder->Control(AV1E_SET_ENABLE_PALETTE, 1); 62 aom_roi_map_t roi = aom_roi_map_t(); 63 const int block_size = 4; 64 roi.rows = (kHeight + block_size - 1) / block_size; 65 roi.cols = (kWidth + block_size - 1) / block_size; 66 memset(&roi.skip, 0, sizeof(roi.skip)); 67 memset(&roi.delta_q, 0, sizeof(roi.delta_q)); 68 memset(&roi.delta_lf, 0, sizeof(roi.delta_lf)); 69 memset(roi.ref_frame, -1, sizeof(roi.ref_frame)); 70 // Set ROI map to be 1 (segment #1) in middle squere of image, 71 // 0 elsewhere. 72 roi.enabled = 1; 73 roi.roi_map = 74 (uint8_t *)calloc(roi.rows * roi.cols, sizeof(*roi.roi_map)); 75 for (unsigned int i = 0; i < roi.rows; ++i) { 76 for (unsigned int j = 0; j < roi.cols; ++j) { 77 const int idx = i * roi.cols + j; 78 if (i > roi.rows / 4 && i < (3 * roi.rows) / 4 && j > roi.cols / 4 && 79 j < (3 * roi.cols) / 4) 80 roi.roi_map[idx] = 1; 81 else 82 roi.roi_map[idx] = 0; 83 } 84 } 85 // Set the ROI feature, on segment #1. 86 if (roi_feature_ == kSkip) 87 roi.skip[1] = 1; 88 else if (roi_feature_ == kDeltaQ) 89 roi.delta_q[1] = -40; 90 else if (roi_feature_ == kReference) 91 roi.ref_frame[1] = 4; // GOLDEN_FRAME; 92 encoder->Control(AOME_SET_ROI_MAP, &roi); 93 free(roi.roi_map); 94 } 95 } 96 97 void ROISkipTest() { 98 cfg_.g_lag_in_frames = 0; 99 cfg_.rc_target_bitrate = 400; 100 cfg_.rc_resize_mode = 0; 101 cfg_.g_pass = AOM_RC_ONE_PASS; 102 cfg_.rc_end_usage = AOM_CBR; 103 cfg_.kf_max_dist = 90000; 104 cfg_.rc_min_quantizer = 0; 105 cfg_.rc_max_quantizer = 52; 106 roi_feature_ = kSkip; 107 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 108 1, 0, 400); 109 110 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 111 } 112 113 void ROIDeltaQTest() { 114 cfg_.g_lag_in_frames = 0; 115 cfg_.rc_target_bitrate = 400; 116 cfg_.rc_resize_mode = 0; 117 cfg_.g_pass = AOM_RC_ONE_PASS; 118 cfg_.rc_end_usage = AOM_CBR; 119 cfg_.kf_max_dist = 90000; 120 cfg_.rc_min_quantizer = 0; 121 cfg_.rc_max_quantizer = 40; 122 roi_feature_ = kDeltaQ; 123 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 124 1, 0, 400); 125 126 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 127 } 128 129 void ROIReferenceTest() { 130 cfg_.g_lag_in_frames = 0; 131 cfg_.rc_target_bitrate = 400; 132 cfg_.rc_resize_mode = 0; 133 cfg_.g_pass = AOM_RC_ONE_PASS; 134 cfg_.rc_end_usage = AOM_CBR; 135 cfg_.kf_max_dist = 90000; 136 cfg_.rc_min_quantizer = 0; 137 cfg_.rc_max_quantizer = 52; 138 roi_feature_ = kReference; 139 ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 140 1, 0, 400); 141 142 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 143 } 144 145 int cpu_used_; 146 int aq_mode_; 147 int screen_mode_; 148 149 private: 150 int roi_feature_; 151 }; 152 153 TEST_P(ROIMapTest, ROISkip) { ROISkipTest(); } 154 155 TEST_P(ROIMapTest, ROIDeltaQ) { ROIDeltaQTest(); } 156 157 TEST_P(ROIMapTest, ROIReference) { ROIReferenceTest(); } 158 159 AV1_INSTANTIATE_TEST_SUITE(ROIMapTest, 160 ::testing::Values(::libaom_test::kRealTime), 161 ::testing::Range(7, 12), ::testing::Values(0, 1), 162 ::testing::Values(0, 1)); 163 164 } // namespace