Ocean
FrameProviderInterface.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_CV_FRAME_PROVIDER_INTERFACE_H
9 #define META_OCEAN_CV_FRAME_PROVIDER_INTERFACE_H
10 
11 #include "ocean/cv/CV.h"
12 
13 #include "ocean/base/Callback.h"
14 #include "ocean/base/Frame.h"
15 #include "ocean/base/ObjectRef.h"
16 
17 namespace Ocean
18 {
19 
20 namespace CV
21 {
22 
23 // Forward declaration.
24 class FrameProviderInterface;
25 
26 /**
27  * Definition of an object reference holding a frame provider interface.
28  * @see FrameProviderInterface;
29  * @ingroup cv
30  */
32 
33 /**
34  * This class defines an abstract interface allowing to request frames from any kind of frame provider.
35  * @ingroup cv
36  */
37 class OCEAN_CV_EXPORT FrameProviderInterface
38 {
39  friend class ObjectRef<FrameProviderInterface>;
40 
41  public:
42 
43  /**
44  * Definition of a frame request callback function.
45  * A frame request callback is invoked by the interface whenever a requested frame arrives.
46  */
48 
49  /**
50  * Definition of a frame number request callback function.
51  */
53 
54  /**
55  * Definition of a frame type request callback function.
56  */
58 
59  protected:
60 
61  /**
62  * Definition of a list that stores frame request callbacks.
63  */
65 
66  /**
67  * Definition of a list that stores frame number request callbacks.
68  */
70 
71  /**
72  * Definition of a list that stores frame type request callbacks.
73  */
75 
76  public:
77 
78  /**
79  * Returns whether the internal information of this interface has been initialized already and whether request functions can be handled.
80  * No request function of this interface should be invoked before this interface has been initialized successfully.<br>
81  * @return True, if so
82  * @see synchronInitializationRequest(), setPreferredFrameType().
83  */
84  virtual bool isInitialized() = 0;
85 
86  /**
87  * Waits until this interface has been initialized.
88  * @param timeout The time this functions waits at most for the initialization, in seconds, with range [0, infinity)
89  * @param abort Optional abort statement allowing to abort the frame type request at any time; set the value True to abort the request
90  * @return True, if the interface is initialized
91  * @see isInitialized().
92  */
93  virtual bool synchronInitializationRequest(const double timeout = 120.0, bool* abort = nullptr);
94 
95  /**
96  * Sets a preferred frame type pixel format and pixel origin for this interface.
97  * If a preferred frame type is set and the native frame type can be converted into the requested frame type, all frames of this interface will have the requested type.<br>
98  * However, there is no guarantee that this interface will be able to provided the requested frame type.<br>
99  * Beware: Ensure that this interface has been initialized before calling this function.<br>
100  * @param pixelFormat The preferred pixel format
101  * @param pixelOrigin The preferred pixel origin
102  * @return True, if succeeded
103  * @see isInitialized().
104  */
105  virtual bool setPreferredFrameType(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin) = 0;
106 
107  /**
108  * Invokes an asynchronous frame request.
109  * The requested frame is identified by the index of the frame.<br>
110  * Even if not frame request callback has been registered, this function can be used to cache the requested frame inside the interface (this might speed up the synchronous frame request).<br>
111  * Beware: There is no guarantee that the requested frame will be delivered eventually, e.g. the requested frame might not exist.<br>
112  * @param index The index of the requested frame, should be in the range [0, synchronFrameNumberRequest())
113  * @param priority True, to request the frame with highest priority
114  * @see synchronFrameRequest().
115  */
116  virtual void asynchronFrameRequest(const unsigned int index, const bool priority = false) = 0;
117 
118  /**
119  * Invokes a synchronous frame request.
120  * The requested frame is identified by the index of the frame.<br>
121  * This function returns an invalid frame if the requested frame cannot be delivered within a specified time frame or the abort statement has been set.<br>
122  * @param index The index of the requested frame, should be in the range [0, synchronFrameNumberRequest())
123  * @param timeout The time this functions waits at most for a requested frame, in seconds, with range [0, infinity)
124  * @param abort Optional abort statement allowing to abort the frame request at any time; set the value True to abort the request
125  * @return Resulting frame, if the frame can be delivered within the specified time frame
126  */
127  virtual FrameRef synchronFrameRequest(const unsigned int index, const double timeout = 10.0, bool* abort = nullptr) = 0;
128 
129  /**
130  * Invokes a suggestion to pre-load or to cache some frames that might be requested soon.
131  * However, there is no guarantee that the requested frames will be pre-loaded.<br>
132  * Every provider is responsible to support the frame suggestions as best as possible regarding the overall system performance.<br>
133  * @param index The index of the next frame that is suggested, with range [0, asynchronFrameNumberRequest())
134  * @param range The positive or negative range of frames that are suggested; use a positive range to cache frame with increasing indices, use a negative range to cache frames with decreasing indices
135  */
136  virtual void frameCacheRequest(const unsigned int index, const int range);
137 
138  /**
139  * Invokes an asynchronous frame number request.
140  * An already registered frame number request callback function is necessary so that the requested frame number can be delivered eventually.<br>
141  * Beware: There is no guarantee that the requested frame number will be delivered eventually.<br>
142  * @see synchronFrameNumberRequest().
143  */
144  virtual void asynchronFrameNumberRequest() = 0;
145 
146  /**
147  * Invokes a synchronous frame number request.
148  * This function returns an invalid frame number if the requested frame number cannot be determined within a specified time frame or if the abort statement has been set.<br>
149  * @param timeout The time this functions waits at most for the requested frame number, in seconds, with range [0, infinity)
150  * @param abort Optional abort statement allowing to abort the frame number request at any time; set the value True to abort the request
151  * @return Resulting number of frames, 0xFFFFFFFF if the frame number is invalid
152  */
153  virtual unsigned int synchronFrameNumberRequest(const double timeout = 10.0, bool* abort = nullptr) = 0;
154 
155  /**
156  * Invokes an asynchronous frame type request.
157  * An already registered frame type request callback function is necessary so that the requested frame type can be delivered eventually.<br>
158  * Beware: There is no guarantee that the requested frame type will be delivered eventually.<br>
159  * @see synchronFrameTypeRequest().
160  */
161  virtual void asynchronFrameTypeRequest() = 0;
162 
163  /**
164  * Invokes a synchronous frame type request.
165  * This function returns an invalid frame type if the requested frame type cannot be determined within a specified time frame or if the abort statement has been set.<br>
166  * @param timeout The time this functions waits at most for the requested frame type, in seconds, with range [0, infinity)
167  * @param abort Optional abort statement allowing to abort the frame type request at any time; set the value True to abort the request
168  * @return Resulting frame type of this interface
169  */
170  virtual FrameType synchronFrameTypeRequest(const double timeout = 10.0, bool* abort = nullptr) = 0;
171 
172  /**
173  * Registers a new callback function for asynchronous frame requests.
174  * All registered functions will be invoked whenever a requested frame arrives.<br>
175  * Each registered callback must be unregistered when it is not needed anymore or before the system is released.<br>
176  * @param callback Frame request callback function that will be registered
177  * @see unregisterFrameCallback().
178  */
179  void registerFrameCallback(const FrameCallback& callback);
180 
181  /**
182  * Unregisters an already registered callback function for frame requests.
183  * @param callback The callback function that will be unregistered
184  * @see registerFrameCallback().
185  */
186  void unregisterFrameCallback(const FrameCallback& callback);
187 
188  /**
189  * Registers a new callback function for asynchronous frame number requests.
190  * All registered functions will be invoked after a frame number request has been invoked.<br>
191  * Each registered callback must be unregistered when it is not needed anymore or before the system is released.<br>
192  * @param callback Frame request callback function that will be registered
193  * @see unregisterFrameCallback().
194  */
196 
197  /**
198  * Unregisters an already registered callback function for frame number requests.
199  * @param callback The callback function that will be unregistered
200  * @see registerFrameNumberCallback().
201  */
203 
204  /**
205  * Registers a new callback function for asynchronous frame type requests.
206  * All registered functions will be invoked after a frame type request has been invoked.<br>
207  * Each registered callback must be unregistered when it is not needed anymore or before the system is released.<br>
208  * @param callback Frame type request callback function that will be registered
209  * @see unregisterFrameTypeCallback().
210  */
212 
213  /**
214  * Unregisters an already registered callback function for frame type requests.
215  * @param callback The callback function that will be unregistered
216  * @see registerFrameTypeCallback().
217  */
219 
220  /**
221  * Releases all associated resources.
222  * Beware: The registered callback functions are not released.
223  */
224  virtual void release();
225 
226  protected:
227 
228  /**
229  * Protected default constructor.
230  */
232 
233  /**
234  * Disabled copy constructor.
235  * @param frameProviderInterface Object which would be copied
236  */
237  FrameProviderInterface(const FrameProviderInterface& frameProviderInterface) = delete;
238 
239  /**
240  * Releases the interface.
241  * At the moment this interface is released all registered resources (callback functions) must be unregistered.
242  */
244 
245  /**
246  * Disabled copy constructor.
247  * @param frameProviderInterface Object which would be copied
248  * @return Reference to this object
249  */
250  FrameProviderInterface& operator=(const FrameProviderInterface& frameProviderInterface) = delete;
251 
252  protected:
253 
254  /// A list of frame request callbacks.
256 
257  /// A list of frame number request callbacks.
259 
260  /// A list of frame type request callbacks.
262 };
263 
264 }
265 
266 }
267 
268 #endif // META_OCEAN_CV_FRAME_PROVIDER_INTERFACE_H
This class defines an abstract interface allowing to request frames from any kind of frame provider.
Definition: FrameProviderInterface.h:38
FrameProviderInterface & operator=(const FrameProviderInterface &frameProviderInterface)=delete
Disabled copy constructor.
virtual bool isInitialized()=0
Returns whether the internal information of this interface has been initialized already and whether r...
virtual ~FrameProviderInterface()
Releases the interface.
void registerFrameTypeCallback(const FrameTypeCallback &callback)
Registers a new callback function for asynchronous frame type requests.
void unregisterFrameTypeCallback(const FrameTypeCallback &callback)
Unregisters an already registered callback function for frame type requests.
void registerFrameNumberCallback(const FrameNumberCallback &callback)
Registers a new callback function for asynchronous frame number requests.
FrameCallbacks frameCallbacks_
A list of frame request callbacks.
Definition: FrameProviderInterface.h:255
ConcurrentCallbacks< FrameCallback > FrameCallbacks
Definition of a list that stores frame request callbacks.
Definition: FrameProviderInterface.h:64
Callback< void, FrameRef, const unsigned int > FrameCallback
Definition of a frame request callback function.
Definition: FrameProviderInterface.h:47
FrameProviderInterface(const FrameProviderInterface &frameProviderInterface)=delete
Disabled copy constructor.
ConcurrentCallbacks< FrameTypeCallback > FrameTypeCallbacks
Definition of a list that stores frame type request callbacks.
Definition: FrameProviderInterface.h:74
Callback< void, unsigned int > FrameNumberCallback
Definition of a frame number request callback function.
Definition: FrameProviderInterface.h:52
virtual bool setPreferredFrameType(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin)=0
Sets a preferred frame type pixel format and pixel origin for this interface.
virtual unsigned int synchronFrameNumberRequest(const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame number request.
void registerFrameCallback(const FrameCallback &callback)
Registers a new callback function for asynchronous frame requests.
virtual FrameType synchronFrameTypeRequest(const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame type request.
Callback< void, const FrameType & > FrameTypeCallback
Definition of a frame type request callback function.
Definition: FrameProviderInterface.h:57
FrameTypeCallbacks frameTypeCallbacks_
A list of frame type request callbacks.
Definition: FrameProviderInterface.h:261
virtual bool synchronInitializationRequest(const double timeout=120.0, bool *abort=nullptr)
Waits until this interface has been initialized.
FrameNumberCallbacks frameNumberCallbacks_
A list of frame number request callbacks.
Definition: FrameProviderInterface.h:258
void unregisterFrameCallback(const FrameCallback &callback)
Unregisters an already registered callback function for frame requests.
void unregisterFrameNumberCallback(const FrameNumberCallback &callback)
Unregisters an already registered callback function for frame number requests.
virtual void asynchronFrameRequest(const unsigned int index, const bool priority=false)=0
Invokes an asynchronous frame request.
ConcurrentCallbacks< FrameNumberCallback > FrameNumberCallbacks
Definition of a list that stores frame number request callbacks.
Definition: FrameProviderInterface.h:69
FrameProviderInterface()=default
Protected default constructor.
virtual void asynchronFrameTypeRequest()=0
Invokes an asynchronous frame type request.
virtual void frameCacheRequest(const unsigned int index, const int range)
Invokes a suggestion to pre-load or to cache some frames that might be requested soon.
virtual void asynchronFrameNumberRequest()=0
Invokes an asynchronous frame number request.
virtual void release()
Releases all associated resources.
virtual FrameRef synchronFrameRequest(const unsigned int index, const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame request.
This class implements a container for callback functions.
Definition: Callback.h:3456
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
PixelOrigin
Defines different types of frame origin positions.
Definition: Frame.h:1014
ObjectRef< FrameProviderInterface > FrameProviderInterfaceRef
Definition of an object reference holding a frame provider interface.
Definition: FrameProviderInterface.h:24
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15