diff options
author | Guido van Rossum <guido@python.org> | 1992-09-24 15:01:37 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-09-24 15:01:37 (GMT) |
commit | 7b47c79a4c2bb83f316e96cf16e3f74d768a428d (patch) | |
tree | bc1aa30ff7cb948eadbbe0fd398fa6493c1c4e16 /Demo/sgi | |
parent | 67b4895291cdb53e63b503426ca4e52b70904a45 (diff) | |
download | cpython-7b47c79a4c2bb83f316e96cf16e3f74d768a428d.zip cpython-7b47c79a4c2bb83f316e96cf16e3f74d768a428d.tar.gz cpython-7b47c79a4c2bb83f316e96cf16e3f74d768a428d.tar.bz2 |
Added options to Vsend and Vreceive; moved common defaults to senddefs.
Optimized LiveVideoIn quite a bit; removed print stmt from LiveVideoOut.
Diffstat (limited to 'Demo/sgi')
-rwxr-xr-x | Demo/sgi/video/LiveVideoOut.py | 3 | ||||
-rwxr-xr-x | Demo/sgi/video/Vreceive.py | 40 | ||||
-rwxr-xr-x | Demo/sgi/video/Vsend.py | 97 | ||||
-rwxr-xr-x | Demo/sgi/video/senddefs.py | 11 |
4 files changed, 115 insertions, 36 deletions
diff --git a/Demo/sgi/video/LiveVideoOut.py b/Demo/sgi/video/LiveVideoOut.py index d9c1138..150e8a0 100755 --- a/Demo/sgi/video/LiveVideoOut.py +++ b/Demo/sgi/video/LiveVideoOut.py @@ -53,4 +53,5 @@ class LiveVideoOut: gl.winset(oldwid) def close(self): - print 'Done video out' + ##print 'Done video out' + pass diff --git a/Demo/sgi/video/Vreceive.py b/Demo/sgi/video/Vreceive.py index 415df59..334fe66 100755 --- a/Demo/sgi/video/Vreceive.py +++ b/Demo/sgi/video/Vreceive.py @@ -14,23 +14,43 @@ import gl, GL, DEVICE sys.path.append('/ufs/guido/src/video') import LiveVideoOut import regsub +import getopt -MYGROUP = '225.0.0.250' -PORT = 5555 +from senddefs import * + + +def usage(msg): + print msg + print 'usage: Vreceive [-m mcastgrp] [-p port]' + print '-m mcastgrp: multicast group (default ' + `DEFMCAST` + ')' + print '-p port : port (default ' + `DEFPORT` + ')' + sys.exit(2) -PKTMAX = 16*1024 -WIDTH = 400 -HEIGHT = 300 def main(): - port = PORT - if sys.argv[1:]: - port = eval(sys.argv[1]) + sys.stdout = sys.stderr + + group = DEFMCAST + port = DEFPORT + width = DEFWIDTH + height = DEFHEIGHT + + try: + opts, args = getopt.getopt(sys.argv[1:], 'm:p:') + except getopt.error, msg: + usage(msg) - s = opensocket(MYGROUP, port) + try: + for opt, optarg in opts: + if opt == '-p': + port = string.atoi(optarg) + if opt == '-m': + group = gethostbyname(optarg) + except string.atoi_error, msg: + usage('bad integer: ' + msg) - width, height = WIDTH, HEIGHT + s = opensocket(group, port) gl.foreground() gl.prefsize(width, height) diff --git a/Demo/sgi/video/Vsend.py b/Demo/sgi/video/Vsend.py index f38e965..e5154c0 100755 --- a/Demo/sgi/video/Vsend.py +++ b/Demo/sgi/video/Vsend.py @@ -1,11 +1,13 @@ #!/ufs/guido/bin/sgi/python-405 # Send live video UDP packets. -# Usage: Vsend [host [port]] +# Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] +# [host] .. import sys import time import struct +import string from socket import * from SOCKET import * import gl, GL, DEVICE @@ -13,37 +15,73 @@ sys.path.append('/ufs/guido/src/video') import LiveVideoIn import LiveVideoOut import SV +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) -PKTMAX_UCAST = 16*1024 - 6 -PKTMAX_BCAST = 1450 -WIDTH = 400 -HEIGHT = 300 -HOST = '225.0.0.250' # Multicast address! -PORT = 5555 def main(): + 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)) + if not LiveVideoIn.have_video: - print 'Sorry, no video (use python-405 on roos)' + print 'Sorry, no video available (use python-405 on roos)' sys.exit(1) - host = HOST - port = PORT - if sys.argv[1:]: - host = sys.argv[1] - if host == '-b': - host = '<broadcast>' - if sys.argv[2:]: - port = eval(sys.argv[2]) - - if host == '<broadcast>': - pktmax = PKTMAX_BCAST - else: - pktmax = PKTMAX_UCAST - gl.foreground() - gl.prefsize(WIDTH, HEIGHT) + gl.prefsize(width, height) + gl.stepunit(8, 6) wid = gl.winopen('Vsend') - gl.keepaspect(WIDTH, HEIGHT) + gl.keepaspect(width, height) gl.stepunit(8, 6) gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX) gl.winconstraints() @@ -62,6 +100,8 @@ def main(): s = socket(AF_INET, SOCK_DGRAM) s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) + if ttl >= 0: + s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, chr(ttl)) frozen = 0 @@ -101,9 +141,16 @@ def main(): lvo.putnextpacket(pos, data) hdr = struct.pack('hhh', pos, width, height) - s.sendto(hdr + data, (host, port)) + 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] lvi.close() lvo.close() + main() diff --git a/Demo/sgi/video/senddefs.py b/Demo/sgi/video/senddefs.py new file mode 100755 index 0000000..c3ce2cd --- /dev/null +++ b/Demo/sgi/video/senddefs.py @@ -0,0 +1,11 @@ +# Defaults shared by Vsend and Vreceice + +DEFMCAST = '225.0.0.250' +DEFPORT = 5555 + +PKTMAX_UCAST = 16*1024 - 6 +PKTMAX_BCAST = 1450 +DEFPKTMAX = PKTMAX_BCAST + +DEFWIDTH = 400 +DEFHEIGHT = 300 |