Beispiel #1
0
 def play_live(self, ip, port, end_wait_time=1):
     """
     Plays a live preview of the current or last armed/playing file to
     the given ip address and port.
     """
     
     with self.__lock:
         # warn if rtpplay is not yet running
         if self.rtpplay_live.isalive():
             msg = "live rtpplay already running, not starting playback."
             raise InvalidOperationError(msg)
         
         # make sure we've been given a file to play
         if self._armed_file is None:
             msg = "no file to view live, arm and/or play a file first."
             raise InvalidOperationError(msg)
         
         # attempt to play the current file
         self.rtpplay_live.start(self._armed_file, ip, port,
                                 skip_to_end=True,
                                 end_wait_time=end_wait_time)
         
         # block for a bit until the process starts
         if not util.block_until(self.rtpplay_live.isalive,
                                 self.max_block_time):
             msg = "rtpplay did not start in the given amount of time."
             raise ProcessOperationTimeoutError(msg)
         
         # mark playback as started
         self._is_live_playing = True
Beispiel #2
0
 def start_record(self):
     """
     Begins dumping the configured stream to disk.
     """
     
     with self.__lock:
         # don't allow the user to start the record process twice
         if self.rtpdump.isalive():
             msg = "rtpdump process was already running"
             raise ProcessAlreadyRunningError(msg)
         
         # name of the file we're dumping to
         dump_file = os.path.join(self.dump_dir,
                         util.generate_file_name(self.video_basename))
         
         # start the process
         self.rtpdump.start(dump_file, self.dump_address, self.dump_port)
         
         if not util.block_until(self.rtpdump.isalive, self.max_block_time):
             msg = "rtpdump process failed to start within allotted time"
             raise ProcessOperationTimeoutError(msg)
         
         # set state variables to correspond to new file if process started
         self._commit_time = None
         self._start_time = util.get_time()
         self._dump_file = dump_file
Beispiel #3
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 #4
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