summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-08 15:04:01 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-08 15:04:01 (GMT)
commit269b2a2eb7c5d63bdfb7989a9c9626e8940aafd4 (patch)
treec45e4187c72c2293da62678ce276f81985975796
parent3577113d8366d1c75cf2cbdbeb5168fd86d2834c (diff)
downloadcpython-269b2a2eb7c5d63bdfb7989a9c9626e8940aafd4.zip
cpython-269b2a2eb7c5d63bdfb7989a9c9626e8940aafd4.tar.gz
cpython-269b2a2eb7c5d63bdfb7989a9c9626e8940aafd4.tar.bz2
VFile: The Entry-Indigo trick doesn't work on 4.0.1 hosts.
VFile: RandomVinFile can now write the cache to the file. Vinfo: use the cached index if present and print a message whether it's there.
-rwxr-xr-xDemo/sgi/video/VFile.py71
-rwxr-xr-xDemo/sgi/video/Vinfo.py15
2 files changed, 70 insertions, 16 deletions
diff --git a/Demo/sgi/video/VFile.py b/Demo/sgi/video/VFile.py
index e5aea41..1516464 100755
--- a/Demo/sgi/video/VFile.py
+++ b/Demo/sgi/video/VFile.py
@@ -324,13 +324,14 @@ class Displayer(VideoParams):
gl.RGBcolor(200, 200, 200) # XXX rather light grey
gl.clear()
return
- if self.format == 'rgb8' and is_entry_indigo():
- gl.RGBmode()
- gl.gconfig()
- gl.RGBcolor(200, 200, 200) # XXX rather light grey
- gl.clear()
- gl.pixmode(GL.PM_SIZE, 8)
- return
+## XXX Unfortunately this doesn't work on IRIX 4.0.1...
+## if self.format == 'rgb8' and is_entry_indigo():
+## gl.RGBmode()
+## gl.gconfig()
+## gl.RGBcolor(200, 200, 200) # XXX rather light grey
+## gl.clear()
+## gl.pixmode(GL.PM_SIZE, 8)
+## return
gl.cmode()
gl.gconfig()
self.skipchrom = 0
@@ -756,7 +757,7 @@ class BasicVinFile(VideoParams):
self.framecount = self.framecount + 1
-# Derived class implementing random access
+# Derived class implementing random access and index cached in the file
class RandomVinFile(BasicVinFile):
@@ -767,12 +768,58 @@ class RandomVinFile(BasicVinFile):
def warmcache(self):
if len(self.index) == 0:
- self.rewind()
- while 1:
- try: dummy = self.skipnextframe()
- except EOFError: break
+ try:
+ self.readcache()
+ except Error:
+ self.buildcache()
else:
print '[RandomVinFile.warmcache(): too late]'
+ self.rewind()
+
+ def buildcache(self):
+ self.index = []
+ self.rewind()
+ while 1:
+ try: dummy = self.skipnextframe()
+ except EOFError: break
+ self.rewind()
+
+ def writecache(self):
+ # Raises IOerror if the file is not seekable & writable!
+ import marshal
+ if len(self.index) == 0:
+ self.buildcache()
+ if len(self.index) == 0:
+ raise Error, self.filename + ': No frames'
+ self.fp.seek(0, 2)
+ self.fp.write('\n/////CMIF/////\n')
+ pos = self.fp.tell()
+ data = `pos`
+ data = '\n-*-*-CMIF-*-*-\n' + data + ' '*(15-len(data)) + '\n'
+ try:
+ marshal.dump(self.index, self.fp)
+ self.fp.write(data)
+ self.fp.flush()
+ finally:
+ self.rewind()
+
+ def readcache(self):
+ # Raises Error if there is no cache in the file
+ import marshal
+ if len(self.index) <> 0:
+ raise CallError
+ self.fp.seek(-32, 2)
+ data = self.fp.read()
+ if data[:16] <> '\n-*-*-CMIF-*-*-\n' or data[-1:] <> '\n':
+ self.rewind()
+ raise Error, self.filename + ': No cache'
+ pos = eval(data[16:-1])
+ self.fp.seek(pos)
+ try:
+ self.index = marshal.load(self.fp)
+ except TypeError:
+ self.rewind()
+ raise Error, self.filename + ': Bad cache'
self.rewind()
def getnextframeheader(self):
diff --git a/Demo/sgi/video/Vinfo.py b/Demo/sgi/video/Vinfo.py
index cfda32a..cf89a8d 100755
--- a/Demo/sgi/video/Vinfo.py
+++ b/Demo/sgi/video/Vinfo.py
@@ -54,7 +54,7 @@ def main():
def process(filename):
try:
- vin = VFile.VinFile().init(filename)
+ vin = VFile.RandomVinFile().init(filename)
except IOError, msg:
sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
return 1
@@ -71,6 +71,12 @@ def process(filename):
vin.close()
return
+ try:
+ vin.readcache()
+ print '[Using cached index]'
+ except VFile.Error:
+ print '[Constructing index on the fly]'
+
if not short:
if delta:
print 'Frame time deltas:',
@@ -83,11 +89,12 @@ def process(filename):
datasize = 0
while 1:
try:
- t, data, cdata = vin.getnextframe()
+ t, ds, cs = vin.getnextframeheader()
+ vin.skipnextframedata(ds, cs)
except EOFError:
break
- datasize = datasize + len(data)
- if cdata: datasize = datasize + len(cdata)
+ datasize = datasize + ds
+ if cs: datasize = datasize + cs
if not short:
if n%8 == 0:
sys.stdout.write('\n')