1# Copyright 2018 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. 4import logging 5import os 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib import file_utils 9from autotest_lib.client.cros.power import power_videotest 10 11 12class power_VideoPlayback(power_videotest.power_VideoTest): 13 """class for power_VideoPlayback test.""" 14 version = 1 15 16 # Time in seconds to measure power per video file. 17 _MEASUREMENT_DURATION = 120 18 19 _BASE_URL='http://storage.googleapis.com/chromiumos-test-assets-public/tast/cros/video/power/30s/' 20 21 # list of video name and url. 22 _VIDEOS = [ 23 ('h264_720_30fps', 24 _BASE_URL + '720p30fpsH264_foodmarket_sync_30s.mp4' 25 ), 26 ('h264_720_60fps', 27 _BASE_URL + '720p60fpsH264_boat_sync_30s.mp4' 28 ), 29 ('h264_1080_30fps', 30 _BASE_URL + '1080p30fpsH264_foodmarket_sync_30s.mp4' 31 ), 32 ('h264_1080_60fps', 33 _BASE_URL + '1080p60fpsH264_boat_sync_30s.mp4' 34 ), 35 ('h264_4k_30fps', 36 _BASE_URL + '4k30fpsH264_foodmarket_sync_vod_30s.mp4' 37 ), 38 ('h264_4k_60fps', 39 _BASE_URL + '4k60fpsH264_boat_sync_vod_30s.mp4' 40 ), 41 ('vp8_720_30fps', 42 _BASE_URL + '720p30fpsVP8_foodmarket_sync_30s.webm' 43 ), 44 ('vp8_720_60fps', 45 _BASE_URL + '720p60fpsVP8_boat_sync_30s.webm' 46 ), 47 ('vp8_1080_30fps', 48 _BASE_URL + '1080p30fpsVP8_foodmarket_sync_30s.webm' 49 ), 50 ('vp8_1080_60fps', 51 _BASE_URL + '1080p60fpsVP8_boat_sync_30s.webm' 52 ), 53 ('vp8_4k_30fps', 54 _BASE_URL + '4k30fpsVP8_foodmarket_sync_30s.webm' 55 ), 56 ('vp8_4k_60fps', 57 _BASE_URL + '4k60fpsVP8_boat_sync_30s.webm' 58 ), 59 ('vp9_720_30fps', 60 _BASE_URL + '720p30fpsVP9_foodmarket_sync_30s.webm' 61 ), 62 ('vp9_720_60fps', 63 _BASE_URL + '720p60fpsVP9_boat_sync_30s.webm' 64 ), 65 ('vp9_1080_30fps', 66 _BASE_URL + '1080p30fpsVP9_foodmarket_sync_30s.webm' 67 ), 68 ('vp9_1080_60fps', 69 _BASE_URL + '1080p60fpsVP9_boat_sync_30s.webm' 70 ), 71 ('vp9_4k_30fps', 72 _BASE_URL + '4k30fpsVP9_foodmarket_sync_30s.webm' 73 ), 74 ('vp9_4k_60fps', 75 _BASE_URL + '4k60fpsVP9_boat_sync_30s.webm' 76 ), 77 ('av1_720_30fps', 78 _BASE_URL + '720p30fpsAV1_foodmarket_sync_30s.mp4' 79 ), 80 ('av1_720_60fps', 81 _BASE_URL + '720p60fpsAV1_boat_sync_30s.mp4' 82 ), 83 ('av1_1080_30fps', 84 _BASE_URL + '1080p30fpsAV1_foodmarket_sync_30s.mp4' 85 ), 86 ('av1_1080_60fps', 87 _BASE_URL + '1080p60fpsAV1_boat_sync_30s.mp4' 88 ), 89 ] 90 91 92 _FAST_BASE_URL = 'http://storage.googleapis.com/chromiumos-test-assets-public/tast/cros/video/power/10s/' 93 _FAST_VIDEOS = [ 94 ('h264_720_30fps', 95 _FAST_BASE_URL + '720p30fpsH264_foodmarket_sync_10s.mp4' 96 ), 97 ('vp8_720_30fps', 98 _FAST_BASE_URL + '720p30fpsVP8_foodmarket_sync_10s.webm' 99 ), 100 ('vp9_720_30fps', 101 _FAST_BASE_URL + '720p30fpsVP9_foodmarket_sync_10s.webm' 102 ), 103 ('av1_720_30fps', 104 _FAST_BASE_URL + '720p30fpsAV1_foodmarket_sync_10s.mp4' 105 ), 106 ] 107 108 def _prepare_video(self, cr, url): 109 """Prepare browser session before playing video. 110 111 @param cr: Autotest Chrome instance. 112 @param url: url of video file to play. 113 """ 114 # Download video to ramdisk 115 local_path = os.path.join(self._RAMDISK, os.path.basename(url)) 116 logging.info('Downloading %s to %s', url, local_path) 117 file_utils.download_file(url, local_path) 118 self.cr.browser.platform.SetHTTPServerDirectories(self._RAMDISK) 119 120 def _start_video(self, cr, url): 121 """Start playing video. 122 123 @param cr: Autotest Chrome instance. 124 @param local_path: path to the local video file to play. 125 """ 126 local_path = os.path.join(self._RAMDISK, os.path.basename(url)) 127 tab = cr.browser.tabs[0] 128 tab.Navigate(cr.browser.platform.http_server.UrlOf(local_path)) 129 tab.WaitForDocumentReadyStateToBeComplete() 130 tab.EvaluateJavaScript( 131 "document.getElementsByTagName('video')[0].loop=true") 132 133 def _teardown_video(self, cr, url): 134 """Teardown browser session after playing video. 135 136 @param cr: Autotest Chrome instance. 137 @param url: url of video file to play. 138 """ 139 self.cr.browser.platform.StopAllLocalServers() 140 local_path = os.path.join(self._RAMDISK, os.path.basename(url)) 141 os.remove(local_path) 142 143 def run_once(self, videos=None, secs_per_video=_MEASUREMENT_DURATION, 144 use_hw_decode=True, fast=False): 145 """run_once method. 146 147 @param videos: list of tuple of tagname and video url to test. 148 @param secs_per_video: time in seconds to play video and measure power. 149 @param use_hw_decode: if False, disable hw video decoding. 150 @param fast: Use smaller set of videos when videos is None. 151 """ 152 default_videos = self._FAST_VIDEOS if fast else self._VIDEOS 153 if not videos: 154 videos = default_videos 155 else: 156 for i, (tagname, url) in enumerate(videos): 157 if url: 158 continue 159 # if url is unset & tagname matches default use that path. 160 for default in default_videos: 161 if tagname == default[0]: 162 videos[i] = default 163 break 164 else: 165 estr = 'Unable to find URL for video name %s' % tagname 166 raise error.TestError(estr) 167 168 super(power_VideoPlayback, self).run_once( 169 videos, secs_per_video, use_hw_decode) 170