Example #1
0
def worker(name,rtsp_url,coordinates,stopworker):

    #Ctrl-C handling
    def signal_sigint_handler(signum,frame):
        logger.info("Ctrl C was pressed")
        stopworker.value = True
    def signal_sigterm_handler(signum,frame):
        logger.info("This process was sigtermed")
        stopworker.value = True
    signal.signal(signal.SIGINT, signal_sigint_handler)
    signal.signal(signal.SIGTERM, signal_sigterm_handler)

    #Logger setup
    logger = setup_logging( "logs/" + name + ".log",__name__)
    logger.debug("logger from " + name)

    #Start stream and watchdog
    attempts=0
    proc=start_subprocess(rtsp_url,coordinates)

    while attempts < 1000 and stopworker.value == False:
        if proc.poll() != None:
            proc=start_subprocess(rtsp_url,coordinates)
            attempts = attempts + 1
            #Wait for omxplayer to crash, or not
            time.sleep(10)
            logger.info("Trying to restart" + name +" attempts:" + str(attempts))
        else:
            attempts=0
        time.sleep(5)

    #If we come to this point, we are instructed to kill this stream
    stop_subprocess(proc)
    logger.info("This stream has been stopped")
Example #2
0
def worker(name,rtsp_url,omxplayer_extra_options,coordinates,stopworker):
    def start_subprocess(rtsp_url,coordinates):
        command_line='/usr/bin/omxplayer --live --timeout 60 --aidx -1 -o hdmi' + ' ' + omxplayer_extra_options + ' ' +  rtsp_url + ' --win ' + '"' + " ".join(map(str,coordinates)) + '"'
        command_line_shlex=shlex.split(command_line)
        logger.debug("Starting stream " + name + " with commandline " + str(command_line_shlex))
        #The other process is just to be able to develop/simulate on a Windows or OSX machine
        if platform.system() == "Windows":
            proc=subprocess.Popen('echo this is a subprocess started with coordinates ' + str(coordinates) + '& ping 192.168.0.160 /t >NUL', shell=True)
        elif platform.system() == "Linux":
            proc=subprocess.Popen(command_line_shlex,preexec_fn=os.setsid,stdin=subprocess.PIPE)
        else:
            proc=subprocess.Popen('echo this is a subprocess started with coordinates ' + str(coordinates), shell=True)
        return proc

    def stop_subprocess(proc):
        #The other process is just to be able to develop on a Windows or OSX machine
        if platform.system() == "Windows":
            proc.kill()
        else:
            #This kill the process group so including all children
            os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
            proc.wait()

    #Ctrl-C handling
    def signal_sigint_handler(signum,frame):
        logger.info("Ctrl C was pressed")
        stopworker.value = True
    def signal_sigterm_handler(signum,frame):
        logger.info("This process was sigtermed")
        stopworker.value = True

    signal.signal(signal.SIGINT, signal_sigint_handler)
    signal.signal(signal.SIGTERM, signal_sigterm_handler)

    #Logger setup
    logger = setup_logging( "logs/" + name + ".log",__name__)
    logger.debug("logger from " + name)

    #Start stream and watchdog
    attempts=0
    proc=start_subprocess(rtsp_url,coordinates)
    while attempts < 100000 and stopworker.value == False:
        if proc.poll() != None:
            proc.communicate(input="\n")
            proc=start_subprocess(rtsp_url,coordinates)
            attempts = attempts + 1
            #Wait for omxplayer to crash, or not
            time.sleep(10)
            logger.info("Trying to restart" + name +" attempts:" + str(attempts))
        else:
            attempts=0
        time.sleep(5)

    #If we come to this point, we are instructed to kill this stream
    stop_subprocess(proc)
    logger.info("This stream has been stopped")
