Skip to content

Commit

Permalink
Merge branch 'chatop2020:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
csuffyy authored Feb 4, 2024
2 parents 6e4784d + b983ef8 commit 2a548e1
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 4 deletions.
Binary file modified AKStreamKeeper/AKStream.ldb
Binary file not shown.
10 changes: 9 additions & 1 deletion AKStreamKeeper/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,20 @@ private static void OnTimedEvent(object source, ElapsedEventArgs e)
}

string reqData = JsonHelper.ToJson(tmpKeepAlive, Formatting.Indented);

#if (DEBUG)
GCommon.Logger.Debug(
$"[{LoggerHead}]->向AKStreamWeb注册本机信息->{reqData}");
#endif
try
{
var httpRet = NetHelper.HttpPostRequest(_akStreamKeeperConfig.AkStreamWebRegisterUrl, null, reqData,
"utf-8", _akStreamKeeperConfig.HttpClientTimeoutSec * 1000);
_sendDataTick = DateTime.Now;
#if (DEBUG)
GCommon.Logger.Debug(
$"[{LoggerHead}]->AKStreamWeb注册本机信息回复内容->{httpRet}");
#endif

if (!string.IsNullOrEmpty(httpRet))
{
if (UtilsHelper.HttpClientResponseIsNetWorkError(httpRet))
Expand Down
3 changes: 2 additions & 1 deletion AKStreamWeb/Config/AKStreamWeb.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"LocalizationKingBaseDb": false,
"ForwardUrlIn": "http://",
"ForwardUrlOut": "http://",
"ForwardUrlOnRecord": "http://"
"ForwardUrlOnRecord": "http://",
"PushStreamIpGetUrl": ""
}
10 changes: 10 additions & 0 deletions AKStreamWeb/Misc/AKStreamWebConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class AKStreamWebConfig
private string? _forwardUrlIn = "";
private string? _forwardUrlOut = "";
private string? _forwardUrlOnRecord = "";
private string? _pushStreamIpGetUrl = "";


/// <summary>
Expand Down Expand Up @@ -188,5 +189,14 @@ public string ForwardUrlOnRecord
get => _forwardUrlOnRecord;
set => _forwardUrlOnRecord = value;
}

/// <summary>
/// GB28181获取设备推流地址的接口
/// </summary>
public string PushStreamIpGetUrl
{
get => _pushStreamIpGetUrl;
set => _pushStreamIpGetUrl = value;
}
}
}
182 changes: 182 additions & 0 deletions AKStreamWeb/Services/SipServerService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading;
using AKStreamWeb.Misc;
using LibCommon;
using LibCommon.Enums;
using LibCommon.Structs;
using LibCommon.Structs.DBModels;
using LibCommon.Structs.GB28181;
using LibCommon.Structs.GB28181.XML;
using LibCommon.Structs.Other;
using LibCommon.Structs.WebRequest;
using LibCommon.Structs.WebResponse;
using LibGB28181SipServer;
Expand Down Expand Up @@ -686,6 +688,66 @@ record = row.RecItems.FindLast(x => x.SsrcId.Equals(ssrcId));
pushMediaInfo.MediaServerIpAddress = mediaServer.IpV4Address;
}

string ip = pushMediaInfo.MediaServerIpAddress;

if (!string.IsNullOrEmpty(Common.AkStreamWebConfig.PushStreamIpGetUrl) &&
UtilsHelper.IsUrl(Common.AkStreamWebConfig.PushStreamIpGetUrl))
{
string url = Common.AkStreamWebConfig.PushStreamIpGetUrl.Trim();

try
{
string reqData = JsonHelper.ToJson(new ReqPushStreamGetIP()
{
DeviceId = sipDevice.DeviceId,
});
Dictionary<string, string> headers = new Dictionary<string, string>();


var httpRet = NetHelper.HttpPostRequest(url, headers, reqData, "utf-8", Common.AkStreamWebConfig.HttpClientTimeoutSec*1000);
if (!string.IsNullOrEmpty(httpRet))
{
if (UtilsHelper.HttpClientResponseIsNetWorkError(httpRet))
{
rs = new ResponseStruct()
{
Code = ErrorNumber.Sys_HttpClientTimeout,
Message = ErrorMessage.ErrorDic![ErrorNumber.Sys_HttpClientTimeout],
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(rs)}");
}
else
{

var resRet = JsonHelper.FromJson<ResPushStreamGetIP>(httpRet);
if (resRet != null && !string.IsNullOrEmpty(resRet.DeviceId) &&
!string.IsNullOrEmpty(resRet.IpAddress))
{
ip = resRet.IpAddress.Trim();
GCommon.Logger.Debug(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址成功,将执行返回中指定的ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(resRet)}");

}
}

}
}
catch (Exception ex)
{
rs = new ResponseStruct()
{
Code = ErrorNumber.MediaServer_WebApiExcept,
Message = ErrorMessage.ErrorDic![ErrorNumber.MediaServer_WebApiExcept],
ExceptMessage = ex.Message,
ExceptStackTrace = ex.StackTrace,
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(rs)}");
}
}
pushMediaInfo.MediaServerIpAddress=ip;//重新设置回去,如果成功获取,将会改写ip变量的值

