blob: 033d925dcf8ae4f6716eb269c118fe6bbaca380b [file] [log] [blame]
Guido van Rossumba066151992-09-22 17:23:17 +00001# Live video output (display video on the screen, presumably from the net)
2
3import gl
4from VFile import Displayer
5
6
7# Video output (displayer) class.
8
9class LiveVideoOut:
10
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000011 # Call this to initialize things. Arguments:
12 # wid: the window id where the video is to be displayed (centered)
13 # vw, vh: size of the video image to be displayed
14
15 def init(self, wid, vw, vh):
Guido van Rossumba066151992-09-22 17:23:17 +000016 ##print 'Init', wid, xywh
17 ##print 'video', vw, vw
18 self.vw = vw
19 self.vh = vh
20 self.disp = Displayer().init()
21 info = ('rgb8', vw, vh, 1, 8, 0, 0, 0, 0)
22 self.disp.setinfo(info)
23 self.wid = wid
24 oldwid = gl.winget()
25 gl.winset(wid)
26 self.disp.initcolormap()
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000027 self.reshapewindow()
Guido van Rossumba066151992-09-22 17:23:17 +000028 gl.winset(oldwid)
29 return self
30
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000031 # Call this in response to every REDRAW event for the window
32 # or if the window size has changed for other reasons.
33
34 def reshapewindow(self):
Guido van Rossumba066151992-09-22 17:23:17 +000035 oldwid = gl.winget()
36 gl.winset(self.wid)
Guido van Rossumba066151992-09-22 17:23:17 +000037 gl.reshapeviewport()
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000038 w, h = gl.getsize()
39 self.disp.xorigin = (w-self.vw)/2
40 self.disp.yorigin = (h-self.vh)/2
Guido van Rossumba066151992-09-22 17:23:17 +000041 self.disp.clear()
42 gl.winset(oldwid)
43
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000044 # Call this to change the size of the video images being displayed.
45 # Implies reshapewindow().
46
47 def resizevideo(self, vw, vh):
48 self.vw, self.vh = vw, vh
49 self.disp.setsize(vw, vh)
50 self.reshapewindow()
51
52 # Call this to display the next video packet. Arguments:
53 # pos: line number where the packet begins
54 # data: image data of the packet
55 # (these correspond directly to the return values from
56 # LiveVideoIn.getnextpacket()).
57
Guido van Rossumba066151992-09-22 17:23:17 +000058 def putnextpacket(self, pos, data):
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000059 nline = len(data)/self.vw
60 if nline*self.vw <> len(data):
61 print 'Incorrect-sized video fragment ignored'
Guido van Rossumba066151992-09-22 17:23:17 +000062 return
63 oldwid = gl.winget()
64 gl.winset(self.wid)
Guido van Rossumba066151992-09-22 17:23:17 +000065 self.disp.showpartframe(data, None, (0, pos, self.vw, nline))
66 gl.winset(oldwid)
67
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000068 # Call this to close the window.
69
Guido van Rossumba066151992-09-22 17:23:17 +000070 def close(self):
Guido van Rossum7b47c791992-09-24 15:01:37 +000071 pass