1991-11-04 14:04:21 -04:00
|
|
|
import getopt
|
1991-10-30 07:52:48 -04:00
|
|
|
from gl import *
|
|
|
|
from GL import *
|
|
|
|
from DEVICE import *
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import al
|
|
|
|
import AL
|
|
|
|
|
|
|
|
BUFFERSIZE = 32000
|
|
|
|
|
|
|
|
class Struct(): pass
|
|
|
|
epoch = Struct()
|
|
|
|
EndOfFile = 'End of file'
|
|
|
|
bye = 'bye'
|
|
|
|
|
|
|
|
def openspkr():
|
|
|
|
conf = al.newconfig()
|
|
|
|
conf.setqueuesize(BUFFERSIZE)
|
|
|
|
conf.setwidth(AL.SAMPLE_16)
|
|
|
|
conf.setchannels(AL.MONO)
|
|
|
|
return al.openport('spkr','w',conf)
|
1991-11-04 10:29:27 -04:00
|
|
|
|
1991-10-30 07:52:48 -04:00
|
|
|
def openvideo(name):
|
1991-11-04 10:29:27 -04:00
|
|
|
try:
|
|
|
|
f = open(name, 'r')
|
|
|
|
except:
|
|
|
|
sys.stderr.write(name + ': cannot open\n')
|
|
|
|
sys.exit(1)
|
1991-10-30 07:52:48 -04:00
|
|
|
line = f.readline()
|
|
|
|
if not line: raise EndOfFile
|
|
|
|
if line[:4] = 'CMIF': line = f.readline()
|
|
|
|
x = eval(line[:-1])
|
|
|
|
if len(x) = 3: w, h, pf = x
|
|
|
|
else: w, h = x; pf = 2
|
|
|
|
return f, w, h, pf
|
1991-11-04 10:29:27 -04:00
|
|
|
|
1991-10-30 07:52:48 -04:00
|
|
|
def loadframe(f,w,h,pf,af,spkr):
|
|
|
|
line = f.readline()
|
|
|
|
if line = '':
|
|
|
|
raise EndOfFile
|
|
|
|
x = eval(line[:-1])
|
|
|
|
if type(x) = type(0) or type(x) = type(0.0):
|
|
|
|
tijd = x
|
|
|
|
if pf = 0:
|
|
|
|
size = w*h*4
|
|
|
|
else:
|
|
|
|
size = (w/pf) * (h/pf)
|
|
|
|
else:
|
|
|
|
tijd, size = x
|
|
|
|
data = f.read(size)
|
|
|
|
if len(data) <> size:
|
|
|
|
raise EndOfFile
|
|
|
|
if pf:
|
|
|
|
rectzoom(pf, pf)
|
|
|
|
w = w/pf
|
|
|
|
h = h/pf
|
|
|
|
data = unpackrect(w, h, 1, data)
|
|
|
|
lrectwrite(0,0,w-1,h-1,data)
|
|
|
|
# This is ugly here, but the only way to get the two
|
|
|
|
# channels started in sync
|
|
|
|
#if af <> None:
|
|
|
|
# playsound(af,spkr)
|
|
|
|
ct = time.millitimer() - epoch.epoch
|
|
|
|
if tijd > 0 and ct < tijd:
|
|
|
|
time.millisleep(tijd-ct)
|
1991-11-04 10:29:27 -04:00
|
|
|
#swapbuffers()
|
1991-10-30 07:52:48 -04:00
|
|
|
return tijd
|
1991-11-04 10:29:27 -04:00
|
|
|
|
1991-10-30 07:52:48 -04:00
|
|
|
def playsound(af, spkr):
|
|
|
|
nsamp = spkr.getfillable()
|
|
|
|
data = af.read(nsamp*2)
|
|
|
|
spkr.writesamps(data)
|
1991-11-04 10:29:27 -04:00
|
|
|
|
1991-10-30 07:52:48 -04:00
|
|
|
def main():
|
1991-11-04 14:04:21 -04:00
|
|
|
looping = 0
|
|
|
|
packfactor = 0
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], 'p:l')
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt = '-p':
|
|
|
|
packfactor = int(eval(arg))
|
|
|
|
elif opt = '-l':
|
|
|
|
looping = 1
|
|
|
|
if args:
|
|
|
|
filename = args[0]
|
1991-11-04 10:29:27 -04:00
|
|
|
else:
|
|
|
|
filename = 'film.video'
|
|
|
|
f, w, h, pf = openvideo(filename)
|
1991-11-04 14:04:21 -04:00
|
|
|
if 0 < packfactor <> pf:
|
|
|
|
w = w/pf*packfactor
|
|
|
|
h = h/pf*packfactor
|
|
|
|
pf = packfactor
|
|
|
|
if args[1:]:
|
|
|
|
audiofilename = args[1]
|
1991-11-04 10:29:27 -04:00
|
|
|
af = open(audiofilename, 'r')
|
|
|
|
spkr = openspkr()
|
1991-11-04 14:04:21 -04:00
|
|
|
afskip = 0
|
1991-11-04 10:29:27 -04:00
|
|
|
if len(sys.argv) > 3:
|
1991-11-04 14:04:21 -04:00
|
|
|
afskip = eval(sys.argv[3])
|
|
|
|
if afskip > 0:
|
|
|
|
af.seek(afskip)
|
1991-11-04 10:29:27 -04:00
|
|
|
else:
|
|
|
|
af, spkr = None, None
|
1991-11-04 14:04:21 -04:00
|
|
|
foreground()
|
1991-11-04 10:29:27 -04:00
|
|
|
prefsize(w,h)
|
|
|
|
win = winopen(filename)
|
|
|
|
RGBmode()
|
|
|
|
#doublebuffer()
|
|
|
|
gconfig()
|
|
|
|
qdevice(ESCKEY)
|
|
|
|
qdevice(WINSHUT)
|
|
|
|
qdevice(WINQUIT)
|
|
|
|
running = 1
|
|
|
|
epoch.epoch = time.millitimer()
|
|
|
|
nframe = 0
|
|
|
|
tijd = 1
|
1991-11-04 14:04:21 -04:00
|
|
|
if looping:
|
|
|
|
looping = f.tell()
|
1991-11-04 10:29:27 -04:00
|
|
|
try:
|
|
|
|
while 1:
|
|
|
|
if running:
|
|
|
|
try:
|
|
|
|
tijd = loadframe(f, w, h, pf, af, spkr)
|
|
|
|
nframe = nframe + 1
|
|
|
|
except EndOfFile:
|
|
|
|
running = 0
|
|
|
|
t = time.millitimer()
|
|
|
|
if tijd > 0:
|
|
|
|
print 'Recorded at',
|
|
|
|
print 0.1 * int(nframe * 10000.0 / tijd),
|
|
|
|
print 'frames/sec'
|
|
|
|
print 'Played', nframe, 'frames at',
|
|
|
|
print 0.1 * int(nframe * 10000.0 / (t-epoch.epoch)),
|
|
|
|
print 'frames/sec'
|
1991-11-04 14:04:21 -04:00
|
|
|
if looping:
|
|
|
|
f.seek(looping)
|
|
|
|
epoch.epoch = time.millitimer()
|
|
|
|
nframe = 0
|
|
|
|
running = 1
|
|
|
|
if af <> None:
|
|
|
|
af.seek(afskip)
|
1991-11-04 10:29:27 -04:00
|
|
|
if af <> None:
|
|
|
|
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
|
1991-10-30 07:52:48 -04:00
|
|
|
|
|
|
|
main()
|