blob: 7d1e65be1eb35e68ba17cacaab19ae722edfe1ef [file] [log] [blame]
wez59ed1bb42014-09-03 04:36:331// 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
dcheng0765c492016-04-06 22:41:537#include <memory>
8
wez59ed1bb42014-09-03 04:36:339#include "remoting/proto/video.pb.h"
10#include "testing/gtest/include/gtest/gtest.h"
11#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
12
13using webrtc::BasicDesktopFrame;
14using webrtc::DesktopRect;
15using webrtc::DesktopRegion;
16using webrtc::DesktopSize;
17using webrtc::DesktopVector;
18
19namespace remoting {
20
21TEST(VideoEncoderHelperTest, PropagatesCommonFields) {
22 BasicDesktopFrame frame(DesktopSize(32, 32));
23 frame.set_dpi(DesktopVector(96, 97));
24 frame.set_capture_time_ms(20);
25 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16));
wez59ed1bb42014-09-03 04:36:3326
27 VideoEncoderHelper helper;
dcheng0765c492016-04-06 22:41:5328 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
wez59ed1bb42014-09-03 04:36:3329
30 ASSERT_TRUE(packet->has_format());
31 EXPECT_FALSE(packet->format().has_encoding());
32 EXPECT_TRUE(packet->format().has_screen_width());
33 EXPECT_TRUE(packet->format().has_screen_height());
34 EXPECT_TRUE(packet->format().has_x_dpi());
35 EXPECT_TRUE(packet->format().has_y_dpi());
36
wez59ed1bb42014-09-03 04:36:3337 EXPECT_EQ(1, packet->dirty_rects().size());
wez59ed1bb42014-09-03 04:36:3338}
39
40TEST(VideoEncoderHelperTest, ZeroDpi) {
41 BasicDesktopFrame frame(DesktopSize(32, 32));
42 // DPI is zero unless explicitly set.
43
44 VideoEncoderHelper helper;
dcheng0765c492016-04-06 22:41:5345 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
wez59ed1bb42014-09-03 04:36:3346
47 // Packet should have a format containing the screen dimensions only.
48 ASSERT_TRUE(packet->has_format());
49 EXPECT_TRUE(packet->format().has_screen_width());
50 EXPECT_TRUE(packet->format().has_screen_height());
51 EXPECT_FALSE(packet->format().has_x_dpi());
52 EXPECT_FALSE(packet->format().has_y_dpi());
53}
54
wez59ed1bb42014-09-03 04:36:3355TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) {
56 BasicDesktopFrame frame(DesktopSize(32, 32));
57 // Set DPI so that the packet will have a format, with DPI but no size.
58 frame.set_dpi(DesktopVector(96, 97));
59
60 VideoEncoderHelper helper;
dcheng0765c492016-04-06 22:41:5361 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
wez59ed1bb42014-09-03 04:36:3362 packet = helper.CreateVideoPacket(frame);
63
64 ASSERT_TRUE(packet->has_format());
65 EXPECT_FALSE(packet->format().has_screen_width());
66 EXPECT_FALSE(packet->format().has_screen_height());
67 EXPECT_TRUE(packet->format().has_x_dpi());
68 EXPECT_TRUE(packet->format().has_y_dpi());
69}
70
71TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) {
72 VideoEncoderHelper helper;
73
74 // Process the same frame twice, so the helper knows the current size, and
75 // to trigger suppression of the size field due to the size not changing.
76 BasicDesktopFrame frame1(DesktopSize(32, 32));
dcheng0765c492016-04-06 22:41:5377 std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1));
wez59ed1bb42014-09-03 04:36:3378 packet = helper.CreateVideoPacket(frame1);
79
80 // Process a different-sized frame to trigger size to be emitted.
81 BasicDesktopFrame frame2(DesktopSize(48, 48));
82 packet = helper.CreateVideoPacket(frame2);
83
84 ASSERT_TRUE(packet->has_format());
85 EXPECT_TRUE(packet->format().has_screen_width());
86 EXPECT_TRUE(packet->format().has_screen_height());
87}
88
89} // namespace remoting