Example usage for android.media MediaFormat setByteBuffer

List of usage examples for android.media MediaFormat setByteBuffer

Introduction

In this page you can find the example usage for android.media MediaFormat setByteBuffer.

Prototype

public final void setByteBuffer(String name, ByteBuffer bytes) 

Source Link

Document

Sets the value of a ByteBuffer key.

Usage

From source file:com.c77.androidstreamingclient.lib.rtp.RtpMediaExtractor.java

/**
 * Retrieves an Android MediaFormat for H.264, 640x480 video codec.
 * SPS and PPS are hardcoded to the ones used by libstreaming.
 * TODO: Think how to get CSD-0/CSD-1 codec-specific data chunks
 *
 * @return//  w  w w .  j  a va 2 s  .c  o m
 */
public MediaFormat getMediaFormat() {
    String mimeType = "video/avc";
    int width = 640;
    int height = 480;

    MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);

    // from avconv, when streaming sample.h264.mp4 from disk
    byte[] header_sps = { 0, 0, 0, 1, // header
            0x67, 0x64, (byte) 0x00, 0x1e, (byte) 0xac, (byte) 0xd9, 0x40, (byte) 0xa0, 0x3d, (byte) 0xa1, 0x00,
            0x00, (byte) 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x3C, 0x0F, 0x16, 0x2D, (byte) 0x96 }; // sps
    byte[] header_pps = { 0, 0, 0, 1, // header
            0x68, (byte) 0xeb, (byte) 0xec, (byte) 0xb2, 0x2C }; // pps

    format.setByteBuffer(CSD_0, ByteBuffer.wrap(header_sps));
    format.setByteBuffer(CSD_1, ByteBuffer.wrap(header_pps));

    //format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, width * height);
    format.setInteger(DURATION_US, 12600000);

    return format;
}

From source file:com.c77.androidstreamingclient.lib.rtp.OriginalRtpMediaExtractor.java

public MediaFormat getMediaFormat() {
    String mimeType = "video/avc";
    int width = 640;
    int height = 480;

    MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
    /*//from   w  ww  . j ava2 s .  c o  m
    // the one got from internet
    byte[] header_sps = { 0, 0, 0, 1, // header
        0x67, 0x42, 0x00, 0x1f, (byte)0xe9, 0x01, 0x68, 0x7b, (byte) 0x20 }; // sps
    byte[] header_pps = { 0, 0, 0, 1, // header
        0x68, (byte)0xce, 0x06, (byte)0xf2 }; // pps
            
    // the one got from libstreaming at HQ
    byte[] header_sps = { 0, 0, 0, 1, // header
        0x67, 0x42, (byte)0x80, 0x14, (byte)0xe4, 0x40, (byte)0xa0, (byte)0xfd, 0x00, (byte)0xda, 0x14, 0x26, (byte)0xa0}; // sps
    byte[] header_pps = { 0, 0, 0, 1, // header
        0x68, (byte)0xce, 0x38, (byte)0x80 }; // pps
            
            
    // the one got from libstreaming at home
    byte[] header_sps = { 0, 0, 0, 1, // header
        0x67, 0x42, (byte) 0xc0, 0x1e, (byte) 0xe9, 0x01, 0x40, 0x7b, 0x40, 0x3c, 0x22, 0x11, (byte) 0xa8}; // sps
    byte[] header_pps = { 0, 0, 0, 1, // header
        0x68, (byte) 0xce, 0x06, (byte) 0xe2}; // pps
     */

    // from avconv, when streaming sample.h264.mp4 from disk
    byte[] header_sps = { 0, 0, 0, 1, // header
            0x67, 0x64, (byte) 0x00, 0x1e, (byte) 0xac, (byte) 0xd9, 0x40, (byte) 0xa0, 0x3d, (byte) 0xa1, 0x00,
            0x00, (byte) 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x3C, 0x0F, 0x16, 0x2D, (byte) 0x96 }; // sps
    byte[] header_pps = { 0, 0, 0, 1, // header
            0x68, (byte) 0xeb, (byte) 0xec, (byte) 0xb2, 0x2C }; // pps

    format.setByteBuffer(CSD_0, ByteBuffer.wrap(header_sps));
    format.setByteBuffer(CSD_1, ByteBuffer.wrap(header_pps));

    //format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, width * height);
    format.setInteger(DURATION_US, 12600000);

    return format;
}

