1# Copyright 2014 The Chromium 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
5import abc
6
7
8class FrameReadError(Exception):
9  pass
10
11
12class FrameGenerator(object):
13  """ Defines an interface for reading input frames.
14
15  Attributes:
16    _generator: A reference to the created generator.
17  """
18  __metaclass__ = abc.ABCMeta
19
20  def __init__(self):
21    """ Initializes the FrameGenerator object. """
22    self._generator = self._CreateGenerator()
23
24  @abc.abstractmethod
25  def _CreateGenerator(self):
26    """ Creates a new generator.
27
28    Implemented in derived classes.
29
30    Raises:
31      FrameReadError: A error occurred in reading the frame.
32    """
33    raise NotImplementedError
34
35  @property
36  def Generator(self):
37    """ Returns:
38          A reference to the created generator.
39    """
40    return self._generator
41
42  @abc.abstractproperty
43  def CurrentTimestamp(self):
44    """ Returns:
45          float, The timestamp of the current frame in milliseconds.
46    """
47    raise NotImplementedError
48
49  @abc.abstractproperty
50  def CurrentFrameNumber(self):
51    """ Returns:
52          int, The frame index of the current frame.
53    """
54    raise NotImplementedError
55
56  @abc.abstractproperty
57  def Dimensions(self):
58    """ Returns:
59          The dimensions of the frame sequence as a tuple int (width, height).
60          This value should be constant across frames.
61    """
62    raise NotImplementedError
63