• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 /*
4  * Copyright (C) 2017 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <array>
20 #include <cstdint>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "common/libs/utils/size_utils.h"
26 #include "common/libs/utils/tcp_socket.h"
27 #include "host/libs/config/cuttlefish_config.h"
28 #include "host/libs/screen_connector/screen_connector.h"
29 
30 namespace cuttlefish {
31 namespace vnc {
32 
33 // TODO(haining) when the hwcomposer gives a sequence number type, use that
34 // instead. It might just work to replace this class with a type alias
35 // using StripeSeqNumber = whatever_the_hwcomposer_uses;
36 class StripeSeqNumber {
37  public:
38   StripeSeqNumber() = default;
StripeSeqNumber(std::uint64_t t)39   explicit StripeSeqNumber(std::uint64_t t) : t_{t} {}
40   bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; }
41 
42   bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; }
43 
44  private:
45   std::uint64_t t_{};
46 };
47 
48 constexpr int32_t kJpegMaxQualityEncoding = -23;
49 constexpr int32_t kJpegMinQualityEncoding = -32;
50 
51 enum class ScreenOrientation { Portrait, Landscape };
52 constexpr int kNumOrientations = 2;
53 
54 struct Stripe {
55   int index = -1;
56   std::uint64_t frame_id{};
57   std::uint16_t x{};
58   std::uint16_t y{};
59   std::uint16_t width{};
60   std::uint16_t stride{};
61   std::uint16_t height{};
62   Message raw_data{};
63   Message jpeg_data{};
64   StripeSeqNumber seq_number{};
65   ScreenOrientation orientation{};
66 };
67 
68 /**
69  * ScreenConnectorImpl will generate this, and enqueue
70  *
71  * It's basically a (processed) frame, so it:
72  *   must be efficiently std::move-able
73  * Also, for the sake of algorithm simplicity:
74  *   must be default-constructable & assignable
75  *
76  */
77 struct VncScProcessedFrame : public ScreenConnectorFrameInfo {
78   Message raw_screen_;
79   std::deque<Stripe> stripes_;
CloneVncScProcessedFrame80   std::unique_ptr<VncScProcessedFrame> Clone() {
81     VncScProcessedFrame* cloned_frame = new VncScProcessedFrame();
82     cloned_frame->raw_screen_ = raw_screen_;
83     cloned_frame->stripes_ = stripes_;
84     return std::unique_ptr<VncScProcessedFrame>(cloned_frame);
85   }
86 };
87 using ScreenConnector = cuttlefish::ScreenConnector<VncScProcessedFrame>;
88 
89 }  // namespace vnc
90 }  // namespace cuttlefish
91