JNI Image Rendering
I have a problem regarding Java and C++. I want to write a Java application that can display the livestream of PTZ cameras and network cameras. It currently works but the algorithm is not very efficient. I have written a C++ library (compiled with Visual Studio 2005) that writes the image data of the cameras in BGR format into a shared memory in RAM. I think that there is a big overhead when trying to move this "unsinged char*" array into Java using "NewDirectByteBuffer".
My questions is now: Is it efficient to use JNI for such a realtime application? Would it be possible that too many JNI calls will slow down my application? The problem is that I will have to call JNI functions more than 25 times per second (because of an frame rate around of 25 FPS).
Thanks for any advices.
[805 byte] By [
thomas.ga] at [2007-11-26 21:20:29]

# 1
I am not going to look it up but if you have the correct method I don't believe it copies anything. It just keeps a pointer to it.
I have been told that java, at least as early as 1.5, supported mapped memory via the API.
Myself I haven't seen any evidence of that. But I haven't looked all that hard either. Somewhere in the file API I believe.
# 2
> I have a problem regarding Java and C++. I want to
> write a Java application that can display the
> livestream of PTZ cameras and network cameras. It
> currently works but the algorithm is not very
> efficient. I have written a C++ library (compiled
> with Visual Studio 2005) that writes the image data
> of the cameras in BGR format into a shared memory in
> RAM. I think that there is a big overhead when trying
> to move this "unsinged char*" array into Java using
> "NewDirectByteBuffer".
>
> My questions is now: Is it efficient to use JNI for
> such a realtime application? Would it be possible
> that too many JNI calls will slow down my
> application? The problem is that I will have to call
> JNI functions more than 25 times per second (because
> of an frame rate around of 25 FPS).
>
> Thanks for any advices.
Have you considered using the AWT Native Interface?
http://java.sun.com/j2se/1.5.0/docs/guide/awt/1.3/AWT_Native_Interface.html
Native painting on a Java application.
Incidentally, I used exactly this method for exactly the same purpose (4-up PTZ camera displays).
Jim S.