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
5import os
6import time, logging, shutil
7
8from autotest_lib.client.bin import test, utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.common_lib.cros import chrome
11from autotest_lib.client.cros.video import constants
12from autotest_lib.client.cros.video import device_capability
13from autotest_lib.client.cros.video import helper_logger
14from autotest_lib.client.cros.video import histogram_verifier
15from autotest_lib.client.cros.video import native_html5_player
16
17
18class video_ChromeVidResChangeHWDecode(test.test):
19    """Verify that VDA works in Chrome for video with resolution changes."""
20    version = 1
21
22    @helper_logger.video_log_wrapper
23    def run_once(self, video_file, video_len, capability):
24        """Verify VDA and playback for the video_file.
25
26        @param video_file: test video file.
27        @param video_len : test video file length.
28        """
29        device_capability.DeviceCapability().ensure_capability(capability)
30
31        with chrome.Chrome(
32                extra_browser_args=helper_logger.chrome_vmodule_flag(),
33                init_network_controller=True) as cr:
34            init_status_differ = histogram_verifier.HistogramDiffer(
35                cr, constants.MEDIA_GVD_INIT_STATUS)
36            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
37            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
38            tab1 = cr.browser.tabs[0]
39            html_fullpath = os.path.join(self.bindir, 'video.html')
40            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
41            logging.info("full url is %s", url)
42            player = native_html5_player.NativeHtml5Player(tab1,
43                 full_url = url,
44                 video_id = 'video',
45                 video_src_path = video_file,
46                 event_timeout = 120)
47            player.load_video()
48            player.play()
49
50            # Verify the video playback.
51            for i in range(1, video_len/2):
52                if (player.paused() or player.ended()):
53                    raise error.TestError('Video either stopped or ended.')
54                time.sleep(1)
55
56            # Verify that video ends successfully.
57            utils.poll_for_condition(
58                    lambda: player.ended(),
59                    timeout=video_len,
60                    exception=error.TestError('Video did not end successfully'),
61                    sleep_interval=1)
62
63            # Make sure decode is hardware accelerated.
64            histogram_verifier.expect_sole_bucket(
65                init_status_differ, constants.MEDIA_GVD_BUCKET, 'OK (0)')
66