Commit ae4b5eec authored by wez's avatar wez Committed by Commit bot

Add tests for resizing VPX larger than initial size.

libvpx/VP8 currently allows resizing upward but will crash on codec
teardown in that case; these tests ensure we don't regress when we
remove the workarounds in VideoEncoderVpx.

BUG=134202

Review URL: https://codereview.chromium.org/866533004

Cr-Commit-Position: refs/heads/master@{#313741}
parent 0da3bc0e
...@@ -20,7 +20,8 @@ const uint32 kBlueColor = 0x0000ff; ...@@ -20,7 +20,8 @@ const uint32 kBlueColor = 0x0000ff;
const uint32 kGreenColor = 0x00ff00; const uint32 kGreenColor = 0x00ff00;
// Creates a frame stippled between blue and red pixels, which is useful for // Creates a frame stippled between blue and red pixels, which is useful for
// lossy/lossless encode and color tests. // lossy/lossless encode and color tests. By default all pixels in the frame
// are included in the updated_region().
static scoped_ptr<webrtc::DesktopFrame> CreateTestFrame( static scoped_ptr<webrtc::DesktopFrame> CreateTestFrame(
const webrtc::DesktopSize& frame_size) { const webrtc::DesktopSize& frame_size) {
scoped_ptr<webrtc::DesktopFrame> frame( scoped_ptr<webrtc::DesktopFrame> frame(
...@@ -33,6 +34,8 @@ static scoped_ptr<webrtc::DesktopFrame> CreateTestFrame( ...@@ -33,6 +34,8 @@ static scoped_ptr<webrtc::DesktopFrame> CreateTestFrame(
((x + y) & 1) ? kGreenColor : kBlueColor; ((x + y) & 1) ? kGreenColor : kBlueColor;
} }
} }
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
return frame.Pass(); return frame.Pass();
} }
...@@ -53,8 +56,6 @@ TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyEncode) { ...@@ -53,8 +56,6 @@ TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyEncode) {
webrtc::DesktopSize frame_size(1024, 768); webrtc::DesktopSize frame_size(1024, 768);
scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
// Lossy encode the first frame. // Lossy encode the first frame.
encoder->SetLosslessEncode(false); encoder->SetLosslessEncode(false);
...@@ -81,8 +82,6 @@ TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyColor) { ...@@ -81,8 +82,6 @@ TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyColor) {
webrtc::DesktopSize frame_size(1024, 768); webrtc::DesktopSize frame_size(1024, 768);
scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
// Lossy encode the first frame. // Lossy encode the first frame.
encoder->SetLosslessColor(false); encoder->SetLosslessColor(false);
...@@ -103,8 +102,6 @@ TEST(VideoEncoderVpxTest, TestVp8VideoEncoderIgnoreLossy) { ...@@ -103,8 +102,6 @@ TEST(VideoEncoderVpxTest, TestVp8VideoEncoderIgnoreLossy) {
webrtc::DesktopSize frame_size(1024, 768); webrtc::DesktopSize frame_size(1024, 768);
scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
// Encode a frame, to give the encoder a chance to crash if misconfigured. // Encode a frame, to give the encoder a chance to crash if misconfigured.
encoder->SetLosslessEncode(true); encoder->SetLosslessEncode(true);
...@@ -113,25 +110,40 @@ TEST(VideoEncoderVpxTest, TestVp8VideoEncoderIgnoreLossy) { ...@@ -113,25 +110,40 @@ TEST(VideoEncoderVpxTest, TestVp8VideoEncoderIgnoreLossy) {
EXPECT_TRUE(packet); EXPECT_TRUE(packet);
} }
// Test that calling Encode with a differently-sized media::ScreenCaptureData // Test that calling Encode with a larger frame size than the initial one
// does not leak memory. // does not cause VP8 to crash.
TEST(VideoEncoderVpxTest, TestSizeChangeNoLeak) { TEST(VideoEncoderVpxTest, TestVp8SizeChangeNoCrash) {
webrtc::DesktopSize frame_size(1000, 1000); webrtc::DesktopSize frame_size(1000, 1000);
scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
// Create first frame & encode it. // Create first frame & encode it.
scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
EXPECT_TRUE(packet); EXPECT_TRUE(packet);
// Halve the size of the frame, and updated region, and encode again. // Double the size of the frame, and updated region, and encode again.
frame_size.set(frame_size.width(), frame_size.height() / 2); frame_size.set(frame_size.width() * 2, frame_size.height() * 2);
frame = CreateTestFrame(frame_size);
packet = encoder->Encode(*frame);
EXPECT_TRUE(packet);
}
// Test that calling Encode with a larger frame size than the initial one
// does not cause VP9 to crash.
TEST(VideoEncoderVpxTest, TestVp9SizeChangeNoCrash) {
webrtc::DesktopSize frame_size(1000, 1000);
scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9());
// Create first frame & encode it.
scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
EXPECT_TRUE(packet);
// Double the size of the frame, and updated region, and encode again.
frame_size.set(frame_size.width() * 2, frame_size.height() * 2);
frame = CreateTestFrame(frame_size); frame = CreateTestFrame(frame_size);
frame->mutable_updated_region()->SetRect(
webrtc::DesktopRect::MakeSize(frame_size));
packet = encoder->Encode(*frame); packet = encoder->Encode(*frame);
EXPECT_TRUE(packet); EXPECT_TRUE(packet);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment