Example #1
0
#! /usr/bin/env python
# Send live video UDP packets.
# Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width]
#              [host] ..
import sys
import time
import struct
import string
import math
from socket import *
from SOCKET import *
import gl, GL, DEVICE
sys.path.append('/ufs/guido/src/video')
import DisplayVideoIn
import LiveVideoOut
import SV
import getopt
from IN import *
from senddefs import *
def usage(msg):
	print msg
	print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]',
	print '[-w width] [host] ...'
	print '-b        : broadcast on local net'
	print '-h height : window height (default ' + `DEFHEIGHT` + ')'
	print '-p port   : port to use (default ' + `DEFPORT` + ')'
	print '-t ttl    : time-to-live (multicast only; default 1)'
	print '-s size   : max packet size (default ' + `DEFPKTMAX` + ')'
	print '-S size   : use this packet size/window size'
	print '-w width  : window width (default ' + `DEFWIDTH` + ')'
Example #2
0
def record(v, info, filename, audiofilename, mono, grey, greybits, \
	  monotreshold, fields, preallocspace):
	import thread
	format, x, y, qsize, rate = info
	fps = 59.64 # Fields per second
	# XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
	tpf = 1000.0 / fps # Time per field in msec
	if filename:
		vout = VFile.VoutFile(filename)
		if mono:
			format = 'mono'
		elif grey and greybits == 8:
			format = 'grey'
		elif grey:
			format = 'grey'+`abs(greybits)`
		else:
			format = 'rgb8'
		vout.setformat(format)
		vout.setsize(x, y)
		if fields:
			vout.setpf((1, -2))
		vout.writeheader()
		if preallocspace:
			print 'Preallocating space...'
			vout.prealloc(preallocspace)
			print 'done.'
		MAXSIZE = 20 # XXX should be a user option
		import Queue
		queue = Queue.Queue(MAXSIZE)
		done = thread.allocate_lock()
		done.acquire_lock()
		convertor = None
		if grey:
			if greybits == 2:
				convertor = imageop.grey2grey2
			elif greybits == 4:
				convertor = imageop.grey2grey4
			elif greybits == -2:
				convertor = imageop.dither2grey2
		thread.start_new_thread(saveframes, \
			  (vout, queue, done, mono, monotreshold, convertor))
		if audiofilename:
			audiodone = thread.allocate_lock()
			audiodone.acquire_lock()
			audiostop = []
			initaudio(audiofilename, audiostop, audiodone)
	gl.wintitle('(rec) ' + filename)
	lastid = 0
	t0 = time.time()
	count = 0
	ids = []
	v.InitContinuousCapture(info)
	while not gl.qtest():
		try:
			cd, id = v.GetCaptureData()
		except sv.error:
			#time.sleep(0.010) # XXX is this necessary?
			sgi.nap(1)	# XXX Try by Jack
			continue
		ids.append(id)
		
		id = id + 2*rate
##		if id <> lastid + 2*rate:
##			print lastid, id
		lastid = id
		count = count+1
		if fields:
			data1, data2 = cd.GetFields()
			cd.UnlockCaptureData()
			if filename:
				queue.put((data1, int(id*tpf)))
				queue.put((data2, int((id+1)*tpf)))
		else:
			data = cd.InterleaveFields(1)
			cd.UnlockCaptureData()
			if filename:
				queue.put((data, int(id*tpf)))
	t1 = time.time()
	gl.wintitle('(busy) ' + filename)
	print lastid, 'fields in', round(t1-t0, 3), 'sec',
	print '--', round(lastid/(t1-t0), 1), 'fields/sec'
	print 'Captured',count*2, 'fields,',
	print round(count*2/(t1-t0), 1), 'f/s',
	if lastid:
		print '(',
		print round(count*200.0/lastid), '%, or',
		print round(count*rate*200.0/lastid), '% of wanted rate )',
	print
	if ids:
		print 'Ids:',
		t0 = ids[0]
		del ids[0]
		for t1 in ids:
			print t1-t0,
			t0 = t1
		print
	if filename and audiofilename:
		audiostop.append(None)
		audiodone.acquire_lock()
	v.EndContinuousCapture()
	if filename:
		queue.put(None) # Sentinel
		done.acquire_lock()
	gl.wintitle('(done) ' + filename)
