mirror of https://github.com/python/cpython
Added multicast to Vsend and Vreceive. Updated README. Rediced queue
size to 1 in LiveVideoIn.
This commit is contained in:
parent
46927bac96
commit
67b4895291
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue