summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-24 16:03:56 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-24 16:03:56 (GMT)
commitcfb6bb2a3036b366aff6add44dce23a6db5b8f50 (patch)
tree4efa72f7ca2cb588f0f06514530bfad014528007 /Demo
parent691e59bcb7919218bb797ed318580d719eaeef92 (diff)
downloadcpython-cfb6bb2a3036b366aff6add44dce23a6db5b8f50.zip
cpython-cfb6bb2a3036b366aff6add44dce23a6db5b8f50.tar.gz
cpython-cfb6bb2a3036b366aff6add44dce23a6db5b8f50.tar.bz2
Changed the init() interface of LiveVideoOut to read out the window
size automatically -- the video is always centered. Added resizevideo() and reshapewindow() interfaces. Documented all methods. Changed Vsend/Vreceive to use the new interface. Allow window resizing by the user in Vreceive.
Diffstat (limited to 'Demo')
-rwxr-xr-xDemo/sgi/video/LiveVideoOut.py50
-rwxr-xr-xDemo/sgi/video/Vreceive.py28
-rwxr-xr-xDemo/sgi/video/Vsend.py10
3 files changed, 49 insertions, 39 deletions
diff --git a/Demo/sgi/video/LiveVideoOut.py b/Demo/sgi/video/LiveVideoOut.py
index 150e8a0..033d925 100755
--- a/Demo/sgi/video/LiveVideoOut.py
+++ b/Demo/sgi/video/LiveVideoOut.py
@@ -8,7 +8,11 @@ from VFile import Displayer
class LiveVideoOut:
- def init(self, wid, xywh, vw, vh):
+ # Call this to initialize things. Arguments:
+ # wid: the window id where the video is to be displayed (centered)
+ # vw, vh: size of the video image to be displayed
+
+ def init(self, wid, vw, vh):
##print 'Init', wid, xywh
##print 'video', vw, vw
self.vw = vw
@@ -20,38 +24,48 @@ class LiveVideoOut:
oldwid = gl.winget()
gl.winset(wid)
self.disp.initcolormap()
- self.resize(xywh)
+ self.reshapewindow()
gl.winset(oldwid)
return self
- def resize(self, (x, y, w, h)):
+ # Call this in response to every REDRAW event for the window
+ # or if the window size has changed for other reasons.
+
+ def reshapewindow(self):
oldwid = gl.winget()
gl.winset(self.wid)
- ##print 'Resize', x, y, w, h
- gl.winposition(x, x+w-1, y, y+h-1)
gl.reshapeviewport()
- if w < self.vw or h < self.vh:
- self.toosmall = 1
- else:
- self.disp.xorigin = (w-self.vw)/2
- self.disp.yorigin = (h-self.vh)/2
- self.toosmall = 0
- ##print 'VIDEO OFFSET:', \
- ## self.disp.xorigin, self.disp.yorigin
+ w, h = gl.getsize()
+ self.disp.xorigin = (w-self.vw)/2
+ self.disp.yorigin = (h-self.vh)/2
self.disp.clear()
gl.winset(oldwid)
+ # Call this to change the size of the video images being displayed.
+ # Implies reshapewindow().
+
+ def resizevideo(self, vw, vh):
+ self.vw, self.vh = vw, vh
+ self.disp.setsize(vw, vh)
+ self.reshapewindow()
+
+ # Call this to display the next video packet. Arguments:
+ # pos: line number where the packet begins
+ # data: image data of the packet
+ # (these correspond directly to the return values from
+ # LiveVideoIn.getnextpacket()).
+
def putnextpacket(self, pos, data):
- if self.toosmall:
+ nline = len(data)/self.vw
+ if nline*self.vw <> len(data):
+ print 'Incorrect-sized video fragment ignored'
return
oldwid = gl.winget()
gl.winset(self.wid)
- nline = len(data)/self.vw
- if nline*self.vw <> len(data):
- print 'Incorrect-sized video fragment'
self.disp.showpartframe(data, None, (0, pos, self.vw, nline))
gl.winset(oldwid)
+ # Call this to close the window.
+
def close(self):
- ##print 'Done video out'
pass
diff --git a/Demo/sgi/video/Vreceive.py b/Demo/sgi/video/Vreceive.py
index 334fe66..17a803f 100755
--- a/Demo/sgi/video/Vreceive.py
+++ b/Demo/sgi/video/Vreceive.py
@@ -19,6 +19,8 @@ import getopt
from senddefs import *
+# Print usage message and exit(2).
+
def usage(msg):
print msg
print 'usage: Vreceive [-m mcastgrp] [-p port]'
@@ -27,6 +29,8 @@ def usage(msg):
sys.exit(2)
+# Main program: parse options and main loop.
+
def main():
sys.stdout = sys.stderr
@@ -55,13 +59,12 @@ def main():
gl.foreground()
gl.prefsize(width, height)
wid = gl.winopen('Vreceive')
+ gl.winconstraints()
gl.qdevice(DEVICE.ESCKEY)
gl.qdevice(DEVICE.WINSHUT)
gl.qdevice(DEVICE.WINQUIT)
- x, y = gl.getorigin()
- lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
- width, height)
+ lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height)
ifdlist = [gl.qgetfd(), s.fileno()]
ofdlist = []
@@ -77,18 +80,16 @@ def main():
DEVICE.WINSHUT, DEVICE.WINQUIT):
break
if dev == DEVICE.REDRAW:
- gl.clear()
+ lvo.reshapewindow()
elif s.avail():
data = s.recv(16*1024)
pos, w, h = struct.unpack('hhh', data[:6])
if (w, h) <> (width, height):
- x, y = gl.getorigin()
+ x, y = gl.getorigin()
y = y + height - h
+ gl.winposition(x, x+w-1, y, y+h-1)
width, height = w, h
- lvo.close()
- lvo = LiveVideoOut.LiveVideoOut() \
- .init(wid, (x, y, width, height), \
- width, height)
+ lvo.resizevideo(width, height)
lvo.putnextpacket(pos, data[6:])
else:
x = select.select(selectargs)
@@ -103,16 +104,16 @@ def opensocket(group, port):
# Create the socket
s = socket(AF_INET, SOCK_DGRAM)
- # Bind the port to it
- s.bind('', port)
-
# Allow multiple copies of this program on one machine
s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) # (Not strictly needed)
+ # Bind the port to it
+ s.bind('', port)
+
# Look up the group once
group = gethostbyname(group)
- # Ugly: construct binary group address
+ # Construct binary group address
group_bytes = eval(regsub.gsub('\.', ',', group))
grpaddr = 0
for byte in group_bytes: grpaddr = (grpaddr << 8) | byte
@@ -126,4 +127,5 @@ def opensocket(group, port):
return s
+
main()
diff --git a/Demo/sgi/video/Vsend.py b/Demo/sgi/video/Vsend.py
index e5154c0..543cd86 100755
--- a/Demo/sgi/video/Vsend.py
+++ b/Demo/sgi/video/Vsend.py
@@ -92,9 +92,7 @@ def main():
gl.qdevice(DEVICE.WINTHAW)
width, height = gl.getsize()
- x, y = gl.getorigin()
- lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
- width, height)
+ lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height)
lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height)
@@ -124,11 +122,7 @@ def main():
width, height = w, h
lvi = LiveVideoIn.LiveVideoIn() \
.init(pktmax, width, height)
- lvo.close()
- lvo = LiveVideoOut.LiveVideoOut() \
- .init(wid, \
- (x, y, width, height), \
- width, height)
+ lvo.resizevideo(width, height)
rv = lvi.getnextpacket()
if not rv: