romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
493 stars 41 forks source link

Working with pointers #344

Open chfritz opened 1 year ago

chfritz commented 1 year ago

I know pointers are tricky, but I was hoping that you might have an idea how to work with function like gst_rtcp_buffer_map that are used to fill a variable with content:

gst_rtcp_buffer_map (GstBuffer *buffer, GstMapFlags flags, GstRTCPBuffer *rtcp)

I have a buffer that I got from RTPSession::on-feedback-rtcp and would like to map it to a RTCP buffer so I can read the content. Of course in C you would create a variable and then pass the address:

GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
gst_rtcp_buffer_map (buf, GST_MAP_READWRITE, &rtcp);

and then do what you want with rtcp. Is there any way I can do the same via node-gtk? I've tried

const rtcp = new GstRtp.RTCPBuffer(1500);
GstRtp.rtcpBufferMap(buffer, 1, rtcp);

But that just throws

(process:3961601): GStreamer-CRITICAL **: 20:55:52.809: gst_object_ref: assertion 'object != NULL' failed

on the first line and then seg fault on the second.

romgrk commented 1 year ago

I'm not familiar enough with the GST API to answer here, it's fairly hard to inspect GST bindings due to its dynamic nature.

What I would recommend is to find how to do what you're trying to do with another of the GIR bindings frameworks (e.g. PyGObject), and copy what that code is doing. If PyGObject can do it, then we can do it here. If not, then it might not be possible.

The problem with codebases that use macros is that C macros are not runtime inspectable, so sometimes some stuff needs to be manually binded. We have (semi)manual bindings for cairo, I wouldn't be averse to adding some for GST in small quantities.

romgrk commented 1 year ago

See if some of this documentation can help, or try to find code examples for that use-case for PyGObject. If none of that works, provide a runnable code example and I could try to inspect what's the type of GstRTCPBuffer, from there I can debug further.