Example #3
0
#! /usr/bin/env python
Example #4
0
    gl.winconstraints()
    gl.qdevice(DEVICE.ESCKEY)
    gl.qdevice(DEVICE.WINSHUT)
    gl.qdevice(DEVICE.WINQUIT)

    lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)

    ifdlist = [gl.qgetfd(), s.fileno()]
    ofdlist = []
    xfdlist = []
    timeout = 1.0
    selectargs = (ifdlist, ofdlist, xfdlist, timeout)

    while 1:

        if gl.qtest():
            dev, val = gl.qread()
            if dev in (DEVICE.ESCKEY, \
             DEVICE.WINSHUT, DEVICE.WINQUIT):
                break
            if dev == DEVICE.REDRAW:
                lvo.reshapewindow()
        elif s.avail():
            data = s.recv(16 * 1024)
            pos, w, h = struct.unpack('hhh', data[:6])
            if (w, h) <> (width, height):
                x, y = gl.getorigin()
                y = y + height - h
                gl.winposition(x, x + w - 1, y, y + h - 1)
                width, height = w, h
                lvo.resizevideo(width, height)
Example #5
0
def record(v, info, filename, audiofilename, mono, grey, greybits, \
   monotreshold, fields, preallocspace):
    import thread
    format, x, y, qsize, rate = info
    fps = 59.64  # Fields per second
    # XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
    tpf = 1000.0 / fps  # Time per field in msec
    if filename:
        vout = VFile.VoutFile(filename)
        if mono:
            format = 'mono'
        elif grey and greybits == 8:
            format = 'grey'
        elif grey:
            format = 'grey' + ` abs(greybits) `
        else:
            format = 'rgb8'
        vout.setformat(format)
        vout.setsize(x, y)
        if fields:
            vout.setpf((1, -2))
        vout.writeheader()
        if preallocspace:
            print 'Preallocating space...'
            vout.prealloc(preallocspace)
            print 'done.'
        MAXSIZE = 20  # XXX should be a user option
        import Queue
        queue = Queue.Queue(MAXSIZE)
        done = thread.allocate_lock()
        done.acquire_lock()
        convertor = None
        if grey:
            if greybits == 2:
                convertor = imageop.grey2grey2
            elif greybits == 4:
                convertor = imageop.grey2grey4
            elif greybits == -2:
                convertor = imageop.dither2grey2
        thread.start_new_thread(saveframes, \
           (vout, queue, done, mono, monotreshold, convertor))
        if audiofilename:
            audiodone = thread.allocate_lock()
            audiodone.acquire_lock()
            audiostop = []
            initaudio(audiofilename, audiostop, audiodone)
    gl.wintitle('(rec) ' + filename)
    lastid = 0
    t0 = time.time()
    count = 0
    ids = []
    v.InitContinuousCapture(info)
    while not gl.qtest():
        try:
            cd, id = v.GetCaptureData()
        except sv.error:
            #time.sleep(0.010) # XXX is this necessary?
            sgi.nap(1)  # XXX Try by Jack
            continue
        ids.append(id)

        id = id + 2 * rate
        ##		if id <> lastid + 2*rate:
        ##			print lastid, id
        lastid = id
        count = count + 1
        if fields:
            data1, data2 = cd.GetFields()
            cd.UnlockCaptureData()
            if filename:
                queue.put((data1, int(id * tpf)))
                queue.put((data2, int((id + 1) * tpf)))
        else:
            data = cd.InterleaveFields(1)
            cd.UnlockCaptureData()
            if filename:
                queue.put((data, int(id * tpf)))
    t1 = time.time()
    gl.wintitle('(busy) ' + filename)
    print lastid, 'fields in', round(t1 - t0, 3), 'sec',
    print '--', round(lastid / (t1 - t0), 1), 'fields/sec'
    print 'Captured', count * 2, 'fields,',
    print round(count * 2 / (t1 - t0), 1), 'f/s',
    if lastid:
        print '(',
        print round(count * 200.0 / lastid), '%, or',
        print round(count * rate * 200.0 / lastid), '% of wanted rate )',
    print
    if ids:
        print 'Ids:',
        t0 = ids[0]
        del ids[0]
        for t1 in ids:
            print t1 - t0,
            t0 = t1
        print
    if filename and audiofilename:
        audiostop.append(None)
        audiodone.acquire_lock()
    v.EndContinuousCapture()
    if filename:
        queue.put(None)  # Sentinel
        done.acquire_lock()
    gl.wintitle('(done) ' + filename)
