Implemented GPX + Audio recording
[gregoa/zavai.git] / zavai / audio.py
index 37b483f72724c7b75df4101ad56dbcb7b40ed61a..b7345d6db1b0fd146842e9cac90ad5768f4d36a7 100755 (executable)
@@ -29,6 +29,31 @@ import gobject
 #import dbus.mainloop.glib
 #import subprocess
 
 #import dbus.mainloop.glib
 #import subprocess
 
+class Recorder(zavai.Resource):
+    def __init__(self, registry):
+        super(Recorder, self).__init__()
+        self.registry = registry
+
+    def shutdown(self):
+        self.stop()
+
+    def start(self, filename):
+        if self.recorder is not None: return
+
+        self.registry.resource("audio").connect("audio", self)
+
+        self.recorder = subprocess.Popen(
+            ["arecord", "-D", "hw", "-f", "cd", "-r", "8000", "-t", "wav", filename])
+
+    def stop(self):
+        if self.recorder is None: return
+
+        os.kill(self.recorder.pid, signal.SIGINT)
+        self.recorder.wait()
+        self.recorder = None
+
+        self.registry.resource("audio").disconnect("audio", self)
+
 
 # TODO:
 #  - hook into the headset plugged/unplugged event
 
 # TODO:
 #  - hook into the headset plugged/unplugged event
@@ -84,10 +109,6 @@ class Audio(zavai.Service):
         self.input_fd.close()
         self.input_fd = None
 
         self.input_fd.close()
         self.input_fd = None
 
-#        if self.recorder is not None:
-#            os.kill(self.recorder.pid, signal.SIGINT)
-#            self.recorder.wait()
-
         # Restore mixer settings
         self.load_scenario(self.saved_scenario)
 
         # Restore mixer settings
         self.load_scenario(self.saved_scenario)
 
@@ -145,12 +166,6 @@ class Audio(zavai.Service):
 #    def set_basename(self, basename):
 #        self.basename = basename
 #
 #    def set_basename(self, basename):
 #        self.basename = basename
 #
-#    def start_recording(self):
-#        if self.basename is None:
-#            raise RuntimeError("Recording requested but basename not set")
-#        self.recorder = subprocess.Popen(
-#            ["arecord", "-D", "hw", "-f", "cd", "-r", "8000", "-t", "wav", self.basename + ".wav"])
-#
 #    def start_levels(self):
 #        self.recorder = subprocess.Popen(
 #            ["arecord", "-D", "hw", "-f", "cd", "-r", "8000", "-t", "wav", "-V", "stereo", "/dev/null"])
 #    def start_levels(self):
 #        self.recorder = subprocess.Popen(
 #            ["arecord", "-D", "hw", "-f", "cd", "-r", "8000", "-t", "wav", "-V", "stereo", "/dev/null"])