def test_cli(self):
     xdg_dir_prev = os.environ.get('XDG_RUNTIME_DIR')
     try:
         os.environ['XDG_RUNTIME_DIR'] = self.tmp_dir
         with contextlib.closing(
                 pulsectl.connect_to_cli(as_file=False)) as s:
             s.send(b'dump\n')
             while True:
                 try:
                     buff = s.recv(2**20)
                 except socket.error:
                     buff = None
                 if not buff: raise AssertionError
                 if b'### EOF' in buff.splitlines(): break
         with contextlib.closing(pulsectl.connect_to_cli()) as s:
             s.write('dump\n')
             for line in s:
                 if line == '### EOF\n': break
             else: raise AssertionError
             s.write('load-module module-cli-protocol-tcp'
                     ' listen={} port={}\n'.format(*self.sock_tcp_cli))
         with contextlib.closing(pulsectl.connect_to_cli(
                 self.sock_tcp_cli)) as s:
             s.write('dump\n')
             for line in s:
                 if line == '### EOF\n': break
             else: raise AssertionError
             s.write('unload-module module-cli-protocol-tcp\n')
     finally:
         if xdg_dir_prev is not None:
             os.environ['XDG_RUNTIME_DIR'] = xdg_dir_prev
예제 #2
0
 def test_cli(self):
     xdg_dir_prev = os.environ.get('XDG_RUNTIME_DIR')
     try:
         os.environ['XDG_RUNTIME_DIR'] = self.tmp_dir
         with contextlib.closing(pulsectl.connect_to_cli()) as s:
             s.write('dump\n')
             for line in s:
                 if line == '### EOF\n': break
             else: raise AssertionError
             s.write('load-module module-cli-protocol-tcp'
                     ' listen={} port={}\n'.format(*self.sock_tcp_cli))
         with contextlib.closing(pulsectl.connect_to_cli(
                 self.sock_tcp_cli)) as s:
             s.write('dump\n')
             for line in s:
                 if line == '### EOF\n': break
             else: raise AssertionError
             s.write('unload-module module-cli-protocol-tcp\n')
     finally:
         if xdg_dir_prev is not None:
             os.environ['XDG_RUNTIME_DIR'] = xdg_dir_prev
예제 #3
0
	def test_cli(self):
		xdg_dir_prev = os.environ.get('XDG_RUNTIME_DIR')
		try:
			os.environ['XDG_RUNTIME_DIR'] = self.tmp_dir
			with contextlib.closing(pulsectl.connect_to_cli()) as s:
				s.write('dump\n')
				for line in s:
					if line == '### EOF\n': break
				else: raise AssertionError
				s.write(
					'load-module module-cli-protocol-tcp'
					' listen={} port={}\n'.format(*self.sock_tcp_cli) )
			with contextlib.closing(pulsectl.connect_to_cli(self.sock_tcp_cli)) as s:
				s.write('dump\n')
				for line in s:
					if line == '### EOF\n': break
				else: raise AssertionError
				s.write('unload-module module-cli-protocol-tcp\n')
		finally:
			if xdg_dir_prev is not None:
				os.environ['XDG_RUNTIME_DIR'] = xdg_dir_prev
예제 #4
0
 def cli_command(command):
     if not isinstance(command, list):
         command = [command]
     with contextlib.closing(pulsectl.connect_to_cli()) as s:
         for c in command:
             s.write(c + "\n")
예제 #5
0
파일: main.py 프로젝트: CBSkarmory/cadmus
def cli_command(command):
    with contextlib.closing(pulsectl.connect_to_cli()) as s:
        s.write(command)
예제 #6
0
    def __init__(self):
        logging.debug("Initing %s", self.__class__.__name__)
        self.pulse = Pulse()
        self.barecmd = connect_to_cli()

        default_sink_name = self.pulse.server_info().default_sink_name
        self.default_sink_info = self.pulse.get_sink_by_name(default_sink_name)

        out_sink_name = "game-out"
        # music + mic
        self.out_sink_module_id = self.pulse.module_load(
            "module-null-sink", 'sink_name=' + out_sink_name)
        self.out_sink_info = self.pulse.get_sink_by_name(out_sink_name)

        MP_sink_name = "Media-player"
        # that is our main sink. send your media here
        # everything that comes in is being copied to game sink and default sink
        self.MP_sink_module_id = self.pulse.module_load(
            "module-combine-sink", 'sink_name=' + MP_sink_name + ' slaves=' +
            str(self.out_sink_info.index) + ',' +
            str(self.default_sink_info.index))
        self.MP_sink_info = self.pulse.get_sink_by_name(MP_sink_name)

        # Get stream media -> speakers
        # TODO: this is also gay but it is somehow possible to retreve all inputs for sink. (sink_input_list(sinkIndex))
        for stream in self.pulse.sink_input_list():
            if stream.owner_module == self.MP_sink_module_id:
                if stream.sink == self.default_sink_info.index:
                    self.sound2speakers = stream
                elif stream.sink == self.out_sink_info.index:
                    self.sound2game = stream

        # send mic stream to game sink. (btw rip 20 ms)
        self.loopback_module_id = self.pulse.module_load(
            "module-loopback", 'sink=' + str(self.out_sink_info.index) +
            ' latency_msec=20 source_dont_move=true sink_dont_move=true')

        # Get stream mic -> game
        # TODO: this is also gay but it is somehow possible to retreve all inputs for sink. (sink_input_list(sinkIndex))
        for stream in self.pulse.sink_input_list():
            if stream.sink == self.out_sink_info.index and stream.owner_module == self.loopback_module_id:
                self.mic2game = stream

        # TODO: combine sink sets volume to earrape because reasons?
        hell = self.sound2speakers.volume
        hell.value_flat = 0.5
        self.pulse.volume_set(self.sound2speakers, hell)
        hell.value_flat = 1.0
        self.pulse.volume_set(self.sound2game, hell)

        # TODO: change names of sinks.
        # https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/615
        # self.barecmd.write(
        #     'update-sink-proplist ' + str(self.out_sink_info.index) + ' device.description="Game media player out"')
        # self.barecmd.write(
        #     'update-sink-proplist ' + str(self.MP_sink_info.index) + ' device.description="Game media player sink"')

        self.pulse.sink_default_set(self.default_sink_info)

        logging.debug("%s class loaded", self.__class__.__name__)
        logging.info("out sink module id: %d", self.out_sink_module_id)
        logging.info("MP sink module id: %d", self.MP_sink_module_id)
        logging.info("loopback module id: %d", self.loopback_module_id)