video_encoder_helper_unittest.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "remoting/codec/video_encoder_helper.h"
  5. #include <memory>
  6. #include "remoting/proto/video.pb.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
  9. using webrtc::BasicDesktopFrame;
  10. using webrtc::DesktopRect;
  11. using webrtc::DesktopRegion;
  12. using webrtc::DesktopSize;
  13. using webrtc::DesktopVector;
  14. namespace remoting {
  15. TEST(VideoEncoderHelperTest, PropagatesCommonFields) {
  16. BasicDesktopFrame frame(DesktopSize(32, 32));
  17. frame.set_dpi(DesktopVector(96, 97));
  18. frame.set_capture_time_ms(20);
  19. frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16));
  20. VideoEncoderHelper helper;
  21. std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
  22. ASSERT_TRUE(packet->has_format());
  23. EXPECT_FALSE(packet->format().has_encoding());
  24. EXPECT_TRUE(packet->format().has_screen_width());
  25. EXPECT_TRUE(packet->format().has_screen_height());
  26. EXPECT_TRUE(packet->format().has_x_dpi());
  27. EXPECT_TRUE(packet->format().has_y_dpi());
  28. EXPECT_EQ(1, packet->dirty_rects().size());
  29. }
  30. TEST(VideoEncoderHelperTest, ZeroDpi) {
  31. BasicDesktopFrame frame(DesktopSize(32, 32));
  32. // DPI is zero unless explicitly set.
  33. VideoEncoderHelper helper;
  34. std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
  35. // Packet should have a format containing the screen dimensions only.
  36. ASSERT_TRUE(packet->has_format());
  37. EXPECT_TRUE(packet->format().has_screen_width());
  38. EXPECT_TRUE(packet->format().has_screen_height());
  39. EXPECT_FALSE(packet->format().has_x_dpi());
  40. EXPECT_FALSE(packet->format().has_y_dpi());
  41. }
  42. TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) {
  43. BasicDesktopFrame frame(DesktopSize(32, 32));
  44. // Set DPI so that the packet will have a format, with DPI but no size.
  45. frame.set_dpi(DesktopVector(96, 97));
  46. VideoEncoderHelper helper;
  47. std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
  48. packet = helper.CreateVideoPacket(frame);
  49. ASSERT_TRUE(packet->has_format());
  50. EXPECT_FALSE(packet->format().has_screen_width());
  51. EXPECT_FALSE(packet->format().has_screen_height());
  52. EXPECT_TRUE(packet->format().has_x_dpi());
  53. EXPECT_TRUE(packet->format().has_y_dpi());
  54. }
  55. TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) {
  56. VideoEncoderHelper helper;
  57. // Process the same frame twice, so the helper knows the current size, and
  58. // to trigger suppression of the size field due to the size not changing.
  59. BasicDesktopFrame frame1(DesktopSize(32, 32));
  60. std::unique_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1));
  61. packet = helper.CreateVideoPacket(frame1);
  62. // Process a different-sized frame to trigger size to be emitted.
  63. BasicDesktopFrame frame2(DesktopSize(48, 48));
  64. packet = helper.CreateVideoPacket(frame2);
  65. ASSERT_TRUE(packet->has_format());
  66. EXPECT_TRUE(packet->format().has_screen_width());
  67. EXPECT_TRUE(packet->format().has_screen_height());
  68. }
  69. } // namespace remoting