Search in sources :

Example 21 with Element

use of streamer.Element in project cloudstack by apache.

the class VncMessageHandler method main.

/**
     * Example.
     */
public static void main(String[] args) {
    // System.setProperty("streamer.Link.debug", "true");
    System.setProperty("streamer.Element.debug", "true");
    // System.setProperty("streamer.Pipeline.debug", "true");
    Element source = new MockSource("source") {

        {
            // Split messages at random boundaries to check "pushback" logic
            bufs = ByteBuffer.convertByteArraysToByteBuffers(new byte[] { // Message type: server bell
            RfbConstants.SERVER_BELL, // Message type: clipboard text
            RfbConstants.SERVER_CUT_TEXT, // Padding
            0, 0, 0, // Length (test)
            0, 0, 0, 4 }, new byte[] { // Clipboard text
            't', 'e', 's', 't', // Message type: frame buffer update
            RfbConstants.SERVER_FRAMEBUFFER_UPDATE, // Padding
            0, // Number of rectangles
            0, 3 }, new byte[] { // x, y, width, height: 0x0@4x4
            0, 0, 0, 0, 0, 4, 0, 4, // Encoding: desktop size
            (byte) ((RfbConstants.ENCODING_DESKTOP_SIZE >> 24) & 0xff), (byte) ((RfbConstants.ENCODING_DESKTOP_SIZE >> 16) & 0xff), (byte) ((RfbConstants.ENCODING_DESKTOP_SIZE >> 8) & 0xff), (byte) ((RfbConstants.ENCODING_DESKTOP_SIZE >> 0) & 0xff) }, new byte[] { // x, y, width, height: 0x0@4x4
            0, 0, 0, 0, 0, 4, 0, 4, // Encoding: raw rect
            (byte) ((RfbConstants.ENCODING_RAW >> 24) & 0xff), (byte) ((RfbConstants.ENCODING_RAW >> 16) & 0xff), (byte) ((RfbConstants.ENCODING_RAW >> 8) & 0xff), (byte) ((RfbConstants.ENCODING_RAW >> 0) & 0xff), // Raw pixel data 4x4x1 bpp
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new byte[] { 11, 12, 13, 14, 15, 16, // x, y, width, height: 0x0@2x2
            0, 0, 0, 0, 0, 2, 0, 2, // Encoding: copy rect
            (byte) ((RfbConstants.ENCODING_COPY_RECT >> 24) & 0xff), (byte) ((RfbConstants.ENCODING_COPY_RECT >> 16) & 0xff), (byte) ((RfbConstants.ENCODING_COPY_RECT >> 8) & 0xff), (byte) ((RfbConstants.ENCODING_COPY_RECT >> 0) & 0xff), // srcX, srcY: 2x2
            0, 2, 0, 2 });
        }
    };
    ScreenDescription screen = new ScreenDescription() {

        {
            bytesPerPixel = 1;
        }
    };
    final Element handler = new VncMessageHandler("handler", screen);
    ByteBuffer[] emptyBuf = ByteBuffer.convertByteArraysToByteBuffers(new byte[] {});
    Element fburSink = new MockSink("fbur", ByteBuffer.convertByteArraysToByteBuffers(new byte[] {}, new byte[] {}));
    Element bellSink = new MockSink("bell", emptyBuf);
    Element clipboardSink = new MockSink("clipboard", emptyBuf);
    Element desktopSizeChangeSink = new MockSink("desktop_size", emptyBuf);
    Element pixelsSink = new MockSink("pixels", ByteBuffer.convertByteArraysToByteBuffers(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }));
    Element copyRectSink = new MockSink("copy_rect", emptyBuf);
    Pipeline pipeline = new PipelineImpl("test");
    pipeline.addAndLink(source, handler);
    pipeline.add(fburSink, bellSink, clipboardSink, desktopSizeChangeSink, pixelsSink, copyRectSink);
    pipeline.link("handler >" + FRAME_BUFFER_UPDATE_REQUEST_ADAPTER_PAD, "fbur");
    pipeline.link("handler >" + SERVER_BELL_ADAPTER_PAD, "bell");
    pipeline.link("handler >" + SERVER_CLIPBOARD_ADAPTER_PAD, "clipboard");
    pipeline.link("handler >" + PIXEL_ADAPTER_PAD, "pixels");
    pipeline.runMainLoop("source", STDOUT, false, false);
}
Also used : MockSource(streamer.debug.MockSource) MockSink(streamer.debug.MockSink) PipelineImpl(streamer.PipelineImpl) Element(streamer.Element) BaseElement(streamer.BaseElement) ScreenDescription(common.ScreenDescription) ByteBuffer(streamer.ByteBuffer) Pipeline(streamer.Pipeline)

