MediaInfoLib icon indicating copy to clipboard operation
MediaInfoLib copied to clipboard

Rust wrapper and example

Open cjee21 opened this issue 2 months ago • 5 comments

Features

  • Bindings generator and Rust wrapper in Source\MediaInfoDLL\MediaInfoDLL-rs
  • Example in Source\Example\HowToUse_Dll-rs
  • Raw bindings are automatically generated from MediaInfoLib header during build
  • Rust wrapper is manually written to wrap raw bindings
  • Building the example will automatically generate and build everything required
  • The CI builds and test runs the Rust example using 7z package generated from MSBuild job for Windows x86-64/ARM64, using MediaInfoLib git plus libmediainfo-dev package from Ubuntu repo for Ubuntu x86-64 and using libmediainfo built/installed with CMake from MediaInfoLib git for MacOS.
  • Example accepts an optional filename as CLI argument or it will use Example.ogg by default
  • Supports Unicode (UTF-8) path input and text output
  • Tested on Windows 11 (x64/arm64), Ubuntu (amd64/aarch64) and MacOS (aarch64)

Limitations

  • Most (commonly used) but not all of the API have manually written wrapper. The remaining can be accessed via raw bindings.
  • Not all wrapped API have unit tests

Note

  • Stream=General and Parameter=90 is using 90 and not same as CPP one because the previous number produces no output.
  • Run cargo doc --open to generate and view HTML documentation.

cjee21 avatar Oct 07 '25 10:10 cjee21

@JeromeMartinez Noticed the official packages on MediaArea.net for x86/i386 does not contain *.lib files.

cjee21 avatar Oct 07 '25 10:10 cjee21

Does not work on Ubuntu. Need changes...

cjee21 avatar Oct 07 '25 15:10 cjee21

@JeromeMartinez is MediaInfo_int8u* Buffer in Open_Buffer_Continue supposed to be const? It is not marked a const and it looks like it is impossible to pass a read-only buffer from Rust to it unless manually doing a 'dangerous' cast.

cjee21 avatar Oct 08 '25 13:10 cjee21

is MediaInfo_int8u* Buffer in Open_Buffer_Continue supposed to be const?

It is const internally, and the C++ interface has the const, and the C interface redirects to the C++ interface., so we don't write at it, the cast would be OK (not sure we can add the "cast" to the interface without breaking the ABI).

JeromeMartinez avatar Oct 08 '25 14:10 JeromeMartinez

Running test_inform() and test_unicode() in parallel will randomly fail. Seems the option is affecting the other instance.


@JeromeMartinez MediaInfoList->Open(file, options), the options do not work. Seems DLL does not pass the option along.


Should be done. Some functions remain (that I do not know of their use) that not yet have Rust wrapper.

I added CI run for Rust code in this PR to test that it works on various OS and so that you can check the example output. If it is too much CI, I can add a variable to disable it.

cjee21 avatar Oct 08 '25 16:10 cjee21