From source file:com.serenegiant.media.TLMediaEncoder.java

private static final MediaFormat asMediaFormat(final String format_str) {
    MediaFormat format = new MediaFormat();
    try {/*from  w w w. j av a  2  s  .c o  m*/
        final JSONObject map = new JSONObject(format_str);
        if (map.has(MediaFormat.KEY_MIME))
            format.setString(MediaFormat.KEY_MIME, (String) map.get(MediaFormat.KEY_MIME));
        if (map.has(MediaFormat.KEY_WIDTH))
            format.setInteger(MediaFormat.KEY_WIDTH, (Integer) map.get(MediaFormat.KEY_WIDTH));
        if (map.has(MediaFormat.KEY_HEIGHT))
            format.setInteger(MediaFormat.KEY_HEIGHT, (Integer) map.get(MediaFormat.KEY_HEIGHT));
        if (map.has(MediaFormat.KEY_BIT_RATE))
            format.setInteger(MediaFormat.KEY_BIT_RATE, (Integer) map.get(MediaFormat.KEY_BIT_RATE));
        if (map.has(MediaFormat.KEY_COLOR_FORMAT))
            format.setInteger(MediaFormat.KEY_COLOR_FORMAT, (Integer) map.get(MediaFormat.KEY_COLOR_FORMAT));
        if (map.has(MediaFormat.KEY_FRAME_RATE))
            format.setInteger(MediaFormat.KEY_FRAME_RATE, (Integer) map.get(MediaFormat.KEY_FRAME_RATE));
        if (map.has(MediaFormat.KEY_I_FRAME_INTERVAL))
            format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,
                    (Integer) map.get(MediaFormat.KEY_I_FRAME_INTERVAL));
        if (map.has(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER))
            format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER,
                    (Long) map.get(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER));
        if (map.has(MediaFormat.KEY_MAX_INPUT_SIZE))
            format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE,
                    (Integer) map.get(MediaFormat.KEY_MAX_INPUT_SIZE));
        if (map.has(MediaFormat.KEY_DURATION))
            format.setInteger(MediaFormat.KEY_DURATION, (Integer) map.get(MediaFormat.KEY_DURATION));
        if (map.has(MediaFormat.KEY_CHANNEL_COUNT))
            format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, (Integer) map.get(MediaFormat.KEY_CHANNEL_COUNT));
        if (map.has(MediaFormat.KEY_SAMPLE_RATE))
            format.setInteger(MediaFormat.KEY_SAMPLE_RATE, (Integer) map.get(MediaFormat.KEY_SAMPLE_RATE));
        if (map.has(MediaFormat.KEY_CHANNEL_MASK))
            format.setInteger(MediaFormat.KEY_CHANNEL_MASK, (Integer) map.get(MediaFormat.KEY_CHANNEL_MASK));
        if (map.has(MediaFormat.KEY_AAC_PROFILE))
            format.setInteger(MediaFormat.KEY_AAC_PROFILE, (Integer) map.get(MediaFormat.KEY_AAC_PROFILE));
        if (map.has(MediaFormat.KEY_AAC_SBR_MODE))
            format.setInteger(MediaFormat.KEY_AAC_SBR_MODE, (Integer) map.get(MediaFormat.KEY_AAC_SBR_MODE));
        if (map.has(MediaFormat.KEY_MAX_INPUT_SIZE))
            format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE,
                    (Integer) map.get(MediaFormat.KEY_MAX_INPUT_SIZE));
        if (map.has(MediaFormat.KEY_IS_ADTS))
            format.setInteger(MediaFormat.KEY_IS_ADTS, (Integer) map.get(MediaFormat.KEY_IS_ADTS));
        if (map.has("what"))
            format.setInteger("what", (Integer) map.get("what"));
        if (map.has("csd-0"))
            format.setByteBuffer("csd-0", asByteBuffer((String) map.get("csd-0")));
        if (map.has("csd-1"))
            format.setByteBuffer("csd-1", asByteBuffer((String) map.get("csd-1")));
    } catch (JSONException e) {
        Log.e(TAG_STATIC, "writeFormat:" + format_str, e);
        format = null;
    }
    return format;
}