| Index: webrtc/media/engine/webrtcvideoframefactory_unittest.cc
|
| diff --git a/webrtc/media/engine/webrtcvideoframefactory_unittest.cc b/webrtc/media/engine/webrtcvideoframefactory_unittest.cc
|
| index 197784b54a3af467f321f792784b8254b38cb4b5..b1fd597660f83bfc8dd45ec930920ebae7e3c528 100644
|
| --- a/webrtc/media/engine/webrtcvideoframefactory_unittest.cc
|
| +++ b/webrtc/media/engine/webrtcvideoframefactory_unittest.cc
|
| @@ -37,8 +37,24 @@ class WebRtcVideoFrameFactoryTest : public testing::Test {
|
| (frame_width * frame_height) +
|
| ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2;
|
| captured_frame_buffer_.reset(new uint8_t[captured_frame_.data_size]);
|
| - // Initialize memory to satisfy DrMemory tests.
|
| - memset(captured_frame_buffer_.get(), 0, captured_frame_.data_size);
|
| +
|
| + // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
|
| + for (int x = 0; x < frame_width; x++)
|
| + for (int y = 0; y < frame_height; y++) {
|
| + captured_frame_buffer_[x + y * frame_width] =
|
| + 128 * (x * frame_height + y * frame_width) /
|
| + (frame_width * frame_height);
|
| + }
|
| + int chroma_width = (frame_width + 1) / 2;
|
| + int chroma_height = (frame_height + 1) / 2;
|
| + for (int x = 0; x < chroma_width; x++)
|
| + for (int y = 0; y < chroma_height; y++) {
|
| + captured_frame_buffer_[frame_width * frame_height +
|
| + x + y*chroma_width] = 256 * x / chroma_width;
|
| + captured_frame_buffer_[frame_width * frame_height +
|
| + chroma_width * chroma_height +
|
| + x + y*chroma_width] = 256 * y / chroma_height;
|
| + }
|
| captured_frame_.data = captured_frame_buffer_.get();
|
| }
|
|
|
| @@ -63,6 +79,43 @@ class WebRtcVideoFrameFactoryTest : public testing::Test {
|
| }
|
| }
|
| }
|
| + void VerifyCrop(webrtc::VideoFrameBuffer* frame,
|
| + webrtc::VideoRotation src_rotation,
|
| + double rel_width,
|
| + double rel_height,
|
| + bool apply_rotation) {
|
| + // Corners, in counter-clockwise order. E.g, 90 degree rotation
|
| + // maps (0,0) onto (1,0).
|
| + struct {
|
| + int x;
|
| + int y;
|
| + } corners[4] = {
|
| + {0, 0}, {1, 0}, {1, 1}, {0, 1},
|
| + };
|
| +
|
| + int rotation = apply_rotation ? src_rotation / 90 : 0;
|
| +
|
| + int width = frame->width();
|
| + int height = frame->height();
|
| + // Check that pixel values in the corners match the gradient used
|
| + // for initialization.
|
| + for (int i = 0; i < 4; i++) {
|
| + // Pixel coordinates of corner 0, after rotation.
|
| + int x = corners[(i + rotation) % 4].x * (width - 1);
|
| + int y = corners[(i + rotation) % 4].y * (height - 1);
|
| + // Pre-rotation coordinates, range 0.0 - 1.0 correspond to the
|
| + // size of the uncropped input frame.
|
| + double orig_x = (1 - rel_width) / 2 + corners[i].x * rel_width;
|
| + double orig_y = (1 - rel_height) / 2 + corners[i].y * rel_height;
|
| +
|
| + EXPECT_NEAR(frame->DataY()[x + y * frame->StrideY()] / 256.0,
|
| + (orig_x + orig_y) / 2, 0.01);
|
| + EXPECT_NEAR(frame->DataU()[x / 2 + (y / 2) * frame->StrideU()] / 256.0,
|
| + orig_x, 0.01);
|
| + EXPECT_NEAR(frame->DataV()[x / 2 + (y / 2) * frame->StrideV()] / 256.0,
|
| + orig_y, 0.01);
|
| + }
|
| + }
|
|
|
| void TestCreateAliasedFrame(bool apply_rotation) {
|
| cricket::VideoFrameFactory& factory = factory_;
|
| @@ -92,6 +145,40 @@ class WebRtcVideoFrameFactoryTest : public testing::Test {
|
| new_height / 2, apply_rotation);
|
| }
|
|
|
| + void TestCreateScaledFrame(bool apply_rotation) {
|
| + cricket::VideoFrameFactory& factory = factory_;
|
| + factory.SetApplyRotation(apply_rotation);
|
| + InitFrame(webrtc::kVideoRotation_270);
|
| + const cricket::CapturedFrame& captured_frame = get_captured_frame();
|
| + // Create the new frame from the CapturedFrame.
|
| + std::unique_ptr<cricket::VideoFrame> frame;
|
| + int new_width = captured_frame.width / 2;
|
| + int new_height = captured_frame.height / 2;
|
| + frame = factory.CreateScaledFrame(&captured_frame, new_width, new_height);
|
| + VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width, new_height,
|
| + apply_rotation);
|
| +
|
| + frame = factory.CreateScaledFrame(&captured_frame,
|
| + new_width / 2, new_height / 2);
|
| + VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width / 2,
|
| + new_height / 2, apply_rotation);
|
| +
|
| + // Vertical cropping
|
| + frame = factory.CreateScaledFrame(&captured_frame,
|
| + new_width / 2, new_height / 3);
|
| + VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width / 2,
|
| + new_height / 3, apply_rotation);
|
| + VerifyCrop(frame->video_frame_buffer(), webrtc::kVideoRotation_270,
|
| + 1.0, 2.0 / 3.0, apply_rotation);
|
| +
|
| + // Horizontal cropping
|
| + frame = factory.CreateScaledFrame(&captured_frame,
|
| + new_width / 3, new_height / 2);
|
| + VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width / 3,
|
| + new_height / 2, apply_rotation);
|
| + VerifyCrop(frame->video_frame_buffer(), webrtc::kVideoRotation_270,
|
| + 2.0 / 3.0, 1.0, apply_rotation);
|
| + }
|
| const cricket::CapturedFrame& get_captured_frame() { return captured_frame_; }
|
|
|
| private:
|
| @@ -100,10 +187,18 @@ class WebRtcVideoFrameFactoryTest : public testing::Test {
|
| cricket::WebRtcVideoFrameFactory factory_;
|
| };
|
|
|
| -TEST_F(WebRtcVideoFrameFactoryTest, NoApplyRotation) {
|
| +TEST_F(WebRtcVideoFrameFactoryTest, CreateAliasedFrameNoApplyRotation) {
|
| TestCreateAliasedFrame(false);
|
| }
|
|
|
| -TEST_F(WebRtcVideoFrameFactoryTest, ApplyRotation) {
|
| +TEST_F(WebRtcVideoFrameFactoryTest, CreateAliasedFrameApplyRotation) {
|
| TestCreateAliasedFrame(true);
|
| }
|
| +
|
| +TEST_F(WebRtcVideoFrameFactoryTest, CreateScaledFrameNoApplyRotation) {
|
| + TestCreateScaledFrame(false);
|
| +}
|
| +
|
| +TEST_F(WebRtcVideoFrameFactoryTest, CreateScaledFrameApplyRotation) {
|
| + TestCreateScaledFrame(true);
|
| +}
|
|
|