Home | History | Annotate | Download | only in audio_MediaBasicVerification
      1 # Copyright 2015 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """This is an audio quality test over headphone using the Chameleon board."""
      6 
      7 import logging
      8 import os
      9 import time
     10 
     11 from autotest_lib.client.common_lib import error
     12 from autotest_lib.client.cros.audio import audio_test_data
     13 from autotest_lib.client.cros.chameleon import audio_test_utils
     14 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
     15 from autotest_lib.client.cros.chameleon import chameleon_audio_helper
     16 from autotest_lib.server.cros.audio import audio_test
     17 from autotest_lib.server.cros.multimedia import remote_facade_factory
     18 
     19 
     20 class audio_MediaBasicVerification(audio_test.AudioTest):
     21     """Server side audio quality test over 3.5 headphones.
     22 
     23     This test talks to a Chameleon board and a Cros device to verify
     24     headphone audio quality of the Cros device.
     25 
     26     """
     27     version = 1
     28     DELAY_BEFORE_RECORD_SECONDS = 0.5
     29     RECORD_SECONDS = 10
     30     DELAY_AFTER_BINDING = 0.5
     31     UNSUPPORTED_BOARD_TYPES = ['CHROMEBIT']
     32 
     33     def run_once(self, host, audio_test_file):
     34 
     35         if host.get_board_type() in self.UNSUPPORTED_BOARD_TYPES:
     36             raise error.TestNAError(
     37                     'DUT is not supported for this scenario. Skipping test.')
     38 
     39         chameleon_board = host.chameleon
     40         factory = remote_facade_factory.RemoteFacadeFactory(
     41                 host, results_dir=self.resultsdir)
     42         chameleon_board.setup_and_reset(self.outputdir)
     43 
     44         widget_factory = chameleon_audio_helper.AudioWidgetFactory(
     45                 factory, host)
     46 
     47         source = widget_factory.create_widget(
     48             chameleon_audio_ids.CrosIds.HEADPHONE)
     49         recorder = widget_factory.create_widget(
     50             chameleon_audio_ids.ChameleonIds.LINEIN)
     51         binder = widget_factory.create_binder(source, recorder)
     52 
     53         with chameleon_audio_helper.bind_widgets(binder):
     54             # Checks the node selected by cras is correct.
     55             time.sleep(self.DELAY_AFTER_BINDING)
     56             audio_facade = factory.create_audio_facade()
     57 
     58             audio_test_utils.dump_cros_audio_logs(
     59                     host, audio_facade, self.resultsdir, 'after_binding')
     60 
     61             output_nodes, _ = audio_facade.get_selected_node_types()
     62             if output_nodes != ['HEADPHONE']:
     63                 raise error.TestFail(
     64                         '%s rather than headphone is selected on Cros '
     65                         'device' % output_nodes)
     66 
     67             # Starts playing, waits for some time, and then starts recording.
     68             # This is to avoid artifact caused by codec initialization.
     69             logging.info('Start playing %s on Cros device',
     70                          audio_test_file)
     71             browser_facade = factory.create_browser_facade()
     72             tab_descriptor = browser_facade.new_tab(audio_test_file)
     73 
     74             time.sleep(self.DELAY_BEFORE_RECORD_SECONDS)
     75             logging.info('Start recording from Chameleon.')
     76             recorder.start_recording()
     77 
     78             time.sleep(self.RECORD_SECONDS)
     79 
     80             recorder.stop_recording()
     81             logging.info('Stopped recording from Chameleon.')
     82             browser_facade.close_tab(tab_descriptor)
     83 
     84             audio_test_utils.dump_cros_audio_logs(
     85                     host, audio_facade, self.resultsdir, 'after_recording')
     86 
     87             recorder.read_recorded_binary()
     88             logging.info('Read recorded binary from Chameleon.')
     89 
     90         recorded_file = os.path.join(self.resultsdir, 'recorded.raw')
     91         logging.info('Saving recorded data to %s', recorded_file)
     92         recorder.save_file(recorded_file)
     93 
     94         # Removes the beginning of recorded data. This is to avoid artifact
     95         # caused by Chameleon codec initialization in the beginning of
     96         # recording.
     97         recorder.remove_head(0.5)
     98 
     99         # Removes noise by a lowpass filter.
    100         recorder.lowpass_filter(4000)
    101         recorded_file = os.path.join(self.resultsdir, 'recorded_filtered.raw')
    102         logging.info('Saving filtered data to %s', recorded_file)
    103         recorder.save_file(recorded_file)
    104 
    105         # Compares data by frequency. Headphone audio signal has gone through
    106         # analog processing. This suffers from codec artifacts and noise on the
    107         # path. Comparing data by frequency is more robust than comparing by
    108         # correlation, which is suitable for fully-digital audio path like USB
    109         # and HDMI.
    110         audio_test_utils.check_recorded_frequency(
    111                 audio_test_data.MEDIA_HEADPHONE_TEST_FILE,
    112                 recorder, check_anomaly=True)
    113