Java Code Examples for android.media.MediaFormat#setByteBuffer()

The following examples show how to use android.media.MediaFormat#setByteBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: H264Decoder.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
protected MediaCodec createMediaCodec() throws IOException {
    parseSps();

    MediaFormat format = MediaFormat.createVideoFormat(mMimeType, mWidth, mHeight);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
        format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        format.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE);
    }

    format.setByteBuffer("csd-0", mCsd0);
    format.setByteBuffer("csd-1", mCsd1);

    if (DEBUG) {
        Log.d(TAG, "H264Decoder::createMediaCodec: " + format);
    }

    MediaCodec mediaCodec = MediaCodec.createDecoderByType(mMimeType);
    mediaCodec.configure(format, getSurface(), null, 0);
    mediaCodec.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    mediaCodec.start();
    return mediaCodec;
}
 
Example 2
Source File: EncoderUtilsTest.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testGetCodecSpecificDataWithInvalidAVCData() {
    // testing an error case when the encoder emits SPS only (which should not happen)
    byte[] sps = new byte[] {
            0x00, 0x00, 0x00, 0x01,
            0x67, 0x42, (byte)0xC0, 0x0A, (byte)0xA6, 0x11, 0x11, (byte)0xE8,
            0x40, 0x00, 0x00, (byte)0xFA, 0x40, 0x00, 0x3A, (byte)0x98,
            0x23, (byte)0xC4, (byte)0x89, (byte)0x84, 0x60
    };

    ByteBuffer spsByteBuffer = ByteBuffer.allocate(sps.length);
    spsByteBuffer.put(sps);
    spsByteBuffer.flip();

    MediaFormat format = MediaFormat.createVideoFormat("video/avc", 16, 16);
    format.setByteBuffer("csd-0", spsByteBuffer);
    // no PPS

    byte[] result = EncoderUtils.getCodecSpecificData(format);
    assertNull(result);
}
 
Example 3
Source File: Format.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Returns a {@link MediaFormat} representation of this format.
 */
@SuppressLint("InlinedApi")
@TargetApi(16)
public final MediaFormat getFrameworkMediaFormatV16() {
  MediaFormat format = new MediaFormat();
  format.setString(MediaFormat.KEY_MIME, sampleMimeType);
  maybeSetStringV16(format, MediaFormat.KEY_LANGUAGE, language);
  maybeSetIntegerV16(format, MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
  maybeSetIntegerV16(format, MediaFormat.KEY_WIDTH, width);
  maybeSetIntegerV16(format, MediaFormat.KEY_HEIGHT, height);
  maybeSetFloatV16(format, MediaFormat.KEY_FRAME_RATE, frameRate);
  maybeSetIntegerV16(format, "rotation-degrees", rotationDegrees);
  maybeSetIntegerV16(format, MediaFormat.KEY_CHANNEL_COUNT, channelCount);
  maybeSetIntegerV16(format, MediaFormat.KEY_SAMPLE_RATE, sampleRate);
  maybeSetIntegerV16(format, "encoder-delay", encoderDelay);
  maybeSetIntegerV16(format, "encoder-padding", encoderPadding);
  for (int i = 0; i < initializationData.size(); i++) {
    format.setByteBuffer("csd-" + i, ByteBuffer.wrap(initializationData.get(i)));
  }
  return format;
}
 
Example 4
Source File: MediaReaper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
@Override
protected MediaFormat createOutputFormat(final byte[] csd, final int size,
	final int ix0, final int ix1, final int ix2) {

	MediaFormat outFormat;
       if (ix0 >= 0) {
		if (DEBUG) Log.w(TAG, "csd may be wrong, it may be for video");
       }
       // audioの時はSTART_MARKが無いので全体をコピーして渡す
       outFormat = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, mChannelCount);
       final ByteBuffer csd0 = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
       csd0.put(csd, 0, size);
       csd0.flip();
       outFormat.setByteBuffer("csd-0", csd0);
       return outFormat;
}
 
