├── .gitattributes
├── .gitignore
├── .gitmodules
├── AtemProxy.sln
├── AtemProxy
├── AtemProxy.csproj
├── AtemProxyUtil.cs
├── AtemServer.cs
├── AtemServerConnection.cs
├── ClientConnectionList.cs
├── CommandQueue.cs
├── Program.cs
├── UpstreamConnection.cs
└── log4net.config
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 |
263 | build
264 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "LibAtem"]
2 | path = LibAtem
3 | url = https://github.com/LibAtem/LibAtem.git
4 |
--------------------------------------------------------------------------------
/AtemProxy.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtemProxy", "AtemProxy\AtemProxy.csproj", "{00C82FAB-C255-4F6B-BC7E-6E0F798DCBF0}"
4 | EndProject
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibAtem", "LibAtem\LibAtem\LibAtem.csproj", "{41BB562D-9C43-4A2A-8117-18DC4CDD4C7C}"
6 | EndProject
7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibAtem.Discovery", "LibAtem\LibAtem.Discovery\LibAtem.Discovery.csproj", "{EE6D9FE0-E821-460B-8E40-682075E32F39}"
8 | EndProject
9 | Global
10 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
11 | Debug|Any CPU = Debug|Any CPU
12 | Release|Any CPU = Release|Any CPU
13 | EndGlobalSection
14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
15 | {00C82FAB-C255-4F6B-BC7E-6E0F798DCBF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16 | {00C82FAB-C255-4F6B-BC7E-6E0F798DCBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
17 | {00C82FAB-C255-4F6B-BC7E-6E0F798DCBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
18 | {00C82FAB-C255-4F6B-BC7E-6E0F798DCBF0}.Release|Any CPU.Build.0 = Release|Any CPU
19 | {41BB562D-9C43-4A2A-8117-18DC4CDD4C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {41BB562D-9C43-4A2A-8117-18DC4CDD4C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {41BB562D-9C43-4A2A-8117-18DC4CDD4C7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {41BB562D-9C43-4A2A-8117-18DC4CDD4C7C}.Release|Any CPU.Build.0 = Release|Any CPU
23 | {EE6D9FE0-E821-460B-8E40-682075E32F39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {EE6D9FE0-E821-460B-8E40-682075E32F39}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {EE6D9FE0-E821-460B-8E40-682075E32F39}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {EE6D9FE0-E821-460B-8E40-682075E32F39}.Release|Any CPU.Build.0 = Release|Any CPU
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/AtemProxy/AtemProxy.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/AtemProxy/AtemProxyUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using LibAtem;
4 | using LibAtem.Commands.Audio;
5 | using LibAtem.Commands.Audio.Fairlight;
6 | using LibAtem.Commands.DataTransfer;
7 | using LibAtem.Net;
8 |
9 | namespace AtemProxy
10 | {
11 | public static class AtemProxyUtil
12 | {
13 |
14 | public static readonly Type[] AudioLevelCommands = new[]
15 | {
16 | typeof(FairlightMixerMasterLevelsCommand), typeof(FairlightMixerSourceLevelsCommand),
17 | typeof(FairlightMixerSendLevelsCommand), typeof(AudioMixerLevelsCommand),
18 | typeof(AudioMixerSendLevelsCommand)
19 | };
20 |
21 | public static readonly Type[] TransferCommands = new[]
22 | {
23 | typeof(DataTransferAbortCommand), typeof(DataTransferAckCommand),
24 | typeof(DataTransferCompleteCommand), typeof(DataTransferDataCommand), typeof(DataTransferErrorCommand),
25 | typeof(DataTransferDownloadRequestCommand), typeof(DataTransferUploadContinueCommand),
26 | typeof(DataTransferUploadRequestCommand)
27 | };
28 |
29 | public static readonly Type[] LockCommands = new[] {typeof(LockObtainedCommand), typeof(LockStateSetCommand)};
30 |
31 | public static byte[] ParsedCommandToBytes(ParsedCommandSpec cmd)
32 | {
33 | var build = new CommandBuilder(cmd.Name);
34 | build.AddByte(cmd.Body);
35 | return build.ToByteArray();
36 | }
37 |
38 | public static List CommandsToMessages(List commands)
39 | {
40 | var messages = new List();
41 | while (commands.Count > 0)
42 | {
43 | var builder = new OutboundMessageBuilder();
44 |
45 | int removeCount = 0;
46 | foreach (byte[] data in commands)
47 | {
48 | if (!builder.TryAddData(data))
49 | break;
50 |
51 | removeCount++;
52 | }
53 |
54 | if (removeCount == 0)
55 | {
56 | throw new Exception("Failed to build message!");
57 | }
58 |
59 | commands.RemoveRange(0, removeCount);
60 | messages.Add(builder.Create());
61 | // Log.InfoFormat("Length {0} {1}", builder.currentLength , removeCount);
62 | }
63 |
64 | return messages;
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/AtemProxy/AtemServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.Specialized;
4 | using System.Linq;
5 | using System.Net;
6 | using System.Net.Sockets;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using LibAtem.Commands;
10 | using LibAtem.Discovery;
11 | using LibAtem.Net;
12 | using log4net;
13 | using Makaretu.Dns;
14 |
15 | namespace AtemProxy
16 | {
17 | public class AtemServer
18 | {
19 | private static readonly ILog Log = LogManager.GetLogger(typeof(AtemServer));
20 |
21 | public ClientConnectionList Connections { get; } = new ClientConnectionList();
22 |
23 | private CommandQueue _state;
24 | private bool _accept = false;
25 |
26 | private Socket _socket;
27 | private readonly MulticastService _mdns = new MulticastService();
28 |
29 | // TODO - remove this list, and replace with something more sensible...
30 | private readonly List timers = new List();
31 |
32 | public AtemServer(CommandQueue state)
33 | {
34 | _state = state;
35 | }
36 |
37 | public void RejectConnections()
38 | {
39 | _accept = false;
40 | Connections.ClearAll();
41 | }
42 |
43 | public void AcceptConnections()
44 | {
45 | _accept = true;
46 | }
47 |
48 | public void StartAnnounce(string modelName, string deviceId)
49 | {
50 | _mdns.UseIpv4 = true;
51 | _mdns.UseIpv6 = false;
52 | var safeModelName = modelName.Replace(' ', '-').ToUpper();
53 | var domain = new DomainName($"Mock {modelName}.{AtemDeviceInfo.ServiceName}");
54 | var deviceDomain = new DomainName($"MOCK-{safeModelName}-{deviceId}.local");
55 |
56 | timers.Add(new Timer(o =>
57 | {
58 | Log.Info("MDNS announce");
59 | DoAnnounce(deviceId, modelName, domain, deviceDomain);
60 | }, null, 0, 10000));
61 | _mdns.QueryReceived += (s, e) =>
62 | {
63 | var msg = e.Message;
64 | if (msg.Questions.Any(q => q.Name == AtemDeviceInfo.ServiceName))
65 | {
66 | Log.Debug("MDNS query");
67 | DoAnnounce(deviceId, modelName, domain, deviceDomain);
68 | }
69 | };
70 | _mdns.Start();
71 | }
72 | private void DoAnnounce(string deviceId, string modelName, DomainName domain, DomainName deviceDomain)
73 | {
74 | var res = new Message();
75 | var addresses = MulticastService.GetIPAddresses()
76 | .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork);
77 | foreach (var address in addresses)
78 | {
79 | res.Answers.Add(new PTRRecord
80 | {
81 | Name = AtemDeviceInfo.ServiceName,
82 | DomainName = domain
83 | });
84 | res.AdditionalRecords.Add(new TXTRecord
85 | {
86 | Name = domain,
87 | Strings = new List
88 | {
89 | "txtvers=1",
90 | $"name=Blackmagic {modelName}",
91 | "class=AtemSwitcher",
92 | "protocol version=0.0",
93 | "internal version=FAKE",
94 | $"unique id={deviceId}"
95 | }
96 | });
97 | res.AdditionalRecords.Add(new ARecord
98 | {
99 | Address = address,
100 | Name = deviceDomain,
101 | });
102 | res.AdditionalRecords.Add(new SRVRecord
103 | {
104 | Name = domain,
105 | Port = 9910,
106 | Priority = 0,
107 | Target = deviceDomain,
108 | Weight = 0
109 | });
110 | /*
111 | res.AdditionalRecords.Add(new NSECRecord
112 | {
113 | Name = domain
114 | });*/
115 | }
116 | _mdns.SendAnswer(res);
117 | }
118 |
119 | public void StartPingTimer()
120 | {
121 | timers.Add(new Timer(o =>
122 | {
123 | Connections.QueuePings();
124 | }, null, 0, AtemConstants.PingInterval));
125 | }
126 |
127 | private static Socket CreateSocket()
128 | {
129 | Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
130 | IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 9910);
131 | serverSocket.Bind(ipEndPoint);
132 |
133 | return serverSocket;
134 | }
135 |
136 | public void StartReceive()
137 | {
138 | _socket = CreateSocket();
139 |
140 | var thread = new Thread(async () =>
141 | {
142 | while (true)
143 | {
144 | try
145 | {
146 | //Start receiving data
147 | ArraySegment buff = new ArraySegment(new byte[2500]);
148 | var end = new IPEndPoint(IPAddress.Any, 0);
149 | SocketReceiveFromResult v = await _socket.ReceiveFromAsync(buff, SocketFlags.None, end);
150 |
151 | // Check if we can accept it
152 | if (!_accept) continue;
153 |
154 | AtemServerConnection conn = Connections.FindOrCreateConnection(v.RemoteEndPoint, out _);
155 | if (conn == null)
156 | continue;
157 |
158 | byte[] buffer = buff.Array;
159 | var packet = new ReceivedPacket(buffer);
160 |
161 | if (packet.CommandCode.HasFlag(ReceivedPacket.CommandCodeFlags.Handshake))
162 | {
163 | conn.ResetConnStatsInfo();
164 | // send handshake back
165 | byte[] test =
166 | {
167 | buffer[0], buffer[1], // flags + length
168 | buffer[2], buffer[3], // session id
169 | 0x00, 0x00, // acked pkt id
170 | 0x00, 0x00, // retransmit request
171 | buffer[8], buffer[9], // unknown2
172 | 0x00, 0x00, // server pkt id
173 | 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00
174 | };
175 |
176 | var sendThread = new Thread(o =>
177 | {
178 | while (!conn.HasTimedOut)
179 | {
180 | conn.TrySendQueued(_socket);
181 | Task.Delay(1).Wait();
182 | }
183 | Console.WriteLine("send finished");
184 | });
185 | sendThread.Name = $"To {conn.Endpoint}";
186 | sendThread.Start();
187 |
188 | await _socket.SendToAsync(new ArraySegment(test, 0, 20), SocketFlags.None, v.RemoteEndPoint);
189 |
190 | continue;
191 | }
192 |
193 | if (!conn.IsOpened)
194 | {
195 | var recvThread = new Thread(o =>
196 | {
197 | while (!conn.HasTimedOut || conn.HasCommandsToProcess)
198 | {
199 | List cmds = conn.GetNextCommands();
200 |
201 | Log.DebugFormat("Recieved {0} commands", cmds.Count);
202 | //conn.HandleInner(_state, connection, cmds);
203 | }
204 | });
205 | recvThread.Name = $"Receive {conn.Endpoint}";
206 | recvThread.Start();
207 | }
208 | conn.Receive(_socket, packet);
209 |
210 | if (conn.ReadyForData)
211 | QueueDataDumps(conn);
212 | }
213 | catch (SocketException)
214 | {
215 | // Reinit the socket as it is now unavailable
216 | //_socket = CreateSocket();
217 | }
218 | }
219 | });
220 | thread.Name = "AtemServer";
221 | thread.Start();
222 | }
223 |
224 | private void QueueDataDumps(AtemConnection conn)
225 | {
226 | try
227 | {
228 | var messages = AtemProxyUtil.CommandsToMessages(_state.Values());
229 | foreach (var msg in messages)
230 | {
231 | conn.QueueMessage(msg);
232 | }
233 | }
234 | catch (Exception e)
235 | {
236 | Console.WriteLine(e.Message);
237 | }
238 | }
239 | }
240 | }
--------------------------------------------------------------------------------
/AtemProxy/AtemServerConnection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using LibAtem.Commands;
4 | using LibAtem.Net;
5 |
6 | namespace AtemProxy
7 | {
8 | public class AtemServerConnection : AtemConnection
9 | {
10 | public AtemServerConnection(EndPoint endpoint, int sessionId) : base(endpoint, sessionId)
11 | {
12 | }
13 |
14 | private bool _sentDataDump;
15 |
16 | public bool ReadyForData
17 | {
18 | get
19 | {
20 | if (_sentDataDump)
21 | return false;
22 |
23 | if (!IsOpened)
24 | return false;
25 |
26 | return _sentDataDump = true;
27 | }
28 | }
29 |
30 | protected override OutboundMessage CompileNextMessage()
31 | {
32 | // TODO
33 | return null;
34 | }
35 |
36 | public override void QueueCommand(ICommand command)
37 | {
38 | throw new NotImplementedException();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/AtemProxy/ClientConnectionList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Net;
4 | using LibAtem.Net;
5 | using log4net;
6 |
7 | namespace AtemProxy
8 | {
9 | public class ClientConnectionList
10 | {
11 | private static readonly ILog Log = LogManager.GetLogger(typeof(ClientConnectionList));
12 |
13 | private readonly Dictionary _connections =
14 | new Dictionary();
15 | private readonly HashSet _subscribedToAudio = new HashSet();
16 |
17 | public event AtemConnection.PacketHandler OnReceive;
18 |
19 | public ClientConnectionList()
20 | {
21 | }
22 |
23 | public AtemServerConnection FindOrCreateConnection(EndPoint ep, out bool isNew)
24 | {
25 | lock (_connections)
26 | {
27 | AtemServerConnection val;
28 | if (_connections.TryGetValue(ep, out val))
29 | {
30 | isNew = false;
31 | return val;
32 | }
33 |
34 | val = new AtemServerConnection(ep, 0x8008);// 0x8008 or 0x26B6? TODO - make dynamic
35 | _connections[ep] = val;
36 | val.OnDisconnect += RemoveTimedOut;
37 |
38 | val.OnReceivePacket += OnReceive;
39 |
40 | Log.InfoFormat("New connection from {0}", ep);
41 |
42 | isNew = true;
43 | return val;
44 | }
45 | }
46 |
47 | public void ClearAll()
48 | {
49 | lock (_connections)
50 | {
51 | _connections.Clear();
52 | }
53 |
54 | lock (_subscribedToAudio)
55 | {
56 | _subscribedToAudio.Clear();
57 | }
58 | }
59 |
60 | private void RemoveTimedOut(object sender)
61 | {
62 | var conn = sender as AtemServerConnection;
63 | if (conn == null)
64 | return;
65 |
66 | Log.InfoFormat("Lost connection to {0}", conn.Endpoint);
67 |
68 | lock (_connections)
69 | {
70 | _connections.Remove(conn.Endpoint);
71 | }
72 |
73 | lock (_subscribedToAudio)
74 | {
75 | // var initSize = _subscribedToAudio.Count;
76 | _subscribedToAudio.Remove(conn);
77 | }
78 | }
79 |
80 | internal void QueuePings()
81 | {
82 | lock (_connections)
83 | {
84 | var toRemove = new List();
85 | foreach (KeyValuePair conn in _connections)
86 | {
87 | if (conn.Value.HasTimedOut)
88 | {
89 | toRemove.Add(conn.Key);
90 | continue;
91 | }
92 |
93 | if (conn.Value.IsOpened)
94 | {
95 | conn.Value.QueuePing();
96 | }
97 | }
98 |
99 | foreach (var ep in toRemove)
100 | {
101 | Log.InfoFormat("Lost connection to {0}", ep);
102 | _connections.Remove(ep);
103 | }
104 | }
105 | }
106 |
107 | public void Broadcast(IReadOnlyList messages)
108 | {
109 | lock (_connections)
110 | {
111 | foreach (var conn in _connections)
112 | {
113 | if (!conn.Value.HasTimedOut)
114 | {
115 | foreach (var msg in messages)
116 | {
117 | conn.Value.QueueMessage(msg);
118 | }
119 | }
120 | }
121 | }
122 | }
123 |
124 | public void BroadcastAudioLevels(IReadOnlyList messages)
125 | {
126 | lock (_subscribedToAudio)
127 | {
128 | foreach (var conn in _subscribedToAudio)
129 | {
130 | if (!conn.HasTimedOut)
131 | {
132 | foreach (var msg in messages)
133 | {
134 | conn.QueueMessage(msg);
135 | }
136 | }
137 | }
138 | }
139 | }
140 |
141 | public bool SubscribeAudio(object sender, bool subscribed)
142 | {
143 | if (sender is AtemServerConnection {HasTimedOut: false} sender2)
144 | {
145 | lock (_subscribedToAudio)
146 | {
147 | if (subscribed)
148 | {
149 | var before = _subscribedToAudio.Count;
150 | _subscribedToAudio.Add(sender2);
151 | return before == 0;
152 | }
153 | else
154 | {
155 | var before = _subscribedToAudio.Count;
156 | _subscribedToAudio.Remove(sender2);
157 | return before != 0 && _subscribedToAudio.Count == 0;
158 | }
159 | }
160 | }
161 | else
162 | {
163 | return false;
164 | }
165 | }
166 |
167 | }
168 | }
--------------------------------------------------------------------------------
/AtemProxy/CommandQueue.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace AtemProxy
5 | {
6 | public class CommandQueue
7 | {
8 | private readonly Dictionary