20240125
This commit is contained in:
parent
98d0761a19
commit
b3f5b23a49
|
@ -8,13 +8,19 @@ EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Debug|x86.Build.0 = Debug|x86
|
||||||
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{4B2B07A3-B601-414A-9B90-E5228C3E55AD}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
<PublishAot>true</PublishAot>
|
<PublishAot>true</PublishAot>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -18,13 +19,14 @@
|
||||||
<Compile Remove="Utils\._JsonUtils.cs" />
|
<Compile Remove="Utils\._JsonUtils.cs" />
|
||||||
<Compile Remove="Utils\._LiteDBUtils.cs" />
|
<Compile Remove="Utils\._LiteDBUtils.cs" />
|
||||||
<Compile Remove="Utils\._LogUtils.cs" />
|
<Compile Remove="Utils\._LogUtils.cs" />
|
||||||
|
<Compile Remove="Utils\._ProcessUtils.cs" />
|
||||||
<Compile Remove="Utils\._SQLiteUtils.cs" />
|
<Compile Remove="Utils\._SQLiteUtils.cs" />
|
||||||
<Compile Remove="Utils\._TaskUtils.cs" />
|
<Compile Remove="Utils\._TaskUtils.cs" />
|
||||||
<Compile Remove="Utils\._UdpClientUtils.cs" />
|
<Compile Remove="Utils\._UdpClientUtils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LiteDB.Async" Version="0.1.7" />
|
<PackageReference Include="LiteDB" Version="5.0.17" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,6 @@
|
||||||
|
using HxServer.Utils;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Net;
|
|
||||||
using HxServer.Utils;
|
|
||||||
using System.Data.SqlTypes;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
using System.Data;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Channels;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using LiteDB;
|
using LiteDB;
|
||||||
using LiteDB.Async;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
||||||
namespace HxServer.Peripheral
|
namespace HxServer.Peripheral
|
||||||
{
|
{
|
||||||
|
@ -51,7 +34,7 @@ namespace HxServer.Peripheral
|
||||||
public DateTime StartTime { get; set; }
|
public DateTime StartTime { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "end_time")]
|
[JsonProperty(PropertyName = "end_time")]
|
||||||
public DateTime EndTime { get; set; }
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "duration")]
|
[JsonProperty(PropertyName = "duration")]
|
||||||
public int Duration { get; set; }
|
public int Duration { get; set; }
|
||||||
|
@ -61,88 +44,102 @@ namespace HxServer.Peripheral
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "path")]
|
[JsonProperty(PropertyName = "path")]
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
public static HxVideoRecord Build(Dictionary<string, object> dictionary)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Channel = Convert.ToInt32(dictionary["channel"]),
|
||||||
|
StartTime = Convert.ToDateTime(dictionary["start_time"]),
|
||||||
|
EndTime = string.IsNullOrEmpty(dictionary["end_time"].ToString()) ? DateTime.MinValue : Convert.ToDateTime(dictionary["end_time"]),
|
||||||
|
Duration = Convert.ToInt32(dictionary["duration"]),
|
||||||
|
Name = dictionary["name"].ToString(),
|
||||||
|
Path = dictionary["path"].ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DataBase
|
public class DataBase
|
||||||
{
|
{
|
||||||
private const string filename = "HxNvr.DataBase.db";
|
private static LiteDatabase Database { get; set; }
|
||||||
|
|
||||||
// 打开数据库 (如果不存在则创建)
|
private static ConnectionString ConnectionString => new() { Filename = "HxNvr.DataBase.db", Connection = ConnectionType.Shared, };
|
||||||
private static LiteDatabaseAsync database { get; set; } = new(@"HxNvr.DataBase.db");
|
|
||||||
|
|
||||||
//private static SQLiteCommand InsertLogCommand = new("INSERT INTO [Log] ([timestamp], [type], [index], [message], [data]) VALUES (@timestamp, @type, @index, @message, @data); SELECT LAST_INSERT_ROWID();");
|
|
||||||
|
|
||||||
public static void Initialization()
|
public static void Initialization()
|
||||||
{
|
{
|
||||||
var collection = database.GetCollection<HxSetting>("Settings");
|
Database = new(ConnectionString);
|
||||||
var array = collection.FindAllAsync().Result;
|
|
||||||
if (array.Count() == 0)
|
var collection = Database.GetCollection<HxSetting>("Settings");
|
||||||
|
var array = collection.FindAll();
|
||||||
|
if (!array.Any())
|
||||||
{
|
{
|
||||||
collection.InsertAsync(new HxSetting() { Name = "code", Value = "TVIS" });
|
collection.InsertBulk(new List<HxSetting>()
|
||||||
collection.InsertAsync(new HxSetting() { Name = "recording_split_time", Value = "10" });
|
{
|
||||||
collection.InsertAsync(new HxSetting() { Name = "recording_reserver_time", Value = "15" });
|
new() { Name = "code", Value = "TVIS" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "drive_threshold", Value = "10" });
|
new() { Name = "recording_split_time", Value = "10" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "is_cleanup_enabled", Value = "1" });
|
new() { Name = "recording_reserver_time", Value = "15" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "is_cleanup_forced_for_reserve_time", Value = "0" });
|
new() { Name = "drive_threshold", Value = "10" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "disks", Value = "/home/hehaoyang/harddisk1;D://" });
|
new() { Name = "is_cleanup_enabled", Value = "1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_00", Value = "0;通道 01;Bsm;teweishi.oicp.net;554;1;15;1;1;0" });
|
new() { Name = "is_cleanup_forced_for_reserve_time", Value = "0" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_01", Value = "1;通道 02;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "disks", Value = "/home/hehaoyang/harddisk1;/root;D:/" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_02", Value = "2;通道 03;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_00", Value = "0;通道 01;AHV;127.0.0.1;8554;0;1;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_03", Value = "3;通道 04;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_01", Value = "1;通道 02;AHV;127.0.0.1;8554;1;1;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_04", Value = "4;通道 05;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_02", Value = "2;通道 03;AHV;127.0.0.1;8554;2;1;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_05", Value = "5;通道 06;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_03", Value = "3;通道 04;AHV;127.0.0.1;8554;3;1;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_06", Value = "6;通道 07;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_04", Value = "4;通道 05;Bsm;192.168.10.105;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_07", Value = "7;通道 08;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_05", Value = "5;通道 06;Bsm;192.168.10.106;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_08", Value = "8;通道 09;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_06", Value = "6;通道 07;Bsm;192.168.10.107;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_09", Value = "9;通道 10;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_07", Value = "7;通道 08;Bsm;192.168.10.108;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_10", Value = "10;通道 11;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_08", Value = "8;通道 09;Bsm;192.168.10.109;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_11", Value = "11;通道 12;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_09", Value = "9;通道 10;Bsm;192.168.10.110;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_12", Value = "12;通道 13;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_10", Value = "10;通道 11;Bsm;192.168.10.111;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_13", Value = "13;通道 14;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_11", Value = "11;通道 12;Bsm;192.168.10.112;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_14", Value = "14;通道 15;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_12", Value = "12;通道 13;Bsm;192.168.10.113;554;0;0;1" },
|
||||||
collection.InsertAsync(new HxSetting() { Name = "channel_15", Value = "15;通道 16;Bsm;192.168.10.101;554;1;15;0;1;0" });
|
new() { Name = "channel_13", Value = "13;通道 14;Bsm;192.168.10.114;554;0;0;1" },
|
||||||
|
new() { Name = "channel_14", Value = "14;通道 15;Bsm;192.168.10.115;554;0;0;1" },
|
||||||
|
new() { Name = "channel_15", Value = "15;通道 16;Bsm;192.168.10.116;554;0;0;1" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Dictionary<string, string> ReadSettings()
|
public static Dictionary<string, string> ReadSettings()
|
||||||
{
|
{
|
||||||
Dictionary<string, string> keyValuePairs = [];
|
Dictionary<string, string> keyValuePairs = [];
|
||||||
|
|
||||||
/* 打开表 */
|
var collection = Database.GetCollection<HxSetting>("Settings");
|
||||||
var collection = database.GetCollection<HxSetting>("Settings");
|
|
||||||
|
|
||||||
var array = collection.FindAllAsync().Result;
|
var array = collection.FindAll();
|
||||||
|
|
||||||
/* 查询所有数据 */
|
|
||||||
foreach (var c in array)
|
foreach (var c in array)
|
||||||
keyValuePairs.Add(c.Name, c.Value);
|
keyValuePairs.Add(c.Name, c.Value);
|
||||||
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"读取设置信息");
|
||||||
|
|
||||||
return keyValuePairs;
|
return keyValuePairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void WriteLogger(DateTime timestamp, int type, int index, string message, string data)
|
public static void WriteLogger(DateTime timestamp, int type, int index, string message, string data)
|
||||||
{
|
{
|
||||||
/* 打开表 */
|
var collection = Database.GetCollection<HxLog>("Log");
|
||||||
var collection = database.GetCollection<HxLog>("Log");
|
|
||||||
|
|
||||||
/* 插入数据 */
|
var res = collection.Insert(new HxLog() { Timestamp = timestamp, Type = type, Index = index, Message = message, Data = data });
|
||||||
await collection.InsertAsync(new HxLog() { Timestamp = timestamp, Type = type, Index = index, Message = message, Data = data });
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"写入日志数据: {message} {data}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<HxVideoRecord> QueryFirstRecord()
|
public static List<HxVideoRecord> QueryFirstRecord()
|
||||||
{
|
{
|
||||||
List<HxVideoRecord> records = [];
|
List<HxVideoRecord> records = [];
|
||||||
|
|
||||||
/* 打开表 */
|
var collection = Database.GetCollection<HxVideoRecord>("Records");
|
||||||
var collection = database.GetCollection<HxVideoRecord>("Records");
|
|
||||||
|
|
||||||
var record = collection.FindOneAsync(x=> !string.IsNullOrEmpty(x.Name)).Result;
|
var record = collection.FindOne(x => !string.IsNullOrEmpty(x.Name));
|
||||||
|
|
||||||
if (record != null)
|
if (record != null)
|
||||||
records.Add(record);
|
records.Add(record);
|
||||||
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"查询第一条录像记录: res = {(records.Count == 0 ? "NULL" : records[0].Name)}");
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,28 +147,50 @@ namespace HxServer.Peripheral
|
||||||
{
|
{
|
||||||
List<HxVideoRecord> records = [];
|
List<HxVideoRecord> records = [];
|
||||||
|
|
||||||
///* 打开表 */
|
try
|
||||||
//var collection = LiteDBUtils.GetCollection<HxVideoRecord>(filename, "Records");
|
{
|
||||||
|
var collection = Database.GetCollection<HxVideoRecord>("Records");
|
||||||
|
var result = collection.Find(x => x.StartTime.Date.CompareTo(date.Date) == 0);
|
||||||
|
if (result == null)
|
||||||
|
records = result.ToList();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
//records = collection.Find(x => x.StartTime.Date.CompareTo(date.Date) == 0).ToList();
|
DebugTrace.WriteLine(nameof(DataBase), $"查询录像日志记录: res = {records.Count}");
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReplaceRecord(int channel, DateTime start_time, DateTime end_time, int duration, string name, string path)
|
public static void ReplaceRecord(HxVideoRecord record)
|
||||||
{
|
{
|
||||||
///* 打开表 */
|
var collection = Database.GetCollection<HxVideoRecord>("Records");
|
||||||
//var collection = LiteDBUtils.GetCollection<HxVideoRecord>(filename, "Records");
|
|
||||||
|
|
||||||
//collection.Update(new HxVideoRecord() { Channel = channel, StartTime = start_time, EndTime = end_time, Duration = duration, Name = name, Path = path });
|
var _record = collection.FindOne(x => x.Name == record.Name);
|
||||||
|
|
||||||
|
if (_record == null)
|
||||||
|
{
|
||||||
|
collection.Insert(record);
|
||||||
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"插入录像日志记录: {record.Name}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_record.EndTime = record.EndTime;
|
||||||
|
_record.Duration = record.Duration;
|
||||||
|
|
||||||
|
collection.Update(_record);
|
||||||
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"更新录像日志记录: {record.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteRecordByPath(string path)
|
public static void DeleteRecordByPath(string path)
|
||||||
{
|
{
|
||||||
///* 打开表 */
|
var collection = Database.GetCollection<HxVideoRecord>("Records");
|
||||||
//var collection = LiteDBUtils.GetCollection<HxVideoRecord>(filename, "Records");
|
|
||||||
|
|
||||||
//var record = collection.DeleteMany(x => x.Path == path);
|
int res = collection.DeleteMany(x => x.Path == path);
|
||||||
|
|
||||||
|
DebugTrace.WriteLine(nameof(DataBase), $"删除录像日志记录, {path}" + (res == 0 ? "删除失败" : "删除成功"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,12 +75,12 @@ public class MonitorServer
|
||||||
|
|
||||||
var buffer = UdpClient.EndReceive(ar, ref point);
|
var buffer = UdpClient.EndReceive(ar, ref point);
|
||||||
|
|
||||||
TaskUtils.Run(Process, buffer, point);
|
TaskUtils.Run(UdpDataProcess, buffer, point);
|
||||||
|
|
||||||
UdpClient.BeginReceive(RequestCallback, null);
|
UdpClient.BeginReceive(RequestCallback, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Process(byte[] buffer, IPEndPoint point)
|
private static void UdpDataProcess(byte[] buffer, IPEndPoint point)
|
||||||
{
|
{
|
||||||
if (buffer.Length > 0)
|
if (buffer.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -94,9 +94,6 @@ public class MonitorServer
|
||||||
switch (model.ActionType)
|
switch (model.ActionType)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (dictionary == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
UpdateAppInfos(dictionary["name"].ToString(), dictionary["version"].ToString(), point);
|
UpdateAppInfos(dictionary["name"].ToString(), dictionary["version"].ToString(), point);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -113,51 +110,43 @@ public class MonitorServer
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if (dictionary == null)
|
{
|
||||||
return;
|
|
||||||
|
|
||||||
DataBase.WriteLogger(Convert.ToDateTime(dictionary["timestamp"]),
|
DataBase.WriteLogger(Convert.ToDateTime(dictionary["timestamp"]),
|
||||||
Convert.ToInt32(dictionary["type"]),
|
Convert.ToInt32(dictionary["type"]),
|
||||||
Convert.ToInt32(dictionary["index"]),
|
Convert.ToInt32(dictionary["index"]),
|
||||||
dictionary["message"].ToString(),
|
dictionary["message"].ToString(),
|
||||||
dictionary["data"].ToString());
|
dictionary["data"].ToString());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
if (dictionary == null || dictionary.Count == 0)
|
{
|
||||||
|
if (dictionary.Count == 0)
|
||||||
{
|
{
|
||||||
UdpClient.Send(point, new Model(5, DataBase.QueryFirstRecord()));
|
UdpClient.Send(point, new Model(5, DataBase.QueryFirstRecord()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (dictionary.ContainsKey("date"))
|
if (dictionary.TryGetValue("date", out object value))
|
||||||
UdpClient.Send(point, new Model(5, DataBase.QueryRecord(Convert.ToDateTime(dictionary["date"].ToString()))));
|
UdpClient.Send(point, new Model(5, DataBase.QueryRecord(Convert.ToDateTime(value.ToString()))));
|
||||||
else
|
else
|
||||||
UdpClient.Send(point, new Model(5, DataBase.QueryRecord(Convert.ToDateTime(dictionary["start_date"].ToString()))));
|
UdpClient.Send(point, new Model(5, DataBase.QueryRecord(Convert.ToDateTime(dictionary["start_date"].ToString()))));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
if (dictionary == null)
|
DataBase.ReplaceRecord(HxVideoRecord.Build(dictionary));
|
||||||
return;
|
|
||||||
|
|
||||||
DataBase.ReplaceRecord(Convert.ToInt32(dictionary["channel"]),
|
|
||||||
Convert.ToDateTime(dictionary["start_time"]),
|
|
||||||
Convert.ToDateTime(dictionary["end_time"]),
|
|
||||||
Convert.ToInt32(dictionary["duration"]),
|
|
||||||
dictionary["name"].ToString(),
|
|
||||||
dictionary["path"].ToString());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
if (dictionary == null)
|
{
|
||||||
return;
|
if (dictionary.TryGetValue("path", out object value))
|
||||||
|
DataBase.DeleteRecordByPath(value.ToString());
|
||||||
if (dictionary.ContainsKey("path"))
|
|
||||||
DataBase.DeleteRecordByPath(dictionary["path"].ToString());
|
|
||||||
//else if (dictionary.ContainsKey("date"))
|
//else if (dictionary.ContainsKey("date"))
|
||||||
// DataBase.DeleteRecord("date", dictionary["date"].ToString());
|
// DataBase.DeleteRecord("date", dictionary["date"].ToString());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +179,23 @@ public class MonitorServer
|
||||||
{
|
{
|
||||||
if (DateTime.Now - app.DateTime >= TimeSpan.FromSeconds(10))
|
if (DateTime.Now - app.DateTime >= TimeSpan.FromSeconds(10))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{app.Name} Reboot");
|
var process = Process.GetProcessesByName(app.Name);
|
||||||
|
|
||||||
|
/* 若进程不存在, 启动进程 */
|
||||||
|
if (process.Length == 0)
|
||||||
|
{
|
||||||
|
Process.Start(app.Path);
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// process[0].Kill();
|
||||||
|
|
||||||
|
// Process.Start(app.Path);
|
||||||
|
|
||||||
|
// DebugTrace.WriteLine(nameof(DataBase), $"超过10s为收到心跳数据, 重启 {app.Name} 软件");
|
||||||
|
//}
|
||||||
|
|
||||||
|
app.DateTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,7 @@ Console.WriteLine($"Hello, World!");
|
||||||
DataBase.Initialization();
|
DataBase.Initialization();
|
||||||
|
|
||||||
/* 服务启动 */
|
/* 服务启动 */
|
||||||
//MonitorServer.Initialization(AppInfo.Set("HxNvr", ""));
|
MonitorServer.Initialization(AppInfo.Set("HxNvr", "D:\\App\\HxNvr\\HxNvr.exe"));
|
||||||
MonitorServer.Initialization();
|
|
||||||
MonitorServer.Startup();
|
MonitorServer.Startup();
|
||||||
|
|
||||||
while (true) ;
|
while (true) ;
|
16
HxServer/HxServer/Utils/DebugTrace.cs
Normal file
16
HxServer/HxServer/Utils/DebugTrace.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HxServer.Utils
|
||||||
|
{
|
||||||
|
public class DebugTrace
|
||||||
|
{
|
||||||
|
public static void WriteLine(string title, string message)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} | {title} | {message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ public class JsonUtils
|
||||||
return JsonConvert.SerializeObject(value);
|
return JsonConvert.SerializeObject(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, object>? ToDictionary(object? message)
|
public static Dictionary<string, object> ToDictionary(object? message)
|
||||||
{
|
{
|
||||||
var json = message?.ToString();
|
var json = message?.ToString();
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
using LiteDB;
|
|
||||||
using LiteDB.Async;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace HxServer.Utils
|
|
||||||
{
|
|
||||||
public static class LiteDBUtils
|
|
||||||
{
|
|
||||||
public static ILiteCollection<T> GetCollection<T>(LiteDatabase database, string name, BsonAutoId autoId = BsonAutoId.ObjectId)
|
|
||||||
{
|
|
||||||
/* 获取集合(相当于表) */
|
|
||||||
return database.GetCollection<T>(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace HxServer.Utils;
|
namespace HxServer.Utils;
|
||||||
|
|
||||||
|
@ -12,32 +13,42 @@ public class LogUtils
|
||||||
|
|
||||||
public static void AppendLog(string message)
|
public static void AppendLog(string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine(message);
|
var data = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} {message}";
|
||||||
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), "log.log"), $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {message}");
|
|
||||||
|
Console.WriteLine(data);
|
||||||
|
|
||||||
|
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), "log.log"), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AppendLog(string filename, string message)
|
public static void AppendLog(string filename, string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine(message);
|
var data = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} {message}";
|
||||||
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), filename), $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {message}");
|
|
||||||
|
Console.WriteLine(data);
|
||||||
|
|
||||||
|
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), filename), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AppendError(string message)
|
public static void AppendError(string message)
|
||||||
{
|
{
|
||||||
|
var data = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} {message}";
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(data);
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), "error.log"), $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {message}");
|
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), "error.log"), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AppendError(string filename, string message)
|
public static void AppendError(string filename, string message)
|
||||||
{
|
{
|
||||||
|
var data = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} {message}";
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(data);
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), filename), $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {message}");
|
FileUtils.Append(Path.Combine(filepath, DateTime.Now.ToString("yyyyMMdd"), filename), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,9 @@ void HxDevice::startup(QJsonObject object)
|
||||||
auto type = array[2].toUpper();
|
auto type = array[2].toUpper();
|
||||||
auto address = array[3];
|
auto address = array[3];
|
||||||
auto port = array[4].toInt();
|
auto port = array[4].toInt();
|
||||||
auto enable = QVariant(array[7]).toBool();
|
auto _channel = array[5].toInt();
|
||||||
auto record = QVariant(array[8]).toBool();
|
auto enable = QVariant(array[6]).toBool();
|
||||||
|
auto record = QVariant(array[7]).toBool();
|
||||||
|
|
||||||
if (enable && record)
|
if (enable && record)
|
||||||
{
|
{
|
||||||
|
@ -43,6 +44,8 @@ void HxDevice::startup(QJsonObject object)
|
||||||
rtspurl = QString("rtsp://%1:%2/stander/livestream/0/%3").arg(address).arg(port).arg(!secondary ? 0 : 1);
|
rtspurl = QString("rtsp://%1:%2/stander/livestream/0/%3").arg(address).arg(port).arg(!secondary ? 0 : 1);
|
||||||
else if (type == "BSM")
|
else if (type == "BSM")
|
||||||
rtspurl = QString("rtsp://%1:%2/%3").arg(address).arg(port).arg(!secondary ? 11 : 12);
|
rtspurl = QString("rtsp://%1:%2/%3").arg(address).arg(port).arg(!secondary ? 11 : 12);
|
||||||
|
else if (type == "AHV")
|
||||||
|
rtspurl = QString("rtsp://%1:%2/dev/video%3").arg(address).arg(port).arg(_channel);
|
||||||
|
|
||||||
/* 创建 视频读取线程 */
|
/* 创建 视频读取线程 */
|
||||||
HxTask::run(this, &HxDevice::frame_read_process, 5000, uuid);
|
HxTask::run(this, &HxDevice::frame_read_process, 5000, uuid);
|
||||||
|
@ -66,7 +69,8 @@ void HxDevice::frame_read_process()
|
||||||
// av_dict_set(&avdic, "audio_buffer_size","30", 0);
|
// av_dict_set(&avdic, "audio_buffer_size","30", 0);
|
||||||
av_dict_set(&avdic, "stimeout", "500000", 0);
|
av_dict_set(&avdic, "stimeout", "500000", 0);
|
||||||
av_dict_set(&avdic, "max_delay", "500000", 0);
|
av_dict_set(&avdic, "max_delay", "500000", 0);
|
||||||
av_dict_set(&avdic, "rtsp_transport", "tcp", 0);
|
av_dict_set(&avdic, "rtsp_transport", "+udp+tcp", 0);
|
||||||
|
// av_dict_set(&avdic, "rtsp_transport", "tcp", 0);
|
||||||
|
|
||||||
avformat_network_init();
|
avformat_network_init();
|
||||||
|
|
||||||
|
|
BIN
HxVideoCaptor/external/HxUtils/lib/libHxUtils.a
vendored
BIN
HxVideoCaptor/external/HxUtils/lib/libHxUtils.a
vendored
Binary file not shown.
38
HxVideoCaptor/external/rtsp-server.c
vendored
Normal file
38
HxVideoCaptor/external/rtsp-server.c
vendored
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <gst/gst.h>
|
||||||
|
#include <gst/rtsp-server/rtsp-server.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
GMainLoop* loop;
|
||||||
|
GstRTSPServer* server;
|
||||||
|
GstRTSPMountPoints* mounts;
|
||||||
|
|
||||||
|
gst_init(NULL, NULL);
|
||||||
|
|
||||||
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
server = gst_rtsp_server_new();
|
||||||
|
gst_rtsp_server_set_service(server, "8554");
|
||||||
|
mounts = gst_rtsp_server_get_mount_points(server);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
char device[1024] = { 0 }, launch[2048] = { 0 };
|
||||||
|
|
||||||
|
sprintf(device, "/dev/video%d", i);
|
||||||
|
sprintf(launch, "( v4l2src device=%s ! videoconvert ! video/x-raw, format=NV12, width=1280, height=720, framerate=25/1 ! videoparse width=1280 height=720 format=nv12 ! clockoverlay time-format=\"%%Y-%%m-%%d %%H:%%M:%%S\"! queue ! mpph264enc ! rtph264pay name=pay0 pt=96 )", device);
|
||||||
|
|
||||||
|
GstRTSPMediaFactory* factory = gst_rtsp_media_factory_new();
|
||||||
|
gst_rtsp_media_factory_set_launch(factory, launch);
|
||||||
|
gst_rtsp_media_factory_set_shared(factory, TRUE);
|
||||||
|
gst_rtsp_mount_points_add_factory(mounts, device, factory);
|
||||||
|
|
||||||
|
g_print(" listern => rtsp://localhost:8554%s\r\n", device);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref(mounts);
|
||||||
|
gst_rtsp_server_attach(server, NULL);
|
||||||
|
g_main_loop_run(loop);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -14,6 +14,9 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
/* 设置最大线程个数 */
|
||||||
|
QThreadPool::globalInstance()->setMaxThreadCount(100);
|
||||||
|
|
||||||
/* UDP广播 初始化 */
|
/* UDP广播 初始化 */
|
||||||
HxBroadcast::initialization(BROADCAST_PORT);
|
HxBroadcast::initialization(BROADCAST_PORT);
|
||||||
QObject::connect(HxBroadcast::context(), &HxBroadcast::receive_event, [=](QByteArray data) { broadcast_receive_event(data); });
|
QObject::connect(HxBroadcast::context(), &HxBroadcast::receive_event, [=](QByteArray data) { broadcast_receive_event(data); });
|
||||||
|
|
Loading…
Reference in New Issue
Block a user