-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_script_win.py
More file actions
293 lines (203 loc) · 13.7 KB
/
main_script_win.py
File metadata and controls
293 lines (203 loc) · 13.7 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
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
import alumia_TCP
import time
import alumia_VideoTools
import alumia_state_manager
STREAM_PATH = 'http://193.168.1.2:8000/stream.mjpeg'
PROCESS_SLEEP_TIME = 0.01
ROOT_SHARED = "E://"
NUMBER_OF_CLIENTS = 4
if __name__ == '__main__':
#-------INIT TCP SERVER------#
tcp_server = alumia_TCP.TCPServer(server_ip="193.168.1.3", server_port=12840, code="win")
#-------------//-------------#
#populate network
while len(tcp_server.tcp_inputs) != NUMBER_OF_CLIENTS:
print("Some connections to server are still missing...")
tcp_server.get_select()
for s in tcp_server.readable:
if s is tcp_server.server:
tcp_server.accept_conn(s)
else:
tcp_server.add_to_outputs(s)
time.sleep(1)
print("All connections established!")
time.sleep(1)
#-------INIT SCREEN PROJECTION------#
video_projector = alumia_VideoTools.VideoProjector()
video_projector.start()
#------------------//-----------------#
#-------INIT SCREEN PROJECTION------#
video_tracker = alumia_VideoTools.VideoFrameTracker()
video_tracker.start()
#------------------//-----------------#
#-------INIT STATE CONTROL------#
state_control = alumia_state_manager.StateManager(root=ROOT_SHARED)
#----------------//-----------------#
while tcp_server.tcp_inputs:
tcp_server.get_select()
for s in tcp_server.readable:
if s is tcp_server.server:
tcp_server.accept_conn(s)
else:
data = tcp_server.server_recv(connection=s)
if data:
tcp_server.add_to_outputs(s)
if data[2] == "9":
if data[0] == "agc":
tcp_server.server_send("193.168.1.2", data)
elif data[0] == "gain":
tcp_server.server_send("193.168.1.2", data)
elif data[0] == "awb":
tcp_server.server_send("193.168.1.2", data)
elif data[2] == "mon": # monitor is asking for an action
if "msp" in data[0]:
tcp_server.server_send("193.168.1.3", data[0]+"_"+data[1])
elif data[0] == "rec": # new recording
#send info to ras script to record video
tcp_server.server_send("193.168.1.2", "rec_0")
elif data[0] == "stop": # stop recording
# inform rasp we want to stop
tcp_server.server_send("193.168.1.2", "stop_0")
elif data[0] == "str": # start/stop stream
# inform rasp
tcp_server.server_send("193.168.1.2", "str_0")
elif data[0] == "fld": # confirmed all changes in folder
params = data[1].split("&")
state_control.change_work_folder(params[0], params[1])
state_control.last_main_number = params[2]
state_control.last_snippet_number = params[3]
elif data[0] == "fps":
tcp_server.server_send("193.168.1.2", "fps_"+data[1])
elif data[0] == "exp":
tcp_server.server_send("193.168.1.2", "exp_"+data[1])
elif data[0] == "blk":
if data[1] == "0":
tcp_server.server_send("193.168.1.4", "blk_"+str(state_control.current_blk))
else:
if data[1] == "1":
if state_control.current_blk < 10:
state_control.current_blk += 1
to_queue_dict = {"fps": -1, "black_frame_ratio": state_control.current_blk, "video_path": -1, "editing_func": -1}
video_projector.set_input_queue(to_queue_dict)
tcp_server.server_send("193.168.1.4", "blk_"+str(state_control.current_blk))
elif data[1] == "-1":
if state_control.current_blk > 1:
state_control.current_blk -= 1
to_queue_dict = {"fps": -1, "black_frame_ratio": state_control.current_blk, "video_path": -1, "editing_func": -1}
video_projector.set_input_queue(to_queue_dict)
tcp_server.server_send("193.168.1.4", "blk_"+str(state_control.current_blk))
elif data[0] == "edt":
if data[1] == "0":
tcp_server.server_send("193.168.1.4", "edt_"+str(state_control.current_edt))
else:
if data[1] == "1":
if state_control.current_edt < 6:
state_control.current_edt += 1
video_projector.editing_tools.curr_edit_func = state_control.current_edt
to_queue_dict = {"fps": -1, "black_frame_ratio": -1, "video_path": -1, "editing_func": state_control.current_edt}
video_projector.set_input_queue(to_queue_dict)
tcp_server.server_send("193.168.1.4", "edt_"+str(state_control.current_edt))
elif data[1] == "-1":
if state_control.current_edt > 1:
state_control.current_edt -= 1
video_projector.editing_tools.curr_edit_func = state_control.current_edt
to_queue_dict = {"fps": -1, "black_frame_ratio": -1, "video_path": -1, "editing_func": state_control.current_edt}
video_projector.set_input_queue(to_queue_dict)
tcp_server.server_send("193.168.1.4", "edt_"+str(state_control.current_edt))
elif data[0] == "bperf":# we want to begin the performance
tcp_server.server_send("193.168.1.2", "bperf_0")
elif data[0] == "eperf":# we want to stop the performance
tcp_server.server_send("193.168.1.2", "eperf_0")
elif data[0] == "play":# we want to play a video
params = data[1].split("&")
video_path = state_control.total_path + params[0] + "_" + params[1] +".avi"
to_queue_dict = {"fps": -1, "black_frame_ratio": -1, "video_path": video_path, "editing_func": -1}
video_projector.set_input_queue(to_queue_dict)
# after loading the video on the projector, we should hold the first frame until we get max confirmation
tcp_server.server_send("193.168.1.3", "play_" + data[1])
# there should be a reply from max
elif data[2] == "ras": # ras is confirming something
if data[0] == "rec": # we started recording
params = data[1].split("&")
#win should start processing
video_path = state_control.total_path + params[0] + "_" + params[1] + ".avi"
state_control.last_snippet_number = params[1]
input_info = ["snippet", video_path, state_control.current_fps]
video_tracker.set_input_queue(input_info)
#inform max we want to start recording that file
tcp_server.server_send("193.168.1.3", "rec_" + data[1])
# in max update internal state
#inform monitor to show video is recording
tcp_server.server_send("193.168.1.4", "vid_1")
elif data[0] == "stop": # we stopped recording
#win should stop processing
video_tracker.set_input_queue(["track", "", ""])
#inform max we want to stop recording
tcp_server.server_send("193.168.1.3", "stop_" + data[1])
#inform monitor video stopped recording
tcp_server.server_send("193.168.1.4", "vid_0")
elif data[0] == "str": # stream started/stopped
if data[1] == "0":# stopped
# win stops stream projection
video_projector.set_stop_queue("end")
state_control.stream_state = False
#inform monitor we stopped streaming
tcp_server.server_send("193.168.1.4", "str_0")
else:# started
#win starts projection
video_path = STREAM_PATH
to_queue_dict = {"fps": -1, "black_frame_ratio": -1, "video_path": video_path, "editing_func": -1}
video_projector.set_input_queue(to_queue_dict)
state_control.stream_state = True
#inform monitor started stream
tcp_server.server_send("193.168.1.4", "str_1")
elif data[0] == "fld": #rasp confirms folder change
# ask monitor to save that folder
tcp_server.server_send("193.168.1.4", "fld_"+data[1])
elif data[0] == "fps":
tcp_server.server_send("193.168.1.4", "fps_"+data[1])
state_control.current_fps = int(data[1])
elif data[0] == "exp":
tcp_server.server_send("193.168.1.4", "exp_"+data[1])
elif data[0] == "bperf":
state_control.last_main_number = data[1]
video_path = state_control.total_path + data[1] + ".mjpeg"
video_tracker.set_input_queue(["track", video_path])
tcp_server.server_send("193.168.1.3", "bperf_"+ data[1]) # to max we should inform about the video number
tcp_server.server_send("193.168.1.4", "bperf_0")
elif data[0] == "eperf":
video_tracker.set_input_queue(["stop", ""])
tcp_server.server_send("193.168.1.3", "eperf_0")
tcp_server.server_send("193.168.1.4", "eperf_0")
elif data[2] == "max": # max wants to confirm something
if data[0] == "rec": # confirm audio is being recorded
# inform monitor audio is being recorded
tcp_server.server_send("193.168.1.4", "aud_1")
elif data[0] == "stop":# confirm audio stoped recording
# informs monitor audio stoped recording
tcp_server.server_send("193.168.1.4", "aud_0")
elif data[0] == "fld":# change work folder
# inform rasp of this change
tcp_server.server_send("193.168.1.2", "fld_"+ data[1])
elif data [0] == "play":# reply with the audio's duration
print(float(data[1]))
to_queue_dict = {"duration": float(data[1])}
video_projector.set_input_queue(to_queue_dict)
elif "msp" in data[0]:
tcp_server.server_send("193.168.1.4", data[0] + "_" + data[1])
elif data[0] == "isogain":
tcp_server.server_send("193.168.1.2", data[0] + "_" + data[1])
elif data[0] == "agc":
tcp_server.server_send("193.168.1.2", data[0] + "_" + data[1])
elif data[0] == "awb":
tcp_server.server_send("193.168.1.2", data[0] + "_" + data[1])
elif data[0] == "end": # close everything
if video_tracker.video_processor.process_state == False and video_projector.play_state == False and state_control.stream_state == False:
# informs monitor and rasp to close
tcp_server.server_send("193.168.1.2", "end_0")
tcp_server.server_send("193.168.1.4", "end_0")
#close local
tcp_server.server_close()
video_projector.join()
exit()
time.sleep(PROCESS_SLEEP_TIME)