As @Aegonis asked in this post
I'm trying to connect the Camera with Android to encode the video frames.
The problem is, trying to do the same than him, in this part, as another 2 users that posted in his topic, it crash:
// called from Camera.setPreviewCallbackWithBuffer(...) in other class
public void encoder(byte[] input) {
try {
ByteBuffer[] inputBuffers = mediaCodec.getInputBuffers();
ByteBuffer[] outputBuffers = mediaCodec.getOutputBuffers();
int inputBufferIndex = mediaCodec.dequeueInputBuffer(-1);
if (inputBufferIndex >= 0) {
ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
inputBuffer.clear();
inputBuffer.put(input);
mediaCodec.queueInputBuffer(inputBufferIndex, 0, input.length, 0, 0);
}
...
The call i do from setPreviewCallbackWithBuffer is like this:
int bufSize= 460800;
camera.addCallbackBuffer(new byte[bufSize]);
camera.setPreviewCallbackWithBuffer(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera arg1) {
codecs.encoder(data);
}
});
...
Having the following error messages
03-04 20:30:46.762: E/AndroidRuntime(26196): java.nio.BufferOverflowException
03-04 20:30:46.762: E/AndroidRuntime(26196): at java.nio.Buffer.checkPutBounds(Buffer.java:189)
03-04 20:30:46.762: E/AndroidRuntime(26196): at java.nio.ReadWriteDirectByteBuffer.put(ReadWriteDirectByteBuffer.java:100)
03-04 20:30:46.762: E/AndroidRuntime(26196): at java.nio.ByteBuffer.put(ByteBuffer.java:712)
So well, the byte buffer is so big, but setPreviewCallbackWithBuffer says you to use at least one buffer with the size: 460800. So... how would you solve this problem?