Author: duncan
Date: Thu Nov  1 14:57:59 2007
New Revision: 10053

Log:
Some fixed to v4l2 and it configuration


Modified:
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/src/config.py
   branches/rel-1/freevo/src/tv/v4l2.py

Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Thu Nov  1 14:57:59 2007
@@ -293,7 +293,7 @@
      XMLTV_FILE, you may also prefer OVERLAY_DIR to be 
FREEVO_STATICDIR+'/overlay',
      Added a plugin that adds a submenu entry for ejecting rom drives and 
binds the default action of
      an empty drive to the eject action
-     Replaced OSD_OVERSCAN_X with OSD_OVERSCAN_LEFT and OSD_OVERSCAN_RIGHT and 
OSD_OVERSCAN_Y with 
+     Replaced OSD_OVERSCAN_X with OSD_OVERSCAN_LEFT and OSD_OVERSCAN_RIGHT and 
OSD_OVERSCAN_Y with
      OSD_OVERSCAN_TOP and OSD_OVERSCAN_BOTTOM
      Added IMAGEVIEW_ASPECT to show images correctly on non-square pixel 
displays, it TVs
      For the webserver configuration tool the following have been changed
@@ -374,7 +374,7 @@
 
 MIXER_MAJOR_CTRL      = 'VOL'        # Freevo takes control over one audio ctrl
                                      # 'VOL', 'PCM' 'OGAIN' etc.
-MIXER_MAJOR_MUTE_CTRL = 'PCM'        # used in alsamixer.py, There are systems 
where 
+MIXER_MAJOR_MUTE_CTRL = 'PCM'        # used in alsamixer.py, There are systems 
where
                                      # volume and mute use different controls
 
 MIXER_DEVICE          = '/dev/mixer' # mixer device
