-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraManager.cs
More file actions
106 lines (94 loc) · 3.24 KB
/
Copy pathCameraManager.cs
File metadata and controls
106 lines (94 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
namespace PylonStream
{
public class CameraManager
{
private readonly List<CameraStreamPipeline> _pipelines = new List<CameraStreamPipeline>();
private readonly object _lock = new object();
private bool _isRunning = false;
public bool IsRunning => _isRunning;
public void StartAll()
{
lock (_lock)
{
if (_isRunning)
{
Modules.SystemLogger.AddLog("Camera service is already running.", "INFO");
return;
}
Modules.SystemLogger.AddLog("Starting all camera stream pipelines...", "INFO");
// Clear any existing pipelines
StopAllInternal();
// Create and start a pipeline for each configured camera
foreach (var camConfig in Modules.Config.Cameras)
{
try
{
var pipeline = new CameraStreamPipeline(camConfig);
_pipelines.Add(pipeline);
pipeline.Start();
}
catch (Exception ex)
{
Modules.SystemLogger.AddLog($"Failed to initialize pipeline for camera {camConfig.IpAddress}: {ex.Message}", "ERROR");
}
}
_isRunning = true;
Modules.SystemLogger.AddLog("All camera stream pipelines initialization completed.", "INFO");
}
}
public void StopAll()
{
lock (_lock)
{
if (!_isRunning)
{
return;
}
Modules.SystemLogger.AddLog("Stopping all camera stream pipelines...", "INFO");
StopAllInternal();
_isRunning = false;
Modules.SystemLogger.AddLog("All camera stream pipelines stopped.", "INFO");
}
}
private void StopAllInternal()
{
foreach (var pipeline in _pipelines)
{
try
{
pipeline.Stop();
}
catch (Exception ex)
{
Modules.SystemLogger.AddLog($"Error stopping pipeline for camera {pipeline.IpAddress}: {ex.Message}", "WARN");
}
}
_pipelines.Clear();
}
public List<CameraStreamPipeline> GetPipelines()
{
lock (_lock)
{
return _pipelines.ToList(); // Return a copy of the list
}
}
public bool RestartPipeline(string ip)
{
lock (_lock)
{
var pipeline = _pipelines.FirstOrDefault(p => p.IpAddress == ip);
if (pipeline != null)
{
Modules.SystemLogger.AddLog($"Manually restarting pipeline for camera {ip}...", "INFO");
pipeline.Stop();
pipeline.Start();
return true;
}
return false;
}
}
}
}