Beispiel #1
0
 def play_preview(self, start_time, duration=30):
     """
     Plays the most recently recorded file from the given time for
     the given duration.
     """
     
     with self.__lock:
         # make sure something has been recorded before previewing
         if self._dump_file is None:
             msg = "a recording must have been started to enable preview"
             raise NoRecordedFileError(msg)
         
         # ensure the file we are trying to play exists already
         if not self.file_exists(self._dump_file):
             msg = ("could not find dump file '%s' for preview" %
                    self._dump_file)
             raise FileNotFoundError(msg)
         
         # end the current preview before starting another one
         self.rtpplay.stop()
         
         if not util.block_while(self.rtpplay.isalive, self.max_block_time):
             msg = "failed to terminate previously running rtpplay process"
             raise ProcessOperationTimeoutError(msg)
         
         # attempt to play the given file
         self.rtpplay.start(self._dump_file, self.preview_address,
                       self.preview_port, start_time=start_time,
                       end_time=start_time + duration)
         
         # wait until the process starts
         if not util.block_until(self.rtpplay.isalive, self.max_block_time):
             msg = "rtpplay failed to start or exited very quickly"
             raise ProcessOperationTimeoutError(msg)
Beispiel #2
0
 def stop_live(self):
     with self.__lock:
         # stop works even on a non-running process
         self.rtpplay_live.stop()
         
         if not util.block_while(self.rtpplay_live.isalive, self.max_block_time):
             msg = "rtpplay did not terminate in the given amount of time."
             raise ProcessOperationTimeoutError(msg)
         
         # mark playback as stopped
         self._is_live_playing = False
Beispiel #3
0
 def arm(self, file_name):
     """
     Attempts to play the file argument.  Returns success if it could
     find the file and was not already playing, otherwise an error.
     """
     
     with self.__lock:
         # only arm again if currently alive and not playing
         if self.rtpplay.isalive():
             
             # don't allow arming if playback is happening
             if self._is_playing:
                 msg = "cannot arm a file during playback."
                 raise InvalidOperationError(msg)
             
             # same file already armed
             if file_name == self._armed_file:
                 return
             
             # kill the old armed process and arm a new one
             self.rtpplay.stop()
             if not util.block_while(self.rtpplay.isalive,
                                     self.max_block_time):
                 msg = ("rtpplay did not stop in the given amount of "
                        "time, failed to arm a new file.")
                 raise ProcessOperationTimeoutError(msg)
         
         path = os.path.join(self.dump_dir, file_name)
         
         # ensure the file exists
         if not self.file_exists(path):
             msg = "could not find file '%s' to arm." % file_name
             raise FileNotFoundError(msg)
         
         # get the commit time from file
         commit_time = self._load_commit_time(file_name)
         if commit_time is None:
             msg = "commit time is required to arm process."
             raise InvalidOperationError(msg)
         
         # attempt to arm the given file
         self.rtpplay.start(path, self.play_address, self.play_port,
                            start_time=commit_time, wait_start=True,
                            end_wait_time=config.END_WAIT_TIME)
         
         # block for a bit until the process starts
         if not util.block_until(self.rtpplay.isalive,
                                 self.max_block_time):
             msg = ("rtpplay did not start in the given amount of "
                    "time, could not arm file.")
             raise ProcessOperationTimeoutError(msg)
         
         # save file name for get_status
         self._armed_file = file_name
Beispiel #4
0
    def testBlockWhileBase(self):
        """
        Test basic use case function of block while
        """

        start_time = time.time()
        f = lambda: True
        result = util.block_while(f, self.max_time)
        end_time = time.time()

        assert end_time-start_time >= self.max_time
        assert not result
	
        start_time = time.time()
        f = lambda: start_time + self.short_time > time.time()
        result = util.block_while(f, self.max_time)
        end_time = time.time()

        assert end_time-start_time < self.max_time
        assert result
Beispiel #5
0
    def testBlockUntilBase(self):
        """
        Test basic function of block until, if passes
        should suffice for all other testing via block while
        """

        start_time = time.time()
        f = lambda: False
        result = util.block_while(f, self.max_time)
        end_time = time.time()

        assert end_time-start_time < self.max_time
        assert result
Beispiel #6
0
 def stop(self):
     """
     End playback of any currently running processes.  Simply resets the
     variables if no process was running.
     """
     
     with self.__lock:
         # stop works even on a non-running process
         self.rtpplay.stop()
         
         if not util.block_while(self.rtpplay.isalive, self.max_block_time):
             msg = "rtpplay did not terminate in the given amount of time."
             raise ProcessOperationTimeoutError(msg)
         
         # mark playback as stopped
         self._is_playing = False
         self._armed_file = None
Beispiel #7
0
 def stop_record(self):
     """
     Terminates the current rtpdump process, or does nothing if no
     process was active.  Returns the final elapsed time and the
     dump file name as a tuple on successful exit.
     """
     
     with self.__lock:
         # tell the process to exit
         self.rtpdump.stop()
         
         # wait until it does, or throw an error if it doesn't
         if not util.block_while(self.rtpdump.isalive, self.max_block_time):
             msg = "rtpdump process failed to end within the allotted time"
             raise ProcessOperationTimeoutError(msg)
         
         # retrieve the final status before resetting it
         final_status = self._get_status()
         
         # since we ended the process, we reset the start time
         self._start_time = None
         
         return final_status