Example #6
0
def playonce(vin):
	vin.rewind()
	vin.colormapinited = 1
	vin.magnify = magnify

	if threading:
		MAXSIZE = 20 # Don't read ahead too much
		import thread
		import Queue
		queue = Queue.Queue(MAXSIZE)
		stop = []
		thread.start_new_thread(read_ahead, (vin, queue, stop))
		# Get the read-ahead thread going
		while queue.qsize() < MAXSIZE/2 and not stop:
			time.sleep(0.100)

	tin = 0
	toffset = 0
	oldtin = 0
	told = 0
	nin = 0
	nout = 0
	nlate = 0
	nskipped = 0
	data = None

	tlast = t0 = time.time()

	while 1:
		if gl.qtest():
			dev, val = gl.qread()
			if dev == ESCKEY and val == 1 or \
					dev in (WINSHUT, WINQUIT) or \
					dev == LEFTMOUSE and val == 1:
				if debug: sys.stderr.write('\n')
				if threading:
					stop.append(None)
					while 1:
						item = queue.get()
						if item == None: break
				return (dev != LEFTMOUSE)
			if dev == REDRAW:
				gl.reshapeviewport()
				if data: vin.showframe(data, cdata)
		if threading:
			if debug and queue.empty(): sys.stderr.write('.')
			item = queue.get()
			if item == None: break
			tin, data, cdata = item
		else:
			try:
				tin, size, csize = vin.getnextframeheader()
			except EOFError:
				break
		tin = tin*0.001
		nin = nin+1
		if tin+toffset < oldtin:
			print 'Fix reversed time:', oldtin, 'to', tin
			toffset = oldtin - tin
		tin = tin + toffset
		oldtin = tin
		if regen: tout = nin * regen
		else: tout = tin
		tout = tout / speed
		if tout - told < mindelta:
			nskipped = nskipped + 1
			if not threading:
				vin.skipnextframedata(size, csize)
		else:
			if not threading:
				try:
					data, cdata = \
					  vin.getnextframedata(size, csize)
				except EOFError:
					if not quiet:
						print '[incomplete last frame]'
					break
			now = time.time()
			dt = (tout-told) - (now-tlast)
			told = tout
			if debug: sys.stderr.write(`round(dt, 3)` + ' ')
			if dt < 0: nlate = nlate + 1
			if dt > 0:
				time.sleep(dt)
				now = time.time()
			tlast = now
			vin.showframe(data, cdata)
			nout = nout + 1

	t1 = time.time()

	if debug: sys.stderr.write('\n')

	if quiet: return 0

	print 'Recorded:', nin, 'frames in', round(tin, 3), 'sec.',
	if tin: print '-- average', round(nin/tin, 1), 'frames/sec',
	print

	if nskipped: print 'Skipped', nskipped, 'frames'

	tout = t1-t0
	print 'Played:', nout,
	print 'frames in', round(tout, 3), 'sec.',
	if tout: print '-- average', round(nout/tout, 1), 'frames/sec',
	print

	if nlate: print 'There were', nlate, 'late frames'

	return 0
def getevent():
    while 1:
        #
        # Get next event from the processed queue, if any
        #
        if G.queue:
            event = G.queue[0]
            del G.queue[0]
            #print 'getevent from queue -->', event
            return event
        #
        # Get next event from the draw queue, if any,
        # but only if there is nothing in the system queue.
        #
        if G.drawqueue and not gl.qtest():
            win = G.drawqueue[0]
            del G.drawqueue[0]
            gl.winset(win._gid)
            gl.color(win._bg)
            gl.clear()
            event = WE_DRAW, win, win._area
            #print 'getevent from drawqueue -->', event
            return event
        #
        # Get next event from system queue, blocking if necessary
        # until one is available.
        # Some cases immediately return the event, others do nothing
        # or append one or more events to the processed queue.
        #
        dev, val = gl.qread()
        #
        if dev == REDRAW:
            win = G.windowmap[ ` val `]
            old_area = win._area
            win._fixviewport()
            win._needredraw()
            if old_area <> win._area:
                #print 'getevent --> WE_SIZE'
                return WE_SIZE, win, None
        elif dev == KEYBD:
            if val == 3:
                raise KeyboardInterrupt  # Control-C in window
            character = chr(val)
            if commands.has_key(character):
                return WE_COMMAND, G.focus, commands[character]
            return WE_CHAR, G.focus, character
        elif dev == LEFTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_LEFT
        elif dev == RIGHTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_RIGHT
        elif dev == UPARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_UP
        elif dev == DOWNARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_DOWN
        elif dev in (LEFTALTKEY, RIGHTALTKEY):
            if val:
                for code in codelist:
                    gl.qdevice(code)
            else:
                for code in codelist:
                    gl.unqdevice(code)
        elif dev in codelist:
            if val:
                event = G.focus._doshortcut(code2key[ ` dev `])
                if event:
                    return event
        elif dev == LEFTMOUSE:
            G.mousex = gl.getvaluator(MOUSEX)
            G.mousey = gl.getvaluator(MOUSEY)
            if val:
                type = WE_MOUSE_DOWN
                gl.qdevice(MOUSEX)
                gl.qdevice(MOUSEY)
            else:
                type = WE_MOUSE_UP
                gl.unqdevice(MOUSEX)
                gl.unqdevice(MOUSEY)
            return _mouseevent(type)
        elif dev == MOUSEX:
            G.mousex = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == MOUSEY:
            G.mousey = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == RIGHTMOUSE:  # Menu button press/release
            if val:  # Press
                event = G.focus._domenu()
                if event:
                    return event
        elif dev == INPUTCHANGE:
            if G.focus:
                G.queue.append(WE_DEACTIVATE, G.focus, None)
            G.focus = G.windowmap[ ` val `]
            if G.focus:
                G.queue.append(WE_ACTIVATE, G.focus, None)
        elif dev in (WINSHUT, WINQUIT):
            return WE_CLOSE, G.windowmap[ ` val `], None
        else:
            print '*** qread() --> dev:', dev, 'val:', val