Example #3
0
def send_stats(version, uniqid, runtime):
    #Because this is run as a subprocess we need to start logging again
    logger_send_stats = setup_logging(logfilepath="logs/send_stats.log",
                                      loggername="send_stats")

    destination = "https://statscollector.rpisurv.net"

    #SSL options
    context = ssl.create_default_context(
        purpose=ssl.Purpose.SERVER_AUTH,
        cafile="core/util/statscollector.rpisurv.net.pem")
    #Force TLS higher then 1.1
    context.options |= ssl.OP_NO_SSLv2
    context.options |= ssl.OP_NO_SSLv3
    context.options |= ssl.OP_NO_TLSv1
    context.options |= ssl.OP_NO_TLSv1_1
    #Normally this has been set by ssl.Purpose.SERVER_AUTH but for safety in future explicitly set CERT_REQUIRED
    context.verify_mode = ssl.CERT_REQUIRED
    httpshandler = urllib2.HTTPSHandler(context=context)

    opener = urllib2.build_opener(httpshandler)
    opener.addheaders = [('User-Agent', uniqid), ('Pragma', 'no-cache'),
                         ('Cache-Control', 'no-cache')]
    #Extra info will be send via cookie headers
    opener.addheaders.append(
        ('Cookie', 'runtime=' + runtime + ';reservedkey=reservedvalue'))
    opener.addheaders.append(
        ('Cookie', 'runtime=' + runtime + ';version=' + str(version)))

    urllib2.install_opener(opener)

    f = opener.open("http://httpbin.org/cookies")
    logger_send_stats.debug("Start sending uniqid " + uniqid + ", runtime " +
                            runtime + ", version " + str(version) + " to " +
                            destination +
                            " for updating stats rpisurv community")
    try:
        response = opener.open(destination, timeout=20)
    except urllib2.HTTPError, e:
        logger_send_stats.error(
            "There was an error connecting to the statistics server at " +
            destination + ". Failed with code " + str(e.code))
Example #4
0
def send_stats(uniqid,runtime):
    #Because this is run as a subprocess we need to start logging again
    logger_send_stats = setup_logging(logfilepath="logs/send_stats.log",loggername="send_stats")

    destination="http://statscollector.rpisurv.net"

    opener = urllib2.build_opener()
    opener.addheaders=[
        ('User-Agent', uniqid),
        ('Pragma', 'no-cache'),
        ('Cache-Control', 'no-cache')
    ]
    #Extra info will be send via cookie headers
    #opener.addheaders.append(('Cookie', 'runtime='+ runtime + ';reservedkey=reservedvalue'))
    opener.addheaders.append(('Cookie', 'runtime='+ runtime ))

    #f = opener.open("http://httpbin.org/cookies")
    logger_send_stats.debug("Start sending uniqid " + uniqid + " and runtime " + runtime + " to " + destination + " for updating stats rpisurv community")
    try:
        response = opener.open(destination, timeout=20)
    except urllib2.HTTPError, e:
        logger_send_stats.error("There was an error connecting to the statistics server at " + destination + ". Failed with code " + str(e.code))
Example #5
0
def worker(name, rtsp_url, coordinates, stopworker):

    #Ctrl-C handling
    def signal_sigint_handler(signum, frame):
        logger.info("Ctrl C was pressed")
        stopworker.value = True

    def signal_sigterm_handler(signum, frame):
        logger.info("This process was sigtermed")
        stopworker.value = True

    signal.signal(signal.SIGINT, signal_sigint_handler)
    signal.signal(signal.SIGTERM, signal_sigterm_handler)

    #Logger setup
    logger = setup_logging("logs/" + name + ".log", __name__)
    logger.debug("logger from " + name)

    #Start stream and watchdog
    attempts = 0
    proc = start_subprocess(rtsp_url, coordinates)

    while attempts < 1000 and stopworker.value == False:
        if proc.poll() != None:
            proc = start_subprocess(rtsp_url, coordinates)
            attempts = attempts + 1
            #Wait for omxplayer to crash, or not
            time.sleep(10)
            logger.info("Trying to restart" + name + " attempts:" +
                        str(attempts))
        else:
            attempts = 0
        time.sleep(5)

    #If we come to this point, we are instructed to kill this stream
    stop_subprocess(proc)
    logger.info("This stream has been stopped")
Example #6
0
def send_stats(uniqid, runtime):
    #Because this is run as a subprocess we need to start logging again
    logger_send_stats = setup_logging(logfilepath="logs/send_stats.log",
                                      loggername="send_stats")

    destination = "http://statscollector.rpisurv.net"

    opener = urllib2.build_opener()
    opener.addheaders = [('User-Agent', uniqid), ('Pragma', 'no-cache'),
                         ('Cache-Control', 'no-cache')]
    #Extra info will be send via cookie headers
    #opener.addheaders.append(('Cookie', 'runtime='+ runtime + ';reservedkey=reservedvalue'))
    opener.addheaders.append(('Cookie', 'runtime=' + runtime))

    #f = opener.open("http://httpbin.org/cookies")
    logger_send_stats.debug("Start sending uniqid " + uniqid +
                            " and runtime " + runtime + " to " + destination +
                            " for updating stats rpisurv community")
    try:
        response = opener.open(destination, timeout=20)
    except urllib2.HTTPError, e:
        logger_send_stats.error(
            "There was an error connecting to the statistics server at " +
            destination + ". Failed with code " + str(e.code))
Example #7
0
        for cam_stream_to_stop in cam_streams_to_stop:
            cam_stream_to_stop.stop_stream()
        sys.exit(0)


