blob: a446c81ef9bd6465f375bd3f6891b7d7adadc1e1 [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>
23
24#include "rfb/rfb.h"
25
26#define VNC_PORT 5901
27
28namespace android {
29
Steve Kondik7225c7f2017-06-14 00:06:16 -070030class VNCFlinger {
Steve Kondik55db0532017-06-12 11:27:18 -070031public:
32 VNCFlinger(int argc, char **argv) :
33 mArgc(argc),
34 mArgv(argv),
35 mClientCount(0) {
36 }
37
Steve Kondik7225c7f2017-06-14 00:06:16 -070038 virtual ~VNCFlinger() {}
Steve Kondik55db0532017-06-12 11:27:18 -070039
40 virtual status_t start();
41 virtual status_t stop();
42
Steve Kondik7225c7f2017-06-14 00:06:16 -070043 virtual size_t addClient();
44 virtual size_t removeClient();
Steve Kondik55db0532017-06-12 11:27:18 -070045
Steve Kondikef4e8652017-06-14 15:07:54 -070046
Steve Kondik55db0532017-06-12 11:27:18 -070047private:
Steve Kondik7225c7f2017-06-14 00:06:16 -070048
Steve Kondik77754522017-06-14 17:00:33 -070049 class FrameListener : public CpuConsumer::FrameAvailableListener {
50 public:
51 FrameListener(VNCFlinger *vnc) : mVNC(vnc) {}
Steve Kondik55db0532017-06-12 11:27:18 -070052
Steve Kondik77754522017-06-14 17:00:33 -070053 virtual void onFrameAvailable(const BufferItem& item);
54
55 private:
56 FrameListener(FrameListener&) {}
57 VNCFlinger *mVNC;
58 };
59
60 virtual void eventLoop();
61
62 virtual status_t createVirtualDisplay();
63 virtual status_t destroyVirtualDisplay();
64 virtual status_t createVNCServer();
65
66 virtual void processFrame();
67
68 // vncserver callbacks
Steve Kondik55db0532017-06-12 11:27:18 -070069 static ClientGoneHookPtr onClientGone(rfbClientPtr cl);
70 static enum rfbNewClientAction onNewClient(rfbClientPtr cl);
Steve Kondikef4e8652017-06-14 15:07:54 -070071 static void onFrameStart(rfbClientPtr cl);
72 static void onFrameDone(rfbClientPtr cl, int result);
Steve Kondik55db0532017-06-12 11:27:18 -070073 static void rfbLogger(const char *format, ...);
Steve Kondik7225c7f2017-06-14 00:06:16 -070074
Steve Kondik77754522017-06-14 17:00:33 -070075 bool mRunning;
76 bool mFrameAvailable;
77
78 Mutex mEventMutex;
79 Mutex mUpdateMutex;
80
81 Condition mEventCond;
Steve Kondik7225c7f2017-06-14 00:06:16 -070082
Steve Kondik55db0532017-06-12 11:27:18 -070083 rfbScreenInfoPtr mVNCScreen;
84 uint8_t *mVNCBuf;
85
86 uint32_t mWidth, mHeight;
Steve Kondik55db0532017-06-12 11:27:18 -070087
88 sp<IBinder> mMainDpy;
89 DisplayInfo mMainDpyInfo;
Steve Kondik55db0532017-06-12 11:27:18 -070090
91 int mArgc;
92 char **mArgv;
93
94 size_t mClientCount;
Steve Kondik77754522017-06-14 17:00:33 -070095
96 sp<FrameListener> mListener;
97
98 // Producer side of queue, passed into the virtual display.
99 sp<IGraphicBufferProducer> mProducer;
100
101 // This receives frames from the virtual display and makes them available
102 sp<CpuConsumer> mCpuConsumer;
103
104 // The virtual display instance
105 sp<IBinder> mDpy;
106
Steve Kondik55db0532017-06-12 11:27:18 -0700107};
108
109};
110#endif