1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "Packetizer.h" 20 21 #include <https/RunLoop.h> 22 23 #include <source/HostToGuestComms.h> 24 25 #include <source/KeyboardSink.h> 26 #include <source/TouchSink.h> 27 #include <source/StreamingSource.h> 28 29 #include <memory> 30 #include <mutex> 31 #include <set> 32 33 #include <host/libs/screen_connector/screen_connector.h> 34 35 struct ServerState { 36 using TouchSink = android::TouchSink; 37 using KeyboardSink = android::KeyboardSink; 38 39 enum class VideoFormat { 40 VP8, 41 }; 42 explicit ServerState( 43 std::shared_ptr<RunLoop> runLoop, 44 VideoFormat videoFormat); 45 46 std::shared_ptr<Packetizer> getVideoPacketizer(); 47 std::shared_ptr<Packetizer> getAudioPacketizer(); 48 std::shared_ptr<TouchSink> getTouchSink(); 49 std::shared_ptr<KeyboardSink> getKeyboardSink(); 50 videoFormatServerState51 VideoFormat videoFormat() const { return mVideoFormat; } 52 53 size_t acquireHandlerId(); 54 void releaseHandlerId(size_t id); 55 56 private: 57 using StreamingSource = android::StreamingSource; 58 59 std::shared_ptr<RunLoop> mRunLoop; 60 61 VideoFormat mVideoFormat; 62 63 std::weak_ptr<Packetizer> mVideoPacketizer; 64 std::weak_ptr<Packetizer> mAudioPacketizer; 65 66 std::shared_ptr<StreamingSource> mFrameBufferSource; 67 68 std::shared_ptr<StreamingSource> mAudioSource; 69 70 std::shared_ptr<cvd::ScreenConnector> mScreenConnector; 71 std::shared_ptr<std::thread> mScreenConnectorMonitor; 72 73 std::shared_ptr<TouchSink> mTouchSink; 74 std::shared_ptr<KeyboardSink> mKeyboardSink; 75 76 std::set<size_t> mAllocatedHandlerIds; 77 78 void MonitorScreenConnector(); 79 }; 80