-
Notifications
You must be signed in to change notification settings - Fork 0
/
atemgateway.py
executable file
·294 lines (283 loc) · 11.3 KB
/
atemgateway.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python
import logging
from atem import AtemDevice
from hmux import HMUXHandler
from threading import Thread
from time import sleep
import os
import math
logging.basicConfig()
class AtemGateway:
def __init__(self, ip, hmuxport,statusdest="HTC-Video"):
self.hmux = HMUXHandler(hmuxport)
self.hmux.setCallback(self.hmuxcb)
self.atem = AtemDevice(ip,callback=self.atemcb)
self.statusdest = statusdest
self.destmap = {0:"PP",1:"ME"}
self.tallycache = {}
self.audiovolumes = {}
def atemcb(self, cmd, args):
if cmd == "program":
me = self.destmap[args["me"]]
src = args["src"]
statusdest = self.statusdest
self.report("KAYAK",me,"PGM",src)
elif cmd == "preview":
me = self.destmap[args["me"]]
src = args["src"]
statusdest = self.statusdest
self.report("KAYAK",me,"PST",src)
elif cmd == "audio":
volume = args["volume"]
self.audiovolumes[args["src"]] = volume
self.report("AUDIO",args["src"],volume)
elif cmd == "audiomaster":
self.report("MASTER",args["volume"])
elif cmd == "key":
self.report("KEY",args["me"],args["keyer"],args["enabled"])
elif cmd == "keyinfo":
self.report("KEYINFO",args["me"],args["keyer"],args["keytype"],args["fillsrc"],args["keysrc"])
elif cmd == "keyluma":
self.report("KEYLUMA",args["me"],args["keyer"],args["premulti"],args["clip"],args["gain"],args["invert"])
elif cmd == "dsk":
if not args.get("trans"):
self.report("DSK",args["keyer"],args["onair"])
elif cmd == "dsksources":
self.report("DSKSOURCES",args["keyer"],args["fillsrc"],args["keysrc"])
elif cmd == "dsksetting":
self.report("DSKSETTING",args["keyer"],
args["tie"],args["premulti"],
args["clip"],args["gain"],args["invert"],args["masked"],
args["top"],args["bottom"],args["left"],args["right"],
)
elif cmd == "black":
if not args.get("trans"):
self.report("BLACK",args["me"],args["black"])
elif cmd == "tally":
sources = args["sources"]
for source in sources:
if source["dim"] != self.tallycache.get(source["src"]):
self.tallycache[source["src"]] = source["dim"]
self.report("TALLY",source["src"],source["dim"])
elif cmd == "color":
self.report("COLOR",args["generator"],args["src"])
elif cmd in ["connect","disconnect","timeout"]:
print "INFO;"+cmd
elif cmd in ["videomodes","videoformat"]:
pass
else:
print "WARN;ATEM",cmd,args
def report(self, *args):
if self.statusdest:
data = "\x02".join([str(x) for x in args])
self.hmux.send("<PORT"+self.statusdest+">\x01"+data+"\x00")
def moveVolume(self,src,volume, frames):
def moveThread(start,end,frames):
pos = start
speed = (end-start)/frames
while (start<end and pos < end) or (start>end and pos > end):
pos += speed
#volume = int(min((pow(1000,pos)/1000),1.99)*32768)
volume = int(pos*32768)
volume = min(volume,65535)
volume = max(volume,0)
print "Vol",volume
#if volume < 150: volume = 0
self.atem.audioSettings(src,volume=volume)
sleep(0.04)
print start,end,frames,speed,pos
start = self.audiovolumes[src]
end = volume
t = Thread(target=moveThread,args=(start,end,frames))
t.start()
def hmuxcb(self,data,src=None):
print "HMUX",data,src
args = data.split(":")
cmd = args.pop(0)
print cmd,args
if cmd == "CUE":
dst = args[0]
src = int(args[1])
if dst == "HB":
self.atem.preview(src,me=0)
elif dst == "BS":
self.atem.preview(src,me=1)
elif cmd == "PSTTAKE":
dst = args[0]
if dst == "HB":
me = 0
elif dst == "BS":
me = 1
mixtime = args[1]
self.atem.transSettings(style=0,me=me) # Mix
self.atem.mixSettings(int(mixtime),me=me)
self.atem.auto(me=me)
elif cmd in["TAKE"]:
dst,src,mixtime,mix = args
if dst == "HB":
me = 0
elif dst == "BS":
me = 1
elif dst.startswith("AUX"):
me = -1
aux = int(dst[3:])
if me < 0:
self.atem.aux(aux,int(src))
else:
if mix == "C":
self.atem.program(int(src),me=me)
elif mix == "M":
self.atem.preview(int(src),me=me)
self.atem.transSettings(style=0,me=me) # Mix
self.atem.mixSettings(int(mixtime),me=me)
self.atem.auto(me=me)
elif mix == "W":
self.atem.preview(int(src),me=me)
self.atem.transSettings(style=2,me=me) # Wipe
self.atem.wipeSettings(int(mixtime),me=me)
self.atem.auto(me=me)
elif cmd == "KEY":
me,keyer,enabled = args
self.atem.keyOn(int(enabled),me=int(me),keyer=int(keyer))
elif cmd == "KEYFILL":
me,keyer,source = args
self.atem.keyFill(int(source),me=int(me),keyer=int(keyer))
elif cmd == "CHROMAKEY":
me,keyer,enabled = args
self.atem.keyType(int(enabled),int(keyer),int(me))
elif cmd == "CHROMAHUE":
me,keyer,value = args
self.atem.keyChroma(int(me), int(keyer), hue=int(float(value)*10))
elif cmd == "CHROMAGAIN":
me,keyer,value = args
self.atem.keyChroma(int(me), int(keyer), gain=int(float(value)*10))
elif cmd == "CHROMAYSUP":
me,keyer,value = args
self.atem.keyChroma(int(me), int(keyer), ysup=int(float(value)*10))
elif cmd == "CHROMALIFT":
me,keyer,value = args
self.atem.keyChroma(int(me), int(keyer), lift=int(float(value)*10))
elif cmd == "CHROMANARROW":
me,keyer,value = args
self.atem.keyChroma(int(me), int(keyer), narrow=int(value))
elif cmd == "DSK":
keyer,enabled = args
self.atem.dskOn(int(keyer),int(enabled))
elif cmd == "DSKSOURCES":
keyer,fill,key = args
self.atem.dskFill(int(keyer),int(fill))
self.atem.dskKey(int(keyer),int(key))
elif cmd == "DSKLUMA":
keyer,premulti,clip,gain,invert = args
self.atem.dskLuma(int(keyer),int(premulti),int(clip),int(gain),int(invert))
elif cmd == "AUX":
chan,src= args
self.atem.aux(int(chan),int(src))
elif cmd == "VOLUME":
src,volume = args
self.atem.audioSettings(int(src),volume=int(volume),option=1)
elif cmd == "MASTERVOLUME":
volume, = args
self.atem.audioMaster(volume=int(volume))
elif cmd == "MOVEVOLUME":
src,volume,frames = args
self.moveVolume(int(src),volume=float(volume)/127,frames=int(frames))
elif cmd.startswith("MOVE\x02"):
cmd,src,volume,frames = cmd.split("\x02")
print cmd,src,volume,frames
if int(frames) <= 0: frames = 1
self.moveVolume(int(src),volume=float(volume),frames=int(frames))
elif cmd == "SSOURCE":
source, = args
self.atem.ssource(int(source))
elif cmd == "BOXSOURCE":
boxnum, source = args
self.atem.boxsrc(int(boxnum), 1, int(source))
elif cmd == "BOXENABLE":
boxnum,state = args
self.atem.boxsrc(int(boxnum),enable=int(state))
elif cmd == "BOXPOS":
boxnum, x, y, size = args
self.atem.boxsrc(int(boxnum),
x=int(float(x)*100),
y=int(float(y)*100),
size=int(float(size)*1000),
)
elif cmd == "BOXCROP":
if len(args) == 2:
boxnum, enable = args
if enable.lower() == "off":
self.atem.boxsrc(int(boxnum), cropped=0)
else:
boxnum, top, bottom, left, right = args
self.atem.boxsrc(int(boxnum), cropped=1,
top=int(float(top)*1000),
bottom=int(float(bottom)*1000),
left=int(float(left)*1000),
right=int(float(right)*1000),
)
elif cmd == "BOXPOSCROP":
boxnum, x, y, size, top, bottom, left, right = args
print "BPC:",boxnum, x, y, size, top, bottom, left, right
self.atem.boxsrc(int(boxnum), cropped=1,
x=int(float(x)*100),
y=int(float(y)*100),
size=int(float(size)*1000),
top=int(float(top)*1000),
bottom=int(float(bottom)*1000),
left=int(float(left)*1000),
right=int(float(right)*1000),
)
elif cmd == "KEYMASK":
me, keyer, masked, top, bottom, left, right = args
self.atem.keyMask(int(me), int(keyer), int(masked),
top=int(float(top)*1000),
bottom=int(float(bottom)*1000),
left=int(float(left)*1000),
right=int(float(right)*1000),
)
elif cmd.startswith("MVI"):
mviewer,window,source = args
self.atem.multiViewInput(int(mviewer),int(window),int(source))
elif cmd.startswith("COLOR"):
num,hue,sat,luma = args
self.atem.colorgen(int(num), int(hue), int(sat), int(luma))
elif cmd.startswith("VERSION"):
if self.atem.version:
ver = self.atem.version
self.hmux.send("<PORT%s>\x01VERSION %s.%s\x00"%(src,ver[0],ver[1]))
else:
self.hmux.send("<PORT%s>\x01VERSION unknown\x00"%(src,))
else:
print "Unknown command",cmd,args
def run(self):
self.hmux.serve_forever()
def getSockets(self):
return self.hmux.getSockets()
def handleSockets(self, sockets):
return self.hmux.handleSockets(sockets)
if __name__ == '__main__':
try:
try:
from daemonctl import dts
except:
import daemontools as dts
#name = os.path.basename(__file__).split(".")[0]
dts.init()
cfg = dts.cfg
except Exception as e:
print e
dts = None
cfg = {"server":"10.20.126.242","hmuxport":12345,"statusdest":"SONYMIXER"}
try:
from pysvt.herrchef import HerrChef
hc = HerrChef()
hc.start()
except:
pass
agw = AtemGateway(cfg.get("server"),int(cfg.get("hmuxport")),cfg.get("statusdest"))
if dts is None:
agw.run()
else:
dts.addModule(agw)
dts.serve_forever()