• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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"""An adapter to remotely access the video facade on DUT."""
6
7import os
8import tempfile
9
10
11class VideoFacadeRemoteAdapter(object):
12    """VideoFacadeRemoteAdapter is an adapter to remotely control DUT video.
13
14    The Autotest host object representing the remote DUT, passed to this
15    class on initialization, can be accessed from its _client property.
16
17    """
18    def __init__(self, host, remote_facade_proxy):
19        """Construct a VideoFacadeRemoteAdapter.
20
21        @param host: Host object representing a remote host.
22        @param remote_facade_proxy: RemoteFacadeProxy object.
23
24        """
25        self._client = host
26        self._proxy = remote_facade_proxy
27
28
29    @property
30    def _video_proxy(self):
31        """Gets the proxy to DUT video facade.
32
33        @return XML RPC proxy to DUT video facade.
34
35        """
36        return self._proxy.video
37
38
39    def send_playback_file(self, path):
40        """Copies a file to client.
41
42        The files on the client side will be deleted by VideoFacadeNative
43        after the test.
44
45        @param path: A path to the file.
46
47        @returns: A new path to the file on client.
48
49        """
50        _, ext = os.path.splitext(path)
51        _, client_file_path = tempfile.mkstemp(
52                prefix='playback_', suffix=ext)
53        self._client.send_file(path, client_file_path)
54        return client_file_path
55
56
57    def prepare_playback(self, file_path, fullscreen=True):
58        """Copies the html file and the video file to /tmp and load the webpage.
59
60        @param file_path: The path to the file.
61        @param fullscreen: Plays the video in fullscreen.
62
63        """
64        client_file_path = self.send_playback_file(file_path)
65        self._video_proxy.prepare_playback(client_file_path, fullscreen)
66
67
68    def start_playback(self, blocking=False):
69        """Starts video playback on the webpage.
70
71        Before calling this method, user should call prepare_playback to
72        put the files to /tmp and load the webpage.
73
74        @param blocking: Blocks this call until playback finishes.
75
76        """
77        self._video_proxy.start_playback(blocking)
78
79
80    def pause_playback(self):
81        """Pauses playback on the webpage."""
82        self._video_proxy.pause_playback()
83
84
85    def dropped_frame_count(self):
86        """
87        Gets the number of dropped frames.
88
89        @returns: An integer indicates the number of dropped frame.
90
91        """
92        return self._video_proxy.dropped_frame_count()
93
94
95    def prepare_arc_playback(self, file_path, fullscreen=True):
96        """Copies the video file to be played into container.
97
98        User should call this method to put the file into container before
99        calling start_arc_playback.
100
101        @param file_path: Path to the file to be played on Server.
102        @param fullscreen: Plays the video in fullscreen.
103
104        """
105        client_file_path = self.send_playback_file(file_path)
106        self._video_proxy.prepare_arc_playback(client_file_path, fullscreen)
107
108
109    def start_arc_playback(self, blocking_secs=None):
110        """Starts playback through Play Video app.
111
112        Before calling this method, user should call set_arc_playback_file to
113        put the file into container and start the app.
114
115        @param blocking_secs: A positive number indicates the timeout to wait
116                              for the playback is finished. Set None to make
117                              it non-blocking.
118
119        """
120        self._video_proxy.start_arc_playback(blocking_secs)
121
122
123    def pause_arc_playback(self):
124        """Pauses playback through Play Video app."""
125        self._video_proxy.pause_arc_playback()
126
127
128    def stop_arc_playback(self):
129        """Stops playback through Play Video app."""
130        self._video_proxy.stop_arc_playback()
131