Package com.xuggle.ferry

Examples of com.xuggle.ferry.IBuffer


    coder.setHeight(288);
    coder.setPixelType(IPixelFormat.Type.YUV420P);
    coder.setTimeBase(IRational.make(1,90000));
    coder.open();
   
    IBuffer buffer = IBuffer.make(null, 4192);
    int len = container.createSDPData(buffer);
    assertTrue(len > 1);
    byte[] stringBuf = new byte[len-1];
    buffer.get(0, stringBuf, 0, stringBuf.length);
    String sdp = new String(stringBuf);
    assertNotNull(sdp);
    log.debug("SDP({}) = {}", sdp.length(), sdp);
   
    String otherSdp = container.createSDPData();
View Full Code Here


    {
      throw new IllegalArgumentException("incorrect number of samples to generate");
    }
   
    // we're going to access the raw data..
    IBuffer buf = samples.getData();
    if (buf == null)
      throw new RuntimeException("could not get IBuffer from samples");
   
    ByteBuffer data = buf.getByteBuffer(0, buf.getBufferSize());
    if (data == null)
      throw new RuntimeException("could not get raw data from samples");
    // clear out all the old data
    data.clear();
  
View Full Code Here

   
    if (frame != null)
    {
      AtomicReference<JNIReference> ref = new AtomicReference<JNIReference>(
          null);
      IBuffer data = null;
      try
      {
        data = frame.getData();
        int bufSize = frame.getSize();
        java.nio.ByteBuffer buffer = data.getByteBuffer(0, bufSize, ref);
        if (buffer != null)
        {
          // we have the raw data; now we set it to the specified YUV value.
          int lineLength = 0;
          int offset = 0;

          // first let's check the L
          offset = 0;
          lineLength = frame.getDataLineSize(0);
          int sliceLen = lineLength * h;
          for (int i = offset; i < offset + sliceLen; i++)
          {
            int x = (i - offset) % lineLength;
            int y = (i - offset) / lineLength;
            if (crossHatchH > 0
                && crossHatchW > 0
                && (((x / crossHatchW) % 2 == 1 && (y / crossHatchH) % 2 == 0) || ((x / crossHatchW) % 2 == 0 && (y / crossHatchH) % 2 == 1)))
              buffer.put(i, (byte) crossHatchYColor);
            else
              buffer.put(i, (byte) yColor);
          }

          // now, check the U value
          offset = (frame.getDataLineSize(0) * h);
          lineLength = frame.getDataLineSize(1);
          sliceLen = lineLength * ((h + 1) / 2);
          for (int i = offset; i < offset + sliceLen; i++)
          {
            if (crossHatchH > 0 && crossHatchW > 0)
            {
              // put x and y in bottom right of pixel range
              int x = ((i - offset) % lineLength) * 2;
              int y = ((i - offset) / lineLength) * 2;

              int[] xCoords = new int[]
              {
                  x, x + 1, x, x + 1
              };
              int[] yCoords = new int[]
              {
                  y, y, y + 1, y + 1
              };
              int finalColor = 0;
              for (int j = 0; j < xCoords.length; j++)
              {
                int color = uColor;
                x = xCoords[j];
                y = yCoords[j];
                if (((x / crossHatchW) % 2 == 1 && (y / crossHatchH) % 2 == 0)
                    || ((x / crossHatchW) % 2 == 0 && (y / crossHatchH) % 2 == 1))
                {
                  color = crossHatchUColor;
                }
                finalColor += color;
              }
              finalColor /= xCoords.length;
              buffer.put(i, (byte) finalColor);
            }
            else
              buffer.put(i, (byte) uColor);
          }

          // and finally the V
          offset = (frame.getDataLineSize(0) * h)
              + (frame.getDataLineSize(1) * ((h + 1) / 2));
          lineLength = frame.getDataLineSize(2);
          sliceLen = lineLength * ((h + 1) / 2);
          for (int i = offset; i < offset + sliceLen; i++)
          {
            if (crossHatchH > 0 && crossHatchW > 0)
            {
              // put x and y in bottom right of pixel range
              int x = ((i - offset) % lineLength) * 2;
              int y = ((i - offset) / lineLength) * 2;

              int[] xCoords = new int[]
              {
                  x, x + 1, x, x + 1
              };
              int[] yCoords = new int[]
              {
                  y, y, y + 1, y + 1
              };
              int finalColor = 0;
              for (int j = 0; j < xCoords.length; j++)
              {
                int color = vColor;
                x = xCoords[j];
                y = yCoords[j];
                if (((x / crossHatchW) % 2 == 1 && (y / crossHatchH) % 2 == 0)
                    || ((x / crossHatchW) % 2 == 0 && (y / crossHatchH) % 2 == 1))
                  color = crossHatchVColor;
                finalColor += color;
              }
              finalColor /= xCoords.length;
              buffer.put(i, (byte) finalColor);
            }
            else
              buffer.put(i, (byte) vColor);
          }
        }
        // set it complete
        frame.setComplete(true, IPixelFormat.Type.YUV420P, w, h, pts);
      }
      finally
      {
        if (data != null)
          data.delete();
        if (ref.get() != null)
          ref.get().delete();
      }

    }