Example 5
Source File: EncoderUtilsTest.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testGetCodecSpecificDataForAVC() {
    // example of SPS NAL unit with 4-byte start code
    byte[] sps = new byte[] {
            0x00, 0x00, 0x00, 0x01,
            0x67, 0x42, (byte)0xC0, 0x0A, (byte)0xA6, 0x11, 0x11, (byte)0xE8,
            0x40, 0x00, 0x00, (byte)0xFA, 0x40, 0x00, 0x3A, (byte)0x98,
            0x23, (byte)0xC4, (byte)0x89, (byte)0x84, 0x60
    };
    // example of PPS NAL unit with 4-byte start code
    byte[] pps = new byte[] {
            0x00, 0x00, 0x00, 0x01,
            0x68, (byte)0xC8, 0x42, 0x0F, 0x13, 0x20
    };

    ByteBuffer spsByteBuffer = ByteBuffer.allocate(sps.length);
    spsByteBuffer.put(sps);
    spsByteBuffer.flip();

    ByteBuffer ppsByteBuffer = ByteBuffer.allocate(pps.length);
    ppsByteBuffer.put(pps);
    ppsByteBuffer.flip();

    MediaFormat format = MediaFormat.createVideoFormat("video/avc", 16, 16);
    format.setByteBuffer("csd-0", spsByteBuffer);
    format.setByteBuffer("csd-1", ppsByteBuffer);

    byte[] result = EncoderUtils.getCodecSpecificData(format);
    assertNotNull(result);

    byte[] expected = new byte[sps.length + pps.length];
    System.arraycopy(sps, 0, expected, 0, sps.length);
    System.arraycopy(pps, 0, expected, sps.length, pps.length);
    assertTrue("Output codec specific data doesn't match", Arrays.equals(expected, result));
}
 
Example 6
Source File: AbstractAudioEncoder.java    From libcommon with Apache License 2.0 6 votes vote down vote up
@Override
	protected MediaFormat createOutputFormat(final byte[] csd, final int size,
		final int ix0, final int ix1, final int ix2) {
		
		MediaFormat outFormat;
        if (ix0 >= 0) {
//        	Log.w(TAG, "csd may be wrong, it may be for video");
        }
        // audioの時はSTART_MARKが無いので全体をコピーして渡す
        outFormat = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, mChannelCount);
        // encodedDataをそのまま渡しても再生できないファイルが出来上がるので一旦コピーしないと駄目
        final ByteBuffer csd0 = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
        csd0.put(csd, 0, size);
        csd0.flip();
        outFormat.setByteBuffer("csd-0", csd0);
        return outFormat;
	}
 
Example 7
Source File: AbstractVideoEncoder.java    From libcommon with Apache License 2.0 6 votes vote down vote up
@Override
protected MediaFormat createOutputFormat(final byte[] csd, final int size,
	final int ix0, final int ix1, final int ix2) {
	
	final MediaFormat outFormat;
       if (ix0 >= 0) {
           outFormat = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
       	final ByteBuffer csd0 = ByteBuffer.allocateDirect(ix1 - ix0).order(ByteOrder.nativeOrder());
       	csd0.put(csd, ix0, ix1 - ix0);
       	csd0.flip();
           outFormat.setByteBuffer("csd-0", csd0);
           if (ix1 > ix0) {
			final int sz = (ix2 > ix1) ? (ix2 - ix1) : (size - ix1);
           	final ByteBuffer csd1 = ByteBuffer.allocateDirect(size - ix1 + ix0).order(ByteOrder.nativeOrder());
           	csd1.put(csd, ix1, size - ix1 + ix0);
           	csd1.flip();
               outFormat.setByteBuffer("csd-1", csd1);
           }
       } else {
       	throw new RuntimeException("unexpected csd data came.");
       }
       return outFormat;
}
 
Example 8
Source File: H265Decoder.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
protected MediaCodec createMediaCodec() throws IOException {
    MediaFormat format = MediaFormat.createVideoFormat(mMimeType, 0, 0);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
        format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        format.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE);
    }

    ByteBuffer csd0 = ByteBuffer.allocate(mVPS.length + mSPS.length + mPPS.length +  12);
    csd0.put(createSPS_PPS(mVPS, mSPS, mPPS));

    format.setByteBuffer("csd-0", csd0);

    if (DEBUG) {
        Log.d(TAG, "H265Deocder::createMediaCodec: " + format);
    }

    MediaCodec mediaCodec = MediaCodec.createDecoderByType(mMimeType);
    mediaCodec.configure(format, getSurface(), null, 0);
    mediaCodec.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    mediaCodec.start();
    return mediaCodec;
}
 
