3 # Send live video UDP packets.
4 # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width]
14 sys
.path
.append('/ufs/guido/src/video')
21 from senddefs
import *
25 print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]',
26 print '[-w width] [host] ...'
27 print '-b : broadcast on local net'
28 print '-h height : window height (default ' + `DEFHEIGHT`
+ ')'
29 print '-p port : port to use (default ' + `DEFPORT`
+ ')'
30 print '-t ttl : time-to-live (multicast only; default 1)'
31 print '-s size : max packet size (default ' + `DEFPKTMAX`
+ ')'
32 print '-w width : window width (default ' + `DEFWIDTH`
+ ')'
33 print '-c type : Type: rgb8, mono or grey (default rgb8)'
34 print '[host] ...: host(s) to send to (default multicast to ' + \
40 sys
.stdout
= sys
.stderr
51 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'bh:p:s:t:w:c:')
52 except getopt
.error
, msg
:
56 for opt
, optarg
in opts
:
58 port
= string
.atoi(optarg
)
62 ttl
= string
.atoi(optarg
)
64 pktmax
= string
.atoi(optarg
)
66 width
= string
.atoi(optarg
)
68 height
= string
.atoi(optarg
)
71 except string
.atoi_error
, msg
:
72 usage('bad integer: ' + msg
)
75 hosts
.append(gethostbyname(host
))
78 hosts
.append(gethostbyname(DEFMCAST
))
80 if not LiveVideoIn
.have_video
:
81 print 'Sorry, no video available (use python-405)'
85 gl
.prefsize(width
, height
)
87 wid
= gl
.winopen('Vsend')
88 gl
.keepaspect(width
, height
)
90 gl
.maxsize(SV
.PAL_XMAX
, SV
.PAL_YMAX
)
92 gl
.qdevice(DEVICE
.ESCKEY
)
93 gl
.qdevice(DEVICE
.WINSHUT
)
94 gl
.qdevice(DEVICE
.WINQUIT
)
95 gl
.qdevice(DEVICE
.WINFREEZE
)
96 gl
.qdevice(DEVICE
.WINTHAW
)
97 width
, height
= gl
.getsize()
99 lvo
= LiveVideoOut
.LiveVideoOut(wid
, width
, height
, vtype
)
101 lvi
= LiveVideoIn
.LiveVideoIn(pktmax
, width
, height
, vtype
)
103 s
= socket(AF_INET
, SOCK_DGRAM
)
104 s
.setsockopt(SOL_SOCKET
, SO_BROADCAST
, 1)
106 s
.setsockopt(IPPROTO_IP
, IP_MULTICAST_TTL
, chr(ttl
))
113 dev
, val
= gl
.qread()
114 if dev
in (DEVICE
.ESCKEY
, \
115 DEVICE
.WINSHUT
, DEVICE
.WINQUIT
):
117 if dev
== DEVICE
.WINFREEZE
:
119 if dev
== DEVICE
.WINTHAW
:
121 if dev
== DEVICE
.REDRAW
:
123 x
, y
= gl
.getorigin()
124 if (w
, h
) <> (width
, height
):
126 lvi
.resizevideo(width
, height
)
127 lvo
.resizevideo(width
, height
)
129 rv
= lvi
.getnextpacket()
137 lvo
.putnextpacket(pos
, data
)
139 hdr
= struct
.pack('hhh', pos
, width
, height
)
142 s
.sendto(hdr
+ data
, (host
, port
))
143 except error
, msg
: # really socket.error
144 if msg
[0] <> 121: # no buffer space available
145 raise error
, msg
# re-raise it
146 print 'Warning:', msg
[1]