video_encoder_helper.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "remoting/proto/video.pb.h"
  6. #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
  7. #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
  8. #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
  9. namespace remoting {
  10. VideoEncoderHelper::VideoEncoderHelper() = default;
  11. std::unique_ptr<VideoPacket> VideoEncoderHelper::CreateVideoPacket(
  12. const webrtc::DesktopFrame& frame) {
  13. return CreateVideoPacketWithUpdatedRegion(frame, frame.updated_region());
  14. }
  15. std::unique_ptr<VideoPacket>
  16. VideoEncoderHelper::CreateVideoPacketWithUpdatedRegion(
  17. const webrtc::DesktopFrame& frame,
  18. const webrtc::DesktopRegion& updated_region) {
  19. std::unique_ptr<VideoPacket> packet(new VideoPacket());
  20. // Set |screen_width| and |screen_height| iff they have changed.
  21. if (!frame.size().equals(screen_size_)) {
  22. screen_size_ = frame.size();
  23. VideoPacketFormat* format = packet->mutable_format();
  24. format->set_screen_width(screen_size_.width());
  25. format->set_screen_height(screen_size_.height());
  26. }
  27. // Record the list of changed rectangles.
  28. for (webrtc::DesktopRegion::Iterator iter(updated_region);
  29. !iter.IsAtEnd(); iter.Advance()) {
  30. const webrtc::DesktopRect& rect = iter.rect();
  31. Rect* dirty_rect = packet->add_dirty_rects();
  32. dirty_rect->set_x(rect.left());
  33. dirty_rect->set_y(rect.top());
  34. dirty_rect->set_width(rect.width());
  35. dirty_rect->set_height(rect.height());
  36. }
  37. // Store frame DPI.
  38. if (!frame.dpi().is_zero()) {
  39. packet->mutable_format()->set_x_dpi(frame.dpi().x());
  40. packet->mutable_format()->set_y_dpi(frame.dpi().y());
  41. }
  42. return packet;
  43. }
  44. } // namespace remoting