Exemplo n.º 1
0
    def run(self):
        self.encoder.run()
        self.output.run()
        self.player.set_out_stream(self.output.input_stream)
        self.player.run()
        self.bt_remote.run()
        self.control_pipe.listen()
        if platform.machine() != "x86_64":
            from gpio_remote import GpioRemote
            self.gpio_remote = GpioRemote(self.remote_event, self.remote_msg)
            self.gpio_remote.run()

        threading.Thread(target=self.check_remotes).start()
        '''
Exemplo n.º 2
0
    def run(self):
        # TODO: use some synchronization mechanism to ensure consistency player -> encoder -> output
        self.player.run()
        self.encoder.run()
        self.output.start()

        # TODO: start other control threads here (remotes) using the same event for all
        self.control_pipe.listen()
        if platform.machine() != "x86_64":
            from gpio_remote import GpioRemote
            self.gpio_remote = GpioRemote(self.remote_event, self.remote_msg)
            self.gpio_remote.run()

        threading.Thread(target=self.check_remotes).start()

        # wait for the player to spawn
        while self.player.stream is None:
            time.sleep(0.2)

        # pre-buffer
        data = self.player.stream.stdout.read(self.player.CHUNK)

        # play stream
        while True:
            try:
                if data is not None:
                    self.encoder.stream.stdin.write(data)
                else:  # avoid 100% CPU when player is paused
                    # print("waiting for player data")
                    raise AttributeError
                encoded = self.encoder.stream.stdout.read(
                    self.player.CHUNK)  # must be non-blocking
                if encoded is not None:  # send the encoded data to output, if any
                    self.output.stream.stdin.write(encoded)
                else:
                    # print("waiting for encoder data")
                    raise AttributeError
            except AttributeError:
                time.sleep(self.player.SLEEP_TIME)
            # advance the "play head"
            if self.player.stream is not None:
                data = self.player.stream.stdout.read(
                    self.player.CHUNK)  # must be non-blocking
Exemplo n.º 3
0
    def run(self):
        self.player.run()
        self.encoder.run()
        self.output.run()
        self.bt_remote.run()
        self.control_pipe.listen()
        if platform.machine() != "x86_64":
            from gpio_remote import GpioRemote
            self.gpio_remote = GpioRemote(self.remote_event, self.remote_msg)
            self.gpio_remote.run()

        threading.Thread(target=self.check_remotes).start()

        # wait for the player to be ready and pre-buffer
        self.player.ready.wait()
        data = self.player.output_stream.read(self.player.CHUNK)
        print("player is ready")

        # play stream
        while True:
            try:
                if data is not None:
                    self.encoder.ready.wait()
                    self.encoder.input_stream.write(data)
                else:
                    # print("waiting for player data")
                    raise AttributeError
                self.encoder.ready.wait()
                encoded = self.encoder.output_stream.read(self.player.CHUNK)
                if encoded is not None:  # send the encoded data to output, if any
                    self.output.ready.wait()
                    self.output.input_stream.write(encoded)
                else:
                    # print("waiting for encoder data")
                    raise AttributeError
            except AttributeError:
                time.sleep(self.player.SLEEP_TIME
                           )  # avoid 100% CPU when player is paused
            # advance the "play head"
            self.player.ready.wait()
            data = self.player.output_stream.read(self.player.CHUNK)