Example usage for java.nio ByteBuffer get

List of usage examples for java.nio ByteBuffer get

Introduction

In this page you can find the example usage for java.nio ByteBuffer get.

Prototype

public abstract byte get(int index);

Source Link

Document

Returns the byte at the specified index and does not change the position.

Usage

From source file:Main.java

public static int[] getAsIntArray(ByteBuffer yuv, int size) {
    byte[] b = new byte[size];
    int[] result = new int[size];
    yuv.get(b);
    for (int i = 0; i < b.length; i++) {
        result[i] = b[i] & 0xff;/* w  w w  . ja v  a  2  s .com*/
    }
    return result;
}

From source file:Main.java

/**
 * Like {@link #parseEAc3SyncframeAudioSampleCount(byte[])} but reads from a byte buffer. The
 * buffer position is not modified.//from ww  w .j av a  2  s .  c  o m
 *
 * @see #parseEAc3SyncframeAudioSampleCount(byte[])
 */
public static int parseEAc3SyncframeAudioSampleCount(ByteBuffer buffer) {
    // See ETSI TS 102 366 subsection E.1.2.2.
    int fscod = (buffer.get(buffer.position() + 4) & 0xC0) >> 6;
    return AUDIO_SAMPLES_PER_AUDIO_BLOCK * (fscod == 0x03 ? 6
            : BLOCKS_PER_SYNCFRAME_BY_NUMBLKSCOD[(buffer.get(buffer.position() + 4) & 0x30) >> 4]);
}

From source file:Main.java

private static byte[] getByteArrayFromBuffer(ByteBuffer byteBuf) {
    byteBuf.flip();/*from  w  w  w.j av  a 2 s .com*/
    byte[] row = new byte[byteBuf.limit()];
    byteBuf.get(row);
    byteBuf.clear();
    return row;
}

From source file:Main.java

public static byte[] array(ByteBuffer byteBuffer) {
    ByteBuffer byteBuffer2 = byteBuffer.duplicate();
    byte[] arrby = new byte[byteBuffer2.limit()];
    byteBuffer2.rewind();/*w w  w  .  j a  v  a2 s  .com*/
    byteBuffer2.get(arrby);
    return arrby;
}

From source file:Main.java

/**
 * Reads the number of audio samples represented by a TrueHD syncframe. The buffer's position is
 * not modified.// www. ja va2  s  . c  o m
 *
 * @param buffer The {@link ByteBuffer} from which to read the syncframe.
 * @param offset The offset of the start of the syncframe relative to the buffer's position.
 * @return The number of audio samples represented by the syncframe.
 */
public static int parseTrueHdSyncframeAudioSampleCount(ByteBuffer buffer, int offset) {
    // TODO: Link to specification if available.
    boolean isMlp = (buffer.get(buffer.position() + offset + 7) & 0xFF) == 0xBB;
    return 40 << ((buffer.get(buffer.position() + offset + (isMlp ? 9 : 8)) >> 4) & 0x07);
}

From source file:Main.java

static void toArray(ByteBuffer src, boolean[] dst, int offset) {
    for (int i = 0; i < dst.length - offset; i++) {
        dst[i + offset] = src.get(i) != 0;
    }//from  w ww.  j a v  a 2 s.  c  o  m
}

From source file:Main.java

/**
 * Like {@link #parseDtsAudioSampleCount(byte[])} but reads from a byte buffer. The buffer
 * position is not modified.//  w  w w  .  j a  v  a2  s.  c  om
 */
public static int parseDtsAudioSampleCount(ByteBuffer data) {
    // See ETSI TS 102 114 subsection 5.4.1.
    int position = data.position();
    int nblks = ((data.get(position + 4) & 0x01) << 6) | ((data.get(position + 5) & 0xFC) >> 2);
    return (nblks + 1) * 32;
}

From source file:Main.java

public static void printBufferInfo(ByteBuffer bb) {
    int limit = bb.limit();
    System.out.println("Position =  " + bb.position() + ", Limit   = " + limit);
    for (int i = 0; i < limit; i++) {
        System.out.print(bb.get(i) + "  ");
    }/* w w  w. j a  v  a2  s  . c  om*/
    System.out.println();
}

From source file:Main.java

/**
 * Like {@link #parseDtsAudioSampleCount(byte[])} but reads from a {@link ByteBuffer}. The
 * buffer's position is not modified.//from   w  ww.  j  a v  a  2 s .c  om
 *
 * @param buffer The {@link ByteBuffer} from which to read.
 * @return The number of audio samples represented by the syncframe.
 */
public static int parseDtsAudioSampleCount(ByteBuffer buffer) {
    // See ETSI TS 102 114 subsection 5.4.1.
    int position = buffer.position();
    int nblks = ((buffer.get(position + 4) & 0x01) << 6) | ((buffer.get(position + 5) & 0xFC) >> 2);
    return (nblks + 1) * 32;
}

From source file:Main.java

public static byte getProfileIdc(ByteBuffer spsBuffer) {
    // Refer: http://www.cardinalpeak.com/blog/the-h-264-sequence-parameter-set/
    // First byte after NAL.
    return spsBuffer.get(0);
}