Example #8
0
#! /usr/bin/env python
# Send live video UDP packets.
# Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width]
#              [host] ..
import sys
import time
import struct
import string
from socket import *
from SOCKET import *
import gl, GL, DEVICE
sys.path.append('/ufs/guido/src/video')
import LiveVideoIn
import LiveVideoOut
import SV
import getopt
from IN import *
from senddefs import *

def usage(msg):
    print msg
    print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]',
    print '[-w width] [host] ...'
    print '-b        : broadcast on local net'
    print '-h height : window height (default ' + ` DEFHEIGHT ` + ')'
    print '-p port   : port to use (default ' + ` DEFPORT ` + ')'
    print '-t ttl    : time-to-live (multicast only; default 1)'
    print '-s size   : max packet size (default ' + ` DEFPKTMAX ` + ')'
    print '-w width  : window width (default ' + ` DEFWIDTH ` + ')'
    print '-c type   : Type: rgb8, mono or grey (default rgb8)'
Example #9
0
#! /usr/bin/env python
Example #10
0
	width, height = gl.getsize()

	lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)

	lvi = LiveVideoIn.LiveVideoIn(pktmax, width, height, vtype)

	s = socket(AF_INET, SOCK_DGRAM)
	s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
	if ttl >= 0:
		s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, chr(ttl))

	frozen = 0

	while 1:

		if gl.qtest():
			dev, val = gl.qread()
			if dev in (DEVICE.ESCKEY, \
				DEVICE.WINSHUT, DEVICE.WINQUIT):
				break
			if dev == DEVICE.WINFREEZE:
				frozen = 1
			if dev == DEVICE.WINTHAW:
				frozen = 0
			if dev == DEVICE.REDRAW:
				w, h = gl.getsize()
				x, y = gl.getorigin()
				if (w, h) <> (width, height):
					width, height = w, h
					lvi.resizevideo(width, height)
					lvo.resizevideo(width, height)
Example #11
0
#! /usr/bin/env python
Example #12
0
#! /usr/bin/env python
# Play synchronous video and audio.
# Highly experimental!
import sys
import getopt
import string
import os
import VFile
import aifc
import gl, GL, DEVICE
import al, AL

def usage():
	sys.stderr.write( \
		'usage: aplay [-o offset] [-q qsize] videofile audiofile\n')
	sys.exit(2)
def main():
	offset = 0
	qsize = 0 # This defaults to 1/10 second of sound
	videofile = 'film.video'
	audiofile = 'film.aiff'
	try:
		opts, args = getopt.getopt(sys.argv[1:], 'o:q:')
	except getopt.error, msg:
		sys.stderr.write(msg + '\n')
		usage()
	try:
		for o, a in opts:
			if o == '-o':
				offset = string.atoi(a)
