]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Changed the init() interface of LiveVideoOut to read out the window
authorGuido van Rossum <guido@python.org>
Thu, 24 Sep 1992 16:03:56 +0000 (16:03 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 24 Sep 1992 16:03:56 +0000 (16:03 +0000)
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.

Demo/sgi/video/LiveVideoOut.py
Demo/sgi/video/Vreceive.py
Demo/sgi/video/Vsend.py

index 150e8a059cd2e0243073738ee04a1e97c5355b73..033d925dcf8ae4f6716eb269c118fe6bbaca380b 100755 (executable)
@@ -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
index 334fe666fb7a6a4ea9a39d18c716ff7ec4bba97a..17a803f7d42800876bd9e4753f1c2bba729ba180 100755 (executable)
@@ -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()
index e5154c04b2e91a95311f21b76989a52acdd7f4ba..543cd8677c57ccc20b693ca2b67806b1364812d6 100755 (executable)
@@ -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: