You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.6 KiB
62 lines
2.6 KiB
using System.IO.Compression;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace EC.Util.CameraSDK;
|
|
|
|
public class CameraFactory
|
|
{
|
|
static CameraFactory()
|
|
{
|
|
string zipPath = Path.Combine("libs", "cameraSdks.zip");
|
|
if (!File.Exists(zipPath)) throw new FileNotFoundException(zipPath);
|
|
using ZipArchive archive = ZipFile.OpenRead(zipPath);
|
|
bool isWin = RuntimeInformation.IsOSPlatform(OSPlatform.Windows), is64 = Environment.Is64BitProcess;
|
|
string sysEnv = string.Format("{0}{1}", isWin ? "win" : "linux", is64 ? "64" : "32");
|
|
string hkOrDir = $"cameraSdks/hik/{sysEnv}/";
|
|
string dhOrDir = $"cameraSdks/dahua/{sysEnv}/";
|
|
string ysOrDir = $"cameraSdks/yushi/{sysEnv}/";
|
|
// TODO: linux chmod 777, LD_LIBRARY_PATH
|
|
foreach (ZipArchiveEntry entry in archive.Entries)
|
|
{
|
|
if (entry.Length == 0) continue;
|
|
string fullName = entry.FullName, fileExtPath = string.Empty;
|
|
if (fullName.StartsWith(hkOrDir))
|
|
fileExtPath = Path.Join("libs", "hik", fullName[(hkOrDir.Length - 1)..]);
|
|
else if (fullName.StartsWith(dhOrDir))
|
|
fileExtPath = Path.Join("libs", "dahua", fullName[(dhOrDir.Length - 1)..]);
|
|
else if (fullName.StartsWith(ysOrDir))
|
|
fileExtPath = Path.Join("libs", "yushi", fullName[(ysOrDir.Length - 1)..]);
|
|
if (string.IsNullOrEmpty(fileExtPath)) continue;
|
|
FileInfo fi = new(fileExtPath);
|
|
if (fi.Directory != null && !fi.Directory.Exists) fi.Directory.Create();
|
|
if (!fi.Exists) entry.ExtractToFile(fileExtPath);
|
|
}
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
string[] hikLibsName = new string[] { "libAudioRender.so", "libSuperRender.so" };
|
|
foreach (string name in hikLibsName)
|
|
{
|
|
if (File.Exists(Path.Join(".", name))) continue;
|
|
string path = Path.Join("libs", "hik", name);
|
|
FileInfo fi = new(path);
|
|
if (!fi.Exists) throw new FileNotFoundException(path);
|
|
fi.CopyTo(Path.Join(".", name), false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void VirtualInit()
|
|
{ }
|
|
|
|
public static ICameraSdk BuildCameraSdk(CameraInfo info)
|
|
{
|
|
ICameraSdk sdk = (info.Manufactor) switch
|
|
{
|
|
CameraManufactor.HiK => new HiKSdk(info),
|
|
CameraManufactor.DaHua => new DaHuaSdk(info),
|
|
CameraManufactor.YuShi => new YuShiSdk(info),
|
|
_ => throw new NotSupportedException(),
|
|
};
|
|
return sdk;
|
|
}
|
|
}
|