Skip to content

Commit

Permalink
激活sip设备时可以选择性传入Activated=true/false
Browse files Browse the repository at this point in the history
  • Loading branch information
chatop committed Nov 30, 2020
1 parent e4310ff commit a167895
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 162 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions CommonFunctions/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using CommonFunction.ManageStructs;
using CommonFunctions.DBStructs;
using CommonFunctions.MediaServerControl;
using CommonFunctions.WebApiStructs.Response;
using LibGB28181SipGate;
using LibSystemInfo;

Expand Down
40 changes: 0 additions & 40 deletions CommonFunctions/FastClone.cs

This file was deleted.

7 changes: 7 additions & 0 deletions CommonFunctions/WebApiStructs/Request/ReqActivateSipCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ReqActivateSipCamera
private bool? _ifGB28181Tcp = false; //如果是gb28181是否采用tcp方式进行推流
private bool? _enableLive;
private bool? _enablePtz;
private bool _activated=true; //默认为激活状态

/// <summary>
/// 摄像头音视频流的GB28181 ID
Expand Down Expand Up @@ -138,5 +139,11 @@ public bool? EnablePtz
get => _enablePtz;
set => _enablePtz = value;
}

public bool Activated
{
get => _activated;
set => _activated = value;
}
}
}
7 changes: 2 additions & 5 deletions LibGB28181SipGate/SipCoreHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public bool ReqLiveForCreateRptPort(string devId, string rptServerIp, ushort rpt
camera.StreamServerIp = rptServerIp;
camera.StreamServerPort = rptPort;
camera.PushStreamSocketType =
tcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP;
tcp ? PushStreamSocketType.TCP : PushStreamSocketType.UDP;
}
}

