gstreamer-java / gst1-java-core

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

Support retrieving GstStructure values from GValuelist #211

Closed czaurel closed 3 years ago

czaurel commented 3 years ago

The facedetect plugin from gst-plugins-bad posts bus messages about detected faces which contain value lists of structures.

Trying to get the values via Structure.getValues(Class<T> type, String fieldName) results in an exception:

if (message.getStructure() != null && message.getStructure().hasField("faces")) {
    List<Structure> faces = message.getStructure().getValues(Structure.class, "faces");
}
->
org.freedesktop.gstreamer.Structure$InvalidFieldException: Structure does not contain Structure field 'faces'
    at org.freedesktop.gstreamer.Structure.getValues(Structure.java:462)

My current workaround was to use register(TypeRegistration<?> registration) for adding a registration like this: Natives.<Structure>registration(Structure.class, "GstStructure", Structure::new). This requires using a non-public API though.

If there is no other reason for omitting it, Gst.init() should probably register a type adapter like this in Gst.loadAllClasses(). I'm not exactly sure which TypeProvider should provide it though.

If this seems like a good idea, I'll throw together a PR.

neilcsmith-net commented 3 years ago

Thanks. Be interesting to see exactly where that's failing. If that fixes things for you then please feel free to add in https://github.com/gstreamer-java/gst1-java-core/blob/master/src/org/freedesktop/gstreamer/Gst.java#L670 There's one type provider per package, to keep the constructors package private. It should be listed there - that's a mistake. In general usage it's falling back to the old behaviour at https://github.com/gstreamer-java/gst1-java-core/blob/master/src/org/freedesktop/gstreamer/glib/NativeObject.java#L188

neilcsmith-net commented 3 years ago

Hopefully now fixed by #220 but not sure how best to test this issue. Please check with master before 1.3 release if you can - will close but can reopen if further issues seen. And if you have thoughts on a useful test, please suggest. Thanks!