Esempio n. 1
0
def main():
    count = 0
    robot_util.sendCameraAliveMessage(infoServerProtocol, infoServer,
                                      commandArgs.camera_id)

    sys.stdout.flush()

    # loop forever and send keep alive every robot_util.KeepAlivePeriod seconds
    while True:
        time.sleep(10)
        if (count % 5) == 0:
            print(count)
        if (count % robot_util.KeepAlivePeriod) == 0:
            robot_util.sendCameraAliveMessage(infoServerProtocol, infoServer,
                                              commandArgs.camera_id)

        count += 1
def main():

    global videoProcess
    global audioProcess

    # clean up, kill any ffmpeg process that are hanging around from a previous run
    print("killing all ffmpeg processes")
    os.system("killall ffmpeg")

    print("main")

    streamProcessDict = None

    twitterSnapCount = 0

    videoProcess = startVideoCapture()
    audioProcess = startAudioCapture()


    count = 0
    while True:
        print("audioProcess.poll()", audioProcess.poll())
        print("videoProcess.poll()", videoProcess.poll())

        if audioProcess.poll() is not None:
            time.sleep(5)
            videoProcess = startAudioCapture()

        if videoProcess.poll() is not None:
            time.sleep(5)
            audioProcess = startVideoCapture()

        if (count % robot_util.KeepAlivePeriod) == 0:
            robot_util.sendCameraAliveMessage(commandArgs.info_server_protocol,
                                              commandArgs.info_server,
                                              commandArgs.camera_id)

        time.sleep(1)
        count += 1
Esempio n. 3
0
def main():

    global robotID
    global audioProcess
    global videoProcess

    # overrides command line parameters using config file
    print("args on command line:", commandArgs)

    robot_util.sendCameraAliveMessage(apiServer, commandArgs.camera_id,
                                      commandArgs.stream_key)

    refreshFromOnlineSettings()

    print("args after loading from server:", robotSettings)

    sys.stdout.flush()

    if robotSettings.camera_enabled:
        if not commandArgs.dry_run:
            videoProcess = startVideoCaptureOBS()
        else:
            videoProcess = DummyProcess()

    if robotSettings.mic_enabled:
        if not commandArgs.dry_run:
            audioProcess = startAudioCaptureOBS()
            _thread.start_new_thread(killallFFMPEGIn30Seconds, ())
        else:
            audioProcess = DummyProcess()

    numVideoRestarts = 0
    numAudioRestarts = 0

    count = 0

    # loop forever and monitor status of ffmpeg processes
    while True:

        time.sleep(1)

        if numVideoRestarts > 20:
            print(
                "rebooting in 20 seconds because of too many restarts. probably lost connection to camera"
            )
            time.sleep(20)

        if (count % robot_util.KeepAlivePeriod) == 0:
            robot_util.sendCameraAliveMessage(apiServer, commandArgs.camera_id,
                                              commandArgs.stream_key)

        if robotSettings.camera_enabled:

            # restart video if needed
            if videoProcess.poll() != None:
                randomSleep()
                videoProcess = startVideoCaptureOBS()
                numVideoRestarts += 1
        else:
            print("video process poll: camera_enabled is false")

        if robotSettings.mic_enabled:

            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 = startAudioCaptureOBS()
                numAudioRestarts += 1

        count += 1
Esempio n. 4
0
def main():

    global robotID
    global audioProcess
    global videoProcess

    # overrides command line parameters using config file
    print("args on command line:", commandArgs)

    robotID = getRobotID()
    identifyRobotId()

    robot_util.sendCameraAliveMessage(infoServerProtocol, infoServer,
                                      commandArgs.camera_id)

    print("robot id:", robotID)

    refreshFromOnlineSettings()

    print("args after loading from server:", robotSettings)

    #todo need to implement for robotstreamer
    # appServerSocketIO.on('command_to_robot', onCommandToRobot)
    # appServerSocketIO.on('connection', onConnection)
    # appServerSocketIO.on('robot_settings_changed', onRobotSettingsChanged)

    sys.stdout.flush()

    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()
            _thread.start_new_thread(killallFFMPEGIn30Seconds, ())
            #appServerSocketIO.emit('send_video_process_start_event', {'camera_id': commandArgs.camera_id})
        else:
            audioProcess = DummyProcess()

    numVideoRestarts = 0
    numAudioRestarts = 0

    count = 0

    # loop forever and monitor status of ffmpeg processes
    while True:
        #todo: make this less annoying to ahole. i think the issue is he wants to see
        #      ffmpeg's status line without robotstreamer's interruptions because ffmpeg
        #      does some weird ncurses things and robot stream is inserting plain text
        #print("-----------------" + str(count) + "-----------------")

        #todo: start using this again
        #appServerSocketIO.wait(seconds=1)

        time.sleep(1)

        # todo: 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:
            print(
                "rebooting in 20 seconds because of too many restarts. probably lost connection to camera"
            )
            time.sleep(20)

        #todo: dress as cute girl and port this to windows
        #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:
            robot_util.sendCameraAliveMessage(infoServerProtocol, infoServer,
                                              commandArgs.camera_id)

        if (count % 60) == 0:
            identifyRobotId()

        if robotSettings.camera_enabled:

            #todo: make this less annoying for ahole
            #print("video process poll", videoProcess.poll(), "pid", videoProcess.pid, "restarts", numVideoRestarts)

            # restart video if needed
            if videoProcess.poll() != None:
                randomSleep()
                videoProcess = startVideoCaptureLinux()
                numVideoRestarts += 1
        else:
            print("video process poll: camera_enabled is false")

        if robotSettings.mic_enabled:

            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
        #todo: make this less annoying for ahole
        #else:
        #    print("audio process poll: mic_enabled is false")

        count += 1
Esempio n. 5
0
def main():

    global robotID
    global audioProcess
    global videoProcess

    # overrides command line parameters using config file
    print("args on command line:", commandArgs)

    robot_util.sendCameraAliveMessage(apiServer, commandArgs.camera_id,
                                      commandArgs.stream_key)
    #starts the backend services and

    print("camera id:", commandArgs.camera_id)

    refreshFromOnlineSettings()

    print("args after loading from server:", robotSettings)

    #todo need to implement for robotstreamer
    # appServerSocketIO.on('command_to_robot', onCommandToRobot)
    # appServerSocketIO.on('connection', onConnection)
    # appServerSocketIO.on('robot_settings_changed', onRobotSettingsChanged)

    sys.stdout.flush()

    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()

    numVideoRestarts = 0
    numAudioRestarts = 0

    count = 0

    # 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: 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()

        if robotSettings.camera_enabled:

            print("video process poll", videoProcess.poll(), "pid",
                  videoProcess.pid, "restarts", numVideoRestarts)

            # restart video if needed
            if videoProcess.poll() != None:
                randomSleep()
                videoProcess = startVideoCaptureLinux()
                numVideoRestarts += 1
        else:
            print("video process poll: camera_enabled is false")

        if robotSettings.mic_enabled:

            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