Skip to content

Commit

Permalink
Fix bug listening on the wrong port. Bind on a different port per camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan authored and Ivan committed Oct 22, 2016
1 parent a97f31a commit 016abbe
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 27 deletions.
18 changes: 15 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SurveillanceMonitor is a windows service that connects to IP Cameras that run th
## Pre-Requisites
* Windows only.
* [VideoLan](http://www.videolan.org/) should be installed
* .NET Framework
* .NET Framework 4.6
* Open ports/Port forwarding so that this application can connect to the camera, and so that the camera can connect to this application

## Capabilities
Expand All @@ -21,17 +21,29 @@ SurveillanceMonitor is a windows service that connects to IP Cameras that run th
During installation you'll be prompted to enter some XML settings, this will be saved as *MonitorSettings.xml* in the installed folder.

` VlcFolder="C:\Program Files (x86)\VideoLAN\VLC"`

`CallbackIp="192.168.0.102"` is the IP address of the machine running the Surveillance service
`CallbackPort="8080"` is the port that the service should listen on for alerts


For each camera
`RtspSource="rtsp://admin:password@192.168.0.103:554/ISAPI/Streaming/channels/101"` enter the RTSP url to your camera. (you can test this out directly in vlc: Media > Open Network stream )

`CameraHttpUrl="http://192.168.0.103:80"` HTTP port of the camera.

`CameraUserName="admin"`

`CameraPassword="password"`

`CallbackPort="8080"` is the port that the service should listen on for alerts from this camera

And alert actions for the camera. At the moment only the VLC VideoDumper is supported
`<alarmAction Type="VideoDumper">
<setting Key="videoDumpDirectory" Value=".\videos\" ></setting>
<setting Key="recordForSeconds" Value="30" ></setting>
</alarmAction>`
</alarmAction>`


# Contributing to Surveillance

I'd be willing to accept pull requests implementing any useful new features
I'd love to hear feedback from other people using it.
5 changes: 5 additions & 0 deletions SurveillanceMonitor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveillanceMonitor", "Surv
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveillanceMonitor.Tests", "SurveillanceMonitor.Tests\SurveillanceMonitor.Tests.csproj", "{D370732B-3701-4276-AAB3-1C4C6D049195}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{0A1DCEB1-4E42-4EE7-BA07-0AC33EF7A8C4}"
ProjectSection(SolutionItems) = preProject
Readme.md = Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,33 @@ public class SurveillanceMonitorConfig
public string VlcFolder { get; set; }

[XmlAttribute]
public string CallbackIp { get; set; }

[XmlAttribute]
public ushort CallbackPort { get; set; }
public string CallbackIp { get; set; }

/// <remarks />
[XmlType(AnonymousType = true)]
public class SurveillanceMonitorCamera
{
/// <remarks />
[XmlAttribute]
public string RtspSource { get; set; }

/// <remarks />
[XmlAttribute]
public string CameraHttpUrl { get; set; }

/// <remarks />
[XmlAttribute]
public string CameraUserName { get; set; }

/// <remarks />
[XmlAttribute]
public string CameraPassword { get; set; }

[XmlAttribute]
public ushort CallbackPort { get; set; }

public int Id { get; set; }
}

[XmlType(AnonymousType = true)]
public class SurveillanceMonitorAlarmAction
{
//[XmlArray("settings")]
//[XmlArrayItem("setting", IsNullable = false)]
[XmlElement("setting")]
public SurveillanceMonitorAlarmActionSetting[] Settings { get; set; }

Expand All @@ -62,11 +56,9 @@ public class SurveillanceMonitorAlarmAction
[XmlType(AnonymousType = true)]
public class SurveillanceMonitorAlarmActionSetting
{
/// <remarks />
[XmlAttribute]
public string Key { get; set; }

/// <remarks />
[XmlAttribute]
public string Value { get; set; }
}
Expand Down
7 changes: 4 additions & 3 deletions SurveillanceMonitor/MonitorSettings.Template.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<surveillanceMonitor
VlcFolder="C:\Program Files (x86)\VideoLAN\VLC"
CallbackIp="192.168.0.102"
CallbackPort="8080">
CallbackIp="192.168.0.102" >
<cameras>
<camera
RtspSource="rtsp://admin:password@192.168.0.103:554/ISAPI/Streaming/channels/101"
CameraHttpUrl="http://192.168.0.103:80"
CameraUserName="admin"
CameraPassword="password">
CameraPassword="password"
CallbackPort="8080"
>
</camera>
</cameras>
<alarmActions>
Expand Down
4 changes: 2 additions & 2 deletions SurveillanceMonitor/Services/CameraMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CameraMonitor
public void Start(CancellationToken cancellationToken)
{
_logger.Information($"Start Monitoring {_cameraSettings.CameraHttpUrl}");
_cameraService.SetAlarmCallbackUrlAsync(_settings.CallbackIp, _settings.CallbackPort);
_cameraService.SetAlarmCallbackUrlAsync(_settings.CallbackIp, _cameraSettings.CallbackPort);

Task.Run(async () =>
{
Expand All @@ -42,7 +42,7 @@ public void Start(CancellationToken cancellationToken)
webServer.PageReceivedEvent += (sender, page) => {
_alarmHandlers.AlarmActivated(_cameraSettings);
};
webServer.Bind(8080);
webServer.Bind(_cameraSettings.CallbackPort);
}
catch (Exception e)
Expand Down
2 changes: 2 additions & 0 deletions SurveillanceMonitor/Services/IMiniSocketService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Net;

namespace SurveillanceMonitor.Services
{
Expand All @@ -7,5 +8,6 @@ public interface IMiniSocketService
void Listen(int port, int backlog);
Stream GetNextRequest();
void Stop();
IPAddress IpAddress { get; }
}
}
5 changes: 3 additions & 2 deletions SurveillanceMonitor/Services/MiniSocketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace SurveillanceMonitor.Services
public class MiniSocketService : IMiniSocketService
{
private Socket _listener;
public IPAddress IpAddress { get; private set; }

public void Listen(int port, int backlog)
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList.First(a=>a.AddressFamily== AddressFamily.InterNetwork);
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
IpAddress = ipHostInfo.AddressList.First(a=>a.AddressFamily== AddressFamily.InterNetwork);
IPEndPoint localEndPoint = new IPEndPoint(IpAddress, port);
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_listener.Bind(localEndPoint);
_listener.Listen(backlog);
Expand Down
2 changes: 1 addition & 1 deletion SurveillanceMonitor/Services/MiniWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Bind(int port)
_bound = true;
while (true)
{
_logger.Write(LogEventLevel.Information, $"Waiting for a connection... port:{port}");
_logger.Write(LogEventLevel.Information, $"Waiting for a connection... ip {_miniSocketService.IpAddress} port:{port}");
// Program is suspended while waiting for an incoming connection.

try
Expand Down
1 change: 0 additions & 1 deletion SurveillanceMonitor/SurveillanceMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Readme.md" />
</ItemGroup>
<ItemGroup>
<Content Include="MonitorSettings.Template.xml" />
Expand Down
6 changes: 3 additions & 3 deletions SurveillanceMonitor/SurveillanceMonitorInstaller.iss
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ begin
Memo.Text := '<?xml version="1.0" encoding="utf-8"?>'#13#10'' +
'<surveillanceMonitor'#13#10'' +
' VlcFolder="' + vlcFolder +'"'#13#10'' +
' CallbackIp="192.168.0.102"'#13#10'' +
' CallbackPort="8080">'#13#10'' +
' CallbackIp="192.168.0.102">'#13#10'' +
' <cameras>'#13#10'' +
' <camera'#13#10'' +
' RtspSource="rtsp://admin:password@192.168.0.103:554/ISAPI/Streaming/channels/101"'#13#10'' +
' CameraHttpUrl="http://192.168.0.103:8040"'#13#10'' +
' CameraUserName="admin"'#13#10'' +
' CameraPassword="password">'#13#10'' +
' CameraPassword="password"'#13#10'' +
' CallbackPort="8080">'#13#10'' +
' </camera>'#13#10'' +
' </cameras>'#13#10'' +
' <alarmActions>'#13#10'' +
Expand Down

0 comments on commit 016abbe

Please sign in to comment.