本文整理汇总了Java中android.media.MediaCodec.getInputBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodec.getInputBuffer方法的具体用法?Java MediaCodec.getInputBuffer怎么用?Java MediaCodec.getInputBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaCodec
的用法示例。
在下文中一共展示了MediaCodec.getInputBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
private ByteBuffer getInputBuffer(MediaCodec codec, int index){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return codec.getInputBuffer(index);
}else{
return codec.getInputBuffers()[index];
}
}
示例2: getInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
public static ByteBuffer getInputBuffer(MediaCodec codec, int index){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return codec.getInputBuffer(index);
}else{
return codec.getInputBuffers()[index];
}
}
示例3: queueInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
private int queueInputBuffer(MediaCodec codec, int inputBufferId) throws IOException {
ByteBuffer inputBuffer = codec.getInputBuffer(inputBufferId);
inputBuffer.clear();
int bytesAvailable = audioRecorderInputStream.available();
int bytesRead = bytesAvailable < inputBuffer.limit() ? bytesAvailable : inputBuffer.limit();
byte[] audioRecorderBytes = new byte[bytesRead];
audioRecorderInputStream.read(audioRecorderBytes);
inputBuffer.put(audioRecorderBytes);
codec.queueInputBuffer(inputBufferId, 0, bytesRead, 0, 0);
return bytesRead;
}
示例4: getInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
private ByteBuffer getInputBuffer(MediaCodec codec, int bufferIndex) {
ByteBuffer buffer;
if (Build.VERSION.SDK_INT < 21) {
buffer = codec.getInputBuffers()[bufferIndex];
buffer.clear();
} else {
buffer = codec.getInputBuffer(bufferIndex);
}
return buffer;
}
示例5: getInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
/**
* 防止出现 http://stackoverflow.com/q/30646885 的问题
*
* @param codec
* @param index
* @return
*/
public static ByteBuffer getInputBuffer(MediaCodec codec, int index) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return codec.getInputBuffer(index);
} else {
return codec.getInputBuffers()[index];
}
}
示例6: renderHevcImage
import android.media.MediaCodec; //导入方法依赖的package包/类
private static void renderHevcImage(ByteBuffer bitstream, ImageInfo info, Surface surface) {
long beginTime = SystemClock.elapsedRealtimeNanos();
// configure HEVC decoder
MediaCodec decoder = configureDecoder(info, bitstream.limit(), surface);
MediaFormat outputFormat = decoder.getOutputFormat();
Log.d(TAG, "HEVC output-format=" + outputFormat);
decoder.start();
try {
// set bitstream to decoder
int inputBufferId = decoder.dequeueInputBuffer(-1);
if (inputBufferId < 0) {
throw new IllegalStateException("dequeueInputBuffer return " + inputBufferId);
}
ByteBuffer inBuffer = decoder.getInputBuffer(inputBufferId);
inBuffer.put(bitstream);
decoder.queueInputBuffer(inputBufferId, 0, bitstream.limit(), 0, 0);
// notify end of stream
inputBufferId = decoder.dequeueInputBuffer(-1);
if (inputBufferId < 0) {
throw new IllegalStateException("dequeueInputBuffer return " + inputBufferId);
}
decoder.queueInputBuffer(inputBufferId, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
// get decoded image
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
while (true) {
int outputBufferId = decoder.dequeueOutputBuffer(bufferInfo, -1);
if (outputBufferId >= 0) {
decoder.releaseOutputBuffer(outputBufferId, true);
break;
} else if (outputBufferId == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
outputFormat = decoder.getOutputFormat();
Log.d(TAG, "HEVC output-format=" + outputFormat);
} else {
Log.d(TAG, "HEVC dequeueOutputBuffer return " + outputBufferId);
}
}
decoder.flush();
} finally {
decoder.stop();
decoder.release();
}
long endTime = SystemClock.elapsedRealtimeNanos();
Log.i(TAG, "HEVC decoding elapsed=" + (endTime - beginTime) / 1000000.f + "[msec]");
}