def sigterm_handler(_signo, _stack_frame):
    draw.destroy()
    sys.exit(0)


if __name__ == '__main__':

    signal.signal(signal.SIGTERM, sigterm_handler)

    #Setup logger
    logger = setup_logging()

    #Read in config
    resolution = set_resolution()
    nr_of_columns = cfg['essentials'][
        'nr_of_columns']  #Max amount of columns per row
    keep_first_screen_layout = cfg['essentials'][
        'keep_first_screen_layout'] if 'keep_first_screen_layout' in cfg[
            "essentials"] else False
    autostretch = cfg['essentials']['autostretch'] if 'autostretch' in cfg[
        "essentials"] else False

    if type(cfg["advanced"]) is dict:
        fixed_width = cfg['advanced']['fixed_width'] if 'fixed_width' in cfg[
            "advanced"] else None  #Override of autocalculation width if set
        fixed_height = cfg['advanced']['fixed_height'] if 'fixed_height' in cfg[
Example #8
0
        logger.error("Can not find or run the fbset binary to autodetect the resolution")
        autodetect_resolution=None
    else:
        regex_result=re.search("geometry (\d+) (\d+)",fbsetresult)
        autodetect_resolution=[regex_result.group(1),regex_result.group(2)]
        logger.debug("autodetected resolution of" + str(autodetect_resolution))

    if autodetect_resolution is None:
        resolution=[cfg['fallbacks']['resolution']['width'],cfg['fallbacks']['resolution']['height']]
    else:
        resolution=autodetect_resolution
    return resolution

if __name__ == '__main__':

    logger = setup_logging()

    #Read in config
    rtsp_urls=cfg['essentials']['rtsp_urls']
    resolution=set_resolution()
    nr_of_columns=cfg['essentials']['nr_of_columns'] #Max amount of columns per row

    #Setup logger
    logger.debug("nr_of_columns = " + nr_of_columns)

    #Setup all camerastream instances
    all_camera_streams=setup_camera_streams(rtsp_urls)

    #Start main
    previous_connectable_camera_streams=[]
    while True:
Example #9
0
def worker(name, rtsp_url, omxplayer_extra_options, coordinates, stopworker):
    def start_subprocess(rtsp_url, coordinates):
        command_line = '/usr/bin/omxplayer --live --timeout 60 --aidx -1 -o hdmi' + ' ' + omxplayer_extra_options + ' ' + rtsp_url + ' --win ' + '"' + " ".join(
            map(str, coordinates)) + '"'
        command_line_shlex = shlex.split(command_line)
        logger.debug("Starting stream " + name + " with commandline " +
                     str(command_line_shlex))
        #The other process is just to be able to develop/simulate on a Windows or OSX machine
        if platform.system() == "Windows":
            proc = subprocess.Popen(
                'echo this is a subprocess started with coordinates ' +
                str(coordinates) + '& ping 192.168.0.160 /t >NUL',
                shell=True)
        elif platform.system() == "Linux":
            proc = subprocess.Popen(command_line_shlex,
                                    preexec_fn=os.setsid,
                                    stdin=subprocess.PIPE)
        else:
            proc = subprocess.Popen(
                'echo this is a subprocess started with coordinates ' +
                str(coordinates),
                shell=True)
        return proc

    def stop_subprocess(proc):
        #The other process is just to be able to develop on a Windows or OSX machine
        if platform.system() == "Windows":
            proc.kill()
        else:
            #This kill the process group so including all children
            os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
            proc.wait()

    #Ctrl-C handling
    def signal_sigint_handler(signum, frame):
        logger.info("Ctrl C was pressed")
        stopworker.value = True

    def signal_sigterm_handler(signum, frame):
        logger.info("This process was sigtermed")
        stopworker.value = True

    signal.signal(signal.SIGINT, signal_sigint_handler)
    signal.signal(signal.SIGTERM, signal_sigterm_handler)

    #Logger setup
    logger = setup_logging("logs/" + name + ".log", __name__)
    logger.debug("logger from " + name)

    #Start stream and watchdog
    attempts = 0
    proc = start_subprocess(rtsp_url, coordinates)
    while attempts < 100000 and stopworker.value == False:
        if proc.poll() != None:
            proc.communicate(input="\n")
            proc = start_subprocess(rtsp_url, coordinates)
            attempts = attempts + 1
            #Wait for omxplayer to crash, or not
            time.sleep(10)
            logger.info("Trying to restart" + name + " attempts:" +
                        str(attempts))
        else:
            attempts = 0
        time.sleep(5)

    #If we come to this point, we are instructed to kill this stream
    stop_subprocess(proc)
    logger.info("This stream has been stopped")