| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging |
| 5 import os | 6 import os |
| 6 import signal | |
| 7 import tempfile | 7 import tempfile |
| 8 import time |
| 8 | 9 |
| 9 from pylib import cmd_helper | 10 from pylib import cmd_helper |
| 11 from pylib import device_signal |
| 12 from pylib.device import device_errors |
| 10 | 13 |
| 11 # TODO(jbudorick) Remove once telemetry gets switched over. | 14 # TODO(jbudorick) Remove once telemetry gets switched over. |
| 12 import pylib.android_commands | 15 import pylib.android_commands |
| 13 import pylib.device.device_utils | 16 import pylib.device.device_utils |
| 14 | 17 |
| 15 | 18 |
| 16 class VideoRecorder(object): | 19 class VideoRecorder(object): |
| 17 """Records a screen capture video from an Android Device (KitKat or newer). | 20 """Records a screen capture video from an Android Device (KitKat or newer). |
| 18 | 21 |
| 19 Args: | 22 Args: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if self._is_started: | 67 if self._is_started: |
| 65 break | 68 break |
| 66 return self._is_started | 69 return self._is_started |
| 67 | 70 |
| 68 def Stop(self): | 71 def Stop(self): |
| 69 """Stop recording video.""" | 72 """Stop recording video.""" |
| 70 os.remove(self._recorder_stdout) | 73 os.remove(self._recorder_stdout) |
| 71 self._is_started = False | 74 self._is_started = False |
| 72 if not self._recorder: | 75 if not self._recorder: |
| 73 return | 76 return |
| 74 self._device.KillAll('screenrecord', signum=signal.SIGINT) | 77 if not self._device.KillAll('screenrecord', signum=device_signal.SIGINT, |
| 78 quiet=True): |
| 79 logging.warning('Nothing to kill: screenrecord was not running') |
| 75 self._recorder.wait() | 80 self._recorder.wait() |
| 76 | 81 |
| 77 def Pull(self, host_file=None): | 82 def Pull(self, host_file=None): |
| 78 """Pull resulting video file from the device. | 83 """Pull resulting video file from the device. |
| 79 | 84 |
| 80 Args: | 85 Args: |
| 81 host_file: Path to the video file to store on the host. | 86 host_file: Path to the video file to store on the host. |
| 82 Returns: | 87 Returns: |
| 83 Output video file name on the host. | 88 Output video file name on the host. |
| 84 """ | 89 """ |
| 85 host_file_name = host_file or ('screen-recording-%s.mp4' % | 90 # TODO(jbudorick): Merge filename generation with the logic for doing so in |
| 86 self._device.old_interface.GetTimestamp()) | 91 # DeviceUtils. |
| 92 host_file_name = ( |
| 93 host_file |
| 94 or 'screen-recording-%s.mp4' % time.strftime('%Y%m%dT%H%M%S', |
| 95 time.localtime())) |
| 87 host_file_name = os.path.abspath(host_file_name) | 96 host_file_name = os.path.abspath(host_file_name) |
| 88 self._device.old_interface.EnsureHostDirectory(host_file_name) | |
| 89 self._device.PullFile(self._device_file, host_file_name) | 97 self._device.PullFile(self._device_file, host_file_name) |
| 90 self._device.RunShellCommand('rm -f "%s"' % self._device_file) | 98 self._device.RunShellCommand('rm -f "%s"' % self._device_file) |
| 91 return host_file_name | 99 return host_file_name |
| OLD | NEW |