Examples of Buffer


Examples of javax.media.Buffer

          td.decodeYUVout(yuv);

          final BufferedImage bi = YUVConverter.toBufferedImage(yuv, ti);

          final Buffer b = ImageToBuffer.createBuffer(bi, format.getFrameRate());

          buffer.setData(b.getData());
          buffer.setLength(b.getLength());
          buffer.setOffset(b.getOffset());
          buffer.setEOM(false);
          buffer.setDiscard(false);
          buffer.setTimeStamp((long) secondsToNanos(videobuf_time));

          //System.out.println("Generated video buffer");
View Full Code Here

Examples of javax.media.Buffer

        }
      }

      public void read(Buffer buffer) throws IOException
      {
        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

            assembler.put((Buffer)input.clone());
            ///dump(input, "Input");

            if ( assembler.complete() )
            {
                Buffer bComplete = baselineCodec == null ? output : new Buffer();
                final int offsetAfterHeaders = assembler.copyToBuffer(bComplete);
               
                frameAssemblers.remove(timestamp);
                frameAssemblers.removeOlderThan(timestamp);    // we have a complete frame, so any earlier fragments are not needed, as they are for older (incomplete) frames.
               
                if (TRACE)
                {
                    System.out.println("COMPLETE: ts=" + timestamp + " bComplete.getLength()=" + bComplete.getLength());
                }
               
                if ( lastRTPtimestamp == -1 )
                {
                    lastRTPtimestamp = input.getTimeStamp();
View Full Code Here

Examples of javax.media.Buffer

         */
        private boolean contiguous() {
            int expect = 0;    // next expected offset.

            for (int i = 0; i < list.size(); ++i) {
                final Buffer b = (Buffer) list.get(i);
                final JpegRTPHeader jpegRtpHeader = parseJpegRTPHeader(b);
                int otherOffset = 0;
                if (jpegRtpHeader.getType()>63) otherOffset += 4;
                if (jpegRtpHeader.getQ()>=128) {
                    int length = 0;
                    int j = b.getOffset() + JpegRTPHeader.HEADER_SIZE + otherOffset + 2; //the size of the offset to the length of custom tables
                    byte[] data = (byte[]) b.getData();
                    length = data[j++] & 0xFF;
                    length <<= 8;
                    length |= data[j] & 0xFF;
                    length += 4; //add 4 bytes that are not included in the length of custom qtables
                    otherOffset += length;
                }
                if (jpegRtpHeader.getFragmentOffset() != expect)
                    return false;
                expect += b.getLength() - JpegRTPHeader.HEADER_SIZE - otherOffset;

            }
            return true;
        }
View Full Code Here

Examples of javax.media.Buffer

                throw new IllegalStateException();
            if (list.size() <= 0)
                throw new IllegalStateException();

            // calculate from offset and length of last buffer:
            final Buffer b = (Buffer) list.get(list.size() - 1);
            final JpegRTPHeader jpegRtpHeader = parseJpegRTPHeader(b);
            // Observed: the frame with the marker has valid offset,
            return jpegRtpHeader.getFragmentOffset() + b.getLength() - JpegRTPHeader.HEADER_SIZE;

        }
View Full Code Here

Examples of javax.media.Buffer

                throw new IllegalStateException();

            // TODO: perhaps what we should do is copy the header if there is not one.
            // The test samples coming from JMStudio had headers in them, so the JPEG could not be
            // parsed if (another) header was prepended.
            final Buffer bFirst = (Buffer) list.get(0);
            final boolean prependHeader = !hasJPEGHeaders((byte[]) bFirst.getData(), bFirst.getOffset() + JpegRTPHeader.HEADER_SIZE, bFirst.getLength() - JpegRTPHeader.HEADER_SIZE);
            final int MAX_HEADER = prependHeader ? 1024 : 0;    // TODO: what is actual max size for the header?  Seems to be fixed size, 600-700 bytes.
            final int MAX_TRAILER = 2;
            final int frameLength = frameLength();
            final byte[] data;
            int inputOffset = bFirst.getOffset();
            int dri = 0;
            byte[] lqt = null;
            byte[] cqt = null;
            byte[] inputData = (byte[]) bFirst.getData();
            if (bDest.getData() != null && ((byte[]) bDest.getData()).length >= (frameLength + MAX_HEADER + MAX_TRAILER)) {
                data = (byte[]) bDest.getData();    // reuse existing byte array
                // zero out:
                zeroData(data);

            } else {
                data = new byte[frameLength + MAX_HEADER + MAX_TRAILER];    // allocate new one - existing one not there or too short
            }
//            System.out.println(Arrays.toString(inputData));
//            System.out.println("Offset:"+inputOffset);

            /*System.out.println("InputData");
            for (byte b:inputData){
                String s = Integer.toHexString(b&0xFF);
                System.out.print((s.length()<2?"0"+s:s)+"-");
            }
            System.out.println("");*/
           
            int offsetAfterHeaders = 0;
            if (prependHeader) {
                // put initial SOI marker manually, we tell RFC2035.MakeHeaders not to do it:
                data[offsetAfterHeaders++] = (byte) 0xff;
                data[offsetAfterHeaders++] = (byte) 0xd8;

                // part of the header with "JFIF" in it, not generated by the code in RFC2035.
                offsetAfterHeaders = buildJFIFHeader(data, offsetAfterHeaders);

                final JpegRTPHeader jpegRtpHeaderFirst = parseJpegRTPHeader(bFirst);
                inputOffset += JpegRTPHeader.HEADER_SIZE;

                if (jpegRtpHeaderFirst.getType() >= 64 && jpegRtpHeaderFirst.getType() <= 127) { //For types 64-127 there has to be restart header

                    dri = inputData[inputOffset++] & 0xFF;
                    dri <<= 8;
                    dri |= inputData[inputOffset++] & 0xFF;
                    inputOffset += 2; //skip rest of the Restart Marker header (2 bytes)
                }
                if (jpegRtpHeaderFirst.getQ() > 127) {
                    inputOffset += 2; //skip MBZ and Precision fields
                    int length = inputData[inputOffset++] & 0xFF;
                    length <<= 8;
                    length |= inputData[inputOffset++] & 0xFF;
                    //Most usual qtable size is 64 bytes, so length is usually 128, for other sizes we would put half to lqt and second half to cqt..

                    // lqt = Arrays.copyOfRange(inputData, inputOffset, inputOffset + length / 2); //Java6 only code
                    lqt = ArrayUtility.copyOfRange(inputData, inputOffset, inputOffset + length /2);
                    inputOffset += length / 2; //TODO what if the length is odd?
                    // (It should not happen though)
                    //cqt = Arrays.copyOfRange(inputData, inputOffset, inputOffset+ length / 2); //Java6 only code
                    cqt = ArrayUtility.copyOfRange(inputData, inputOffset, inputOffset + length /2);
                    inputOffset += length / 2;
                }
                //TODO add special handling if q>128, but first we should handle Reset Header
                offsetAfterHeaders = RFC2035.MakeHeaders(false, data, offsetAfterHeaders, jpegRtpHeaderFirst.getType(), jpegRtpHeaderFirst.getQ(), jpegRtpHeaderFirst.getWidthInBlocks(), jpegRtpHeaderFirst.getHeightInBlocks(), lqt, cqt, dri);

                /*System.out.println("OutputData");
              for (byte b:data){
                  String s = Integer.toHexString(b&0xFF);
                  System.out.print((s.length()<2?"0"+s:s)+"-");
              }
              System.out.println("");*/
            }
            if (TRACE) System.out.println("offsetAfterHeaders=" + offsetAfterHeaders);
            for (int i = 0; i < list.size(); ++i) {
                final Buffer b = (Buffer) list.get(i);
                final JpegRTPHeader jpegRtpHeader = parseJpegRTPHeader(b);

//        if (TRACE) System.out.println("Copying, length=" + (b.getLength() - JpegRTPHeader.HEADER_SIZE) + ":");
//        if (TRACE) System.out.println(dump((byte[]) b.getData(), b.getOffset() + JpegRTPHeader.HEADER_SIZE, (b.getLength() - JpegRTPHeader.HEADER_SIZE) > MAX_DUMP_SIZE ? MAX_DUMP_SIZE : (b.getLength() - JpegRTPHeader.HEADER_SIZE)));
//        if (TRACE) System.out.println("End copying.");

                System.arraycopy(b.getData(), b.getOffset() + JpegRTPHeader.HEADER_SIZE, data, offsetAfterHeaders + jpegRtpHeader.getFragmentOffset(), b.getLength() - JpegRTPHeader.HEADER_SIZE);
            }

            final boolean appendEOI = !hasJPEGTrailer(data, offsetAfterHeaders + frameLength, MAX_TRAILER);    // no need to append if it is already there.
            int trailing = 0;
            if (appendEOI) {
View Full Code Here

Examples of javax.media.Buffer

      final int result = filterGraph.process(null, trackNumber, -1, flags);
      if ((result & PlugIn.BUFFER_PROCESSED_FAILED) != 0)
      {  throw new RuntimeException("BUFFER_PROCESSED_FAILED")// TODO: what is the right thing to do?
      }
     
      final Buffer b = filterGraph.getRoot().getOutputBuffer(trackNumber);
      if (b == null)
        throw new NullPointerException();
      return b;
     
    }
View Full Code Here

Examples of javax.media.Buffer

              flags = firstFlags;  // if firstFlags == FilterGraph.SUPPRESS_TRACK_READ, first frame has already been read, only needs redisplay
            else if (inputEOM)
              flags = FilterGraph.SUPPRESS_TRACK_READ;
            else
              flags = FilterGraph.PROCESS_DEFAULT;
            Buffer b = readAndProcessNextFrame(flags);
            if (isClosing())
              return;
            if (first)
            {  first = false;
            }
            if (b.isEOM())
              inputEOM = true// we continue processing, however, until the final buffer in the chain gets EOM.
                        // this is needed to handle the case where there is residual data in the codecs.
                        //TODO: how close is this to what JMF does?  How does JMF handle this?
                        // if we don't do this, the effect is that codecs that are not 1:1 in terms of buffers will have any
                        // data buffered up in the codecs cut off. 
           
            if (b.isDiscard())
              continue;
           

           
            if (!(penultimateNode instanceof RendererNode) && !(penultimateNode instanceof MuxNode))
            {
              // we need to sleep based on the time in the processed data, not the input data. 
              // if the graph goes demux->renderer, then the output buffer of the demux,
              // which is set to b above, is what we use to check.
              b = penultimateNode.getOutputBuffer(0);
              // TODO: this can cause a NPE below if b is null (not sure how it could be null)
 
              if (b == null)
                continue// this can be null if it has not been set yet, if codecs earlier in the chain have been
                      // returning INPUT_BUFFER_NOT_CONSUMED or OUTPUT_BUFFER_NOT_FILLED.
            }
           
            if (b.isEOM())  // TODO: is there data in an eom buffer?
              break;
            if (b.isDiscard())
              continue;
           
                  //  Update the video time
                  nanoseconds = b.getTimeStamp();
          }
         
          eom = true;
          checkAllTracksEOM();
        }
View Full Code Here

Examples of javax.media.Buffer

    {
      // TODO: this is very inefficient - it allocates a new byte array (or more) every time
      final ByteArrayInputStream is = new ByteArrayInputStream((byte[]) input.getData(), input.getOffset(), input.getLength());
      final BufferedImage image = ImageIO.read(is);
      is.close();
      final Buffer b = ImageToBuffer.createBuffer(image, ((VideoFormat) outputFormat).getFrameRate());
     
      output.setData(b.getData());
      output.setOffset(b.getOffset());
      output.setLength(b.getLength());
      output.setFormat(b.getFormat())// TODO: this is a bit hacky, this format will be more specific than the actual set output format, because now we know what ImageIO gave us for a BufferedImage as far as pixel masks, etc.
     
      return BUFFER_PROCESSED_OK;

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