Home | History | Annotate | Download | only in video_ChromeRTCHWDecodeUsed
      1 # Copyright (c) 2014 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 os
      6 
      7 from autotest_lib.client.bin import test
      8 from autotest_lib.client.common_lib import error, file_utils, utils
      9 from autotest_lib.client.common_lib.cros import chrome
     10 from autotest_lib.client.cros.video import histogram_verifier
     11 
     12 
     13 # Chrome flags to use fake camera and skip camera permission.
     14 EXTRA_BROWSER_ARGS = ['--use-fake-device-for-media-stream',
     15                       '--use-fake-ui-for-media-stream']
     16 FAKE_FILE_ARG = '--use-file-for-fake-video-capture="%s"'
     17 DOWNLOAD_BASE = 'http://commondatastorage.googleapis.com/chromiumos-test-assets-public/crowd/'
     18 
     19 HISTOGRAMS_URL = 'chrome://histograms/'
     20 
     21 
     22 class video_ChromeRTCHWDecodeUsed(test.test):
     23     """The test verifies HW Encoding for WebRTC video."""
     24     version = 1
     25 
     26 
     27     def is_skipping_test(self):
     28         """Determine whether this test should skip."""
     29         blacklist = [
     30                 # (board, milestone); None if don't care.
     31 
     32                 # kevin did support hw decode, but not ready in M54 and M55.
     33                 ('kevin', 54), ('kevin', 55),
     34 
     35                 # elm and hana support hw decode since M57.
     36                 ('elm', 56), ('hana', 56),
     37         ]
     38 
     39         entry = (utils.get_current_board(), utils.get_chrome_milestone())
     40         for black_entry in blacklist:
     41             for i, to_match in enumerate(black_entry):
     42                 if to_match and str(to_match) != entry[i]:
     43                     break
     44             else:
     45                 return True
     46 
     47         return False
     48 
     49     def start_loopback(self, cr):
     50         """
     51         Opens WebRTC loopback page.
     52 
     53         @param cr: Autotest Chrome instance.
     54         """
     55         tab = cr.browser.tabs.New()
     56         tab.Navigate(cr.browser.platform.http_server.UrlOf(
     57             os.path.join(self.bindir, 'loopback.html')))
     58         tab.WaitForDocumentReadyStateToBeComplete()
     59 
     60 
     61     def run_once(self, video_name, histogram_name, histogram_bucket_val):
     62         if self.is_skipping_test():
     63             raise error.TestNAError('Skipping test run on this board.')
     64 
     65         # Download test video.
     66         url = DOWNLOAD_BASE + video_name
     67         local_path = os.path.join(self.bindir, video_name)
     68         file_utils.download_file(url, local_path)
     69 
     70         # Start chrome with test flags.
     71         EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
     72         with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
     73                            init_network_controller=True) as cr:
     74             # Open WebRTC loopback page.
     75             cr.browser.platform.SetHTTPServerDirectories(self.bindir)
     76             self.start_loopback(cr)
     77 
     78             # Make sure decode is hardware accelerated.
     79             histogram_verifier.verify(cr, histogram_name, histogram_bucket_val)
     80