forked from robotstreamer/robotstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_video.py
663 lines (516 loc) · 25 KB
/
send_video.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
import subprocess
import shlex
import re
import os
import time
import platform
import json
import sys
import base64
import random
import datetime
import traceback
import robot_util
import _thread
import copy
import argparse
import audio_util
import urllib.request
import rtc_signalling
from subprocess import Popen, PIPE
from threading import Thread
from queue import Queue
#from Queue import Queue # Python 2
import video_util
try:
from usb.core import find as finddev
except:
print("usb MODULE IMPORT FAILED, TRY INSTALLING WITH pip")
class DummyProcess:
def poll(self):
return None
def __init__(self):
self.pid = 123456789
parser = argparse.ArgumentParser(description='robot control')
parser.add_argument('camera_id')
parser.add_argument('video_device_number', default=0, type=int)
parser.add_argument('--api-url', help="Server that robot will connect to listen for API update events", default='https://api.robotstreamer.com')
parser.add_argument('--xres', type=int, default=768)
parser.add_argument('--yres', type=int, default=432)
parser.add_argument('--audio-device-number', default=1, type=int)
parser.add_argument('--audio-device-name')
parser.add_argument('--audio-rate', default="32000", help="examples: 44100 or 48000 or 16000,32000 it will alternate if comma delimited, this helped make a C920 work for whatever reason")
parser.add_argument('--kbps', default=350, type=int)
parser.add_argument('--kbps-audio', default=64, type=int)
parser.add_argument('--framerate', default=25, type=int)
parser.add_argument('--protocol', default='jsmpeg', help="options: jsmpeg, H264, VP8")
parser.add_argument('--h264preset', default='ultrafast')
parser.add_argument('--h264extraParams', default='-tune zerolatency')
parser.add_argument('--h264codecParams', default='nal-hrd=cbr:keyint=50')
parser.add_argument('--VPXextraParams', default='')
parser.add_argument('--brightness', type=int, help='camera brightness')
parser.add_argument('--contrast', type=int, help='camera contrast')
parser.add_argument('--saturation', type=int, help='camera saturation')
parser.add_argument('--rotate180', default=False, type=bool, help='rotate image 180 degrees')
parser.add_argument('--env', default="prod")
parser.add_argument('--screen-capture', dest='screen_capture', action='store_true') # tells windows to pull from different camera, this should just be replaced with a video input device option
parser.set_defaults(screen_capture=False)
parser.add_argument('--no-mic', dest='mic_enabled', action='store_false')
parser.set_defaults(mic_enabled=True)
parser.add_argument('--restart-on-video-fail', dest='restart_on_video_fail', action='store_true')
parser.set_defaults(restart_on_video_fail=False)
parser.add_argument('--no-audio-restart', dest='audio_restart_enabled', action='store_false')
parser.set_defaults(audio_restart_enabled=True)
parser.add_argument('--no-camera', dest='camera_enabled', action='store_false')
parser.set_defaults(camera_enabled=True)
parser.add_argument('--dry-run', dest='dry_run', action='store_true')
parser.add_argument('--mic-channels', type=int, help='microphone channels, typically 1 or 2', default=1)
parser.add_argument('--audio-input-device', default='Microphone (HD Webcam C270)') # currently, this option is only used for windows screen capture
parser.add_argument('--stream-key', default='hellobluecat')
parser.add_argument('--ffmpeg-path', default='/usr/local/bin/ffmpeg')
parser.add_argument('--usb-reset-id', default=None)
charCount = {}
lastCharCount = None
commandArgs = parser.parse_args()
#print("sleeping")
#time.sleep(commandArgs.video_device_number * 2) # this is so they don't run at the same time if you start many simultaneously
#workingVideoDevices = video_util.findWorkingVideoDevices()
robotSettings = None
resolutionChanged = False
currentXres = None
currentYres = None
apiServer = commandArgs.api_url
websocketSFU = None
audioProcess = None
videoProcess = None
#from socketIO_client import SocketIO, LoggingNamespace
# enable raspicam driver in case a raspicam is being used
os.system("sudo modprobe bcm2835-v4l2")
def sayInfo(message):
f = open("/tmp/tempfile", "w")
f.write(message)
f.close()
os.system("espeak -a 20 -p 160 -f /tmp/tempfile -ven-sc+f3 test --stdout | aplay -D plughw:3,0")
os.unlink("/tmp/tempfile")
def reader(pipe, queue):
try:
with pipe:
#for line in iter(pipe.readline, b''):
# queue.put((pipe, line))
while True:
c = pipe.read(1)
if not c:
print("End of file")
break
#print("Read a character:", c)
queue.put((pipe, c))
finally:
queue.put(None)
def printOutput(label, q):
global charCount
charCount[label] = 0
for _ in range(2):
for source, line in iter(q.get, None):
print(line.decode("utf-8"), end="")
charCount[label] += 1
#print(label + "(" + str(charCount[label]) + ")", end="")
#print("%s %s: %s" % (label, source, line))
def runAndMonitor(label, command):
process = Popen(command, stdout=PIPE, stderr=PIPE, bufsize=1)
q = Queue()
Thread(target=reader, args=[process.stdout, q]).start()
Thread(target=reader, args=[process.stderr, q]).start()
Thread(target=printOutput, args=[label, q]).start()
return process
def getVideoEndpoint():
url = '%s/v1/get_endpoint/jsmpeg_video_capture/%s' % (apiServer, commandArgs.camera_id)
response = robot_util.getWithRetry(url)
return json.loads(response)
def getAudioEndpoint():
url = '%s/v1/get_endpoint/jsmpeg_audio_capture/%s' % (apiServer, commandArgs.camera_id)
response = robot_util.getWithRetry(url)
return json.loads(response)
def getVideoSFU():
url = '%s/v1/get_endpoint/webrtc_sfu/100' % (apiServer)
response = robot_util.getWithRetry(url)
return json.loads(response)
def getOnlineRobotSettings(robotID):
url = '%s/api/v1/robots/%s' % (apiServer, robotID)
response = robot_util.getWithRetry(url)
return json.loads(response)
def randomSleep():
"""A short wait is good for quick recovery, but sometimes a longer delay is needed or it will just keep
trying and failing short intervals, like because the system thinks the port is still in use and every retry
makes the system think it's still in use. So, this has a high likelihood of picking a short interval,
but will pick a long one sometimes."""
timeToWait = random.choice((0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1))
t = timeToWait * 12.0
print("sleeping", t, "seconds")
time.sleep(t)
def startVideoCaptureLinux():
videoEndpoint = getVideoEndpoint()
videoHost = videoEndpoint['host']
videoPort = videoEndpoint['port']
print("start video capture, video endpoint:", videoEndpoint)
# set brightness
if (robotSettings.brightness is not None):
print("brightness")
os.system("v4l2-ctl -c brightness={brightness}".format(brightness=robotSettings.brightness))
# set contrast
if (robotSettings.contrast is not None):
print("contrast")
os.system("v4l2-ctl -c contrast={contrast}".format(contrast=robotSettings.contrast))
# set saturation
if (robotSettings.saturation is not None):
print("saturation")
os.system("v4l2-ctl -c saturation={saturation}".format(saturation=robotSettings.saturation))
videoCommandLine = '{ffmpeg_path} -f v4l2 -framerate 25 -video_size {xres}x{yres} -r 25 -i /dev/video{video_device_number} {rotation_option} \
-f mpegts -codec:v mpeg1video -b:v {kbps}k -bf 0 -muxdelay 0.001 http://{video_host}:{video_port}/{stream_key}/{xres}/{yres}/'\
.format(ffmpeg_path=robotSettings.ffmpeg_path, video_device_number=robotSettings.video_device_number, rotation_option=rotationOption(),\
kbps=robotSettings.kbps, video_host=videoHost, video_port=videoPort, xres=robotSettings.xres, yres=robotSettings.yres, stream_key=robotSettings.stream_key)
print(videoCommandLine)
#return subprocess.Popen(shlex.split(videoCommandLine))
return runAndMonitor("video", shlex.split(videoCommandLine))
startAudioCounter = 0
def startAudioCaptureLinux():
global startAudioCounter
audioEndpoint = getAudioEndpoint()
audioHost = audioEndpoint['host']
audioPort = audioEndpoint['port']
# if a comma delimited list of rates is given, this
# switches the rate each time this is called. for some reason this makes a C920 work more reliably
# particularly on cornbot
if ',' in robotSettings.audio_rate:
rates = robotSettings.audio_rate.split(',')
audioRate = int(rates[startAudioCounter % len(rates)])
startAudioCounter += 1
else:
audioRate = int(robotSettings.audio_rate)
audioDevNum = robotSettings.audio_device_number
if robotSettings.audio_device_name is not None:
audioDevNum = audio_util.getAudioRecordingDeviceByName(robotSettings.audio_device_name)
if audioDevNum is None:
raise Exception("the name doesn't exist" + robotSettings.audio_device_name)
print((robotSettings.ffmpeg_path, audioRate, robotSettings.mic_channels, audioDevNum, audioHost, audioPort, robotSettings.stream_key))
#audioCommandLine = '%s -f alsa -ar 44100 -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 32k -muxdelay 0.001 http://%s:%s/%s/640/480/' % (robotSettings.ffmpeg_path, robotSettings.mic_channels, audioDevNum, audioHost, audioEndpoint['port'], robotSettings.stream_key)
audioCommandLine = '%s -f alsa -ar %d -ac %d -i hw:%d -f mpegts -codec:a mp2 -b:a 64k -muxdelay 0.01 http://%s:%s/%s/640/480/'\
% (robotSettings.ffmpeg_path, audioRate, robotSettings.mic_channels, audioDevNum, audioHost, audioPort, robotSettings.stream_key)
print(audioCommandLine)
if commandArgs.usb_reset_id != None:
if len(commandArgs.usb_reset_id) == 8:
vendor_id=int(commandArgs.usb_reset_id[0:4], 16)
product_id=int(commandArgs.usb_reset_id[4:], 16)
dev=finddev(idVendor=vendor_id, idProduct=product_id)
dev.reset()
#return subprocess.Popen(shlex.split(audioCommandLine))
return runAndMonitor("audio", shlex.split(audioCommandLine))
def rotationOption():
if robotSettings.rotate180:
return "-vf transpose=2,transpose=2"
else:
return ""
def onCommandToRobot(*args):
global robotID
if len(args) > 0 and 'robot_id' in args[0] and args[0]['robot_id'] == robotID:
commandMessage = args[0]
print('command for this robot received:', commandMessage)
command = commandMessage['command']
if command == 'VIDOFF':
print('disabling camera capture process')
print("args", args)
robotSettings.camera_enabled = False
os.system("killall ffmpeg")
if command == 'VIDON':
if robotSettings.camera_enabled:
print('enabling camera capture process')
print("args", args)
robotSettings.camera_enabled = True
sys.stdout.flush()
def onConnection(*args):
print('connection:', args)
sys.stdout.flush()
def onRobotSettingsChanged(*args):
print('---------------------------------------')
print('set message recieved:', args)
refreshFromOnlineSettings()
def killallFFMPEGIn30Seconds():
time.sleep(30)
os.system("killall ffmpeg")
#todo, this needs to work differently. likely the configuration will be json and pull in stuff from command line rather than the other way around.
def overrideSettings(commandArgs, onlineSettings):
global resolutionChanged
global currentXres
global currentYres
resolutionChanged = False
c = copy.deepcopy(commandArgs)
print("onlineSettings:", onlineSettings)
if 'mic_enabled' in onlineSettings:
c.mic_enabled = onlineSettings['mic_enabled']
if 'xres' in onlineSettings:
if currentXres != onlineSettings['xres']:
resolutionChanged = True
c.xres = onlineSettings['xres']
currentXres = onlineSettings['xres']
if 'yres' in onlineSettings:
if currentYres != onlineSettings['yres']:
resolutionChanged = True
c.yres = onlineSettings['yres']
currentYres = onlineSettings['yres']
print("onlineSettings['mic_enabled']:", onlineSettings['mic_enabled'])
return c
def refreshFromOnlineSettings():
global robotSettings
global resolutionChanged
print("refreshing from online settings")
#onlineSettings = getOnlineRobotSettings(robotID)
#robotSettings = overrideSettings(commandArgs, onlineSettings)
robotSettings = commandArgs
if not robotSettings.mic_enabled:
print("KILLING**********************")
if audioProcess is not None:
print("KILLING**********************")
audioProcess.kill()
if resolutionChanged:
print("KILLING VIDEO DUE TO RESOLUTION CHANGE**********************")
if videoProcess is not None:
print("KILLING**********************")
videoProcess.kill()
else:
print("NOT KILLING***********************")
def checkForStuckProcesses():
global lastCharCount
global videoProcess
if lastCharCount is not None:
if robotSettings.camera_enabled:
videoInfoRate = charCount['video'] - lastCharCount['video']
print("video info rate:", videoInfoRate)
if abs(videoInfoRate) < 10:
print("video process has stopped outputting info")
print("KILLING VIDEO PROCESS")
videoProcess.kill()
if robotSettings.mic_enabled and robotSettings.protocol == 'jsmpeg':
audioInfoRate = charCount['audio'] - lastCharCount['audio']
print("audio info rate:", audioInfoRate)
if abs(audioInfoRate) < 10:
print("audio process has stopped outputting info")
print("KILLING AUDIO PROCESS")
audioProcess.kill()
print("ffmpeg output character count:", charCount)
lastCharCount = copy.deepcopy(charCount)
def startRTCffmpeg(videoEndpoint, SSRCV, audioEndpoint, SSRCA):
# set brightness
if (robotSettings.brightness is not None):
print("brightness")
os.system("v4l2-ctl -c brightness={brightness}".format(brightness=robotSettings.brightness))
# set contrast
if (robotSettings.contrast is not None):
print("contrast")
os.system("v4l2-ctl -c contrast={contrast}".format(contrast=robotSettings.contrast))
# set saturation
if (robotSettings.saturation is not None):
print("saturation")
os.system("v4l2-ctl -c saturation={saturation}".format(saturation=robotSettings.saturation))
audioDevNum = robotSettings.audio_device_number
if robotSettings.audio_device_name is not None:
audioDevNum = audio_util.getAudioRecordingDeviceByName(robotSettings.audio_device_name)
if robotSettings.protocol == 'video/VP8':
#ffmpeg -h encoder=libvpx
videoParameters = '-c:v libvpx \
{VPXextraParams} \
-tune psnr \
-deadline realtime \
-quality realtime \
-cpu-used 16 \
-pix_fmt yuv420p \
-b:v {kbps}k \
-preset ultrafast \
-map 0:v:0'\
.format(kbps=robotSettings.kbps,
VPXextraParams=robotSettings.VPXextraParams)
else:
#ffmpeg -h encoder=libx264
videoParameters = '-c:v libx264 \
-pix_fmt yuv420p \
-vsync 2 \
-x264-params "{h264codecParams}" \
-b:v {kbps}k -minrate {kbps}k -maxrate {kbps}k -bufsize 2M \
-preset {h264preset} \
{h264extraParams}\
-g 50 \
-map 0:v:0'\
.format(kbps=robotSettings.kbps,
h264codecParams=robotSettings.h264codecParams,
h264preset=robotSettings.h264preset,
h264extraParams=robotSettings.h264extraParams)
videoCommandLine = '{ffmpeg_path} \
-f v4l2 -video_size {xres}x{yres} -r {framerate} -i /dev/video{video_device_number} {rotation_option} \
-f alsa -i hw:{audio_device_number} \
{video} \
-c:a libopus \
-b:a {kbpsAudio}k \
-async 1 \
-preset ultrafast \
-map 1:a:0 \
-f tee "[select=a:f=rtp:ssrc={SSRCA}:payload_type=100]rtp://{audio_host}:{audio_port}|[select=v:f=rtp:ssrc={SSRCV}:payload_type=101]rtp://{video_host}:{video_port}"'\
.format(ffmpeg_path=robotSettings.ffmpeg_path,
video_device_number=robotSettings.video_device_number,
xres=robotSettings.xres,
yres=robotSettings.yres,
framerate=robotSettings.framerate,
audio_device_number=audioDevNum,
rotation_option=rotationOption(),
video=videoParameters,
kbpsAudio=robotSettings.kbps_audio,
audio_host=audioEndpoint['localIp'], audio_port=audioEndpoint['localPort'],
video_host=videoEndpoint['localIp'], video_port=videoEndpoint['localPort'],
SSRCA=SSRCA, SSRCV=SSRCV)
print(videoCommandLine)
return runAndMonitor("video", shlex.split(videoCommandLine))
#return subprocess.Popen(shlex.split(videoCommandLine))
def startRTCvideo():
global websocketSFU
global videoProcess
print("RTC Codec: ", robotSettings.protocol)
# convert camera_id to robot
robotID = str(int(commandArgs.camera_id) - int(100))
videoSSRC = int(random.randint(1000,9999))
audioSSRC = int(random.randint(1000,9999))
peerID = str(random.randint(100000,999999))
videoSFU = getVideoSFU()
print("robotID: ", robotID)
print("videoSSRC: ", videoSSRC)
print("audioSSRC: ", audioSSRC)
print("SFU", videoSFU)
if websocketSFU:
# close if open to dump the old transports
websocketSFU.close()
websocketSFU = rtc_signalling.SFUClient('wss://'+str(videoSFU['host'])+':'+str(videoSFU['port'])\
+'/?roomId='+robotID+'&peerId=p:robot_'+peerID, protocols=['protoo'])
websocketSFU.init(robotSettings.stream_key,
robotSettings.protocol,
videoSSRC,
audioSSRC)
websocketSFU.connect()
websocketSFU.getRouterRtpCapabilities() #n/a producer
websocketSFU.requestPlainTransportVideo()
websocketSFU.requestPlainTransportAudio()
# wait for endpoint results
while websocketSFU.videoEndpoint == False:
pass
while websocketSFU.audioEndpoint == False:
pass
videoProcess = startRTCffmpeg(websocketSFU.videoEndpoint, videoSSRC, websocketSFU.audioEndpoint, audioSSRC)
return
def checkVideoDevices():
import os.path
if os.path.exists("/dev/video" + str(robotSettings.video_device_number)):
#sayInfo("video device " + str(robotSettings.video_device_number) + " exists")
pass
else:
sayInfo("video device " + str(robotSettings.video_device_number) + " is missing")
def main():
global robotID
global audioProcess
global videoProcess
numVideoRestarts = 0
numAudioRestarts = 0
count = 0
# overrides command line parameters using config file
print("args on command line:", commandArgs)
print("camera id:", commandArgs.camera_id)
refreshFromOnlineSettings()
print("args after loading from server:", robotSettings)
if robotSettings.protocol != 'jsmpeg':
robotSettings.protocol = 'video/'+str(robotSettings.protocol)
robot_util.sendCameraAliveMessage(apiServer, commandArgs.camera_id, commandArgs.stream_key)
sys.stdout.flush()
checkVideoDevices()
if robotSettings.protocol != 'jsmpeg':
# RTC
startRTCvideo()
else:
# jsmpeg
if robotSettings.camera_enabled:
if not commandArgs.dry_run:
videoProcess = startVideoCaptureLinux()
else:
videoProcess = DummyProcess()
if robotSettings.mic_enabled:
if not commandArgs.dry_run:
audioProcess = startAudioCaptureLinux()
if commandArgs.audio_restart_enabled:
_thread.start_new_thread(killallFFMPEGIn30Seconds, ())
#appServerSocketIO.emit('send_video_process_start_event', {'camera_id': commandArgs.camera_id})
else:
audioProcess = DummyProcess()
# loop forever and monitor status of ffmpeg processes
while True:
print("-----------------" + str(count) + "-----------------")
#todo: start using this again
#appServerSocketIO.wait(seconds=1)
time.sleep(1)
# todo jsmpeg: note about the following ffmpeg_process_exists is not technically true, but need to update
# server code to check for send_video_process_exists if you want to set it technically accurate
# because the process doesn't always exist, like when the relay is not started yet.
# send status to server
######appServerSocketIO.emit('send_video_status', {'send_video_process_exists': True,
###### 'ffmpeg_process_exists': True,
###### 'camera_id':commandArgs.camera_id})
if numVideoRestarts > 20:
if commandArgs.restart_on_video_fail:
print("rebooting in 20 seconds because of too many restarts. probably lost connection to camera")
time.sleep(20)
os.system("sudo reboot")
if count % 20 == 0:
try:
with os.fdopen(os.open('/tmp/send_video_summary.txt', os.O_WRONLY | os.O_CREAT, 0o777), 'w') as statusFile:
statusFile.write("time" + str(datetime.datetime.now()) + "\n")
statusFile.write("video process poll " + str(videoProcess.poll()) + " pid " + str(videoProcess.pid) + " restarts " + str(numVideoRestarts) + " \n")
statusFile.write("audio process poll " + str(audioProcess.poll()) + " pid " + str(audioProcess.pid) + " restarts " + str(numAudioRestarts) + " \n")
print("status file written")
sys.stdout.flush()
except:
print("status file could not be written")
traceback.print_exc()
sys.stdout.flush()
if (count % robot_util.KeepAlivePeriod) == 0:
print("")
print("sending camera alive message")
print("")
robot_util.sendCameraAliveMessage(apiServer,
commandArgs.camera_id,
robotSettings.stream_key)
if (count % 2) == 0:
checkForStuckProcesses()
# poll when jsmpeg and rtc
if robotSettings.camera_enabled and videoProcess:
print("video process poll", videoProcess.poll(), "pid", videoProcess.pid, "restarts", numVideoRestarts)
# restart video if needed
if videoProcess.poll() != None:
randomSleep()
if robotSettings.protocol != 'jsmpeg':
print("RESTART RTC")
startRTCvideo()
else:
#jsmpeg restart
videoProcess = startVideoCaptureLinux()
numVideoRestarts += 1
else:
print("video process poll: camera_enabled is false")
# only poll when jsmpeg; rtc has no audio process
if robotSettings.mic_enabled and robotSettings.protocol == 'jsmpeg':
if audioProcess is None:
print("audio process poll: audioProcess object is None")
else:
print("audio process poll", audioProcess.poll(), "pid", audioProcess.pid, "restarts", numAudioRestarts)
# restart audio if needed
if (audioProcess is None) or (audioProcess.poll() != None):
randomSleep()
audioProcess = startAudioCaptureLinux()
#time.sleep(30)
#appServerSocketIO.emit('send_video_process_start_event', {'camera_id': commandArgs.camera_id})
numAudioRestarts += 1
else:
print("audio process poll: mic_enabled is false")
count += 1
main()