Search in sources :

Example 36 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class ServerFormatListPDU method sendFormatListParseResponse.

/**
 * The Format List Response PDU is sent as a reply to the Format List PDU. It
 * is used to indicate whether processing of the Format List PDU was
 * successful.
 *
 * @param b
 */
protected void sendFormatListParseResponse(boolean ok) {
    ByteBuffer buf = new ByteBuffer(8, true);
    // Type
    buf.writeShortLE(ServerClipRdrChannelRouter.CB_FORMAT_LIST_RESPONSE);
    // Message flags
    buf.writeShortLE((ok) ? ServerClipRdrChannelRouter.CB_RESPONSE_OK : ServerClipRdrChannelRouter.CB_RESPONSE_FAIL);
    // Length
    buf.writeIntLE(0);
    buf.trimAtCursor();
    pushDataToPad(STDOUT, buf);
}
Also used : ByteBuffer(streamer.ByteBuffer)

Example 37 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class Sequence method readTagValue.

@Override
public void readTagValue(ByteBuffer buf, BerType typeAndFlags) {
    // Type is already read by parent parser
    long length = buf.readBerLength();
    if (length > buf.remainderLength())
        throw new RuntimeException("BER sequence is too long: " + length + " bytes, while buffer remainder length is " + buf.remainderLength() + ". Data: " + buf + ".");
    ByteBuffer value = buf.readBytes((int) length);
    parseContent(value);
    value.unref();
}
Also used : ByteBuffer(streamer.ByteBuffer)

Example 38 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class AprSocketSource method poll.

/**
 * Read data from input stream.
 */
@Override
public void poll(boolean block) {
    if (socketWrapper.shutdown) {
        socketWrapper.destroyPull();
        return;
    }
    try {
        // Create buffer of recommended size and with default offset
        ByteBuffer buf = new ByteBuffer(incommingBufLength);
        if (verbose)
            System.out.println("[" + this + "] INFO: Reading data from stream.");
        // to unblock during reboot
        long startTime = System.currentTimeMillis();
        // FIXME: If pull is destroyed or socket is closed, segfault will happen here
        int actualLength = // Blocking read
        (block) ? Socket.recv(socket, buf.data, buf.offset, buf.data.length - buf.offset) : // Non-blocking read
        Socket.recvt(socket, buf.data, buf.offset, buf.data.length - buf.offset, 5000000);
        if (socketWrapper.shutdown) {
            socketWrapper.destroyPull();
            return;
        }
        long elapsedTime = System.currentTimeMillis() - startTime;
        if (actualLength < 0 || elapsedTime > 5000) {
            if (verbose)
                System.out.println("[" + this + "] INFO: End of stream or timeout");
            buf.unref();
            closeStream();
            sendEventToAllPads(Event.STREAM_CLOSE, Direction.OUT);
            return;
        }
        if (actualLength == 0) {
            if (verbose)
                System.out.println("[" + this + "] INFO: Empty buffer is read from stream.");
            buf.unref();
            return;
        }
        buf.length = actualLength;
        if (verbose)
            System.out.println("[" + this + "] INFO: Data read from stream: " + buf + ".");
        pushDataToAllOuts(buf);
    } catch (Exception e) {
        System.err.println("[" + this + "] ERROR: " + e.getMessage());
        closeStream();
    }
}
Also used : ByteBuffer(streamer.ByteBuffer)

Example 39 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class MockSink 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;
            numBuffers = bufs.length;
        }
    };
    Element mockSink = new MockSink("sink") {

        {
            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;
        }
    };
    Link link = new SyncLink() {

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

Example 40 with ByteBuffer

use of streamer.ByteBuffer in project cloudstack by apache.

the class RGB888LE32PixelFormatRequest method handleData.

@Override
public void handleData(ByteBuffer buf, Link link) {
    if (buf == null)
        return;
    if (verbose)
        System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
    buf.unref();
    ByteBuffer outBuf = new ByteBuffer(20);
    outBuf.writeByte(RfbConstants.CLIENT_SET_PIXEL_FORMAT);
    // Padding
    outBuf.writeByte(0);
    outBuf.writeByte(0);
    outBuf.writeByte(0);
    // Send pixel format
    outBuf.writeByte(bitsPerPixel);
    outBuf.writeByte(depth);
    outBuf.writeByte(bigEndianFlag);
    outBuf.writeByte(trueColourFlag);
    outBuf.writeShort(redMax);
    outBuf.writeShort(greenMax);
    outBuf.writeShort(blueMax);
    outBuf.writeByte(redShift);
    outBuf.writeByte(greenShift);
    outBuf.writeByte(blueShift);
    // Padding
    outBuf.writeByte(0);
    outBuf.writeByte(0);
    outBuf.writeByte(0);
    screen.setPixelFormat(bitsPerPixel, depth, bigEndianFlag != RfbConstants.LITTLE_ENDIAN, trueColourFlag == RfbConstants.TRUE_COLOR, redMax, greenMax, blueMax, redShift, greenShift, blueShift);
    pushDataToAllOuts(outBuf);
}
Also used : ByteBuffer(streamer.ByteBuffer)

Aggregations

ByteBuffer (streamer.ByteBuffer)110 Element (streamer.Element)12 BaseElement (streamer.BaseElement)9 Pipeline (streamer.Pipeline)7 PipelineImpl (streamer.PipelineImpl)7 TSRequest (rdpclient.ntlmssp.asn1.TSRequest)6 MockSink (streamer.debug.MockSink)5 MockSource (streamer.debug.MockSource)5 BitmapRectangle (common.BitmapRectangle)3 ScreenDescription (common.ScreenDescription)3 SyncLink (streamer.SyncLink)3 AssertingByteBuffer (streamer.debug.AssertingByteBuffer)3 BitmapOrder (common.BitmapOrder)2 KeyOrder (common.KeyOrder)2 MouseOrder (common.MouseOrder)2 NegoItem (rdpclient.ntlmssp.asn1.NegoItem)2 Link (streamer.Link)2 FakeSink (streamer.debug.FakeSink)2 BufferedImageCanvas (common.BufferedImageCanvas)1 CopyRectOrder (common.CopyRectOrder)1