Example 22 with Element

use of streamer.Element in project cloudstack by apache.

the class MockSource method main.

/**
     * Example.
     */
public static void main(String[] args) {
    Element mockSource = new MockSource("source") {

        {
            bufs = new ByteBuffer[] { new ByteBuffer(new byte[] { 1, 1, 2, 3, 4, 5 }), new ByteBuffer(new byte[] { 2, 1, 2, 3, 4 }), new ByteBuffer(new byte[] { 3, 1, 2, 3 }), new ByteBuffer(new byte[] { 4, 1, 2 }), new ByteBuffer(new byte[] { 5, 1 }) };
            verbose = true;
            delay = 100;
        // this.numBuffers = this.bufs.length;
        }
    };
    Element fakeSink = new FakeSink("sink") {

        {
            verbose = true;
        }
    };
    Link link = new SyncLink();
    mockSource.setLink(STDOUT, link, Direction.OUT);
    fakeSink.setLink(STDIN, link, Direction.IN);
    link.run();
}
Also used : Element(streamer.Element) SyncLink(streamer.SyncLink) ByteBuffer(streamer.ByteBuffer) SyncLink(streamer.SyncLink) Link(streamer.Link)

Example 23 with Element

use of streamer.Element in project cloudstack by apache.

the class Vnc33Authentication method main.

/**
     * Example.
     */
public static void main(String[] args) {
    // System.setProperty("streamer.Link.debug", "true");
    System.setProperty("streamer.Element.debug", "true");
    // System.setProperty("streamer.Pipeline.debug", "true");
    final String password = "test";
    Element source = new MockSource("source") {

        {
            bufs = ByteBuffer.convertByteArraysToByteBuffers(// Request authentication and send 16 byte challenge
            new byte[] { 0, 0, 0, RfbConstants.VNC_AUTH, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, // Respond to challenge with AUTH_OK
            new byte[] { 0, 0, 0, RfbConstants.VNC_AUTH_OK });
        }
    };
    Element mainSink = new FakeSink("mainSink");
    final Vnc33Authentication auth = new Vnc33Authentication("auth", password);
    Element initSink = new MockSink("initSink") {

        {
            // Expect encoded password
            bufs = new ByteBuffer[] { auth.encodePassword(new ByteBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }), password) };
        }
    };
    Pipeline pipeline = new PipelineImpl("test");
    pipeline.addAndLink(source, auth, mainSink);
    pipeline.add(initSink);
    pipeline.link("auth >otout", "initSink");
    pipeline.runMainLoop("source", STDOUT, false, false);
}
Also used : MockSource(streamer.debug.MockSource) FakeSink(streamer.debug.FakeSink) MockSink(streamer.debug.MockSink) PipelineImpl(streamer.PipelineImpl) Element(streamer.Element) ByteBuffer(streamer.ByteBuffer) Pipeline(streamer.Pipeline)

Example 24 with Element

use of streamer.Element in project cloudstack by apache.

the class VncInitializer method main.

/**
     * Example.
     */
