Skip to content

Commit 20a6823

Browse files
committed
Improve PTZControl2 live controls and preview
1 parent 1845a17 commit 20a6823

12 files changed

Lines changed: 913 additions & 150 deletions

PTZControl.Core/CameraBackend.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public interface ICameraBackend
1515
void SetDirectShowCameraName(string devicePath, string friendlyName);
1616
(int min, int max, int step, int def) GetRange(string camera, CameraProperty property);
1717
int GetValue(string camera, CameraProperty property);
18+
(int min, int max, int step, int def) GetVideoProcessingRange(string camera, VideoProcessingProperty property);
19+
int GetVideoProcessingValue(string camera, VideoProcessingProperty property);
20+
void SetVideoProcessingValue(string camera, VideoProcessingProperty property, int value);
1821
void SetPanTiltZoom(string camera, int? pan = null, int? tilt = null, int? zoom = null);
22+
void MoveRelativeZoom(string camera, int deltaPercent);
1923
void MoveRelativePanTilt(string camera, int? x = null, int? y = null);
2024
void RestoreHome(string camera, bool zoom, bool move);
2125
void RestoreDefault(string camera, bool zoom, bool pan, bool tilt);
@@ -91,9 +95,21 @@ private static string BuildDirectShowCameraRegistryPath(string devicePath)
9195
public int GetValue(string camera, CameraProperty property) =>
9296
UvcCamera.GetValue(camera, property);
9397

98+
public (int min, int max, int step, int def) GetVideoProcessingRange(string camera, VideoProcessingProperty property) =>
99+
UvcCamera.GetVideoProcessingRange(camera, property);
100+
101+
public int GetVideoProcessingValue(string camera, VideoProcessingProperty property) =>
102+
UvcCamera.GetVideoProcessingValue(camera, property);
103+
104+
public void SetVideoProcessingValue(string camera, VideoProcessingProperty property, int value) =>
105+
UvcCamera.SetVideoProcessingValue(camera, property, value);
106+
94107
public void SetPanTiltZoom(string camera, int? pan = null, int? tilt = null, int? zoom = null) =>
95108
UvcCamera.SetPanTiltZoom(camera, pan, tilt, zoom);
96109

110+
public void MoveRelativeZoom(string camera, int deltaPercent) =>
111+
UvcCamera.MoveRelativeZoom(camera, deltaPercent);
112+
97113
public void MoveRelativePanTilt(string camera, int? x = null, int? y = null) =>
98114
UvcCamera.MoveRelativePanTilt(camera, x, y);
99115

@@ -159,6 +175,15 @@ public int GetValue(string camera, CameraProperty property)
159175
return control.Value;
160176
}
161177

178+
public (int min, int max, int step, int def) GetVideoProcessingRange(string camera, VideoProcessingProperty property) =>
179+
throw new NotSupportedException("Linux video processing controls are not implemented yet.");
180+
181+
public int GetVideoProcessingValue(string camera, VideoProcessingProperty property) =>
182+
throw new NotSupportedException("Linux video processing controls are not implemented yet.");
183+
184+
public void SetVideoProcessingValue(string camera, VideoProcessingProperty property, int value) =>
185+
throw new NotSupportedException("Linux video processing controls are not implemented yet.");
186+
162187
public void SetPanTiltZoom(string camera, int? pan = null, int? tilt = null, int? zoom = null)
163188
{
164189
using var device = OpenCamera(camera);
@@ -177,6 +202,12 @@ public void MoveRelativePanTilt(string camera, int? x = null, int? y = null)
177202
SetPanTiltZoom(camera, pan, tilt);
178203
}
179204

205+
public void MoveRelativeZoom(string camera, int deltaPercent)
206+
{
207+
var zoom = AddDelta(camera, CameraProperty.Zoom, deltaPercent);
208+
SetPanTiltZoom(camera, zoom: zoom);
209+
}
210+
180211
public void RestoreHome(string camera, bool zoom, bool move) =>
181212
throw LinuxPresetNotSupported();
182213

@@ -207,6 +238,8 @@ private int AddDelta(string camera, CameraProperty property, int deltaPercent)
207238
var range = GetRange(camera, property);
208239
var current = GetValue(camera, property);
209240
var delta = (int)Math.Round((range.max - range.min) * (deltaPercent / 100.0));
241+
if (delta == 0 && deltaPercent != 0 && range.max > range.min)
242+
delta = Math.Sign(deltaPercent) * Math.Max(1, range.step);
210243
return Math.Clamp(current + delta, range.min, range.max);
211244
}
212245

@@ -340,9 +373,21 @@ public void SetDirectShowCameraName(string devicePath, string friendlyName) =>
340373
public int GetValue(string camera, CameraProperty property) =>
341374
throw new NotSupportedException(message);
342375

376+
public (int min, int max, int step, int def) GetVideoProcessingRange(string camera, VideoProcessingProperty property) =>
377+
throw new NotSupportedException(message);
378+
379+
public int GetVideoProcessingValue(string camera, VideoProcessingProperty property) =>
380+
throw new NotSupportedException(message);
381+
382+
public void SetVideoProcessingValue(string camera, VideoProcessingProperty property, int value) =>
383+
throw new NotSupportedException(message);
384+
343385
public void SetPanTiltZoom(string camera, int? pan = null, int? tilt = null, int? zoom = null) =>
344386
throw new NotSupportedException(message);
345387

388+
public void MoveRelativeZoom(string camera, int deltaPercent) =>
389+
throw new NotSupportedException(message);
390+
346391
public void MoveRelativePanTilt(string camera, int? x = null, int? y = null) =>
347392
throw new NotSupportedException(message);
348393

0 commit comments

Comments
 (0)