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