|
1 |
| -using Microsoft.Extensions.Logging; |
2 |
| -using System.ComponentModel; |
3 |
| -using VL.Lib.Basics.Video; |
4 |
| -using VL.Model; |
5 |
| -using VL.Devices.Orbbec.Advanced; |
6 |
| -using System.Reactive.Subjects; |
7 |
| -using System.Reactive.Linq; |
8 |
| -using Orbbec; |
9 |
| -using System.Net; |
10 |
| - |
11 |
| -namespace VL.Devices.Orbbec |
12 |
| -{ |
13 |
| - [ProcessNode] |
14 |
| - public class VideoIn : IVideoSource2, IDisposable |
15 |
| - { |
16 |
| - private readonly ILogger _logger; |
17 |
| - private readonly BehaviorSubject<Acquisition?> _aquicitionStarted = new BehaviorSubject<Acquisition?>(null); |
18 |
| - |
19 |
| - private int _changedTicket; |
20 |
| - private Advanced.DeviceInfo? _device; |
21 |
| - private Int2 _resolution; |
22 |
| - private int _fps; |
23 |
| - //private IConfiguration? _configuration; |
24 |
| - private bool _enabled; |
25 |
| - private string _IP; |
26 |
| - |
27 |
| - |
28 |
| - internal string Info { get; set; } = ""; |
29 |
| - internal Spread<PropertyInfo> PropertyInfos { get; set; } = new SpreadBuilder<PropertyInfo>().ToSpread(); |
30 |
| - |
31 |
| - public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext) |
32 |
| - { |
33 |
| - _logger = nodeContext.GetLogger(); |
34 |
| - } |
35 |
| - |
36 |
| - [return: Pin(Name = "Output")] |
37 |
| - public VideoIn? Update( |
| 1 | +using Microsoft.Extensions.Logging; |
| 2 | +using System.ComponentModel; |
| 3 | +using VL.Lib.Basics.Video; |
| 4 | +using VL.Model; |
| 5 | +using VL.Devices.Orbbec.Advanced; |
| 6 | +using System.Reactive.Subjects; |
| 7 | +using System.Reactive.Linq; |
| 8 | +using Orbbec; |
| 9 | +using System.Net; |
| 10 | + |
| 11 | +namespace VL.Devices.Orbbec |
| 12 | +{ |
| 13 | + [ProcessNode] |
| 14 | + public class VideoIn : IVideoSource2, IDisposable |
| 15 | + { |
| 16 | + private readonly ILogger _logger; |
| 17 | + private readonly BehaviorSubject<Acquisition?> _aquicitionStarted = new BehaviorSubject<Acquisition?>(null); |
| 18 | + |
| 19 | + private int _changedTicket; |
| 20 | + private Advanced.DeviceInfo? _device; |
| 21 | + private Int2 _resolution; |
| 22 | + private int _fps; |
| 23 | + //private IConfiguration? _configuration; |
| 24 | + private bool _enabled; |
| 25 | + private string _IP; |
| 26 | + |
| 27 | + |
| 28 | + internal string Info { get; set; } = ""; |
| 29 | + internal Spread<PropertyInfo> PropertyInfos { get; set; } = new SpreadBuilder<PropertyInfo>().ToSpread(); |
| 30 | + |
| 31 | + public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext) |
| 32 | + { |
| 33 | + _logger = nodeContext.GetLogger(); |
| 34 | + } |
| 35 | + |
| 36 | + [return: Pin(Name = "Output")] |
| 37 | + public VideoIn? Update( |
38 | 38 | OrbbecDevice? device,
|
39 |
| - [DefaultValue("640, 576")] Int2 resolution, |
40 |
| - [DefaultValue("30")] int FPS, |
41 |
| - //IConfiguration configuration, |
42 |
| - [DefaultValue("true")] bool enabled, |
43 |
| - out string Info) |
44 |
| - { |
45 |
| - // By comparing the device info we can be sure that on re-connect of the device we see the change |
46 |
| - if (!Equals(device?.Tag, _device) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration) |
47 |
| - { |
48 |
| - _device = device?.Tag as Advanced.DeviceInfo; |
49 |
| - _resolution = resolution; |
50 |
| - _fps = FPS; |
51 |
| - //_configuration = configuration; |
52 |
| - _enabled = enabled; |
53 |
| - _changedTicket++; |
54 |
| - } |
55 |
| - |
56 |
| - Info = this.Info; |
57 |
| - |
58 |
| - if (!enabled) return null; |
59 |
| - |
60 |
| - return this; |
61 |
| - } |
62 |
| - |
63 |
| - internal IObservable<Acquisition> AcquisitionStarted => _aquicitionStarted.Where(a => a != null && !a.IsDisposed)!; |
64 |
| - |
65 |
| - IVideoPlayer? IVideoSource2.Start(VideoPlaybackContext ctx) |
66 |
| - { |
67 |
| - var device = _device; |
68 |
| - if (device is null) |
69 |
| - return null; |
70 |
| - |
71 |
| - try |
72 |
| - { |
73 |
| - var result = Acquisition.Start(this, device, _logger, _resolution, _fps);//, _configuration |
74 |
| - //_aquicitionStarted.OnNext(result); |
75 |
| - return result; |
76 |
| - } |
77 |
| - catch (Exception e) |
78 |
| - { |
79 |
| - _logger.LogError(e, "Failed to start image acquisition"); |
80 |
| - return null; |
81 |
| - } |
82 |
| - } |
83 |
| - |
84 |
| - int IVideoSource2.ChangedTicket => _changedTicket; |
85 |
| - |
86 |
| - public void Dispose() |
87 |
| - { |
88 |
| - //_ic4LibSubscription.Dispose(); |
89 |
| - } |
90 |
| - } |
91 |
| -} |
| 39 | + [DefaultValue("640, 576")] Int2 resolution, |
| 40 | + [DefaultValue("30")] int FPS, |
| 41 | + //IConfiguration configuration, |
| 42 | + [DefaultValue("true")] bool enabled, |
| 43 | + out string Info) |
| 44 | + { |
| 45 | + // By comparing the device info we can be sure that on re-connect of the device we see the change |
| 46 | + if (!Equals(device?.Tag, _device) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration) |
| 47 | + { |
| 48 | + _device = device?.Tag as Advanced.DeviceInfo; |
| 49 | + _resolution = resolution; |
| 50 | + _fps = FPS; |
| 51 | + //_configuration = configuration; |
| 52 | + _enabled = enabled; |
| 53 | + _changedTicket++; |
| 54 | + } |
| 55 | + |
| 56 | + Info = this.Info; |
| 57 | + |
| 58 | + if (!enabled) return null; |
| 59 | + |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + internal IObservable<Acquisition> AcquisitionStarted => _aquicitionStarted.Where(a => a != null && !a.IsDisposed)!; |
| 64 | + |
| 65 | + IVideoPlayer? IVideoSource2.Start(VideoPlaybackContext ctx) |
| 66 | + { |
| 67 | + var device = _device; |
| 68 | + if (device is null) |
| 69 | + return null; |
| 70 | + |
| 71 | + try |
| 72 | + { |
| 73 | + var result = Acquisition.Start(this, device, _logger, _resolution, _fps);//, _configuration |
| 74 | + //_aquicitionStarted.OnNext(result); |
| 75 | + return result; |
| 76 | + } |
| 77 | + catch (Exception e) |
| 78 | + { |
| 79 | + _logger.LogError(e, "Failed to start image acquisition"); |
| 80 | + return null; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + int IVideoSource2.ChangedTicket => _changedTicket; |
| 85 | + |
| 86 | + public void Dispose() |
| 87 | + { |
| 88 | + //_ic4LibSubscription.Dispose(); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments