Change ownership of video file

Review URL: https://codereview.chromium.org/379443002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282189 0039d316-1c4b-4281-b951-d872f2087c98
parent bb2966ae
...@@ -24,7 +24,7 @@ class VideoRecorder(object): ...@@ -24,7 +24,7 @@ class VideoRecorder(object):
default. default.
rotate: If True, the video will be rotated 90 degrees. rotate: If True, the video will be rotated 90 degrees.
""" """
def __init__(self, device, host_file, megabits_per_second=4, size=None, def __init__(self, device, megabits_per_second=4, size=None,
rotate=False): rotate=False):
# TODO(jbudorick) Remove once telemetry gets switched over. # TODO(jbudorick) Remove once telemetry gets switched over.
if isinstance(device, pylib.android_commands.AndroidCommands): if isinstance(device, pylib.android_commands.AndroidCommands):
...@@ -32,9 +32,6 @@ class VideoRecorder(object): ...@@ -32,9 +32,6 @@ class VideoRecorder(object):
self._device = device self._device = device
self._device_file = ( self._device_file = (
'%s/screen-recording.mp4' % device.GetExternalStoragePath()) '%s/screen-recording.mp4' % device.GetExternalStoragePath())
self._host_file = host_file or ('screen-recording-%s.mp4' %
device.old_interface.GetTimestamp())
self._host_file = os.path.abspath(self._host_file)
self._recorder = None self._recorder = None
self._recorder_pids = None self._recorder_pids = None
self._recorder_stdout = None self._recorder_stdout = None
...@@ -53,7 +50,6 @@ class VideoRecorder(object): ...@@ -53,7 +50,6 @@ class VideoRecorder(object):
def Start(self): def Start(self):
"""Start recording video.""" """Start recording video."""
self._device.old_interface.EnsureHostDirectory(self._host_file)
self._recorder_stdout = tempfile.mkstemp()[1] self._recorder_stdout = tempfile.mkstemp()[1]
self._recorder = cmd_helper.Popen( self._recorder = cmd_helper.Popen(
self._args, stdout=open(self._recorder_stdout, 'w')) self._args, stdout=open(self._recorder_stdout, 'w'))
...@@ -80,12 +76,15 @@ class VideoRecorder(object): ...@@ -80,12 +76,15 @@ class VideoRecorder(object):
'kill -SIGINT ' + ' '.join(self._recorder_pids)) 'kill -SIGINT ' + ' '.join(self._recorder_pids))
self._recorder.wait() self._recorder.wait()
def Pull(self): def Pull(self, host_file):
"""Pull resulting video file from the device. """Pull resulting video file from the device.
Returns: Args:
Output video file name on the host. host_file: Path to the video file to store on the host.
""" """
self._device.PullFile(self._device_file, self._host_file) host_file_name = host_file or ('screen-recording-%s.mp4' %
self._device.old_interface.GetTimestamp())
host_file = os.path.abspath(host_file_name)
self._device.old_interface.EnsureHostDirectory(self._host_file)
self._device.PullFile(self._device_file, host_file_name)
self._device.RunShellCommand('rm -f "%s"' % self._device_file) self._device.RunShellCommand('rm -f "%s"' % self._device_file)
return self._host_file
...@@ -28,7 +28,6 @@ def _CaptureScreenshot(device, host_file): ...@@ -28,7 +28,6 @@ def _CaptureScreenshot(device, host_file):
def _CaptureVideo(device, host_file, options): def _CaptureVideo(device, host_file, options):
size = tuple(map(int, options.size.split('x'))) if options.size else None size = tuple(map(int, options.size.split('x'))) if options.size else None
recorder = screenshot.VideoRecorder(device, recorder = screenshot.VideoRecorder(device,
host_file,
megabits_per_second=options.bitrate, megabits_per_second=options.bitrate,
size=size, size=size,
rotate=options.rotate) rotate=options.rotate)
...@@ -38,7 +37,7 @@ def _CaptureVideo(device, host_file, options): ...@@ -38,7 +37,7 @@ def _CaptureVideo(device, host_file, options):
raw_input() raw_input()
finally: finally:
recorder.Stop() recorder.Stop()
host_file = recorder.Pull() recorder.Pull(host_file)
_PrintMessage('Video written to %s' % os.path.abspath(host_file)) _PrintMessage('Video written to %s' % os.path.abspath(host_file))
......
...@@ -58,7 +58,6 @@ class AndroidPlatformBackend( ...@@ -58,7 +58,6 @@ class AndroidPlatformBackend(
self._powermonitor = android_temperature_monitor.AndroidTemperatureMonitor( self._powermonitor = android_temperature_monitor.AndroidTemperatureMonitor(
power_controller, device) power_controller, device)
self._video_recorder = None self._video_recorder = None
self._video_output = None
if self._no_performance_mode: if self._no_performance_mode:
logging.warning('CPU governor will not be set!') logging.warning('CPU governor will not be set!')
...@@ -225,11 +224,10 @@ class AndroidPlatformBackend( ...@@ -225,11 +224,10 @@ class AndroidPlatformBackend(
if min_bitrate_mbps > 100: if min_bitrate_mbps > 100:
raise ValueError('Android video capture cannot capture at %dmbps. ' raise ValueError('Android video capture cannot capture at %dmbps. '
'Max capture rate is 100mbps.' % min_bitrate_mbps) 'Max capture rate is 100mbps.' % min_bitrate_mbps)
self._video_output = tempfile.mkstemp()[1]
if self.is_video_capture_running: if self.is_video_capture_running:
self._video_recorder.Stop() self._video_recorder.Stop()
self._video_recorder = screenshot.VideoRecorder( self._video_recorder = screenshot.VideoRecorder(
self._device, self._video_output, megabits_per_second=min_bitrate_mbps) self._device, megabits_per_second=min_bitrate_mbps)
self._video_recorder.Start() self._video_recorder.Start()
util.WaitFor(self._video_recorder.IsStarted, 5) util.WaitFor(self._video_recorder.IsStarted, 5)
...@@ -240,10 +238,11 @@ class AndroidPlatformBackend( ...@@ -240,10 +238,11 @@ class AndroidPlatformBackend(
def StopVideoCapture(self): def StopVideoCapture(self):
assert self.is_video_capture_running, 'Must start video capture first' assert self.is_video_capture_running, 'Must start video capture first'
self._video_recorder.Stop() self._video_recorder.Stop()
self._video_recorder.Pull() video_file_obj = tempfile.NamedTemporaryFile()
self._video_recorder.Pull(video_file_obj.name)
self._video_recorder = None self._video_recorder = None
return video.Video(self._video_output) return video.Video(video_file_obj)
def CanMonitorPower(self): def CanMonitorPower(self):
return self._powermonitor.CanMonitorPower() return self._powermonitor.CanMonitorPower()
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import logging import logging
import tempfile
from telemetry import benchmark from telemetry import benchmark
from telemetry.core import bitmap from telemetry.core import bitmap
...@@ -28,7 +29,7 @@ class FakePlatform(object): ...@@ -28,7 +29,7 @@ class FakePlatform(object):
def StopVideoCapture(self): def StopVideoCapture(self):
self._is_video_capture_running = False self._is_video_capture_running = False
return video.Video(None) return video.Video(tempfile.NamedTemporaryFile())
def SetFullPerformanceModeEnabled(self, enabled): def SetFullPerformanceModeEnabled(self, enabled):
pass pass
......
...@@ -17,9 +17,10 @@ class BoundingBoxNotFoundException(Exception): ...@@ -17,9 +17,10 @@ class BoundingBoxNotFoundException(Exception):
class Video(object): class Video(object):
"""Utilities for storing and interacting with the video capture.""" """Utilities for storing and interacting with the video capture."""
def __init__(self, video_file_path): def __init__(self, video_file_obj):
# TODO(satyanarayana): Figure out when to delete this file. assert video_file_obj.delete
self._video_file_path = video_file_path assert not video_file_obj.close_called
self._video_file_obj = video_file_obj
self._tab_contents_bounding_box = None self._tab_contents_bounding_box = None
def UploadToCloudStorage(self, bucket, target_path): def UploadToCloudStorage(self, bucket, target_path):
...@@ -28,7 +29,7 @@ class Video(object): ...@@ -28,7 +29,7 @@ class Video(object):
Args: Args:
target_path: Path indicating where to store the file in cloud storage. target_path: Path indicating where to store the file in cloud storage.
""" """
cloud_storage.Insert(bucket, target_path, self._video_file_path) cloud_storage.Insert(bucket, target_path, self._video_file_obj.name)
def GetVideoFrameIter(self): def GetVideoFrameIter(self):
"""Returns the iteration for processing the video capture. """Returns the iteration for processing the video capture.
...@@ -42,7 +43,7 @@ class Video(object): ...@@ -42,7 +43,7 @@ class Video(object):
time_ms is milliseconds since navigationStart. time_ms is milliseconds since navigationStart.
bitmap is a telemetry.core.Bitmap. bitmap is a telemetry.core.Bitmap.
""" """
frame_generator = self._FramesFromMp4(self._video_file_path) frame_generator = self._FramesFromMp4(self._video_file_obj.name)
# Flip through frames until we find the initial tab contents flash. # Flip through frames until we find the initial tab contents flash.
content_box = None content_box = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment