Examples of Buffer


Examples of javax.media.Buffer

    @Override
    public void read(Buffer buffer) throws IOException
    {
        try
        {
            Buffer data = itsRTPBuffer.remove();
           
            if ((data != null) && (buffer != null))
            {
                buffer.setData(data.getData());
                buffer.setOffset(data.getOffset());
                buffer.setLength(data.getLength());
                buffer.setTimeStamp(data.getTimeStamp());
                buffer.setSequenceNumber(data.getSequenceNumber());
                buffer.setFlags(data.getFlags());
                buffer.setFormat(format);
   
                // mgodehardt: will measure thruput in bits per second for the BitRateControl
                // dont know if this the right place to measure the thruput
                long currentTimestamp = System.nanoTime();
                if ( -1 == lastTimestamp )
                {
                    lastTimestamp = currentTimestamp;
                }
               
                bytesProcessed += data.getLength();
               
                if ( (currentTimestamp - lastTimestamp) > 1000000000L )
                {
                    bitsPerSecond = bytesProcessed << 3;
                    bytesProcessed = 0;
View Full Code Here

Examples of javax.media.Buffer

          // underlying buffer, and queue it to ourself and all other cloned streams of the same
          // underlying stream (same stream index):
         
          if (bufferQueue.isEmpty())
          {
            final Buffer originalBuffer = new Buffer()// TODO: find a way to reuse buffers/avoid allocating new memory each time
            stream.read(originalBuffer);
            try
            {
              for (ClonedDataSource clone : clones)
              {
                final ClonedDataSource.ClonedPullBufferStream clonedStream = (ClonedDataSource.ClonedPullBufferStream) clone.getStreams()[streamIndex];
                clonedStream.getBufferQueue().put((Buffer) originalBuffer.clone());
              }
            }
            catch (InterruptedException e)
            {
              logger.log(Level.WARNING, "" + e, e);
              throw new InterruptedIOException();
            }
          }
        }
       
        Buffer nextBuffer = null;
        try
        {
          nextBuffer = (Buffer) bufferQueue.get();
        } catch (InterruptedException e)
        {
          throw new InterruptedIOException("" + e);
        }
        if (nextBuffer.isEOM())
          eos = true;
       
        buffer.copy(nextBuffer);
       
       
View Full Code Here

Examples of javax.media.Buffer

{
 
  public void testVideoCodec3()
  {
    MyVideoCodec c = new MyVideoCodec();
    Buffer b = new Buffer();
    VideoFormat f = new VideoFormat("xyz", new Dimension(1, 2), 1000, byte[].class, 2.f);
    c.doUpdateOutput(b, f, 3333, 44);
    assertTrue(b.getFormat() == f);
    assertTrue(b.getLength() == 3333);
    assertTrue(b.getOffset() == 44);
    assertFalse(b.isDiscard());
    assertFalse(b.isEOM());
   
    c.doUpdateOutput(b, null, 3335, 45);
    assertTrue(b.getFormat() == null);
    assertTrue(b.getLength() == 3335);
    assertTrue(b.getOffset() == 45);

   
   
  }
View Full Code Here

Examples of javax.media.Buffer

       
        final Link linkDest = n.getDestLink(i);
        if (linkDest != null)
        {  if (n.getOutputBuffer(i) == null)
            throw new NullPointerException("Buffer " + i + " is null, trackNumber=" + sourceTrackNumber + ", flags=" + flags);
          final Buffer b = n.getOutputBuffer(i);
          // TODO: what is the proper place to check for and/or propagate EOM/discard?
//          if (b.isEOM())
//            continue;
          if (b.isDiscard())
          { 
//            try
//            {
//              Thread.sleep(20);
//            } catch (InterruptedException e)
View Full Code Here

Examples of javax.media.Buffer

      if ((flags & FilterGraphProcessor.SUPPRESS_TRACK_READ) == 0)
      {
        // JMF re-uses the previous buffer
        if (getOutputBuffer(i) == null)
        {
          setOutputBuffer(i, new Buffer());
        }
        final Buffer buffer1 = getOutputBuffer(i);
        buffer1.setLength(0);
        buffer1.setSequenceNumber(sequenceNumber++); // TODO: 1 seq # per track is needed
        buffer1.setFlags(0)// clear all flags. TODO: does JMF do this?  Or must the demux itself clear the flags?
       
//        // It does not appear that JMF sets the timestamp to what it thinks it is going to be.
        // although this is theoretically possible knowing the frame/buffer # and the framerate.

        // according to the docs,  Each track has a sequence number that is updated by the Demultiplexer for each frame
        // however, the OggDemux does not do this, and it appears that JMF sets the sequence number before giving it to the demux.
//         TODO: other fields to clear?
       
       
        getTracks()[i].readFrame(buffer1);
        if (buffer1.getFormat() == null)
          buffer1.setFormat(getTracks()[i].getFormat())// TODO: is this right?  JMF appears to set the format in between demux track read adnd codec process.

      }

    }
   
View Full Code Here

Examples of javax.media.Buffer

  {
    final MyBasicPlugIn p = new MyBasicPlugIn();
   
    // test empty buffer:
    {
      final Buffer b = new Buffer();
      assertEquals(b.getData(), null);
      assertEquals(b.getLength(), 0);
      assertEquals(b.getOffset(), 0);
     
      for (int i = 0; i < 10; ++i)
      {
        final byte[] ba = p.doValidateByteArraySize(b, i);
        assertEquals(ba.length, i);
        for (int j = 0; j < i; ++j)
        {  assertEquals(ba[j], 0);
        }
        assertEquals(b.getData(), ba);
        assertEquals(b.getLength(), 0);
        assertEquals(b.getOffset(), 0);
      }
    }
   
    // buf of len 5 with length set to 5:
    {
      final Buffer b = new Buffer();
      final byte[] bBuf = new byte[5];
      b.setData(bBuf);
      b.setLength(bBuf.length);
      assertTrue(b.getData() == bBuf);
      assertEquals(b.getLength(), bBuf.length);
      assertEquals(b.getOffset(), 0);
     
      for (int i = 0; i < 10; ++i)
      {
        final byte[] ba = p.doValidateByteArraySize(b, i);
        if (i >  bBuf.length)
          assertTrue(ba != bBuf);
        else
          assertTrue(ba == bBuf);
        final int max = i > bBuf.length ? i : bBuf.length;
        assertEquals(ba.length, max);
        for (int j = 0; j < i; ++j)
        {  assertEquals(ba[j], 0);
        }
        assertEquals(b.getData(), ba);
        assertEquals(b.getLength(), bBuf.length);
        assertEquals(b.getOffset(), 0);
      }
    }
   
    // buf of len 5 with length set to 0:
    {
      final Buffer b = new Buffer();
      final byte[] bBuf = new byte[5];
      b.setData(bBuf);
      b.setLength(0);
      assertTrue(b.getData() == bBuf);
      assertEquals(b.getLength(), 0);
      assertEquals(b.getOffset(), 0);
     
      for (int i = 0; i < 10; ++i)
      {
        final byte[] ba = p.doValidateByteArraySize(b, i);
        if (i >  bBuf.length)
          assertTrue(ba != bBuf);
        else
          assertTrue(ba == bBuf);
        final int max = i > bBuf.length ? i : bBuf.length;
        assertEquals(ba.length, max);
        for (int j = 0; j < i; ++j)
        {  assertEquals(ba[j], 0);
        }
        assertEquals(b.getData(), ba);
        assertEquals(b.getLength(), 0);
        assertEquals(b.getOffset(), 0);
      }
    }
   
    // it appears that getLength/setLength has nothing to do with doValidateByteArraySize.
    // doValidateByteArraySize looks like it checks the size of the buf, and reallocates it
    // if too small.
   
    // try with a non-bytearray
    {
      final Buffer b = new Buffer();
      final int[] bBuf = new int[5];
      b.setData(bBuf);
      b.setLength(0);
      assertTrue(b.getData() == bBuf);
      assertEquals(b.getLength(), 0);
      assertEquals(b.getOffset(), 0);
     
      for (int i = 0; i < 10; ++i)
      {
        final byte[] ba = p.doValidateByteArraySize(b, i);
//        if (i >  bBuf.length)
//          assertTrue(ba != bBuf);
//        else
//          assertTrue(ba == bBuf);
        assertEquals(ba.length, i);
        for (int j = 0; j < i; ++j)
        {  assertEquals(ba[j], 0);
        }
        assertEquals(b.getData(), ba);
        assertEquals(b.getLength(), 0);
        assertEquals(b.getOffset(), 0);
      }
    }
   
    // appears to simply reallocate if not a byte array.
    // See if it copies existing data:
    {
      final Buffer b = new Buffer();
      final byte[] bBuf = new byte[] {0, 1, 2, 3, 4};
      b.setData(bBuf);
      b.setLength(0);
      assertTrue(b.getData() == bBuf);
      assertEquals(b.getLength(), 0);
      assertEquals(b.getOffset(), 0);
     
      for (int i = 0; i < 10; ++i)
      {
        final byte[] ba = p.doValidateByteArraySize(b, i);
        if (i >  bBuf.length)
          assertTrue(ba != bBuf);
        else
          assertTrue(ba == bBuf);
        final int max = i > bBuf.length ? i : bBuf.length;
        assertEquals(ba.length, max);
        for (int j = 0; j < i; ++j)
        { 
          if (j < bBuf.length)
            assertEquals(ba[j], bBuf[j]);
          else
            assertEquals(ba[j], 0);
        }
        assertEquals(b.getData(), ba);
        assertEquals(b.getLength(), 0);
        assertEquals(b.getOffset(), 0);
      }
    }
   
    // it does copy existing data.
View Full Code Here

Examples of net.rootnode.loomchild.util.collections.Buffer

   */
  public ReaderCharSequence(Reader reader, int length, int bufferSize,
      int lookahead) {
    this.reader = reader;
    this.lookahead = lookahead;
    this.buffer = new Buffer(bufferSize);
    this.position = 0;
    this.length = length;
    fillBuffer(-1);
  }
View Full Code Here

Examples of net.sf.cindy.Buffer

    public void testGetAndPut() {
        for (int i = 0; i < 10; i++) {
            byte[] b = new byte[random.nextInt(1000) + 100];
            random.nextBytes(b);

            Buffer buffer = newBuffer(b.length);
            buffer.put(b);
            assertEquals(b.length, buffer.position());
            buffer.flip();
            assertEquals(0, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.capacity());
            assertEquals(b.length, buffer.remaining());
            assertTrue(buffer.hasRemaining());
            assertEquals(buffer.asByteBuffer(), ByteBuffer.wrap(b));

            random.nextBytes(b);
            buffer.put(ByteBuffer.wrap(b));
            assertEquals(b.length, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.capacity());
            assertEquals(0, buffer.remaining());
            assertFalse(buffer.hasRemaining());
            buffer.flip();
            assertEquals(buffer.asByteBuffer(), ByteBuffer.wrap(b));
            assertEquals(0, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.remaining());
            assertEquals(b.length, buffer.capacity());
            assertTrue(buffer.hasRemaining());

            Buffer b1 = newBuffer(b.length);
            random.nextBytes(b);
            b1.put(0, b);
            buffer.put(b1);
            assertEquals(b.length, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.capacity());
            assertEquals(0, buffer.remaining());
            assertFalse(buffer.hasRemaining());
            buffer.flip();
            assertEquals(buffer.asByteBuffer(), ByteBuffer.wrap(b));
            assertEquals(0, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.remaining());
            assertEquals(b.length, buffer.capacity());
            assertTrue(buffer.hasRemaining());

            ByteBuffer b2 = ByteBuffer.wrap(b);
            for (int j = 0; j < 100; j++) {
                int index = Math.max(0, random.nextInt(b.length) - 8);
                assertEquals(buffer.get(index), b2.get(index));
                assertEquals(buffer.getShort(index), b2.getShort(index));
                assertEquals(buffer.getChar(index), b2.getChar(index));
                assertEquals(buffer.getInt(index), b2.getInt(index));
                assertEquals(buffer.getLong(index), b2.getLong(index));
                assertEquals(new Float(buffer.getFloat(index)), new Float(b2
                        .getFloat(index)));
                assertEquals(new Double(buffer.getDouble(index)), new Double(b2
                        .getDouble(index)));
            }

            while (buffer.hasRemaining()) {
                assertEquals(b2.get(), buffer.get());
            }
            assertFalse(buffer.hasRemaining());
            assertEquals(b.length, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(0, buffer.remaining());

            buffer.clear();
            assertEquals(0, buffer.position());
            assertEquals(b.length, buffer.limit());
            assertEquals(b.length, buffer.remaining());

            for (int j = 0; j < b.length; j++) {
                buffer.put(b[j]);
                assertEquals(j + 1, buffer.position());
                assertEquals(b.length, buffer.limit());
                assertEquals(b.length - j - 1, buffer.remaining());
            }

            for (int j = 0; j < 100; j++) {
                int index = Math.max(0, random.nextInt(b.length) - 8);
                short s = (short) random.nextInt();
                buffer.putShort(index, s);
                assertEquals(buffer.getShort(index), s);
                int in = random.nextInt();
                buffer.putInt(index, in);
                assertEquals(buffer.getInt(index), in);
                long l = random.nextLong();
                buffer.putLong(index, l);
                assertEquals(buffer.getLong(index), l);
                float f = random.nextFloat();
                buffer.putFloat(index, f);
                assertEquals(new Float(buffer.getFloat(index)), new Float(f));
                double d = random.nextDouble();
                buffer.putDouble(index, d);
                assertEquals(new Double(buffer.getDouble(index)), new Double(d));
            }
        }

        Buffer buffer = newBuffer(256);
        for (int i = 0; i < 256; i++) {
            buffer.put((byte) i);
        }
        buffer.flip();
        for (int i = 0; i < 5; i++) {
            byte[] b = new byte[random.nextInt(buffer.capacity())];
            int start = random.nextInt(buffer.capacity() - b.length);
            buffer.get(start, b);
            for (int j = 0; j < b.length; j++) {
                assertEquals(b[j], (byte) (start + j));
            }
        }
        for (int i = 0; i < 5; i++) {
            buffer.clear();
            byte[] b = new byte[random.nextInt(buffer.capacity())];
            int start = random.nextInt(buffer.capacity() - b.length);
            buffer.position(start);
            buffer.get(b);
            assertEquals(buffer.position(), start + b.length);
            for (int j = 0; j < b.length; j++) {
                assertEquals(b[j], (byte) (start + j));
            }
        }
    }
View Full Code Here

Examples of net.tomp2p.message.Buffer

   
    PeerAddress receiver = UtilsNAT.createAddress();
    message.recipient(receiver);
    message.recipientSocket(receiver.createSocketTCP());
   
    Buffer encoded = RelayUtils.encodeMessage(message, signature);
    Message decoded = RelayUtils.decodeMessage(encoded, message.recipientSocket(), message.senderSocket(), signature);
    Assert.assertEquals(message.peerSocketAddresses().size(), decoded.peerSocketAddresses().size());
  }
View Full Code Here

Examples of org.apache.activemq.protobuf.Buffer

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oout = new ObjectOutputStream(baos);
        oout.writeObject(metadata.producerSequenceIdTracker);
        oout.flush();
        oout.close();
        return store(new KahaProducerAuditCommand().setAudit(new Buffer(baos.toByteArray())));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.