Commit cfb6bb2a authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 691e59bc
...@@ -8,7 +8,11 @@ from VFile import Displayer ...@@ -8,7 +8,11 @@ from VFile import Displayer
class LiveVideoOut: 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 'Init', wid, xywh
##print 'video', vw, vw ##print 'video', vw, vw
self.vw = vw self.vw = vw
...@@ -20,38 +24,48 @@ class LiveVideoOut: ...@@ -20,38 +24,48 @@ class LiveVideoOut:
oldwid = gl.winget() oldwid = gl.winget()
gl.winset(wid) gl.winset(wid)
self.disp.initcolormap() self.disp.initcolormap()
self.resize(xywh) self.reshapewindow()
gl.winset(oldwid) gl.winset(oldwid)
return self 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() oldwid = gl.winget()
gl.winset(self.wid) gl.winset(self.wid)
##print 'Resize', x, y, w, h
gl.winposition(x, x+w-1, y, y+h-1)
gl.reshapeviewport() gl.reshapeviewport()
if w < self.vw or h < self.vh: w, h = gl.getsize()
self.toosmall = 1 self.disp.xorigin = (w-self.vw)/2
else: self.disp.yorigin = (h-self.vh)/2
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
self.disp.clear() self.disp.clear()
gl.winset(oldwid) 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): 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 return
oldwid = gl.winget() oldwid = gl.winget()
gl.winset(self.wid) 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)) self.disp.showpartframe(data, None, (0, pos, self.vw, nline))
gl.winset(oldwid) gl.winset(oldwid)
# Call this to close the window.
def close(self): def close(self):
##print 'Done video out'
pass pass
...@@ -19,6 +19,8 @@ import getopt ...@@ -19,6 +19,8 @@ import getopt
from senddefs import * from senddefs import *
# Print usage message and exit(2).
def usage(msg): def usage(msg):
print msg print msg
print 'usage: Vreceive [-m mcastgrp] [-p port]' print 'usage: Vreceive [-m mcastgrp] [-p port]'
...@@ -27,6 +29,8 @@ def usage(msg): ...@@ -27,6 +29,8 @@ def usage(msg):
sys.exit(2) sys.exit(2)
# Main program: parse options and main loop.
def main(): def main():
sys.stdout = sys.stderr sys.stdout = sys.stderr
...@@ -55,13 +59,12 @@ def main(): ...@@ -55,13 +59,12 @@ def main():
gl.foreground() gl.foreground()
gl.prefsize(width, height) gl.prefsize(width, height)
wid = gl.winopen('Vreceive') wid = gl.winopen('Vreceive')
gl.winconstraints()
gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.ESCKEY)
gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.WINSHUT)
gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINQUIT)
x, y = gl.getorigin() lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height)
lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
width, height)
ifdlist = [gl.qgetfd(), s.fileno()] ifdlist = [gl.qgetfd(), s.fileno()]
ofdlist = [] ofdlist = []
...@@ -77,18 +80,16 @@ def main(): ...@@ -77,18 +80,16 @@ def main():
DEVICE.WINSHUT, DEVICE.WINQUIT): DEVICE.WINSHUT, DEVICE.WINQUIT):
break break
if dev == DEVICE.REDRAW: if dev == DEVICE.REDRAW:
gl.clear() lvo.reshapewindow()
elif s.avail(): elif s.avail():
data = s.recv(16*1024) data = s.recv(16*1024)
pos, w, h = struct.unpack('hhh', data[:6]) pos, w, h = struct.unpack('hhh', data[:6])
if (w, h) <> (width, height): if (w, h) <> (width, height):
x, y = gl.getorigin() x, y = gl.getorigin()
y = y + height - h y = y + height - h
gl.winposition(x, x+w-1, y, y+h-1)
width, height = w, h width, height = w, h
lvo.close() lvo.resizevideo(width, height)
lvo = LiveVideoOut.LiveVideoOut() \
.init(wid, (x, y, width, height), \
width, height)
lvo.putnextpacket(pos, data[6:]) lvo.putnextpacket(pos, data[6:])
else: else:
x = select.select(selectargs) x = select.select(selectargs)
...@@ -103,16 +104,16 @@ def opensocket(group, port): ...@@ -103,16 +104,16 @@ def opensocket(group, port):
# Create the socket # Create the socket
s = socket(AF_INET, SOCK_DGRAM) s = socket(AF_INET, SOCK_DGRAM)
# Bind the port to it
s.bind('', port)
# Allow multiple copies of this program on one machine # Allow multiple copies of this program on one machine
s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) # (Not strictly needed) s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) # (Not strictly needed)
# Bind the port to it
s.bind('', port)
# Look up the group once # Look up the group once
group = gethostbyname(group) group = gethostbyname(group)
# Ugly: construct binary group address # Construct binary group address
group_bytes = eval(regsub.gsub('\.', ',', group)) group_bytes = eval(regsub.gsub('\.', ',', group))
grpaddr = 0 grpaddr = 0
for byte in group_bytes: grpaddr = (grpaddr << 8) | byte for byte in group_bytes: grpaddr = (grpaddr << 8) | byte
...@@ -126,4 +127,5 @@ def opensocket(group, port): ...@@ -126,4 +127,5 @@ def opensocket(group, port):
return s return s
main() main()
...@@ -92,9 +92,7 @@ def main(): ...@@ -92,9 +92,7 @@ def main():
gl.qdevice(DEVICE.WINTHAW) gl.qdevice(DEVICE.WINTHAW)
width, height = gl.getsize() width, height = gl.getsize()
x, y = gl.getorigin() lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height)
lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
width, height)
lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height) lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height)
...@@ -124,11 +122,7 @@ def main(): ...@@ -124,11 +122,7 @@ def main():
width, height = w, h width, height = w, h
lvi = LiveVideoIn.LiveVideoIn() \ lvi = LiveVideoIn.LiveVideoIn() \
.init(pktmax, width, height) .init(pktmax, width, height)
lvo.close() lvo.resizevideo(width, height)
lvo = LiveVideoOut.LiveVideoOut() \
.init(wid, \
(x, y, width, height), \
width, height)
rv = lvi.getnextpacket() rv = lvi.getnextpacket()
if not rv: if not rv:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment