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