Ocean
FrameMedium.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_FRAME_MEDIUM_H
9 #define META_OCEAN_MEDIA_FRAME_MEDIUM_H
10 
11 #include "ocean/media/Media.h"
13 #include "ocean/media/Medium.h"
14 #include "ocean/media/MediumRef.h"
15 
16 #include "ocean/base/Frame.h"
18 #include "ocean/base/Timestamp.h"
19 
20 #include "ocean/math/AnyCamera.h"
22 
23 #include <functional>
24 
25 namespace Ocean
26 {
27 
28 namespace Media
29 {
30 
31 // Forward declaration.
32 class FrameMedium;
33 
34 /**
35  * Definition of a smart medium reference holding a frame medium object.
36  * @see SmartMediumRef, FrameMedium.
37  * @ingroup media
38  */
40 
41 /**
42  * Definition of a vector holding frame medium reference objects.
43  * @see FrameMediumRef.
44  * @ingroup media
45  */
46 typedef std::vector<FrameMediumRef> FrameMediumRefs;
47 
48 /**
49  * This is the base class for all frame mediums.
50  * @ingroup media
51  */
52 class OCEAN_MEDIA_EXPORT FrameMedium : virtual public Medium
53 {
54  public:
55 
56  /**
57  * Definition of a frame frequency defined in Hz.
58  */
59  typedef double FrameFrequency;
60 
61  /**
62  * Definition of a media frame type composed by the frame dimension, pixel format, pixel origin and a frame frequency.
63  */
64  class OCEAN_MEDIA_EXPORT MediaFrameType : public FrameType
65  {
66  public:
67 
68  /**
69  * Creates a new media frame type with invalid parameters.
70  */
71  MediaFrameType() = default;
72 
73  /**
74  * Creates a new media frame type.
75  * @param frameType Frame type defining most parameters
76  * @param frequency Frame frequency in Hz
77  */
78  inline MediaFrameType(const FrameType& frameType, const FrameFrequency frequency);
79 
80  /**
81  * Creates a new media frame type from a given media frame type with new width and height parameter.
82  * @param mediaFrameType The media frame type that is used as template for the new one
83  * @param width The width of the frame in pixel, with range [mediaFrameType.croppingLeft() + mediaFrameType.croppingWidth(), infinity)
84  * @param height The height of the frame in pixel, with range [mediaFrameType.croppingTop() + mediaFrameType.croppingHeight(), infinity)
85  */
86  inline MediaFrameType(const MediaFrameType& mediaFrameType, const unsigned int width, const unsigned int height);
87 
88  /**
89  * Creates a new media frame type from a given media frame type with new pixel format.
90  * @param mediaFrameType The media frame type that is used as template for the new one
91  * @param pixelFormat The new pixel format
92  */
93  inline MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat);
94 
95  /**
96  * Creates a new media frame type from a given media frame type with new pixel format.
97  * @param mediaFrameType The media frame type that is used as template for the new one
98  * @param pixelFormat The new pixel format
99  * @param pixelOrigin The new pixel origin
100  */
101  inline MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin);
102 
103  /**
104  * Creates a new frame type.
105  * @param width The width of the frame in pixel, with range [0, infinity)
106  * @param height The height of the frame in pixel, with range [0, infinity)
107  * @param pixelFormat Pixel format of the frame
108  * @param pixelOrigin Pixel origin of the frame
109  * @param frequency Frame frequency in Hz
110  */
111  inline MediaFrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin, const FrameFrequency frequency);
112 
113  /**
114  * Returns the frame frequency in Hz.
115  * @return Frame frequency in Hz
116  */
117  inline FrameFrequency frequency() const;
118 
119  /**
120  * Returns the left start position of the cropping area.
121  * @return Left start position, in pixel
122  */
123  inline unsigned int croppingLeft() const;
124 
125  /**
126  * Returns the top start position of the cropping area.
127  * @return Top start position, in pixel
128  */
129  inline unsigned int croppingTop() const;
130 
131  /**
132  * Returns the width of the cropping area in pixel,
133  * @return Width of the cropping area, 0 if no cropping is defined
134  */
135  inline unsigned int croppingWidth() const;
136 
137  /**
138  * Returns the height of the cropping area in pixel,
139  * @return Height of the cropping area, 0 if no cropping is defined
140  */
141  inline unsigned int croppingHeight() const;
142 
143  /**
144  * Sets the frame frequency in Hz.
145  * @param frequency The frequency to set
146  */
147  inline void setFrequency(const FrameFrequency frequency);
148 
149  /**
150  * Sets the optional cropping area of this media frame type.
151  * @param left The left cropping start position
152  * @param top The top cropping start position
153  * @param width The width of the cropping area, 0 if no cropping is defined
154  * @param height The height of the cropping area, 0 if no cropping is defined
155  */
156  inline void setCroppingArea(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height);
157 
158  protected:
159 
160  /// Frame frequency.
162 
163  /// Left cropping start position, in pixel
164  unsigned int croppingLeft_ = 0u;
165 
166  /// Top cropping start position, in pixel
167  unsigned int croppingTop_ = 0u;
168 
169  /// Width of the cropping area, in pixel, 0 if no cropping is defined
170  unsigned int croppingWidth_ = 0u;
171 
172  /// Height of the cropping area, in pixel, 0 if no cropping is defined
173  unsigned int croppingHeight_ = 0u;
174  };
175 
176  /**
177  * Definition of a callback function for frame events.
178  * @param frame The event's frame, will be valid
179  * @param camera The camera profile associated with the frame, invalid if unknown
180  */
181  typedef std::function<void(const Frame& frame, const SharedAnyCamera& camera)> FrameCallbackFunction;
182 
183  /**
184  * Definition of a subscription object for frame callback events.
185  */
187 
188  /**
189  * This class implements a simpler receiver for frames which can be used with the frame callback functionality of FrameMedium.
190  * Below the code showing how to use the FrameReceiver.
191  * @code
192  * Media::FrameMediumRef frameMedium = Media::Manager::get().newMedium(...);
193  * ocean_assert(frameMedium);
194  *
195  * FrameReceiver frameReceiver;
196  *
197  * Media::FrameMedium::FrameCallbackScopedSubscription subscription = frameMedium->addFrameCallback(std::bind(&FrameReceiver::onFrame, &frameReceiver, std::placeholders::_1, std::placeholders::_2));
198  *
199  * frameMedium->start();
200  *
201  * // alternative 1: latestFrame() which does not make a copy of the frame's memory
202  * while (!frameMedium->taskFinished())
203  * {
204  * Frame frame;
205  * if (frameReceiver.latestFrame(frame))
206  * {
207  * // the frame will not own the memory
208  * ocean_assert(!frame.isOwner());
209  *
210  * frameReceiver.reset();
211  * }
212  *
213  * // the 'frame' most not be accessed anymore
214  * }
215  *
216  * // alternative 2: latestFrameAndReset() which does make a copy of the frame's memory
217  * while (!frameMedium->taskFinished())
218  * {
219  * Frame frame;
220  * if (frameReceiver.latestFrameAndReset(frame))
221  * {
222  * ocean_assert(frame.isOwner());
223  * }
224  *
225  * // we still can access the frame if latestFrameAndReset() returned 'true'
226  * }
227  * @endcode
228  * @see addFrameCallback().
229  */
230  class OCEAN_MEDIA_EXPORT FrameReceiver final
231  {
232  public:
233 
234  /**
235  * Default constructor.
236  */
237  FrameReceiver() = default;
238 
239  /**
240  * Resets and destructor this object.
241  */
243 
244  /**
245  * Event function for a new movie frame.
246  * This function will not return until this object does not hold a latest frame anymore.
247  * @param frame The new movie frame, will be valid
248  * @param camera The camera profile associated with the frame, invalid if unknown
249  */
250  void onFrame(const Frame& frame, const SharedAnyCamera& camera);
251 
252  /**
253  * Returns the latest frame and camera profile.
254  * Use this function to avoid making a copy of the original frame as the resulting frame does not own the memory.<br>
255  * The same latest frame will be provided until reset() is called.
256  * @param frame The resulting frame, not owning the memory
257  * @param camera Optional resulting camera
258  * @return True, if a latest frame exists
259  * @see reset(), latestFrameAndReset().
260  */
261  bool latestFrame(Frame& frame, SharedAnyCamera* camera = nullptr);
262 
263  /**
264  * Returns the latest frame and camera profile and resets the receiver.
265  * This function provides a copy of the original frame so that the frame owns the memory.<br>
266  * The receive will be reset so that the object can receive a new frame.
267  * @param frame The resulting frame, not owning the memory
268  * @param camera Optional resulting camera
269  * @return True, if a latest frame exists
270  */
271  bool latestFrameAndReset(Frame& frame, SharedAnyCamera* camera = nullptr);
272 
273  /**
274  * Resets the receiver so that a new frame can be received.
275  */
276  void reset();
277 
278  protected:
279 
280  /// The most recent frame.
282 
283  /// The camera profile associated with the most recent frame.
285 
286  /// The object's lock.
288  };
289 
290  protected:
291 
292  /**
293  * Definition of a thread-safe subscription handler for frame callback functions.
294  */
296 
297  protected:
298 
299  /**
300  * Definition of a vector holding frame types.
301  */
302  typedef std::vector<MediaFrameType> FrameTypes;
303 
304  /**
305  * Class allowing the sorting of several frame media types according their popularity.
306  */
307  class OCEAN_MEDIA_EXPORT SortableFrameType
308  {
309  public:
310 
311  /**
312  * Creates a new sortable frame media type.
313  * @param frameType Preferable frame type
314  */
316 
317  /**
318  * Creates a new sortable frame type.
319  * @param width Preferable reference width
320  * @param height Preferable reference height
321  * @param pixelFormat Preferable reference pixel format
322  * @param pixelOrigin Preferable reference pixel origin
323  * @param frequency Preferable reference frequency
324  */
325  SortableFrameType(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const FrameFrequency frequency);
326 
327  /**
328  * Returns whether the left sortable media type is more preferred than the right one.
329  * @param right The right sortable media type
330  * @return True, if so
331  */
332  bool operator<(const SortableFrameType& right) const;
333 
334  protected:
335 
336  /// Actual frame type.
338 
339  /// Preferable frame type.
341  };
342 
343  public:
344 
345  /**
346  * Destructs a frame object.
347  */
348  ~FrameMedium() override;
349 
350  /**
351  * Returns whether the object holds a frame.
352  * @return True, if so
353  */
354  inline bool hasFrame() const;
355 
356  /**
357  * Returns the frequency of the frame in Hz.
358  * @return Frequency of the frame in Hz
359  */
360  inline FrameFrequency frameFrequency() const;
361 
362  /**
363  * Returns the most recent frame.
364  * @param anyCamera Optional resulting camera profile of the frame, if known
365  * @return Most recent frame
366  */
367  virtual FrameRef frame(SharedAnyCamera* anyCamera = nullptr) const;
368 
369  /**
370  * Returns the frame with a specific timestamp.
371  * If no frame exists with the given timestamp the most recent frame is returned.
372  * @param timestamp The timestamp of the frame to return
373  * @param anyCamera Optional resulting camera profile of the frame, if known
374  * @return Requested frame
375  * @see hasFrame().
376  */
377  virtual FrameRef frame(const Timestamp timestamp, SharedAnyCamera* anyCamera = nullptr) const;
378 
379  /**
380  * Waits until the first frame is available.
381  * If the time to wait is exceeded and no frame is available, no frame is returned.<br>
382  * @param timeout Time to wait for the first frame, in seconds, with range [0, infinity)
383  * @param anyCamera Optional resulting camera profile of the frame, if known
384  * @return Frame if available
385  */
386  virtual FrameRef frameTimeout(const double timeout, SharedAnyCamera* anyCamera = nullptr) const;
387 
388  /**
389  * Returns whether this media object currently holds a frame with specified timestamp.
390  * Beware: There is no guarantee that the frame will be available after this call due to multi-thread issues!
391  * @param timestamp The timestamp to be checked
392  * @return True, if so
393  */
394  virtual bool hasFrame(const Timestamp timestamp) const;
395 
396  /**
397  * Returns the preferred width of the frame in pixel.
398  * @return Preferred frame width
399  * @see setPreferredFrameDiminsion(), preferredFrameHeight().
400  */
401  inline unsigned int preferredFrameWidth() const;
402 
403  /**
404  * Returns the preferred height of the frame in pixel.
405  * @return Preferred frame height
406  * @see setPreferredFrameDiminsion(), preferredFrameWidth().
407  */
408  inline unsigned int preferredFrameHeight() const;
409 
410  /**
411  * Returns the preferred frame pixel format.
412  * @return Preferred pixel format
413  * @see setPreferredFramePixelFormat().
414  */
415  inline FrameType::PixelFormat preferredFramePixelFormat() const;
416 
417  /**
418  * Returns the preferred frame frequency in Hz.
419  * @return Preferred frame frequency in Hz
420  * @see setPreferredFrameFrequency().
421  */
422  inline FrameFrequency preferredFrameFrequency() const;
423 
424  /**
425  * Returns the transformation between the camera and device.
426  * The device can be either a webcam, a mobile phone, or any other device delivering visual information.
427  * The transformation between camera and device represents the offset translation and orientation between the camera sensor and the device (e.g., the display of the device).<br>
428  * The device coordinate system has the origin in the center of the device (e.g., the display) and the Z-axis is pointing out towards the user.<br>
429  * The camera coordinate system has the origin in the center of the camera (center of projection) and the negative Z-axis is pointing towards the scene.
430  * <pre>
431  * device top
432  * ...........................
433  * . . camera
434  * . ^ . ---------------------------------
435  * . Y | . | ^ |
436  * . | . | Y | |
437  * . | . | | |
438  * . O ---------> . | | |
439  * . / X . | O ---------> |
440  * . / Z . | / X |
441  * . v . | / Z |
442  * . . | v |
443  * ........................... ---------------------------------
444  * . home button .
445  * ...........................
446  * device bottom
447  * </pre>
448  */
450 
451  /**
452  * Sets the preferred frame dimension.
453  * Beware: There is no guarantee that this dimension can be provided.
454  * @param width Preferred frame width in pixel
455  * @param height Preferred frame height in pixel
456  * @return True, if the medium accepts this preferred values.
457  * @see preferredFrameWidth(), preferredFrameHeight().
458  */
459  virtual bool setPreferredFrameDimension(const unsigned int width, const unsigned int height);
460 
461  /**
462  * Sets the preferred frame pixel format.
463  * Beware: There is no guarantee that this pixel format can be provided.
464  * @param format Preferred pixel format
465  * @return True, if the medium accepts this preferred value.
466  * @see preferredFramePixelFormat().
467  */
469 
470  /**
471  * Sets the preferred frame frequency in Hz.
472  * Beware: There is no guarantee that this frequency can be provided.
473  * @param frequency Preferred frequency in Hz
474  * @return True, if the medium accepts this preferred value.
475  * @see preferredFrameFrequency().
476  */
477  virtual bool setPreferredFrameFrequency(const FrameFrequency frequency);
478 
479  /**
480  * Returns the capacity of the frame history of this frame medium object.
481  * @return The capacity of frames, with range [1, infinity)
482  */
483  size_t capacity() const;
484 
485  /**
486  * Sets or changes the capacity of the frame history of this frame medium object.
487  * @param capacity The capacity to set, with range [1, infinity)
488  * @return True, if succeeded
489  */
490  bool setCapacity(const size_t capacity);
491 
492  /**
493  * Adds a callback function which is called whenever a new frame arrives.
494  * If at least one callback is registered, this frame medium will not store any frame in the internal frame store.
495  * @param frameCallbackFunction The callback function to be added, must be valid
496  * @return The subscription object, the callback function will exist as long as the subscription object exists
497  * @see frame()
498  */
500 
501  /**
502  * Extracts most recent frames from several frame medium objects and ensures that the timestamps of all frames are identical.
503  * @param frameMediums The frame medium objects from which the frames will be extracted, at least one
504  * @param lastTimestamp The timestamp of the last extracted frames to accept frames with newer timestamp only, an invalid timestamp to accept any frame
505  * @param frames The resulting frames with identical timestamp, one for each frame medium object
506  * @param cameras The resulting camera profiles, one for each frame medium object
507  * @param waitTime The wait time in milliseconds this function will wait until it fails if not all frame medium objects can provide the expected frame
508  * @param timedOut Optional resulting True in case the function timed out when waiting for all synced frames; nullptr if not of interest
509  * @param device_T_cameras Optional resulting transformations between camera and device, one for each frame medium object; nullptr if not of interest
510  * @return True, if succeeded
511  */
512  static bool syncedFrames(const FrameMediumRefs& frameMediums, const Timestamp lastTimestamp, FrameRefs& frames, SharedAnyCameras& cameras, const unsigned int waitTime = 2u, bool* timedOut = nullptr, HomogenousMatricesD4* device_T_cameras = nullptr);
513 
514  protected:
515 
516  /**
517  * Creates a new frame medium by a given url.
518  * @param url Url of the frame medium
519  */
520  explicit FrameMedium(const std::string& url);
521 
522  /**
523  * Delivers a new frame to this FrameMedium.
524  * The new frame will either be stored in the medium's frame collection or forwarded to subscribed frame callback functions.
525  * @param frame The new frame to deliver, must be valid
526  * @param anyCamera The camera profile associated with the frame, invalid if unknown
527  * @return True, if succeeded
528  */
529  virtual bool deliverNewFrame(Frame&& frame, SharedAnyCamera&& anyCamera = SharedAnyCamera());
530 
531  protected:
532 
533  /// Frame collection storing several frames with different timestamps.
535 
536  /// The handler for frame callback functions.
538 
539  /// Frame frequency.
540  FrameFrequency recentFrameFrequency_ = FrameFrequency(0);
541 
542  /// Preferred frame type of the medium.
544 };
545 
546 inline FrameMedium::MediaFrameType::MediaFrameType(const FrameType& frameType, const FrameFrequency frequency) :
547  FrameType(frameType),
548  frequency_(frequency)
549 {
550  // nothing to do here
551 }
552 
553 inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const unsigned int width, const unsigned int height) :
554  FrameType(mediaFrameType, width, height),
555  frequency_(mediaFrameType.frequency_),
556  croppingLeft_(mediaFrameType.croppingLeft_),
557  croppingTop_(mediaFrameType.croppingTop_),
558  croppingWidth_(mediaFrameType.croppingWidth_),
559  croppingHeight_(mediaFrameType.croppingHeight_)
560 {
561  ocean_assert(croppingLeft_ + croppingWidth_ <= width);
562  ocean_assert(croppingTop_ + croppingHeight_ <= height);
563 }
564 
565 inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat) :
566  FrameType(mediaFrameType, pixelFormat),
567  frequency_(mediaFrameType.frequency_),
568  croppingLeft_(mediaFrameType.croppingLeft_),
569  croppingTop_(mediaFrameType.croppingTop_),
570  croppingWidth_(mediaFrameType.croppingWidth_),
571  croppingHeight_(mediaFrameType.croppingHeight_)
572 {
573  // nothing to do here
574 }
575 
576 inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
577  FrameType(mediaFrameType, pixelFormat, pixelOrigin),
578  frequency_(mediaFrameType.frequency_),
579  croppingLeft_(mediaFrameType.croppingLeft_),
580  croppingTop_(mediaFrameType.croppingTop_),
581  croppingWidth_(mediaFrameType.croppingWidth_),
582  croppingHeight_(mediaFrameType.croppingHeight_)
583 {
584  // nothing to do here
585 }
586 
587 inline FrameMedium::MediaFrameType::MediaFrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin, const FrameFrequency frequency) :
588  FrameType(width, height, pixelFormat, pixelOrigin),
589  frequency_(frequency)
590 {
591  // nothing to do here
592 }
593 
595 {
596  return frequency_;
597 }
598 
599 inline unsigned int FrameMedium::MediaFrameType::croppingLeft() const
600 {
601  return croppingLeft_;
602 }
603 
604 inline unsigned int FrameMedium::MediaFrameType::croppingTop() const
605 {
606  return croppingTop_;
607 }
608 
610 {
611  return croppingWidth_;
612 }
613 
615 {
616  return croppingHeight_;
617 }
618 
620 {
621  frequency_ = frequency;
622 }
623 
624 inline void FrameMedium::MediaFrameType::setCroppingArea(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height)
625 {
626  croppingLeft_ = left;
627  croppingTop_ = top;
628  croppingWidth_ = width;
629  croppingHeight_ = height;
630 }
631 
632 inline bool FrameMedium::hasFrame() const
633 {
634  return bool(frameCollection_.recent());
635 }
636 
638 {
639  return recentFrameFrequency_;
640 }
641 
642 inline unsigned int FrameMedium::preferredFrameWidth() const
643 {
644  return preferredFrameType_.width();
645 }
646 
647 inline unsigned int FrameMedium::preferredFrameHeight() const
648 {
649  return preferredFrameType_.height();
650 }
651 
653 {
655 }
656 
658 {
660 }
661 
662 }
663 
664 }
665 
666 #endif
This class implements Ocean's image class.
Definition: Frame.h:1760
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
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3111
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3121
PixelOrigin
Defines different types of frame origin positions.
Definition: Frame.h:1014
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3116
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a simple buffer holding several frames combined with their timestamps and optio...
Definition: FrameCollection.h:30
FrameRef recent(SharedAnyCamera *anyCamera=nullptr) const
Returns the most recent frame.
This class implements a simpler receiver for frames which can be used with the frame callback functio...
Definition: FrameMedium.h:231
bool latestFrame(Frame &frame, SharedAnyCamera *camera=nullptr)
Returns the latest frame and camera profile.
SharedAnyCamera camera_
The camera profile associated with the most recent frame.
Definition: FrameMedium.h:284
FrameReceiver()=default
Default constructor.
~FrameReceiver()
Resets and destructor this object.
void reset()
Resets the receiver so that a new frame can be received.
Lock lock_
The object's lock.
Definition: FrameMedium.h:287
Frame frame_
The most recent frame.
Definition: FrameMedium.h:281
void onFrame(const Frame &frame, const SharedAnyCamera &camera)
Event function for a new movie frame.
bool latestFrameAndReset(Frame &frame, SharedAnyCamera *camera=nullptr)
Returns the latest frame and camera profile and resets the receiver.
Definition of a media frame type composed by the frame dimension, pixel format, pixel origin and a fr...
Definition: FrameMedium.h:65
unsigned int croppingLeft() const
Returns the left start position of the cropping area.
Definition: FrameMedium.h:599
unsigned int croppingWidth() const
Returns the width of the cropping area in pixel,.
Definition: FrameMedium.h:609
unsigned int croppingTop_
Top cropping start position, in pixel.
Definition: FrameMedium.h:167
FrameFrequency frequency() const
Returns the frame frequency in Hz.
Definition: FrameMedium.h:594
unsigned int croppingLeft_
Left cropping start position, in pixel.
Definition: FrameMedium.h:164
unsigned int croppingHeight() const
Returns the height of the cropping area in pixel,.
Definition: FrameMedium.h:614
MediaFrameType()=default
Creates a new media frame type with invalid parameters.
unsigned int croppingWidth_
Width of the cropping area, in pixel, 0 if no cropping is defined.
Definition: FrameMedium.h:170
void setFrequency(const FrameFrequency frequency)
Sets the frame frequency in Hz.
Definition: FrameMedium.h:619
unsigned int croppingTop() const
Returns the top start position of the cropping area.
Definition: FrameMedium.h:604
unsigned int croppingHeight_
Height of the cropping area, in pixel, 0 if no cropping is defined.
Definition: FrameMedium.h:173
void setCroppingArea(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height)
Sets the optional cropping area of this media frame type.
Definition: FrameMedium.h:624
Class allowing the sorting of several frame media types according their popularity.
Definition: FrameMedium.h:308
MediaFrameType preferableFrameType_
Preferable frame type.
Definition: FrameMedium.h:340
SortableFrameType(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const FrameFrequency frequency)
Creates a new sortable frame type.
MediaFrameType actualFrameType_
Actual frame type.
Definition: FrameMedium.h:337
bool operator<(const SortableFrameType &right) const
Returns whether the left sortable media type is more preferred than the right one.
SortableFrameType(const MediaFrameType &frameType)
Creates a new sortable frame media type.
This is the base class for all frame mediums.
Definition: FrameMedium.h:53
static bool syncedFrames(const FrameMediumRefs &frameMediums, const Timestamp lastTimestamp, FrameRefs &frames, SharedAnyCameras &cameras, const unsigned int waitTime=2u, bool *timedOut=nullptr, HomogenousMatricesD4 *device_T_cameras=nullptr)
Extracts most recent frames from several frame medium objects and ensures that the timestamps of all ...
FrameCallbackHandler frameCallbackHandler_
The handler for frame callback functions.
Definition: FrameMedium.h:537
virtual FrameRef frame(SharedAnyCamera *anyCamera=nullptr) const
Returns the most recent frame.
virtual HomogenousMatrixD4 device_T_camera() const
Returns the transformation between the camera and device.
virtual bool setPreferredFrameFrequency(const FrameFrequency frequency)
Sets the preferred frame frequency in Hz.
FrameMedium(const std::string &url)
Creates a new frame medium by a given url.
FrameFrequency frameFrequency() const
Returns the frequency of the frame in Hz.
Definition: FrameMedium.h:637
virtual bool setPreferredFramePixelFormat(const FrameType::PixelFormat format)
Sets the preferred frame pixel format.
FrameFrequency recentFrameFrequency_
Frame frequency.
Definition: FrameMedium.h:540
~FrameMedium() override
Destructs a frame object.
virtual FrameRef frameTimeout(const double timeout, SharedAnyCamera *anyCamera=nullptr) const
Waits until the first frame is available.
ScopedSubscriptionCallbackHandlerT< FrameCallbackFunction, FrameMedium, true > FrameCallbackHandler
Definition of a thread-safe subscription handler for frame callback functions.
Definition: FrameMedium.h:295
FrameFrequency preferredFrameFrequency() const
Returns the preferred frame frequency in Hz.
Definition: FrameMedium.h:657
bool setCapacity(const size_t capacity)
Sets or changes the capacity of the frame history of this frame medium object.
FrameType::PixelFormat preferredFramePixelFormat() const
Returns the preferred frame pixel format.
Definition: FrameMedium.h:652
unsigned int preferredFrameHeight() const
Returns the preferred height of the frame in pixel.
Definition: FrameMedium.h:647
virtual bool hasFrame(const Timestamp timestamp) const
Returns whether this media object currently holds a frame with specified timestamp.
virtual bool deliverNewFrame(Frame &&frame, SharedAnyCamera &&anyCamera=SharedAnyCamera())
Delivers a new frame to this FrameMedium.
FrameCollection frameCollection_
Frame collection storing several frames with different timestamps.
Definition: FrameMedium.h:534
std::vector< MediaFrameType > FrameTypes
Definition of a vector holding frame types.
Definition: FrameMedium.h:302
ScopedSubscriptionHandler::ScopedSubscriptionType FrameCallbackScopedSubscription
Definition of a subscription object for frame callback events.
Definition: FrameMedium.h:186
size_t capacity() const
Returns the capacity of the frame history of this frame medium object.
std::function< void(const Frame &frame, const SharedAnyCamera &camera)> FrameCallbackFunction
Definition of a callback function for frame events.
Definition: FrameMedium.h:181
double FrameFrequency
Definition of a frame frequency defined in Hz.
Definition: FrameMedium.h:59
virtual FrameRef frame(const Timestamp timestamp, SharedAnyCamera *anyCamera=nullptr) const
Returns the frame with a specific timestamp.
FrameCallbackScopedSubscription addFrameCallback(FrameCallbackFunction &&frameCallbackFunction)
Adds a callback function which is called whenever a new frame arrives.
unsigned int preferredFrameWidth() const
Returns the preferred width of the frame in pixel.
Definition: FrameMedium.h:642
bool hasFrame() const
Returns whether the object holds a frame.
Definition: FrameMedium.h:632
MediaFrameType preferredFrameType_
Preferred frame type of the medium.
Definition: FrameMedium.h:543
virtual bool setPreferredFrameDimension(const unsigned int width, const unsigned int height)
Sets the preferred frame dimension.
This is the base class for all mediums.
Definition: Medium.h:48
This class implements a smart medium reference.
Definition: MediumRef.h:33
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class implements a subscription object which can be used unique subscriptions to e....
Definition: ScopedSubscription.h:28
This class implements a timestamp.
Definition: Timestamp.h:36
std::vector< FrameRef > FrameRefs
Definition of a vector holding frame references.
Definition: Frame.h:1735
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition: AnyCamera.h:60
std::vector< HomogenousMatrixD4 > HomogenousMatricesD4
Definition of a vector holding HomogenousMatrixD4 objects.
Definition: HomogenousMatrix4.h:79
SharedAnyCamerasT< Scalar > SharedAnyCameras
Definition of a vector holding AnyCamera objects.
Definition: AnyCamera.h:90
std::vector< FrameMediumRef > FrameMediumRefs
Definition of a vector holding frame medium reference objects.
Definition: FrameMedium.h:46
SmartMediumRef< FrameMedium > FrameMediumRef
Definition of a smart medium reference holding a frame medium object.
Definition: FrameMedium.h:32
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15