Expand Down Expand Up @@ -932,12 +932,9 @@ public bool Stop()
public bool Start()
{
_sipDeviceList.Clear();
SIPTransport m_sipTransport = null;
SIPTransport m_sipTransport;
m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false);
m_sipTransport.PerformanceMonitorPrefix = SIPSorceryPerformanceMonitor.REGISTRAR_PREFIX;
SIPAccount account = SipStorage.Instance.Accounts.FirstOrDefault();
/*var sipChannels = SIPTransportConfig.ParseSIPChannelsNode(account);
m_sipTransport.AddSIPChannel(sipChannels);*/
SipStorage sipAccountStorage = new SipStorage();
IMemoCache<Camera> memoCache = new DeviceObjectCache();
_sipMessageCore = new SIPMessageCore(m_sipTransport, sipAccountStorage, memoCache);
Expand Down
Binary file modified StreamMediaServerKeeper/.DS_Store
Binary file not shown.
8 changes: 7 additions & 1 deletion StreamNode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_GetSystemRunningTime",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logger", "Logger\Logger.csproj", "{033881F7-CDA4-4F67-905C-11D907C22A0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_SIPSocket", "Test_SIPSocket\Test_SIPSocket.csproj", "{230AFBF9-001D-4B82-953F-939176E6F86B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_SIPSocketServer", "Test_SIPSocketServer\Test_SIPSocketServer.csproj", "{230AFBF9-001D-4B82-953F-939176E6F86B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_RunProcess", "Test_RunProcess\Test_RunProcess.csproj", "{1297BA0F-CF40-4D64-B92B-2EC906173251}"
EndProject
Expand All @@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinNetworkStaCli", "WinNetw
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_GetSystemInfo", "Test_GetSystemInfo\Test_GetSystemInfo.csproj", "{18ABEB8F-72BB-4B2D-80FD-8C8E8408F0DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_SipSocketClient", "Test_SipSocketClient\Test_SipSocketClient.csproj", "{D4D2E275-3226-48D1-AC36-40907D28B9F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -96,5 +98,9 @@ Global
{18ABEB8F-72BB-4B2D-80FD-8C8E8408F0DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18ABEB8F-72BB-4B2D-80FD-8C8E8408F0DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18ABEB8F-72BB-4B2D-80FD-8C8E8408F0DE}.Release|Any CPU.Build.0 = Release|Any CPU
{D4D2E275-3226-48D1-AC36-40907D28B9F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4D2E275-3226-48D1-AC36-40907D28B9F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4D2E275-3226-48D1-AC36-40907D28B9F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4D2E275-3226-48D1-AC36-40907D28B9F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
48 changes: 5 additions & 43 deletions StreamNodeCtrlApis/SipGateApis/CommonApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,7 @@ public static ResLiveVideoResponse ByeLiveVideo(string mediaServerDeviceId, stri
App = "",
PushStreamSocketType = null,
};

/*
CameraInstance cameraInst = null;
lock (Common.CameraInstanceListLock)
{
cameraInst = Common.CameraInstanceList.FindLast(x =>
x.CameraDeviceLable.Equals(dev.DeviceId) && x.CameraChannelLable.Equals(cameraid) &&
x.PushMediaServerId.Equals(mediaServerDeviceId));
}
*/

string streamid = dev.IpAddress + dev.DeviceId + camera.Camera.DeviceID;
/*if (cameraInst != null && cameraInst.MobileCamera == true)
{
streamid = cameraInst.MobileCamera + dev.DeviceId + camera.Camera.DeviceID + mediaServerDeviceId;
}
else
{
streamid = dev.IpAddress + dev.DeviceId + camera.Camera.DeviceID + mediaServerDeviceId;
}*/

uint stid = CRC32Cls.GetCRC32(streamid);
string mediaStreamId = string.Format("{0:X8}", stid);
ReqZLMediaKitCloseRtpPort req = new ReqZLMediaKitCloseRtpPort()
Expand Down Expand Up @@ -260,31 +240,13 @@ public static ResLiveVideoResponse LiveVideo(string mediaServerDeviceId, string
MediaId = string.Format("{0:X8}", camera.StreamId),
Vhost = camera.Vhost,
App = camera.App,
PushStreamSocketType = tcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
PushStreamSocketType = tcp ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
};
if (camera.SipCameraStatus == SipCameraStatus.Idle)
{
CameraInstance cameraInst = null;
/*lock (Common.CameraInstanceListLock)
{
cameraInst = Common.CameraInstanceList.FindLast(x =>
x.CameraDeviceLable.Equals(dev.DeviceId) && x.CameraChannelLable.Equals(cameraid) &&
x.PushMediaServerId.Equals(mediaServerDeviceId));
}*/

string streamid = dev.IpAddress + dev.DeviceId + camera.Camera.DeviceID;
/*if (cameraInst != null && cameraInst.MobileCamera == true)
{
streamid = cameraInst.MobileCamera + dev.DeviceId + camera.Camera.DeviceID + mediaServerDeviceId;
}
else
{
streamid = dev.IpAddress + dev.DeviceId + camera.Camera.DeviceID + mediaServerDeviceId;
}*/

uint stid = CRC32Cls.GetCRC32(streamid);


string mediaStreamId = string.Format("{0:X8}", stid);
ReqZLMediaKitOpenRtpPort req = new ReqZLMediaKitOpenRtpPort()
{
Expand Down Expand Up @@ -312,13 +274,13 @@ public static ResLiveVideoResponse LiveVideo(string mediaServerDeviceId, string
App = camera.App,
Play_Url = "http://" + mediaServer.Ipaddress + ":" + mediaServer.MediaServerHttpPort + "/" +
camera.App + "/" + mediaStreamId + ".flv",
PushStreamSocketType = tcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
PushStreamSocketType = tcp ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
};
return obj;
}

//以下是:如果摄像头返回推流失败,再判断一次流媒体的onpublish返回中是否存在,如果存在则一样返回成功
CameraSession session = null;
CameraSession session;
lock (Common.CameraSessionLock)
{
session = Common.CameraSessions.FindLast(x =>
Expand All @@ -342,7 +304,7 @@ public static ResLiveVideoResponse LiveVideo(string mediaServerDeviceId, string
Vhost = camera.Vhost,
App = camera.App,
PushStreamSocketType =
tcp == true ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
tcp ? PushStreamSocketType.TCP : PushStreamSocketType.UDP,
};
session.IsOnline = true;
session.ForceOffline = false;
Expand All @@ -354,7 +316,7 @@ public static ResLiveVideoResponse LiveVideo(string mediaServerDeviceId, string
Code = ErrorNumber.SipRealVideoExcept,
Message = ErrorMessage.ErrorDic![ErrorNumber.SipRealVideoExcept],
};
return null;
return null!;
}
}

Expand Down
6 changes: 3 additions & 3 deletions StreamNodeCtrlApis/SystemApis/MediaServerApis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ public static CameraInstance ActivateSipCamera(ReqActivateSipCamera req, out Res
var ret = OrmService.Db.Select<CameraInstance>()
.Where(x => x.CameraDeviceLable.Equals(req.CameraDeviceLable))
.Where(x => x.CameraChannelLable.Equals(req.CameraChannelLable))
.Where(x => x.Activated.Equals(false)).First();
.First();


if (ret != null)
Expand All @@ -2784,16 +2784,16 @@ public static CameraInstance ActivateSipCamera(ReqActivateSipCamera req, out Res
.Set(x => x.Activated, true)
.Set(x => x.CameraId, cid)
.Set(x => x.UpdateTime, DateTime.Now)
.Set(x=>x.Activated,req.Activated)
.Where(x => x.CameraDeviceLable.Equals(req.CameraDeviceLable))
.Where(x => x.CameraChannelLable.Equals(req.CameraChannelLable))
.Where(x => x.Activated.Equals(false))
.ExecuteAffrows();
if (ret2 == 1)
{
return OrmService.Db.Select<CameraInstance>()
.Where(x => x.CameraDeviceLable.Equals(req.CameraDeviceLable))
.Where(x => x.CameraChannelLable.Equals(req.CameraChannelLable))
.Where(x => x.Activated.Equals(true)).First();
.First();
}
}

Expand Down
7 changes: 5 additions & 2 deletions StreamNodeWebApi/AutoTasker/CameraAutoKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,12 @@ private static void liveCamera(CameraInstance cil)
if (camera != null)
{
found = true;
//break;
}
}
}

if (found == true)
if (found)

{
LiveGb28181(cil);
}
Expand Down Expand Up @@ -471,6 +471,7 @@ private static void keeperCamera()

foreach (var cit in Common.CameraInstanceList)
{

if (cit.PushMediaServerId.Contains("unknow"))
{
continue;
Expand All @@ -479,13 +480,15 @@ private static void keeperCamera()
if (cit != null && cit.EnableLive && cit.Activated == true) //启动摄像头,必须是activated为true时才能启动
{
liveCamera(cit);
Thread.Sleep(2000);//动作太快容易把流媒体搞死,这里做点延迟
}

if (cit != null && cit.Activated == true && cit.EnableLive == false
) //为了自己可控的进行推流与断流控制,这边只处理cit.Activated为true的情况
//手动推流的情况下,可以将数据库Activated设置了False来解决推上去后又断下来的问题
{
stopCamera(cit);
Thread.Sleep(2000);//动作太快容易把流媒体搞死,这里做点延迟
}
}
}
Expand Down
66 changes: 0 additions & 66 deletions Test_SIPSocket/Program.cs

This file was deleted.

39 changes: 39 additions & 0 deletions Test_SIPSocketServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Concurrent;
using System.Runtime.Loader;
using System.Text;
using System.Threading;
using DNLiCore_Socket.Server;


namespace Test_SIPSocketServer
{
class Program
{
private static UdpServer udpServer = null;
private static void UdpServer_OnSend(System.Net.EndPoint arg1, int arg2)
{
Console.WriteLine("【消息发送成功】【客户端地址:"+arg1+"】【长度:"+arg2+"】");
}

private static void UdpServer_OnReceive(System.Net.EndPoint arg1, byte[] arg2, int arg3, int arg4)
{
string test = Encoding.UTF8.GetString(arg2);
Console.WriteLine("【消息接收成功】【客户端地址:" + arg1 + "】【数据:" + test + "】【偏移量:" + arg3 + "】【长度:" + arg4 + "】");
Thread.Sleep(500);
udpServer.Send(arg1,arg2,arg3,arg4);
}

static void Main(string[] args)
{

udpServer= new UdpServer(1500);
udpServer.OnReceive += UdpServer_OnReceive; //接收数据事件
udpServer.OnSend += UdpServer_OnSend; //发送数据事件
udpServer.Start(8099,true);

Console.ReadLine();
Console.WriteLine("Hello World!");
}
}
}
Loading

0 comments on commit a167895

Please sign in to comment.