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

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

Issue 109553002: [Telemetry] Make StartVideoCapture start capturing synchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: skyostil comments Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/screenshot.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 time 7 import time
7 8
8 import android_commands 9 import android_commands
9 import cmd_helper 10 import cmd_helper
10 11
11 12
12 def _GetTimestamp(): 13 def _GetTimestamp():
13 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) 14 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime())
14 15
15 16
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 rotate: If True, the video will be rotated 90 degrees. 50 rotate: If True, the video will be rotated 90 degrees.
50 """ 51 """
51 def __init__(self, adb, host_file, megabits_per_second=4, size=None, 52 def __init__(self, adb, host_file, megabits_per_second=4, size=None,
52 rotate=False): 53 rotate=False):
53 self._adb = adb 54 self._adb = adb
54 self._device_file = '%s/screen-recording.mp4' % adb.GetExternalStorage() 55 self._device_file = '%s/screen-recording.mp4' % adb.GetExternalStorage()
55 self._host_file = host_file or 'screen-recording-%s.mp4' % _GetTimestamp() 56 self._host_file = host_file or 'screen-recording-%s.mp4' % _GetTimestamp()
56 self._host_file = os.path.abspath(self._host_file) 57 self._host_file = os.path.abspath(self._host_file)
57 self._recorder = None 58 self._recorder = None
58 self._recorder_pids = None 59 self._recorder_pids = None
60 self._recorder_stdout = None
61 self._is_started = False
59 62
60 self._args = ['adb'] 63 self._args = ['adb']
61 if self._adb.GetDevice(): 64 if self._adb.GetDevice():
62 self._args += ['-s', self._adb.GetDevice()] 65 self._args += ['-s', self._adb.GetDevice()]
63 self._args += ['shell', 'screenrecord'] 66 self._args += ['shell', 'screenrecord', '--verbose']
64 self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)] 67 self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)]
65 if size: 68 if size:
66 self._args += ['--size', '%dx%d' % size] 69 self._args += ['--size', '%dx%d' % size]
67 if rotate: 70 if rotate:
68 self._args += ['--rotate'] 71 self._args += ['--rotate']
69 self._args += [self._device_file] 72 self._args += [self._device_file]
70 73
71 def Start(self): 74 def Start(self):
72 """Start recording video.""" 75 """Start recording video."""
73 _EnsureHostDirectory(self._host_file) 76 _EnsureHostDirectory(self._host_file)
74 self._recorder = cmd_helper.Popen(self._args) 77 self._recorder_stdout = tempfile.mkstemp()[1]
78 self._recorder = cmd_helper.Popen(
79 self._args, stdout=open(self._recorder_stdout, 'w'))
75 self._recorder_pids = self._adb.ExtractPid('screenrecord') 80 self._recorder_pids = self._adb.ExtractPid('screenrecord')
76 if not self._recorder_pids: 81 if not self._recorder_pids:
77 raise RuntimeError('Recording failed. Is your device running Android ' 82 raise RuntimeError('Recording failed. Is your device running Android '
78 'KitKat or later?') 83 'KitKat or later?')
79 84
85 def IsStarted(self):
86 if not self._is_started:
87 for line in open(self._recorder_stdout):
88 self._is_started = line.startswith('Content area is ')
89 if self._is_started:
90 break
91 return self._is_started
92
80 def Stop(self): 93 def Stop(self):
81 """Stop recording video.""" 94 """Stop recording video."""
95 os.remove(self._recorder_stdout)
96 self._is_started = False
82 if not self._recorder or not self._recorder_pids: 97 if not self._recorder or not self._recorder_pids:
83 return 98 return
84 self._adb.RunShellCommand('kill -SIGINT ' + ' '.join(self._recorder_pids)) 99 self._adb.RunShellCommand('kill -SIGINT ' + ' '.join(self._recorder_pids))
85 self._recorder.wait() 100 self._recorder.wait()
86 101
87 def Pull(self): 102 def Pull(self):
88 """Pull resulting video file from the device. 103 """Pull resulting video file from the device.
89 104
90 Returns: 105 Returns:
91 Output video file name on the host. 106 Output video file name on the host.
92 """ 107 """
93 self._adb.PullFileFromDevice(self._device_file, self._host_file) 108 self._adb.PullFileFromDevice(self._device_file, self._host_file)
94 self._adb.RunShellCommand('rm -f "%s"' % self._device_file) 109 self._adb.RunShellCommand('rm -f "%s"' % self._device_file)
95 return self._host_file 110 return self._host_file
OLDNEW
« no previous file with comments | « no previous file | build/android/screenshot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698