Example 9
Source File: AudioUtil.java    From VideoProcessor with Apache License 2.0 5 votes vote down vote up
public static void checkCsd(MediaFormat audioMediaFormat, int profile, int sampleRate, int channel) {
        int freqIdx = freqIdxMap.containsKey(sampleRate) ? freqIdxMap.get(sampleRate) : 4;
//        byte[] bytes = new byte[]{(byte) 0x11, (byte) 0x90};
//        ByteBuffer bb = ByteBuffer.wrap(bytes);
        ByteBuffer csd = ByteBuffer.allocate(2);
        csd.put(0, (byte) (profile << 3 | freqIdx >> 1));
        csd.put(1, (byte) ((freqIdx & 0x01) << 7 | channel << 3));
        audioMediaFormat.setByteBuffer("csd-0", csd);
    }
 
Example 10
Source File: AudioRecordThread.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
private void checkCsd(MediaFormat audioMediaFormat, int profile, int sampleRate, int channel) {
        int freqIdx = freqIdxMap.containsKey(sampleRate) ? freqIdxMap.get(sampleRate) : 4;
//        byte[] bytes = new byte[]{(byte) 0x11, (byte) 0x90};
//        ByteBuffer bb = ByteBuffer.wrap(bytes);
        ByteBuffer csd = ByteBuffer.allocate(2);
        csd.put(0, (byte) (profile << 3 | freqIdx >> 1));
        csd.put(1, (byte) ((freqIdx & 0x01) << 7 | channel << 3));
        audioMediaFormat.setByteBuffer("csd-0", csd);
    }
 
Example 11
Source File: AACDecoder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * MediaCodec を作成します.
 *
 * @return MediaCodec
 * @throws IOException MediaCodec の作成に失敗した場合に発生
 */
private MediaCodec createMediaCodec() throws IOException {
    MediaFormat format = MediaFormat.createAudioFormat("audio/mp4a-latm",
            getSamplingRate(), getChannelCount());

    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);

    int audioProfile = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
    int sampleIndex = getFreqIdx(getSamplingRate());
    int channelConfig = getChannelCount();

    ByteBuffer csd = ByteBuffer.allocateDirect(2);
    csd.put((byte) ((audioProfile << 3) | (sampleIndex >> 1)));
    csd.position(1);
    csd.put((byte) ((byte) ((sampleIndex << 7) & 0x80) | (channelConfig << 3)));
    csd.flip();

    format.setByteBuffer("csd-0", csd);

    if (DEBUG) {
        Log.d(TAG, "AACDecoder::createMediaCodec: " + format);
    }

    MediaCodec mediaCodec = MediaCodec.createDecoderByType("audio/mp4a-latm");
    mediaCodec.configure(format, null, null, 0);
    mediaCodec.start();
    return mediaCodec;
}
 
Example 12
Source File: H265Decoder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected MediaCodec createMediaCodec() throws IOException {
    parseSps();

    MediaFormat format = MediaFormat.createVideoFormat(mMimeType, mWidth, mHeight);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
        format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_FULL);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        format.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE);
    }

    ByteBuffer csd0 = ByteBuffer.allocateDirect(mVPS.length + mSPS.length + mPPS.length);
    csd0.put(mVPS);
    csd0.position(mVPS.length);
    csd0.put(mSPS);
    csd0.position(mVPS.length + mSPS.length);
    csd0.put(mPPS);

    format.setByteBuffer("csd-0", csd0);

    if (DEBUG) {
        Log.d(TAG, "H265Decoder::createMediaCodec: " + format);
    }

    MediaCodec mediaCodec = MediaCodec.createDecoderByType(mMimeType);
    mediaCodec.configure(format, getSurface(), null, 0);
    mediaCodec.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    mediaCodec.start();
    return mediaCodec;
}
 
Example 13
Source File: AACDecoder.java    From AndroidScreenShare with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化解码器
 *
 * @return 初始化失败返回false,成功返回true
 */
