2012-05-23 21:55:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2013-01-18 20:51:12 +01:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
|
|
#include "test/codec_factory.h"
|
2012-05-23 21:55:27 +02:00
|
|
|
#include "test/encode_test_driver.h"
|
2013-02-06 21:44:20 +01:00
|
|
|
#include "test/i420_video_source.h"
|
2012-05-23 21:55:27 +02:00
|
|
|
#include "test/video_source.h"
|
2013-01-18 20:51:12 +01:00
|
|
|
#include "test/util.h"
|
2012-05-23 21:55:27 +02:00
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
// Enable(1) or Disable(0) writing of the compressed bitstream.
|
|
|
|
#define WRITE_COMPRESSED_STREAM 0
|
|
|
|
|
2012-05-23 21:55:27 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
static void mem_put_le16(char *const mem, const unsigned int val) {
|
|
|
|
mem[0] = val;
|
|
|
|
mem[1] = val >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mem_put_le32(char *const mem, const unsigned int val) {
|
|
|
|
mem[0] = val;
|
|
|
|
mem[1] = val >> 8;
|
|
|
|
mem[2] = val >> 16;
|
|
|
|
mem[3] = val >> 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_ivf_file_header(const vpx_codec_enc_cfg_t *const cfg,
|
|
|
|
int frame_cnt, FILE *const outfile) {
|
|
|
|
char header[32];
|
|
|
|
|
|
|
|
header[0] = 'D';
|
|
|
|
header[1] = 'K';
|
|
|
|
header[2] = 'I';
|
|
|
|
header[3] = 'F';
|
|
|
|
mem_put_le16(header + 4, 0); /* version */
|
|
|
|
mem_put_le16(header + 6, 32); /* headersize */
|
|
|
|
mem_put_le32(header + 8, 0x30395056); /* fourcc (vp9) */
|
|
|
|
mem_put_le16(header + 12, cfg->g_w); /* width */
|
|
|
|
mem_put_le16(header + 14, cfg->g_h); /* height */
|
|
|
|
mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */
|
|
|
|
mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */
|
|
|
|
mem_put_le32(header + 24, frame_cnt); /* length */
|
|
|
|
mem_put_le32(header + 28, 0); /* unused */
|
|
|
|
|
|
|
|
(void)fwrite(header, 1, 32, outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_ivf_frame_size(FILE *const outfile, const size_t size) {
|
|
|
|
char header[4];
|
|
|
|
mem_put_le32(header, static_cast<unsigned int>(size));
|
|
|
|
(void)fwrite(header, 1, 4, outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_ivf_frame_header(const vpx_codec_cx_pkt_t *const pkt,
|
|
|
|
FILE *const outfile) {
|
|
|
|
char header[12];
|
|
|
|
vpx_codec_pts_t pts;
|
|
|
|
|
|
|
|
if (pkt->kind != VPX_CODEC_CX_FRAME_PKT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pts = pkt->data.frame.pts;
|
|
|
|
mem_put_le32(header, static_cast<unsigned int>(pkt->data.frame.sz));
|
|
|
|
mem_put_le32(header + 4, pts & 0xFFFFFFFF);
|
|
|
|
mem_put_le32(header + 8, pts >> 32);
|
|
|
|
|
|
|
|
(void)fwrite(header, 1, 12, outfile);
|
|
|
|
}
|
|
|
|
#endif // WRITE_COMPRESSED_STREAM
|
|
|
|
|
2012-05-23 21:55:27 +02:00
|
|
|
const unsigned int kInitialWidth = 320;
|
|
|
|
const unsigned int kInitialHeight = 240;
|
|
|
|
|
2015-09-15 23:17:04 +02:00
|
|
|
struct FrameInfo {
|
|
|
|
FrameInfo(vpx_codec_pts_t _pts, unsigned int _w, unsigned int _h)
|
|
|
|
: pts(_pts), w(_w), h(_h) {}
|
|
|
|
|
|
|
|
vpx_codec_pts_t pts;
|
|
|
|
unsigned int w;
|
|
|
|
unsigned int h;
|
|
|
|
};
|
|
|
|
|
2016-02-10 20:39:04 +01:00
|
|
|
void ScaleForFrameNumber(unsigned int frame,
|
|
|
|
unsigned int initial_w,
|
|
|
|
unsigned int initial_h,
|
|
|
|
unsigned int *w,
|
|
|
|
unsigned int *h,
|
|
|
|
int flag_codec) {
|
|
|
|
if (frame < 10) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 20) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 30) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 40) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 50) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 60) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 70) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 80) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 90) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 100) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 110) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 120) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 130) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 140) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 150) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 160) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 170) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 180) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 190) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 200) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 210) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 220) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 230) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 240) {
|
|
|
|
*w = initial_w * 3 / 4;
|
|
|
|
*h = initial_h * 3 / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 250) {
|
|
|
|
*w = initial_w / 2;
|
|
|
|
*h = initial_h / 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame < 260) {
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Go down very low.
|
|
|
|
if (frame < 270) {
|
|
|
|
*w = initial_w / 4;
|
|
|
|
*h = initial_h / 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (flag_codec == 1) {
|
|
|
|
// Cases that only works for VP9.
|
|
|
|
// For VP9: Swap width and height of original.
|
|
|
|
if (frame < 320) {
|
|
|
|
*w = initial_h;
|
|
|
|
*h = initial_w;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*w = initial_w;
|
|
|
|
*h = initial_h;
|
2012-05-23 21:55:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ResizingVideoSource : public ::libvpx_test::DummyVideoSource {
|
|
|
|
public:
|
|
|
|
ResizingVideoSource() {
|
|
|
|
SetSize(kInitialWidth, kInitialHeight);
|
2016-02-10 20:39:04 +01:00
|
|
|
limit_ = 350;
|
2012-05-23 21:55:27 +02:00
|
|
|
}
|
2016-02-10 20:39:04 +01:00
|
|
|
int flag_codec_;
|
2013-09-12 18:35:04 +02:00
|
|
|
virtual ~ResizingVideoSource() {}
|
|
|
|
|
2012-05-23 21:55:27 +02:00
|
|
|
protected:
|
|
|
|
virtual void Next() {
|
|
|
|
++frame_;
|
2016-02-10 20:39:04 +01:00
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, &width, &height,
|
|
|
|
flag_codec_);
|
|
|
|
SetSize(width, height);
|
2012-05-23 21:55:27 +02:00
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResizeTest : public ::libvpx_test::EncoderTest,
|
2013-01-18 20:51:12 +01:00
|
|
|
public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
|
2012-05-23 21:55:27 +02:00
|
|
|
protected:
|
2013-01-18 20:51:12 +01:00
|
|
|
ResizeTest() : EncoderTest(GET_PARAM(0)) {}
|
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
virtual ~ResizeTest() {}
|
|
|
|
|
2012-05-23 21:55:27 +02:00
|
|
|
virtual void SetUp() {
|
|
|
|
InitializeConfig();
|
2013-01-18 20:51:12 +01:00
|
|
|
SetMode(GET_PARAM(1));
|
2012-05-23 21:55:27 +02:00
|
|
|
}
|
|
|
|
|
2013-02-06 21:44:20 +01:00
|
|
|
virtual void DecompressedFrameHook(const vpx_image_t &img,
|
|
|
|
vpx_codec_pts_t pts) {
|
|
|
|
frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
|
2012-05-23 21:55:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< FrameInfo > frame_info_list_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(ResizeTest, TestExternalResizeWorks) {
|
|
|
|
ResizingVideoSource video;
|
2016-02-10 20:39:04 +01:00
|
|
|
video.flag_codec_ = 0;
|
2015-01-13 01:26:05 +01:00
|
|
|
cfg_.g_lag_in_frames = 0;
|
2012-05-23 21:55:27 +02:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
|
2014-02-01 05:11:55 +01:00
|
|
|
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
|
2012-05-23 21:55:27 +02:00
|
|
|
info != frame_info_list_.end(); ++info) {
|
2014-02-01 05:10:28 +01:00
|
|
|
const unsigned int frame = static_cast<unsigned>(info->pts);
|
2016-02-10 20:39:04 +01:00
|
|
|
unsigned int expected_w;
|
|
|
|
unsigned int expected_h;
|
|
|
|
ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
|
|
|
|
&expected_w, &expected_h, 0);
|
2012-05-23 21:55:27 +02:00
|
|
|
EXPECT_EQ(expected_w, info->w)
|
2015-01-13 01:26:05 +01:00
|
|
|
<< "Frame " << frame << " had unexpected width";
|
2012-05-23 21:55:27 +02:00
|
|
|
EXPECT_EQ(expected_h, info->h)
|
2015-01-13 01:26:05 +01:00
|
|
|
<< "Frame " << frame << " had unexpected height";
|
2012-05-23 21:55:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
const unsigned int kStepDownFrame = 3;
|
|
|
|
const unsigned int kStepUpFrame = 6;
|
|
|
|
|
2013-02-06 21:44:20 +01:00
|
|
|
class ResizeInternalTest : public ResizeTest {
|
|
|
|
protected:
|
2013-09-12 18:35:04 +02:00
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
ResizeInternalTest()
|
|
|
|
: ResizeTest(),
|
|
|
|
frame0_psnr_(0.0),
|
|
|
|
outfile_(NULL),
|
|
|
|
out_frames_(0) {}
|
|
|
|
#else
|
2013-02-21 19:38:27 +01:00
|
|
|
ResizeInternalTest() : ResizeTest(), frame0_psnr_(0.0) {}
|
2013-09-12 18:35:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual ~ResizeInternalTest() {}
|
|
|
|
|
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
outfile_ = fopen("vp90-2-05-resize.ivf", "wb");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void EndPassHook() {
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
if (outfile_) {
|
|
|
|
if (!fseek(outfile_, 0, SEEK_SET))
|
|
|
|
write_ivf_file_header(&cfg_, out_frames_, outfile_);
|
|
|
|
fclose(outfile_);
|
|
|
|
outfile_ = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2013-02-06 21:44:20 +01:00
|
|
|
|
|
|
|
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
|
|
|
|
libvpx_test::Encoder *encoder) {
|
2015-09-21 18:37:46 +02:00
|
|
|
if (change_config_) {
|
|
|
|
int new_q = 60;
|
|
|
|
if (video->frame() == 0) {
|
|
|
|
struct vpx_scaling_mode mode = {VP8E_ONETWO, VP8E_ONETWO};
|
|
|
|
encoder->Control(VP8E_SET_SCALEMODE, &mode);
|
|
|
|
}
|
|
|
|
if (video->frame() == 1) {
|
|
|
|
struct vpx_scaling_mode mode = {VP8E_NORMAL, VP8E_NORMAL};
|
|
|
|
encoder->Control(VP8E_SET_SCALEMODE, &mode);
|
|
|
|
cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = new_q;
|
|
|
|
encoder->Config(&cfg_);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (video->frame() == kStepDownFrame) {
|
|
|
|
struct vpx_scaling_mode mode = {VP8E_FOURFIVE, VP8E_THREEFIVE};
|
|
|
|
encoder->Control(VP8E_SET_SCALEMODE, &mode);
|
|
|
|
}
|
|
|
|
if (video->frame() == kStepUpFrame) {
|
|
|
|
struct vpx_scaling_mode mode = {VP8E_NORMAL, VP8E_NORMAL};
|
|
|
|
encoder->Control(VP8E_SET_SCALEMODE, &mode);
|
|
|
|
}
|
2013-02-21 19:38:27 +01:00
|
|
|
}
|
2013-02-06 21:44:20 +01:00
|
|
|
}
|
2013-02-21 19:38:27 +01:00
|
|
|
|
|
|
|
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
|
|
|
|
if (!frame0_psnr_)
|
|
|
|
frame0_psnr_ = pkt->data.psnr.psnr[0];
|
2014-01-17 21:56:36 +01:00
|
|
|
EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0);
|
2013-02-21 19:38:27 +01:00
|
|
|
}
|
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
#if WRITE_COMPRESSED_STREAM
|
2014-08-22 21:11:42 +02:00
|
|
|
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
|
2013-09-12 18:35:04 +02:00
|
|
|
++out_frames_;
|
|
|
|
|
|
|
|
// Write initial file header if first frame.
|
|
|
|
if (pkt->data.frame.pts == 0)
|
|
|
|
write_ivf_file_header(&cfg_, 0, outfile_);
|
|
|
|
|
|
|
|
// Write frame header and data.
|
|
|
|
write_ivf_frame_header(pkt, outfile_);
|
|
|
|
(void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_);
|
|
|
|
}
|
2014-08-22 21:11:42 +02:00
|
|
|
#endif
|
2013-09-12 18:35:04 +02:00
|
|
|
|
2013-02-21 19:38:27 +01:00
|
|
|
double frame0_psnr_;
|
2015-09-21 18:37:46 +02:00
|
|
|
bool change_config_;
|
2013-09-12 18:35:04 +02:00
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
FILE *outfile_;
|
|
|
|
unsigned int out_frames_;
|
|
|
|
#endif
|
2013-02-06 21:44:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(ResizeInternalTest, TestInternalResizeWorks) {
|
|
|
|
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
2013-02-21 19:38:27 +01:00
|
|
|
30, 1, 0, 10);
|
|
|
|
init_flags_ = VPX_CODEC_USE_PSNR;
|
2015-09-21 18:37:46 +02:00
|
|
|
change_config_ = false;
|
2013-09-10 21:02:37 +02:00
|
|
|
|
2013-09-12 18:35:04 +02:00
|
|
|
// q picked such that initial keyframe on this clip is ~30dB PSNR
|
|
|
|
cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48;
|
|
|
|
|
2013-09-10 21:02:37 +02:00
|
|
|
// If the number of frames being encoded is smaller than g_lag_in_frames
|
|
|
|
// the encoded frame is unavailable using the current API. Comparing
|
|
|
|
// frames to detect mismatch would then not be possible. Set
|
|
|
|
// g_lag_in_frames = 0 to get around this.
|
|
|
|
cfg_.g_lag_in_frames = 0;
|
2013-02-06 21:44:20 +01:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
|
2014-02-01 05:11:55 +01:00
|
|
|
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
|
2013-02-06 21:44:20 +01:00
|
|
|
info != frame_info_list_.end(); ++info) {
|
|
|
|
const vpx_codec_pts_t pts = info->pts;
|
2013-09-12 18:35:04 +02:00
|
|
|
if (pts >= kStepDownFrame && pts < kStepUpFrame) {
|
2013-02-06 21:44:20 +01:00
|
|
|
ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width";
|
|
|
|
ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height";
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width";
|
|
|
|
EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 18:37:46 +02:00
|
|
|
TEST_P(ResizeInternalTest, TestInternalResizeChangeConfig) {
|
|
|
|
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
|
|
|
30, 1, 0, 10);
|
|
|
|
cfg_.g_w = 352;
|
|
|
|
cfg_.g_h = 288;
|
|
|
|
change_config_ = true;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
}
|
|
|
|
|
2015-11-09 23:58:14 +01:00
|
|
|
class ResizeRealtimeTest : public ::libvpx_test::EncoderTest,
|
2015-09-15 23:17:04 +02:00
|
|
|
public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
|
|
|
|
protected:
|
2015-11-09 23:58:14 +01:00
|
|
|
ResizeRealtimeTest() : EncoderTest(GET_PARAM(0)) {}
|
|
|
|
virtual ~ResizeRealtimeTest() {}
|
2015-09-15 23:17:04 +02:00
|
|
|
|
|
|
|
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
|
|
|
|
libvpx_test::Encoder *encoder) {
|
|
|
|
if (video->frame() == 0) {
|
|
|
|
encoder->Control(VP9E_SET_AQ_MODE, 3);
|
|
|
|
encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
|
|
|
|
}
|
2015-09-16 00:47:11 +02:00
|
|
|
|
|
|
|
if (change_bitrate_ && video->frame() == 120) {
|
|
|
|
change_bitrate_ = false;
|
|
|
|
cfg_.rc_target_bitrate = 500;
|
|
|
|
encoder->Config(&cfg_);
|
|
|
|
}
|
2015-09-15 23:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
InitializeConfig();
|
|
|
|
SetMode(GET_PARAM(1));
|
|
|
|
set_cpu_used_ = GET_PARAM(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DecompressedFrameHook(const vpx_image_t &img,
|
|
|
|
vpx_codec_pts_t pts) {
|
|
|
|
frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:58:06 +01:00
|
|
|
virtual void MismatchHook(const vpx_image_t *img1,
|
|
|
|
const vpx_image_t *img2) {
|
|
|
|
double mismatch_psnr = compute_psnr(img1, img2);
|
|
|
|
mismatch_psnr_ += mismatch_psnr;
|
|
|
|
++mismatch_nframes_;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GetMismatchFrames() {
|
|
|
|
return mismatch_nframes_;
|
|
|
|
}
|
|
|
|
|
2015-09-15 23:17:04 +02:00
|
|
|
void DefaultConfig() {
|
|
|
|
cfg_.rc_buf_initial_sz = 500;
|
|
|
|
cfg_.rc_buf_optimal_sz = 600;
|
|
|
|
cfg_.rc_buf_sz = 1000;
|
|
|
|
cfg_.rc_min_quantizer = 2;
|
|
|
|
cfg_.rc_max_quantizer = 56;
|
|
|
|
cfg_.rc_undershoot_pct = 50;
|
|
|
|
cfg_.rc_overshoot_pct = 50;
|
|
|
|
cfg_.rc_end_usage = VPX_CBR;
|
|
|
|
cfg_.kf_mode = VPX_KF_AUTO;
|
|
|
|
cfg_.g_lag_in_frames = 0;
|
|
|
|
cfg_.kf_min_dist = cfg_.kf_max_dist = 3000;
|
|
|
|
// Enable dropped frames.
|
|
|
|
cfg_.rc_dropframe_thresh = 1;
|
|
|
|
// Enable error_resilience mode.
|
|
|
|
cfg_.g_error_resilient = 1;
|
|
|
|
// Enable dynamic resizing.
|
|
|
|
cfg_.rc_resize_allowed = 1;
|
|
|
|
// Run at low bitrate.
|
|
|
|
cfg_.rc_target_bitrate = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< FrameInfo > frame_info_list_;
|
|
|
|
int set_cpu_used_;
|
2015-09-16 00:47:11 +02:00
|
|
|
bool change_bitrate_;
|
2016-03-08 01:58:06 +01:00
|
|
|
double mismatch_psnr_;
|
|
|
|
int mismatch_nframes_;
|
2015-09-15 23:17:04 +02:00
|
|
|
};
|
|
|
|
|
2015-11-09 23:58:14 +01:00
|
|
|
TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) {
|
|
|
|
ResizingVideoSource video;
|
2016-02-10 20:39:04 +01:00
|
|
|
video.flag_codec_ = 1;
|
2015-11-09 23:58:14 +01:00
|
|
|
DefaultConfig();
|
2016-02-11 01:59:09 +01:00
|
|
|
// Disable internal resize for this test.
|
|
|
|
cfg_.rc_resize_allowed = 0;
|
2015-11-09 23:58:14 +01:00
|
|
|
change_bitrate_ = false;
|
2016-03-08 01:58:06 +01:00
|
|
|
mismatch_psnr_ = 0.0;
|
|
|
|
mismatch_nframes_ = 0;
|
2015-11-09 23:58:14 +01:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
|
|
|
|
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
|
|
|
|
info != frame_info_list_.end(); ++info) {
|
|
|
|
const unsigned int frame = static_cast<unsigned>(info->pts);
|
2016-02-10 20:39:04 +01:00
|
|
|
unsigned int expected_w;
|
|
|
|
unsigned int expected_h;
|
|
|
|
ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
|
|
|
|
&expected_w, &expected_h, 1);
|
2015-11-09 23:58:14 +01:00
|
|
|
EXPECT_EQ(expected_w, info->w)
|
|
|
|
<< "Frame " << frame << " had unexpected width";
|
|
|
|
EXPECT_EQ(expected_h, info->h)
|
|
|
|
<< "Frame " << frame << " had unexpected height";
|
2016-03-08 01:58:06 +01:00
|
|
|
EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
|
2015-11-09 23:58:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 23:17:04 +02:00
|
|
|
// Verify the dynamic resizer behavior for real time, 1 pass CBR mode.
|
|
|
|
// Run at low bitrate, with resize_allowed = 1, and verify that we get
|
|
|
|
// one resize down event.
|
2015-11-09 23:58:14 +01:00
|
|
|
TEST_P(ResizeRealtimeTest, TestInternalResizeDown) {
|
2015-09-15 23:17:04 +02:00
|
|
|
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
|
|
|
30, 1, 0, 299);
|
|
|
|
DefaultConfig();
|
2015-11-09 23:58:14 +01:00
|
|
|
cfg_.g_w = 352;
|
|
|
|
cfg_.g_h = 288;
|
2015-09-16 00:47:11 +02:00
|
|
|
change_bitrate_ = false;
|
2016-03-08 01:58:06 +01:00
|
|
|
mismatch_psnr_ = 0.0;
|
|
|
|
mismatch_nframes_ = 0;
|
2015-09-15 23:17:04 +02:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
|
|
|
|
unsigned int last_w = cfg_.g_w;
|
|
|
|
unsigned int last_h = cfg_.g_h;
|
|
|
|
int resize_count = 0;
|
|
|
|
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
|
|
|
|
info != frame_info_list_.end(); ++info) {
|
|
|
|
if (info->w != last_w || info->h != last_h) {
|
|
|
|
// Verify that resize down occurs.
|
|
|
|
ASSERT_LT(info->w, last_w);
|
|
|
|
ASSERT_LT(info->h, last_h);
|
|
|
|
last_w = info->w;
|
|
|
|
last_h = info->h;
|
|
|
|
resize_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that we get 1 resize down event in this test.
|
|
|
|
ASSERT_EQ(1, resize_count) << "Resizing should occur.";
|
2016-03-08 01:58:06 +01:00
|
|
|
EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
|
2015-09-15 23:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-09-16 00:47:11 +02:00
|
|
|
// Verify the dynamic resizer behavior for real time, 1 pass CBR mode.
|
|
|
|
// Start at low target bitrate, raise the bitrate in the middle of the clip,
|
|
|
|
// scaling-up should occur after bitrate changed.
|
2015-11-09 23:58:14 +01:00
|
|
|
TEST_P(ResizeRealtimeTest, TestInternalResizeDownUpChangeBitRate) {
|
2015-09-16 00:47:11 +02:00
|
|
|
::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
|
2015-11-09 23:04:58 +01:00
|
|
|
30, 1, 0, 359);
|
2015-09-16 00:47:11 +02:00
|
|
|
DefaultConfig();
|
2015-11-09 23:58:14 +01:00
|
|
|
cfg_.g_w = 352;
|
|
|
|
cfg_.g_h = 288;
|
2015-09-16 00:47:11 +02:00
|
|
|
change_bitrate_ = true;
|
2016-03-08 01:58:06 +01:00
|
|
|
mismatch_psnr_ = 0.0;
|
|
|
|
mismatch_nframes_ = 0;
|
2015-09-16 00:47:11 +02:00
|
|
|
// Disable dropped frames.
|
|
|
|
cfg_.rc_dropframe_thresh = 0;
|
|
|
|
// Starting bitrate low.
|
2015-11-14 01:02:43 +01:00
|
|
|
cfg_.rc_target_bitrate = 80;
|
2015-09-16 00:47:11 +02:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
|
|
|
|
unsigned int last_w = cfg_.g_w;
|
|
|
|
unsigned int last_h = cfg_.g_h;
|
|
|
|
int resize_count = 0;
|
|
|
|
for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
|
|
|
|
info != frame_info_list_.end(); ++info) {
|
|
|
|
if (info->w != last_w || info->h != last_h) {
|
|
|
|
resize_count++;
|
|
|
|
if (resize_count == 1) {
|
|
|
|
// Verify that resize down occurs.
|
|
|
|
ASSERT_LT(info->w, last_w);
|
|
|
|
ASSERT_LT(info->h, last_h);
|
|
|
|
} else if (resize_count == 2) {
|
|
|
|
// Verify that resize up occurs.
|
|
|
|
ASSERT_GT(info->w, last_w);
|
|
|
|
ASSERT_GT(info->h, last_h);
|
|
|
|
}
|
|
|
|
last_w = info->w;
|
|
|
|
last_h = info->h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 01:02:43 +01:00
|
|
|
// Verify that we get 2 resize events in this test.
|
|
|
|
ASSERT_EQ(resize_count, 2) << "Resizing should occur twice.";
|
2016-03-08 01:58:06 +01:00
|
|
|
EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
|
2015-09-16 00:47:11 +02:00
|
|
|
}
|
|
|
|
|
2015-01-15 22:56:55 +01:00
|
|
|
vpx_img_fmt_t CspForFrameNumber(int frame) {
|
|
|
|
if (frame < 10)
|
|
|
|
return VPX_IMG_FMT_I420;
|
|
|
|
if (frame < 20)
|
|
|
|
return VPX_IMG_FMT_I444;
|
|
|
|
return VPX_IMG_FMT_I420;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ResizeCspTest : public ResizeTest {
|
|
|
|
protected:
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
ResizeCspTest()
|
|
|
|
: ResizeTest(),
|
|
|
|
frame0_psnr_(0.0),
|
|
|
|
outfile_(NULL),
|
|
|
|
out_frames_(0) {}
|
|
|
|
#else
|
|
|
|
ResizeCspTest() : ResizeTest(), frame0_psnr_(0.0) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual ~ResizeCspTest() {}
|
|
|
|
|
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
outfile_ = fopen("vp91-2-05-cspchape.ivf", "wb");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void EndPassHook() {
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
if (outfile_) {
|
|
|
|
if (!fseek(outfile_, 0, SEEK_SET))
|
|
|
|
write_ivf_file_header(&cfg_, out_frames_, outfile_);
|
|
|
|
fclose(outfile_);
|
|
|
|
outfile_ = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
|
|
|
|
libvpx_test::Encoder *encoder) {
|
|
|
|
if (CspForFrameNumber(video->frame()) != VPX_IMG_FMT_I420 &&
|
|
|
|
cfg_.g_profile != 1) {
|
|
|
|
cfg_.g_profile = 1;
|
|
|
|
encoder->Config(&cfg_);
|
|
|
|
}
|
|
|
|
if (CspForFrameNumber(video->frame()) == VPX_IMG_FMT_I420 &&
|
|
|
|
cfg_.g_profile != 0) {
|
|
|
|
cfg_.g_profile = 0;
|
|
|
|
encoder->Config(&cfg_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
|
|
|
|
if (!frame0_psnr_)
|
|
|
|
frame0_psnr_ = pkt->data.psnr.psnr[0];
|
|
|
|
EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
|
|
|
|
++out_frames_;
|
|
|
|
|
|
|
|
// Write initial file header if first frame.
|
|
|
|
if (pkt->data.frame.pts == 0)
|
|
|
|
write_ivf_file_header(&cfg_, 0, outfile_);
|
|
|
|
|
|
|
|
// Write frame header and data.
|
|
|
|
write_ivf_frame_header(pkt, outfile_);
|
|
|
|
(void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
double frame0_psnr_;
|
|
|
|
#if WRITE_COMPRESSED_STREAM
|
|
|
|
FILE *outfile_;
|
|
|
|
unsigned int out_frames_;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResizingCspVideoSource : public ::libvpx_test::DummyVideoSource {
|
|
|
|
public:
|
|
|
|
ResizingCspVideoSource() {
|
|
|
|
SetSize(kInitialWidth, kInitialHeight);
|
|
|
|
limit_ = 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ResizingCspVideoSource() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Next() {
|
|
|
|
++frame_;
|
|
|
|
SetImageFormat(CspForFrameNumber(frame_));
|
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(ResizeCspTest, TestResizeCspWorks) {
|
|
|
|
ResizingCspVideoSource video;
|
2015-02-27 05:31:59 +01:00
|
|
|
init_flags_ = VPX_CODEC_USE_PSNR;
|
2015-01-15 22:56:55 +01:00
|
|
|
cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48;
|
|
|
|
cfg_.g_lag_in_frames = 0;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
}
|
|
|
|
|
2013-01-18 20:51:12 +01:00
|
|
|
VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES);
|
2015-01-13 01:26:05 +01:00
|
|
|
VP9_INSTANTIATE_TEST_CASE(ResizeTest,
|
|
|
|
::testing::Values(::libvpx_test::kRealTime));
|
2013-02-06 21:44:20 +01:00
|
|
|
VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest,
|
|
|
|
::testing::Values(::libvpx_test::kOnePassBest));
|
2015-11-09 23:58:14 +01:00
|
|
|
VP9_INSTANTIATE_TEST_CASE(ResizeRealtimeTest,
|
2015-09-15 23:17:04 +02:00
|
|
|
::testing::Values(::libvpx_test::kRealTime),
|
|
|
|
::testing::Range(5, 9));
|
2015-01-15 22:56:55 +01:00
|
|
|
VP9_INSTANTIATE_TEST_CASE(ResizeCspTest,
|
|
|
|
::testing::Values(::libvpx_test::kRealTime));
|
2012-05-23 21:55:27 +02:00
|
|
|
} // namespace
|