Hi,
We are using SRT commands in shell scripts call by Python and Java programs...
But it would be interesting to have a binding (or a native implementation !) in both this languages, it should offer better integration and direct usage of stream connection, statistics...
Thanks to take this in consideration,
Best regards
C. Mourad Jaber
Java has JNI support so you can easily load SRT libs and call srt functions from srt.h.
I'm sure you can do the same from python
Not that you asked for this language, but the title might make other walk down this road - I made an experimental wrapper for C# - you can see this here:
https://github.com/Cinegy/Cinegy.SRT
It was never taken to production levels, but would be a great start for anyone that is trying to use this from .NET
I went the hard way and made a managed c++ wrapper around the library.
Check out GitHub.com/cinegy and you should see my c# 'SRTAnalyser' project
that uses the library (and the library, but I forget what I called it).
It not very fully featured, but it lets you catch a stream :)
Lewis
On Fri, 3 May 2019, 17:57 Nick Drouin, notifications@github.com wrote:
Has anyone gone down the road of attempting to use SWIG
http://www.swig.org or CppSharp https://github.com/mono/CppSharp to
auto-gen srt.h into C#/PInvoke targeting .Net Core (or Standard)?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Haivision/srt/issues/239#issuecomment-489166255, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAOAVMBNQJWIWJRDFCX5SJ3PTRVIDANCNFSM4ENN2ZVA
.
Thanks Lewis, I did have a look prior to going down the auto-gen road, however, I was looking for cross platform: .Net Core (versus .Net Framework). I was also a bit weary of my ability to getting the type marshaling correct. ;)
Reporting back my progress: I was able to create a SWIG binding for CSharp.
From that, I create a .Net Standard dll, which I was able to include in a .Net Core project. From there I can call into LibSrt on both linux and windows.
To do this, the following was added after the SRT_API definition in srt.h (currently line 65):
#ifdef SWIG
/*
To automatically generate bindings via SWIG (http://www.swig.org)
Install swig via the following (or use Windows instructions from the link above):
sudo apt install swig
Generate the bindings using:
mkdir srtcore/bindings/csharp -p
swig -v -csharp -outdir ./srtcore/bindings/csharp/ ./srtcore/srt.h
Create a .Net Standard class library with:
cd srtcore/bindings/csharp
dotnet new classlib -n srtsharp
You can now reference the srtsharp lib in your .Net Core projects. Ensure the srtlib.so (or srt.dll) is in the binary path of your .NetCore project.
*/
%module srt
%{
// BUG: The generated file SRT_ERRNO.cs has errors, it does not prefix the referenced enums from CodeMajor.cs and CodeMinor.cs
// BUG: The generated code has no namespace.
#include "srt.h"
%}
// Remove SRT_API definition when using SWIG
#undef SRT_API
#define SRT_API
#endif
As you will read, the SWIG auto-gen is not (yet) clean, but it was very straight-forward. When I have it auto-generating bug-free, I'll propose a PR with the above. I do question if the ./bindings/csharp/[files] should be part of the PR as well -- which is more of a philosophical question for the SRT project.
In addition to the code above, libsrt (srt.dll) needs to include the generated srt_wrap.c: it is added to filelist.maf. The new srt_wrap.c publicly exposes it's own functions, these work with the srt.cs that is generated to correctly marshal objects across the language boundary.
@newbeewan : The above should work with Python.
Apologies for opening an old thread - but i decided to finally review this strategy to look for a solid cross-platform story.
Thanks to the helpful information above, i have got this working - however, i'm not very happy with my implementation.
I hand-crafted a few adjustments on the P/Invokes - but to create the SWIGTYPE_p_sockaddr that is used to pass in address information for the socket, i had to use Marshal.StructureToPtr - which is marked obsolete and I can't easily see what is supposed to replace it.
@NickDrouin did you get much further with this? You comment mentioned everything was a bit of a WIP - I would certainly like to help push this up to 'production' level, and would be happy to get rid of my dead-end managed C++
Most helpful comment
Not that you asked for this language, but the title might make other walk down this road - I made an experimental wrapper for C# - you can see this here:
https://github.com/Cinegy/Cinegy.SRT
It was never taken to production levels, but would be a great start for anyone that is trying to use this from .NET