public boolean prepare() {

    try {
        //需要解码数据的类型
        String mine = "audio/mp4a-latm";
        //初始化解码器
        mDecoder = MediaCodec.createDecoderByType(mine);
        //MediaFormat用于描述音视频数据的相关参数
        MediaFormat mediaFormat = new MediaFormat();
        //数据类型
        mediaFormat.setString(MediaFormat.KEY_MIME, mine);
        //声道个数
        mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, channelCount);
        //采样率
        mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
        //比特率
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
        //用来标记AAC是否有adts头,1->有
        mediaFormat.setInteger(MediaFormat.KEY_IS_ADTS, 1);
        //用来标记aac的类型
        mediaFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
        //ByteBuffer key(暂时不了解该参数的含义,但必须设置)
        byte[] data = new byte[]{(byte) 0x11, (byte) 0x90};
        ByteBuffer csd_0 = ByteBuffer.wrap(data);
        mediaFormat.setByteBuffer("csd-0", csd_0);
        //解码器配置
        mDecoder.configure(mediaFormat, null, null, 0);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    if (mDecoder == null) {
        return false;
    }
    mDecoder.start();
    return true;
}
 
Example 14
Source File: EncoderDebugger.java    From libstreaming with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates and starts the decoder.
 * @throws IOException The decoder cannot be configured
 */	
private void configureDecoder() throws IOException {
	byte[] prefix = new byte[] {0x00,0x00,0x00,0x01};

	ByteBuffer csd0 = ByteBuffer.allocate(4+mSPS.length+4+mPPS.length);
	csd0.put(new byte[] {0x00,0x00,0x00,0x01});
	csd0.put(mSPS);
	csd0.put(new byte[] {0x00,0x00,0x00,0x01});
	csd0.put(mPPS);

	mDecoder = MediaCodec.createByCodecName(mDecoderName);
	MediaFormat mediaFormat = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
	mediaFormat.setByteBuffer("csd-0", csd0);
	mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, mDecoderColorFormat);
	mDecoder.configure(mediaFormat, null, null, 0);
	mDecoder.start();

	ByteBuffer[] decInputBuffers = mDecoder.getInputBuffers();

	int decInputIndex = mDecoder.dequeueInputBuffer(1000000/FRAMERATE);
	if (decInputIndex>=0) {
		decInputBuffers[decInputIndex].clear();
		decInputBuffers[decInputIndex].put(prefix);
		decInputBuffers[decInputIndex].put(mSPS);
		mDecoder.queueInputBuffer(decInputIndex, 0, decInputBuffers[decInputIndex].position(), timestamp(), 0);
	} else {
		if (VERBOSE) Log.e(TAG,"No buffer available !");
	}

	decInputIndex = mDecoder.dequeueInputBuffer(1000000/FRAMERATE);
	if (decInputIndex>=0) {
		decInputBuffers[decInputIndex].clear();
		decInputBuffers[decInputIndex].put(prefix);
		decInputBuffers[decInputIndex].put(mPPS);
		mDecoder.queueInputBuffer(decInputIndex, 0, decInputBuffers[decInputIndex].position(), timestamp(), 0);
	} else {
		if (VERBOSE) Log.e(TAG,"No buffer available !");
	}


}
 
