• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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
5import os
6import time
7import shutil
8import logging
9
10from autotest_lib.client.bin import test
11from autotest_lib.client.common_lib import error, utils
12from autotest_lib.client.common_lib.cros import chrome
13from autotest_lib.client.cros.video import constants
14from autotest_lib.client.cros.video import device_capability
15from autotest_lib.client.cros.video import helper_logger
16from autotest_lib.client.cros.video import histogram_verifier
17from autotest_lib.client.cros.video import native_html5_player
18
19
20class video_ChromeHWDecodeUsed(test.test):
21    """This test verifies VDA works in Chrome."""
22    version = 1
23
24    def is_skipping_test(self, codec):
25        """Determine whether this test should skip.
26
27        @param codec: the codec to be tested. Example values: 'vp8', 'vp9',
28                      'h264'.
29        """
30        blacklist = [
31                # (board, milestone, codec); None if don't care.
32
33                # kevin did support hw decode, but not ready in M54 and M55.
34                ('kevin', 54, 'vp8'),('kevin', 55, 'vp8')
35        ]
36
37        entry = (utils.get_current_board(), utils.get_chrome_milestone(), codec)
38        for black_entry in blacklist:
39            for i, to_match in enumerate(black_entry):
40                if to_match and str(to_match) != entry[i]:
41                    break
42            else:
43                return True
44
45        return False
46
47    @helper_logger.video_log_wrapper
48    def run_once(self, codec, is_mse, video_file, capability, arc_mode=None):
49        """
50        Tests whether VDA works by verifying histogram for the loaded video.
51
52        @param is_mse: bool, True if the content uses MSE, False otherwise.
53        @param video_file: Sample video file to be loaded in Chrome.
54        @param capability: Capability required for executing this test.
55        """
56        if self.is_skipping_test(codec):
57            raise error.TestNAError('Skipping test run on this board.')
58
59        if not device_capability.DeviceCapability().have_capability(capability):
60            logging.warning("Missing Capability: %s", capability)
61            return
62
63        with chrome.Chrome(
64                extra_browser_args=helper_logger.chrome_vmodule_flag(),
65                arc_mode=arc_mode,
66                init_network_controller=True) as cr:
67            init_status_differ = histogram_verifier.HistogramDiffer(
68                cr, constants.MEDIA_GVD_INIT_STATUS)
69            error_differ = histogram_verifier.HistogramDiffer(
70                cr, constants.MEDIA_GVD_ERROR)
71
72            # This will execute for MSE video by accesing shaka player
73            if is_mse:
74                 tab1 = cr.browser.tabs.New()
75                 tab1.Navigate(video_file)
76                 tab1.WaitForDocumentReadyStateToBeComplete()
77                 # Running the test longer to check errors and longer playback
78                 # for MSE videos.
79                 time.sleep(30)
80            else:
81                 #This execute for normal video for downloading html file
82                 shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
83                 video_path = os.path.join(constants.CROS_VIDEO_DIR,
84                                           'files', video_file)
85                 shutil.copy2(video_path, self.bindir)
86
87                 cr.browser.platform.SetHTTPServerDirectories(self.bindir)
88                 tab = cr.browser.tabs.New()
89                 html_fullpath = os.path.join(self.bindir, 'video.html')
90                 url = cr.browser.platform.http_server.UrlOf(html_fullpath)
91
92                 player = native_html5_player.NativeHtml5Player(
93                         tab,
94                         full_url = url,
95                         video_id = 'video',
96                         video_src_path = video_file,
97                         event_timeout = 120)
98                 player.load_video()
99                 player.play()
100                 # Waits until the video ends or an error happens.
101                 player.wait_ended_or_error()
102
103            # Wait for histogram updated for the test video.
104            histogram_verifier.expect_sole_bucket(
105                init_status_differ, constants.MEDIA_GVD_BUCKET, 'OK (0)')
106
107            # Check if there's GPU Video Error for a period of time.
108            has_error, diff_error = histogram_verifier.poll_histogram_grow(
109                error_differ)
110            if has_error:
111                raise error.TestError(
112                    'GPU Video Decoder Error. Histogram diff: %r' % diff_error)
113
114            # Verify the video ends successully for normal videos.
115            if not is_mse and player.check_error():
116                raise error.TestError('player did not end successully '\
117                                      '(HTML5 Player Error %s: %s)'
118                                      % player.get_error_info())
119