]> git.alsa-project.org Git - alsa.git/commitdiff
hda-analyzer: add --monitor mode
authorJaroslav Kysela <perex@perex.cz>
Mon, 1 Feb 2010 12:20:16 +0000 (13:20 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 1 Feb 2010 12:20:16 +0000 (13:20 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
hda-analyzer/hda_analyzer.py
hda-analyzer/hda_codec.py

index 037029233a9b22e4896407177918f342534702cc..818cdc35b9d9a4efc0c8eedf3ea260ebfc91fdf4 100755 (executable)
 hda_analyzer - a tool to analyze HDA codecs widgets and connections
 
 Usage: hda_analyzer [[codec_proc] ...]
+   or: hda_analyzer --monitor
 
     codec_proc might specify multiple codec files per card:
         codec_proc_file1+codec_proc_file2
     or codec_proc might be a dump from alsa-info.sh
     or codec_proc might be a hash for codec database at www.alsa-project.org
     or codec_proc might be a URL for codec dump or alsa-info.sh dump
+
+    Monitor mode: check for codec changes in realtime and dump diffs.
 """
 
 import os
@@ -969,10 +972,42 @@ mailing list, too.
     mframe.add(vbox)
     w.add_with_viewport(mframe)
 
-def main():
-  if len(sys.argv) > 1 and sys.argv[1] in ('-h', '-help', '--help'):
+def monitor():
+  from time import sleep
+  print "Watching %s cards" % len(CODEC_TREE)
+  dumps = {}
+  while 1:
+    ok = False
+    for card in CODEC_TREE:
+      if not card in dumps:
+        dumps[card] = {}
+      for codec in CODEC_TREE[card]:
+        if not codec in dumps[card]:
+          dumps[card][codec] = ''
+        c = CODEC_TREE[card][codec]
+        if c.hwaccess:
+          ok = True
+        c.reread()
+        diff = ''
+        dump1 = c.dump()
+        if dumps[card][codec]:
+          diff = do_diff1(c, dumps[card][codec])
+        dumps[card][codec] = dump1
+        if diff:
+          print "======================================"
+          print diff
+    if not ok:
+      print "Nothing to monitor (no hwdep access)"
+      break
+    sleep(1)
+
+def main(argv):
+  if len(argv) > 1 and argv[1] in ('-h', '-help', '--help'):
     print __doc__ % globals()
-    sys.exit(0)
+    return 0
+  if len(argv) > 1 and argv[1] in ('-m', '-monitor', '--monitor'):
+    cmd = 'monitor'
+    del argv[1]
   if read_nodes(sys.argv[1:]) == 0:
     print "No HDA codecs were found or insufficient priviledges for "
     print "/dev/snd/controlC* and /dev/snd/hwdepC*D* device files."
@@ -981,9 +1016,14 @@ def main():
     print "interface as well or close all application using HWDEP."
     print
     print "Try run this program as root user."
+    return 0
   else:
+    if cmd == 'monitor':
+      monitor()
+      return 1
     HDAAnalyzer()
     gtk.main()
+  return 1
 
 if __name__ == '__main__':
-  main()
+  sys.exit(main(sys.argv))
index b6c8b6d599872d063ea060728ad511000804d702..5d3de7d915dc0aa222c8b25673d468e8b1ec5a04 100644 (file)
@@ -716,7 +716,8 @@ class HDACodec:
   subsystem_id = None
   revision_id = None
 
-  def __init__(self, card=0, device=0):
+  def __init__(self, card=0, device=0, clonefd=None):
+    self.fd = None
     self.hwaccess = True
     if type(1) == type(card):
       self.device = device
@@ -726,7 +727,10 @@ class HDACodec:
       self.device = device
       self.mcard = card
       self.card = card.card
-    self.fd = os.open("/dev/snd/hwC%sD%s" % (card, device), os.O_RDWR)
+    if not clonefd:
+      self.fd = os.open("/dev/snd/hwC%sD%s" % (card, device), os.O_RDWR)
+    else:
+      self.fd = os.dup(clonefd)
     info = struct.pack('Ii64s80si64s', 0, 0, '', '', 0, '')
     res = ioctl(self.fd, IOCTL_INFO, info)
     name = struct.unpack('Ii64s80si64s', res)[3]
@@ -737,6 +741,10 @@ class HDACodec:
     if self.version < 0x00010000:      # 1.0.0
       raise IOError, "unknown HDA hwdep version"
 
+  def __del__(self):
+    if not self.fd is None:
+      os.close(self.fd)
+
   def rw(self, nid, verb, param):
     """do elementary read/write operation"""
     verb = (nid << 24) | (verb << 8) | param
@@ -857,6 +865,11 @@ class HDACodec:
       self.nodes[nid] = HDANode(self, nid)
       nid += 1
 
+  def reread(self):
+    self.gpio.reread()
+    for node in self.nodes:
+      self.nodes[node].reread()
+
   def analyze_pcm_rates(self, pcm):
     rates = [8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
              96000, 176400, 192000, 384000]
@@ -1156,7 +1169,7 @@ class HDACodec:
       str += print_realtek_coef(node)
     return str
 
-  def dump_node_extra(node):
+  def dump_node_extra(self, node):
     return ''
 
 def HDA_card_list():