|
15 | 15 | // encode two frames of increasing sizes. The second aom_codec_encode() should |
16 | 16 | // not crash or have memory errors. |
17 | 17 |
|
| 18 | +#include <algorithm> |
18 | 19 | #include <memory> |
| 20 | +#include <vector> |
19 | 21 |
|
20 | 22 | #include "aom/aomcx.h" |
21 | 23 | #include "aom/aom_encoder.h" |
@@ -89,6 +91,114 @@ TEST(EncodeForcedMaxFrameWidthHeight, GoodQualityLag1TuneSSIM) { |
89 | 91 | RunTest(AOM_USAGE_GOOD_QUALITY, /*lag_in_frames=*/1, "ssim"); |
90 | 92 | } |
91 | 93 |
|
| 94 | +void FillImageGradient(aom_image_t *image, int bit_depth) { |
| 95 | + assert(image->range == AOM_CR_FULL_RANGE); |
| 96 | + for (int plane = 0; plane < 3; plane++) { |
| 97 | + const int plane_width = aom_img_plane_width(image, plane); |
| 98 | + const int plane_height = aom_img_plane_height(image, plane); |
| 99 | + unsigned char *row = image->planes[plane]; |
| 100 | + const int stride = image->stride[plane]; |
| 101 | + for (int y = 0; y < plane_height; ++y) { |
| 102 | + for (int x = 0; x < plane_width; ++x) { |
| 103 | + const int value = (x + y) * ((1 << bit_depth) - 1) / |
| 104 | + std::max(1, plane_width + plane_height - 2); |
| 105 | + assert(value >= 0 && value <= (1 << bit_depth) - 1); |
| 106 | + if (bit_depth > 8) { |
| 107 | + reinterpret_cast<uint16_t *>(row)[x] = static_cast<uint16_t>(value); |
| 108 | + } else { |
| 109 | + row[x] = static_cast<unsigned char>(value); |
| 110 | + } |
| 111 | + } |
| 112 | + row += stride; |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +// A test that reproduces bug aomedia:3348: Assertion |
| 118 | +// `ms_params->ms_buffers.ref->stride == ms_params->search_sites->stride' |
| 119 | +// failed. |
| 120 | +TEST(EncodeForcedMaxFrameWidthHeight, DISABLED_DimensionDecreasing) { |
| 121 | + constexpr int kWidth = 128; |
| 122 | + constexpr int kHeight = 128; |
| 123 | + constexpr size_t kBufferSize = 3 * kWidth * kHeight; |
| 124 | + std::vector<unsigned char> buffer(kBufferSize); |
| 125 | + |
| 126 | + aom_image_t img; |
| 127 | + EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, kWidth, kHeight, 1, |
| 128 | + buffer.data())); |
| 129 | + img.cp = AOM_CICP_CP_UNSPECIFIED; |
| 130 | + img.tc = AOM_CICP_TC_UNSPECIFIED; |
| 131 | + img.mc = AOM_CICP_MC_UNSPECIFIED; |
| 132 | + img.range = AOM_CR_FULL_RANGE; |
| 133 | + FillImageGradient(&img, 8); |
| 134 | + |
| 135 | + aom_codec_iface_t *iface = aom_codec_av1_cx(); |
| 136 | + aom_codec_enc_cfg_t cfg; |
| 137 | + EXPECT_EQ(AOM_CODEC_OK, |
| 138 | + aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_GOOD_QUALITY)); |
| 139 | + cfg.rc_end_usage = AOM_Q; |
| 140 | + cfg.g_profile = 0; |
| 141 | + cfg.g_bit_depth = AOM_BITS_8; |
| 142 | + cfg.g_input_bit_depth = 8; |
| 143 | + cfg.g_w = kWidth; |
| 144 | + cfg.g_h = kHeight; |
| 145 | + cfg.g_forced_max_frame_width = kWidth; |
| 146 | + cfg.g_forced_max_frame_height = kHeight; |
| 147 | + cfg.g_lag_in_frames = 1; |
| 148 | + cfg.rc_min_quantizer = 20; |
| 149 | + cfg.rc_max_quantizer = 40; |
| 150 | + aom_codec_ctx_t enc; |
| 151 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0)); |
| 152 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CQ_LEVEL, 30)); |
| 153 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 6)); |
| 154 | + EXPECT_EQ(AOM_CODEC_OK, |
| 155 | + aom_codec_control(&enc, AV1E_SET_COLOR_RANGE, AOM_CR_FULL_RANGE)); |
| 156 | + EXPECT_EQ(AOM_CODEC_OK, |
| 157 | + aom_codec_control(&enc, AOME_SET_TUNING, AOM_TUNE_SSIM)); |
| 158 | + |
| 159 | + // First frame |
| 160 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0)); |
| 161 | + aom_codec_iter_t iter = nullptr; |
| 162 | + const aom_codec_cx_pkt_t *pkt = aom_codec_get_cx_data(&enc, &iter); |
| 163 | + EXPECT_NE(pkt, nullptr); |
| 164 | + EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT); |
| 165 | + // pkt->data.frame.flags is 0x1f0011. |
| 166 | + EXPECT_NE(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u); |
| 167 | + pkt = aom_codec_get_cx_data(&enc, &iter); |
| 168 | + EXPECT_EQ(pkt, nullptr); |
| 169 | + |
| 170 | + // Second frame |
| 171 | + constexpr int kWidthSmall = 64; |
| 172 | + constexpr int kHeightSmall = 64; |
| 173 | + EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, kWidthSmall, |
| 174 | + kHeightSmall, 1, buffer.data())); |
| 175 | + img.cp = AOM_CICP_CP_UNSPECIFIED; |
| 176 | + img.tc = AOM_CICP_TC_UNSPECIFIED; |
| 177 | + img.mc = AOM_CICP_MC_UNSPECIFIED; |
| 178 | + img.range = AOM_CR_FULL_RANGE; |
| 179 | + FillImageGradient(&img, 8); |
| 180 | + cfg.g_w = kWidthSmall; |
| 181 | + cfg.g_h = kHeightSmall; |
| 182 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg)); |
| 183 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0)); |
| 184 | + iter = nullptr; |
| 185 | + pkt = aom_codec_get_cx_data(&enc, &iter); |
| 186 | + EXPECT_NE(pkt, nullptr); |
| 187 | + EXPECT_EQ(pkt->kind, AOM_CODEC_CX_FRAME_PKT); |
| 188 | + // pkt->data.frame.flags is 0. |
| 189 | + EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, 0u); |
| 190 | + pkt = aom_codec_get_cx_data(&enc, &iter); |
| 191 | + EXPECT_EQ(pkt, nullptr); |
| 192 | + |
| 193 | + // Flush encoder |
| 194 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 1, 0)); |
| 195 | + iter = nullptr; |
| 196 | + pkt = aom_codec_get_cx_data(&enc, &iter); |
| 197 | + EXPECT_EQ(pkt, nullptr); |
| 198 | + |
| 199 | + EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc)); |
| 200 | +} |
| 201 | + |
92 | 202 | #endif // !CONFIG_REALTIME_ONLY |
93 | 203 |
|
94 | 204 | TEST(EncodeForcedMaxFrameWidthHeight, RealtimeLag0TunePSNR) { |
|
0 commit comments