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 "base/memory/scoped_ptr.h" |
8 #include "remoting/proto/video.pb.h" | 8 #include "remoting/proto/video.pb.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
11 | 11 |
12 using webrtc::BasicDesktopFrame; | 12 using webrtc::BasicDesktopFrame; |
13 using webrtc::DesktopRect; | 13 using webrtc::DesktopRect; |
14 using webrtc::DesktopRegion; | 14 using webrtc::DesktopRegion; |
15 using webrtc::DesktopSize; | 15 using webrtc::DesktopSize; |
16 using webrtc::DesktopVector; | 16 using webrtc::DesktopVector; |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
20 TEST(VideoEncoderHelperTest, PropagatesCommonFields) { | 20 TEST(VideoEncoderHelperTest, PropagatesCommonFields) { |
21 BasicDesktopFrame frame(DesktopSize(32, 32)); | 21 BasicDesktopFrame frame(DesktopSize(32, 32)); |
22 frame.set_dpi(DesktopVector(96, 97)); | 22 frame.set_dpi(DesktopVector(96, 97)); |
23 frame.set_capture_time_ms(20); | 23 frame.set_capture_time_ms(20); |
24 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16)); | 24 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16)); |
25 scoped_ptr<DesktopRegion> shape( | |
26 new DesktopRegion(DesktopRect::MakeLTRB(16, 0, 32, 16))); | |
27 frame.set_shape(shape.release()); | |
28 | 25 |
29 VideoEncoderHelper helper; | 26 VideoEncoderHelper helper; |
30 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 27 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
31 | 28 |
32 ASSERT_TRUE(packet->has_format()); | 29 ASSERT_TRUE(packet->has_format()); |
33 EXPECT_FALSE(packet->format().has_encoding()); | 30 EXPECT_FALSE(packet->format().has_encoding()); |
34 EXPECT_TRUE(packet->format().has_screen_width()); | 31 EXPECT_TRUE(packet->format().has_screen_width()); |
35 EXPECT_TRUE(packet->format().has_screen_height()); | 32 EXPECT_TRUE(packet->format().has_screen_height()); |
36 EXPECT_TRUE(packet->format().has_x_dpi()); | 33 EXPECT_TRUE(packet->format().has_x_dpi()); |
37 EXPECT_TRUE(packet->format().has_y_dpi()); | 34 EXPECT_TRUE(packet->format().has_y_dpi()); |
38 | 35 |
39 EXPECT_EQ(1, packet->dirty_rects().size()); | 36 EXPECT_EQ(1, packet->dirty_rects().size()); |
40 | |
41 ASSERT_TRUE(packet->has_use_desktop_shape()); | |
42 EXPECT_TRUE(packet->use_desktop_shape()); | |
43 | |
44 EXPECT_EQ(1, packet->desktop_shape_rects().size()); | |
45 } | 37 } |
46 | 38 |
47 TEST(VideoEncoderHelperTest, ZeroDpi) { | 39 TEST(VideoEncoderHelperTest, ZeroDpi) { |
48 BasicDesktopFrame frame(DesktopSize(32, 32)); | 40 BasicDesktopFrame frame(DesktopSize(32, 32)); |
49 // DPI is zero unless explicitly set. | 41 // DPI is zero unless explicitly set. |
50 | 42 |
51 VideoEncoderHelper helper; | 43 VideoEncoderHelper helper; |
52 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 44 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
53 | 45 |
54 // Packet should have a format containing the screen dimensions only. | 46 // Packet should have a format containing the screen dimensions only. |
55 ASSERT_TRUE(packet->has_format()); | 47 ASSERT_TRUE(packet->has_format()); |
56 EXPECT_TRUE(packet->format().has_screen_width()); | 48 EXPECT_TRUE(packet->format().has_screen_width()); |
57 EXPECT_TRUE(packet->format().has_screen_height()); | 49 EXPECT_TRUE(packet->format().has_screen_height()); |
58 EXPECT_FALSE(packet->format().has_x_dpi()); | 50 EXPECT_FALSE(packet->format().has_x_dpi()); |
59 EXPECT_FALSE(packet->format().has_y_dpi()); | 51 EXPECT_FALSE(packet->format().has_y_dpi()); |
60 } | 52 } |
61 | 53 |
62 TEST(VideoEncoderHelperTest, NoShape) { | |
63 BasicDesktopFrame frame(DesktopSize(32, 32)); | |
64 | |
65 VideoEncoderHelper helper; | |
66 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | |
67 | |
68 EXPECT_FALSE(packet->use_desktop_shape()); | |
69 EXPECT_EQ(0, packet->desktop_shape_rects().size()); | |
70 } | |
71 | |
72 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) { | 54 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) { |
73 BasicDesktopFrame frame(DesktopSize(32, 32)); | 55 BasicDesktopFrame frame(DesktopSize(32, 32)); |
74 // Set DPI so that the packet will have a format, with DPI but no size. | 56 // Set DPI so that the packet will have a format, with DPI but no size. |
75 frame.set_dpi(DesktopVector(96, 97)); | 57 frame.set_dpi(DesktopVector(96, 97)); |
76 | 58 |
77 VideoEncoderHelper helper; | 59 VideoEncoderHelper helper; |
78 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); | 60 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame)); |
79 packet = helper.CreateVideoPacket(frame); | 61 packet = helper.CreateVideoPacket(frame); |
80 | 62 |
81 ASSERT_TRUE(packet->has_format()); | 63 ASSERT_TRUE(packet->has_format()); |
(...skipping 15 matching lines...) Expand all Loading... |
97 // Process a different-sized frame to trigger size to be emitted. | 79 // Process a different-sized frame to trigger size to be emitted. |
98 BasicDesktopFrame frame2(DesktopSize(48, 48)); | 80 BasicDesktopFrame frame2(DesktopSize(48, 48)); |
99 packet = helper.CreateVideoPacket(frame2); | 81 packet = helper.CreateVideoPacket(frame2); |
100 | 82 |
101 ASSERT_TRUE(packet->has_format()); | 83 ASSERT_TRUE(packet->has_format()); |
102 EXPECT_TRUE(packet->format().has_screen_width()); | 84 EXPECT_TRUE(packet->format().has_screen_width()); |
103 EXPECT_TRUE(packet->format().has_screen_height()); | 85 EXPECT_TRUE(packet->format().has_screen_height()); |
104 } | 86 } |
105 | 87 |
106 } // namespace remoting | 88 } // namespace remoting |
OLD | NEW |