bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.43k stars 576 forks source link

Why are only ten callbacks allocated? #648

Open zhuker opened 1 year ago

zhuker commented 1 year ago

I am trying to create a wrapper around https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-c/ The client code uses callbacks heavily How do i use more than 10 at the same time? eg C:

/**
 * @brief RtcOnConnectionStateChange is fired to report a change in peer connection state.
 *
 * Reference: https://www.w3.org/TR/webrtc/#event-iceconnectionstatechange
 */
typedef VOID (*RtcOnConnectionStateChange)(UINT64, RTC_PEER_CONNECTION_STATE);

jni wrapper

static void (*JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callbacks[10])(UINT64 arg0, RTC_PEER_CONNECTION_STATE arg1) = {
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback1,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback2,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback3,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback4,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback5,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback6,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback7,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback8,
        JavaCPP_video_zhuker_kinesis_KinesisWebrtc_00024RtcOnConnectionStateChange_allocate_callback9 };
saudet commented 1 year ago

We can set that amount with the @Allocator(max=... annotation value: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/annotation/Allocator.html#max--

saudet commented 1 year ago

We can also create trampolines dynamically using libffi: https://github.com/bytedeco/javacpp-presets/tree/master/libffi It's slower though, and it's not as easy to use as the wrappers in JNA...

DemonJun commented 11 months ago

We can set that amount with the @Allocator(max=... annotation value: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/annotation/Allocator.html#max--

where is @Allocator should i use?

saudet commented 11 months ago

Like this: https://github.com/bytedeco/javacpp/blob/master/src/test/java/org/bytedeco/javacpp/PointerTest.java#L59