multimedia: Clean up temporary files in audio_facade_native
When multimedia_xmlrpc_server stops, clean up the temporary files used
in audio_facade_native.
BUG=chromium:491058
TEST=manually start/stop multimedia_xmlrpc_server and check the
temporary files are cleared.
Change-Id: I66a6a3c3c86fe888db6c92761eb98bcd1d68f953
Reviewed-on: https://chromium-review.googlesource.com/273128
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/client/cros/multimedia/audio_facade_native.py b/client/cros/multimedia/audio_facade_native.py
index d0752eb..147421a 100644
--- a/client/cros/multimedia/audio_facade_native.py
+++ b/client/cros/multimedia/audio_facade_native.py
@@ -4,8 +4,10 @@
"""Facade to access the audio-related functionality."""
+import glob
import logging
import multiprocessing
+import os
import tempfile
from autotest_lib.client.cros.audio import audio_helper
@@ -36,6 +38,15 @@
self._recorder = None
+ def cleanup(self):
+ """Clean up the temporary files."""
+ for path in glob.glob('/tmp/playback_*'):
+ os.unlink(path)
+
+ for path in glob.glob('/tmp/capture_*'):
+ os.unlink(path)
+
+
def playback(self, file_path, data_format, blocking=False):
"""Playback a file.
@@ -164,7 +175,7 @@
"""
def __init__(self):
"""Initializes a Recorder."""
- _, self.file_path = tempfile.mkstemp(prefix='capture', suffix='.raw')
+ _, self.file_path = tempfile.mkstemp(prefix='capture_', suffix='.raw')
self._capture_subprocess = None
diff --git a/client/cros/multimedia/multimedia_xmlrpc_server.py b/client/cros/multimedia/multimedia_xmlrpc_server.py
index 8b193dc..9b9f860 100755
--- a/client/cros/multimedia/multimedia_xmlrpc_server.py
+++ b/client/cros/multimedia/multimedia_xmlrpc_server.py
@@ -27,6 +27,12 @@
'display': display_facade_native.DisplayFacadeNative(chromium)
}
+
+ def __exit__(self, exception, value, traceback):
+ """Clean up the resources."""
+ self._facades['audio'].cleanup()
+
+
def _dispatch(self, method, params):
"""Dispatches the method to the proper facade.