Home | History | Annotate | Download | only in audiovideo_AVSyncInternalDisplayAudioJack
      1 # Copyright 2016 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 import logging
      6 import os
      7 import tempfile
      8 
      9 from autotest_lib.client.common_lib import file_utils
     10 from autotest_lib.client.cros.chameleon import avsync_probe_utils
     11 from autotest_lib.server import test
     12 from autotest_lib.server.cros.multimedia import remote_facade_factory
     13 
     14 
     15 class audiovideo_AVSyncInternalDisplayAudioJack(test.test):
     16     """Server side audio/video sync quality measurement.
     17 
     18     This test measure the audio/video sync between internal display and audio
     19     jack.
     20 
     21     """
     22     version = 1
     23 
     24     def run_once(self, host, video_url, capture_seconds, video_fps,
     25                  sound_interval_frames, perf_prefix):
     26         """Running audio/video synchronization quality measurement
     27 
     28         @param host: A host object representing the DUT.
     29         @param video_url: The ULR of the test video.
     30         @param capture_seconds: How long do we capture the data from
     31                 avsync_probe device.
     32         @param video_fps: Video frames per second of the video. We need the
     33                 data to detect corrupted video frame.
     34         @param sound_interval_frames: The period of sound (beep) in the number
     35                 of video frames.
     36         @param perf_prefix: The prefix name of perf graph.
     37 
     38         """
     39         factory = remote_facade_factory.RemoteFacadeFactory(
     40                 host, results_dir=self.resultsdir, no_chrome=True)
     41 
     42         chameleon_board = host.chameleon
     43         audio_facade = factory.create_audio_facade()
     44         browser_facade = factory.create_browser_facade()
     45         video_facade = factory.create_video_facade()
     46         avsync_probe = chameleon_board.get_avsync_probe()
     47         chameleon_board.setup_and_reset(self.outputdir)
     48 
     49         browser_facade.start_default_chrome()
     50 
     51         _, ext = os.path.splitext(video_url)
     52         with tempfile.NamedTemporaryFile(prefix='playback_', suffix=ext) as f:
     53             # The default permission is 0o600.
     54             os.chmod(f.name, 0o644)
     55 
     56             file_utils.download_file(video_url, f.name)
     57             video_facade.prepare_playback(f.name)
     58 
     59         audio_facade.set_chrome_active_volume(100)
     60         video_facade.start_playback()
     61         capture_data = avsync_probe.Capture(capture_seconds)
     62         parser = avsync_probe_utils.AVSyncProbeDataParser(
     63                 self.resultsdir, capture_data, video_fps, sound_interval_frames)
     64 
     65         logging.info('Video frame stats:')
     66         logging.info('average: %f', parser.video_duration_average)
     67         logging.info('standard deviation: %f', parser.video_duration_std)
     68         logging.info('Sync stats:')
     69         logging.info('average: %f', parser.sync_duration_average)
     70         logging.info('standard deviation: %f', parser.sync_duration_std)
     71         logging.info('Number of total frames: %d',
     72                      parser.cumulative_frame_count)
     73         logging.info('Number of corrupted frames: %d',
     74                      parser.corrupted_frame_count)
     75         logging.info('Number of dropoped frames: %d',
     76                      parser.dropped_frame_count)
     77         logging.info('Number of dropoped frames by player: %d',
     78                      video_facade.dropped_frame_count())
     79 
     80         video_graph_name = '%s_video' % perf_prefix
     81         audiovideo_graph_name = '%s_audiovideo' % perf_prefix
     82         self.output_perf_value(description='Video frame duration average',
     83                                value=parser.video_duration_average, units='ms',
     84                                graph=video_graph_name)
     85         self.output_perf_value(description='Video frame duration std',
     86                                value=parser.video_duration_std,
     87                                graph=video_graph_name)
     88         self.output_perf_value(description='Corrupted video frames',
     89                                value=parser.corrupted_frame_count,
     90                                higher_is_better=False, graph=video_graph_name)
     91         self.output_perf_value(description='Dropped video frames',
     92                                value=parser.dropped_frame_count,
     93                                higher_is_better=False, graph=video_graph_name)
     94         self.output_perf_value(description='Dropped video frames by player',
     95                                value=video_facade.dropped_frame_count(),
     96                                higher_is_better=False, graph=video_graph_name)
     97 
     98         self.output_perf_value(description='Audio/Video Sync duration average',
     99                                value=parser.sync_duration_average, units='ms',
    100                                higher_is_better=False,
    101                                graph=audiovideo_graph_name)
    102         self.output_perf_value(description='Audio/Video Sync std',
    103                                value=parser.sync_duration_std,
    104                                higher_is_better=False,
    105                                graph=audiovideo_graph_name)
    106