本文整理汇总了Java中android.media.MediaCodec.queueInputBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodec.queueInputBuffer方法的具体用法?Java MediaCodec.queueInputBuffer怎么用?Java MediaCodec.queueInputBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaCodec
的用法示例。
在下文中一共展示了MediaCodec.queueInputBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queueInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
/**
* Copy audio from the recorder into the encoder.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int queueInputBuffer(MediaCodec codec, ByteBuffer[] inputBuffers, int index, SpeechRecord speechRecord) {
if (speechRecord == null || speechRecord.getRecordingState() != SpeechRecord.RECORDSTATE_RECORDING) {
return -1;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ByteBuffer inputBuffer = inputBuffers[index];
inputBuffer.clear();
int size = inputBuffer.limit();
byte[] buffer = new byte[size];
int status = read(speechRecord, buffer);
if (status < 0) {
handleError("status = " + status);
return -1;
}
inputBuffer.put(buffer);
codec.queueInputBuffer(index, 0, size, 0, 0);
return size;
}
return -1;
}
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:26,代码来源:EncodedAudioRecorder.java
示例2: recorderEncoderLoop
import android.media.MediaCodec; //导入方法依赖的package包/类
/**
* Reads bytes from the given recorder and encodes them with the given encoder.
* Uses the (deprecated) Synchronous Processing using Buffer Arrays.
* <p/>
* Encoders (or codecs that generate compressed data) will create and return the codec specific
* data before any valid output buffer in output buffers marked with the codec-config flag.
* Buffers containing codec-specific-data have no meaningful timestamps.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void recorderEncoderLoop(MediaCodec codec, SpeechRecord speechRecord) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
codec.start();
// Getting some buffers (e.g. 4 of each) to communicate with the codec
ByteBuffer[] codecInputBuffers = codec.getInputBuffers();
ByteBuffer[] codecOutputBuffers = codec.getOutputBuffers();
Log.i("input buffers " + codecInputBuffers.length + "; output buffers: " + codecOutputBuffers.length);
boolean doneSubmittingInput = false;
int numRetriesDequeueOutputBuffer = 0;
int index;
while (true) {
if (!doneSubmittingInput) {
index = codec.dequeueInputBuffer(DEQUEUE_TIMEOUT);
if (index >= 0) {
int size = queueInputBuffer(codec, codecInputBuffers, index, speechRecord);
if (size == -1) {
codec.queueInputBuffer(index, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
Log.i("enc: in: EOS");
doneSubmittingInput = true;
} else {
Log.i("enc: in: " + size);
mNumBytesSubmitted += size;
}
} else {
Log.i("enc: in: timeout, will try again");
}
}
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
index = codec.dequeueOutputBuffer(info, DEQUEUE_TIMEOUT);
Log.i("enc: out: flags/index: " + info.flags + "/" + index);
if (index == MediaCodec.INFO_TRY_AGAIN_LATER) {
Log.i("enc: out: INFO_TRY_AGAIN_LATER: " + numRetriesDequeueOutputBuffer);
if (++numRetriesDequeueOutputBuffer > MAX_NUM_RETRIES_DEQUEUE_OUTPUT_BUFFER) {
break;
}
} else if (index == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat format = codec.getOutputFormat();
Log.i("enc: out: INFO_OUTPUT_FORMAT_CHANGED: " + format.toString());
} else if (index == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
codecOutputBuffers = codec.getOutputBuffers();
Log.i("enc: out: INFO_OUTPUT_BUFFERS_CHANGED");
} else {
dequeueOutputBuffer(codec, codecOutputBuffers, index, info);
mNumBytesDequeued += info.size;
if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
Log.i("enc: out: EOS");
break;
}
}
}
codec.stop();
codec.release();
}
}
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:64,代码来源:EncodedAudioRecorder.java
示例3: handleCodecInput
import android.media.MediaCodec; //导入方法依赖的package包/类
private void handleCodecInput(AudioRecord audioRecord, byte[] audioRecordData,
MediaCodec mediaCodec, ByteBuffer[] codecInputBuffers,
boolean running)
{
int length = audioRecord.read(audioRecordData, 0, audioRecordData.length);
int codecInputBufferIndex = mediaCodec.dequeueInputBuffer(10 * 1000);
if (codecInputBufferIndex >= 0) {
ByteBuffer codecBuffer = codecInputBuffers[codecInputBufferIndex];
codecBuffer.clear();
codecBuffer.put(audioRecordData);
mediaCodec.queueInputBuffer(codecInputBufferIndex, 0, length, 0, running ? 0 : MediaCodec.BUFFER_FLAG_END_OF_STREAM);
}
}
示例4: 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;
}
示例5: 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]");
}
示例6: fillInputBuffer
import android.media.MediaCodec; //导入方法依赖的package包/类
public int fillInputBuffer(byte[] data, long pts, int flush) {
int sampleSize = data.length;
if (sampleSize <= 0) {
return -3;
}
try {
int inputBufIndex = this.codec.dequeueInputBuffer(10000);
if (inputBufIndex >= 0) {
ByteBuffer dstBuf = this.codecInputBuffers[inputBufIndex];
if (dstBuf.capacity() < sampleSize) {
Log.d(LOG_TAG, "Input buffer too small " + dstBuf.capacity() + " vs " + sampleSize);
return getOutputBuffer();
}
dstBuf.clear();
dstBuf.put(data);
long presentationTimeUs = pts;
if (pts < 0) {
presentationTimeUs = 0;
}
if (this.first_frame == 0) {
this.first_frame = 1;
this.codec.queueInputBuffer(inputBufIndex, 0, sampleSize, 1, 2);
return 0;
}
int i;
MediaCodec mediaCodec = this.codec;
if (false) {
i = 4;
} else {
i = 0;
}
mediaCodec.queueInputBuffer(inputBufIndex, 0, sampleSize, presentationTimeUs, i);
return getOutputBuffer();
}
getOutputBuffer();
return -1;
} catch (IllegalStateException e) {
Log.d(LOG_TAG, "IllegalStateException catched in fillInputBuffer");
return -2;
}
}