blob: 7433f0c3dfe12b6c93f639165a431f9eb23c6b4b [file] [log] [blame]
Steve Kondik95027ea2017-06-14 17:22:58 -07001//
2// vncflinger - Copyright (C) 2017 Steve Kondik
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
Steve Kondik55db0532017-06-12 11:27:18 -070018#ifndef VNCFLINGER_H
19#define VNCFLINGER_H
20
Steve Kondik77754522017-06-14 17:00:33 -070021#include <gui/CpuConsumer.h>
Steve Kondik55db0532017-06-12 11:27:18 -070022#include <ui/DisplayInfo.h>
Steve Kondik5c8655c2017-06-19 00:28:47 -070023#include <utils/String8.h>
Steve Kondik55db0532017-06-12 11:27:18 -070024
Steve Kondik5f7b0a82017-06-16 09:04:43 -070025#include <rfb/rfb.h>
Steve Kondik55db0532017-06-12 11:27:18 -070026
Steve Kondik5c8655c2017-06-19 00:28:47 -070027#define VNC_AUTH_FILE "/data/system/vncauth"
Steve Kondik5f7b0a82017-06-16 09:04:43 -070028#define NUM_BUFS 1
Steve Kondik55db0532017-06-12 11:27:18 -070029
30namespace android {
31
Steve Kondik5c8655c2017-06-19 00:28:47 -070032class VNCFlinger : public RefBase {
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070033 public:
Steve Kondik5c8655c2017-06-19 00:28:47 -070034 VNCFlinger();
Steve Kondik55db0532017-06-12 11:27:18 -070035
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070036 virtual ~VNCFlinger() {
37 }
Steve Kondik55db0532017-06-12 11:27:18 -070038
39 virtual status_t start();
40 virtual status_t stop();
41
Steve Kondik7225c7f2017-06-14 00:06:16 -070042 virtual size_t addClient();
43 virtual size_t removeClient();
Steve Kondik55db0532017-06-12 11:27:18 -070044
Steve Kondik5c8655c2017-06-19 00:28:47 -070045 virtual status_t setListenAddress(String8& address, bool v6);
46 virtual status_t setPort(unsigned int port);
47
48 virtual status_t clearPassword();
49 virtual status_t setPassword(String8& passwd);
50
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070051 private:
Steve Kondik77754522017-06-14 17:00:33 -070052 class FrameListener : public CpuConsumer::FrameAvailableListener {
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070053 public:
54 FrameListener(VNCFlinger* vnc) : mVNC(vnc) {
55 }
Steve Kondik55db0532017-06-12 11:27:18 -070056
Steve Kondik77754522017-06-14 17:00:33 -070057 virtual void onFrameAvailable(const BufferItem& item);
58
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070059 private:
60 FrameListener(FrameListener&) {
61 }
62 VNCFlinger* mVNC;
Steve Kondik77754522017-06-14 17:00:33 -070063 };
64
65 virtual void eventLoop();
66
67 virtual status_t createVirtualDisplay();
Steve Kondik6ec5bc82017-06-15 01:31:51 -070068 virtual status_t destroyVirtualDisplayLocked();
Steve Kondik5c8655c2017-06-19 00:28:47 -070069
Steve Kondik77754522017-06-14 17:00:33 -070070 virtual status_t createVNCServer();
Steve Kondik5c8655c2017-06-19 00:28:47 -070071 virtual status_t startVNCServer();
Steve Kondik77754522017-06-14 17:00:33 -070072
73 virtual void processFrame();
74
Steve Kondik6ec5bc82017-06-15 01:31:51 -070075 virtual bool isDeviceRotated(int orientation);
76 virtual bool updateDisplayProjection();
Steve Kondik5f7b0a82017-06-16 09:04:43 -070077 virtual bool updateFBSize(CpuConsumer::LockedBuffer& buf);
Steve Kondik6ec5bc82017-06-15 01:31:51 -070078
Steve Kondik77754522017-06-14 17:00:33 -070079 // vncserver callbacks
Steve Kondik55db0532017-06-12 11:27:18 -070080 static ClientGoneHookPtr onClientGone(rfbClientPtr cl);
81 static enum rfbNewClientAction onNewClient(rfbClientPtr cl);
Steve Kondikef4e8652017-06-14 15:07:54 -070082 static void onFrameStart(rfbClientPtr cl);
83 static void onFrameDone(rfbClientPtr cl, int result);
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070084 static void rfbLogger(const char* format, ...);
85
Steve Kondik77754522017-06-14 17:00:33 -070086 bool mRunning;
87 bool mFrameAvailable;
Steve Kondik6ec5bc82017-06-15 01:31:51 -070088 bool mRotate;
89 bool mVDSActive;
Steve Kondik77754522017-06-14 17:00:33 -070090
91 Mutex mEventMutex;
92 Mutex mUpdateMutex;
93
94 Condition mEventCond;
Steve Kondik7225c7f2017-06-14 00:06:16 -070095
Steve Kondik5f7b0a82017-06-16 09:04:43 -070096 uint32_t mWidth, mHeight;
97 int32_t mOrientation;
Steve Kondik55db0532017-06-12 11:27:18 -070098
99 size_t mClientCount;
Steve Kondik77754522017-06-14 17:00:33 -0700100
Steve Kondik5f7b0a82017-06-16 09:04:43 -0700101 // Framebuffers
102 uint64_t mFrameNumber;
103 uint64_t mFrameSize;
104 nsecs_t mFrameStartWhen;
Steve Kondik6ec5bc82017-06-15 01:31:51 -0700105
Steve Kondik2c9d0cf2017-06-15 23:39:29 -0700106 // Server instance
107 rfbScreenInfoPtr mVNCScreen;
108
109 // Primary display
110 sp<IBinder> mMainDpy;
111
112 // Virtual display
113 sp<IBinder> mDpy;
Steve Kondik77754522017-06-14 17:00:33 -0700114
115 // Producer side of queue, passed into the virtual display.
116 sp<IGraphicBufferProducer> mProducer;
117
118 // This receives frames from the virtual display and makes them available
119 sp<CpuConsumer> mCpuConsumer;
120
Steve Kondik2c9d0cf2017-06-15 23:39:29 -0700121 // Consumer callback
122 sp<FrameListener> mListener;
Steve Kondik55db0532017-06-12 11:27:18 -0700123};
Steve Kondik55db0532017-06-12 11:27:18 -0700124};
125#endif