Using OpenH264 DLL in C# Project

非 Y 不嫁゛ 提交于 2021-02-20 00:42:40

问题


I'm receiving an H264 stream over UDP. I'd like to decode the stream so I can send frames to OpenCV or whatever. I came across Cisco's open sourced H264 decoder here: https://github.com/cisco/openh264 With a little effort I got the decoder solution to build in Visual Studio 2019 and tested it from the command line with a file I created from the raw UDP datagrams. It works.

Now I want to figure out how to use the decoder DLL (welsdec.dll) in a C# project. The last time I did anything serious with C++ in Windows was back in the DirectShow and Delphi 5 days, so I'm completely lost.

Nothing in the H264 project is explicitly exported with __declspec(dllexport). Is that normal? Adding the DLL as a project reference to the C# project doesn't work ("the reference is invalid or unsupported").

I'm guessing the DLL is unmanaged. Can I consume that directly in C#? Am I going to have to rewrite the DLL as, or maybe or wrap it, in a C++ CX library to get this working?


回答1:


You can consume an unmanaged DLL in C# explicitly using PInvoke.

You can also write an intermediary DLL in C++/CLI to ease the invocations between your managed C# application and the native DLL. This is the approach taken by secile/OpenH264Lib.NET per stuartd's comment.

It looks like the H264 project uses module definition files (.def) in lieu of decorating exports with declspec. You should still be able to access these publicly exported functions using the above methods.



来源:https://stackoverflow.com/questions/56230212/using-openh264-dll-in-c-sharp-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!