1 # Live video output (display video on the screen, presumably from the net)
4 from VFile
import Displayer
7 # Video output (displayer) class.
11 # 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
15 def __init__(self
, wid
, vw
, vh
, type):
16 ##print 'Init', wid, xywh
17 ##print 'video', vw, vw
20 self
.disp
= Displayer()
21 if not type in ('rgb', 'rgb8', 'grey', 'mono', 'grey2', \
23 raise 'Incorrent live video output type', type
25 info
= (type, vw
, vh
, 0, 32, 0, 0, 0, 0)
27 info
= (type, vw
, vh
, 1, 8, 0, 0, 0, 0)
28 self
.disp
.setinfo(info
)
32 self
.disp
.initcolormap()
36 # Call this in response to every REDRAW event for the window
37 # or if the window size has changed for other reasons.
39 def reshapewindow(self
):
44 self
.disp
.xorigin
= (w
-self
.vw
)/2
45 self
.disp
.yorigin
= (h
-self
.vh
)/2
49 # Call this to change the size of the video images being displayed.
50 # Implies reshapewindow().
52 def resizevideo(self
, vw
, vh
):
53 self
.vw
, self
.vh
= vw
, vh
54 self
.disp
.setsize(vw
, vh
)
57 # Return the number of bytes in one video line
59 if self
.disp
.format
== 'rgb':
61 if self
.disp
.format
== 'mono':
63 elif self
.disp
.format
== 'grey2':
65 elif self
.disp
.format
== 'grey4':
70 # Call this to display the next video packet. Arguments:
71 # pos: line number where the packet begins
72 # data: image data of the packet
73 # (these correspond directly to the return values from
74 # LiveVideoIn.getnextpacket()).
76 def putnextpacket(self
, pos
, data
):
77 nline
= len(data
)/self
.linewidth()
78 if nline
*self
.linewidth() <> len(data
):
79 print 'Incorrect-sized video fragment ignored'
83 self
.disp
.showpartframe(data
, None, (0, pos
, self
.vw
, nline
))
86 # Call this to close the window.
91 # Call this to set optional mirroring of video
92 def setmirror(self
, mirrored
):
93 f
, w
, h
, pf
, c0
, c1
, c2
, o
, cp
= self
.disp
.getinfo()
94 if type(pf
) == type(()):
101 info
= (f
, w
, h
, (xpf
, ypf
), c0
, c1
, c2
, o
, cp
)
102 self
.disp
.setinfo(info
)
103 self
.disp
.initcolormap()
107 # This derived class has one difference with the base class: the video is
108 # not displayed until an entire image has been gotten
110 class LiveVideoOutSlow(LiveVideoOut
):
112 # Reshapewindow - Realloc buffer.
113 # (is also called by __init__() indirectly)
115 def reshapewindow(self
):
116 LiveVideoOut
.reshapewindow(self
)
117 self
.buffer = '\0'*self
.linewidth()*self
.vh
120 # putnextpacket - buffer incoming data until a complete
121 # image has been received
123 def putnextpacket(self
, pos
, data
):
124 if pos
in self
.isbuffered
or pos
== 0:
125 LiveVideoOut
.putnextpacket(self
, 0, self
.buffer)
127 self
.isbuffered
.append(pos
)
128 bpos
= pos
* self
.linewidth()
129 epos
= bpos
+ len(data
)
130 self
.buffer = self
.buffer[:bpos
] + data
+ self
.buffer[epos
:]