コード例 #1
0
ファイル: server.py プロジェクト: kamaal44/ludit
    def __init__(self, configuration_file):
        super(Server, self).__init__(name='server')

        log.info('starting server at %s' % util.local_ip())

        self.configuration_file = configuration_file
        self.configuration = None
        self.load_configuration()

        self.play_sequencer = None
        self.play_thread_active = True
        self.cant_play_warning = 5
        self.delayed_broadcast = None

        self.launch_playsequencer()

        source_config = self.configuration['sources']
        streaming_config = self.configuration['streaming']
        self.input_mux = inputmux.InputMux(source_config, streaming_config)

        self.multicast = multicast.Server(
            self.configuration['multicast']['ip'],
            int(self.configuration['multicast']['port']))

        self.multicast.connect('server_receive', self.multicast_rx)

        self.ws = websocket.WebSocket(util.local_ip(),
                                      source_config['ludit_websocket_port'])
        self.ws.connect('message', self.websocket_rx)

        self.start()
コード例 #2
0
    def __init__(self, id):
        super(ServerSocket, self).__init__(name='serversoc ')
        self.connection = None
        self.id = id
        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            # close gracefully from this end
            l_onoff = 1
            l_linger = 0
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
                                   struct.pack('ii', l_onoff, l_linger))
            # and detect peers that didn't close gracefully with a reset
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            self.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 2)
            self.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 2)
            self.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, 2)
            self.socket.bind((util.local_ip(), 0))
            self.socket.listen(1)
        except socket.error as e:
            if e.errno == 98:  # Address already in use
                log.critical(str(e) + ' - cant start')
                raise e
        except Exception as e:
            log.critical('serversocket %s caught %s' % (self.id, str(e)))

        self.start()
コード例 #3
0
ファイル: sourcetcp.py プロジェクト: bjerrep/ludit
    def construct_pipeline(self):
        if self.pipeline:
            self.pipeline.set_state(Gst.State.NULL)

        try:
            # playing a sine wave through this source (always remember the volume or be prepared for a wakeup call):
            # gst-launch-1.0 audiotestsrc freq=1000 volume=0.004 is-live=true ! audioconvert ! audio/x-raw, channels=2 !
            # faac ! aacparse ! avmux_adts ! tcpclientsink host=<hostname> port=4666
            #
            # for playing the pipeline above directly on a second command line (without the server running):
            # gst-launch-1.0 tcpserversrc host=<hostname> port=4666 ! decodebin ! audioconvert ! alsasink
            #
            ip = util.local_ip()
            pipeline = 'tcpserversrc host=%s port=%i ! appsink name=appsink emit-signals=true sync=false' % \
                       (ip, self.port)

            log.info('launching %s pipeline listening at %s:%i' %
                     (self.name, ip, self.port))
            self.pipeline = Gst.parse_launch(pipeline)

            appsink = self.pipeline.get_by_name('appsink')
            appsink.connect('new-sample', self.new_sample)

            bus = self.pipeline.get_bus()
            bus.add_signal_watch()
            bus.enable_sync_message_emission()
            bus.connect('message', self.bus_message)

            self.pipeline.set_state(Gst.State.PLAYING)

        except Exception as e:
            log.critical("couldn't construct pipeline, %s" % str(e))
コード例 #4
0
 def __init__(self):
     super(Monitor, self).__init__()
     self.multicast = multicast.Server(util.remote_multicast_ip,
                                       util.remote_multicast_port)
     self.multicast.connect('server_receive', self.multicast_rx)
     self.ws = websocket.WebSocket(util.local_ip(), monitor_websocket_port)
     self.ws.connect('message', self.websocket_rx)
     self.start()
     self.bt = bluetooth_metrics.BTDiscoverer()
     self.bt.connect('bt_client', self.bt_slot)
コード例 #5
0
    def websocket_rx(self, message):
        ip = message['ip']
        command = message['command']
        log.debug('got websocket command %s from %s' % (command, ip))
        result = None

        if command == 'restart_all':
            self.multicast.send({'command': 'restart_all', 'to': '*'})
            self.computer(command)
        elif command == 'restart_ludit':
            self.multicast.send({'command': 'restart_ludit', 'to': '*'})
            self.computer(command)
        elif command == 'reboot':
            self.multicast.send({'command': 'reboot', 'to': '*'})
            self.computer(command)
        elif command == 'get_cputemperature':
            self.multicast.send({'command': 'cputemperature', 'to': '*'})
            result = metrics.get_cputemperature()
        elif command == 'get_uptime':
            self.multicast.send({'command': 'uptime', 'to': '*'})
            result = metrics.get_uptime()
        elif command == 'get_loadaverages':
            self.multicast.send({'command': 'loadaverages', 'to': '*'})
            result = metrics.get_loadaverages()
        elif command == 'get_cpuload':
            self.multicast.send({'command': 'cpuload', 'to': '*'})
            result = metrics.get_cpu_load()
        elif command == "get_wifi_stats":
            self.multicast.send({'command': 'wifi_stats', 'to': '*'})
        elif command == "get_bluetooth_clients":
            if not self.bt:
                self.bt = bluetooth_metrics.BTDiscoverer()
                self.bt.connect('bt_client', self.bt_slot)
            else:
                log.info('bluetooth request ignored, already active')
        elif command == 'get_ip':
            self.multicast.send({'command': 'ip', 'to': '*'})
            result = util.local_ip()

        if result:
            self.send_websocket_result(command, result)
コード例 #6
0
    def __init__(self, id):
        super(ServerSocket, self).__init__(name='serversoc ')
        self.connection = None
        self.id = id
        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            l_onoff = 1
            l_linger = 0
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
                                   struct.pack('ii', l_onoff, l_linger))
            self.socket.bind((util.local_ip(), 0))
            self.socket.listen(1)
        except socket.error as e:
            if e.errno == 98:  # Address already in use
                log.critical(str(e) + ' - cant start')
                raise e
        except Exception as e:
            log.critical('serversocket %s caught %s' % (self.id, str(e)))

        self.start()
コード例 #7
0
ファイル: remote.py プロジェクト: kamaal44/ludit
    def multicast_rx(self, message):
        self.server_lost_time = time.time() + self.SERVER_LOST_SECONDS
        command = message['command']
        log.debug('processing command %s' % command)
        result = None
        if command in ('start', 'stop'):
            result = self.service(command, message['service'])
        elif command in ('reboot', 'restart_all'):
            result = self.computer(command)
        elif command == 'cputemperature':
            result = metrics.get_cputemperature()
        elif command == 'ip':
            result = util.local_ip()
        elif command == 'uptime':
            result = metrics.get_uptime()
        elif command == 'loadaverages':
            result = metrics.get_loadaverages()
        elif command == 'cpuload':
            result = metrics.get_cpu_load()
        elif command == 'wifi_stats':
            result = metrics.get_wifi_stats()
        elif command == 'message':
            log.info('message: %s' % message['message'])
        elif command == 'ping':
            pass
        else:
            result = str(-1)

        if result:
            log.debug('%s returns %s = %s' % (self.id, command, result))
            self.multicast.send({
                'command': command,
                'to': 'server',
                'from': self.id,
                'result': result
            })
コード例 #8
0
ファイル: server.py プロジェクト: kamaal44/ludit
def generate_config():
    kitchen_device_left = {'name': 'left', 'channel': 'left'}
    kitchen_device_right = {'name': 'right', 'channel': 'right'}

    kitchen_group = {
        'general': {
            'legend': 'Kitchen',
            'name': 'kitchen',
            'enabled': "true",
            'playing': "true",
            'devices': [kitchen_device_left, kitchen_device_right],
        },
        'levels': {
            'volume': '10.0',
            'balance': '0.0',
            'equalizer': {
                '0': '12.0',
                '1': '10.0',
                '2': '3.0'
            }
        },
        'xover': {
            'highlowbalance': '-0.1',
            'freq': '1500',
            'poles': '4',
        },
        'stereoenhance': {
            'visible': 'false',
            'depth': '0.0',
            'enabled': "false",
        }
    }

    stereo_device = {'name': 'stereo', 'channel': 'stereo'}

    stereo_group = {
        'general': {
            'legend': 'Stereo',
            'name': 'stereo',
            'enabled': "true",
            'playing': "false",
            'devices': [stereo_device],
        },
        'levels': {
            'volume': '10.0',
            'balance': '0.0',
            'equalizer': {
                '0': '12.0',
                '1': '10.0',
                '2': '0.0'
            }
        },
        'xover': {
            'highlowbalance': '-0.1',
            'freq': '1500',
            'poles': '4',
        },
        'stereoenhance': {
            'visible': 'false',
            'depth': '0.0',
            'enabled': "false",
        },
        'realtime': {
            'enabled': 'false',
            'level_db': '-40.0',
            'duration_sec': '15'
        }
    }

    configuration = {
        'version': util.CONFIG_VERSION,
        'groups': [kitchen_group, stereo_group],
        'streaming': {
            'audiotimeout': '5',
            'playdelay': '0.5',
            'buffersize': '200000'
        },
        'sources': {
            'mopidy_ws_enabled': 'false',
            'mopidy_ws_address': util.local_ip(),
            'mopidy_ws_port': '6680',
            'mopidy_gst_port': '4666',
            'gstreamer_port': '4665',
            'ludit_websocket_port': '45658',
            'audiominblocksize': '3000',
            'alsasource': {
                'enabled': 'false',
                'device': 'hw:0',
                'timeout': '5.0',
                'threshold_dB': '-40.0'
            }
        },
        'multicast': {
            'ip': util.multicast_ip,
            'port': str(util.multicast_port)
        }
    }
    return configuration