View Full Code Here

    coder.setHeight(288);
    coder.setPixelType(IPixelFormat.Type.YUV420P);
    coder.setTimeBase(IRational.make(1,90000));
    coder.open(null, null);
   
    IBuffer buffer = IBuffer.make(null, 4192);
    int len = container.createSDPData(buffer);
    assertTrue(len > 1);
    byte[] stringBuf = new byte[len-1];
    buffer.get(0, stringBuf, 0, stringBuf.length);
    String sdp = new String(stringBuf);
    assertNotNull(sdp);
    log.debug("SDP({}) = {}", sdp.length(), sdp);
   
    String otherSdp = container.createSDPData();
View Full Code Here

    assertTrue("is complete", frame.isComplete());
    assertTrue("correct pts", frame.getPts() == pts);

    // now, loop through the array and ensure it is set
    // correctly.
    IBuffer data = frame.getData();
    java.nio.ByteBuffer buffer = data.getByteBuffer(0, data.getBufferSize());
    assertNotNull(buffer);
    // we have the raw data; now we set it to the specified YUV value.
    int lineLength = 0;
    int offset = 0;
View Full Code Here

    // Let's add some fake data
    byte[] fakeData = new byte[64*576];
    for(int i = 0; i < fakeData.length; i++)
      fakeData[i] = (byte)i; // garbage
   
    IBuffer buffer = IBuffer.make(null, fakeData, 0, fakeData.length);
    IAudioSamples samples = IAudioSamples.make(buffer,
        coder.getChannels(), coder.getSampleFormat());
    samples.setComplete(true,
        fakeData.length/2, coder.getSampleRate(),
        coder.getChannels(), coder.getSampleFormat(), 0);
View Full Code Here

    int bufSize = 100;
    byte[] inData = new byte[bufSize];
    byte[] outData = new byte[inData.length];
    for(int i = 0; i < inData.length; i++)
      inData[i] = (byte) i;
    IBuffer buffer = IBuffer.make(null, inData, 0, inData.length);
    IAudioSamples samples = IAudioSamples.make(1024,2);
    samples.setData(buffer);
   
    IBuffer outBuffer = samples.getData();
    outBuffer.get(0, outData, 0, outData.length);
    for(int i = 0; i < inData.length; i++)
      assertEquals(inData[i], outData[i]);
    outBuffer.delete();
   
    samples.toString();
    IVideoPicture picture = IVideoPicture.make(IPixelFormat.Type.YUV420P,
        4,4);
    picture.setData(buffer);

    outBuffer = picture.getData();
    outBuffer.get(0, outData, 0, outData.length);
    for(int i = 0; i < inData.length; i++)
      assertEquals(inData[i], outData[i]);
    outBuffer.delete();
   
    IPacket packet = IPacket.make(1024);
    packet.setData(buffer);
   
    outBuffer = packet.getData();
    outBuffer.get(0, outData, 0, outData.length);
    for(int i = 0; i < inData.length; i++)
      assertEquals(inData[i], outData[i]);
    outBuffer.delete();
   
   
    packet.delete();
    samples.delete();
    picture.delete();
View Full Code Here

  {
    // free up any references from other tests
    JNIMemoryManager.getMgr().flush();
    byte[] in = new byte[]{ 0x38, 0x2C, 0x18, 0x7F };
    byte[] out = new byte[in.length];
    IBuffer buf = IBuffer.make(null, 1024);
    buf.put(in, 0, 0, in.length);
    buf.get(0, out, 0, in.length);
    for(int i = 0; i < in.length; i++)
      assertEquals("mismatched bytes at " + i,
          in[i], out[i]);
    buf.delete();
    assertEquals("more objects around than expected",
        0, JNIMemoryManager.getMgr().getNumPinnedObjects());
  }
View Full Code Here

  {
    // free up any references from other tests
    JNIMemoryManager.getMgr().flush();
    short[] in = new short[]{ 0x38, 0x2C, 0x18, 0x7F };
    short[] out = new short[in.length];
    IBuffer buf = IBuffer.make(null, 1024);
    buf.put(in, 0, 0, in.length);
    buf.get(0, out, 0, in.length);
    for(int i = 0; i < in.length; i++)
      assertEquals("mismatched bytes at " + i,
          in[i], out[i]);
    buf.delete();
    assertEquals("more objects around than expected",
        0, JNIMemoryManager.getMgr().getNumPinnedObjects());
  }
View Full Code Here

  {
    // free up any references from other tests
    JNIMemoryManager.getMgr().flush();
    int[] in = new int[]{ 0x38, 0x2C, 0x18, 0x7F };
    int[] out = new int[in.length];
    IBuffer buf = IBuffer.make(null, 1024);
    buf.put(in, 0, 0, in.length);
    buf.get(0, out, 0, in.length);
    for(int i = 0; i < in.length; i++)
      assertEquals("mismatched bytes at " + i,
          in[i], out[i]);
    buf.delete();
    assertEquals("more objects around than expected",
        0, JNIMemoryManager.getMgr().getNumPinnedObjects());
  }
View Full Code Here

TOP

Related Classes of com.xuggle.ferry.IBuffer

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.