public static void main(String[] args) {
    // System.setProperty("streamer.Link.debug", "true");
    System.setProperty("streamer.Element.debug", "true");
    // System.setProperty("streamer.Pipeline.debug", "true");
    final String desktopName = "test";
    Element source = new MockSource("source") {

        {
            bufs = ByteBuffer.convertByteArraysToByteBuffers(// Send screen description
            new byte[] { // Framebuffer width (short)
            0, (byte) 200, // Framebuffer height (short)
            0, 100, // Bits per pixel
            32, // Depth,
            24, // Endianness flag
            RfbConstants.LITTLE_ENDIAN, // Truecolor flag
            RfbConstants.TRUE_COLOR, // Red max (short)
            0, (byte) 255, // Green max (short)
            0, (byte) 255, // Blue max (short)
            0, (byte) 255, // Red shift
            16, // Green shift
            8, // Blue shift
            0, // Padding
            0, 0, 0, // Desktop name length (int)
            0, 0, 0, 4, // Desktop name ("test", 4 bytes)
            't', 'e', 's', 't', // Tail
            1, 2, 3 }, // Tail packet
            new byte[] { 4, 5, 6 });
        }
    };
    ScreenDescription screen = new ScreenDescription();
    final VncInitializer init = new VncInitializer("init", true, screen);
    Element initSink = new MockSink("initSink") {

        {
            // Expect shared flag
            bufs = ByteBuffer.convertByteArraysToByteBuffers(new byte[] { RfbConstants.SHARED_ACCESS });
        }
    };
    Element mainSink = new MockSink("mainSink") {

        {
            // Expect two tail packets
            bufs = ByteBuffer.convertByteArraysToByteBuffers(new byte[] { 1, 2, 3 }, new byte[] { 4, 5, 6 });
        }
    };
    ByteBuffer[] emptyBuf = ByteBuffer.convertByteArraysToByteBuffers(new byte[] {});
    Element encodingsSink = new MockSink("encodings", emptyBuf);
    Element pixelFormatSink = new MockSink("pixel_format", emptyBuf);
    Pipeline pipeline = new PipelineImpl("test");
    pipeline.addAndLink(source, init, mainSink);
    pipeline.add(encodingsSink, pixelFormatSink, initSink);
    pipeline.link("init >otout", "initSink");
    pipeline.link("init >" + CLIENT_SUPPORTED_ENCODINGS_ADAPTER_PAD, "encodings");
    pipeline.link("init >" + CLIENT_PIXEL_FORMAT_ADAPTER_PAD, "pixel_format");
    pipeline.runMainLoop("source", STDOUT, false, false);
    if (!screen.isRGB888_32_LE())
        System.err.println("Screen description was read incorrectly: " + screen + ".");
    if (!desktopName.equals(screen.getDesktopName()))
        System.err.println("Screen desktop name was read incorrectly: \"" + screen.getDesktopName() + "\".");
}
Also used : MockSource(streamer.debug.MockSource) MockSink(streamer.debug.MockSink) PipelineImpl(streamer.PipelineImpl) Element(streamer.Element) ScreenDescription(common.ScreenDescription) ByteBuffer(streamer.ByteBuffer) Pipeline(streamer.Pipeline)

Example 25 with Element

use of streamer.Element in project cloudstack by apache.

the class FrameBufferUpdateRequest method main.

public static void main(String[] args) {
    System.setProperty("streamer.Element.debug", "true");
    ScreenDescription screen = new ScreenDescription();
    screen.setFramebufferSize(120, 80);
    Element adapter = new FrameBufferUpdateRequest("renderer", screen);
    Element sink = new MockSink("sink", ByteBuffer.convertByteArraysToByteBuffers(new byte[] { // Request
    RfbConstants.CLIENT_FRAMEBUFFER_UPDATE_REQUEST, // Full update (redraw area)
    RfbConstants.FRAMEBUFFER_FULL_UPDATE_REQUEST, // X
    0, 1, // Y
    0, 2, // Width
    0, 3, // Height
    0, 4 }));
    ByteBuffer buf = new ByteBuffer(new byte[0]);
    buf.putMetadata(TARGET_X, 1);
    buf.putMetadata(TARGET_Y, 2);
    buf.putMetadata(WIDTH, 3);
    buf.putMetadata(HEIGHT, 4);
    Element source = new MockSource("source", new ByteBuffer[] { buf });
    Pipeline pipeline = new PipelineImpl("test");
    pipeline.addAndLink(source, adapter, sink);
    pipeline.runMainLoop("source", STDOUT, false, false);
}
Also used : MockSource(streamer.debug.MockSource) MockSink(streamer.debug.MockSink) PipelineImpl(streamer.PipelineImpl) ScreenDescription(common.ScreenDescription) Element(streamer.Element) BaseElement(streamer.BaseElement) ByteBuffer(streamer.ByteBuffer) Pipeline(streamer.Pipeline)

Aggregations

Element (streamer.Element)36 Pipeline (streamer.Pipeline)28 PipelineImpl (streamer.PipelineImpl)28 MockSource (streamer.debug.MockSource)25 MockSink (streamer.debug.MockSink)24 BaseElement (streamer.BaseElement)18 ByteBuffer (streamer.ByteBuffer)12 ScreenDescription (common.ScreenDescription)5 SyncLink (streamer.SyncLink)4 Link (streamer.Link)3 FakeSink (streamer.debug.FakeSink)3 BufferedImageCanvas (common.BufferedImageCanvas)1 DataBufferInt (java.awt.image.DataBufferInt)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1 RdpClient (rdpclient.RdpClient)1 ServerBitmapUpdate (rdpclient.rdp.ServerBitmapUpdate)1 SocketWrapper (streamer.SocketWrapper)1 FakeSource (streamer.debug.FakeSource)1 SSLState (streamer.ssl.SSLState)1