Ocean
Loading...
Searching...
No Matches
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"
15
16#include "ocean/base/Frame.h"
19
22
23#include <functional>
24
25namespace Ocean
26{
27
28namespace Media
29{
30
31// Forward declaration.
32class 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 */
46using FrameMediumRefs = std::vector<FrameMediumRef>;
47
48/**
49 * This is the base class for all frame mediums.
50 * @ingroup media
51 */
52class OCEAN_MEDIA_EXPORT FrameMedium : virtual public Medium
53{
54 public:
55
56 /**
57 * Definition of a frame frequency defined in Hz.
58 */
59 using FrameFrequency = double;
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 using FrameCallbackFunction = std::function<void(const Frame& frame, const SharedAnyCamera& camera)>;
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 * @param timeout The timeout in milliseconds to wait for a new frame, with range [0, infinity)
259 * @return True, if a latest frame exists
260 * @see reset(), latestFrameAndReset().
261 */
262 bool latestFrame(Frame& frame, SharedAnyCamera* camera = nullptr, const unsigned int timeout = 100u);
263
264 /**
265 * Returns the latest frame and camera profile and resets the receiver.
266 * This function provides a copy of the original frame so that the frame owns the memory.<br>
267 * The receive will be reset so that the object can receive a new frame.
268 * @param frame The resulting frame, not owning the memory
269 * @param camera Optional resulting camera
270 * @param timeout The timeout in milliseconds to wait for a new frame, with range [0, infinity)
271 * @return True, if a latest frame exists
272 */
273 bool latestFrameAndReset(Frame& frame, SharedAnyCamera* camera = nullptr, const unsigned int timeout = 100u);
274
275 /**
276 * Resets the receiver so that a new frame can be received.
277 */
278 void reset();
279
280 protected:
281
282 /// The most recent frame.
284
285 /// The camera profile associated with the most recent frame.
287
288 /// The object's lock.
290 };
291
292 protected:
293
294 /**
295 * Definition of a thread-safe subscription handler for frame callback functions.
296 */
298
299 protected:
300
301 /**
302 * Definition of a vector holding frame types.
303 */
304 using FrameTypes = std::vector<MediaFrameType>;
305
306 /**
307 * Class allowing the sorting of several frame media types according their popularity.
308 */
309 class OCEAN_MEDIA_EXPORT SortableFrameType
310 {
311 public:
312
313 /**
314 * Creates a new sortable frame media type.
315 * @param frameType Preferable frame type
316 */
318
319 /**
320 * Creates a new sortable frame type.
321 * @param width Preferable reference width
322 * @param height Preferable reference height
323 * @param pixelFormat Preferable reference pixel format
324 * @param pixelOrigin Preferable reference pixel origin
325 * @param frequency Preferable reference frequency
326 */
327 SortableFrameType(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const FrameFrequency frequency);
328
329 /**
330 * Returns whether the left sortable media type is more preferred than the right one.
331 * @param right The right sortable media type
332 * @return True, if so
333 */
334 bool operator<(const SortableFrameType& right) const;
335
336 protected:
337
338 /// Actual frame type.
340
341 /// Preferable frame type.
343 };
344
345 public:
346
347 /**
348 * Destructs a frame object.
349 */
350 ~FrameMedium() override;
351
352 /**
353 * Returns whether the object holds a frame.
354 * @return True, if so
355 */
356 inline bool hasFrame() const;
357
358 /**
359 * Returns the frequency of the frame in Hz.
360 * @return Frequency of the frame in Hz
361 */
362 inline FrameFrequency frameFrequency() const;
363
364 /**
365 * Returns the most recent frame.
366 * @param anyCamera Optional resulting camera profile of the frame, if known
367 * @return Most recent frame
368 */
369 virtual FrameRef frame(SharedAnyCamera* anyCamera = nullptr) const;
370
371 /**
372 * Returns the frame with a specific timestamp.
373 * If no frame exists with the given timestamp the most recent frame is returned.
374 * @param timestamp The timestamp of the frame to return
375 * @param anyCamera Optional resulting camera profile of the frame, if known
376 * @return Requested frame
377 * @see hasFrame().
378 */
379 virtual FrameRef frame(const Timestamp timestamp, SharedAnyCamera* anyCamera = nullptr) const;
380
381 /**
382 * Waits until the first frame is available.
383 * If the time to wait is exceeded and no frame is available, no frame is returned.<br>
384 * @param timeout Time to wait for the first frame, in seconds, with range [0, infinity)
385 * @param anyCamera Optional resulting camera profile of the frame, if known
386 * @return Frame if available
387 */
388 virtual FrameRef frameTimeout(const double timeout, SharedAnyCamera* anyCamera = nullptr) const;
389
390 /**
391 * Returns whether this media object currently holds a frame with specified timestamp.
392 * Beware: There is no guarantee that the frame will be available after this call due to multi-thread issues!
393 * @param timestamp The timestamp to be checked
394 * @return True, if so
395 */
396 virtual bool hasFrame(const Timestamp timestamp) const;
397
398 /**
399 * Returns the preferred width of the frame in pixel.
400 * @return Preferred frame width
401 * @see setPreferredFrameDimension(), preferredFrameHeight().
402 */
403 inline unsigned int preferredFrameWidth() const;
404
405 /**
406 * Returns the preferred height of the frame in pixel.
407 * @return Preferred frame height
408 * @see setPreferredFrameDimension(), preferredFrameWidth().
409 */
410 inline unsigned int preferredFrameHeight() const;
411
412 /**
413 * Returns the preferred frame pixel format.
414 * @return Preferred pixel format
415 * @see setPreferredFramePixelFormat().
416 */
417 inline FrameType::PixelFormat preferredFramePixelFormat() const;
418
419 /**
420 * Returns the preferred frame frequency in Hz.
421 * @return Preferred frame frequency in Hz
422 * @see setPreferredFrameFrequency().
423 */
424 inline FrameFrequency preferredFrameFrequency() const;
425
426 /**
427 * Returns the transformation between the camera and device.
428 * The device can be either a webcam, a mobile phone, or any other device delivering visual information.
429 * 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>
430 * 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>
431 * 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.
432 * <pre>
433 * device top
434 * ...........................
435 * . . camera
436 * . ^ . ---------------------------------
437 * . Y | . | ^ |
438 * . | . | Y | |
439 * . | . | | |
440 * . O ---------> . | | |
441 * . / X . | O ---------> |
442 * . / Z . | / X |
443 * . v . | / Z |
444 * . . | v |
445 * ........................... ---------------------------------
446 * . home button .
447 * ...........................
448 * device bottom
449 * </pre>
450 */
452
453 /**
454 * Sets the preferred frame dimension.
455 * Beware: There is no guarantee that this dimension can be provided.
456 * @param width Preferred frame width in pixel
457 * @param height Preferred frame height in pixel
458 * @return True, if the medium accepts this preferred values.
459 * @see preferredFrameWidth(), preferredFrameHeight().
460 */
461 virtual bool setPreferredFrameDimension(const unsigned int width, const unsigned int height);
462
463 /**
464 * Sets the preferred frame pixel format.
465 * Beware: There is no guarantee that this pixel format can be provided.
466 * @param format Preferred pixel format
467 * @return True, if the medium accepts this preferred value.
468 * @see preferredFramePixelFormat().
469 */
471
472 /**
473 * Sets the preferred frame frequency in Hz.
474 * Beware: There is no guarantee that this frequency can be provided.
475 * @param frequency Preferred frequency in Hz
476 * @return True, if the medium accepts this preferred value.
477 * @see preferredFrameFrequency().
478 */
479 virtual bool setPreferredFrameFrequency(const FrameFrequency frequency);
480
481 /**
482 * Returns the capacity of the frame history of this frame medium object.
483 * @return The capacity of frames, with range [1, infinity)
484 */
485 size_t capacity() const;
486
487 /**
488 * Sets or changes the capacity of the frame history of this frame medium object.
489 * @param capacity The capacity to set, with range [1, infinity)
490 * @return True, if succeeded
491 */
492 bool setCapacity(const size_t capacity);
493
494 /**
495 * Sets the known camera profile of this frame medium.
496 * This function allows to set a mainly static camera profile which does not change too often over time.<br>
497 * In case the camera profile is changing on a per-frame basis, the camera profile should be provided internally with a custom mechanism in a derived class.
498 * @param camera The camera profile to set, invalid to remove an existing camera profile
499 * @return True, if succeeded
500 */
501 virtual bool setCamera(SharedAnyCamera&& camera);
502
503 /**
504 * Adds a callback function which is called whenever a new frame arrives.
505 * If at least one callback is registered, this frame medium will not store any frame in the internal frame store.
506 * @param frameCallbackFunction The callback function to be added, must be valid
507 * @return The subscription object, the callback function will exist as long as the subscription object exists
508 * @see frame()
509 */
511
512 /**
513 * Extracts most recent frames from several frame medium objects and ensures that the timestamps of all frames are identical.
514 * @param frameMediums The frame medium objects from which the frames will be extracted, at least one
515 * @param lastTimestamp The timestamp of the last extracted frames to accept frames with newer timestamp only, an invalid timestamp to accept any frame
516 * @param frames The resulting frames with identical timestamp, one for each frame medium object
517 * @param cameras The resulting camera profiles, one for each frame medium object
518 * @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
519 * @param timedOut Optional resulting True in case the function timed out when waiting for all synced frames; nullptr if not of interest
520 * @param device_T_cameras Optional resulting transformations between camera and device, one for each frame medium object; nullptr if not of interest
521 * @return True, if succeeded
522 */
523 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);
524
525 protected:
526
527 /**
528 * Creates a new frame medium by a given url.
529 * @param url Url of the frame medium
530 */
531 explicit FrameMedium(const std::string& url);
532
533 /**
534 * Delivers a new frame to this FrameMedium.
535 * The new frame will either be stored in the medium's frame collection or forwarded to subscribed frame callback functions.
536 * @param frame The new frame to deliver, must be valid
537 * @param anyCamera The camera profile associated with the frame, invalid if unknown
538 * @return True, if succeeded
539 */
540 virtual bool deliverNewFrame(Frame&& frame, SharedAnyCamera&& anyCamera = SharedAnyCamera());
541
542 protected:
543
544 /// Frame collection storing several frames with different timestamps.
546
547 /// The handler for frame callback functions.
549
550 /// Frame frequency.
551 FrameFrequency recentFrameFrequency_ = FrameFrequency(0);
552
553 /// Preferred frame type of the medium.
555};
556
558 FrameType(frameType),
559 frequency_(frequency)
560{
561 // nothing to do here
562}
563
564inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const unsigned int width, const unsigned int height) :
565 FrameType(mediaFrameType, width, height),
566 frequency_(mediaFrameType.frequency_),
567 croppingLeft_(mediaFrameType.croppingLeft_),
568 croppingTop_(mediaFrameType.croppingTop_),
569 croppingWidth_(mediaFrameType.croppingWidth_),
570 croppingHeight_(mediaFrameType.croppingHeight_)
571{
572 ocean_assert(croppingLeft_ + croppingWidth_ <= width);
573 ocean_assert(croppingTop_ + croppingHeight_ <= height);
574}
575
576inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat) :
577 FrameType(mediaFrameType, pixelFormat),
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
587inline FrameMedium::MediaFrameType::MediaFrameType(const MediaFrameType& mediaFrameType, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
588 FrameType(mediaFrameType, pixelFormat, pixelOrigin),
589 frequency_(mediaFrameType.frequency_),
590 croppingLeft_(mediaFrameType.croppingLeft_),
591 croppingTop_(mediaFrameType.croppingTop_),
592 croppingWidth_(mediaFrameType.croppingWidth_),
593 croppingHeight_(mediaFrameType.croppingHeight_)
594{
595 // nothing to do here
596}
597
598inline FrameMedium::MediaFrameType::MediaFrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin, const FrameFrequency frequency) :
599 FrameType(width, height, pixelFormat, pixelOrigin),
600 frequency_(frequency)
601{
602 // nothing to do here
603}
604
606{
607 return frequency_;
608}
609
611{
612 return croppingLeft_;
613}
614
616{
617 return croppingTop_;
618}
619
621{
622 return croppingWidth_;
623}
624
626{
627 return croppingHeight_;
628}
629
631{
632 frequency_ = frequency;
633}
634
635inline void FrameMedium::MediaFrameType::setCroppingArea(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height)
636{
637 croppingLeft_ = left;
638 croppingTop_ = top;
639 croppingWidth_ = width;
640 croppingHeight_ = height;
641}
642
643inline bool FrameMedium::hasFrame() const
644{
645 return bool(frameCollection_.recent());
646}
647
652
653inline unsigned int FrameMedium::preferredFrameWidth() const
654{
655 return preferredFrameType_.width();
656}
657
658inline unsigned int FrameMedium::preferredFrameHeight() const
659{
661}
662
667
672
673}
674
675}
676
677#endif
This class implements Ocean's image class.
Definition Frame.h:1808
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:3170
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
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
SharedAnyCamera camera_
The camera profile associated with the most recent frame.
Definition FrameMedium.h:286
FrameReceiver()=default
Default constructor.
bool latestFrame(Frame &frame, SharedAnyCamera *camera=nullptr, const unsigned int timeout=100u)
Returns the latest frame and camera profile.
bool latestFrameAndReset(Frame &frame, SharedAnyCamera *camera=nullptr, const unsigned int timeout=100u)
Returns the latest frame and camera profile and resets the receiver.
~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:289
Frame frame_
The most recent frame.
Definition FrameMedium.h:283
void onFrame(const Frame &frame, const SharedAnyCamera &camera)
Event function for a new movie frame.
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:610
unsigned int croppingWidth() const
Returns the width of the cropping area in pixel,.
Definition FrameMedium.h:620
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:605
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:625
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:630
unsigned int croppingTop() const
Returns the top start position of the cropping area.
Definition FrameMedium.h:615
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:635
Class allowing the sorting of several frame media types according their popularity.
Definition FrameMedium.h:310
MediaFrameType preferableFrameType_
Preferable frame type.
Definition FrameMedium.h:342
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:339
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:548
double FrameFrequency
Definition of a frame frequency defined in Hz.
Definition FrameMedium.h:59
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:648
virtual bool setPreferredFramePixelFormat(const FrameType::PixelFormat format)
Sets the preferred frame pixel format.
FrameFrequency recentFrameFrequency_
Frame frequency.
Definition FrameMedium.h:551
~FrameMedium() override
Destructs a frame object.
virtual FrameRef frameTimeout(const double timeout, SharedAnyCamera *anyCamera=nullptr) const
Waits until the first frame is available.
FrameFrequency preferredFrameFrequency() const
Returns the preferred frame frequency in Hz.
Definition FrameMedium.h:668
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:663
unsigned int preferredFrameHeight() const
Returns the preferred height of the frame in pixel.
Definition FrameMedium.h:658
virtual bool setCamera(SharedAnyCamera &&camera)
Sets the known camera profile of this frame medium.
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:545
size_t capacity() const
Returns the capacity of the frame history of this frame medium object.
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:653
bool hasFrame() const
Returns whether the object holds a frame.
Definition FrameMedium.h:643
std::vector< MediaFrameType > FrameTypes
Definition of a vector holding frame types.
Definition FrameMedium.h:304
std::function< void(const Frame &frame, const SharedAnyCamera &camera)> FrameCallbackFunction
Definition of a callback function for frame events.
Definition FrameMedium.h:181
MediaFrameType preferredFrameType_
Preferred frame type of the medium.
Definition FrameMedium.h:554
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:1783
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
SmartMediumRef< FrameMedium > FrameMediumRef
Definition of a smart medium reference holding a frame medium object.
Definition FrameMedium.h:39
std::vector< FrameMediumRef > FrameMediumRefs
Definition of a vector holding frame medium reference objects.
Definition FrameMedium.h:46
The namespace covering the entire Ocean framework.
Definition Accessor.h:15