Java ByteBuffer Put putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType)

Here you can find the source of putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType)

Description

put NAL

License

BSD License

Declaration

private static void putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType) 

Method Source Code

//package com.java2s;
/**//  w  ww  .  j a va  2 s . com
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * @author The JCodec project
 * 
 */

import java.nio.ByteBuffer;

public class Main {
    private static void putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType) {
        ByteBuffer dst = ByteBuffer.allocate(byteBuffer.remaining() * 2);
        escapeNAL(byteBuffer, dst);
        dst.flip();
        codecPrivate.putInt(1);
        codecPrivate.put((byte) nalType);
        codecPrivate.put(dst);
    }

    public static final void escapeNAL(ByteBuffer src, ByteBuffer dst) {
        byte p1 = src.get(), p2 = src.get();
        dst.put(p1);
        dst.put(p2);
        while (src.hasRemaining()) {
            byte b = src.get();
            if (p1 == 0 && p2 == 0 && (b & 0xff) <= 3) {
                dst.put((byte) 3);
                p1 = p2;
                p2 = 3;
            }
            dst.put(b);
            p1 = p2;
            p2 = b;
        }
    }
}

Related

  1. putInt(int i, ByteBuffer buffer)
  2. putIntArray(int ints[], ByteBuffer bb)
  3. putIntByteBuffer(ByteBuffer buf, int b)
  4. putIntByteBuffer(ByteBuffer buf, int b)
  5. putIntLSBMSB(ByteBuffer byteBuffer, int value)
  6. putNullTerminal(ByteBuffer buffer)
  7. putObject(ByteBuffer byteBuffer, Object object)
  8. putObject(final ByteBuffer buffer, Serializable o)
  9. putQuickchatParam(ByteBuffer buf, long param, int size)