blob: 32385f0f9c1f395f9d7a5c5e598c2dab4a0cc7a1 [file] [log] [blame]
Guido van Rossumba066151992-09-22 17:23:17 +00001#!/ufs/guido/bin/sgi/python-405
2
3# Send live video UDP packets.
4# Usage: Vsend [host [port]]
5
6import sys
7import time
8import struct
9from socket import *
10import gl, GL, DEVICE
11sys.path.append('/ufs/guido/src/video')
12import LiveVideoIn
13import LiveVideoOut
14
15PKTMAX_UCAST = 16*1024 - 6
16PKTMAX_BCAST = 1450
17WIDTH = 400
18HEIGHT = 300
19HOST = '<broadcast>'
20PORT = 5555
21
22def main():
23 if not LiveVideoIn.have_video:
24 print 'Sorry, no video (use python-405 on roos)'
25 sys.exit(1)
26
27 host = HOST
28 port = PORT
29 if sys.argv[1:]:
30 host = sys.argv[1]
31 if sys.argv[2:]:
32 port = eval(sys.argv[2])
33
34 if host == '<broadcast>':
35 pktmax = PKTMAX_BCAST
36 else:
37 pktmax = PKTMAX_UCAST
38
39 gl.foreground()
40 gl.prefsize(WIDTH, HEIGHT)
41 wid = gl.winopen('Vsend')
42 gl.keepaspect(WIDTH, HEIGHT)
43 gl.stepunit(8, 6)
44 gl.winconstraints()
45 gl.qdevice(DEVICE.ESCKEY)
46 gl.qdevice(DEVICE.WINSHUT)
47 gl.qdevice(DEVICE.WINQUIT)
48 width, height = gl.getsize()
49
50 x, y = gl.getorigin()
51 lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
52 width, height)
53
54 lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height)
55
56 s = socket(AF_INET, SOCK_DGRAM)
57 s.allowbroadcast(1)
58
59 while 1:
60
61 if gl.qtest():
62 dev, val = gl.qread()
63 if dev in (DEVICE.ESCKEY, \
64 DEVICE.WINSHUT, DEVICE.WINQUIT):
65 break
66 if dev == DEVICE.REDRAW:
67 w, h = gl.getsize()
68 x, y = gl.getorigin()
69 if (w, h) <> (width, height):
70 lvi.close()
71 width, height = w, h
72 lvi = LiveVideoIn.LiveVideoIn() \
73 .init(pktmax, width, height)
74 lvo.close()
75 lvo = LiveVideoOut.LiveVideoOut() \
76 .init(wid, \
77 (x, y, width, height), \
78 width, height)
79
80 rv = lvi.getnextpacket()
81 if not rv:
82 time.millisleep(10)
83 continue
84
85 pos, data = rv
86 lvo.putnextpacket(pos, data)
87
88 hdr = struct.pack('hhh', pos, width, height)
89 s.sendto(hdr + data, (host, port))
90
91 lvi.close()
92 lvo.close()
93
94main()