Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: build/android/pylib/screenshot.py

Issue 379443002: Change ownership of video file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing the comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 os 5 import os
6 import tempfile 6 import tempfile
7 7
8 from pylib import cmd_helper 8 from pylib import cmd_helper
9 9
10 # TODO(jbudorick) Remove once telemetry gets switched over. 10 # TODO(jbudorick) Remove once telemetry gets switched over.
11 import pylib.android_commands 11 import pylib.android_commands
12 import pylib.device.device_utils 12 import pylib.device.device_utils
13 13
14 14
15 class VideoRecorder(object): 15 class VideoRecorder(object):
16 """Records a screen capture video from an Android Device (KitKat or newer). 16 """Records a screen capture video from an Android Device (KitKat or newer).
17 17
18 Args: 18 Args:
19 device: DeviceUtils instance. 19 device: DeviceUtils instance.
20 host_file: Path to the video file to store on the host. 20 host_file: Path to the video file to store on the host.
21 megabits_per_second: Video bitrate in megabits per second. Allowed range 21 megabits_per_second: Video bitrate in megabits per second. Allowed range
22 from 0.1 to 100 mbps. 22 from 0.1 to 100 mbps.
23 size: Video frame size tuple (width, height) or None to use the device 23 size: Video frame size tuple (width, height) or None to use the device
24 default. 24 default.
25 rotate: If True, the video will be rotated 90 degrees. 25 rotate: If True, the video will be rotated 90 degrees.
26 """ 26 """
27 def __init__(self, device, host_file, megabits_per_second=4, size=None, 27 def __init__(self, device, megabits_per_second=4, size=None,
28 rotate=False): 28 rotate=False):
nednguyen 2014/07/08 22:28:12 There are other place that specifies the host_file
nduca 2014/07/08 22:34:21 or update the other callsites to use the new pull
Satyanarayana N H Manyam 2014/07/08 22:46:41 Ok added the parameter to the Pull then.
29 # TODO(jbudorick) Remove once telemetry gets switched over. 29 # TODO(jbudorick) Remove once telemetry gets switched over.
30 if isinstance(device, pylib.android_commands.AndroidCommands): 30 if isinstance(device, pylib.android_commands.AndroidCommands):
31 device = pylib.device.device_utils.DeviceUtils(device) 31 device = pylib.device.device_utils.DeviceUtils(device)
32 self._device = device 32 self._device = device
33 self._device_file = ( 33 self._device_file = (
34 '%s/screen-recording.mp4' % device.GetExternalStoragePath()) 34 '%s/screen-recording.mp4' % device.GetExternalStoragePath())
35 self._host_file = host_file or ('screen-recording-%s.mp4' %
36 device.old_interface.GetTimestamp())
37 self._host_file = os.path.abspath(self._host_file)
38 self._recorder = None 35 self._recorder = None
39 self._recorder_pids = None 36 self._recorder_pids = None
40 self._recorder_stdout = None 37 self._recorder_stdout = None
41 self._is_started = False 38 self._is_started = False
42 39
43 self._args = ['adb'] 40 self._args = ['adb']
44 if self._device.old_interface.GetDevice(): 41 if self._device.old_interface.GetDevice():
45 self._args += ['-s', self._device.old_interface.GetDevice()] 42 self._args += ['-s', self._device.old_interface.GetDevice()]
46 self._args += ['shell', 'screenrecord', '--verbose'] 43 self._args += ['shell', 'screenrecord', '--verbose']
47 self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)] 44 self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)]
48 if size: 45 if size:
49 self._args += ['--size', '%dx%d' % size] 46 self._args += ['--size', '%dx%d' % size]
50 if rotate: 47 if rotate:
51 self._args += ['--rotate'] 48 self._args += ['--rotate']
52 self._args += [self._device_file] 49 self._args += [self._device_file]
53 50
54 def Start(self): 51 def Start(self):
55 """Start recording video.""" 52 """Start recording video."""
56 self._device.old_interface.EnsureHostDirectory(self._host_file)
57 self._recorder_stdout = tempfile.mkstemp()[1] 53 self._recorder_stdout = tempfile.mkstemp()[1]
58 self._recorder = cmd_helper.Popen( 54 self._recorder = cmd_helper.Popen(
59 self._args, stdout=open(self._recorder_stdout, 'w')) 55 self._args, stdout=open(self._recorder_stdout, 'w'))
60 self._recorder_pids = self._device.old_interface.ExtractPid('screenrecord') 56 self._recorder_pids = self._device.old_interface.ExtractPid('screenrecord')
61 if not self._recorder_pids: 57 if not self._recorder_pids:
62 raise RuntimeError('Recording failed. Is your device running Android ' 58 raise RuntimeError('Recording failed. Is your device running Android '
63 'KitKat or later?') 59 'KitKat or later?')
64 60
65 def IsStarted(self): 61 def IsStarted(self):
66 if not self._is_started: 62 if not self._is_started:
(...skipping 10 matching lines...) Expand all
77 if not self._recorder or not self._recorder_pids: 73 if not self._recorder or not self._recorder_pids:
78 return 74 return
79 self._device.RunShellCommand( 75 self._device.RunShellCommand(
80 'kill -SIGINT ' + ' '.join(self._recorder_pids)) 76 'kill -SIGINT ' + ' '.join(self._recorder_pids))
81 self._recorder.wait() 77 self._recorder.wait()
82 78
83 def Pull(self): 79 def Pull(self):
84 """Pull resulting video file from the device. 80 """Pull resulting video file from the device.
85 81
86 Returns: 82 Returns:
87 Output video file name on the host. 83 Output video file object on the host.
nduca 2014/07/08 22:34:21 NamedTemporaryFile containing the video, on the ho
Satyanarayana N H Manyam 2014/07/08 22:57:27 Updated the code a bit
88 """ 84 """
85 host_file_obj = tempfile.NamedTemporaryFile(
86 suffix='screen-recording-%s.mp4' % (
87 self._device.old_interface.GetTimestamp()))
89 self._device.old_interface.PullFileFromDevice( 88 self._device.old_interface.PullFileFromDevice(
90 self._device_file, self._host_file) 89 self._device_file, host_file_obj.name)
91 self._device.RunShellCommand('rm -f "%s"' % self._device_file) 90 self._device.RunShellCommand('rm -f "%s"' % self._device_file)
92 return self._host_file 91 return host_file_obj
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698