Commit 917044d9 authored by Guido van Rossum's avatar Guido van Rossum

Cosmetics, single buffering, block when not running, etc...

parent c402ece5
...@@ -19,8 +19,13 @@ def openspkr(): ...@@ -19,8 +19,13 @@ def openspkr():
conf.setwidth(AL.SAMPLE_16) conf.setwidth(AL.SAMPLE_16)
conf.setchannels(AL.MONO) conf.setchannels(AL.MONO)
return al.openport('spkr','w',conf) return al.openport('spkr','w',conf)
def openvideo(name): def openvideo(name):
f = open(name, 'r') try:
f = open(name, 'r')
except:
sys.stderr.write(name + ': cannot open\n')
sys.exit(1)
line = f.readline() line = f.readline()
if not line: raise EndOfFile if not line: raise EndOfFile
if line[:4] = 'CMIF': line = f.readline() if line[:4] = 'CMIF': line = f.readline()
...@@ -28,6 +33,7 @@ def openvideo(name): ...@@ -28,6 +33,7 @@ def openvideo(name):
if len(x) = 3: w, h, pf = x if len(x) = 3: w, h, pf = x
else: w, h = x; pf = 2 else: w, h = x; pf = 2
return f, w, h, pf return f, w, h, pf
def loadframe(f,w,h,pf,af,spkr): def loadframe(f,w,h,pf,af,spkr):
line = f.readline() line = f.readline()
if line = '': if line = '':
...@@ -57,56 +63,66 @@ def loadframe(f,w,h,pf,af,spkr): ...@@ -57,56 +63,66 @@ def loadframe(f,w,h,pf,af,spkr):
ct = time.millitimer() - epoch.epoch ct = time.millitimer() - epoch.epoch
if tijd > 0 and ct < tijd: if tijd > 0 and ct < tijd:
time.millisleep(tijd-ct) time.millisleep(tijd-ct)
swapbuffers() #swapbuffers()
return tijd return tijd
def playsound(af, spkr): def playsound(af, spkr):
nsamp = spkr.getfillable() nsamp = spkr.getfillable()
data = af.read(nsamp*2) data = af.read(nsamp*2)
spkr.writesamps(data) spkr.writesamps(data)
def main(): def main():
if len(sys.argv) > 1: foreground()
f, w, h, pf = openvideo(sys.argv[1]) if len(sys.argv) > 1:
else: filename = sys.argv[1]
f, w, h, pf = openvideo('film.video') else:
af = None filename = 'film.video'
spkr = None f, w, h, pf = openvideo(filename)
if len(sys.argv) > 2: if len(sys.argv) > 2:
af = open(sys.argv[2], 'r') audiofilename = sys.argv[2]
spkr = openspkr() af = open(audiofilename, 'r')
if len(sys.argv) > 3: spkr = openspkr()
data = af.read(eval(sys.argv[3])) if len(sys.argv) > 3:
del data af.seek(eval(sys.argv[3]))
foreground() else:
prefsize(w,h) af, spkr = None, None
win = winopen('Video player') prefsize(w,h)
RGBmode() win = winopen(filename)
doublebuffer() RGBmode()
gconfig() #doublebuffer()
qdevice(ESCKEY) gconfig()
running = 1 qdevice(ESCKEY)
epoch.epoch = time.millitimer() qdevice(WINSHUT)
nframe = 0 qdevice(WINQUIT)
tijd = 1 running = 1
try: epoch.epoch = time.millitimer()
while 1: nframe = 0
if running: tijd = 1
try: try:
tijd = loadframe(f, w, h, pf, af, spkr) while 1:
nframe = nframe + 1 if running:
except EndOfFile: try:
running = 0 tijd = loadframe(f, w, h, pf, af, spkr)
t = time.millitimer() nframe = nframe + 1
if tijd > 0: except EndOfFile:
print 'Recorded at ', nframe * 1000.0 / tijd, running = 0
print 'frames/second (', tijd, 'ms total)' t = time.millitimer()
print 'Played at', nframe * 1000.0 / (t-epoch.epoch), if tijd > 0:
print 'frames/second' print 'Recorded at',
if af <> None: print 0.1 * int(nframe * 10000.0 / tijd),
playsound(af,spkr) print 'frames/sec'
if qtest(): print 'Played', nframe, 'frames at',
if qread() = (ESCKEY,1): print 0.1 * int(nframe * 10000.0 / (t-epoch.epoch)),
raise bye print 'frames/sec'
except bye: if af <> None:
pass playsound(af,spkr)
if not running or qtest():
dev, val = qread()
if dev in (ESCKEY, WINSHUT, WINQUIT):
raise bye
elif dev = REDRAW:
reshapeviewport()
except bye:
pass
main() main()
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