Package javax.media

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


      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

  {
    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

  {
    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 short[] ba = p.doValidateShortArraySize(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 short[] bBuf = new short[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 short[] ba = p.doValidateShortArraySize(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 short[] bBuf = new short[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 short[] ba = p.doValidateShortArraySize(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 doValidateShortArraySize.
    // doValidateShortArraySize looks like it checks the size of the buf, and reallocates it
    // if too small.
   
    // try with a non-shortarray
    {
      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 short[] ba = p.doValidateShortArraySize(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 short array.
    // See if it copies existing data:
    {
      final Buffer b = new Buffer();
      final short[] bBuf = new short[] {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 short[] ba = p.doValidateShortArraySize(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

        if ( null == firstItem )
        {
            wait();
        }
       
        Buffer aBuffer = null;
       
        RTPBuffer aRTPBuffer = firstItem;
       
        firstItem = lastItem = null;
        itemCount = 0;
View Full Code Here

            if ( null != firstItem )
            {
                firstItem.previousBuffer = null;
            }
           
            Buffer aBuffer = aRTPBuffer.buffer;
           
            aRTPBuffer.nextBuffer = null;
            aRTPBuffer.previousBuffer = null;
            aRTPBuffer.buffer = null;
           
            itemCount--;
            duration -= aBuffer.getDuration();
           
            return aBuffer;
        }
       
        return null;
View Full Code Here

   
      this.stream = stream;
      // set format
     
      // read first frame to determine format
      final Buffer buffer = new Buffer();
      readFrame(buffer);
      if (buffer.isDiscard() || buffer.isEOM())
        throw new ResourceUnavailableException("Unable to read first frame");
      // TODO: catch runtime exception too?
     
      // parse jpeg
      final java.awt.Image image;
      try
      {
        image = ImageIO.read(new ByteArrayInputStream((byte []) buffer.getData(), buffer.getOffset(), buffer.getLength()));
      } catch (IOException e)
      {
        logger.log(Level.WARNING, "" + e, e);
        throw new ResourceUnavailableException("Error reading image: " + e);
      }
View Full Code Here

      this.streamIndex = streamIndex;
    }

    public void transferData(PushSourceStream stream)
    {
      final Buffer originalBuffer = new Buffer()// TODO: find a way to reuse buffers/avoid allocating new memory each time
     
      try
      {
        final byte[] originalBufferData = new byte[READ_BUFFER_SIZE];
        originalBuffer.setData(originalBufferData);
        int numRead = stream.read(originalBufferData, 0, originalBufferData.length);
        if (numRead < 0)
          originalBuffer.setEOM(true);
        else
          originalBuffer.setLength(numRead);       
      } catch (IOException e)
      {
        originalBuffer.setEOM(true)// TODO
        originalBuffer.setDiscard(true)// TODO
        originalBuffer.setLength(0);
        if (!(e instanceof InterruptedIOException))  // logging interruptions is noisy.
          logger.log(Level.WARNING, "" + e, e);
      }
     
      final List<ClonedDataSource.ClonedPushSourceStream> clonedStreams = new ArrayList<ClonedDataSource.ClonedPushSourceStream>();
      synchronized (CloneablePushDataSource.this)
      {
        for (ClonedDataSource clone : clones)
        {
          final ClonedDataSource.ClonedPushSourceStream clonedStream = (ClonedDataSource.ClonedPushSourceStream) clone.getStreams()[streamIndex];
          clonedStreams.add(clonedStream);
         
        }
      }
     
      // TODO: additional synchronization?
      try
      {
        // put a clone of the buffer in each stream's buffer queue
        for (ClonedDataSource.ClonedPushSourceStream clonedStream : clonedStreams)
        {
          clonedStream.getBufferQueue().put(originalBuffer.clone());
         
        }
       
        // notify their transfer handlers asynchronously:
        for (ClonedDataSource.ClonedPushSourceStream clonedStream : clonedStreams)
View Full Code Here

   
   
    @Override
    public void readFrame(Buffer buffer)
    {
      Buffer b;
      try
      {
        b = xmlMovieSAXHandler.readBuffer(track);
      } catch (SAXException e)
      {
View Full Code Here

      input.setFormat(getInputFormat())// TODO: is this right?  JMF appears to set the format in between demux track read adnd codec process.
   
    // JMF re-uses the previous buffer
    if (getOutputBuffer(0) == null)
    {
      setOutputBuffer(0, new Buffer());
    }
   
    final Buffer buffer1 = getOutputBuffer(0);
    buffer1.setLength(0);
    buffer1.setTimeStamp(input.getTimeStamp())// TODO: is this correct?
    buffer1.setFlags(input.getFlags())// mgodehardt: this was missing, TODO: propagate EOM or anything else?
//    TODO: other fields to set/clear? these determined empirically
//     Seems like setting the format is a good idea.  At least some codecs (like com.sun.media.codec.audio.ulaw.DePacketizer) do not
//    appear to set the format of their output buffer.
    if (buffer1.getFormat() == null)
      buffer1.setFormat(getDestLink(0).getDestNode().getInputFormat());
//    if (buffer1.getFormat() == null)
//      System.out.println("FORMAT NULL EVEN AFTER SET!!!!");
      //      throw new NullPointerException();
    buffer1.setSequenceNumber(input.getSequenceNumber())// TODO: is this right?  JMF appears to be setting the sequence numbers, not the codec
    // the one thing that is wierd about the sequence numbers, is that in the case of something like a packetizers, all of the packets derived from
    // a single source buffer will have the same sequence number.
   

   
View Full Code Here

TOP

Related Classes of javax.media.Buffer

Copyright © 2018 www.massapicom. 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.