blob: 8d7150e9ee428f875e9929de3292b20adeea27fe [file] [log] [blame]
Guido van Rossumba066151992-09-22 17:23:17 +00001#!/ufs/guido/bin/sgi/python-405
2
3# Receive live video UDP packets.
4# Usage: Vreceive [port]
5
6import sys
7import struct
8from socket import *
9import select
10import gl, GL, DEVICE
11sys.path.append('/ufs/guido/src/video')
12import LiveVideoOut
13
14PKTMAX = 16*1024
15WIDTH = 400
16HEIGHT = 300
17HOST = ''
18PORT = 5555
19
20def main():
21
22 port = PORT
23 if sys.argv[1:]:
24 port = eval(sys.argv[1])
25
26 width, height = WIDTH, HEIGHT
27
28 gl.foreground()
29 gl.prefsize(width, height)
30 wid = gl.winopen('Vreceive')
31 gl.qdevice(DEVICE.ESCKEY)
32 gl.qdevice(DEVICE.WINSHUT)
33 gl.qdevice(DEVICE.WINQUIT)
34
35 x, y = gl.getorigin()
36 lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
37 width, height)
38
39 s = socket(AF_INET, SOCK_DGRAM)
40 s.bind(HOST, port)
41
42 ifdlist = [gl.qgetfd(), s.fileno()]
43 ofdlist = []
44 xfdlist = []
45 timeout = 1.0
46 selectargs = (ifdlist, ofdlist, xfdlist, timeout)
47
48 while 1:
49
50 if gl.qtest():
51 dev, val = gl.qread()
52 if dev in (DEVICE.ESCKEY, \
53 DEVICE.WINSHUT, DEVICE.WINQUIT):
54 break
55 if dev == DEVICE.REDRAW:
56 gl.clear()
57 elif s.avail():
58 data = s.recv(16*1024)
59 pos, w, h = struct.unpack('hhh', data[:6])
60 if (w, h) <> (width, height):
61 x, y = gl.getorigin()
62 y = y + height - h
63 width, height = w, h
64 lvo.close()
65 lvo = LiveVideoOut.LiveVideoOut() \
66 .init(wid, (x, y, width, height), \
67 width, height)
68 lvo.putnextpacket(pos, data[6:])
69 else:
70 x = select.select(selectargs)
71
72 lvo.close()
73
74main()