Ocean
ImageSequence.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MEDIA_IMAGE_SEQUENCE_H
9 #define META_OCEAN_MEDIA_IMAGE_SEQUENCE_H
10 
11 #include "ocean/media/Media.h"
14 
15 #include "ocean/base/Thread.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Media
21 {
22 
23 // Forward declaration.
24 class ImageSequence;
25 
26 /**
27  * Definition of a smart medium reference holding an image sequence object.
28  * @see SmartMediumRef, ImageSequence.
29  * @ingroup media
30  */
32 
33 /**
34  * This class is the base class for all image sequences.
35  * An image sequence provides a sequence of several images.<br>
36  * This media object will provide all images that are part of the entire image sequence.<br>
37  * Two individual modes exist to receive the images: automatic and explicit.
38  *
39  * The automatic mode (default) delivers frames automatically.<br>
40  * By default the image sequence will deliver one frame per second (default fps = 1).<br>
41  * Change the preferred frame rate as desired but be aware the actual frame rate can be lower.<br>
42  * If a frame rate of 0 fps is specified, the medium will pause after each new frame and will need to be restarted afterwards.<br>
43  *
44  * The explicit mode does not deliver frames based on a specified frame rate (fps) but provides a new frame each time forceNextFrame() is called.<br>
45  * Thus, the explicit mode allows to receive frames as fast as possible (based on the system performance) or can deliver frames very uneven - whatever is needed.
46  * @see Image, PixelImage, mode(), setMode(), forceFrame().
47  * @ingroup media
48  */
49 class OCEAN_MEDIA_EXPORT ImageSequence :
50  public virtual FiniteMedium,
51  public virtual FrameMedium
52 {
53  public:
54 
55  /**
56  * Defines different sequence modes.
57  */
59  {
60  /// Invalid sequence mode.
62  /// Automatic sequence mode, frames will be delivered regarding the preferred fps.
64  /// Explicit sequence mode, frames will be delivered by explicit request.
65  SM_EXPLICIT
66  };
67 
68  public:
69 
70  /**
71  * Returns the mode of this image sequence object.
72  * @return Sequence mode, SM_AUTOMATIC by default
73  * @see forceNextFrame().
74  */
75  virtual SequenceMode mode() const;
76 
77  /**
78  * Returns the index of the current image.
79  * The index of the frame may not be related with the digits within the corresponding filename,<br>
80  * as the first available frame of this sequence has index 0.
81  * @return Current image index, with range [0, images())
82  * @see images().
83  */
84  virtual unsigned int index() const;
85 
86  /**
87  * Returns the url of the current image.
88  * @return Current image url
89  */
90  virtual std::string currentUrl() const = 0;
91 
92  /**
93  * Sets the sequence mode of this image sequence.
94  * The explicit loading is allowed for explicit sequence mode only.
95  * @see mode(), forceNextFrame().
96  * @return True, if succeeded
97  */
98  virtual bool setMode(const SequenceMode mode);
99 
100  /**
101  * Returns the number of images part of the sequence.
102  * @return Number of images, with range [0, infinity)
103  * @see index().
104  */
105  virtual unsigned int images() const = 0;
106 
107  /**
108  * Sets the preferred frame pixel format.
109  * @see FrameMedium::setPreferredFramePixelFormat().
110  */
112 
113  /**
114  * Sets the preferred frame frequency in Hz.
115  * @see FrameMedium::setPreferredFrameFrequency().
116  */
117  bool setPreferredFrameFrequency(const FrameFrequency frequency) override;
118 
119  /**
120  * Forces the loading of the next image in the sequence.
121  * This function must be called whenever a new frame should be delivered.<br>
122  * Beware: Do not call this function unless the sequence mode is SM_EXPLICIT.
123  * @return True, if a new frame will be delivered; False, if the end of the image sequence has been reached or if this medium is invalid
124  */
125  virtual bool forceNextFrame() = 0;
126 
127  protected:
128 
129  /**
130  * Creates a new image sequence by a given url.
131  * @param url Url of the image
132  */
133  explicit ImageSequence(const std::string& url);
134 
135  /**
136  * Destructs an image sequence object.
137  */
138  ~ImageSequence() override;
139 
140  protected:
141 
142  /// Index of the first frame.
143  unsigned int mediumFrameStartIndex;
144 
145  /// Index of the recent frame.
146  unsigned int mediumFrameIndex;
147 
148  /// Number of sequence frames.
149  mutable unsigned int mediumImages;
150 
151  /// State determining whether the sequence filenames have a constant length.
153 
154  /// Sequence mode of this image sequence object.
156 
157  /// State determining whether the explicit sequence mode has been started.
159 };
160 
161 }
162 
163 }
164 
165 #endif // META_OCEAN_MEDIA_IMAGE_SEQUENCE_H
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
This class is the base class for all finite mediums.
Definition: FiniteMedium.h:36
This is the base class for all frame mediums.
Definition: FrameMedium.h:53
double FrameFrequency
Definition of a frame frequency defined in Hz.
Definition: FrameMedium.h:59
This class is the base class for all image sequences.
Definition: ImageSequence.h:52
unsigned int mediumFrameIndex
Index of the recent frame.
Definition: ImageSequence.h:146
bool setPreferredFramePixelFormat(const FrameType::PixelFormat format) override
Sets the preferred frame pixel format.
bool mediumExplicitSequenceModeStarted
State determining whether the explicit sequence mode has been started.
Definition: ImageSequence.h:158
SequenceMode mediumSequenceMode
Sequence mode of this image sequence object.
Definition: ImageSequence.h:155
virtual bool forceNextFrame()=0
Forces the loading of the next image in the sequence.
unsigned int mediumFrameStartIndex
Index of the first frame.
Definition: ImageSequence.h:143
virtual SequenceMode mode() const
Returns the mode of this image sequence object.
unsigned int mediumImages
Number of sequence frames.
Definition: ImageSequence.h:149
~ImageSequence() override
Destructs an image sequence object.
SequenceMode
Defines different sequence modes.
Definition: ImageSequence.h:59
@ SM_AUTOMATIC
Automatic sequence mode, frames will be delivered regarding the preferred fps.
Definition: ImageSequence.h:63
@ SM_INVALID
Invalid sequence mode.
Definition: ImageSequence.h:61
virtual bool setMode(const SequenceMode mode)
Sets the sequence mode of this image sequence.
ImageSequence(const std::string &url)
Creates a new image sequence by a given url.
virtual unsigned int index() const
Returns the index of the current image.
virtual std::string currentUrl() const =0
Returns the url of the current image.
bool setPreferredFrameFrequency(const FrameFrequency frequency) override
Sets the preferred frame frequency in Hz.
virtual unsigned int images() const =0
Returns the number of images part of the sequence.
unsigned int mediumFilenameIndexLength
State determining whether the sequence filenames have a constant length.
Definition: ImageSequence.h:152
SmartMediumRef< ImageSequence > ImageSequenceRef
Definition of a smart medium reference holding an image sequence object.
Definition: ImageSequence.h:24
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15