From 7852f11cebb7f147e8d74c517bca1daedf7faa46 Mon Sep 17 00:00:00 2001 From: betzalel Date: Thu, 24 Aug 2017 14:33:53 +0300 Subject: [PATCH] starting to create a new file format --- client/client-conn.go | 6 +++--- client/server-messages.go | 6 +++--- common/conn-interfaces.go | 2 +- player/fbs-play-listener.go | 14 +++++++++++--- player/fbs-reader.go | 9 +++++++-- todo.md | 9 ++++++++- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/client/client-conn.go b/client/client-conn.go index 8226933..730eea0 100644 --- a/client/client-conn.go +++ b/client/client-conn.go @@ -116,9 +116,9 @@ func (c *ClientConn) Read(bytes []byte) (n int, err error) { return c.conn.Read(bytes) } -func (c *ClientConn) CurrentColorMap() *common.ColorMap { - return &c.ColorMap -} +// func (c *ClientConn) CurrentColorMap() *common.ColorMap { +// return &c.ColorMap +// } // CutText tells the server that the client has new text in its cut buffer. // The text string MUST only contain Latin-1 characters. This encoding diff --git a/client/server-messages.go b/client/server-messages.go index 4ce2292..5f04cae 100644 --- a/client/server-messages.go +++ b/client/server-messages.go @@ -175,9 +175,9 @@ func (m *MsgSetColorMapEntries) Read(c common.IClientConn, r *common.RfbReadHelp return nil, err } } - cmap := c.CurrentColorMap() - // Update the connection's color map - cmap[result.FirstColor+i] = *color + // cmap := c.CurrentColorMap() + // // Update the connection's color map + // cmap[result.FirstColor+i] = *color } r.SendMessageEnd(common.ServerMessageType(m.Type())) return &result, nil diff --git a/common/conn-interfaces.go b/common/conn-interfaces.go index a5eed93..cb04c39 100644 --- a/common/conn-interfaces.go +++ b/common/conn-interfaces.go @@ -25,6 +25,6 @@ type IServerConn interface { type IClientConn interface { CurrentPixelFormat() *PixelFormat - CurrentColorMap() *ColorMap + //CurrentColorMap() *ColorMap Encodings() []IEncoding } diff --git a/player/fbs-play-listener.go b/player/fbs-play-listener.go index 29e2c8f..f4458aa 100644 --- a/player/fbs-play-listener.go +++ b/player/fbs-play-listener.go @@ -3,17 +3,25 @@ package player import ( "encoding/binary" + "io" "time" "vncproxy/client" "vncproxy/common" - "vncproxy/logger" "vncproxy/server" ) +type VncStreamFileReader interface { + io.Reader + CurrentTimestamp() int + ReadStartSession() (*common.ServerInit, error) + CurrentPixelFormat() *common.PixelFormat + Encodings() []common.IEncoding +} + type FBSPlayListener struct { Conn *server.ServerConn - Fbs *FbsReader + Fbs VncStreamFileReader serverMessageMap map[uint8]common.ServerMessage firstSegDone bool startTime int @@ -88,7 +96,7 @@ func (h *FBSPlayListener) sendFbsMessage() { return } timeSinceStart := int(time.Now().UnixNano()/int64(time.Millisecond)) - h.startTime - timeToSleep := fbs.currentTimestamp - timeSinceStart + timeToSleep := fbs.CurrentTimestamp() - timeSinceStart if timeToSleep > 0 { time.Sleep(time.Duration(timeToSleep) * time.Millisecond) } diff --git a/player/fbs-reader.go b/player/fbs-reader.go index 148707f..173bcaf 100644 --- a/player/fbs-reader.go +++ b/player/fbs-reader.go @@ -18,6 +18,10 @@ type FbsReader struct { encodings []common.IEncoding } +func (fbs *FbsReader) CurrentTimestamp() int { + return fbs.currentTimestamp +} + func (fbs *FbsReader) Read(p []byte) (n int, err error) { if fbs.buffer.Len() < len(p) { seg, err := fbs.ReadSegment() @@ -33,8 +37,9 @@ func (fbs *FbsReader) Read(p []byte) (n int, err error) { } func (fbs *FbsReader) CurrentPixelFormat() *common.PixelFormat { return fbs.pixelFormat } -func (fbs *FbsReader) CurrentColorMap() *common.ColorMap { return &common.ColorMap{} } -func (fbs *FbsReader) Encodings() []common.IEncoding { return fbs.encodings } + +//func (fbs *FbsReader) CurrentColorMap() *common.ColorMap { return &common.ColorMap{} } +func (fbs *FbsReader) Encodings() []common.IEncoding { return fbs.encodings } func NewFbsReader(fbsFile string) (*FbsReader, error) { diff --git a/todo.md b/todo.md index 6e3f83d..b614aeb 100644 --- a/todo.md +++ b/todo.md @@ -6,4 +6,11 @@ * code stuff: * move encodings to be on the framebufferupdate message object * clear all messages read functions from updating stuff, move modification logic to another listener - * message read function should accept only an io.Reader, move read helper logic (readuint8) to an actual helper class \ No newline at end of file + * message read function should accept only an io.Reader, move read helper logic (readuint8) to an actual helper class +* new recording format: + * rfb extension + * save FBResponse messages with additional fields + * timestamp + * is incremental + * size (bytes) + * have a header which contains an index of messages, holding timestamps & file positions for seeking