| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/codec/video_encoder_helper.h" | 5 #include "remoting/codec/video_encoder_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 8 #include "remoting/proto/video.pb.h" | 9 #include "remoting/proto/video.pb.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 11 | 12 |
| 12 using webrtc::BasicDesktopFrame; | 13 using webrtc::BasicDesktopFrame; |
| 13 using webrtc::DesktopRect; | 14 using webrtc::DesktopRect; |
| 14 using webrtc::DesktopRegion; | 15 using webrtc::DesktopRegion; |
| 15 using webrtc::DesktopSize; | 16 using webrtc::DesktopSize; |
| 16 using webrtc::DesktopVector; | 17 using webrtc::DesktopVector; |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 | 20 |
| 20 TEST(VideoEncoderHelperTest, PropagatesCommonFields) { | 21 TEST(VideoEncoderHelperTest, PropagatesCommonFields) { |
| 21 BasicDesktopFrame frame(DesktopSize(32, 32)); | 22 BasicDesktopFrame frame(DesktopSize(32, 32)); |
| 22 frame.set_dpi(DesktopVector(96, 97)); | 23 frame.set_dpi(DesktopVector(96, 97)); |
| 23 frame.set_capture_time_ms(20); | 24 frame.set_capture_time_ms(20); |
| 24 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16)); | 25 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16)); |
| 25 | 26 |
| 26 VideoEncoderHelper helper; | 27 VideoEncoderHelper helper; |
| 27 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 28 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
| 28 | 29 |
| 29 ASSERT_TRUE(packet->has_format()); | 30 ASSERT_TRUE(packet->has_format()); |
| 30 EXPECT_FALSE(packet->format().has_encoding()); | 31 EXPECT_FALSE(packet->format().has_encoding()); |
| 31 EXPECT_TRUE(packet->format().has_screen_width()); | 32 EXPECT_TRUE(packet->format().has_screen_width()); |
| 32 EXPECT_TRUE(packet->format().has_screen_height()); | 33 EXPECT_TRUE(packet->format().has_screen_height()); |
| 33 EXPECT_TRUE(packet->format().has_x_dpi()); | 34 EXPECT_TRUE(packet->format().has_x_dpi()); |
| 34 EXPECT_TRUE(packet->format().has_y_dpi()); | 35 EXPECT_TRUE(packet->format().has_y_dpi()); |
| 35 | 36 |
| 36 EXPECT_EQ(1, packet->dirty_rects().size()); | 37 EXPECT_EQ(1, packet->dirty_rects().size()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 TEST(VideoEncoderHelperTest, ZeroDpi) { | 40 TEST(VideoEncoderHelperTest, ZeroDpi) { |
| 40 BasicDesktopFrame frame(DesktopSize(32, 32)); | 41 BasicDesktopFrame frame(DesktopSize(32, 32)); |
| 41 // DPI is zero unless explicitly set. | 42 // DPI is zero unless explicitly set. |
| 42 | 43 |
| 43 VideoEncoderHelper helper; | 44 VideoEncoderHelper helper; |
| 44 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 45 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
| 45 | 46 |
| 46 // Packet should have a format containing the screen dimensions only. | 47 // Packet should have a format containing the screen dimensions only. |
| 47 ASSERT_TRUE(packet->has_format()); | 48 ASSERT_TRUE(packet->has_format()); |
| 48 EXPECT_TRUE(packet->format().has_screen_width()); | 49 EXPECT_TRUE(packet->format().has_screen_width()); |
| 49 EXPECT_TRUE(packet->format().has_screen_height()); | 50 EXPECT_TRUE(packet->format().has_screen_height()); |
| 50 EXPECT_FALSE(packet->format().has_x_dpi()); | 51 EXPECT_FALSE(packet->format().has_x_dpi()); |
| 51 EXPECT_FALSE(packet->format().has_y_dpi()); | 52 EXPECT_FALSE(packet->format().has_y_dpi()); |
| 52 } | 53 } |
| 53 | 54 |
| 54 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) { | 55 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) { |
| 55 BasicDesktopFrame frame(DesktopSize(32, 32)); | 56 BasicDesktopFrame frame(DesktopSize(32, 32)); |
| 56 // Set DPI so that the packet will have a format, with DPI but no size. | 57 // Set DPI so that the packet will have a format, with DPI but no size. |
| 57 frame.set_dpi(DesktopVector(96, 97)); | 58 frame.set_dpi(DesktopVector(96, 97)); |
| 58 | 59 |
| 59 VideoEncoderHelper helper; | 60 VideoEncoderHelper helper; |
| 60 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 61 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
| 61 packet = helper.CreateVideoPacket(frame); | 62 packet = helper.CreateVideoPacket(frame); |
| 62 | 63 |
| 63 ASSERT_TRUE(packet->has_format()); | 64 ASSERT_TRUE(packet->has_format()); |
| 64 EXPECT_FALSE(packet->format().has_screen_width()); | 65 EXPECT_FALSE(packet->format().has_screen_width()); |
| 65 EXPECT_FALSE(packet->format().has_screen_height()); | 66 EXPECT_FALSE(packet->format().has_screen_height()); |
| 66 EXPECT_TRUE(packet->format().has_x_dpi()); | 67 EXPECT_TRUE(packet->format().has_x_dpi()); |
| 67 EXPECT_TRUE(packet->format().has_y_dpi()); | 68 EXPECT_TRUE(packet->format().has_y_dpi()); |
| 68 } | 69 } |
| 69 | 70 |
| 70 TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) { | 71 TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) { |
| 71 VideoEncoderHelper helper; | 72 VideoEncoderHelper helper; |
| 72 | 73 |
| 73 // Process the same frame twice, so the helper knows the current size, and | 74 // Process the same frame twice, so the helper knows the current size, and |
| 74 // to trigger suppression of the size field due to the size not changing. | 75 // to trigger suppression of the size field due to the size not changing. |
| 75 BasicDesktopFrame frame1(DesktopSize(32, 32)); | 76 BasicDesktopFrame frame1(DesktopSize(32, 32)); |
| 76 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1)); | 77 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1)); |
| 77 packet = helper.CreateVideoPacket(frame1); | 78 packet = helper.CreateVideoPacket(frame1); |
| 78 | 79 |
| 79 // Process a different-sized frame to trigger size to be emitted. | 80 // Process a different-sized frame to trigger size to be emitted. |
| 80 BasicDesktopFrame frame2(DesktopSize(48, 48)); | 81 BasicDesktopFrame frame2(DesktopSize(48, 48)); |
| 81 packet = helper.CreateVideoPacket(frame2); | 82 packet = helper.CreateVideoPacket(frame2); |
| 82 | 83 |
| 83 ASSERT_TRUE(packet->has_format()); | 84 ASSERT_TRUE(packet->has_format()); |
| 84 EXPECT_TRUE(packet->format().has_screen_width()); | 85 EXPECT_TRUE(packet->format().has_screen_width()); |
| 85 EXPECT_TRUE(packet->format().has_screen_height()); | 86 EXPECT_TRUE(packet->format().has_screen_height()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace remoting | 89 } // namespace remoting |
| OLD | NEW |