| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | #!/ufs/guido/bin/sgi/python-405 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Send live video UDP packets. | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] | 
					
						
							|  |  |  | #              [host] .. | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import time | 
					
						
							|  |  |  | import struct | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | import string | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | from socket import * | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | from SOCKET import * | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | import gl, GL, DEVICE | 
					
						
							|  |  |  | sys.path.append('/ufs/guido/src/video') | 
					
						
							|  |  |  | import LiveVideoIn | 
					
						
							|  |  |  | import LiveVideoOut | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | import SV | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | import getopt | 
					
						
							|  |  |  | from IN import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from senddefs import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def usage(msg): | 
					
						
							|  |  |  | 	print msg | 
					
						
							|  |  |  | 	print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl]', | 
					
						
							|  |  |  | 	print '[-w width] [host] ...' | 
					
						
							|  |  |  | 	print '-b        : broadcast on local net' | 
					
						
							|  |  |  | 	print '-h height : window height (default ' + `DEFHEIGHT` + ')' | 
					
						
							|  |  |  | 	print '-p port   : port to use (default ' + `DEFPORT` + ')' | 
					
						
							|  |  |  | 	print '-t ttl    : time-to-live (multicast only; default 1)' | 
					
						
							|  |  |  | 	print '-s size   : max packet size (default ' + `DEFPKTMAX` + ')' | 
					
						
							|  |  |  | 	print '-w width  : window width (default ' + `DEFWIDTH` + ')' | 
					
						
							|  |  |  | 	print '[host] ...: host(s) to send to (default multicast to ' + \ | 
					
						
							|  |  |  | 		DEFMCAST + ')' | 
					
						
							|  |  |  | 	sys.exit(2) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 	sys.stdout = sys.stderr | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hosts = [] | 
					
						
							|  |  |  | 	port = DEFPORT | 
					
						
							|  |  |  | 	ttl = -1 | 
					
						
							|  |  |  | 	pktmax = DEFPKTMAX | 
					
						
							|  |  |  | 	width = DEFWIDTH | 
					
						
							|  |  |  | 	height = DEFHEIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		opts, args = getopt.getopt(sys.argv[1:], 'bh:p:s:t:w:') | 
					
						
							|  |  |  | 	except getopt.error, msg: | 
					
						
							|  |  |  | 		usage(msg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		for opt, optarg in opts: | 
					
						
							|  |  |  | 			if opt == '-p': | 
					
						
							|  |  |  | 				port = string.atoi(optarg) | 
					
						
							|  |  |  | 			if opt == '-b': | 
					
						
							|  |  |  | 				host = '<broadcast>' | 
					
						
							|  |  |  | 			if opt == '-t': | 
					
						
							|  |  |  | 				ttl = string.atoi(optarg) | 
					
						
							|  |  |  | 			if opt == '-s': | 
					
						
							|  |  |  | 				pktmax = string.atoi(optarg) | 
					
						
							|  |  |  | 			if opt == '-w': | 
					
						
							|  |  |  | 				width = string.atoi(optarg) | 
					
						
							|  |  |  | 			if opt == '-h': | 
					
						
							|  |  |  | 				height = string.atoi(optarg) | 
					
						
							|  |  |  | 	except string.atoi_error, msg: | 
					
						
							|  |  |  | 		usage('bad integer: ' + msg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for host in args: | 
					
						
							|  |  |  | 		hosts.append(gethostbyname(host)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if not hosts: | 
					
						
							|  |  |  | 		hosts.append(gethostbyname(DEFMCAST)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 	if not LiveVideoIn.have_video: | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 		print 'Sorry, no video available (use python-405 on roos)' | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 		sys.exit(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gl.foreground() | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 	gl.prefsize(width, height) | 
					
						
							|  |  |  | 	gl.stepunit(8, 6) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 	wid = gl.winopen('Vsend') | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 	gl.keepaspect(width, height) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 	gl.stepunit(8, 6) | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 	gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 	gl.winconstraints() | 
					
						
							|  |  |  | 	gl.qdevice(DEVICE.ESCKEY) | 
					
						
							|  |  |  | 	gl.qdevice(DEVICE.WINSHUT) | 
					
						
							|  |  |  | 	gl.qdevice(DEVICE.WINQUIT) | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 	gl.qdevice(DEVICE.WINFREEZE) | 
					
						
							|  |  |  | 	gl.qdevice(DEVICE.WINTHAW) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 	width, height = gl.getsize() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-09-24 16:03:56 +00:00
										 |  |  | 	lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s = socket(AF_INET, SOCK_DGRAM) | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 	s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 	if ttl >= 0: | 
					
						
							|  |  |  | 		s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, chr(ttl)) | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	frozen = 0 | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while 1: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if gl.qtest(): | 
					
						
							|  |  |  | 			dev, val = gl.qread() | 
					
						
							|  |  |  | 			if dev in (DEVICE.ESCKEY, \ | 
					
						
							|  |  |  | 				DEVICE.WINSHUT, DEVICE.WINQUIT): | 
					
						
							|  |  |  | 				break | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 			if dev == DEVICE.WINFREEZE: | 
					
						
							|  |  |  | 				frozen = 1 | 
					
						
							|  |  |  | 			if dev == DEVICE.WINTHAW: | 
					
						
							|  |  |  | 				frozen = 0 | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 			if dev == DEVICE.REDRAW: | 
					
						
							|  |  |  | 				w, h = gl.getsize() | 
					
						
							|  |  |  | 				x, y = gl.getorigin() | 
					
						
							|  |  |  | 				if (w, h) <> (width, height): | 
					
						
							|  |  |  | 					width, height = w, h | 
					
						
							| 
									
										
										
										
											1992-09-24 16:53:51 +00:00
										 |  |  | 					lvi.resizevideo(width, height) | 
					
						
							| 
									
										
										
										
											1992-09-24 16:03:56 +00:00
										 |  |  | 					lvo.resizevideo(width, height) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		rv = lvi.getnextpacket() | 
					
						
							|  |  |  | 		if not rv: | 
					
						
							|  |  |  | 			time.millisleep(10) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pos, data = rv | 
					
						
							| 
									
										
										
										
											1992-09-24 12:54:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if not frozen: | 
					
						
							|  |  |  | 			lvo.putnextpacket(pos, data) | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		hdr = struct.pack('hhh', pos, width, height) | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 		for host in hosts: | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				s.sendto(hdr + data, (host, port)) | 
					
						
							|  |  |  | 			except error, msg: # really socket.error | 
					
						
							|  |  |  | 				if msg[0] <> 121: # no buffer space available | 
					
						
							|  |  |  | 					raise error, msg # re-raise it | 
					
						
							|  |  |  | 				print 'Warning:', msg[1] | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	lvi.close() | 
					
						
							|  |  |  | 	lvo.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-09-24 15:01:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1992-09-22 17:23:17 +00:00
										 |  |  | main() |