Example 15
Source File: VIARecorder.java    From VIA-AI with MIT License 4 votes vote down vote up
public VIARecorder(String path, String prefix,int width, int height, int bitrate, int fps, long perodicTimeInSec, Mode mode){
        mMode = mode;
        mWidth = width;
        mHeight = height;
        mPrefix = prefix;
        if(mMode.equals(Mode.YUV420SemiPlanar)) {
            COLOR_FORMAT = MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar;
        } else if (mMode.equals(Mode.Surface)) {
            COLOR_FORMAT = MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface;
        }

        AvcEncoder.EncodeParameters parameters = new AvcEncoder.EncodeParameters(width,height,bitrate, COLOR_FORMAT);
        mFPS = fps;
        mFrameDiffTimes = 1000/mFPS;
        mPeriodicTimeInSec = perodicTimeInSec;
        mPath = path;

        File f = new File(path);
        if(!f.exists()) {
            f.mkdirs();
        }
        f = null;

        try {
            mMediaFormat = new MediaFormat();
            mMediaFormat.setInteger(MediaFormat.KEY_WIDTH, width);
            mMediaFormat.setInteger(MediaFormat.KEY_HEIGHT, height);
            mMediaFormat.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC);
            mMediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);
            mMediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, fps);
            mMediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);

            mAvcEncoder = new AvcEncoder(parameters, new AvcEncoder.EncodedFrameListener() {
                @Override
                public void onFirstSpsPpsEncoded(byte[] sps, byte[] pps) {
                    mMediaFormat.setByteBuffer("csd-0", ByteBuffer.wrap(sps));
                    mMediaFormat.setByteBuffer("csd-1", ByteBuffer.wrap(pps));
                    bFormatReady = true;
                }

                @Override
                public boolean onFrameEncoded(ByteBuffer nalu, MediaCodec.BufferInfo info) {
                    if(!bStarted) return false;

                    mFrameCount++;
                    info.presentationTimeUs = System.currentTimeMillis()*1000;
                    boolean bFlush = false;
//                    mTime += mFrameDiffTimes;
                    if(((info.flags&MediaCodec.BUFFER_FLAG_KEY_FRAME)==1) && (System.currentTimeMillis()-mFileStartTime)>=mPeriodicTimeInSec*1000) {
                        createRecordFile();
                        bFlush = false;
                    }

                    synchronized (mLock) {
                        if (mMediaMuxer != null && bFormatReady) {
                            if (mVideoTrack == -1) {
                                mVideoTrack = mMediaMuxer.addTrack(mMediaFormat);
                                mMediaMuxer.start();
                            }
                            if(null!=mMuxerCallback) {
                                mMuxerCallback.OnMuxerWriterFrame(info.presentationTimeUs/1000);
                            }
                            mMediaMuxer.writeSampleData(mVideoTrack, nalu, info);
                        }
                    }
                    return bFlush;
                }
            });
        } catch (IOException e) {
            Log.d("VIARecorder", "VIARecorder: "+e.toString());
        }
    }
 
Example 16
Source File: TLMediaEncoder.java    From TimeLapseRecordingSample with Apache License 2.0 4 votes vote down vote up
private static final MediaFormat asMediaFormat(final String format_str) {
	MediaFormat format = new MediaFormat();
	try {
		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;
}
 
Example 17
Source File: MediaFormatUtil.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets a {@link MediaFormat} {@link ByteBuffer} value. Does nothing if {@code value} is null.
 *
 * @param format The {@link MediaFormat} being configured.
 * @param key The key to set.
 * @param value The {@link byte[]} that will be wrapped to obtain the value.
 */
public static void maybeSetByteBuffer(MediaFormat format, String key, @Nullable byte[] value) {
  if (value != null) {
    format.setByteBuffer(key, ByteBuffer.wrap(value));
  }
}
 
Example 18
Source File: MediaFormatUtil.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a {@link MediaFormat}'s codec specific data buffers.
 *
 * @param format The {@link MediaFormat} being configured.
 * @param csdBuffers The csd buffers to set.
 */
public static void setCsdBuffers(MediaFormat format, List<byte[]> csdBuffers) {
  for (int i = 0; i < csdBuffers.size(); i++) {
    format.setByteBuffer("csd-" + i, ByteBuffer.wrap(csdBuffers.get(i)));
  }
}
 
Example 19
Source File: MediaFormatUtil.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets a {@link MediaFormat} {@link ByteBuffer} value. Does nothing if {@code value} is null.
 *
 * @param format The {@link MediaFormat} being configured.
 * @param key The key to set.
 * @param value The {@link byte[]} that will be wrapped to obtain the value.
 */
public static void maybeSetByteBuffer(MediaFormat format, String key, @Nullable byte[] value) {
  if (value != null) {
    format.setByteBuffer(key, ByteBuffer.wrap(value));
  }
}
 
Example 20
Source File: MediaFormatUtil.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a {@link MediaFormat} {@link ByteBuffer} value. Does nothing if {@code value} is null.
 *
 * @param format The {@link MediaFormat} being configured.
 * @param key The key to set.
 * @param value The {@link byte[]} that will be wrapped to obtain the value.
 */
public static void maybeSetByteBuffer(MediaFormat format, String key, @Nullable byte[] value) {
  if (value != null) {
    format.setByteBuffer(key, ByteBuffer.wrap(value));
  }
}