Hi again,

as mentioned on IRC, I tried to make ivtv.py "behave" and give it sane default 
values.  Attached you'll find a patch which adds default values != None and 
descriptions.

However, Rob and I agree that adding default values here is not a good 
solution, since some of the settings should preferably just be left alone 
(the kernel driver has defaults, too).  Thus, I tried to add support for 
default=None in kaa.base.config.

The problem seems to be that Group.__getattr__ creates a VarProxy which 
derives its type from the config value alone.  (VarProxy.__new__ creates a 
new classobj with clstype = type(value) as base class, which is not allowed 
for value == None.)  Thus, I simply added a parameter "vartype" which 
determines the type instead of type(value), and passed item._type in 
Group.__getattr__, but that failed miserably, and I cannot see exactly why (I 
get an AttributeError: 'Config' object has no attribute 'norm', where "norm" 
is the first setting a VarProxy is created for.  The problem might be that 
_type is a tuple ("pal", "ntsc") for this setting; I tried to fall back to 
type(item._type[0]) in this case, but that does not seem to do it..

Also, I wondered why in config.py line 166, super(Base, self) is used, but 
we're in VarProxy - is that intended?
Second, in in config.py line 157, you test "if value: ...", but I guess you 
meant "if value == None:", since value could be a False bool for example?

I am attaching the *non-working* patch for config.py just to make my 
intentions clear - somehow I seem to miss something (haven't got much 
experience with __new__, maybe that's it).

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
Index: tvdev/src/ivtv.py
===================================================================
--- tvdev/src/ivtv.py	(Revision 7946)
+++ tvdev/src/ivtv.py	(Arbeitskopie)
@@ -59,38 +59,110 @@
         # TODO: config?
         self.input = 4
 
-        # TODO: add nice default values and descriptions
         codec = Group(name='codec', desc='Codec definitions', schema= [
-            Var(name='aspect',   type=int, default=None,
-                desc=_('Rob: add desc and check type')),
+            Var(name='aspect',   type=int, default=2,
+                desc=_('''aspect ratio:
+1 - 1:1
+2 - 4:3 (normal TV, default)
+3 - 16:9 (widescreen)
+4 - 2.21:1''')),
             Var('audio_bitmask', default=0x00a9,
-                desc=_('Rob: add desc and check type')),
-            Var('bframes',       type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('bitrate_mode',  default=1,
-                desc=_('Rob: add desc and check type')),
-            Var('bitrate',       default=4500000,
-                desc=_('Rob: add desc and check type')),
-            Var('bitrate_peak',  default=4500000,
-                desc=_('Rob: add desc and check type')),
-            Var('dnr_mode',      type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('dnr_spatial',   type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('dnr_temporal',  type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('dnr_type',      type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('framerate',     type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('framespergop',  type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('gop_closure',   default=1,
-                desc=_('Rob: add desc and check type')),
-            Var('pulldown',      type=int, default=None,
-                desc=_('Rob: add desc and check type')),
-            Var('stream_type',   default=14,
-                desc=_('Rob: add desc and check type'))])
+                desc=_('''audio bitmask, binary OR of the following values:
+Samplerate
+  0x0000  44,100Hz (CD)
+  0x0001  48,00Hz (AC97, default)
+  0x0002  32,000Hz
+Layer
+  0x0004  Layer 1
+  0x0008  Layer 2 (default)
+Bitrate
+  0x0000  Free Format
+  0x0010  32kbps
+  0x0020  L1: 64kbps, L2: 48kbps
+  0x0030  L1: 96kbps, L2: 56kbps
+  0x0040  L1: 128kbps, L2: 64kbps
+  0x0050  L1: 160kbps, L2: 80kbps
+  0x0060  L1: 192kbps, L2: 96kbps
+  0x0070  L1: 224kbps, L2: 112kbps
+  0x0080  L1: 256kbps, L2: 128kbps
+  0x0090  L1: 288kbps, L2: 160kbps
+  0x00A0  L1: 320kbps, L2: 192kbps (default)
+  0x00B0  L1: 352kbps, L2: 224kbps
+  0x00C0  L1: 384kbps, L2: 256kbps
+  0x00D0  L1: 416kbps, L2: 320kbps
+  0x00E0  L1: 448kbps, L2: 384kbps
+Mode
+  0x0000  Stereo (default)
+  0x0100  Joint Stereo
+  0x0200  Dual
+  0x0300  Mono
+Mode Extension (for Joint Stereo)
+  0x0000  subbands 4-31 in intensity_stereo, bound==4
+  0x0400  subbands 8-31 in intensity_stereo, bound==8
+  0x0800  subbands 12-31 in intensity_stereo, bound==12
+  0x0C00  subbands 16-31 in intensity_stereo, bound==16
+Emphasis
+  0x0000  none (default)
+  0x1000  50/15uS
+  0x3000  CCITT J.17
+CRC (Cyclic Redundancy Check)
+  0x0000  Off (default)
+  0x4000  On
+Copyright
+  0x0000  Off (default)
+  0x8000  On
+Generation
+  0x0000  Copy (default)
+  0x10000  Original''')),
+            Var('bframes',       type=int, default=3,
+                desc=_('number of B (bidirectional) frames PLUS 1\n(default setting of 3 generates 2 b-frames between P and I frames)')),
+            Var('bitrate_mode',  type=int, default=1,
+                desc=_('bitrate mode: 0 = variable, 1 = constant')),
+            Var('bitrate',       type=int, default=4500000,
+                desc=_('bitrate (bits/second, DVD max = 9.6Mbps)')),
+            Var('bitrate_peak',  type=int, default=4500000,
+                desc=_('maximal bitrate (must be >= bitrate)')),
+            Var('dnr_mode',      type=int, default=3,
+                desc=_('''Dynamic Noise Reduction filter mode
+0 both manual
+1 spatial: automatic, temporal: manual
+2 spatial: manual, temporal: automatic
+3 both automatic''')),
+            Var('dnr_spatial',   type=int, default=1,
+                desc=_('amount of spatial (horizontal) smoothing (0..15)')),
+            Var('dnr_temporal',  type=int, default=1,
+                desc=_('amount of temporal (motion) smoothing (0..31)')),
+            Var('dnr_type',      type=int, default=0,
+                desc=_('''Median Filter 
+0  Disabled
+1  Horizontal
+2  Vertical
+3  Horizontal/Vertical
+4  Diagonal''')),
+            Var('framerate',     type=int, default=1,
+                desc=_('0: 30 frames/s (NTSC)\n1: 25 frames/s (PAL, default)')),
+            Var('framespergop',  type=int, default=15,
+                desc=_('number of frames in a Group Of Pictures')),
+            Var('gop_closure',   type=int, default=1,
+                desc=_('0/1: open/closed GOP (Group Of Pictures)')),
+            Var('pulldown',      type=int, default=0,
+                desc=_('1 activates inverse telecine (default: 0 = off)\n(needed for telecined material, mostly NTSC, search for "pulldown explained")')),
+            Var('stream_type',   type=int, default=14,
+                desc=_('''0  Program Stream (PS)
+ 1: Transport Stream (TS, may not work)
+ 2: MPEG1
+ 3: PES A/V
+ 4: ?
+ 5: PES Video
+ 6: ?
+ 7: PES Audio
+ 8: ?
+ 9: ?
+10: DVD
+11: VCD
+12: SVCD
+13: DVD_S1
+14: DVD_S2'''))])
 
         # add codec group to config
         self._cfg_add(codec)
Index: src/base/config.py
===================================================================
--- src/base/config.py	(Revision 1165)
+++ src/base/config.py	(Arbeitskopie)
@@ -143,8 +143,10 @@
     value (int, str, unicode, etc.) and offers add_monitor and remove_monitor
     methods to manage the monitor list of the original Var object.
     """
-    def __new__(cls, value = None, monitors = [], parent = None):
-        clstype = realclass = type(value)
+    def __new__(cls, value = None, monitors = [], parent = None, vartype = None):
+        if vartype == None:
+            vartype = type(value)
+        clstype = realclass = vartype
         if clstype == bool:
             # You can't subclass a boolean, so use int instead.  In practice,
             # this isn't a problem, since __class__ will end up being bool,
@@ -163,13 +165,13 @@
 
 
     def __init__(self, value = None, monitors = [], parent = None):
-        super(Base, self).__init__(default = value)
+        super(VarProxy, self).__init__(default = value)
         self._monitors = monitors
         self._parent = parent
 
     def __getattribute__(self, attr):
         if attr == "__class__":
-            return super(VarProxy, self).__getattribute__("_class")
+            attr = "_class" # redirect to stored class attribute
         return super(VarProxy, self).__getattribute__(attr)
 
     def __str__(self):
@@ -329,7 +331,10 @@
             return object.__getattribute__(self, key)
         item = self._cfg_get(key)
         if isinstance(item, Var):
-            return VarProxy(item._value, item._monitors, item._parent)
+            vartype = item._type
+            if isinstance(vartype, (list, tuple)):
+                vartype = type(vartype[0])
+            return VarProxy(item._value, item._monitors, item._parent, vartype)
 
         return item
 

Attachment: pgpRcsmyy1otb.pgp
Description: PGP signature

Reply via email to