]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added multicast to Vsend and Vreceive. Updated README. Rediced queue
authorGuido van Rossum <guido@python.org>
Thu, 24 Sep 1992 12:54:35 +0000 (12:54 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 24 Sep 1992 12:54:35 +0000 (12:54 +0000)
size to 1 in LiveVideoIn.

Demo/sgi/video/LiveVideoIn.py
Demo/sgi/video/README
Demo/sgi/video/Vreceive.py
Demo/sgi/video/Vsend.py

index 65e531774c609990378a810e8b8a9a97d79ebc2d..920123d468254cf2fecfd27ea31aadf9c914b80b 100755 (executable)
@@ -54,7 +54,7 @@ class LiveVideoIn:
                # Initialize capture
                v.SetSize(self.realwidth, self.realheight)
                dummy = v.InitContinuousCapture(SV.RGB8_FRAMES, \
-                         self.realwidth, self.realheight, 2, 5)
+                         self.realwidth, self.realheight, 1, 5)
                self.data = None
                self.lpos = 0
                return self
index 335a108368cfcbcd1bba64599b8646a10eb550ae..5e14cff50aadf31fd95fe4160fdc4fd6e8f1692a 100644 (file)
@@ -57,6 +57,10 @@ Vtime.py     (unrelated to vtime!!!) Copy a video file,
 
 Vedit.py       interactive video editing program
 
+Vsend.py       unicast or multicast live video as UDP packets
+
+Vreceive.py    receive transmissions from Vsend
+
 
 These modules are used by the above programs:
 
@@ -64,6 +68,10 @@ VFile.py     classes that read and write CMIF video files
 
 Viewer.py      two viewer classes used by Vedit
 
+LiveVideoIn.py live video input class, used by Vsend
+
+LiveVideoOut.py        live video output class, used by Vsend and Vreceive
+
 
 The following are C programs, either for efficiency or because they
 need to link with a C library:
index 8d7150e9ee428f875e9929de3292b20adeea27fe..415df593180a58e6c160c9a16358353bb8584934 100755 (executable)
@@ -5,17 +5,22 @@
 
 import sys
 import struct
-from socket import *
+from socket import *                   # syscalls and support functions
+from SOCKET import *                   # <sys/socket.h>
+from IN import *                       # <netinet/in.h>
 import select
+import struct
 import gl, GL, DEVICE
 sys.path.append('/ufs/guido/src/video')
 import LiveVideoOut
+import regsub
+
+MYGROUP = '225.0.0.250'
+PORT = 5555
 
 PKTMAX = 16*1024
 WIDTH = 400
 HEIGHT = 300
-HOST = ''
-PORT = 5555
 
 def main():
 
@@ -23,6 +28,8 @@ def main():
        if sys.argv[1:]:
                port = eval(sys.argv[1])
 
+       s = opensocket(MYGROUP, port)
+
        width, height = WIDTH, HEIGHT
 
        gl.foreground()
@@ -36,9 +43,6 @@ def main():
        lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
                width, height)
 
-       s = socket(AF_INET, SOCK_DGRAM)
-       s.bind(HOST, port)
-
        ifdlist = [gl.qgetfd(), s.fileno()]
        ofdlist = []
        xfdlist = []
@@ -71,4 +75,35 @@ def main():
 
        lvo.close()
 
+
+# Subroutine to create and properly initialize the receiving socket
+
+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)
+
+       # Look up the group once
+       group = gethostbyname(group)
+
+       # Ugly: construct binary group address
+       group_bytes = eval(regsub.gsub('\.', ',', group))
+       grpaddr = 0
+       for byte in group_bytes: grpaddr = (grpaddr << 8) | byte
+
+       # Construct struct mreq from grpaddr and ifaddr
+       ifaddr = INADDR_ANY
+       mreq = struct.pack('ll', grpaddr, ifaddr)
+
+       # Add group membership
+       s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
+
+       return s
+
 main()
index 32385f0f9c1f395f9d7a5c5e598c2dab4a0cc7a1..f38e965c27dcdd999da1e76be5830a893b43dbf8 100755 (executable)
@@ -7,16 +7,18 @@ import sys
 import time
 import struct
 from socket import *
+from SOCKET import *
 import gl, GL, DEVICE
 sys.path.append('/ufs/guido/src/video')
 import LiveVideoIn
 import LiveVideoOut
+import SV
 
 PKTMAX_UCAST = 16*1024 - 6
 PKTMAX_BCAST = 1450
 WIDTH = 400
 HEIGHT = 300
-HOST = '<broadcast>'
+HOST = '225.0.0.250' # Multicast address!
 PORT = 5555
 
 def main():
@@ -28,6 +30,8 @@ def main():
        port = PORT
        if sys.argv[1:]:
                host = sys.argv[1]
+               if host == '-b':
+                       host = '<broadcast>'
                if sys.argv[2:]:
                        port = eval(sys.argv[2])
 
@@ -41,10 +45,13 @@ def main():
        wid = gl.winopen('Vsend')
        gl.keepaspect(WIDTH, HEIGHT)
        gl.stepunit(8, 6)
+       gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX)
        gl.winconstraints()
        gl.qdevice(DEVICE.ESCKEY)
        gl.qdevice(DEVICE.WINSHUT)
        gl.qdevice(DEVICE.WINQUIT)
+       gl.qdevice(DEVICE.WINFREEZE)
+       gl.qdevice(DEVICE.WINTHAW)
        width, height = gl.getsize()
 
        x, y = gl.getorigin()
@@ -54,7 +61,9 @@ def main():
        lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height)
 
        s = socket(AF_INET, SOCK_DGRAM)
-       s.allowbroadcast(1)
+       s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
+
+       frozen = 0
 
        while 1:
 
@@ -63,6 +72,10 @@ def main():
                        if dev in (DEVICE.ESCKEY, \
                                DEVICE.WINSHUT, DEVICE.WINQUIT):
                                break
+                       if dev == DEVICE.WINFREEZE:
+                               frozen = 1
+                       if dev == DEVICE.WINTHAW:
+                               frozen = 0
                        if dev == DEVICE.REDRAW:
                                w, h = gl.getsize()
                                x, y = gl.getorigin()
@@ -83,7 +96,9 @@ def main():
                        continue
 
                pos, data = rv
-               lvo.putnextpacket(pos, data)
+
+               if not frozen:
+                       lvo.putnextpacket(pos, data)
 
                hdr = struct.pack('hhh', pos, width, height)
                s.sendto(hdr + data, (host, port))