Beispiel #1
0
 def _create_conf(self):
     fd, conf_path = tempfile.mkstemp(suffix='.conf')
     conf = "start  {}\nend {}\ninterface {}\nnotify_file dumpleases\noption subnet {}\noption lease {}\n".format(
         Settings().peeraddress,
         Settings().peeraddress, self.interface,
         Settings().netmask,
         Settings().timeout)
     with open(conf_path, 'w') as c:
         c.write(conf)
     return conf_path
Beispiel #2
0
 def __init__(self, interface: str, logger='picast'):
     """Constructor accept an interface to listen."""
     self.config = Settings()
     self.dhcpd = None
     self.interface = interface
     self.logger = getLogger(logger)
     self.conf_path = self._create_conf()
Beispiel #3
0
def main(arg: Optional[Any] = None):
    parser = argparse.ArgumentParser(
        prog='picast',
        description='picast',
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=True)
    parser.add_argument("--debug",
                        action="store_true",
                        help="Verbose debug output")
    parser.add_argument("-c", "--config", help="Specify configuration file.")

    args = parser.parse_args(arg)
    if args.config:
        config_file = args.config
        if os.path.exists(config_file) and os.path.isfile(config_file):
            pass
        else:
            config_file = None
    else:
        config_file = None

    # ------------------- start of configurations
    # it should call first: load configurations from ini files
    config = Settings(config=config_file)
    package_dir = os.path.join(os.path.dirname(__file__))
    if config.logging_config:
        logging_ini = config.logging_config
        if not os.path.exists(logging_ini):
            if os.path.exists(os.path.join(package_dir, logging_ini)):
                logging_ini = os.path.join(package_dir, logging_ini)
    else:
        logging_ini = os.path.join(package_dir, "logging.ini")
    LoggingConfig.fileConfig(logging_ini)
    logger = getLogger(config.logger)
    if args.debug:
        logger.setLevel("DEBUG")

    if config.player == "gst":
        player = GstPlayer()  # type: Optional[Union[GstPlayer, VlcPlayer]]
    elif config.player == "vlc":
        player = VlcPlayer()
    else:
        player = None
        logger.fatal("FATAL: Unknown player name option!: {}".format(
            config.player))
        exit(1)
    # ------------------- end of configurations

    wifip2p = WifiP2PServer()
    rtspsink = RtspSink(player)

    wifip2p.start()
    rtspsink.start()

    rtspsink.join()
    wifip2p.join()
Beispiel #4
0
 def __init__(self):
     self.config = Settings()
     self.native = 0x06
     self.preferred = 0
     self.profile = 0x01
     self.level = 0x10
     with open(os.path.join(os.path.dirname(__file__), 'resolutions.json'),
               'r') as j:
         self.resolutions = json.load(j)[0]
     self._get_display_resolutions()
Beispiel #5
0
 def __init__(self,  player, logger='picast'):
     super(RtspSink, self).__init__(name='rtsp-server-0', daemon=True)
     self.config = Settings()
     self.logger = getLogger(logger)
     self.player = player
     self.watchdog = 0
     self.csnum = 0
     self.daemon = True
     self.video = RasberryPiVideo()
     self.wfd_parameters = self.config.get_wfd_parameters()
     self.wfd_video_formats = self.video.get_wfd_video_formats()
Beispiel #6
0
def test_config_override():
    fd, temp_path = tempfile.mkstemp()
    with open(temp_path, "w") as f:
        f.write("[player]\n")
        f.write("name=nop\n")
    Settings()._config = None # Clean singletone state
    assert Settings().device_name == 'picast'
    assert Settings().player == 'vlc'
    Settings()._config = None # Clena singletone state
    assert Settings(config=temp_path).device_name == 'picast'
    assert Settings(config=temp_path).player == 'nop'
    Settings()._config = None # Clena singletone state
    os.unlink(temp_path)
Beispiel #7
0
def test_config_device_name():
    assert Settings().device_name == 'picast'
Beispiel #8
0
def test_config_device_type():
    assert Settings().device_type == '7-0050F204-4'
Beispiel #9
0
def test_config_rtp_port():
    assert Settings().rtp_port == 1028
Beispiel #10
0
def test_config_rtsp_port():
    assert Settings().rtsp_port == 7236
Beispiel #11
0
def test_config_group_name():
    assert Settings().group_name == 'persistent'
Beispiel #12
0
def test_config_netmask():
    assert Settings().netmask == '255.255.255.0'
Beispiel #13
0
def test_config_player_custom_args():
    assert Settings().player_custom_args == []
Beispiel #14
0
 def __init__(self, logger='picast'):
     self.config = Settings()
     self.logger = getLogger(logger)
     Gst.init(None)
Beispiel #15
0
def test_config_player():
    assert Settings().player == 'vlc'
Beispiel #16
0
def test_config_recreate_group():
    assert Settings().recreate_group == False
Beispiel #17
0
def test_config_gst_decoder():
    assert Settings().gst_decoder == 'omxh264dec'
Beispiel #18
0
def test_config_max_timeout():
    assert Settings().max_timeout == '10'
Beispiel #19
0
def test_config_wps_mode():
    assert Settings().wps_mode == 'pin'
Beispiel #20
0
def test_config_pin():
    assert Settings().pin == '12345678'
Beispiel #21
0
def test_config_logger():
    assert Settings().logger == 'picast'
Beispiel #22
0
def test_config_player_log_file():
    assert Settings().player_log_file == '/var/tmp/player.log'
Beispiel #23
0
def test_config_logging_config():
    assert Settings().logging_config == 'logging.ini'
Beispiel #24
0
def test_config_myaddress():
    assert Settings().myaddress == '192.168.173.1'
Beispiel #25
0
def test_config_peeraddress():
    assert Settings().peeraddress == '192.168.173.80'
Beispiel #26
0
 def __init__(self):
     self.config = Settings()
     self.logger = getLogger(self.config.logger)
     self.zc = zeroconf.Zeroconf()
Beispiel #27
0
 def __init__(self, R2=False, logger='picast'):
     super(WifiP2PServer, self).__init__(name='wifi-p2p-0', daemon=False)
     self.config = Settings()
     self.logger = getLogger(logger)
     self.set_p2p_interface(R2)