Beispiel #1
0
class WaveRecorder(object):
    """
    An object capable of recording to a WAV file. It can be used as part of an
    AudioBridge as it implements the IAudioPort interface.
    """

    implements(IAudioPort)

    def __init__(self, mixer, filename):
        self.mixer = mixer
        self.filename = filename
        self._recording_wave_file = None

    @property
    def is_active(self):
        return bool(self._recording_wave_file
                    and self._recording_wave_file.is_active)

    @property
    def consumer_slot(self):
        return self._recording_wave_file.slot if self._recording_wave_file else None

    @property
    def producer_slot(self):
        return None

    def start(self):
        # There is still a race condition here in that the directory can be removed
        # before the PJSIP opens the file. There's nothing that can be done about
        # it as long as PJSIP doesn't accept an already open file descriptor. -Luci
        makedirs(os.path.dirname(self.filename))
        self._recording_wave_file = RecordingWaveFile(self.mixer,
                                                      self.filename)
        self._recording_wave_file.start()
        notification_center = NotificationCenter()
        notification_center.post_notification(
            'AudioPortDidChangeSlots',
            sender=self,
            data=NotificationData(
                consumer_slot_changed=True,
                producer_slot_changed=False,
                old_consumer_slot=None,
                new_consumer_slot=self._recording_wave_file.slot))

    def stop(self):
        old_slot = self.consumer_slot
        self._recording_wave_file.stop()
        self._recording_wave_file = None
        notification_center = NotificationCenter()
        notification_center.post_notification('AudioPortDidChangeSlots',
                                              sender=self,
                                              data=NotificationData(
                                                  consumer_slot_changed=True,
                                                  producer_slot_changed=False,
                                                  old_consumer_slot=old_slot,
                                                  new_consumer_slot=None))
Beispiel #2
0
 def start(self):
     # There is still a race condition here in that the directory can be removed
     # before the PJSIP opens the file. There's nothing that can be done about
     # it as long as PJSIP doesn't accept an already open file descriptor. -Luci
     makedirs(os.path.dirname(self.filename))
     self._recording_wave_file = RecordingWaveFile(self.mixer,
                                                   self.filename)
     self._recording_wave_file.start()
     notification_center = NotificationCenter()
     notification_center.post_notification(
         'AudioPortDidChangeSlots',
         sender=self,
         data=NotificationData(
             consumer_slot_changed=True,
             producer_slot_changed=False,
             old_consumer_slot=None,
             new_consumer_slot=self._recording_wave_file.slot))
Beispiel #3
0
 def start(self):
     # There is still a race condition here in that the directory can be removed
     # before the PJSIP opens the file. There's nothing that can be done about
     # it as long as PJSIP doesn't accept an already open file descriptor. -Luci
     makedirs(os.path.dirname(self.filename))
     self._recording_wave_file = RecordingWaveFile(self.mixer, self.filename)
     self._recording_wave_file.start()
     notification_center = NotificationCenter()
     notification_center.post_notification('AudioPortDidChangeSlots', sender=self, data=NotificationData(consumer_slot_changed=True, producer_slot_changed=False,
                                                                                                         old_consumer_slot=None, new_consumer_slot=self._recording_wave_file.slot))
Beispiel #4
0
class WaveRecorder(object):
    """
    An object capable of recording to a WAV file. It can be used as part of an
    AudioBridge as it implements the IAudioPort interface.
    """

    implements(IAudioPort)

    def __init__(self, mixer, filename):
        self.mixer = mixer
        self.filename = filename
        self._recording_wave_file = None

    @property
    def is_active(self):
        return bool(self._recording_wave_file and self._recording_wave_file.is_active)

    @property
    def consumer_slot(self):
        return self._recording_wave_file.slot if self._recording_wave_file else None

    @property
    def producer_slot(self):
        return None

    def start(self):
        # There is still a race condition here in that the directory can be removed
        # before the PJSIP opens the file. There's nothing that can be done about
        # it as long as PJSIP doesn't accept an already open file descriptor. -Luci
        makedirs(os.path.dirname(self.filename))
        self._recording_wave_file = RecordingWaveFile(self.mixer, self.filename)
        self._recording_wave_file.start()
        notification_center = NotificationCenter()
        notification_center.post_notification('AudioPortDidChangeSlots', sender=self, data=NotificationData(consumer_slot_changed=True, producer_slot_changed=False,
                                                                                                            old_consumer_slot=None, new_consumer_slot=self._recording_wave_file.slot))

    def stop(self):
        old_slot = self.consumer_slot
        self._recording_wave_file.stop()
        self._recording_wave_file = None
        notification_center = NotificationCenter()
        notification_center.post_notification('AudioPortDidChangeSlots', sender=self, data=NotificationData(consumer_slot_changed=True, producer_slot_changed=False,
                                                                                                            old_consumer_slot=old_slot, new_consumer_slot=None))