Ocean
Loading...
Searching...
No Matches
LiveVideo.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_LIVE_VIDEO_H
9#define META_OCEAN_MEDIA_LIVE_VIDEO_H
10
11#include "ocean/media/Media.h"
14
15namespace Ocean
16{
17
18namespace Media
19{
20
21// Forward declaration.
22class LiveVideo;
23
24/**
25 * Definition of a smart medium reference holding a live video object.
26 * @see SmartMediumRef, LiveVideo.
27 * @ingroup media
28 */
30
31/**
32 * This class is the base class for all live videos.
33 * @ingroup media
34 */
35class OCEAN_MEDIA_EXPORT LiveVideo :
36 public virtual FrameMedium,
37 public virtual LiveMedium
38{
39 public:
40
41 /**
42 * Definition of individual control modes.
43 * The modes are used for exposure, ISO, and focus.
44 */
45 enum ControlMode : uint32_t
46 {
47 /// An invalid control mode.
48 CM_INVALID = 0u,
49 /// The control is fixed (e.g., because the exposure, ISO, or focus was set manually).
51 /// The control is dynamic (e.g., because auto exposure, ISO, or focus is enabled).
52 CM_DYNAMIC
53 };
54
55 /**
56 * Definition of individual stream types.
57 */
58 enum StreamType : uint32_t
59 {
60 /// An invalid stream type.
61 ST_INVALID = 0u,
62 /// A stream composed of individual uncompressed frames with individual pixel formats (e.g., FORMAT_RGB24, FORMAT_YUYV16, etc.).
64 /// A stream composed of Motion JPEG frames.
66 /// A stream composed of compressed frames with individual codecs (e.g., H264, H265).
67 ST_CODEC
68 };
69
70 /**
71 * Definition of a vector holding stream types.
72 */
73 using StreamTypes = std::vector<StreamType>;
74
75 /**
76 * Definition of individual codec types.
77 */
78 enum CodecType : uint32_t
79 {
80 /// An invalid codec type.
81 CT_INVALID = 0u,
82 /// Codec using H.264 for encoding or decoding.
84 /// Codec using H.265 for encoding or decoding.
85 CT_H265
86 };
87
88 /**
89 * This class holds the relevant information describing a video stream configuration.
90 */
91 class OCEAN_MEDIA_EXPORT StreamConfiguration
92 {
93 public:
94
95 /**
96 * Default constructor creating an invalid object.
97 */
99
100 /**
101 * Creates a new stream configuration object.
102 * @param streamType The type of the stream
103 * @param width The width of the stream in pixel
104 * @param height The height of the stream in pixel
105 * @param frameRates The frame rates of the stream in Hz
106 * @param framePixelFormat The pixel format of the stream, invalid if stream type is not ST_FRAME
107 * @param codecType The type of the stream, invalid if stream type is not ST_CODEC
108 */
109 StreamConfiguration(const StreamType streamType, const unsigned int width, unsigned int height, std::vector<double>&& frameRates, const FrameType::PixelFormat framePixelFormat, const CodecType codecType);
110
111 /**
112 * Returns a string containing the readable information of this stream configuration.
113 * @return The readable information of this stream configuration
114 */
115 std::string toString() const;
116
117 /**
118 * Returns whether this configuration object holds a valid configuration.
119 * The configuration is valid if a valid stream type and a valid image resolution is defined.
120 * @return True, if so
121 */
122 inline bool isValid() const;
123
124 public:
125
126 /// The type of the stream.
127 StreamType streamType_ = ST_INVALID;
128
129 /// The width of the stream in pixel.
130 unsigned int width_ = 0u;
131
132 /// The height of the stream in pixel.
133 unsigned int height_ = 0u;
134
135 /// The frame rates of the stream in Hz.
136 std::vector<double> frameRates_;
137
138 /// The pixel format of the stream, only valid if the stream type is ST_FRAME.
139 FrameType::PixelFormat framePixelFormat_ = FrameType::FORMAT_UNDEFINED;
140
141 /// The codec of the stream, only valid if the stream type is ST_CODEC.
142 CodecType codecType_ = CT_INVALID;
143 };
144
145 /**
146 * Definition of a vector holding stream configurations.
147 */
148 using StreamConfigurations = std::vector<StreamConfiguration>;
149
150 public:
151
152 /**
153 * Returns the supported stream types.
154 * @return The types of all supported streams, empty if this object does not allow (or does not need) to select the stream type.
155 */
157
158 /**
159 * Returns the supported stream configurations for a given stream type.
160 * @param streamType The type of the stream for which the supported stream configurations will be returned, ST_INVALID to return all stream configurations for all stream types
161 * @return The supported stream configurations
162 */
163 virtual StreamConfigurations supportedStreamConfigurations(const StreamType streamType = ST_INVALID) const;
164
165 /**
166 * Returns the current exposure duration of this device.
167 * @param minDuration Optional resulting minimal duration to set, in seconds, with range (0, infinity), -1 if unknown
168 * @param maxDuration Optional resulting maximal duration to set, in seconds, with range [minDuration, infinity), -1 if unknown
169 * @param exposureMode Optional resulting exposure mode, nullptr if not of interest
170 * @return The duration in seconds, with range [minDuration, maxDuration], -1 if unknown
171 * @see setExposureDuration().
172 */
173 virtual double exposureDuration(double* minDuration = nullptr, double* maxDuration = nullptr, ControlMode* exposureMode = nullptr) const;
174
175 /**
176 * Returns the current ISO of this device.
177 * @param minISO Optional resulting minimal ISO to set, with range (0, infinity), -1 if unknown
178 * @param maxISO Optional resulting maximal ISO to set, with range (0, infinity), -1 if unknown
179 * @param isoMode Optional resulting ISO mode, nullptr if not of interest
180 * @return The current ISO, with range [minISO, maxISO], -1 if unknown
181 */
182 virtual float iso(float* minISO = nullptr, float* maxISO = nullptr, ControlMode* isoMode = nullptr) const;
183
184 /**
185 * Returns the current focus of this device.
186 * @return The device's focus, with range [0, 1] with 0 shortest distance and 1 furthest distance
187 * @param focusMode Optional resulting focus mode, nullptr if not of interest
188 */
189 virtual float focus(ControlMode* focusMode = nullptr) const;
190
191 /**
192 * Sets the preferred stream type.
193 * There is no guarantee that the device will use this stream type.
194 * @param streamType The preferred stream type to be set, must be valid
195 * @return True, if succeeded
196 * @see setPreferredStreamConfiguration().
197 */
198 virtual bool setPreferredStreamType(const StreamType streamType);
199
200 /**
201 * Sets the preferred stream configuration.
202 * Using this function will forward some settings to the underlying FrameMedium object via setPreferredFrameDimension(), setPreferredFramePixelFormat(), and setPreferredFrameFrequency().
203 * There is no guarantee that the device will use this stream type.
204 * @param streamConfiguration The preferred stream configuration to be set, must be valid
205 * @return True, if succeeded
206 * @see setPreferredStreamType(), FrameMedium::setPreferredFrameDimension(), FrameMedium::setPreferredFramePixelFormat(), and FrameMedium::setPreferredFrameFrequency()
207 */
208 virtual bool setPreferredStreamConfiguration(const StreamConfiguration& streamConfiguration);
209
210 /**
211 * Sets the exposure duration of this device.
212 * @param duration The exposure duration to be set, in seconds, with range (0, infinity), 0 for auto exposure, -1 for a one-time auto exposure
213 * @param allowShorterExposure True, to allow shorter exposure durations than the specified duration; False, to enforce the specified duration; Ignored if auto exposure is used
214 * @return True, if succeeded
215 * @see exposureDuration().
216 */
217 virtual bool setExposureDuration(const double duration, const bool allowShorterExposure = false);
218
219 /**
220 * Sets the ISO of this device.
221 * @param iso The ISO to be set, with range (0, infinity), -1 for auto ISO
222 * @return True, if succeeded
223 * @see iso().
224 */
225 virtual bool setISO(const float iso);
226
227 /**
228 * Sets the focus of this device.
229 * @param position The focus position to be set, with range [0, 1] with 0 shortest distance and 1 furthest distance, -1 for auto focus
230 * @return True, if succeeded
231 * @see focus().
232 */
233 virtual bool setFocus(const float position);
234
235 /**
236 * Translates a control mode to a string.
237 * @param controlMode The control mode to translate
238 * @return The translated string, 'Invalid' if the control mode is invalid or unknown
239 */
240 static std::string translateControlMode(const ControlMode controlMode);
241
242 /**
243 * Translates a stream type to a string.
244 * @param streamType The stream type to be translated
245 * @return The translated string, 'Invalid' if the stream type is invalid or unknown
246 */
247 static std::string translateStreamType(const StreamType streamType);
248
249 /**
250 * Translates a codec type to a string.
251 * @param codecType The stream type to be translated
252 * @return The translated string, 'Invalid' if the codec type is invalid or unknown
253 */
254 static std::string translateCodecType(const CodecType codecType);
255
256 protected:
257
258 /**
259 * Creates a new live video source by a given url.
260 * @param url Url of the live video source
261 */
262 explicit LiveVideo(const std::string& url);
263};
264
266{
267 return streamType_ != ST_INVALID && width_ > 0u && height_ > 0u;
268}
269
270}
271
272}
273
274#endif // META_OCEAN_MEDIA_LIVE_VIDEO_H
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
This is the base class for all frame mediums.
Definition FrameMedium.h:53
This class it the base class for all live mediums.
Definition LiveMedium.h:38
This class holds the relevant information describing a video stream configuration.
Definition LiveVideo.h:92
std::vector< double > frameRates_
The frame rates of the stream in Hz.
Definition LiveVideo.h:136
std::string toString() const
Returns a string containing the readable information of this stream configuration.
unsigned int height_
The height of the stream in pixel.
Definition LiveVideo.h:133
StreamType streamType_
The type of the stream.
Definition LiveVideo.h:127
bool isValid() const
Returns whether this configuration object holds a valid configuration.
Definition LiveVideo.h:265
unsigned int width_
The width of the stream in pixel.
Definition LiveVideo.h:130
StreamConfiguration()=default
Default constructor creating an invalid object.
StreamConfiguration(const StreamType streamType, const unsigned int width, unsigned int height, std::vector< double > &&frameRates, const FrameType::PixelFormat framePixelFormat, const CodecType codecType)
Creates a new stream configuration object.
This class is the base class for all live videos.
Definition LiveVideo.h:38
virtual double exposureDuration(double *minDuration=nullptr, double *maxDuration=nullptr, ControlMode *exposureMode=nullptr) const
Returns the current exposure duration of this device.
CodecType
Definition of individual codec types.
Definition LiveVideo.h:79
@ CT_H264
Codec using H.264 for encoding or decoding.
Definition LiveVideo.h:83
LiveVideo(const std::string &url)
Creates a new live video source by a given url.
virtual bool setPreferredStreamType(const StreamType streamType)
Sets the preferred stream type.
virtual bool setExposureDuration(const double duration, const bool allowShorterExposure=false)
Sets the exposure duration of this device.
virtual StreamConfigurations supportedStreamConfigurations(const StreamType streamType=ST_INVALID) const
Returns the supported stream configurations for a given stream type.
StreamType
Definition of individual stream types.
Definition LiveVideo.h:59
@ ST_INVALID
An invalid stream type.
Definition LiveVideo.h:61
@ ST_MJPEG
A stream composed of Motion JPEG frames.
Definition LiveVideo.h:65
@ ST_FRAME
A stream composed of individual uncompressed frames with individual pixel formats (e....
Definition LiveVideo.h:63
ControlMode
Definition of individual control modes.
Definition LiveVideo.h:46
@ CM_FIXED
The control is fixed (e.g., because the exposure, ISO, or focus was set manually).
Definition LiveVideo.h:50
virtual bool setFocus(const float position)
Sets the focus of this device.
virtual bool setISO(const float iso)
Sets the ISO of this device.
std::vector< StreamConfiguration > StreamConfigurations
Definition of a vector holding stream configurations.
Definition LiveVideo.h:148
virtual StreamTypes supportedStreamTypes() const
Returns the supported stream types.
static std::string translateControlMode(const ControlMode controlMode)
Translates a control mode to a string.
virtual bool setPreferredStreamConfiguration(const StreamConfiguration &streamConfiguration)
Sets the preferred stream configuration.
virtual float iso(float *minISO=nullptr, float *maxISO=nullptr, ControlMode *isoMode=nullptr) const
Returns the current ISO of this device.
std::vector< StreamType > StreamTypes
Definition of a vector holding stream types.
Definition LiveVideo.h:73
static std::string translateStreamType(const StreamType streamType)
Translates a stream type to a string.
static std::string translateCodecType(const CodecType codecType)
Translates a codec type to a string.
virtual float focus(ControlMode *focusMode=nullptr) const
Returns the current focus of this device.
This class implements a smart medium reference.
Definition MediumRef.h:33
SmartMediumRef< LiveVideo > LiveVideoRef
Definition of a smart medium reference holding a live video object.
Definition LiveVideo.h:29
The namespace covering the entire Ocean framework.
Definition Accessor.h:15