blob: fa8966f8b3b0e93ecf89cca8a4eabc5e34d14f6d [file] [log] [blame]
Guido van Rossume4bddea1991-10-30 11:52:48 +00001import sys
2from socket import *
3from gl import *
4from GL import *
5from DEVICE import *
6from time import millitimer
7
8HS = 40 # Header size (must be same as in tv.py)
9
10# Rely on UDP packet (de)fragmentation for smoother images
11# (Changed for broadcast)
12MAX = 16000
13
14PF = 2 # Default packfactor
15
16# Default receiver station is voorn.
17# Kwik has no yellow pages, so...
18HOST = '192.16.201.121'
19PORT = 5555
20
21if sys.argv[1:]:
22 PF = eval(sys.argv[1])
23
24if sys.argv[2:]:
25 HOST = sys.argv[2]
Guido van Rossumf47d0481992-02-11 14:50:22 +000026 if HOST == 'all':
Guido van Rossume4bddea1991-10-30 11:52:48 +000027 HOST = '<broadcast>'
28 MAX = 1400
29
30PF2 = PF*PF
31
32def main():
33 centerx, centery = 400, 300
34
35 foreground()
36 wid = winopen('cam')
37 RGBmode()
38 doublebuffer()
39 gconfig()
40 qdevice(ESCKEY)
41
42 w, h = getsize()
43 ortho2(0, w, 0, h)
44 w = w/PF*PF
45 h = h/PF*PF
46
47 readsource(SRC_FRAMEGRABBER)
48
49 s = socket(AF_INET, SOCK_DGRAM)
Guido van Rossumf47d0481992-02-11 14:50:22 +000050 if HOST == '<broadcast>':
Guido van Rossume4bddea1991-10-30 11:52:48 +000051 s.allowbroadcast(1)
52 addr = HOST, PORT
53
54 bytesperline = w/PF2
55 linesperchunk = MAX/bytesperline
56 linesperchunk = linesperchunk/PF*PF
57 nchunks = (h+linesperchunk-1)/linesperchunk
58
59 print 'MAX=', MAX,
60 print 'linesperchunk=', linesperchunk,
61 print 'nchunks=', nchunks,
62 print 'w=', w, 'h=', h
63
64 x1, x2 = 0, w-1
65
66 t1 = millitimer()
67 nframes = 0
68 fps = 0
69
70 msg = ''
71
72 while 1:
73 while qtest():
74 dev, val = qread()
Guido van Rossumf47d0481992-02-11 14:50:22 +000075 if dev == REDRAW:
Guido van Rossume4bddea1991-10-30 11:52:48 +000076 reshapeviewport()
77 w, h = getsize()
78 ortho2(0, w, 0, h)
79 w = w/PF*PF
80 h = h/PF*PF
81
82 bytesperline = w/PF2
83 linesperchunk = MAX/bytesperline
84 linesperchunk = linesperchunk/PF*PF
85 nchunks = (h+linesperchunk-1)/linesperchunk
86
87 print 'MAX=', MAX,
88 print 'linesperchunk=', linesperchunk,
89 print 'nchunks=', nchunks,
90 print 'w=', w, 'h=', h
91
92 x1, x2 = 0, w-1
93
94 fps = 0
95
Guido van Rossumf47d0481992-02-11 14:50:22 +000096 elif dev == ESCKEY:
Guido van Rossume4bddea1991-10-30 11:52:48 +000097 winclose(wid)
98 return
99
100 readsource(SRC_FRAMEGRABBER)
101
102 nframes = nframes+1
103 if nframes >= fps:
104 t2 = millitimer()
105 if t2 <> t1:
106 fps = int(10000.0*nframes/(t2-t1)) * 0.1
107 msg = `fps` + ' frames/sec'
108 t1 = t2
109 nframes = 0
110
111 RGBcolor(255,255,255)
112 cmov2i(9,9)
113 charstr(msg)
114
115 swapbuffers()
116 rectcopy(centerx-w/2, centery-w/2, centerx+w/2, centery+w/2, 0, 0)
117
118 for i in range(nchunks):
119 y1 = i*linesperchunk
120 y2 = y1 + linesperchunk-1
121 if y2 >= h: y2 = h-1
122 data = lrectread(x1, y1, x2, y2)
123 data2 = packrect(x2-x1+1, y2-y1+1, PF, data)
124 prefix = `w, h, PF, x1, y1, x2, y2`
125 prefix = prefix + ' ' * (HS-len(prefix))
126 data3 = prefix + data2
127 s.sendto(data3, addr)
128
129main()