// Path: librestreaming/src/main/java/me/lake/librestreaming/tools/ByteArrayTools.java
// public class ByteArrayTools {
//     public static void intToByteArrayFull(byte[] dst, int pos, int interger) {
//         dst[pos] = (byte) ((interger >> 24) & 0xFF);
//         dst[pos + 1] = (byte) ((interger >> 16) & 0xFF);
//         dst[pos + 2] = (byte) ((interger >> 8) & 0xFF);
//         dst[pos + 3] = (byte) ((interger) & 0xFF);
//     }
// 
//     public static void intToByteArrayTwoByte(byte[] dst, int pos, int interger) {
//         dst[pos] = (byte) ((interger >> 8) & 0xFF);
//         dst[pos + 1] = (byte) ((interger) & 0xFF);
//     }
// }


import android.media.MediaFormat;
import java.nio.ByteBuffer;
import me.lake.librestreaming.tools.ByteArrayTools;
package me.lake.librestreaming.core;




/**
 * Created by lake on 16-3-30.
 */
public class Packager {
    public static class H264Packager {

        public static byte[] generateAVCDecoderConfigurationRecord(MediaFormat mediaFormat) {
            ByteBuffer SPSByteBuff = mediaFormat.getByteBuffer("csd-0");
            SPSByteBuff.position(4);
            ByteBuffer PPSByteBuff = mediaFormat.getByteBuffer("csd-1");
            PPSByteBuff.position(4);
            int spslength = SPSByteBuff.remaining();
            int ppslength = PPSByteBuff.remaining();
            int length = 11 + spslength + ppslength;
            byte[] result = new byte[length];
            SPSByteBuff.get(result, 8, spslength);
            PPSByteBuff.get(result, 8 + spslength + 3, ppslength);
            /**
             * UB[8]configurationVersion
             * UB[8]AVCProfileIndication
             * UB[8]profile_compatibility
             * UB[8]AVCLevelIndication
             * UB[8]lengthSizeMinusOne
             */
// Path: librestreaming/src/main/java/me/lake/librestreaming/tools/ByteArrayTools.java
// public class ByteArrayTools {
//     public static void intToByteArrayFull(byte[] dst, int pos, int interger) {
//         dst[pos] = (byte) ((interger >> 24) & 0xFF);
//         dst[pos + 1] = (byte) ((interger >> 16) & 0xFF);
//         dst[pos + 2] = (byte) ((interger >> 8) & 0xFF);
//         dst[pos + 3] = (byte) ((interger) & 0xFF);
//     }
// 
//     public static void intToByteArrayTwoByte(byte[] dst, int pos, int interger) {
//         dst[pos] = (byte) ((interger >> 8) & 0xFF);
//         dst[pos + 1] = (byte) ((interger) & 0xFF);
//     }
// }


// Path: librestreaming/src/main/java/me/lake/librestreaming/core/Packager.java
import android.media.MediaFormat;
import java.nio.ByteBuffer;
import me.lake.librestreaming.tools.ByteArrayTools;

package me.lake.librestreaming.core;




/**
 * Created by lake on 16-3-30.
 */
public class Packager {
    public static class H264Packager {

        public static byte[] generateAVCDecoderConfigurationRecord(MediaFormat mediaFormat) {
            ByteBuffer SPSByteBuff = mediaFormat.getByteBuffer("csd-0");
            SPSByteBuff.position(4);
            ByteBuffer PPSByteBuff = mediaFormat.getByteBuffer("csd-1");
            PPSByteBuff.position(4);
            int spslength = SPSByteBuff.remaining();
            int ppslength = PPSByteBuff.remaining();
            int length = 11 + spslength + ppslength;
            byte[] result = new byte[length];
            SPSByteBuff.get(result, 8, spslength);
            PPSByteBuff.get(result, 8 + spslength + 3, ppslength);
            /**
             * UB[8]configurationVersion
             * UB[8]AVCProfileIndication
             * UB[8]profile_compatibility
             * UB[8]AVCLevelIndication
             * UB[8]lengthSizeMinusOne
             */
            result[0] = 0x01;