@@ -1841,7 +1841,7 @@
 TV_VIDEO_GROUPS = [
     VideoGroup(vdev=TV_DEVICE,
                adev=AUDIO_DEVICE,
-               input_type='tuner',
+               input_num=0,
                tuner_norm=CONF.tv,
                tuner_chanlist=CONF.chanlist,
                desc='Default Video Group',

Modified: branches/rel-1/freevo/src/config.py
==============================================================================
--- branches/rel-1/freevo/src/config.py (original)
+++ branches/rel-1/freevo/src/config.py Thu Nov  1 14:57:59 2007
@@ -61,7 +61,7 @@
 DERROR = -2
 DCRITICAL = -3
 
-locale.setlocale(locale.LC_TIME,'')
+locale.setlocale(locale.LC_TIME, '')
 
 if float(sys.version[0:3]) >= 2.3:
     import warnings
@@ -183,7 +183,7 @@
         self.vdev = vdev
         self.vvbi = vvbi
         self.adev = adev
-        self.input_type = input_type
+        self.input_type = string.lower(input_type)
         self.input_num  = int(input_num)
         self.tuner_type = tuner_type
         self.tuner_norm = string.upper(tuner_norm)
@@ -195,7 +195,7 @@
         self.in_use = FALSE
         self.tuner = None
         self.cmd = None
-        if cmd != None and isinstance(cmd,str) and cmd.strip() != '':
+        if cmd != None and isinstance(cmd, str) and cmd.strip() != '':
             self.cmd = cmd.strip()
 
     def __str__(self):
@@ -204,6 +204,40 @@
         return s
 
 
+    def checkvdev(self, vdev):
+        """
+        Check if the video device is correctly configured
+        """
+        from tv.v4l2 import Videodev
+        try:
+            dev = Videodev(vdev)
+            try:
+                if input_type != 'webcam':
+                    try:
+                        if input_type:
+                            input_num = dev.getinputbyname(input_type)[0]
+                    except KeyError, e:
+                        print 'cannot find tuner %r for %r\npossible values 
are: %r' % \
+                            (input_type, vdev, dev.inputs.keys())
+                        sys.exit(1)
+                    try:
+                        if tuner_norm:
+                            tuner_std = dev.getstdbyname(tuner_norm)
+                    except KeyError, e:
+                        print 'cannot find norm %r for %r\npossible values 
are: %r' % \
+                            (tuner_norm, vdev, dev.standards.keys())
+                        sys.exit(1)
+                    print '%r:%r=%r' % (vdev, input_type, input_num)
+                    print '%r:%r=%r' % (vdev, tuner_norm, tuner_std)
+                else:
+                    print '%r:%r=%r' % (vdev, input_type, dev.inputs.keys())
+                    print '%r:%r=%r' % (vdev, tuner_norm, dev.standards.keys())
+            finally:
+                dev.close()
+        except OSError, e:
+            print 'Video device %r: %s' % (vdev, e)
+
+
 def print_config_changes(conf_version, file_version, changelist):
     """
     print changes made between version on the screen
@@ -401,7 +435,7 @@
     try:
         try:
             # add the current trace to the string
-            if isinstance( s, unicode ):
+            if isinstance(s, unicode):
                 s = s.encode(encoding, 'replace')
             where =  traceback.extract_stack(limit = 2)[0]
             msg = '%s (%s): %s' % (where[0][where[0].rfind('/')+1:], where[1], 
s)
@@ -439,8 +473,8 @@
 #
 # Config file handling
 #
-cfgfilepath = [ '.', os.path.expanduser('~/.freevo'), '/etc/freevo',
-                '/usr/local/etc/freevo' ]
+cfgfilepath = ['.', os.path.expanduser('~/.freevo'), '/etc/freevo',
+                '/usr/local/etc/freevo']
 
 
 #
@@ -734,13 +768,13 @@
 if ROM_DRIVES == None:
     ROM_DRIVES = []
     if os.path.isfile('/etc/fstab'):
-        re_cd        = re.compile( 
'^(/dev/cdrom[0-9]*|/dev/[am]?cd[0-9]+[a-z]?)[ \t]+([^ \t]+)[ \t]+', re.I )
-        re_cdrec     = re.compile( '^(/dev/cdrecorder[0-9]*)[ \t]+([^ \t]+)[ 
\t]+', re.I )
-        re_dvd       = re.compile( '^(/dev/dvd[0-9]*)[ \t]+([^ \t]+)[ \t]+', 
re.I )
-        re_iso       = re.compile( '^([^ \t]+)[ \t]+([^ \t]+)[ 
\t]+(iso|cd)9660', re.I )
-        re_automount = re.compile( '^none[ \t]+([^ 
\t]+).*supermount.*dev=([^,]+).*', re.I )
-        re_bymountcd = re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*cdrom[0-9]*)[ 
\t]+', re.I )
-        re_bymountdvd= re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*dvd[0-9]*)[ 
\t]+', re.I )
+        re_cd        = 
re.compile('^(/dev/cdrom[0-9]*|/dev/[am]?cd[0-9]+[a-z]?)[ \t]+([^ \t]+)[ \t]+', 
re.I)
+        re_cdrec     = re.compile('^(/dev/cdrecorder[0-9]*)[ \t]+([^ \t]+)[ 
\t]+', re.I)
+        re_dvd       = re.compile('^(/dev/dvd[0-9]*)[ \t]+([^ \t]+)[ \t]+', 
re.I)
+        re_iso       = re.compile('^([^ \t]+)[ \t]+([^ \t]+)[ 
\t]+(iso|cd)9660', re.I)
+        re_automount = re.compile('^none[ \t]+([^ 
\t]+).*supermount.*dev=([^,]+).*', re.I)
+        re_bymountcd = re.compile('^(/dev/[^ \t]+)[ \t]+([^ ]*cdrom[0-9]*)[ 
\t]+', re.I)
+        re_bymountdvd= re.compile('^(/dev/[^ \t]+)[ \t]+([^ ]*dvd[0-9]*)[ 
\t]+', re.I)
         fd_fstab = open('/etc/fstab')
         for line in fd_fstab:
             # Match on the devices /dev/cdrom, /dev/dvd, and fstype iso9660
@@ -782,7 +816,7 @@
                     print 'Trying to autodetect type of %s' % devname
                     if os.path.exists('/proc/ide/' + re.sub(r'^(/dev/)', '', 
devname) + '/media'):
                         if open('/proc/ide/'+  re.sub(r'^(/dev/)', '', 
devname) +\
-                             '/media','r').read().lower().find('cdrom') !=1:
+                             '/media', 'r').read().lower().find('cdrom') !=1:
                             dispname = 'CD-%s' % (len(ROM_DRIVES)+1)
                             print ("%s is a cdrom drive" %devname)
                     else:
@@ -809,7 +843,7 @@
             else:
                 # This was not a duplicate of another device
                 if mntdir and devname and dispname:
-                    ROM_DRIVES += [ (mntdir, devname, dispname) ]
+                    ROM_DRIVES += [(mntdir, devname, dispname)]
                     if not HELPER:
                         print 'ROM_DRIVES: Auto-detected and added "%s"' % 
(ROM_DRIVES[-1], )
         fd_fstab.close()
@@ -832,7 +866,7 @@
     # index for the tunerid and forcing 'int'
     for l in list:
         if len(l[key]) == 1:
-            l[key].append(('0',))
+            l[key].append(('0', ))
     nlist = map(lambda x, key=key: (string.split(x[key][1][0])[0], x), list)
     nlist.sort()
     return map(lambda (key, x): x, nlist)
@@ -852,7 +886,7 @@
     path = FREEVO_CACHEDIR
     pfile = 'xmltv_channels.pickle'
 
-    pname = os.path.join(path,pfile)
+    pname = os.path.join(path, pfile)
 
     if not os.path.isfile(file):
         if not HELPER:
@@ -895,7 +929,7 @@
         xmltv_channels = xmltv.read_channels(tmp)
         tmp.close()
 
-        xmltv_channels = sortchannels(xmltv_channels,'display-name')
+        xmltv_channels = sortchannels(xmltv_channels, 'display-name')
         chanlist = []
 
         for a in xmltv_channels:
@@ -907,7 +941,7 @@
                 tunerid = string.split(a['display-name'][0][0].encode(LOCALE, 
'ignore'))[0]
             id = a['id'].encode(LOCALE, 'ignore')
 
-            chanlist += [(id,display_name,tunerid)]
+            chanlist += [(id, display_name, tunerid)]
 
         f = lambda a, b: cmp(int(a[2]), int(b[2]))
         chanlist.sort(f)
@@ -995,11 +1029,11 @@
 
 encoding = None
 try:
-    encoding = os.environ[ 'LANG' ].split( '.' )[ 1 ]
+    encoding = os.environ['LANG'].split('.')[1]
     ''.encode(encoding)
 except:
     try:
-        encoding = os.environ[ 'LC_ALL' ].split( '.' )[ 1 ]
+        encoding = os.environ['LC_ALL'].split('.')[1]
         ''.encode(encoding)
     except:
         encoding = LOCALE
@@ -1008,9 +1042,9 @@
     encoding = LOCALE
 
 if not HELPER:
-    _debug_( "Using '%s' encoding" % encoding )
+    _debug_("Using '%s' encoding" % encoding)
 
-for k,v in CONF.__dict__.items():
+for k, v in CONF.__dict__.items():
     _debug_('%r: %r' % (k, v))
 
 # make sure USER and HOME are set

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        Thu Nov  1 14:57:59 2007
@@ -39,6 +39,7 @@
 
 import config
 
+
 # Different formats depending on word size
 bit32 = struct.calcsize('L') == struct.calcsize('I')
 
@@ -238,11 +239,11 @@
 class Videodev:
     def __init__(self, device):
         self.chanlist = None
-        self.device = os.open (device, os.O_TRUNC)
+        self.device = os.open(device, os.O_TRUNC)
         if self.device < 0:
             sys.exit('Error: %d' % self.device)
         else:
-            _debug_('Video Opened at %s' % device)
+            _debug_('Video opened for %r' % device)
 
         results           = self.querycap()
         self.driver       = results[0]
@@ -250,12 +251,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()
+        #print 'inputs=%r' % self.inputs
+        #print 'standards=%r' % self.standards
+        #print 'controls=%r' % self.controls
 
 
     def getdriver(self):
@@ -383,6 +384,14 @@
             raise
 
 
+    def getinputbyname(self, name):
+        """
+        Get the TV input by name, eg: TELEVISION, s-video
+        """
+        v_input = name.lower()
+        return self.inputs[v_input]
+
+
     def setinputbyname(self, name):
         """
         Set the TV input by name, eg: TELEVISION, s-video
@@ -417,7 +426,7 @@
             while 1:
                 (index, id, name, frameperiod, framelines, reserved) = 
self.enumstd(num)
                 name = name.rstrip('\0')
-                res[name.lower()] = (index, id, name, frameperiod, framelines)
+                res[name.upper()] = (index, id, name, frameperiod, framelines)
                 num += 1
         except IOError, e:
             pass
@@ -444,6 +453,14 @@
         _debug_('setstd: val=%r, r=%r' % (val, r), 3)
 
 
+    def getstdbyname(self, name):
+        """
+        Get the TV standard by name, eg: PAL-BGH, secam-dk, etc
+        """
+        v_norm = name.upper()
+        return self.standards[v_norm]
+
+
     def setstdbyname(self, name):
         """
         Set the TV standard by name, eg: PAL-BGH, secam-dk, etc
@@ -451,7 +468,7 @@
         v_norm = name.upper()
         try:
             _debug_('setstdbyname: %s (0x%08X) set' % (name, NORMS[v_norm]))
-            self.setstd(NORMS.get(v_norm))
+            self.setstd(NORMS[v_norm])
         except KeyError, e:
             _debug_('setstdbyname failed: %s' % (e), DERROR)
             _debug_('possible are: %r' % (NORMS.keys()), DINFO)
@@ -509,9 +526,9 @@
 
 
     def getctrl(self, id):
-        '''
+        """
         Get the value of a control
-        '''
+        """
         val = struct.pack(CTRL_ST, id, 0)
         r = fcntl.ioctl(self.device, i32(G_CTRL_NO), val)
         res = struct.unpack(CTRL_ST, r)
@@ -520,9 +537,9 @@
 
 
     def setctrl(self, id, value):
-        '''
+        """
         Set the value of a control
-        '''
+        """
         val = struct.pack(CTRL_ST, id, value)
         r = fcntl.ioctl(self.device, i32(S_CTRL_NO), val)
         res = struct.unpack(CTRL_ST, r)
@@ -530,11 +547,11 @@
 
 
     def getextctrl(self, id):
-        '''
+        """
         Get the value of an external control
         EXT_CTRL_type->id, res1, res2, value
         EXT_CTRLS_ST->class, count, error_idx, res1, res2, ptr
-        '''
+        """
         extctrl = array.array('B')
         extctrl.fromstring(struct.pack(EXT_CTRL_ST, id, 0, 0, 0))
         extctrl_p = extctrl.buffer_info()[0]
@@ -552,9 +569,9 @@
 
 
     def setextctrl(self, id, value):
-        '''
+        """
         Set the value of an external control
-        '''
+        """
         extctrl = array.array('B')
         extctrl.fromstring(struct.pack(EXT_CTRL_ST, id, 0, 0, value))
         extctrl_p = extctrl.buffer_info()[0]
@@ -615,12 +632,16 @@
 
 
     def ctrlname(self, name):
-        ''' converts a control to lowercase and replaces spaces with 
underscore, like v4l2-ctl
-        '''
+        """
+        converts a control to lowercase and replaces spaces with underscore, 
like v4l2-ctl
+        """
         return name.replace(' ', '_').lower()
 
 
     def listcontrols(self):
+        """
+        prints all the controls
+        """
         id = V4L2_CTRL_FLAG_NEXT_CTRL
         while 1:
             try:
@@ -643,39 +664,39 @@
 
 
     def enumcontrols(self):
-        self.controls = {}
+        res = {}
         id = V4L2_CTRL_FLAG_NEXT_CTRL
         while 1:
             try:
-                res = self.queryctrl(id)
-                (id, type, name, min, max, step, default, flags, value) = res
+                ctrl = self.queryctrl(id)
+                (id, type, name, min, max, step, default, flags, value) = ctrl
                 if flags == V4L2_CTRL_FLAG_DISABLED:
-                    id = res[0] | V4L2_CTRL_FLAG_NEXT_CTRL
+                    id = ctrl[0] | V4L2_CTRL_FLAG_NEXT_CTRL
                     continue
-                key = self.ctrlname(name)
-                self.controls[key] = res
-                id = res[0] | V4L2_CTRL_FLAG_NEXT_CTRL
+                res[self.ctrlname(name)] = ctrl
+                id = ctrl[0] | V4L2_CTRL_FLAG_NEXT_CTRL
             except IOError, e:
                 break
         if id != V4L2_CTRL_FLAG_NEXT_CTRL:
-            return self.controls
+            return res
 
         id = V4L2_CID_USER_BASE
         for id in range(V4L2_CID_FIRSTP1, V4L2_CID_LASTP1):
             try:
-                res = self.queryctrl(id)
-                (id, type, name, min, max, step, default, flags, value) = res
+                ctrl = self.queryctrl(id)
+                (id, type, name, min, max, step, default, flags, value) = ctrl
                 if flags & V4L2_CTRL_FLAG_DISABLED:
                     continue
+                res[self.ctrlname(name)] = ctrl
             except IOError, e:
                 break
-        return self.controls
+        return res
 
 
     def findcontrol(self, id):
-        '''
+        """
         find a control by id
-        '''
+        """
         for ctrl in self.controls.keys():
             if self.controls[ctrl][0] == id:
                 return ctrl
@@ -683,11 +704,10 @@
 
 
     def getcontrol(self, name):
-        '''
+        """
         get the control record by name
-        '''
-        key = self.ctrlname(name)
-        if not self.controls.has_key(key):
+        """
+        if not self.controls.has_key(self.ctrlname(name)):
             _debug_('control \"%s\" does not exists' % (name), DWARNING)
             return None
         (id, type, name, min, max, step, default, flags, value) = 
self.controls[key]
@@ -695,11 +715,10 @@
 
 
     def setcontrol(self, name, value):
-        '''
+        """
         get the control record by name
-        '''
-        key = self.ctrlname(name)
-        if not self.controls.has_key(key):
+        """
+        if not self.controls.has_key(self.ctrlname(name)):
             _debug_('control \"%s\" does not exists' % (name), DWARNING)
             return None
         (id, type, name, min, max, step, default, flags, oldvalue) = 
self.controls[key]
@@ -713,8 +732,8 @@
 
 
     def updatecontrol(self, name, value):
-        ''' set the control record by name
-        '''
+        """ set the control record by name
+        """
         if self.getcontrol(name) == None:
             return
 
@@ -728,8 +747,8 @@
 
 
     def init_settings(self):
-        ''' initialise the V4L2 setting
-        '''
+        """ initialise the V4L2 setting
+        """
         (v_norm, v_input, v_clist, v_dev) = config.TV_SETTINGS.split()
         self.inputs = self.enuminputs()
         self.standards = self.enumstds()
@@ -797,7 +816,11 @@
     config.DEBUG = 3
     config.LOGGING = config.logging.DEBUG
 
-    viddev=Videodev('/dev/video0')
+    videodev = '/dev/video0'
+    if len(sys.argv) > 1:
+        videodev = sys.argv[1]
+    viddev=Videodev(videodev)
+    print 'Device = %r' % videodev
     print 'Driver = \"%s\"' % viddev.getdriver()
     print 'Driver Version = %02d.%02d' % (viddev.getversion() / 256, 
viddev.getversion() % 256)
     viddev.print_settings()
@@ -902,7 +925,7 @@
     #print 'EXT_CTRL_ST=%s %s' % (EXT_CTRL_ST, struct.calcsize(EXT_CTRL_ST))
     #print 'EXT_CTRLS_ST=%s %s' % (EXT_CTRLS_ST, struct.calcsize(EXT_CTRLS_ST))
 
-    #'''
+    #"""
     #viddev=Videodev('/dev/video0')
     #print
     #print viddev.querycap()
@@ -944,11 +967,11 @@
     #print '0x00990900 = %d' % viddev.getextctrl(0x00990900)
     #DEBUG=4
     #print 'getfreq:', viddev.getfreq()
-    #'''
+    #"""
 
     viddev.close()
 
-#'''
+#"""
 #To run this as standalone use the following before running python v4l2.py
 #pythonversion=$(python -V 2>&1 | cut -d" " -f2 | cut -d"." -f1-2)
 #export PYTHONPATH=/usr/lib/python${pythonversion}/site-packages/freevo
@@ -959,4 +982,4 @@
 #python v4l2.py
 #OR
 #freevo execute v4l2.py
-#'''
+#"""

-------------------------------------------------------------------------
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

Reply via email to