encoder.Encode(false);
encoder.Encode(false);
}
-
-class EncodeApiGetTplStatsTest
- : public ::libvpx_test::EncoderTest,
- public ::testing::TestWithParam<const libvpx_test::CodecFactory *> {
- public:
- EncodeApiGetTplStatsTest() : EncoderTest(GetParam()), test_io_(false) {}
- ~EncodeApiGetTplStatsTest() override = default;
-
- protected:
- void SetUp() override {
- InitializeConfig();
- SetMode(::libvpx_test::kTwoPassGood);
- }
-
- void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
- ::libvpx_test::Encoder *encoder) override {
- if (video->frame() == 0) {
- encoder->Control(VP9E_SET_TPL, 1);
- }
- }
-
- vpx_codec_err_t AllocateTplList(VpxTplGopStats *data) {
- // Allocate MAX_ARF_GOP_SIZE (50) * sizeof(VpxTplFrameStats) that will be
- // filled by VP9E_GET_TPL_STATS.
- // MAX_ARF_GOP_SIZE is used here because the test doesn't know the size of
- // each GOP before getting TPL stats from the encoder.
- data->size = 50;
- data->frame_stats_list =
- static_cast<VpxTplFrameStats *>(calloc(50, sizeof(VpxTplFrameStats)));
- if (data->frame_stats_list == nullptr) return VPX_CODEC_MEM_ERROR;
- return VPX_CODEC_OK;
- }
-
- void CompareTplGopStats(const VpxTplGopStats &ref_gop_stats,
- const VpxTplGopStats &test_gop_stats) {
- ASSERT_EQ(ref_gop_stats.size, test_gop_stats.size);
- for (int frame = 0; frame < ref_gop_stats.size; frame++) {
- const VpxTplFrameStats &ref_frame_stats =
- ref_gop_stats.frame_stats_list[frame];
- const VpxTplFrameStats &test_frame_stats =
- test_gop_stats.frame_stats_list[frame];
- ASSERT_EQ(ref_frame_stats.num_blocks, test_frame_stats.num_blocks);
- ASSERT_EQ(ref_frame_stats.frame_width, test_frame_stats.frame_width);
- ASSERT_EQ(ref_frame_stats.frame_height, test_frame_stats.frame_height);
- for (int block = 0; block < ref_frame_stats.num_blocks; block++) {
- const VpxTplBlockStats &ref_block_stats =
- ref_frame_stats.block_stats_list[block];
- const VpxTplBlockStats &test_block_stats =
- test_frame_stats.block_stats_list[block];
- ASSERT_EQ(ref_block_stats.inter_cost, test_block_stats.inter_cost);
- ASSERT_EQ(ref_block_stats.intra_cost, test_block_stats.intra_cost);
- ASSERT_EQ(ref_block_stats.mv_c, test_block_stats.mv_c);
- ASSERT_EQ(ref_block_stats.mv_r, test_block_stats.mv_r);
- ASSERT_EQ(ref_block_stats.recrf_dist, test_block_stats.recrf_dist);
- ASSERT_EQ(ref_block_stats.recrf_rate, test_block_stats.recrf_rate);
- ASSERT_EQ(ref_block_stats.ref_frame_index,
- test_block_stats.ref_frame_index);
- }
- }
- }
-
- void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override {
- ::libvpx_test::CxDataIterator iter = encoder->GetCxData();
- while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) {
- switch (pkt->kind) {
- case VPX_CODEC_CX_FRAME_PKT: {
- VpxTplGopStats tpl_stats;
- EXPECT_EQ(AllocateTplList(&tpl_stats), VPX_CODEC_OK);
- encoder->Control(VP9E_GET_TPL_STATS, &tpl_stats);
- bool stats_not_all_zero = false;
- for (int i = 0; i < tpl_stats.size; i++) {
- VpxTplFrameStats *frame_stats_list = tpl_stats.frame_stats_list;
- if (frame_stats_list[i].frame_width != 0) {
- ASSERT_EQ(frame_stats_list[i].frame_width, width_);
- ASSERT_EQ(frame_stats_list[i].frame_height, height_);
- ASSERT_GT(frame_stats_list[i].num_blocks, 0);
- ASSERT_NE(frame_stats_list[i].block_stats_list, nullptr);
- stats_not_all_zero = true;
- }
- }
- ASSERT_TRUE(stats_not_all_zero);
- if (test_io_ && tpl_stats.size > 0) {
- libvpx_test::TempOutFile *temp_out_file =
- new (std::nothrow) libvpx_test::TempOutFile("w+");
- ASSERT_NE(temp_out_file, nullptr);
- ASSERT_NE(temp_out_file->file(), nullptr);
- vpx_write_tpl_gop_stats(temp_out_file->file(), &tpl_stats);
- rewind(temp_out_file->file());
- VpxTplGopStats gop_stats_io;
- ASSERT_EQ(
- vpx_read_tpl_gop_stats(temp_out_file->file(), &gop_stats_io),
- VPX_CODEC_OK);
- CompareTplGopStats(gop_stats_io, tpl_stats);
- vpx_free_tpl_gop_stats(&gop_stats_io);
- delete temp_out_file;
- }
- free(tpl_stats.frame_stats_list);
- break;
- }
- default: break;
- }
- }
- }
-
- int width_;
- int height_;
- bool test_io_;
-};
-
-TEST_P(EncodeApiGetTplStatsTest, GetTplStats) {
- cfg_.g_lag_in_frames = 25;
- width_ = 352;
- height_ = 288;
- ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", width_,
- height_, 30, 1, 0, 50);
- ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
-}
-
-TEST_P(EncodeApiGetTplStatsTest, GetTplStatsIO) {
- cfg_.g_lag_in_frames = 25;
- width_ = 352;
- height_ = 288;
- test_io_ = true;
- ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", width_,
- height_, 30, 1, 0, 50);
- ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
-}
-
-INSTANTIATE_TEST_SUITE_P(
- VP9, EncodeApiGetTplStatsTest,
- ::testing::Values(
- static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)));
#endif // CONFIG_VP9_ENCODER
} // namespace