0

We are making video stream application on java. We use JNI on h264 encode and decode , but the most big problem on java is All data must send from Java to JNI by copying. There is solution that is called ByteBuffers but on ByteBuffers when the data returned back to java. I need to return data back to byte[] for manupilating data.Again it is making copying.

There is ByteBuffer get method: ByteBuffer bb; ... bb.get(0); //but this is very slow to get data by index on the loops... byte data[] = new byte[bb.limit()]; bb.get(data); // this one is "copying" again to manupilating data.

So , i need to pass ByteBuffer to JNI method pass again to manupilating data without copying.

is there any solution to get byte[] from jni to java make data without copying ? I heard about GetPrimitiveArrayCritical , but some people call its freezing JVM Garbage collector.

What about mappedbytebuffer on java ? can we make shared data to use directly as byte[] array on java.

Kadir BASOL
  • 729
  • 2
  • 10
  • 20
  • possible duplicate of [Java JNI - associating resources allocated in C with java objects?](http://stackoverflow.com/questions/1998094/java-jni-associating-resources-allocated-in-c-with-java-objects) – Java42 Apr 29 '14 at 23:13
  • Not really , I want to manipulate JNI returned array from Java side without doing any copying or recreating anything.Seems like ByteBuffer is not solution.GetPrimitiveArrayCritical seems like solution but it freezes Garbage Collector.Any other solution? – Kadir BASOL Apr 29 '14 at 23:20

0 Answers0