gstreamer-java / gst1-java-core

Java bindings for GStreamer 1.x
GNU Lesser General Public License v3.0
188 stars 72 forks source link

get() on WebRTCBin causes java.lang.InstantiationException #240

Open suCRR opened 3 years ago

suCRR commented 3 years ago

Hi,

I'm trying to get the ice-agent of on webRTCBin. This property is quite new (I don't know the exact gst version) and most probably isn't known within the java bindings. The property is type of GstWebRTCICE class and I couldn't find a GstWebRTCICE class within the java binding code.

webRTCBin = new WebRTCBin("sendonly"); Object agent = webRTCBin.get("ice-agent");

causes:

java.lang.RuntimeException: java.lang.InstantiationException at org.freedesktop.gstreamer.glib.NativeObject.objectFor(NativeObject.java:195) at org.freedesktop.gstreamer.glib.Natives.objectFor(Natives.java:166) at org.freedesktop.gstreamer.glib.Natives.callerOwnsReturn(Natives.java:140) at org.freedesktop.gstreamer.lowlevel.GTypeMapper$2.fromNative(GTypeMapper.java:113) at com.sun.jna.Function.invoke(Function.java:369) at com.sun.jna.Library$Handler.invoke(Library.java:244) at com.sun.proxy.$Proxy18.g_value_dup_object(Unknown Source) at org.freedesktop.gstreamer.glib.GObject.get(GObject.java:194)

Is there any workaround for this? How could a implement a binding for GstWebRTCICE?

BR Clemens

neilcsmith-net commented 3 years ago

You can register your own mappings by implementing `NativeObject.TypeProvider (eg. like https://github.com/gstreamer-java/gst1-java-core/blob/master/src/org/freedesktop/gstreamer/webrtc/WebRTC.java#L33 ) and registering it to be picked up by ServiceLoader

However, this should be giving you a GstObject already in the mapping, so might be a bug that needs looking at. Or the hierarchy of the GType has changed? There is a problem with GObject being abstract, but the docs at https://gstreamer.freedesktop.org/documentation/webrtc/index.html?gi-language=c#GstWebRTCICE suggest GstObject. If you add a mapping, make sure it extends GstObject.

This might be better discussed on the mailing list - might get more people to see / comment there. Then we can follow up if there's an issue to fix, or features to add.

gpr-indevelopment commented 2 years ago

I have been having the same problem while calling get() on a property of a GObject that cannot be mapped to a GType. The underlying code tries to instantiate the property with the constructor from GObject, which will always fail because it is abstract.

@neilcsmith-net mentioned that GstObject should be picked up automatically, but it is not happening. I am trying to retrieve a sender object: https://gstreamer.freedesktop.org/documentation/webrtclib/gst-libs/gst/webrtc/webrtc-priv.html?gi-language=c#GstWebRTCRTPSender

Tested with version 0.94 and 1.4 of the Java bindings.

Will try registering a mapping like suggested to see if it works

neilcsmith-net commented 2 years ago

@gpr-indevelopment can you share a simple example that shows the problem you're facing exactly? That type should be a GstObject so shouldn't be affected by GObject being abstract. Need to look more in depth at what is happening.

gpr-indevelopment commented 2 years ago

@neilcsmith-net Sure! Sorry for taking this long.

I have an active unidirectional video stream going from my server to a browser client. In this example the pipeline is playing. I tried calling get on "sender" since it is listed under listPropertyNames method of the transceiver. The error happens when:

GstObject transceiver = webRtcBin.emit(GstObject.class, "get-transceiver", 0); // This returns a valid object
transceiver.get("sender"); // Throws InstantiationException
gpr-indevelopment commented 2 years ago

@neilcsmith-net actually registering a new mapping for GstWebRTCICE like you suggested did the trick, and the java.lang.InstantiationException doesnt happen anymore.

You can register your own mappings by implementing `NativeObject.TypeProvider (eg. like https://github.com/gstreamer-java/gst1-java-core/blob/master/src/org/freedesktop/gstreamer/webrtc/WebRTC.java#L33 ) and registering it to be picked up by ServiceLoader

However, this should be giving you a GstObject already in the mapping, so might be a bug that needs looking at. Or the hierarchy of the GType has changed? There is a problem with GObject being abstract, but the docs at https://gstreamer.freedesktop.org/documentation/webrtc/index.html?gi-language=c#GstWebRTCICE suggest GstObject. If you add a mapping, make sure it extends GstObject.

This might be better discussed on the mailing list - might get more people to see / comment there. Then we can follow up if there's an issue to fix, or features to add.

lionelmazeyrat commented 1 year ago

@gpr-indevelopment could you please post the example code to register the mapping for GstWebRTCICE. I try to emit "add-local-ip-address" and to set add min-rtp-port/max-rtp-port

GstWebRTCICE GObject.Object ╰──GObject.InitiallyUnowned ╰──Gst.Object ╰──GstWebRTCICE Action Signals add-local-ip-address let ret = object.emit ("add-local-ip-address", address);