本文整理匯總了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]");
}