Esempio n. 1
0
 def start_sound_source(self, device=None):
     log("start_sound_source(%s)", device)
     assert self.sound_source is None
     def sound_source_state_changed(*_args):
         self.emit("microphone-changed")
     #find the matching codecs:
     matching_codecs = self.get_matching_codecs(self.microphone_codecs, self.server_sound_decoders)
     log("start_sound_source(%s) matching codecs: %s", device, csv(matching_codecs))
     if not matching_codecs:
         self.no_matching_codec_error("microphone", self.server_sound_decoders, self.microphone_codecs)
         return False
     try:
         from xpra.sound.wrapper import start_sending_sound
         plugins = self.sound_properties.get("plugins")
         ss = start_sending_sound(plugins, self.sound_source_plugin, device or self.microphone_device,
                                  None, 1.0, False, matching_codecs,
                                  self.server_pulseaudio_server, self.server_pulseaudio_id)
         if not ss:
             return False
         self.sound_source = ss
         ss.sequence = self.sound_source_sequence
         ss.connect("new-buffer", self.new_sound_buffer)
         ss.connect("state-changed", sound_source_state_changed)
         ss.connect("new-stream", self.new_stream)
         ss.start()
         log("start_sound_source(%s) sound source %s started", device, ss)
         return True
     except Exception as e:
         self.may_notify_audio("Failed to start microphone forwarding", "%s" % e)
         log.error("Error setting up microphone forwarding:")
         log.error(" %s", e)
         return False
Esempio n. 2
0
 def start_sending_sound(self, codec=None, volume=1.0,
                         new_stream=None, new_buffer=None, skip_client_codec_check=False):
     log("start_sending_sound(%s)", codec)
     ss = None
     if getattr(self, "suspended", False):
         log.warn("Warning: not starting sound whilst in suspended state")
         return None
     if not self.supports_speaker:
         log.error("Error sending sound: support not enabled on the server")
         return None
     if self.sound_source:
         log.error("Error sending sound: forwarding already in progress")
         return None
     if not self.sound_receive:
         log.error("Error sending sound: support is not enabled on the client")
         return None
     if codec is None:
         codecs = [x for x in self.sound_decoders if x in self.speaker_codecs]
         if not codecs:
             log.error("Error sending sound: no codecs in common")
             return None
         codec = codecs[0]
     elif codec not in self.speaker_codecs:
         log.warn("Warning: invalid codec specified: %s", codec)
         return None
     elif (codec not in self.sound_decoders) and not skip_client_codec_check:
         log.warn("Error sending sound: invalid codec '%s'", codec)
         log.warn(" is not in the list of decoders supported by the client: %s", csv(self.sound_decoders))
         return None
     if not self.audio_loop_check("speaker"):
         return None
     try:
         from xpra.sound.wrapper import start_sending_sound
         plugins = self.sound_properties.strtupleget("plugins")
         ss = start_sending_sound(plugins, self.sound_source_plugin,
                                  None, codec, volume, True, [codec],
                                  self.pulseaudio_server, self.pulseaudio_id)
         self.sound_source = ss
         log("start_sending_sound() sound source=%s", ss)
         if not ss:
             return None
         ss.sequence = self.sound_source_sequence
         ss.connect("new-buffer", new_buffer or self.new_sound_buffer)
         ss.connect("new-stream", new_stream or self.new_stream)
         ss.connect("info", self.sound_source_info)
         ss.connect("exit", self.sound_source_exit)
         ss.connect("error", self.sound_source_error)
         ss.start()
         return ss
     except Exception as e:
         log.error("error setting up sound: %s", e, exc_info=True)
         self.stop_sending_sound()
         ss = None
         return None
     finally:
         if ss is None:
             #tell the client we're not sending anything:
             self.send_eos(codec)