Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: remoting/codec/video_encoder_helper_unittest.cc

Issue 530243002: Move common VideoPacket initialization into VideoEncoderHelper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/codec/video_encoder_helper.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "remoting/proto/video.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
11
12 using webrtc::BasicDesktopFrame;
13 using webrtc::DesktopRect;
14 using webrtc::DesktopRegion;
15 using webrtc::DesktopSize;
16 using webrtc::DesktopVector;
17
18 namespace remoting {
19
20 TEST(VideoEncoderHelperTest, PropagatesCommonFields) {
21 BasicDesktopFrame frame(DesktopSize(32, 32));
22 frame.set_dpi(DesktopVector(96, 97));
23 frame.set_capture_time_ms(20);
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
29 VideoEncoderHelper helper;
30 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
31
32 ASSERT_TRUE(packet->has_format());
33 EXPECT_FALSE(packet->format().has_encoding());
34 EXPECT_TRUE(packet->format().has_screen_width());
35 EXPECT_TRUE(packet->format().has_screen_height());
36 EXPECT_TRUE(packet->format().has_x_dpi());
37 EXPECT_TRUE(packet->format().has_y_dpi());
38
39 EXPECT_TRUE(packet->has_capture_time_ms());
40 EXPECT_EQ(1, packet->dirty_rects().size());
41
42 ASSERT_TRUE(packet->has_use_desktop_shape());
43 EXPECT_TRUE(packet->use_desktop_shape());
44
45 EXPECT_EQ(1, packet->desktop_shape_rects().size());
46 }
47
48 TEST(VideoEncoderHelperTest, ZeroDpi) {
49 BasicDesktopFrame frame(DesktopSize(32, 32));
50 // DPI is zero unless explicitly set.
51
52 VideoEncoderHelper helper;
53 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
54
55 // Packet should have a format containing the screen dimensions only.
56 ASSERT_TRUE(packet->has_format());
57 EXPECT_TRUE(packet->format().has_screen_width());
58 EXPECT_TRUE(packet->format().has_screen_height());
59 EXPECT_FALSE(packet->format().has_x_dpi());
60 EXPECT_FALSE(packet->format().has_y_dpi());
61 }
62
63 TEST(VideoEncoderHelperTest, NoShape) {
64 BasicDesktopFrame frame(DesktopSize(32, 32));
65
66 VideoEncoderHelper helper;
67 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
68
69 EXPECT_FALSE(packet->use_desktop_shape());
70 EXPECT_EQ(0, packet->desktop_shape_rects().size());
71 }
72
73 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) {
74 BasicDesktopFrame frame(DesktopSize(32, 32));
75 // Set DPI so that the packet will have a format, with DPI but no size.
76 frame.set_dpi(DesktopVector(96, 97));
77
78 VideoEncoderHelper helper;
79 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
80 packet = helper.CreateVideoPacket(frame);
81
82 ASSERT_TRUE(packet->has_format());
83 EXPECT_FALSE(packet->format().has_screen_width());
84 EXPECT_FALSE(packet->format().has_screen_height());
85 EXPECT_TRUE(packet->format().has_x_dpi());
86 EXPECT_TRUE(packet->format().has_y_dpi());
87 }
88
89 TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) {
90 VideoEncoderHelper helper;
91
92 // Process the same frame twice, so the helper knows the current size, and
93 // to trigger suppression of the size field due to the size not changing.
94 BasicDesktopFrame frame1(DesktopSize(32, 32));
95 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1));
96 packet = helper.CreateVideoPacket(frame1);
97
98 // Process a different-sized frame to trigger size to be emitted.
99 BasicDesktopFrame frame2(DesktopSize(48, 48));
100 packet = helper.CreateVideoPacket(frame2);
101
102 ASSERT_TRUE(packet->has_format());
103 EXPECT_TRUE(packet->format().has_screen_width());
104 EXPECT_TRUE(packet->format().has_screen_height());
105 }
106
107 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698