Android and JNI, how to transfer a Byte [] data array to JNI and get Byte [] back

I want to transfer byte [] the data (frame) captured by the camera to the JNI part. I need some frames to go through immediately, so I think if I can create byte [] [] to store byte [] so that I can get byte [] back from JNI. Is it possible? I know that getByteArrayElement()can help. Does anyone know how to achieve it?

Actually, I tried to use the queue to achieve the goal of passing the byte [] earlier, but this seems impossible, as some people answered me.

Past code (put byte [] in arraylist):

aCamera.setPreviewCallback(new PreviewCallback(){
            public void onPreviewFrame(byte[] data, Camera camera) {
                synchronized (TestClass.this){
                    AFrame = data;
                    int i = 0;
                    queue = new ArrayList<byte[]>(definedSize);

                    if(queue.size()<definedSize){
                    queue.add(data);
                    }
                    else{
                        queue.remove(0);
                    }
                    TestClass.this.notify();
                }
            }

        });

Arraylist cannot return to JNI, so this time I think if I can do it with another byte array.

Android . - - ? , .

+4
1

JNI - Java. ( Java) ( C/++). , , .

, :

void Java_MyClass_Solution(JNIEnv* env, jobject, jobject input, jobjectArray output)
{
    jsize nThumbnails = env->GetArrayLength(output) - 1;
    void* inputPtr = env->GetDirectBufferAddress(input);
    jlong inputLength = env->GetDirectBufferCapacity(input);

    // ...

    void* hash = ...; // a pointer to the hash data
    int hashDataLength = ...;
    void** thumbnails = ...; // an array of pointers, each one points to thumbnail data
    int* thumbnailDataLengths = ...; // an array of ints, each one is the length of the thumbnail data with the same index

    jobject hashBuffer = env->NewDirectByteBuffer(hash, hashDataLength);
    env->SetObjectArrayElement(output, 0, hashBuffer);

    for (int i = 0; i < nThumbnails; i++)
        env->SetObjectArrayElement(output, i + 1, env->NewDirectByteBuffer(thumbnails[i], thumbnailDataLengths[i]));
}

+2

All Articles