1# Copyright (c) 2014 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 5from autotest_lib.client.cros.video import method_logger 6 7 8class VideoScreenShotCollector(object): 9 """ 10 Captures and collects screenshots of a video at specified time points. 11 12 """ 13 14 15 @method_logger.log 16 def __init__(self, player, screenshot_namer, screenshot_capturer): 17 self.player = player 18 self.screnshot_namer = screenshot_namer 19 self.screnshot_capturer = screenshot_capturer 20 21 22 @method_logger.log 23 def collect_screenshot(self, timestamp): 24 """ 25 Get a screenshot of video at a particular time. 26 27 Navigates player to a given time value, captures and saves a 28 screenshot at that time value. 29 30 @param timestamp: time_delta, the time value to capture screenshot for. 31 32 @returns a complete path to the screenshot captured. 33 34 """ 35 filename = self.screnshot_namer.get_filename(timestamp) 36 37 self.player.seek_to(timestamp) 38 self.player.wait_for_video_to_seek() 39 40 return self.screnshot_capturer.capture(filename) 41 42 43 @method_logger.log 44 def ensure_player_is_ready(self): 45 """ 46 Loads video and waits for player to be ready. 47 48 @raises whatever load_video() raises. 49 50 """ 51 self.player.load_video() 52 53 54 @method_logger.log 55 def collect_multiple_screenshots(self, timestamps): 56 """ 57 Collects screenshots for each timevalue in a list. 58 59 @param timestamps: time_delta list, time values to collect 60 screenshots for. 61 62 @returns a list of complete paths for screenshot captured. 63 64 """ 65 self.ensure_player_is_ready() 66 67 with self.screnshot_capturer: 68 return [self.collect_screenshot(t) for t in timestamps]