Steve Kondik | 95027ea | 2017-06-14 17:22:58 -0700 | [diff] [blame^] | 1 | // |
| 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 Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 18 | #ifndef VNCFLINGER_H |
| 19 | #define VNCFLINGER_H |
| 20 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 21 | #include <gui/CpuConsumer.h> |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 22 | #include <ui/DisplayInfo.h> |
| 23 | |
| 24 | #include "rfb/rfb.h" |
| 25 | |
| 26 | #define VNC_PORT 5901 |
| 27 | |
| 28 | namespace android { |
| 29 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 30 | class VNCFlinger { |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 31 | public: |
| 32 | VNCFlinger(int argc, char **argv) : |
| 33 | mArgc(argc), |
| 34 | mArgv(argv), |
| 35 | mClientCount(0) { |
| 36 | } |
| 37 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 38 | virtual ~VNCFlinger() {} |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 39 | |
| 40 | virtual status_t start(); |
| 41 | virtual status_t stop(); |
| 42 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 43 | virtual size_t addClient(); |
| 44 | virtual size_t removeClient(); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 45 | |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame] | 46 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 47 | private: |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 48 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 49 | class FrameListener : public CpuConsumer::FrameAvailableListener { |
| 50 | public: |
| 51 | FrameListener(VNCFlinger *vnc) : mVNC(vnc) {} |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 52 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 53 | 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 Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 69 | static ClientGoneHookPtr onClientGone(rfbClientPtr cl); |
| 70 | static enum rfbNewClientAction onNewClient(rfbClientPtr cl); |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame] | 71 | static void onFrameStart(rfbClientPtr cl); |
| 72 | static void onFrameDone(rfbClientPtr cl, int result); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 73 | static void rfbLogger(const char *format, ...); |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 74 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 75 | bool mRunning; |
| 76 | bool mFrameAvailable; |
| 77 | |
| 78 | Mutex mEventMutex; |
| 79 | Mutex mUpdateMutex; |
| 80 | |
| 81 | Condition mEventCond; |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 82 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 83 | rfbScreenInfoPtr mVNCScreen; |
| 84 | uint8_t *mVNCBuf; |
| 85 | |
| 86 | uint32_t mWidth, mHeight; |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 87 | |
| 88 | sp<IBinder> mMainDpy; |
| 89 | DisplayInfo mMainDpyInfo; |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 90 | |
| 91 | int mArgc; |
| 92 | char **mArgv; |
| 93 | |
| 94 | size_t mClientCount; |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 95 | |
| 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 Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | }; |
| 110 | #endif |