示例#1
0
def audioOut_run(ao_conn, log_file_name, output_folder, snd_files, session_start_hour, session_end_hour):
    global LOG
    cwd = os.getcwd()
    LOG = log_file_name

    if FLAG_INITIAL_DELAY:
        func_start_time = time()
        while True:
            elapsed_time = time() - func_start_time
            #print "Elapsed time: %i (s)"%elapsed_time
            if elapsed_time > 90: # wait for 1.5 minutes before actual starting
                break

    OAD_inst = Output_AudioData(snd_files)
    last_fps_timestamp = time()
    fps_cnt = 0
    flag_session_changed_to_off = False
    flag_session_changed_to_on = False

    while True:
        if chk_session_time(session_start_hour, session_end_hour) == False:
            if flag_session_changed_to_off == False: # 1st run after finishing the session-time
                OAD_inst.close_output_streams()
                flag_session_changed_to_off = True
                flag_session_changed_to_on = False
            if ao_conn.poll(): # check whether there's any message arrive through the pipe
                msg = ao_conn.recv() # receive the message
                if msg == 'q': break
            sleep(1)
            continue
        else:
            if flag_session_changed_to_on == False: # 1st run after starting the session-time
                OAD_inst.open_output_streams()
                flag_session_changed_to_off = False
                flag_session_changed_to_on = True
                LOG = update_log_file_path(output_folder, LOG)

        ### FPS-check
        if FLAG_DEBUG:
            fps, fps_cnt, last_fps_timestamp = chk_fps(last_fps_timestamp, fps_cnt)
            if fps != -1: print "LoopPerSecond-check from audioOut module : %i"%fps

        if ao_conn.poll(): # check whether there's any message arrive through the pipe
            msg = ao_conn.recv() # receive the message
            if msg == 'q': break
            elif msg.startswith('play_sound:'):
                msg = msg.split(":")
                OAD_inst.play_sound(msg[1])
            elif msg == '4th_speaker_test':
                OAD_inst.flag_4th_speaker_test = True
            elif msg == 'SWS_test':
                OAD_inst.flag_SWS_test = True
            elif msg == 'NVS_test':
                OAD_inst.flag_NVS_test = True

        sleep(0.05)
示例#2
0
def videoIn_run(vi_conn, log_file_path, output_folder, cID, flag_ffmpeg_on_the_run, session_start_hour, session_end_hour):
    global FLAG_DEBUG, FLAG_FFMPEG_ON_THE_RUN, LOG, PLACE_TO_CHECK_MOVEMENTS
    cwd = os.getcwd()
    FLAG_FFMPEG_ON_THE_RUN = flag_ffmpeg_on_the_run
    LOG = log_file_path

    if FLAG_INITIAL_DELAY:
        func_start_time = time()
        while True:
            elapsed_time = time() - func_start_time
            #print "Elapsed time: %i (s)"%elapsed_time
            if elapsed_time > 90: # wait for 1.5 minutes before actual starting
                break

    CV_inst = C_Vision(vi_conn, cwd, output_folder, cID)

    last_fps_timestamp = time()
    fps_cnt = 0
    flag_session_changed_to_off = False
    flag_session_changed_to_on = False
    while True:
        if chk_session_time(session_start_hour, session_end_hour) == False:
            if flag_session_changed_to_off == False: # 1st run after finishing the session-time
                CV_inst = None # Turn off CV
                flag_session_changed_to_off = True
                flag_session_changed_to_on = False
            if vi_conn.poll(): # check whether there's any message arrived through the pipe
                msg = vi_conn.recv() # receive the message
                if msg == 'q':
                    break
            sleep(1)
            continue
        else:
            if flag_session_changed_to_on == False: # 1st run after starting the session-time
                flag_session_changed_to_off = False
                flag_session_changed_to_on = True
                LOG = update_log_file_path(output_folder, LOG)
                CV_inst = C_Vision(vi_conn, cwd, output_folder, cID) # initialize the CV

        ### FPS-check
        fps, fps_cnt, last_fps_timestamp = chk_fps(last_fps_timestamp, fps_cnt)
        if FLAG_DEBUG:
            if fps != -1: print "LoopPerSecond-check from video module : %i"%fps

        CV_inst.run(fps) # run the image porcessing

        if CV_inst.flag_save_movie != None:
            if FLAG_FFMPEG_ON_THE_RUN:
                ### send a message for generating a movie file
                file_name = "%s_cID%.2i%s"%(CV_inst.recording_timestamp, cID, CV_inst.movie_file_ext)
                output_video_file = os.path.join(cwd, output_folder, file_name)
                tmp_file = CV_inst.recording_timestamp + "_%05d.jpg"
                tmp_file = os.path.join(CV_inst.tmp_img_dir_path, tmp_file)
                command = ("ffmpeg -r %i -i %s -vcodec %s -qscale %i %s,%s")%(CV_inst.rec_fps, tmp_file, CV_inst.movie_vcodec, CV_inst.movie_vquality, output_video_file, CV_inst.tmp_img_dir_path)
                vi_conn.send(command) # send the command to the organizer to save the movie
            CV_inst.init_movie_params()

        if vi_conn.poll(): # check whether there's any message arrived through the pipe
            msg = vi_conn.recv() # receive the message
            if msg == 'q':
                break
            elif msg == 'check_motion_at_feeder':
                PLACE_TO_CHECK_MOVEMENTS = "feeder"