vncserver.cc (8232:b28d06a175be) vncserver.cc (8635:23ba076b2cca)
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 29 unchanged lines hidden (view full) ---

38 * William Wang
39 */
40
41/** @file
42 * Implementiation of a VNC server
43 */
44
45#include <sys/ioctl.h>
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 29 unchanged lines hidden (view full) ---

38 * William Wang
39 */
40
41/** @file
42 * Implementiation of a VNC server
43 */
44
45#include <sys/ioctl.h>
46#include <sys/stat.h>
46#include <sys/termios.h>
47#include <sys/termios.h>
48#include <sys/types.h>
49#include <fcntl.h>
47#include <poll.h>
48#include <unistd.h>
49
50#include <cerrno>
51#include <cstdio>
52
53#include "base/vnc/vncserver.hh"
54#include "base/atomicio.hh"
50#include <poll.h>
51#include <unistd.h>
52
53#include <cerrno>
54#include <cstdio>
55
56#include "base/vnc/vncserver.hh"
57#include "base/atomicio.hh"
58#include "base/bitmap.hh"
55#include "base/misc.hh"
59#include "base/misc.hh"
60#include "base/output.hh"
56#include "base/socket.hh"
57#include "base/trace.hh"
58#include "debug/VNC.hh"
59#include "sim/byteswap.hh"
61#include "base/socket.hh"
62#include "base/trace.hh"
63#include "debug/VNC.hh"
64#include "sim/byteswap.hh"
65#include "sim/core.hh"
60
61using namespace std;
62
63/**
64 * Poll event for the listen socket
65 */
66VncServer::ListenEvent::ListenEvent(VncServer *vs, int fd, int e)
67 : PollEvent(fd, e), vncserver(vs)

--- 25 unchanged lines hidden (view full) ---

93
94/**
95 * VncServer
96 */
97VncServer::VncServer(const Params *p)
98 : SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number),
99 dataFd(-1), _videoWidth(1), _videoHeight(1), clientRfb(0), keyboard(NULL),
100 mouse(NULL), sendUpdate(false), videoMode(VideoConvert::UnknownMode),
66
67using namespace std;
68
69/**
70 * Poll event for the listen socket
71 */
72VncServer::ListenEvent::ListenEvent(VncServer *vs, int fd, int e)
73 : PollEvent(fd, e), vncserver(vs)

--- 25 unchanged lines hidden (view full) ---

99
100/**
101 * VncServer
102 */
103VncServer::VncServer(const Params *p)
104 : SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number),
105 dataFd(-1), _videoWidth(1), _videoHeight(1), clientRfb(0), keyboard(NULL),
106 mouse(NULL), sendUpdate(false), videoMode(VideoConvert::UnknownMode),
101 vc(NULL)
107 vc(NULL), captureEnabled(p->frame_capture), captureCurrentFrame(0),
108 captureLastHash(0), captureBitmap(0)
102{
103 if (p->port)
104 listen(p->port);
105
106 curState = WaitForProtocolVersion;
107
109{
110 if (p->port)
111 listen(p->port);
112
113 curState = WaitForProtocolVersion;
114
108
109 // currently we only support this one pixel format
110 // unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
111 // keep it around for telling the client and making
112 // sure the client cooperates
113 pixelFormat.bpp = 32;
114 pixelFormat.depth = 24;
115 pixelFormat.bigendian = 0;
116 pixelFormat.truecolor = 1;
117 pixelFormat.redmax = 0xff;
118 pixelFormat.greenmax = 0xff;
119 pixelFormat.bluemax = 0xff;
120 pixelFormat.redshift = 16;
121 pixelFormat.greenshift = 8;
122 pixelFormat.blueshift = 0;
123
115 // currently we only support this one pixel format
116 // unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
117 // keep it around for telling the client and making
118 // sure the client cooperates
119 pixelFormat.bpp = 32;
120 pixelFormat.depth = 24;
121 pixelFormat.bigendian = 0;
122 pixelFormat.truecolor = 1;
123 pixelFormat.redmax = 0xff;
124 pixelFormat.greenmax = 0xff;
125 pixelFormat.bluemax = 0xff;
126 pixelFormat.redshift = 16;
127 pixelFormat.greenshift = 8;
128 pixelFormat.blueshift = 0;
129
130 if (captureEnabled) {
131 // remove existing frame output directory if it exists, then create a
132 // clean empty directory
133 const string FRAME_OUTPUT_SUBDIR = "frames_" + name();
134 simout.remove(FRAME_OUTPUT_SUBDIR, true);
135 captureOutputDirectory = simout.createSubdirectory(
136 FRAME_OUTPUT_SUBDIR);
137 }
124
125 DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
126}
127
128VncServer::~VncServer()
129{
130 if (dataFd != -1)
131 ::close(dataFd);

--- 549 unchanged lines hidden (view full) ---

681 _videoHeight = height;
682
683 if (vc)
684 delete vc;
685
686 vc = new VideoConvert(mode, VideoConvert::rgb8888, videoWidth(),
687 videoHeight());
688
138
139 DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
140}
141
142VncServer::~VncServer()
143{
144 if (dataFd != -1)
145 ::close(dataFd);

--- 549 unchanged lines hidden (view full) ---

695 _videoHeight = height;
696
697 if (vc)
698 delete vc;
699
700 vc = new VideoConvert(mode, VideoConvert::rgb8888, videoWidth(),
701 videoHeight());
702
703 if (captureEnabled) {
704 // create bitmap of the frame with new attributes
705 if (captureBitmap)
706 delete captureBitmap;
707
708 assert(clientRfb);
709 captureBitmap = new Bitmap(videoMode, width, height, clientRfb);
710 assert(captureBitmap);
711 }
712
689 if (dataFd > 0 && clientRfb && curState == NormalPhase) {
690 if (supportsResizeEnc)
691 sendFrameBufferResized();
692 else
693 // The frame buffer changed size and we can't update the client
694 detach();
695 }
696 }
697}
698
699// create the VNC server object
700VncServer *
701VncServerParams::create()
702{
703 return new VncServer(this);
704}
713 if (dataFd > 0 && clientRfb && curState == NormalPhase) {
714 if (supportsResizeEnc)
715 sendFrameBufferResized();
716 else
717 // The frame buffer changed size and we can't update the client
718 detach();
719 }
720 }
721}
722
723// create the VNC server object
724VncServer *
725VncServerParams::create()
726{
727 return new VncServer(this);
728}
729
730void
731VncServer::captureFrameBuffer()
732{
733 assert(captureBitmap);
734
735 // skip identical frames
736 uint64_t new_hash = captureBitmap->getHash();
737 if (captureLastHash == new_hash)
738 return;
739 captureLastHash = new_hash;
740
741 // get the filename for the current frame
742 char frameFilenameBuffer[64];
743 snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.bmp.gz",
744 captureCurrentFrame, static_cast<long long int>(curTick()));
745 const string frameFilename(frameFilenameBuffer);
746
747 // create the compressed framebuffer file
748 ostream *fb_out = simout.create(captureOutputDirectory + frameFilename,
749 true);
750 captureBitmap->write(fb_out);
751 simout.close(fb_out);
752
753 ++captureCurrentFrame;
754}