VNC: Add support for capturing frame buffer to file each time it is changed.
When a change in the frame buffer from the VNC server is detected, the new frame is stored out to the m5out/frames_*/ directory. Specifiy the flag "--frame-capture" when running configs/example/fs.py to enable this behavior. --HG-- extra : rebase_source : d4e08e83f4fa6ff79f3dc9c433fc1f0487e057fc
This commit is contained in:
parent
5bde1d359f
commit
9aea847f58
8 changed files with 163 additions and 21 deletions
|
@ -72,6 +72,10 @@ parser.add_option("--timesync", action="store_true",
|
||||||
# System options
|
# System options
|
||||||
parser.add_option("--kernel", action="store", type="string")
|
parser.add_option("--kernel", action="store", type="string")
|
||||||
parser.add_option("--script", action="store", type="string")
|
parser.add_option("--script", action="store", type="string")
|
||||||
|
parser.add_option("--frame-capture", action="store_true",
|
||||||
|
help="Stores changed frame buffers from the VNC server to compressed "\
|
||||||
|
"files in the gem5 output directory")
|
||||||
|
|
||||||
if buildEnv['TARGET_ISA'] == "arm":
|
if buildEnv['TARGET_ISA'] == "arm":
|
||||||
parser.add_option("--bare-metal", action="store_true",
|
parser.add_option("--bare-metal", action="store_true",
|
||||||
help="Provide the raw system without the linux specific bits")
|
help="Provide the raw system without the linux specific bits")
|
||||||
|
@ -205,4 +209,7 @@ else:
|
||||||
if options.timesync:
|
if options.timesync:
|
||||||
root.time_sync_enable = True
|
root.time_sync_enable = True
|
||||||
|
|
||||||
|
if options.frame_capture:
|
||||||
|
VncServer.frame_capture = True
|
||||||
|
|
||||||
Simulation.run(options, root, test_sys, FutureClass)
|
Simulation.run(options, root, test_sys, FutureClass)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
*
|
*
|
||||||
* Authors: William Wang
|
* Authors: William Wang
|
||||||
* Ali Saidi
|
* Ali Saidi
|
||||||
|
* Chris Emmons
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -43,29 +44,50 @@
|
||||||
#include "base/bitmap.hh"
|
#include "base/bitmap.hh"
|
||||||
#include "base/misc.hh"
|
#include "base/misc.hh"
|
||||||
|
|
||||||
|
const size_t Bitmap::sizeofHeaderBuffer = sizeof(Magic) + sizeof(Header) +
|
||||||
|
sizeof(Info);
|
||||||
|
|
||||||
// bitmap class ctor
|
// bitmap class ctor
|
||||||
Bitmap::Bitmap(VideoConvert::Mode _mode, uint16_t w, uint16_t h, uint8_t *d)
|
Bitmap::Bitmap(VideoConvert::Mode _mode, uint16_t w, uint16_t h, uint8_t *d)
|
||||||
: mode(_mode), height(h), width(w), data(d),
|
: mode(_mode), height(h), width(w), data(d),
|
||||||
vc(mode, VideoConvert::rgb8888, width, height)
|
vc(mode, VideoConvert::rgb8888, width, height), headerBuffer(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bitmap::~Bitmap() {
|
||||||
|
if (headerBuffer)
|
||||||
|
delete [] headerBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Bitmap::write(std::ostream *bmp)
|
Bitmap::write(std::ostream *bmp) const
|
||||||
{
|
{
|
||||||
assert(data);
|
assert(data);
|
||||||
|
|
||||||
// For further information see: http://en.wikipedia.org/wiki/BMP_file_format
|
// header is always the same for a bitmap object; compute the info once per
|
||||||
Magic magic = {{'B','M'}};
|
// bitmap object
|
||||||
Header header = {sizeof(VideoConvert::Rgb8888) * width * height , 0, 0, 54};
|
if (!headerBuffer) {
|
||||||
Info info = {sizeof(Info), width, height, 1,
|
// For further information see:
|
||||||
sizeof(VideoConvert::Rgb8888) * 8, 0,
|
// http://en.wikipedia.org/wiki/BMP_file_format
|
||||||
sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0};
|
Magic magic = {{'B','M'}};
|
||||||
|
Header header = {sizeof(VideoConvert::Rgb8888) * width * height,
|
||||||
|
0, 0, 54};
|
||||||
|
Info info = {sizeof(Info), width, height, 1,
|
||||||
|
sizeof(VideoConvert::Rgb8888) * 8, 0,
|
||||||
|
sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0};
|
||||||
|
|
||||||
bmp->write(reinterpret_cast<char*>(&magic), sizeof(magic));
|
char *p = headerBuffer = new char[sizeofHeaderBuffer];
|
||||||
bmp->write(reinterpret_cast<char*>(&header), sizeof(header));
|
memcpy(p, &magic, sizeof(Magic));
|
||||||
bmp->write(reinterpret_cast<char*>(&info), sizeof(info));
|
p += sizeof(Magic);
|
||||||
|
memcpy(p, &header, sizeof(Header));
|
||||||
|
p += sizeof(Header);
|
||||||
|
memcpy(p, &info, sizeof(Info));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. write the header
|
||||||
|
bmp->write(headerBuffer, sizeofHeaderBuffer);
|
||||||
|
|
||||||
|
// 2. write the bitmap data
|
||||||
uint8_t *tmp = vc.convert(data);
|
uint8_t *tmp = vc.convert(data);
|
||||||
uint32_t *tmp32 = (uint32_t*)tmp;
|
uint32_t *tmp32 = (uint32_t*)tmp;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
*
|
*
|
||||||
* Authors: William Wang
|
* Authors: William Wang
|
||||||
* Ali Saidi
|
* Ali Saidi
|
||||||
|
* Chris Emmons
|
||||||
*/
|
*/
|
||||||
#ifndef __BASE_BITMAP_HH__
|
#ifndef __BASE_BITMAP_HH__
|
||||||
#define __BASE_BITMAP_HH__
|
#define __BASE_BITMAP_HH__
|
||||||
|
@ -62,6 +63,9 @@ class Bitmap
|
||||||
*/
|
*/
|
||||||
Bitmap(VideoConvert::Mode mode, uint16_t w, uint16_t h, uint8_t *d);
|
Bitmap(VideoConvert::Mode mode, uint16_t w, uint16_t h, uint8_t *d);
|
||||||
|
|
||||||
|
/** Destructor */
|
||||||
|
~Bitmap();
|
||||||
|
|
||||||
/** Provide the converter with the data that should be output. It will be
|
/** Provide the converter with the data that should be output. It will be
|
||||||
* converted into rgb8888 and write out when write() is called.
|
* converted into rgb8888 and write out when write() is called.
|
||||||
* @param d the data
|
* @param d the data
|
||||||
|
@ -71,7 +75,13 @@ class Bitmap
|
||||||
/** Write the provided data into the fstream provided
|
/** Write the provided data into the fstream provided
|
||||||
* @param bmp stream to write to
|
* @param bmp stream to write to
|
||||||
*/
|
*/
|
||||||
void write(std::ostream *bmp);
|
void write(std::ostream *bmp) const;
|
||||||
|
|
||||||
|
/** Gets a hash over the bitmap for quick comparisons to other bitmaps.
|
||||||
|
* @return hash of the bitmap
|
||||||
|
*/
|
||||||
|
uint64_t getHash() const { return vc.getHash(data); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoConvert::Mode mode;
|
VideoConvert::Mode mode;
|
||||||
|
@ -81,6 +91,9 @@ class Bitmap
|
||||||
|
|
||||||
VideoConvert vc;
|
VideoConvert vc;
|
||||||
|
|
||||||
|
mutable char *headerBuffer;
|
||||||
|
static const size_t sizeofHeaderBuffer;
|
||||||
|
|
||||||
struct Magic
|
struct Magic
|
||||||
{
|
{
|
||||||
unsigned char magic_number[2];
|
unsigned char magic_number[2];
|
||||||
|
|
|
@ -43,3 +43,4 @@ class VncServer(SimObject):
|
||||||
type = 'VncServer'
|
type = 'VncServer'
|
||||||
port = Param.TcpPort(5900, "listen port")
|
port = Param.TcpPort(5900, "listen port")
|
||||||
number = Param.Int(0, "vnc client number")
|
number = Param.Int(0, "vnc client number")
|
||||||
|
frame_capture = Param.Bool(False, "capture changed frames to files")
|
||||||
|
|
|
@ -67,7 +67,7 @@ VideoConvert::~VideoConvert()
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t*
|
uint8_t*
|
||||||
VideoConvert::convert(uint8_t *fb)
|
VideoConvert::convert(const uint8_t *fb) const
|
||||||
{
|
{
|
||||||
switch (inputMode) {
|
switch (inputMode) {
|
||||||
case bgr565:
|
case bgr565:
|
||||||
|
@ -82,7 +82,7 @@ VideoConvert::convert(uint8_t *fb)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t*
|
uint8_t*
|
||||||
VideoConvert::m565rgb8888(uint8_t *fb, bool bgr)
|
VideoConvert::m565rgb8888(const uint8_t *fb, bool bgr) const
|
||||||
{
|
{
|
||||||
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
|
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
|
||||||
uint32_t *out32 = (uint32_t*)out;
|
uint32_t *out32 = (uint32_t*)out;
|
||||||
|
@ -113,7 +113,7 @@ VideoConvert::m565rgb8888(uint8_t *fb, bool bgr)
|
||||||
|
|
||||||
|
|
||||||
uint8_t*
|
uint8_t*
|
||||||
VideoConvert::bgr8888rgb8888(uint8_t *fb)
|
VideoConvert::bgr8888rgb8888(const uint8_t *fb) const
|
||||||
{
|
{
|
||||||
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
|
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
|
||||||
uint32_t *out32 = (uint32_t*)out;
|
uint32_t *out32 = (uint32_t*)out;
|
||||||
|
@ -136,4 +136,21 @@ VideoConvert::bgr8888rgb8888(uint8_t *fb)
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
uint64_t
|
||||||
|
VideoConvert::getHash(const uint8_t *fb) const
|
||||||
|
{
|
||||||
|
const uint8_t *fb_e = fb + area();
|
||||||
|
|
||||||
|
uint64_t hash = 1;
|
||||||
|
while (fb < fb_e - 8) {
|
||||||
|
hash += *((const uint64_t*)fb);
|
||||||
|
fb += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fb < fb_e) {
|
||||||
|
hash += *(fb++);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}*/
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#ifndef __BASE_VNC_CONVERT_HH__
|
#ifndef __BASE_VNC_CONVERT_HH__
|
||||||
#define __BASE_VNC_CONVERT_HH__
|
#define __BASE_VNC_CONVERT_HH__
|
||||||
|
|
||||||
|
#include <zlib.h>
|
||||||
#include "base/bitunion.hh"
|
#include "base/bitunion.hh"
|
||||||
|
|
||||||
class VideoConvert
|
class VideoConvert
|
||||||
|
@ -107,12 +108,21 @@ class VideoConvert
|
||||||
* @param fb the frame buffer to convert
|
* @param fb the frame buffer to convert
|
||||||
* @return the converted data (user must free)
|
* @return the converted data (user must free)
|
||||||
*/
|
*/
|
||||||
uint8_t* convert(uint8_t *fb);
|
uint8_t* convert(const uint8_t *fb) const;
|
||||||
|
|
||||||
/** Return the number of pixels that this buffer specifies
|
/** Return the number of pixels that this buffer specifies
|
||||||
* @return number of pixels
|
* @return number of pixels
|
||||||
*/
|
*/
|
||||||
int area() { return width * height; }
|
int area() const { return width * height; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a hash on the raw data.
|
||||||
|
*
|
||||||
|
* @return hash of the buffer
|
||||||
|
*/
|
||||||
|
inline uint64_t getHash(const uint8_t *fb) const {
|
||||||
|
return adler32(0UL, fb, width * height);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -121,7 +131,7 @@ class VideoConvert
|
||||||
* @param fb the data to convert
|
* @param fb the data to convert
|
||||||
* @return converted data
|
* @return converted data
|
||||||
*/
|
*/
|
||||||
uint8_t* bgr8888rgb8888(uint8_t *fb);
|
uint8_t* bgr8888rgb8888(const uint8_t *fb) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a bgr565 or rgb565 input to rgb8888.
|
* Convert a bgr565 or rgb565 input to rgb8888.
|
||||||
|
@ -129,7 +139,7 @@ class VideoConvert
|
||||||
* @param bgr true if the input data is bgr565
|
* @param bgr true if the input data is bgr565
|
||||||
* @return converted data
|
* @return converted data
|
||||||
*/
|
*/
|
||||||
uint8_t* m565rgb8888(uint8_t *fb, bool bgr);
|
uint8_t* m565rgb8888(const uint8_t *fb, bool bgr) const;
|
||||||
|
|
||||||
Mode inputMode;
|
Mode inputMode;
|
||||||
Mode outputMode;
|
Mode outputMode;
|
||||||
|
|
|
@ -43,7 +43,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/termios.h>
|
#include <sys/termios.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -52,11 +55,14 @@
|
||||||
|
|
||||||
#include "base/vnc/vncserver.hh"
|
#include "base/vnc/vncserver.hh"
|
||||||
#include "base/atomicio.hh"
|
#include "base/atomicio.hh"
|
||||||
|
#include "base/bitmap.hh"
|
||||||
#include "base/misc.hh"
|
#include "base/misc.hh"
|
||||||
|
#include "base/output.hh"
|
||||||
#include "base/socket.hh"
|
#include "base/socket.hh"
|
||||||
#include "base/trace.hh"
|
#include "base/trace.hh"
|
||||||
#include "debug/VNC.hh"
|
#include "debug/VNC.hh"
|
||||||
#include "sim/byteswap.hh"
|
#include "sim/byteswap.hh"
|
||||||
|
#include "sim/core.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -98,14 +104,14 @@ VncServer::VncServer(const Params *p)
|
||||||
: SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number),
|
: SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number),
|
||||||
dataFd(-1), _videoWidth(1), _videoHeight(1), clientRfb(0), keyboard(NULL),
|
dataFd(-1), _videoWidth(1), _videoHeight(1), clientRfb(0), keyboard(NULL),
|
||||||
mouse(NULL), sendUpdate(false), videoMode(VideoConvert::UnknownMode),
|
mouse(NULL), sendUpdate(false), videoMode(VideoConvert::UnknownMode),
|
||||||
vc(NULL)
|
vc(NULL), captureEnabled(p->frame_capture), captureCurrentFrame(0),
|
||||||
|
captureLastHash(0), captureBitmap(0)
|
||||||
{
|
{
|
||||||
if (p->port)
|
if (p->port)
|
||||||
listen(p->port);
|
listen(p->port);
|
||||||
|
|
||||||
curState = WaitForProtocolVersion;
|
curState = WaitForProtocolVersion;
|
||||||
|
|
||||||
|
|
||||||
// currently we only support this one pixel format
|
// currently we only support this one pixel format
|
||||||
// unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
|
// unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
|
||||||
// keep it around for telling the client and making
|
// keep it around for telling the client and making
|
||||||
|
@ -121,6 +127,14 @@ VncServer::VncServer(const Params *p)
|
||||||
pixelFormat.greenshift = 8;
|
pixelFormat.greenshift = 8;
|
||||||
pixelFormat.blueshift = 0;
|
pixelFormat.blueshift = 0;
|
||||||
|
|
||||||
|
if (captureEnabled) {
|
||||||
|
// remove existing frame output directory if it exists, then create a
|
||||||
|
// clean empty directory
|
||||||
|
const string FRAME_OUTPUT_SUBDIR = "frames_" + name();
|
||||||
|
simout.remove(FRAME_OUTPUT_SUBDIR, true);
|
||||||
|
captureOutputDirectory = simout.createSubdirectory(
|
||||||
|
FRAME_OUTPUT_SUBDIR);
|
||||||
|
}
|
||||||
|
|
||||||
DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
|
DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
|
||||||
}
|
}
|
||||||
|
@ -686,6 +700,16 @@ VncServer::setFrameBufferParams(VideoConvert::Mode mode, int width, int height)
|
||||||
vc = new VideoConvert(mode, VideoConvert::rgb8888, videoWidth(),
|
vc = new VideoConvert(mode, VideoConvert::rgb8888, videoWidth(),
|
||||||
videoHeight());
|
videoHeight());
|
||||||
|
|
||||||
|
if (captureEnabled) {
|
||||||
|
// create bitmap of the frame with new attributes
|
||||||
|
if (captureBitmap)
|
||||||
|
delete captureBitmap;
|
||||||
|
|
||||||
|
assert(clientRfb);
|
||||||
|
captureBitmap = new Bitmap(videoMode, width, height, clientRfb);
|
||||||
|
assert(captureBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
if (dataFd > 0 && clientRfb && curState == NormalPhase) {
|
if (dataFd > 0 && clientRfb && curState == NormalPhase) {
|
||||||
if (supportsResizeEnc)
|
if (supportsResizeEnc)
|
||||||
sendFrameBufferResized();
|
sendFrameBufferResized();
|
||||||
|
@ -702,3 +726,29 @@ VncServerParams::create()
|
||||||
{
|
{
|
||||||
return new VncServer(this);
|
return new VncServer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
VncServer::captureFrameBuffer()
|
||||||
|
{
|
||||||
|
assert(captureBitmap);
|
||||||
|
|
||||||
|
// skip identical frames
|
||||||
|
uint64_t new_hash = captureBitmap->getHash();
|
||||||
|
if (captureLastHash == new_hash)
|
||||||
|
return;
|
||||||
|
captureLastHash = new_hash;
|
||||||
|
|
||||||
|
// get the filename for the current frame
|
||||||
|
char frameFilenameBuffer[64];
|
||||||
|
snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.bmp.gz",
|
||||||
|
captureCurrentFrame, static_cast<long long int>(curTick()));
|
||||||
|
const string frameFilename(frameFilenameBuffer);
|
||||||
|
|
||||||
|
// create the compressed framebuffer file
|
||||||
|
ostream *fb_out = simout.create(captureOutputDirectory + frameFilename,
|
||||||
|
true);
|
||||||
|
captureBitmap->write(fb_out);
|
||||||
|
simout.close(fb_out);
|
||||||
|
|
||||||
|
++captureCurrentFrame;
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "base/vnc/convert.hh"
|
#include "base/vnc/convert.hh"
|
||||||
|
#include "base/bitmap.hh"
|
||||||
#include "base/circlebuf.hh"
|
#include "base/circlebuf.hh"
|
||||||
#include "base/pollevent.hh"
|
#include "base/pollevent.hh"
|
||||||
#include "base/socket.hh"
|
#include "base/socket.hh"
|
||||||
|
@ -55,6 +56,7 @@
|
||||||
#include "params/VncServer.hh"
|
#include "params/VncServer.hh"
|
||||||
#include "sim/sim_object.hh"
|
#include "sim/sim_object.hh"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A device that expects to receive input from the vnc server should derrive
|
* A device that expects to receive input from the vnc server should derrive
|
||||||
* (through mulitple inheritence if necessary from VncKeyboard or VncMouse
|
* (through mulitple inheritence if necessary from VncKeyboard or VncMouse
|
||||||
|
@ -316,7 +318,25 @@ class VncServer : public SimObject
|
||||||
/** The video converter that transforms data for us */
|
/** The video converter that transforms data for us */
|
||||||
VideoConvert *vc;
|
VideoConvert *vc;
|
||||||
|
|
||||||
|
/** Flag indicating whether to capture snapshots of frame buffer or not */
|
||||||
|
bool captureEnabled;
|
||||||
|
|
||||||
|
/** Current frame number being captured to a file */
|
||||||
|
int captureCurrentFrame;
|
||||||
|
|
||||||
|
/** Directory to store captured frames to */
|
||||||
|
std::string captureOutputDirectory;
|
||||||
|
|
||||||
|
/** Computed hash of the last captured frame */
|
||||||
|
uint64_t captureLastHash;
|
||||||
|
|
||||||
|
/** Cached bitmap object for writing out frame buffers to file */
|
||||||
|
Bitmap *captureBitmap;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/** Captures the current frame buffer to a file */
|
||||||
|
void captureFrameBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vnc client Interface
|
* vnc client Interface
|
||||||
*/
|
*/
|
||||||
|
@ -449,6 +469,8 @@ class VncServer : public SimObject
|
||||||
setDirty()
|
setDirty()
|
||||||
{
|
{
|
||||||
sendUpdate = true;
|
sendUpdate = true;
|
||||||
|
if (captureEnabled)
|
||||||
|
captureFrameBuffer();
|
||||||
sendFrameBufferUpdate();
|
sendFrameBufferUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue