use of streamer.ByteBuffer in project cloudstack by apache.
the class AssertingByteBuffer method writeBytes.
@Override
public void writeBytes(byte[] actualData, int offset, int length) {
ByteBuffer actual = new ByteBuffer(actualData, offset, length);
// *DEBUG*/System.out.println("WriteString: "+actual+", cursor:"+cursor+".");
ByteBuffer expected = readBytes(actual.length);
if (!actual.equals(expected))
throw new RuntimeException("Expected value does not match actual value. Expected value: " + expected + ", actual value: " + actual + ".");
}
use of streamer.ByteBuffer in project cloudstack by apache.
the class FakeSink method main.
/**
* Example.
*/
public static void main(String[] args) {
Element sink = new FakeSink("sink") {
{
verbose = true;
}
};
byte[] data = new byte[] { 1, 2, 3 };
ByteBuffer buf = new ByteBuffer(data);
sink.setLink(STDIN, new SyncLink(), Direction.IN);
sink.getLink(STDIN).sendData(buf);
}
use of streamer.ByteBuffer in project cloudstack by apache.
the class ServerBitmapUpdate method readRectangle.
public BitmapRectangle readRectangle(ByteBuffer buf) {
BitmapRectangle rectangle = new BitmapRectangle();
// (2 bytes): A 16-bit, unsigned integer. Left bound of the rectangle.
rectangle.x = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. Top bound of the rectangle.
rectangle.y = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. Inclusive right bound of the
// rectangle.
int destRight = buf.readSignedShortLE();
rectangle.width = destRight - rectangle.x + 1;
// (2 bytes): A 16-bit, unsigned integer. Inclusive bottom bound of the
// rectangle.
int destBottom = buf.readSignedShortLE();
rectangle.height = destBottom - rectangle.y + 1;
// (2 bytes): A 16-bit, unsigned integer. The width of the rectangle.
rectangle.bufferWidth = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The height of the rectangle.
rectangle.bufferHeight = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The color depth of the rectangle
// data in bits-per-pixel.
rectangle.colorDepth = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The flags describing the format of
// the bitmap data in the bitmapDataStream field.
int flags = buf.readSignedShortLE();
// BITMAP_COMPRESSION 0x0001
// Indicates that the bitmap data is compressed. The bitmapComprHdr field
// MUST be present if the NO_BITMAP_COMPRESSION_HDR (0x0400) flag is not
// set.
boolean compressed = ((flags & BITMAP_COMPRESSION) > 0);
// (2 bytes): A 16-bit, unsigned integer. The size in bytes of the data in
// the bitmapComprHdr and bitmapDataStream fields.
int bitmapLength = buf.readSignedShortLE();
// bandwidth efficiency to save 8 bytes).
if (compressed && (flags & NO_BITMAP_COMPRESSION_HDR) == 0) {
// (8 bytes): Optional Compressed Data Header structure specifying the
// bitmap data in the bitmapDataStream.
// This field MUST be present if the BITMAP_COMPRESSION (0x0001) flag is
// present in the Flags field, but the NO_BITMAP_COMPRESSION_HDR (0x0400)
// flag is not.
// Note: Even when compression header is enabled, server sends nothing.
// rectangle.compressedBitmapHeader = buf.readBytes(8);
}
// an RDP 6.0 Bitmap Compressed Stream structure.
if (!compressed) {
rectangle.bitmapDataStream = buf.readBytes(bitmapLength);
} else {
ByteBuffer compressedImage = buf.readBytes(bitmapLength);
// * DEBUG */System.out.println("Compressed image: " + compressedImage + ", depth: " + rectangle.bitsPerPixel + ".");
rectangle.bitmapDataStream = RLEBitmapDecompression.rleDecompress(compressedImage, rectangle.bufferWidth, rectangle.bufferHeight, rectangle.colorDepth);
compressedImage.unref();
}
return rectangle;
}
use of streamer.ByteBuffer in project cloudstack by apache.
the class ServerBitmapUpdate method handleData.
@Override
public void handleData(ByteBuffer buf, Link link) {
if (verbose)
System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
// * DEBUG */System.out.println(buf.toHexString(buf.length));
BitmapOrder order = new BitmapOrder();
// (2 bytes): A 16-bit, unsigned integer. The update type. This field MUST
// be set to UPDATETYPE_BITMAP (0x0001).
int updateType = buf.readSignedShortLE();
if (updateType != UPDATETYPE_BITMAP)
throw new RuntimeException("Unknown update type. Expected update type: UPDATETYPE_BITMAP (0x1). Actual update type: " + updateType + ", buf: " + buf + ".");
// (2 bytes): A 16-bit, unsigned integer. The number of screen rectangles
// present in the rectangles field.
int numberRectangles = buf.readSignedShortLE();
// (variable): Variable-length array of TS_BITMAP_DATA structures, each of
// which contains a rectangular clipping taken from the server-side screen
// frame buffer. The number of screen clippings in the array is specified by
// the numberRectangles field.
BitmapRectangle[] rectangles = new BitmapRectangle[numberRectangles];
for (int i = 0; i < numberRectangles; i++) {
rectangles[i] = readRectangle(buf);
}
order.rectangles = rectangles;
buf.assertThatBufferIsFullyRead();
ByteBuffer data = new ByteBuffer(order);
pushDataToAllOuts(data);
buf.unref();
}
use of streamer.ByteBuffer in project cloudstack by apache.
the class ServerBitmapUpdate method main.
/**
* Example.
*/
public static void main(String[] args) {
ByteBuffer packet = new ByteBuffer(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x10, 0x00, 0x01, 0x04, 0x0a, 0x00, 0x0c, (byte) 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
Element bitmap = new ServerBitmapUpdate("bitmap") {
{
verbose = true;
}
};
FakeSink fakeSink = new FakeSink("sink") {
{
verbose = true;
}
};
Pipeline pipeline = new PipelineImpl("test");
// BufferedImageCanvas canvas = new BufferedImageCanvas(1024, 768);
// Element adapter = new AwtRdpAdapter("test",canvas );
// pipeline.addAndLink(bitmap, adapter);
pipeline.addAndLink(bitmap, fakeSink);
bitmap.handleData(packet, null);
}
Aggregations