# Copyright 2014 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Facade to access the audio-related functionality.""" import functools import glob import logging import numpy as np import os import tempfile from autotest_lib.client.cros import constants from autotest_lib.client.cros.audio import audio_helper from autotest_lib.client.cros.audio import cmd_utils from autotest_lib.client.cros.audio import cras_dbus_utils from autotest_lib.client.cros.audio import cras_utils from autotest_lib.client.cros.audio import alsa_utils from autotest_lib.client.cros.multimedia import audio_extension_handler class AudioFacadeNativeError(Exception): """Error in AudioFacadeNative.""" pass def check_arc_resource(func): """Decorator function for ARC related functions in AudioFacadeNative.""" @functools.wraps(func) def wrapper(instance, *args, **kwargs): """Wrapper for the methods to check _arc_resource. @param instance: Object instance. @raises: AudioFacadeNativeError if there is no ARC resource. """ if not instance._arc_resource: raise AudioFacadeNativeError('There is no ARC resource.') return func(instance, *args, **kwargs) return wrapper def file_contains_all_zeros(path): """Reads a file and checks whether the file contains all zeros.""" with open(path) as f: binary = f.read() # Assume data is in 16 bit signed int format. The real format # does not matter though since we only care if there is nonzero data. np_array = np.fromstring(binary, dtype='