def main(): u""" This is a working example utility using this class, this method will : * Parse arguments from command line * Register handlers to SIGTERM and SIGINT * Instantiate a :mod:`SocketFecGenerator` and start it """ import doctest, errno, signal from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, FileType from pytoolbox.encoding import configure_unicode from pytoolbox.logging import setup_logging from ...ip import IPSocket configure_unicode() setup_logging(name=u'smpte2022lib', filename=None, console=True, level=logging.DEBUG) log.info(u'Testing SocketFecGenerator with doctest') doctest.testmod(verbose=False) log.info(u'OK') HELP_MEDIA = u'Socket of input stream' HELP_COL = u'Socket of generated FEC column stream' HELP_ROW = u'Socket of generated FEC row stream' HELP_L = u'Horizontal size of the FEC matrix (columns)' HELP_D = u'Vertical size of the FEC matrix (rows)' HELP_TIMEOUT = u'Set timeout for socket operations (in seconds)' HELP_PROFILE = u'Set profiling output file (this enable profiling)' HELP_STOP = u'Automatic stop time (in seconds)' dmedia = SocketFecGenerator.DEFAULT_MEDIA dcol = SocketFecGenerator.DEFAULT_COL drow = SocketFecGenerator.DEFAULT_ROW parser = ArgumentParser( formatter_class=ArgumentDefaultsHelpFormatter, epilog=u'''This utility create SMPTE 2022-1 FEC streams from a sniffed source stream. SMPTE 2022-1 help streaming systems to improve QoE of real-time RTP transmissions.''') parser.add_argument(u'-m', u'--media', type=IPSocket, help=HELP_MEDIA, default=dmedia) parser.add_argument(u'-c', u'--col', type=IPSocket, help=HELP_COL, default=dcol) parser.add_argument(u'-r', u'--row', type=IPSocket, help=HELP_ROW, default=drow) parser.add_argument(u'-l', type=int, help=HELP_L, default=5) parser.add_argument(u'-d', type=int, help=HELP_D, default=6) parser.add_argument(u'-t', u'--timeout', type=int, help=HELP_TIMEOUT, nargs='?', default=None) parser.add_argument(u'-s', u'--stop-time', type=int, help=HELP_STOP, nargs='?', default=None) parser.add_argument(u'-p', u'--profile', type=FileType('w'), help=HELP_PROFILE, nargs='?', default=None) args = parser.parse_args() def handle_stop_signal(SIGNAL, stack): generator.stop() try: signal.signal(signal.SIGTERM, handle_stop_signal) signal.signal(signal.SIGINT, handle_stop_signal) generator = SocketFecGenerator(args.media, args.col, args.row, args.l, args.d) if args.profile: from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput with PyCallGraph(output=GraphvizOutput(output_file=args.profile.name)): generator.run(args.timeout, args.stop_time) else: generator.run(args.timeout, args.stop_time) except socket.error as e: if e.errno != errno.EINTR: raise
CONFIG_FILENAME = join(abspath(dirname(__file__)), LOCAL_CONFIG_FILENAME) CSV_DIRECTORY = join(abspath(dirname(__file__)), u'mock') HELP_MOCK = u'Mock the MongoDB driver with MongoMock ([WARNING] Still not a perfect mock of the real-one)' try: configure_unicode() parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter, epilog=ABOUT) parser.add_argument(u'-m', u'--mock', action=u'store_true', help=HELP_MOCK, default=False) args = parser.parse_args() if args.mock: local_config = ORCHESTRA_CONFIG_TEST else: local_config = OrchestraLocalConfig.read(CONFIG_FILENAME, inspect_constructor=False) setup_logging(console=True, level=local_config.log_level) if not local_config.storage_uri(): logging.warning(u'Shared storage is not set in configuration ... exiting') sys.exit(0) if not local_config.mongo_admin_connection: logging.warning(u'MongoDB is not set in configuration ... mocking') if not local_config.rabbit_connection: logging.warning(u'RabbitMQ is not set in configuration ... exiting') sys.exit(0) # Create an instance of the API core api_core = get_test_api_core(CSV_DIRECTORY) if args.mock else OrchestraAPICore(local_config) is_standalone = api_core.config.is_standalone
def main(): u""" This is a working example utility using this class, this method will : * Parse arguments from command line * Register handlers to SIGTERM and SIGINT * Instantiate a :mod:`TwistedFecGenerator` and start it """ import doctest, errno, signal from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, FileType from pytoolbox.encoding import configure_unicode from pytoolbox.logging import setup_logging from twisted.internet import reactor from ...ip import IPSocket configure_unicode() setup_logging(name=u'smpte2022lib', filename=None, console=True, level=logging.DEBUG) log.info(u'Testing TwistedFecGenerator with doctest') doctest.testmod(verbose=False) log.info(u'OK') HELP_MEDIA = u'Socket of input stream' HELP_COL = u'Socket of generated FEC column stream' HELP_ROW = u'Socket of generated FEC row stream' HELP_L = u'Horizontal size of the FEC matrix (columns)' HELP_D = u'Vertical size of the FEC matrix (rows)' HELP_PROFILE = u'Set profiling output file (this enable profiling)' dmedia = TwistedFecGenerator.DEFAULT_MEDIA dcol = TwistedFecGenerator.DEFAULT_COL drow = TwistedFecGenerator.DEFAULT_ROW parser = ArgumentParser( formatter_class=ArgumentDefaultsHelpFormatter, epilog=u'''This utility create SMPTE 2022-1 FEC streams from a sniffed source stream. SMPTE 2022-1 help streaming systems to improve QoE of real-time RTP transmissions.''') parser.add_argument(u'-m', u'--media', type=IPSocket, help=HELP_MEDIA, default=dmedia) parser.add_argument(u'-c', u'--col', type=IPSocket, help=HELP_COL, default=dcol) parser.add_argument(u'-r', u'--row', type=IPSocket, help=HELP_ROW, default=drow) parser.add_argument(u'-l', type=int, help=HELP_L, default=5) parser.add_argument(u'-d', type=int, help=HELP_D, default=6) parser.add_argument(u'-p', u'--profile', type=FileType('w'), help=HELP_PROFILE, nargs='?', default=None) args = parser.parse_args() def handle_stop_signal(SIGNAL, stack): log.info(u'\nGenerator stopped\n') reactor.stop() try: signal.signal(signal.SIGTERM, handle_stop_signal) signal.signal(signal.SIGINT, handle_stop_signal) # FIXME port ? TwistedFecGenerator(args.media[u'ip'], u'MyGenerator', args.col, args.row, args.l, args.d) # Disabled otherwise multicast packets are received twice ! # See ``sudo watch ip maddr show`` they will be 2 clients if uncommented : # reactor.run() vs -> reactor.listenMulticast(args.media['port'], generator, listenMultiple=True) <- if args.profile: from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput with PyCallGraph(output=GraphvizOutput(output_file=args.profile.name)): reactor.run() else: reactor.run() except socket.error as e: if e.errno != errno.EINTR: raise