Changeset 323 for py-tcpmultiplexer
- Timestamp:
- Jul 19, 2011, 10:11:40 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
py-tcpmultiplexer/TCPMultiplexer.py
r322 r323 12 12 import argparse 13 13 import logging 14 import os 15 import socket 14 16 import sys 15 17 import threading 16 18 import time 17 19 import urllib2 18 import os19 20 20 21 # Some boring defaults … … 23 24 DEFAULT_CONFIG = 'streams.yaml' 24 25 DEFAULT_DOCUMENTROOT = './htdocs' 26 DEFAULT_TIMEOUT = 2 25 27 26 28 … … 30 32 '/cam1/audio' : 'http://172.16.0.67:8080/audio.wav', 31 33 } 34 32 35 33 36 # Global variables used as ring-buffers or shared-storage … … 95 98 del urldata[urlid][self] 96 99 100 101 97 102 def get_data(url, urlid, *args): 103 """ Fetch the DATA from the WAV or MJPEG Stream """ 98 104 global running, dataheader, urlheader, urldata 99 105 logger = logging.getLogger('recv_id=' + urlid) … … 101 107 logger.info("Starting thread '%s' (%s)", url, urlid) 102 108 while running: 109 urlheader[urlid] = None 110 dataheader[urlid] = None 111 urldata[urlid] = None 103 112 try: 104 113 f = urllib2.urlopen(url) 105 114 urlheader[urlid] = ''.join(f.info().headers) 106 115 urldata[urlid] = dict() 116 117 # Find datatype 107 118 datatype = None 108 119 urltype = f.info().gettype() … … 112 123 elif urltype == 'multipart/x-mixed-replace': 113 124 datatype = 'mjpeg' 125 126 # Be verbose to the user 127 if datatype: 128 logger.info("'%s' Identified as %s", url, datatype) 114 129 else: 115 130 logger.warning("Cannot find file type of '%s'", url) 116 131 117 if datatype: 118 logger.info("'%s' Identified as %s", url, datatype) 119 132 # Set the correct data header 120 133 if datatype == 'wav': 121 134 # WAV header … … 147 160 while running: 148 161 data = f.read(10000) 162 # logger.debug("Received data chunk with length: %s", len(data)) 149 163 for key in urldata[urlid].keys(): 150 164 urldata[urlid][key].append(data) … … 164 178 parser.add_argument('--host', dest='host', default=DEFAULT_HOST, help='Listen to IP [default: %s]' % DEFAULT_HOST) 165 179 parser.add_argument('--port', dest='port', default=DEFAULT_PORT, type=int, help='Listen to PORT [default: %s]' % DEFAULT_PORT) 180 parser.add_argument('--timeout', dest='timeout', default=DEFAULT_TIMEOUT, type=int, help='Default socket timeout [default: %s]' % DEFAULT_TIMEOUT) 166 181 parser.add_argument('--stream-cfg', dest='stream_cfg', default=DEFAULT_CONFIG, help='YAML Stream configuration [default: %s]' % DEFAULT_CONFIG) 167 182 parser.add_argument('--document-root', dest='document_root', default=DEFAULT_DOCUMENTROOT, help='Document Root File Directory [default: %s]' % DEFAULT_DOCUMENTROOT) … … 170 185 document_root = os.path.abspath(os.path.join(os.path.dirname(__file__),args.document_root)) 171 186 logging.info("Serving '/htdocs' from document_root '%s'", document_root) 187 188 # Set the timeout 189 socket.setdefaulttimeout(args.timeout) 172 190 173 191 # Inport streams
Note:
See TracChangeset
for help on using the changeset viewer.