#include <memory>
#include "aom/aomcx.h"
#include "aom/aom_encoder.h"
#include "config/aom_config.h"
#include "gtest/gtest.h"
namespace {
constexpr unsigned char kBuffer[2 * (256 * 512 + 2 * 128 * 256)] = …;
#if CONFIG_REALTIME_ONLY
const int kUsage = …;
#else
const int kUsage = 0;
#endif
void EncodeSmallWidthMultiThreaded(aom_img_fmt fmt, aom_codec_flags_t flag) { … }
TEST(EncodeSmallWidthHeight, SmallWidthMultiThreaded) { … }
#if CONFIG_AV1_HIGHBITDEPTH
TEST(HighbdEncodeSmallWidthHeight, SmallWidthMultiThreaded) {
EncodeSmallWidthMultiThreaded(AOM_IMG_FMT_I42016, AOM_CODEC_USE_HIGHBITDEPTH);
}
#endif
#if !CONFIG_REALTIME_ONLY
void EncodeSmallWidthMultiThreadedSpeed0(aom_img_fmt fmt,
aom_codec_flags_t flag) {
constexpr int kWidth = 256;
constexpr int kHeight = 512;
aom_image_t img;
EXPECT_EQ(&img, aom_img_wrap(&img, fmt, kWidth, kHeight, 1,
const_cast<unsigned char *>(kBuffer)));
aom_codec_iface_t *iface = aom_codec_av1_cx();
aom_codec_enc_cfg_t cfg;
EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(iface, &cfg, 0));
cfg.g_threads = 2;
cfg.g_w = kWidth;
cfg.g_h = kHeight;
aom_codec_ctx_t enc;
EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, flag));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 0, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
}
TEST(EncodeSmallWidthHeight, SmallWidthMultiThreadedSpeed0) {
EncodeSmallWidthMultiThreadedSpeed0(AOM_IMG_FMT_I420, 0);
}
#if CONFIG_AV1_HIGHBITDEPTH
TEST(HighbdEncodeSmallWidthHeight, SmallWidthMultiThreadedSpeed0) {
EncodeSmallWidthMultiThreadedSpeed0(AOM_IMG_FMT_I42016,
AOM_CODEC_USE_HIGHBITDEPTH);
}
#endif
#endif
void EncodeSmallHeightMultiThreaded(aom_img_fmt fmt, aom_codec_flags_t flag) { … }
TEST(EncodeSmallWidthHeight, SmallHeightMultiThreaded) { … }
#if CONFIG_AV1_HIGHBITDEPTH
TEST(HighbdEncodeSmallWidthHeight, SmallHeightMultiThreaded) {
EncodeSmallHeightMultiThreaded(AOM_IMG_FMT_I42016,
AOM_CODEC_USE_HIGHBITDEPTH);
}
#endif
#if !CONFIG_REALTIME_ONLY
void EncodeSmallHeightMultiThreadedSpeed0(aom_img_fmt fmt,
aom_codec_flags_t flag) {
constexpr int kWidth = 512;
constexpr int kHeight = 128;
aom_image_t img;
EXPECT_EQ(&img, aom_img_wrap(&img, fmt, kWidth, kHeight, 1,
const_cast<unsigned char *>(kBuffer)));
aom_codec_iface_t *iface = aom_codec_av1_cx();
aom_codec_enc_cfg_t cfg;
EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(iface, &cfg, 0));
cfg.g_threads = 2;
cfg.g_w = kWidth;
cfg.g_h = kHeight;
aom_codec_ctx_t enc;
EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, flag));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 0, 0));
EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
}
TEST(EncodeSmallWidthHeight, SmallHeightMultiThreadedSpeed0) {
EncodeSmallHeightMultiThreadedSpeed0(AOM_IMG_FMT_I420, 0);
}
#if CONFIG_AV1_HIGHBITDEPTH
TEST(HighbdEncodeSmallWidthHeight, SmallHeightMultiThreadedSpeed0) {
EncodeSmallHeightMultiThreadedSpeed0(AOM_IMG_FMT_I42016,
AOM_CODEC_USE_HIGHBITDEPTH);
}
#endif
#endif
void Encode1x1(aom_img_fmt fmt, int bitdepth, aom_codec_flags_t flags) { … }
TEST(EncodeSmallWidthHeight, 1x1) { … }
#if CONFIG_AV1_HIGHBITDEPTH
TEST(HighbdEncodeSmallWidthHeight, 1x1) {
Encode1x1(AOM_IMG_FMT_I42016, 12, AOM_CODEC_USE_HIGHBITDEPTH);
}
#endif
}