Logo Search packages:      
Sourcecode: scenic version File versions  Download package

def scenic::streamer::StreamerManager::start (   self,
  host 
)
Starts the sender and receiver processes.

@param host: str ip addr
Raises a RuntimeError if a sesison is already in progress.

Definition at line 276 of file streamer.py.

                         :
        """
        Starts the sender and receiver processes.
        
        @param host: str ip addr
        Raises a RuntimeError if a sesison is already in progress.
        """
        if self.state != process.STATE_STOPPED:
            raise RuntimeError("Cannot start streamers since they are %s." % (self.state)) # the programmer has done something wrong if we're here.
        
        self._gather_config_to_stream(host)
        details = self.session_details
        send_video_enabled = self.session_details["send"]["video"]["enabled"]
        send_audio_enabled = self.session_details["send"]["audio"]["enabled"]
        recv_video_enabled = self.session_details["receive"]["video"]["enabled"]
        recv_audio_enabled = self.session_details["receive"]["audio"]["enabled"]
        midi_recv_enabled = self.session_details["receive"]["midi"]["enabled"]
        midi_send_enabled = self.session_details["send"]["midi"]["enabled"]
        jack_autoconnect = self.session_details["send"]["audio"]["jack_autoconnect"] # either send or recv
        extra_send_enabled = not self.session_details["send"]["audio"]["synchronized"] and send_audio_enabled
        extra_recv_enabled = not self.session_details["receive"]["audio"]["synchronized"] and recv_audio_enabled
        normal_recv_enabled = recv_video_enabled or recv_audio_enabled and not extra_recv_enabled # if the self.sender and self.receiver are enabled
        normal_send_enabled = send_video_enabled or send_audio_enabled and not extra_send_enabled
        if not send_audio_enabled and not send_video_enabled and not midi_send_enabled and not midi_recv_enabled and not recv_audio_enabled and not recv_video_enabled:
            raise RuntimeError("Everything is disabled, but the application is trying to start to stream. This should not happen.") # the programmer has done a mistake if we're here.

        log.debug("send_video_enabled %s" % (send_video_enabled))
        log.debug("send_audio_enabled %s" % (send_audio_enabled))
        log.debug("recv_video_enabled %s" % (recv_video_enabled))
        log.debug("recv_audio_enabled %s" % (recv_audio_enabled))
        log.debug("midi_recv_enabled %s" % (midi_recv_enabled))
        log.debug("midi_send_enabled %s" % (midi_send_enabled))

        # we store the arguments in lists
        milhouse_send_cmd_common = []
        milhouse_send_cmd_audio = []
        milhouse_send_cmd_video = []
        milhouse_recv_cmd_common = []
        milhouse_recv_cmd_audio = []
        milhouse_recv_cmd_video = []

        # ------------------ send ---------------
        # every element in the lists must be strings since we join them .
        # int elements are converted to str.
        milhouse_send_cmd_common.extend([
            "milhouse", 
            '--sender', 
            '--address', details["peer"]["address"]
            ])

        # send video:
        if send_video_enabled:
            milhouse_send_cmd_video.extend([
                '--videosource', details["send"]["video"]["source"],
                '--videocodec', details["send"]["video"]["codec"],
                '--videoport', str(details["send"]["video"]["port"]),
                '--width', str(details["send"]["video"]["width"]), 
                '--height', str(details["send"]["video"]["height"]),
                '--aspect-ratio', str(details["send"]["video"]["aspect-ratio"]),
                ])
            if details["send"]["video"]["source"] == "v4l2src":
                dev = self.app.parse_v4l2_device_name(details["send"]["video"]["device"])
                if dev is None:
                    log.error("v4l2 device is not found !!!!")
                else:
                    v4l2_dev_name = dev["name"]
                milhouse_send_cmd_video.extend(["--videodevice", v4l2_dev_name])
            if details["send"]["video"]["codec"] != "theora":
                milhouse_send_cmd_video.extend(['--videobitrate', str(int(details["send"]["video"]["bitrate"] * 1000000))])

        # send audio:
        if send_audio_enabled:
            milhouse_send_cmd_audio.extend([
                '--audiosource', details["send"]["audio"]["source"],
                '--numchannels', str(details["send"]["audio"]["numchannels"]),
                '--audiocodec', details["send"]["audio"]["codec"],
                '--audioport', str(details["send"]["audio"]["port"]),
                '--vumeter-id', str(details["send"]["audio"]["vumeter-id"]),
                '--audio-buffer', str(details["send"]["audio"]["buffer"])
                ])
            if not jack_autoconnect:
                milhouse_send_cmd_audio.extend([
                    "--disable-jack-autoconnect"
                    ])

        # ------------------- recv ----------------
        milhouse_recv_cmd_common.extend([
            "milhouse",
            '--receiver', 
            '--address', details["peer"]["address"]
            ])

        # recv video:
        if recv_video_enabled:
            milhouse_recv_cmd_video.extend([
                '--videosink', details["receive"]["video"]["sink"],
                '--videocodec', details["receive"]["video"]["codec"],
                '--videoport', str(details["receive"]["video"]["port"]),
                '--jitterbuffer', str(details["receive"]["video"]["jitterbuffer"]),
                '--width', str(details["receive"]["video"]["width"]),
                '--height', str(details["receive"]["video"]["height"]),
                '--aspect-ratio', details["receive"]["video"]["aspect-ratio"],
                '--window-title', details["receive"]["video"]["window-title"],
                '--videodisplay', details["receive"]["video"]["display"],
                ])
            if details["receive"]["video"]["fullscreen"]:
                milhouse_recv_cmd_video.append('--fullscreen')
            if details["receive"]["video"]["deinterlace"]:
                milhouse_recv_cmd_video.append('--deinterlace')

        # recv audio:
        if recv_audio_enabled:
            milhouse_recv_cmd_audio.extend([
                # audio:
                '--audiosink', details["receive"]["audio"]["sink"],
                '--numchannels', str(details["receive"]["audio"]["numchannels"]),
                '--audiocodec', details["receive"]["audio"]["codec"],
                '--audioport', str(details["receive"]["audio"]["port"]),
                '--vumeter-id', str(details["receive"]["audio"]["vumeter-id"]),
                '--audio-buffer', str(details["receive"]["audio"]["buffer"])
                ])
            if not jack_autoconnect:
                milhouse_recv_cmd_audio.extend([
                    "--disable-jack-autoconnect"
                    ])

        self._prepare_stats_and_errors_dicts()
        # every element in the lists must be strings since we join them 
        # TODO: not sync
        # TODO: if both disabled, do not start sender/receiver
        # ---- audio/video receiver ----
        if recv_audio_enabled or recv_video_enabled: # receiver(s)
            milhouse_recv_cmd_final = []
            milhouse_recv_cmd_extra = []
            
            milhouse_recv_cmd_final.extend(milhouse_recv_cmd_common)
            milhouse_recv_cmd_extra.extend(milhouse_recv_cmd_common)
            milhouse_recv_cmd_final.extend(milhouse_recv_cmd_video)
            if extra_recv_enabled:
                milhouse_recv_cmd_extra.extend(milhouse_recv_cmd_audio)
                milhouse_recv_cmd_extra.extend(["--jitterbuffer", str(details["receive"]["audio"]["jitterbuffer"])])
            else:
                milhouse_recv_cmd_final.extend(milhouse_recv_cmd_audio)
            try:
                recv_cmd = " ".join(milhouse_recv_cmd_final)
            except TypeError, e:
                log.error(e)
                log.error(milhouse_recv_cmd_final)
                raise
            try:
                extra_recv_cmd = " ".join(milhouse_recv_cmd_extra)
            except TypeError, e:
                log.error(e)
                log.error(milhouse_recv_cmd_extra)
                raise
            if normal_recv_enabled:
                self.receiver = process.ProcessManager(command=recv_cmd, identifier="receiver")
                self.receiver.state_changed_signal.connect(self.on_process_state_changed)
                self.receiver.stdout_line_signal.connect(self.on_receiver_stdout_line)
                self.receiver.stderr_line_signal.connect(self.on_receiver_stderr_line)
            if extra_recv_enabled:
                self.extra_receiver = process.ProcessManager(command=extra_recv_cmd, identifier="extra_receiver")
                self.extra_receiver.state_changed_signal.connect(self.on_process_state_changed)
                self.extra_receiver.stdout_line_signal.connect(self.on_receiver_stdout_line)
                self.extra_receiver.stderr_line_signal.connect(self.on_receiver_stderr_line)
        # ---- audio/video sender ----
        if send_audio_enabled or send_video_enabled: # sender(s)
            milhouse_send_cmd_final = []
            milhouse_send_cmd_extra = []
            
            milhouse_send_cmd_final.extend(milhouse_send_cmd_common)
            milhouse_send_cmd_extra.extend(milhouse_send_cmd_common) # only used if we have to
            milhouse_send_cmd_final.extend(milhouse_send_cmd_video)
            if extra_send_enabled:
                milhouse_send_cmd_extra.extend(milhouse_send_cmd_audio)
            else:
                milhouse_send_cmd_final.extend(milhouse_send_cmd_audio)
            send_cmd = " ".join(milhouse_send_cmd_final)
            extra_send_cmd = " ".join(milhouse_send_cmd_extra)
            if normal_send_enabled:
                self.sender = process.ProcessManager(command=send_cmd, identifier="sender")
                self.sender.state_changed_signal.connect(self.on_process_state_changed)
                self.sender.stdout_line_signal.connect(self.on_sender_stdout_line)
                self.sender.stderr_line_signal.connect(self.on_sender_stderr_line)
            if extra_send_enabled:
                self.extra_sender = process.ProcessManager(command=extra_send_cmd, identifier="extra_sender")
                self.extra_sender.state_changed_signal.connect(self.on_process_state_changed)
                self.extra_sender.stdout_line_signal.connect(self.on_sender_stdout_line)
                self.extra_sender.stderr_line_signal.connect(self.on_sender_stderr_line)
                # FIXME: too much code duplication
        
        if midi_recv_enabled:
            midi_out_device = self.app.parse_midi_device_name(details["receive"]["midi"]["output_device"], is_input=False)
            #TODO: check if is None
            midi_recv_args = [
                "midistream",
                "--address", details["peer"]["address"],
                "--receiving-port", str(details["receive"]["midi"]["port"]),
                "--jitter-buffer", str(details["receive"]["midi"]["jitterbuffer"]),
                "--output-device", str(midi_out_device["number"])
                ]
                #"--verbose",
            midi_recv_command = " ".join(midi_recv_args) 
            self.midi_receiver = process.ProcessManager(command=midi_recv_command, identifier="midi_receiver")
            self.midi_receiver.state_changed_signal.connect(self.on_process_state_changed)
            self.midi_receiver.stdout_line_signal.connect(self.on_midi_stdout_line)
            self.midi_receiver.stderr_line_signal.connect(self.on_midi_stderr_line)
        
        if midi_send_enabled:
            midi_in_device = self.app.parse_midi_device_name(details["send"]["midi"]["input_device"], is_input=True)
            #TODO: check if is None
            midi_send_args = [
                "midistream",
                "--address", details["peer"]["address"],
                "--sending-port", str(details["send"]["midi"]["port"]),
                "--input-device", str(midi_in_device["number"])
                ]
                #"--verbose",
            midi_send_command = " ".join(midi_send_args) 
            self.midi_sender = process.ProcessManager(command=midi_send_command, identifier="midi_sender")
            self.midi_sender.state_changed_signal.connect(self.on_process_state_changed)
            self.midi_sender.stdout_line_signal.connect(self.on_midi_stdout_line)
            self.midi_sender.stderr_line_signal.connect(self.on_midi_stderr_line)
        
        # starting
        self._set_state(process.STATE_STARTING)
        if send_audio_enabled or send_video_enabled:
            log.info("$ %s" % (send_cmd))
            if normal_send_enabled:
                self.sender.start()
            if extra_send_enabled:
                self.extra_sender.start()
        if recv_audio_enabled or recv_video_enabled:
            log.info("$ %s" % (recv_cmd))
            if normal_recv_enabled:
                self.receiver.start()
            if extra_recv_enabled:
                self.extra_receiver.start()
        if midi_recv_enabled:
            self.midi_receiver.start()
        if midi_send_enabled:
            self.midi_sender.start()


Generated by  Doxygen 1.6.0   Back to index