def getevent():
    while 1:
        #
        # Get next event from the processed queue, if any
        #
        if G.queue:
            event = G.queue[0]
            del G.queue[0]
            # print 'getevent from queue -->', event
            return event
            #
            # Get next event from the draw queue, if any,
            # but only if there is nothing in the system queue.
            #
        if G.drawqueue and not gl.qtest():
            win = G.drawqueue[0]
            del G.drawqueue[0]
            gl.winset(win._gid)
            gl.color(win._bg)
            gl.clear()
            event = WE_DRAW, win, win._area
            # print 'getevent from drawqueue -->', event
            return event
            #
            # Get next event from system queue, blocking if necessary
            # until one is available.
            # Some cases immediately return the event, others do nothing
            # or append one or more events to the processed queue.
            #
        dev, val = gl.qread()
        #
        if dev == REDRAW:
            win = G.windowmap[` val `]
            old_area = win._area
            win._fixviewport()
            win._needredraw()
            if old_area <> win._area:
                # print 'getevent --> WE_SIZE'
                return WE_SIZE, win, None
        elif dev == KEYBD:
            if val == 3:
                raise KeyboardInterrupt  # Control-C in window
            character = chr(val)
            if commands.has_key(character):
                return WE_COMMAND, G.focus, commands[character]
            return WE_CHAR, G.focus, character
        elif dev == LEFTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_LEFT
        elif dev == RIGHTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_RIGHT
        elif dev == UPARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_UP
        elif dev == DOWNARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_DOWN
        elif dev in (LEFTALTKEY, RIGHTALTKEY):
            if val:
                for code in codelist:
                    gl.qdevice(code)
            else:
                for code in codelist:
                    gl.unqdevice(code)
        elif dev in codelist:
            if val:
                event = G.focus._doshortcut(code2key[` dev `])
                if event:
                    return event
        elif dev == LEFTMOUSE:
            G.mousex = gl.getvaluator(MOUSEX)
            G.mousey = gl.getvaluator(MOUSEY)
            if val:
                type = WE_MOUSE_DOWN
                gl.qdevice(MOUSEX)
                gl.qdevice(MOUSEY)
            else:
                type = WE_MOUSE_UP
                gl.unqdevice(MOUSEX)
                gl.unqdevice(MOUSEY)
            return _mouseevent(type)
        elif dev == MOUSEX:
            G.mousex = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == MOUSEY:
            G.mousey = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == RIGHTMOUSE:  # Menu button press/release
            if val:  # Press
                event = G.focus._domenu()
                if event:
                    return event
        elif dev == INPUTCHANGE:
            if G.focus:
                G.queue.append(WE_DEACTIVATE, G.focus, None)
            G.focus = G.windowmap[` val `]
            if G.focus:
                G.queue.append(WE_ACTIVATE, G.focus, None)
        elif dev in (WINSHUT, WINQUIT):
            return WE_CLOSE, G.windowmap[` val `], None
        else:
            print "*** qread() --> dev:", dev, "val:", val
Example #14
0
#! /usr/bin/env python
# Send live video UDP packets.
# Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width]
#              [host] ..
import sys
import time
import struct
import string
from socket import *
from SOCKET import *
import gl, GL, DEVICE
sys.path.append('/ufs/guido/src/video')
import LiveVideoIn
import LiveVideoOut
import SV
import getopt
from IN import *
from senddefs import *
def usage(msg):
	print msg
	print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]',
	print '[-w width] [host] ...'
	print '-b        : broadcast on local net'
	print '-h height : window height (default ' + `DEFHEIGHT` + ')'
	print '-p port   : port to use (default ' + `DEFPORT` + ')'
	print '-t ttl    : time-to-live (multicast only; default 1)'
	print '-s size   : max packet size (default ' + `DEFPKTMAX` + ')'
	print '-w width  : window width (default ' + `DEFWIDTH` + ')'
	print '-c type   : Type: rgb8, mono or grey (default rgb8)'
	print '[host] ...: host(s) to send to (default multicast to ' + \
Example #15
0
#! /usr/bin/env python
# Send live video UDP packets.
# Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width]
#              [host] ..
import sys
import time
import struct
import string
import math
from socket import *
from SOCKET import *
import gl, GL, DEVICE
sys.path.append('/ufs/guido/src/video')
import DisplayVideoIn
import LiveVideoOut
import SV
import getopt
from IN import *
from senddefs import *

def usage(msg):
    print msg
    print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]',
    print '[-w width] [host] ...'
    print '-b        : broadcast on local net'
    print '-h height : window height (default ' + ` DEFHEIGHT ` + ')'
    print '-p port   : port to use (default ' + ` DEFPORT ` + ')'
    print '-t ttl    : time-to-live (multicast only; default 1)'
    print '-s size   : max packet size (default ' + ` DEFPKTMAX ` + ')'
    print '-S size   : use this packet size/window size'