Author: duncan
Date: Mon Oct 22 10:29:27 2007
New Revision: 10022
Log:
THis is a resonably large change with the video groups and set the tv channel
The tuner input is set by it's name and the TV standards is also set by it's
name
Modified:
branches/rel-1/freevo/src/config.py
branches/rel-1/freevo/src/tv/channels.py
branches/rel-1/freevo/src/tv/ivtv.py
branches/rel-1/freevo/src/tv/plugins/ivtv_record.py
branches/rel-1/freevo/src/tv/plugins/ivtv_xine_tv.py
branches/rel-1/freevo/src/tv/plugins/mplayer.py
branches/rel-1/freevo/src/tv/plugins/tvtime.py
branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py
branches/rel-1/freevo/src/tv/v4l2.py
Modified: branches/rel-1/freevo/src/config.py
==============================================================================
--- branches/rel-1/freevo/src/config.py (original)
+++ branches/rel-1/freevo/src/config.py Mon Oct 22 10:29:27 2007
@@ -164,13 +164,22 @@
cmd: Command for execute external prog after the channel
switched, such as 'sudo /usr/local/bin/setuptuner'
"""
- def __init__(self, vdev='/dev/video', vvbi='/dev/vbi', adev=None,
input_type='tuner',
- input_num=0, tuner_norm='NTSC', tuner_chanlist='us-cable',
+ def __init__(self, vdev=None, vvbi='/dev/vbi', adev=None, input_type=None,
+ input_num=0, tuner_norm=None, tuner_chanlist=None,
tuner_type='internal', tuner_chan=None,
- record_group=None, desc='Freevo default VideoGroup',
+ record_group=None, desc='Freevo Default Video Group',
group_type='normal', cmd=None):
- # XXX: Put checks in here for supplied values.
+ (v_norm, v_input, v_clist, v_dev) = TV_SETTINGS.split()
+ if vdev is None:
+ vdev = v_dev
+ if input_type is None:
+ input_type = v_input
+ if tuner_norm is None:
+ tuner_norm = v_norm
+ if tuner_chanlist is None:
+ tuner_chanlist = v_clist
+
self.vdev = vdev
self.vvbi = vvbi
self.adev = adev
Modified: branches/rel-1/freevo/src/tv/channels.py
==============================================================================
--- branches/rel-1/freevo/src/tv/channels.py (original)
+++ branches/rel-1/freevo/src/tv/channels.py Mon Oct 22 10:29:27 2007
@@ -190,13 +190,25 @@
# Lets set the freq ourselves using the V4L device.
try:
vd = tv.v4l2.Videodev(vg.vdev)
+
+ try:
+ vd.setinputbyname(vg.input_type)
+ except KeyError:
+ print 'Cannot set input %r, must be one of:\n%r' %
(vg.input_type, vd.inputs.keys())
+
+ try:
+ vd.setstdbyname(vg.tuner_norm)
+ except KeyError:
+ print 'Cannot set standard %r, must be one of:\n%r' %
(vg.tuner_norm, tv.v4l2.NORMS.keys())
+
try:
vd.setfreq(freq)
except:
vd.setfreq_old(freq)
+
vd.close()
- except:
- print 'Failed to set freq for channel %s.' % chan
+ except Exception, e:
+ print 'Cannot set frequency for %s/%s/%s: %s' %
(vg.input_type, vg.tuner_norm, chan, e)
if vg.cmd:
_debug_("run cmd: %s" % vg.cmd)
@@ -210,9 +222,11 @@
def getChannel(self):
return config.TV_CHANNELS[self.chan_index][2]
+
def getChannelNum(self):
return (self.chan_index) % len(config.TV_CHANNELS)
+
def getManChannelNum(self, channel=0):
return (channel-1) % len(config.TV_CHANNELS)
@@ -271,8 +285,6 @@
return tuner_id, chan_name, prog_info
-
-
if __name__ == '__main__':
fc = FreevoChannels()
print 'CHAN: %s' % fc.getChannel()
Modified: branches/rel-1/freevo/src/tv/ivtv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/ivtv.py (original)
+++ branches/rel-1/freevo/src/tv/ivtv.py Mon Oct 22 10:29:27 2007
@@ -57,19 +57,19 @@
_IOC_WRITE = 1
_IOC_READ = 2
-def _IOC(dir,type,nr,size):
+def _IOC(dir, type, nr, size):
return (((dir) << _IOC_DIRSHIFT) | \
(ord(type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
-def _IO(type,nr): return _IOC(_IOC_NONE,(type),(nr),0)
+def _IO(type, nr): return _IOC(_IOC_NONE, (type), (nr), 0)
-def _IOR(type,nr,size): return
_IOC(_IOC_READ,(type),(nr),struct.calcsize(size))
+def _IOR(type, nr, size): return _IOC(_IOC_READ, (type), (nr),
struct.calcsize(size))
-def _IOW(type,nr,size): return
_IOC(_IOC_WRITE,(type),(nr),struct.calcsize(size))
+def _IOW(type, nr, size): return _IOC(_IOC_WRITE, (type), (nr),
struct.calcsize(size))
-def _IOWR(type,nr,size): return
_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),struct.calcsize(size))
+def _IOWR(type, nr, size): return _IOC(_IOC_READ|_IOC_WRITE, (type), (nr),
struct.calcsize(size))
# used to decode ioctl numbers..
def _IOC_DIR(nr): return (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
@@ -129,8 +129,7 @@
0 : 0, 2 : 2, 3 : 10, 4 : 11, 5 : 12,
}
try:
- if config.DEBUG >= 1:
- print 'streamTypeV4l2ToIVTV %s -> %s' % (stream_type,
map_v4l2_to_ivtv[stream_type])
+ _debug_('streamTypeV4l2ToIVTV %s -> %s' % (stream_type,
map_v4l2_to_ivtv[stream_type]))
return map_v4l2_to_ivtv[stream_type]
except:
print 'streamTypeV4l2ToIVTV %s failed' % (stream_type)
@@ -162,7 +161,6 @@
framespergop = tv.v4l2.Videodev.getcontrol(self, 'Video GOP Size')
gop_closure = tv.v4l2.Videodev.getcontrol(self, 'Video GOP
Closure')
pulldown = 0
- #pulldown = tv.v4l2.Videodev.getcontrol(self, 'Video Pulldown')
#insert_navigation_packets = tv.v4l2.Videodev.getcontrol(self,
'insert_navigation_packets')
stream_type =
self.streamTypeV4l2ToIVTV(tv.v4l2.Videodev.getcontrol(self, 'Stream Type'))
codec_list = (aspect, audio_bitmask, bframes, bitrate_mode,
bitrate, bitrate_peak,
@@ -170,7 +168,7 @@
pulldown, stream_type)
return IVTVCodec(codec_list)
- val = struct.pack( CODEC_ST, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 )
+ val = struct.pack( CODEC_ST, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0 )
r = fcntl.ioctl(self.device, i32(IVTV_IOC_G_CODEC), val)
codec_list = struct.unpack(CODEC_ST, r)
if config.DEBUG >= 3: print "getCodecInfo: val=%r, r=%r, res=%r" %
(val, r, struct.unpack(CODEC_ST, r))
@@ -265,7 +263,6 @@
VIDIOC_S_STD 'framerate' : 0,
'Video GOP Size' 'framespergop' : 12,
'Video GOP Closure' 'gop_closure' : 1,
- 'Video Pulldown' 'pulldown' : 0,
'Stream Type' 'stream_type' : 14,
'''
tv.v4l2.Videodev.updatecontrol(self, 'Video Aspect',
codec.aspect-1)
@@ -287,7 +284,6 @@
tv.v4l2.Videodev.updatecontrol(self, 'Median Filter Type',
codec.dnr_type)
tv.v4l2.Videodev.updatecontrol(self, 'Video GOP Size',
codec.framespergop)
tv.v4l2.Videodev.updatecontrol(self, 'Video GOP Closure',
codec.gop_closure)
- tv.v4l2.Videodev.updatecontrol(self, 'Video Pulldown',
codec.pulldown)
tv.v4l2.Videodev.updatecontrol(self, 'Stream Type',
self.streamTypeIvtvToV4l2(codec.stream_type))
return
@@ -302,10 +298,10 @@
codec.dnr_spatial,
codec.dnr_temporal,
codec.dnr_type,
- codec.framerate, #read only, ignored on write
- codec.framespergop, #read only, ignored on write
+ codec.framerate, # read only, ignored on write
+ codec.framespergop, # read only, ignored on write
codec.gop_closure,
- codec.pulldown,
+ codec.pulldown, # removed from ivtv driver
codec.stream_type)
r = fcntl.ioctl(self.device, i32(IVTV_IOC_S_CODEC), val)
if config.DEBUG >= 3: print "setCodecInfo: val=%r, r=%r" % (val, r)
@@ -324,11 +320,11 @@
if self.version >= 0x800:
return self.getcontrol('Stream VBI Format')
try:
- r = fcntl.ioctl(self.device, i32(GETVBI_EMBED_NO),
struct.pack(VBI_EMBED_ST,0))
+ r = fcntl.ioctl(self.device, i32(GETVBI_EMBED_NO),
struct.pack(VBI_EMBED_ST, 0))
if config.DEBUG >= 3:
- print "getvbiembed: val=%r, r=%r, res=%r" %
(struct.pack(VBI_EMBED_ST,0), r,
- struct.unpack(VBI_EMBED_ST,r))
- return struct.unpack(VBI_EMBED_ST,r)[0]
+ print "getvbiembed: val=%r, r=%r, res=%r" %
(struct.pack(VBI_EMBED_ST, 0), r,
+ struct.unpack(VBI_EMBED_ST, r))
+ return struct.unpack(VBI_EMBED_ST, r)[0]
except IOError:
print 'getvbiembed: failed'
return 0
@@ -359,8 +355,8 @@
(width, height) = string.split(opts['resolution'], 'x')
self.setfmt(int(width), int(height))
- if self.version >= 0x800:
- tv.v4l2.Videodev.getcontrols(self)
+ #if self.version >= 0x800:
+ # tv.v4l2.Videodev.enumcontrols(self)
codec = self.getCodecInfo()
@@ -448,7 +444,7 @@
config.DEBUG = 0
- ivtv_dev = IVTV('/dev/video0')
+ ivtv_dev = IVTV('/dev/video1')
ivtv_dev.init_settings()
ivtv_dev.listcontrols()
x = ivtv_dev.getcontrol('Spatial Luma Filter Type')
Modified: branches/rel-1/freevo/src/tv/plugins/ivtv_record.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/ivtv_record.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/ivtv_record.py Mon Oct 22 10:29:27 2007
@@ -124,8 +124,8 @@
v.init_settings()
vg = fc.getVideoGroup(self.prog.tunerid, False)
- _debug_('Setting Input to %s' % vg.input_num)
- v.setinput(vg.input_num)
+ _debug_('Setting Input to %s' % vg.input_type)
+ v.setinputbyname(vg.input_type)
cur_std = v.getstd()
try:
Modified: branches/rel-1/freevo/src/tv/plugins/ivtv_xine_tv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/ivtv_xine_tv.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/ivtv_xine_tv.py Mon Oct 22
10:29:27 2007
@@ -228,8 +228,7 @@
| VideoGroup(
| vdev='/dev/video0',
| adev=None,
- | input_type='tuner',
- | input_num=0,
+ | input_type='Tuner 1',
| tuner_norm='pal',
| tuner_chanlist='europe-west',
| desc='Regular Cable',
@@ -239,8 +238,7 @@
| VideoGroup(
| vdev='/dev/video0',
| adev=None,
- | input_type='svideo',
- | input_num=1,
+ | input_type='S-Video 1',
| tuner_type='external',
| desc='S-Video Input',
| group_type='ivtv',
@@ -249,15 +247,14 @@
| VideoGroup(
| vdev='/dev/video0',
| adev=None,
- | input_type='composite',
- | input_num=5,
+ | input_type='Composite 2',
| tuner_type='external',
| desc='Composite Input',
| group_type='ivtv',
| record_group = None
| ),
| ]
- |
+ |
| TV_CHANNELS = [
| ('ned1', 'NED 1', 'C22', '', 0),
| ...
Modified: branches/rel-1/freevo/src/tv/plugins/mplayer.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/mplayer.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/mplayer.py Mon Oct 22 10:29:27 2007
@@ -84,9 +84,9 @@
vg = self.current_vg = self.fc.getVideoGroup(tuner_channel, True)
# Convert to MPlayer TV setting strings
- norm = 'norm=%s' % vg.tuner_norm
- input = 'input=%s' % vg.input_num
device= 'device=%s' % vg.vdev
+ input = 'input=%s' % vg.input_num
+ norm = 'norm=%s' % vg.tuner_norm
w, h = config.TV_VIEW_SIZE
outfmt = 'outfmt=%s' % config.TV_VIEW_OUTFMT
@@ -99,7 +99,7 @@
if vg.group_type == 'ivtv':
ivtv_dev = ivtv.IVTV(vg.vdev)
ivtv_dev.init_settings()
- ivtv_dev.setinput(vg.input_num)
+ ivtv_dev.setinputbyname(vg.input_type)
cur_std = ivtv_dev.getstd()
import tv.v4l2
try:
Modified: branches/rel-1/freevo/src/tv/plugins/tvtime.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/tvtime.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/tvtime.py Mon Oct 22 10:29:27 2007
@@ -432,14 +432,8 @@
_debug_('starting channel is %s' % mychan)
- command = '%s %s -k -I %s -n %s -d %s -f %s -c %s -i %s' %
(config.TVTIME_CMD,
-
outputplugin,
- w,
- s_norm,
- cf_device,
- 'freevo',
- mychan,
- cf_input)
+ command = '%s %s -k -I %s -n %s -d %s -f %s -c %s -i %s' % \
+ (config.TVTIME_CMD, outputplugin, w, s_norm, cf_device,
'freevo', mychan, cf_input)
if osd.get_fullscreen() == 1:
command += ' -m'
Modified: branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py Mon Oct 22
10:29:27 2007
@@ -63,7 +63,7 @@
class PluginInterface(plugin.Plugin):
"""
Record subtitles from teletext pages (IVTV cards only)
- Also uses the PDC (Programme Delivery Control) from VPS (Video
+ Also uses the PDC (Programme Delivery Control) from VPS (Video
Programming Signal) to start and stop the recording.
The teletext page number is taken from TV_CHANNELS, eg:
@@ -220,16 +220,13 @@
fc = FreevoChannels()
_debug_('channel %s' % fc.getChannel())
- (v_norm, v_input, v_clist, v_dev) = config.TV_SETTINGS.split()
+ self.vg = fc.getVideoGroup(self.prog.tunerid, False)
- v = tv.ivtv.IVTV(v_dev)
+ v = tv.ivtv.IVTV(self.vg.vdev)
v.init_settings()
- self.vg = fc.getVideoGroup(self.prog.tunerid, False)
_debug_('Using video device %s' % self.vg.vdev)
- _debug_('Setting Input to %s' % self.vg.input_num)
- v.setinput(self.vg.input_num)
_debug_('Setting Channel to %s' % self.prog.tunerid)
fc.chanSet(str(self.prog.tunerid), False)
Modified: branches/rel-1/freevo/src/tv/v4l2.py
==============================================================================
--- branches/rel-1/freevo/src/tv/v4l2.py (original)
+++ branches/rel-1/freevo/src/tv/v4l2.py Mon Oct 22 10:29:27 2007
@@ -64,19 +64,19 @@
_IOC_WRITE = 1
_IOC_READ = 2
-def _IOC(dir,type,nr,size):
+def _IOC(dir, type, nr, size):
return (((dir) << _IOC_DIRSHIFT) | \
(ord(type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
-def _IO(type,nr): return _IOC(_IOC_NONE,(type),(nr),0)
+def _IO(type, nr): return _IOC(_IOC_NONE, (type), (nr), 0)
-def _IOR(type,nr,size): return
_IOC(_IOC_READ,(type),(nr),struct.calcsize(size))
+def _IOR(type, nr, size): return _IOC(_IOC_READ, (type), (nr),
struct.calcsize(size))
-def _IOW(type,nr,size): return
_IOC(_IOC_WRITE,(type),(nr),struct.calcsize(size))
+def _IOW(type, nr, size): return _IOC(_IOC_WRITE, (type), (nr),
struct.calcsize(size))
-def _IOWR(type,nr,size): return
_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),struct.calcsize(size))
+def _IOWR(type, nr, size): return _IOC(_IOC_READ|_IOC_WRITE, (type), (nr),
struct.calcsize(size))
# used to decode ioctl numbers..
def _IOC_DIR(nr): return (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
@@ -88,11 +88,11 @@
QUERYCAP_ST = "<16s32s32sII16x"
-QUERYCAP_NO = _IOR('V', 0, QUERYCAP_ST)
+QUERYCAP_NO = _IOR('V', 0, QUERYCAP_ST)
FMT_ST = bit32 and "<I7I4x168x" or "<Q7I4x168x"
-GET_FMT_NO = _IOWR('V', 4, FMT_ST)
-SET_FMT_NO = _IOWR('V', 5, FMT_ST)
+GET_FMT_NO = _IOWR('V', 4, FMT_ST)
+SET_FMT_NO = _IOWR('V', 5, FMT_ST)
SETFREQ_NO_V4L = _IOW('v', 15, "L")
@@ -192,13 +192,49 @@
}
NORMS = {
- 'NTSC' : 0x00003000,
- 'PAL' : 0x000000ff,
- 'SECAM' : 0x007f0000,
- 'SECAM-DK' : 0x00320000,
+ 'PAL_B' : 0x00000001,
+ 'PAL_B1' : 0x00000002,
+ 'PAL_G' : 0x00000004,
+ 'PAL_H' : 0x00000008,
+ 'PAL_I' : 0x00000010,
+ 'PAL_D' : 0x00000020,
+ 'PAL_D1' : 0x00000040,
+ 'PAL_K' : 0x00000080,
+ 'PAL_M' : 0x00000100,
+ 'PAL_N' : 0x00000200,
+ 'PAL_Nc' : 0x00000400,
+ 'PAL_60' : 0x00000800,
+ 'NTSC_M' : 0x00001000,
+ 'NTSC_M_JP' : 0x00002000,
+ 'NTSC_443' : 0x00004000,
+ 'NTSC_M_KR' : 0x00008000,
+ 'SECAM_B' : 0x00010000,
+ 'SECAM_D' : 0x00020000,
+ 'SECAM_G' : 0x00040000,
+ 'SECAM_H' : 0x00080000,
+ 'SECAM_K' : 0x00100000,
+ 'SECAM_K1' : 0x00200000,
+ 'SECAM_L' : 0x00400000,
+ 'SECAM_LC' : 0x00800000,
+ 'ATSC_8_VSB' : 0x01000000,
+ 'ATSC_16_VSB' : 0x02000000,
+
+ 'PAL_BG' : 0x00000007,
+ 'B' : 0x00010003,
+ 'GH' : 0x000C000C,
+ 'PAL_DK' : 0x000000E0,
+ 'PAL' : 0x000000FF,
+ 'NTSC' : 0x0000B000,
+ 'MN' : 0x0000B700,
+ 'SECAM_DK' : 0x00320000,
+ 'DK' : 0x003200E0,
+ 'SECAM' : 0x00FF0000,
+ '525_60' : 0x0000F900,
+ '625_50' : 0x00FF06FF,
+ 'UNKNOWN' : 0x00000000,
+ 'ALL' : 0x00FFFFFF,
}
-
class Videodev:
def __init__(self, device):
self.chanlist = None
@@ -214,7 +250,12 @@
self.bus_info = results[2]
self.version = results[3]
self.capabilities = results[4]
+ self.inputs = {}
+ self.standards = {}
self.controls = {}
+ self.inputs = self.enuminputs()
+ self.standards = self.enumstds()
+ self.controls = self.enumcontrols()
def getdriver(self):
@@ -237,17 +278,25 @@
self.chanlist = freq.CHANLIST[chanlist]
+ def querycap(self):
+ val = struct.pack(QUERYCAP_ST, "", "", "", 0, 0)
+ r = fcntl.ioctl(self.device, i32(QUERYCAP_NO), val)
+ res = struct.unpack(QUERYCAP_ST, r)
+ _debug_('querycap: val=%r, %d, res=%r' % (val, len(val), res), 3)
+ return res
+
+
def getfreq(self):
- val = struct.pack(FREQUENCY_ST, 0,0,0)
+ val = struct.pack(FREQUENCY_ST, 0, 0, 0)
r = fcntl.ioctl(self.device, i32(GETFREQ_NO), val)
res = struct.unpack(FREQUENCY_ST, r)
_debug_('getfreq: val=%r, r=%r, res=%r' % (val, r, res), 3)
- (tuner, type, freq,) = res
+ (tuner, type, freq, ) = res
return freq
def getfreq2(self):
- val = struct.pack(FREQUENCY_ST, 0,0,0)
+ val = struct.pack(FREQUENCY_ST, 0, 0, 0)
r = fcntl.ioctl(self.device, i32(GETFREQ_NO), val)
res = struct.unpack(FREQUENCY_ST, r)
_debug_('getfreq2: val=%r, r=%s, res=%r' % (val, r, res), 3)
@@ -289,10 +338,38 @@
_debug_('setfreq: val=%r, r=%r' % (val, r), 3)
+ def enuminput(self, num):
+ """
+ Enumerate a video device input
+ @param num is the input number
+ """
+ val = struct.pack(ENUMINPUT_ST, num, "", 0, 0, 0, 0, 0)
+ r = fcntl.ioctl(self.device, i32(ENUMINPUT_NO), val)
+ res = struct.unpack(ENUMINPUT_ST, r)
+ _debug_('enuminput: val=%r, %d, res=%r' % (val, len(val), res), 3)
+ return res
+
+ def enuminputs(self):
+ """
+ Enumerate all inputs
+ @returns a dict of the inputs index by name
+ """
+ res = {}
+ num = 0
+ try:
+ while 1:
+ (index, name, type, audioset, tuner, std, status) =
self.enuminput(num)
+ name = name.rstrip('\0')
+ res[name.lower()] = (index, name, type, audioset, tuner, std,
status)
+ num += 1
+ except IOError, e:
+ pass
+ return res
+
def getinput(self):
- val = struct.pack(INPUT_ST,0)
+ val = struct.pack(INPUT_ST, 0)
r = fcntl.ioctl(self.device, i32(GETINPUT_NO), val)
- res = struct.unpack(INPUT_ST,r)
+ res = struct.unpack(INPUT_ST, r)
_debug_('getinput: val=%r, %d, res=%r' % (val, len(val), res), 3)
return res[0]
@@ -306,23 +383,50 @@
raise
- def querycap(self):
- val = struct.pack(QUERYCAP_ST, "", "", "", 0, 0)
- r = fcntl.ioctl(self.device, i32(QUERYCAP_NO), val)
- res = struct.unpack(QUERYCAP_ST, r)
- _debug_('querycap: val=%r, %d, res=%r' % (val, len(val), res), 3)
- return res
+ def setinputbyname(self, name):
+ """
+ Set the TV input by name, eg: TELEVISION, s-video
+ """
+ v_input = name.lower()
+ try:
+ (index, name, type, audioset, tuner, std, status) =
self.inputs[v_input]
+ self.setinput(index)
+ except KeyError, e:
+ _debug_('setinputbyname failed: %s' % (e), DERROR)
+ raise
+ _debug_('setinputbyname: %s->%s set' % (name, index))
- def enumstd(self, no):
- val = struct.pack(ENUMSTD_ST, no, 0, "", 0, 0, 0)
+ def enumstd(self, num):
+ val = struct.pack(ENUMSTD_ST, num, 0, "", 0, 0, 0)
r = fcntl.ioctl(self.device, i32(ENUMSTD_NO), val)
res = struct.unpack(ENUMSTD_ST, r)
_debug_('enumstd: val=%r, %d, res=%r' % (val, len(val), res), 3)
return res
+ def enumstds(self):
+ """
+ Enumerate the TV standards
+ @returns a dict of the standards index by name
+ """
+ res = {}
+ num = 0
+ try:
+ while 1:
+ (index, id, name, frameperiod, framelines, reserved) =
self.enumstd(num)
+ name = name.rstrip('\0')
+ res[name.lower()] = (index, id, name, frameperiod, framelines)
+ num += 1
+ except IOError, e:
+ pass
+ return res
+
+
def getstd(self):
+ """
+ Get the current TV standard
+ """
val = struct.pack(STANDARD_ST, 0)
r = fcntl.ioctl(self.device, i32(GETSTD_NO), val)
res = struct.unpack(STANDARD_ST, r)
@@ -331,13 +435,29 @@
def setstd(self, value):
+ """
+ Set the TV standard by number
+ """
val = struct.pack(STANDARD_ST, value)
r = fcntl.ioctl(self.device, i32(SETSTD_NO), val)
_debug_('setstd: val=%r, r=%r' % (val, r), 3)
- def enuminput(self,index):
- val = struct.pack(ENUMINPUT_ST, index, "", 0,0,0,0,0)
+ def setstdbyname(self, name):
+ """
+ Set the TV standard by name, eg: PAL-BGH, secam-dk, etc
+ """
+ v_norm = name.upper()
+ try:
+ _debug_('setstdbyname: %s (0x%08X) set' % (name, NORMS[v_norm]))
+ self.setstd(NORMS.get(v_norm))
+ except KeyError, e:
+ _debug_('setstdbyname failed: %s' % (e), DERROR)
+ _debug_('setstdbyname: %s (0x%08X) set' % (name, NORMS[v_norm]))
+
+
+ def enuminput(self, num):
+ val = struct.pack(ENUMINPUT_ST, num, "", 0, 0, 0, 0, 0)
r = fcntl.ioctl(self.device, i32(ENUMINPUT_NO), val)
res = struct.unpack(ENUMINPUT_ST, r)
_debug_('enuminput: val=%r, %d, res=%r' % (val, len(val), res), 3)
@@ -345,7 +465,7 @@
def getfmt(self):
- val = struct.pack(FMT_ST, 1,0,0,0,0,0,0,0)
+ val = struct.pack(FMT_ST, 1, 0, 0, 0, 0, 0, 0, 0)
r = fcntl.ioctl(self.device, i32(GET_FMT_NO), val)
res = struct.unpack(FMT_ST, r)
_debug_('getfmt: val=%r, %d, res=%r' % (val, len(val), res), 3)
@@ -358,30 +478,30 @@
_debug_('setfmt: val=%r, r=%r' % (val, r), 3)
- def gettuner(self,index):
- val = struct.pack(TUNER_ST, index, "", 0,0,0,0,0,0,0,0)
+ def gettuner(self, num):
+ val = struct.pack(TUNER_ST, num, "", 0, 0, 0, 0, 0, 0, 0, 0)
r = fcntl.ioctl(self.device, i32(GET_TUNER_NO), val)
res = struct.unpack(TUNER_ST, r)
_debug_('gettuner: val=%r, %d, res=%r' % (val, len(val), res), 3)
return res
- def settuner(self,index,audmode):
- val = struct.pack(TUNER_ST, index, "", 0,0,0,0,0,audmode,0,0)
+ def settuner(self, num, audmode):
+ val = struct.pack(TUNER_ST, num, "", 0, 0, 0, 0, 0, audmode, 0, 0)
r = fcntl.ioctl(self.device, i32(SET_TUNER_NO), val)
_debug_('settuner: val=%r, r=%r' % (val, r), 3)
- def getaudio(self,index):
- val = struct.pack(AUDIO_ST, index, "", 0,0)
+ def getaudio(self, num):
+ val = struct.pack(AUDIO_ST, num, "", 0, 0)
r = fcntl.ioctl(self.device, i32(GET_AUDIO_NO), val)
res = struct.unpack(AUDIO_ST, r)
_debug_('getaudio: val=%r, %d, res=%r' % (val, len(val), res), 3)
return res
- def setaudio(self,index,mode):
- val = struct.pack(AUDIO_ST, index, "", mode, 0)
+ def setaudio(self, num, mode):
+ val = struct.pack(AUDIO_ST, num, "", mode, 0)
r = fcntl.ioctl(self.device, i32(SET_AUDIO_NO), val)
_debug_('setaudio: val=%r, r=%r' % (val, r), 3)
@@ -447,8 +567,8 @@
_debug_('setextctrl(%s) %r: %s' % (id, self.findcontrol(id), e),
DWARNING)
- def querymenu(self, id, index):
- val = struct.pack(QUERYMENU_ST, id, index, "", 0)
+ def querymenu(self, id, num):
+ val = struct.pack(QUERYMENU_ST, id, num, "", 0)
try:
r = fcntl.ioctl(self.device, i32(QUERYMENU_NO), val)
res = struct.unpack(QUERYMENU_ST, r)
@@ -487,7 +607,7 @@
print 'id=%08x, type=%s, name=\"%s\", min=%d, max=%d, step=%d,
default=%d, flags=%04x value=%d' % \
(id, V4L2_CTRL_TYPES[type], name, min, max, step, default, flags,
value)
if type == V4L2_CTRL_TYPE_MENU:
- for i in range(min,max+1):
+ for i in range(min, max+1):
(id, index, name, res1) = self.querymenu(id, i)
print 'index=%d, name=\"%s\"' % (index, name)
@@ -520,7 +640,7 @@
break
- def getcontrols(self):
+ def enumcontrols(self):
self.controls = {}
id = V4L2_CTRL_FLAG_NEXT_CTRL
while 1:
@@ -609,10 +729,11 @@
''' initialise the V4L2 setting
'''
(v_norm, v_input, v_clist, v_dev) = config.TV_SETTINGS.split()
- v_norm = string.upper(v_norm)
- self.setstd(NORMS.get(v_norm))
+ self.inputs = self.enuminputs()
+ self.standards = self.enumstds()
+ self.controls = self.enumcontrols()
+ self.setstdbyname(v_norm)
self.setchanlist(v_clist)
- self.getcontrols()
# XXX TODO: make a good way of setting the input
# self.setinput(....)
@@ -626,8 +747,8 @@
print "Enumerating supported Standards."
try:
- for i in range(0,255):
- (index,id,name,junk,junk,junk) = self.enumstd(i)
+ for i in range(0, 255):
+ (index, id, name, junk, junk, junk) = self.enumstd(i)
print " %i: 0x%x %s" % (index, id, name.strip('\0'))
except:
pass
@@ -635,8 +756,8 @@
print "Enumerating supported Inputs."
try:
- for i in range(0,255):
- (index,name,type,audioset,tuner,std,status) = self.enuminput(i)
+ for i in range(0, 255):
+ (index, name, type, audioset, tuner, std, status) =
self.enuminput(i)
print " %i: %s" % (index, name.strip('\0'))
except:
pass
@@ -644,7 +765,7 @@
(buf_type, width, height, pixelformat, field, bytesperline,
sizeimage, colorspace) = self.getfmt()
- print "Width: %i, Height: %i" % (width,height)
+ print "Width: %i, Height: %i" % (width, height)
print "Read Frequency: %i" % self.getfreq()
@@ -678,7 +799,7 @@
print 'Driver = \"%s\"' % viddev.getdriver()
print 'Driver Version = %02d.%02d' % (viddev.getversion() / 256,
viddev.getversion() % 256)
viddev.print_settings()
- viddev.getcontrols()
+ viddev.enumcontrols()
viddev.listcontrols()
ctrlname = 'Median Luma Filter Minimum'
ctrlkey = 'median_luma_filter_minimum'
@@ -692,12 +813,53 @@
viddev.setcontrol(ctrlname, mlfm+1)
print '%s -> %s %s' % (mlfm, viddev.getcontrol(ctrlname),
viddev.getextctrl(ctrlcode))
- #dict = viddev.getcontrols()
+ NORMS['PAL_BG'] = (NORMS['PAL_B']+NORMS['PAL_B1']+NORMS['PAL_G'])
+ NORMS['B'] = (NORMS['PAL_B']+NORMS['PAL_B1']+NORMS['SECAM_B'])
+ NORMS['GH'] =
(NORMS['PAL_G']+NORMS['PAL_H']+NORMS['SECAM_G']+NORMS['SECAM_H'])
+ NORMS['PAL_DK'] = (NORMS['PAL_D']+NORMS['PAL_D1']+NORMS['PAL_K'])
+ NORMS['PAL'] =
(NORMS['PAL_BG']+NORMS['PAL_DK']+NORMS['PAL_H']+NORMS['PAL_I'])
+ NORMS['NTSC'] = (NORMS['NTSC_M']+NORMS['NTSC_M_JP']+NORMS['NTSC_M_KR'])
+ NORMS['MN'] = (NORMS['PAL_M']+NORMS['PAL_N']+NORMS['PAL_Nc']+NORMS['NTSC'])
+ NORMS['SECAM_DK'] = (NORMS['SECAM_D']+NORMS['SECAM_K']+NORMS['SECAM_K1'])
+ NORMS['DK'] = (NORMS['PAL_DK']+NORMS['SECAM_DK'])
+ NORMS['SECAM'] =
(NORMS['SECAM_B']+NORMS['SECAM_G']+NORMS['SECAM_H']+NORMS['SECAM_DK']+NORMS['SECAM_L']+NORMS['SECAM_LC'])
+ NORMS['525_60'] =
(NORMS['PAL_M']+NORMS['PAL_60']+NORMS['NTSC']+NORMS['NTSC_443'])
+ NORMS['625_50'] =
(NORMS['PAL']+NORMS['PAL_N']+NORMS['PAL_Nc']+NORMS['SECAM'])
+ NORMS['UNKNOWN'] = 0
+ NORMS['ALL'] = (NORMS['525_60']+NORMS['625_50'])
+
+ print '\'%s\' : 0x%08X, ' % ('PAL_BG', NORMS['PAL_BG'])
+ print '\'%s\' : 0x%08X, ' % ('B', NORMS['B'])
+ print '\'%s\' : 0x%08X, ' % ('GH', NORMS['GH'])
+ print '\'%s\' : 0x%08X, ' % ('PAL_DK', NORMS['PAL_DK'])
+ print '\'%s\' : 0x%08X, ' % ('PAL', NORMS['PAL'])
+ print '\'%s\' : 0x%08X, ' % ('NTSC', NORMS['NTSC'])
+ print '\'%s\' : 0x%08X, ' % ('MN', NORMS['MN'])
+ print '\'%s\' : 0x%08X, ' % ('SECAM_DK', NORMS['SECAM_DK'])
+ print '\'%s\' : 0x%08X, ' % ('DK', NORMS['DK'])
+ print '\'%s\' : 0x%08X, ' % ('SECAM', NORMS['SECAM'])
+ print '\'%s\' : 0x%08X, ' % ('525_60', NORMS['525_60'])
+ print '\'%s\' : 0x%08X, ' % ('625_50', NORMS['625_50'])
+ print '\'%s\' : 0x%08X, ' % ('UNKNOWN', NORMS['UNKNOWN'])
+ print '\'%s\' : 0x%08X, ' % ('ALL', NORMS['ALL'])
+
+ inputs = viddev.enuminputs()
+ print inputs
+ standards = viddev.enumstds()
+ print standards
+ viddev.setinputbyname('Composite1')
+ print viddev.getinput()
+ viddev.setstdbyname('PAL')
+ print '0x%08X' % viddev.getstd()
+ viddev.setinputbyname('Television')
+ print viddev.getinput()
+
+ #dict = viddev.enumcontrols()
#keys = list(dict)
#keys.sort()
#print keys
#for ctrl in keys:
- # print '%-28s : %r' % (ctrl, dict[ctrl],)
+ # print '%-28s : %r' % (ctrl, dict[ctrl], )
##print viddev.querycap()
#inp = viddev.getinput()
@@ -712,7 +874,7 @@
#print 'std:', std
#print 'CONTROLS'
#viddev.listcontrols()
- #dict = viddev.getcontrols()
+ #dict = viddev.enumcontrols()
#viddev.setextctrl(0x009909c9, 2)
#print '0x009909c9 = %d' % viddev.getextctrl(0x009909c9)
#viddev.setextctrl(0x009909cf, 7000000)
@@ -747,11 +909,10 @@
#viddev.setinput(inp)
#print 'viddev.setinput okay'
#fmt = viddev.getfmt()
- #(buf_type, width, height, pixelformat, field, bytesperline,
- #sizeimage, colorspace) = fmt
+ #(buf_type, width, height, pixelformat, field, bytesperline, #sizeimage,
colorspace) = fmt
#print 'viddev.getfmt=%s' % (buf_type)
#print viddev.enuminput(inp)
- #for i in range(0,99):
+ #for i in range(0, 99):
#try:
#print viddev.gettuner(i)
#except IOError:
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog