Changeset 313
- Timestamp:
- Jul 19, 2011, 1:08:43 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
py-tcpmultiplexer/TCPMultiplexer.py
r312 r313 1 1 #!/usr/bin/env python 2 # 2 """ 3 3 # Multiplexer for HTTP streams, used for broadcast of MPJEG and WAV streams 4 4 # … … 6 6 # 7 7 # Rick van der Zwet <info@rickvanderzwet.nl> 8 # 8 """ 9 9 10 import SocketServer 10 11 import argparse … … 17 18 # Some boring defaults 18 19 DEFAULT_HOST = '0.0.0.0' 19 DEFAULT_PORT = '9999' 20 DEFAULT_PORT = 9999 21 DEFAULT_CONFIG = 'streams.yaml' 22 23 # URL : TARGET 24 DEFAULT_STREAMS = { 25 '/cam1/video' : 'http://172.16.0.67:8080/videofeed', 26 '/cam1/audio' : 'http://172.16.0.67:8080/audio.wav', 27 } 20 28 21 29 # Global variables used as ring-buffers or shared-storage … … 117 125 118 126 if __name__ == "__main__": 119 parser = argparse.ArgumentParser(description='Process some integers.') 127 parser = argparse.ArgumentParser(description=__doc__,formatter_class=argparse.RawDescriptionHelpFormatter) 128 parser.add_argument('--host', dest='host', default=DEFAULT_HOST, help='Listen to IP [default: %s]' % DEFAULT_HOST) 129 parser.add_argument('--port', dest='port', default=DEFAULT_PORT, type=int, help='Listen to PORT [default: %s]' % DEFAULT_PORT) 130 parser.add_argument('--stream-cfg', dest='stream_cfg', default=DEFAULT_CONFIG, help='YAML Stream configuration [default: %s]' % DEFAULT_CONFIG) 131 args = parser.parse_args() 120 132 121 # URL : TARGET 122 DEFAULT_STREAMS = { 123 '/cam1/video' : 'http://172.16.0.67:8080/videofeed', 124 '/cam1/audio' : 'http://172.16.0.67:8080/audio.wav', 125 } 126 # Flexible enough to specify using yaml file (sys.argv) as well 127 if len(sys.argv) > 1: 128 config_file = sys.argv[1] 129 try: 130 import yaml 131 streams = yaml.load(open(config_file)) 132 except (ImportError, IOError) as e: 133 logging.error("Config file '%s' not readable or parsable (%s)", config_file, e) 133 # Inport streams 134 streams = DEFAULT_STREAMS 135 try: 136 import yaml 137 streams = yaml.load(open(args.stream_cfg)) 138 except (ImportError, IOError) as e: 139 logging.warning("Stream config file '%s' not readable or parsable (%s)", args.stream_cfg, e) 134 140 135 141 136 HOST, PORT = "0.0.0.0", 9999 137 # Create the server 142 # Create the base server 138 143 try: 139 144 while True: 140 145 try: 141 146 ThreadedTCPServer.allow_reuse_address = True 142 server = ThreadedTCPServer(( HOST, PORT), MyTCPHandler)147 server = ThreadedTCPServer((args.host, args.port), MyTCPHandler) 143 148 break 144 149 except IOError, e: 145 logging.warning('For conection %s:%s to become available (%s)', HOST, PORT, e)150 logging.warning('For conection %s:%s to become available (%s)', args.host, args.port , e) 146 151 time.sleep(1) 147 152 except KeyboardInterrupt: … … 156 161 # interrupt the program with Ctrl-C 157 162 try: 158 logging.info('Serving at %s:%s', HOST,PORT)163 logging.info('Serving at %s:%s', args.host, args.port) 159 164 server.serve_forever() 160 165 except KeyboardInterrupt, IOError:
Note:
See TracChangeset
for help on using the changeset viewer.