pushMediaInfo.PushStreamSocketType =
videoChannel.RtpWithTcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP;
try
Expand Down Expand Up @@ -1095,6 +1157,66 @@ public static MediaServerStreamInfo LiveVideo(string deviceId, string channelId,
pushMediaInfo.MediaServerIpAddress = mediaServer.IpV4Address;
}

string ip = pushMediaInfo.MediaServerIpAddress;

if (!string.IsNullOrEmpty(Common.AkStreamWebConfig.PushStreamIpGetUrl) &&
UtilsHelper.IsUrl(Common.AkStreamWebConfig.PushStreamIpGetUrl))
{
string url = Common.AkStreamWebConfig.PushStreamIpGetUrl.Trim();

try
{
string reqData = JsonHelper.ToJson(new ReqPushStreamGetIP()
{
DeviceId = deviceId,
});
Dictionary<string, string> headers = new Dictionary<string, string>();


var httpRet = NetHelper.HttpPostRequest(url, headers, reqData, "utf-8", Common.AkStreamWebConfig.HttpClientTimeoutSec*1000);
if (!string.IsNullOrEmpty(httpRet))
{
if (UtilsHelper.HttpClientResponseIsNetWorkError(httpRet))
{
rs = new ResponseStruct()
{
Code = ErrorNumber.Sys_HttpClientTimeout,
Message = ErrorMessage.ErrorDic![ErrorNumber.Sys_HttpClientTimeout],
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{deviceId}-{channelId}->{JsonHelper.ToJson(rs)}");
}
else
{

var resRet = JsonHelper.FromJson<ResPushStreamGetIP>(httpRet);
if (resRet != null && !string.IsNullOrEmpty(resRet.DeviceId) &&
!string.IsNullOrEmpty(resRet.IpAddress))
{
ip = resRet.IpAddress.Trim();
GCommon.Logger.Debug(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址成功,将执行返回中指定的ip地址->{deviceId}-{channelId}->{JsonHelper.ToJson(resRet)}");

}
}

}
}
catch (Exception ex)
{
rs = new ResponseStruct()
{
Code = ErrorNumber.MediaServer_WebApiExcept,
Message = ErrorMessage.ErrorDic![ErrorNumber.MediaServer_WebApiExcept],
ExceptMessage = ex.Message,
ExceptStackTrace = ex.StackTrace,
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{deviceId}-{channelId}->{JsonHelper.ToJson(rs)}");
}
}
pushMediaInfo.MediaServerIpAddress=ip;//重新设置回去,如果成功获取,将会改写ip变量的值

pushMediaInfo.PushStreamSocketType =
videoChannel.RtpWithTcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP;
try
Expand Down Expand Up @@ -1708,6 +1830,66 @@ record = row.RecItems.FindLast(x => x.SsrcId.Equals(ssrcId.ToString()));
pushMediaInfo.MediaServerIpAddress = mediaServer.IpV4Address;
}

string ip = pushMediaInfo.MediaServerIpAddress;

if (!string.IsNullOrEmpty(Common.AkStreamWebConfig.PushStreamIpGetUrl) &&
UtilsHelper.IsUrl(Common.AkStreamWebConfig.PushStreamIpGetUrl))
{
string url = Common.AkStreamWebConfig.PushStreamIpGetUrl.Trim();

try
{
string reqData = JsonHelper.ToJson(new ReqPushStreamGetIP()
{
DeviceId = sipDevice.DeviceId,
});
Dictionary<string, string> headers = new Dictionary<string, string>();


var httpRet = NetHelper.HttpPostRequest(url, headers, reqData, "utf-8", Common.AkStreamWebConfig.HttpClientTimeoutSec*1000);
if (!string.IsNullOrEmpty(httpRet))
{
if (UtilsHelper.HttpClientResponseIsNetWorkError(httpRet))
{
rs = new ResponseStruct()
{
Code = ErrorNumber.Sys_HttpClientTimeout,
Message = ErrorMessage.ErrorDic![ErrorNumber.Sys_HttpClientTimeout],
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(rs)}");
}
else
{

var resRet = JsonHelper.FromJson<ResPushStreamGetIP>(httpRet);
if (resRet != null && !string.IsNullOrEmpty(resRet.DeviceId) &&
!string.IsNullOrEmpty(resRet.IpAddress))
{
ip = resRet.IpAddress.Trim();
GCommon.Logger.Debug(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址成功,将执行返回中指定的ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(resRet)}");

}
}

}
}
catch (Exception ex)
{
rs = new ResponseStruct()
{
Code = ErrorNumber.MediaServer_WebApiExcept,
Message = ErrorMessage.ErrorDic![ErrorNumber.MediaServer_WebApiExcept],
ExceptMessage = ex.Message,
ExceptStackTrace = ex.StackTrace,
};
GCommon.Logger.Error(
$"[{Common.LoggerHead}]->请求Sip推流->获取指定流媒体服务器ip地址失败,将执行默认ip地址->{sipDevice.DeviceId}-{sipChannel.DeviceId}->{JsonHelper.ToJson(rs)}");
}
}
pushMediaInfo.MediaServerIpAddress=ip;//重新设置回去,如果成功获取,将会改写ip变量的值

pushMediaInfo.PushStreamSocketType =
videoChannel.RtpWithTcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP;
try
Expand Down
18 changes: 18 additions & 0 deletions LibCommon/Structs/Other/ReqPushStreamGetIP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace LibCommon.Structs.Other;

[Serializable]
public class ReqPushStreamGetIP
{
private string? _deviceId;

/// <summary>
/// sip设备id
/// </summary>
public string? DeviceId
{
get => _deviceId;
set => _deviceId = value;
}
}
28 changes: 28 additions & 0 deletions LibCommon/Structs/Other/ResPushStreamGetIP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace LibCommon.Structs.Other;

[Serializable]
public class ResPushStreamGetIP
{
private string? _ipAddress;
private string? _deviceId;

/// <summary>
/// 设备对应的流媒体服务器ip地址
/// </summary>
public string? IpAddress
{
get => _ipAddress;
set => _ipAddress = value;
}

/// <summary>
/// sip设备id
/// </summary>
public string? DeviceId
{
get => _deviceId;
set => _deviceId = value;
}
}
2 changes: 1 addition & 1 deletion LibSystemInfo/NetWorkLinuxValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static NetWorkLinuxValue()
Console.WriteLine("/usr/sbin/route->命令不存在,请用软连接生成/usr/sbin/route命令");
}

tmpProcess.RunProcess("/usr/sbin/route", "", 20000, out string std, out string err);
tmpProcess.RunProcess("/usr/sbin/route", "-n", 20000, out string std, out string err);
bool isFound = false;
if (!string.IsNullOrEmpty(std))
{
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# AKStream介绍
## 技术交流QQ群:870526956
## 技术交流QQ群:870526956
## 注意:本项目的相关资料与Wiki内容都只在GitHub更新,不会在Gitee更新(但是最新代码会同步提交到GitHub和Gitee),有需要最新文档和资料的朋友请移步GitHub
-------
# 感谢DartNoder提供免费的服务器给AKStream
# Thanks to DartNoder for providing free servers to AKStream. Dear friends, if you have efficient server needs, you can consider DartNoder
<a href='https://dartnode.com' _target="blank"><img src="https://i.ibb.co/5cPHFS5/WX20240121-210752-2x.png" width="158" height="49" /></a>
# 感谢jetbrains提供免费的开发者授权证书!
# Thanks to jetbrains for providing a free developer license
<img src="https://i.ibb.co/cbvPfgM/jb-beam.png" width="200" height="200" />


![akstream](https://i.loli.net/2021/08/05/5IgjLfCoS9e7NRm.png)
* AKStream是一套全功能的软NVR接口平台,软NVR指的是软件定义的NVR(Network Video Recoder),AKStream经过长达一年半的开发,测试与调优,已经具备了一定的使用价值,在可靠性,实用性方面都有着较为不错的表现,同时因为AKStream是一套完全开源的软件产品,在众多网友的一起加持下,AKStream的安全性也得到了验证。

Expand Down

0 comments on commit 2a548e1

Please sign in to comment.