Is there a way to use GstCuda from Rust?

I have a GStreamer application in C++ that uses NVCODEC for decoding a video stream and GstCuda to extract pointers to CUDA memory and pass them to Libtorch.

I would like to rewrite this application in Rust. I can use NVCODEC elements, and there are nice Rust bindings to Libtorch, but I am having troubles finding GstCuda bindings to grab these pointers as I do in the C API. Is there a reason they weren’t picked up by introspection? Is there a way I could add it myself?

Thank you!

The Rust binding for the GstCuda library have not been generated yet, we just need someone to do the work and you are welcome to start the work on adding gstreamer-cuda to gstreamer-rs!

For the time being you can also directly call the C API via FFI, as with any C library’s API. Writing proper bindings would of course be better but also more work.

Great, thank you both! I will experiment with this and hopefully contribute something :slight_smile:

I was looking through gstreamer-gl for inspiration, but to be honest, I’m not sure how I would go about e.g. generating Gir.toml. Is there any tutorials or beginner PRs that could give me some introduction to writing such bindings? I’m happy to contribute, just not sure where to start!

Does the FFI also have to generated like in How would I go about doing it? Or did you mean using Rust FFI libraries separately from gstreamer-rs?

Edit: I believe what I am looking for is generating .gir files with GObject introspection from the C API and then using gtk-rs/gir to generate Rust bindings, which can be either safe abstracted or unsafe FFI. And hopefully the unsafe FFI should work, while the safe does not generate. But how to go about making the safe one work?

Check Introduction - Generate Rust bindings for GIR based libraries. However, creating bindings requires quite a bit of knowledge about GObject and the underlying C library (and how it’s supposed to be used).

For GObject-based libraries I would recommend using gir, for anything else bindgen.

As CUDA is very low-level, I would start with trying to use the FFI bindings and writing the code like you would do in C. Then you can figure out how to wrap that in safe bindings, if possible / useful at all.

How does it fail? I expect there to be quite a few obstacles because of CUDA.