Skip to content

Resolve native libraries at runtime rather than at compile time #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Examples/AVRecord/AVRecord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
<ProjectReference Include="..\..\H264Sharp\H264Sharp.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="H264SharpNative-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="openh264-2.4.1-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\H264Sharp\runtimes\win-x86\**\*">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\H264Sharp\runtimes\win-x64\**\*">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file removed Examples/AVRecord/H264SharpNative-win64.dll
Binary file not shown.
Binary file removed Examples/AVRecord/openh264-2.4.1-win64.dll
Binary file not shown.
23 changes: 8 additions & 15 deletions Examples/CrossPlatformTest/CrossPlatformTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="H264Sharp">
<HintPath>H264Sharp.dll</HintPath>
</Reference>
<ProjectReference Include="..\..\H264Sharp\H264Sharp.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\H264Sharp\runtimes\**\*">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Update="H264Sharp.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="H264SharpNative-linux64.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="H264SharpNative-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="libopenh264-2.4.1-linux64.7.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="RawBgr.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Binary file removed Examples/CrossPlatformTest/H264Sharp.dll
Binary file not shown.
Binary file not shown.
17 changes: 11 additions & 6 deletions Examples/H264SharpNativePInvoke/H264SharpNativePInvoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
</ItemGroup>

<ItemGroup>
<None Update="H264SharpNative-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ocean 1280x720.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -41,8 +38,16 @@
<None Update="ocean1080.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="openh264-2.4.1-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Include="..\..\H264Sharp\runtimes\win-x86\**\*">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\H264Sharp\runtimes\win-x64\**\*">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
20 changes: 18 additions & 2 deletions Examples/H264SharpNativePInvoke/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@ static void Main(string[] args)
{
// You can change version or specify the path for cisco dll.

//Defines.CiscoDllName64bit = "openh264-2.4.0-win64.dll";
//Defines.CiscoDllName32bit = "openh264-2.4.0-win32.dll";
//string ciscoDll = "";
//switch (RuntimeScanApi.OperatingSystem)
//{
// case H264Sharp.OperatingSystem.Windows:
// ciscoDll = RuntimeScanApi.Is64BitProcess
// ? "openh264-2.4.0-win64.dll"
// : "openh264-2.4.0-win32.dll";
// break;
// case H264Sharp.OperatingSystem.Linux:
// ciscoDll = RuntimeScanApi.Is64BitProcess
// ? "libopenh264-2.4.1-linux64.7.so"
// : "libopenh264-2.4.1-linux32.7.so";
// break;
// default:
// throw new NotSupportedException($"{RuntimeScanApi.OperatingSystem} OS is not supported");
//}
//H264Encoder encoder = new H264Encoder(ciscoDll);
//H264Decoder decoder = new H264Decoder(ciscoDll);

H264Encoder encoder = new H264Encoder();
H264Decoder decoder = new H264Decoder();
Expand Down
Binary file not shown.
59 changes: 3 additions & 56 deletions H264Sharp/Converter.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
using System;
using System.Runtime.InteropServices;

namespace H264Sharp
{
public class Converter
{
//todo
[DllImport(Defines.WrapperDllName64bit, EntryPoint = "GetDecoder", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
private static extern void RGBtoYUVx64(ref RGBImagePointer rgb, ref YUVImagePointer yuv, int numThreads);

[DllImport(Defines.WrapperDllName32bit, EntryPoint = "DecodeAsRGB", CallingConvention = CallingConvention.Cdecl)]
private static extern void RGBtoYUVx86( ref RGBImagePointer rgb, ref YUVImagePointer yuv,int numThreads);

[DllImport(Defines.WrapperDllName64bit, EntryPoint = "GetDecoder", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
private static extern void YUV2RGBx64(ref YUVImagePointer rgb, ref RGBImagePointer yuv, int numThreads);

[DllImport(Defines.WrapperDllName32bit, EntryPoint = "DecodeAsRGB", CallingConvention = CallingConvention.Cdecl)]
private static extern void YUV2RGBx86(ref YUVImagePointer rgb, ref RGBImagePointer yuv, int numThreads);
//

[DllImport(Defines.WrapperDllName32bit, EntryPoint = "DownscaleImg", CallingConvention = CallingConvention.Cdecl)]
private static extern void DownscaleImgx86(ref UnsafeGenericImage from, ref UnsafeGenericImage to, int mul);

[DllImport(Defines.WrapperDllName64bit, EntryPoint = "DownscaleImg", CallingConvention = CallingConvention.Cdecl)]
private static extern void DownscaleImgx64(ref UnsafeGenericImage from, ref UnsafeGenericImage to, int mul);



private readonly bool x64 = Environment.Is64BitProcess;

public void Downscale(ImageData from, RgbImage to, int multiplier)
{
unsafe
Expand All @@ -54,15 +29,7 @@ public void Downscale(ImageData from, RgbImage to, int multiplier)
t.Stride = from.Stride;
t.ImgType = ImageType.Rgb;

if (x64)
{
DownscaleImgx64(ref ugi, ref t, multiplier);
}
else
{
DownscaleImgx86(ref ugi, ref t, multiplier);
}

H264NativeApi.DownscaleImg(ref ugi, ref t, multiplier);
}
}
else
Expand All @@ -85,29 +52,9 @@ public void Downscale(ImageData from, RgbImage to, int multiplier)
t.Stride = from.Stride;
t.ImgType = ImageType.Rgb;

if (x64)
{
DownscaleImgx64(ref ugi, ref t, multiplier);
}
else
{
DownscaleImgx86(ref ugi, ref t, multiplier);
}
H264NativeApi.DownscaleImg(ref ugi, ref t, multiplier);
}



}

}





}

}



}
36 changes: 18 additions & 18 deletions H264Sharp/Defines.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
//#define OS_LINUX
//#undef OS_WINDOWS
namespace H264Sharp
namespace H264Sharp
{
public class Defines
{
#if OS_WINDOWS
public static string CiscoDllName64bit = "openh264-2.4.1-win64.dll";
public static string CiscoDllName32bit = "openh264-2.4.1-win32.dll";
#region WrapperDll

public const string WrapperDllName64bit = "H264SharpNative-win64.dll";
public const string WrapperDllName32bit = "H264SharpNative-win32.dll";
#elif OS_LINUX
public static string CiscoDllName64bit = "./libopenh264-2.4.1-linux64.7.so";
public static string CiscoDllName32bit = "./libopenh264-2.4.1-linux32.7.so";
public const string WrapperDll = "H264SharpNativeLib";

public const string WrapperDllName64bit = "H264SharpNative-linux64.so";
public const string WrapperDllName32bit = "H264SharpNative-linux32.so";
#elif OS_FREEBSD
// FreeBSD-specific dll
#elif OS_MAC
// Mac-specific dll
#endif
public const string WrapperDllWin64 = "H264SharpNative-win64.dll";
public const string WrapperDllWin32 = "H264SharpNative-win32.dll";

public const string WrapperDllLinux64 = "H264SharpNative-linux64.so";
public const string WrapperDllLinux32 = "H264SharpNative-linux32.so";

#endregion

#region CiscoDll

public const string CiscoDllWin64 = "openh264-2.4.1-win64.dll";
public const string CiscoDllWin32 = "openh264-2.4.1-win32.dll";

public const string CiscoDllLinux64 = "libopenh264-2.4.1-linux64.7.so";
public const string CiscoDllLinux32 = "libopenh264-2.4.1-linux32.7.so";

#endregion
}
}
Loading