mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Cosmetics, single buffering, block when not running, etc...
This commit is contained in:
		
							parent
							
								
									e4bddeae23
								
							
						
					
					
						commit
						b51afcc5c4
					
				
					 1 changed files with 62 additions and 46 deletions
				
			
		|  | @ -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): | ||||||
|  |     try: | ||||||
|         f = open(name, 'r') |         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): | ||||||
|     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,32 +63,37 @@ 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(): | ||||||
|  | 	foreground() | ||||||
| 	if len(sys.argv) > 1: | 	if len(sys.argv) > 1: | ||||||
| 	f, w, h, pf = openvideo(sys.argv[1]) | 		filename = sys.argv[1] | ||||||
| 	else: | 	else: | ||||||
| 	f, w, h, pf = openvideo('film.video') | 		filename = 'film.video' | ||||||
|     af = None | 	f, w, h, pf = openvideo(filename) | ||||||
|     spkr = None |  | ||||||
| 	if len(sys.argv) > 2: | 	if len(sys.argv) > 2: | ||||||
| 	af = open(sys.argv[2], 'r') | 		audiofilename = sys.argv[2] | ||||||
|  | 		af = open(audiofilename, 'r') | ||||||
| 		spkr = openspkr() | 		spkr = openspkr() | ||||||
| 		if len(sys.argv) > 3: | 		if len(sys.argv) > 3: | ||||||
| 	data = af.read(eval(sys.argv[3])) | 			af.seek(eval(sys.argv[3])) | ||||||
| 	del data | 	else: | ||||||
|     foreground() | 		af, spkr = None, None | ||||||
| 	prefsize(w,h) | 	prefsize(w,h) | ||||||
|     win = winopen('Video player') | 	win = winopen(filename) | ||||||
| 	RGBmode() | 	RGBmode() | ||||||
|     doublebuffer() | 	#doublebuffer() | ||||||
| 	gconfig() | 	gconfig() | ||||||
| 	qdevice(ESCKEY) | 	qdevice(ESCKEY) | ||||||
|  | 	qdevice(WINSHUT) | ||||||
|  | 	qdevice(WINQUIT) | ||||||
| 	running = 1 | 	running = 1 | ||||||
| 	epoch.epoch = time.millitimer() | 	epoch.epoch = time.millitimer() | ||||||
| 	nframe = 0 | 	nframe = 0 | ||||||
|  | @ -97,15 +108,20 @@ def main(): | ||||||
| 			running = 0 | 			running = 0 | ||||||
| 			t = time.millitimer() | 			t = time.millitimer() | ||||||
| 			if tijd > 0: | 			if tijd > 0: | ||||||
| 			    print 'Recorded at ', nframe * 1000.0 / tijd, | 				print 'Recorded at', | ||||||
| 			    print 'frames/second (', tijd, 'ms total)' | 				print 0.1 * int(nframe * 10000.0 / tijd), | ||||||
| 		    print 'Played at', nframe * 1000.0 / (t-epoch.epoch), | 				print 'frames/sec' | ||||||
| 		    print 'frames/second' | 			print 'Played', nframe, 'frames at', | ||||||
|  | 			print 0.1 * int(nframe * 10000.0 / (t-epoch.epoch)), | ||||||
|  | 			print 'frames/sec' | ||||||
| 		if af <> None: | 		if af <> None: | ||||||
| 			playsound(af,spkr) | 			playsound(af,spkr) | ||||||
| 	    if qtest(): | 		if not running or qtest(): | ||||||
| 		if qread() = (ESCKEY,1): | 		    dev, val = qread() | ||||||
|  | 		    if dev in (ESCKEY, WINSHUT, WINQUIT): | ||||||
| 			raise bye | 			raise bye | ||||||
|  | 		    elif dev = REDRAW: | ||||||
|  | 		    	reshapeviewport() | ||||||
| 	except bye: | 	except bye: | ||||||
| 	    pass | 	    pass | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum