Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Demo / sgi / sv / contcapt.py
blob6c0a0003bb4efbf27047f8e2d25630a19d22c724
1 import sys
2 import sv, SV
3 import gl, GL, DEVICE
5 def main():
6 format = SV.RGB8_FRAMES
7 framerate = 25
8 queuesize = 16
9 samplingrate = 2
11 v = sv.OpenVideo()
12 # Determine maximum window size based on signal standard
13 param = [SV.BROADCAST, 0]
14 v.GetParam(param)
15 if param[1] == SV.PAL:
16 width = SV.PAL_XMAX
17 height = SV.PAL_YMAX
18 framefreq = 25
19 else:
20 width = SV.NTSC_XMAX
21 height = SV.NTSC_YMAX
22 framefreq = 30
24 # Allow resizing window if capturing RGB frames, which can be scaled
25 if format == SV.RGB8_FRAMES:
26 gl.keepaspect(width, height)
27 gl.maxsize(width, height)
28 gl.stepunit(8, 6)
29 gl.minsize(120, 90)
30 else:
31 if format == SV.YUV411_FRAMES_AND_BLANKING_BUFFER:
32 height = height + SV.BLANKING_BUFFER_SIZE
33 gl.prefposition(300, 300+width-1, 100, 100+height-1)
35 # Open the window
36 gl.foreground()
37 win = gl.winopen('Continuous Capture')
38 gl.RGBmode()
39 gl.gconfig()
40 if format == SV.RGB8_FRAMES:
41 width, height = gl.getsize()
42 gl.pixmode(GL.PM_SIZE, 8)
43 else:
44 gl.pixmode(GL.PM_SIZE, 32)
46 svci = (format, width, height, queuesize, samplingrate)
47 [svci]
49 svci = v.InitContinuousCapture(svci)
50 width, height = svci[1:3]
51 [svci]
53 hz = gl.getgdesc(GL.GD_TIMERHZ)
54 gl.noise(DEVICE.TIMER0, hz / framerate)
55 gl.qdevice(DEVICE.TIMER0)
56 gl.qdevice(DEVICE.WINQUIT)
57 gl.qdevice(DEVICE.WINSHUT)
58 gl.qdevice(DEVICE.ESCKEY)
60 ndisplayed = 0
61 lastfieldID = 0
63 while 1:
64 dev, val = gl.qread()
65 if dev == DEVICE.REDRAW:
66 oldw = width
67 oldh = height
68 width, height = gl.getsize()
69 if oldw != width or oldh != height:
70 v.EndContinuousCapture()
71 gl.viewport(0, width-1, 0, height-1)
72 svci = (svci[0], width, height) + svci[3:]
73 svci = v.InitContinuousCapture(svci)
74 width, height = svci[1:3]
75 [svci]
76 if ndisplayed:
77 print 'lost',
78 print fieldID/(svci[4]*2) - ndisplayed,
79 print 'frames'
80 ndisplayed = 0
81 elif dev == DEVICE.TIMER0:
82 try:
83 captureData, fieldID = v.GetCaptureData()
84 except sv.error, val:
85 if val <> 'no data available':
86 print val
87 continue
88 if fieldID - lastfieldID <> 2*samplingrate:
89 print lastfieldID, fieldID
90 lastfieldID = fieldID
91 if svci[0] == SV.RGB8_FRAMES:
92 rgbbuf = captureData.InterleaveFields(1)
93 else:
94 rgbbuf = captureData.YUVtoRGB(1)
95 captureData.UnlockCaptureData()
96 gl.lrectwrite(0, 0, width-1, height-1, rgbbuf)
97 ndisplayed = ndisplayed + 1
98 elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
99 v.EndContinuousCapture()
100 v.CloseVideo()
101 gl.winclose(win)
102 print fieldID, ndisplayed, svci[4]
103 print 'lost', fieldID/(svci[4]*2) - ndisplayed,
104 print 'frames'
105 return
107 main()