Ocean
Loading...
Searching...
No Matches
MFLiveVideo.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_MF_LIVE_VIDEO_H
9#define META_OCEAN_MEDIA_MF_LIVE_VIDEO_H
10
13
14#include "ocean/media/Library.h"
16
17namespace Ocean
18{
19
20namespace Media
21{
22
23namespace MediaFoundation
24{
25
26/**
27 * This class implements a MediaFoundation live video object allowing to access e.g., webcams.
28 * @ingroup mediamf
29 */
30class OCEAN_MEDIA_MF_EXPORT MFLiveVideo :
31 public virtual MFFrameMedium,
32 public virtual LiveVideo
33{
34 friend class MFLibrary;
35
36 protected:
37
38 /**
39 * Definition of an unordered map mapping stream properties to their frame rates.
40 */
41 using StreamPropertyMap = std::unordered_map<StreamProperty, std::vector<double>, StreamProperty::Hash>;
42
43 public:
44
45 /**
46 * Returns the supported stream types.
47 * @see LiveVideo::supportedStreamTypes().
48 */
50
51 /**
52 * Returns the supported stream configurations for a given stream type.
53 * @see supportedStreamConfigurations().
54 */
56
57 /**
58 * Returns the current exposure duration of this device.
59 * @see LiveVideo::exposureDuration().
60 */
61 double exposureDuration(double* minDuration = nullptr, double* maxDuration = nullptr, ControlMode* exposureMode = nullptr) const override;
62
63 /**
64 * Sets the exposure duration of this device.
65 * @see LiveVideo::setExposureDuration().
66 */
67 bool setExposureDuration(const double duration, const bool allowShorterExposure = false) override;
68
69 /**
70 * Enumerates all currently available video devices.
71 * @param definitions The resulting video devices
72 * @return True, if succeeded
73 */
75
76 protected:
77
78 /**
79 * Creates a new live video by a given URL.
80 * @param url The URL of the live video
81 * @param symbolicLink Optional the symbolic link of the live video, if known
82 */
83 explicit MFLiveVideo(const std::string& url, const std::string& symbolicLink);
84
85 /**
86 * Destructs a MFLiveVideo object.
87 */
88 ~MFLiveVideo() override;
89
90 /**
91 * Creates and builds the topology of this object.
92 * @see MFMedium::createTopology().
93 */
94 bool createTopology(const bool respectPlaybackTime) override;
95
96 /**
97 * Creates the media source object.
98 * @see MFMedium::createTopology().
99 */
100 bool createMediaSource() override;
101
102 /**
103 * Releases the topology.
104 */
105 void releaseTopology() override;
106
107 /**
108 * Session started event function.
109 * @see MFMedium::onSessionStarted().
110 */
111 void onSessionStarted() override;
112
113 /**
114 * Session stopped event function.
115 * @see MFMedium::onSessionStopped().
116 */
117 void onSessionStopped() override;
118
119 /**
120 * Determines the exposure range of the camera.
121 * @param iKsControl The IKsControl interface of the camera, must be valid
122 * @param minExposure The resulting minimal exposure value, in seconds
123 * @param maxExposure The resulting maximal exposure value, in seconds
124 * @return True, if succeeded
125 */
126 static bool exposureRange(IKsControl* iKsControl, double& minExposure, double& maxExposure);
127
128 /**
129 * Sets the exposure of the camera.
130 * @param iKsControl The IKsControl interface of the camera, must be valid
131 * @param exposure The exposure to be set, in seconds, with range (0, infinity), 0 for auto exposure
132 * @return True, if succeeded
133 */
134 static bool setExposure(IKsControl* iKsControl, const double exposure);
135
136 /**
137 * Returns the exposure of the camera.
138 * @param iKsControl The IKsControl interface of the camera, must be valid
139 * @param exposure The resulting exposure value, in seconds
140 * @param controlMode The resulting control mode
141 * @return True, if succeeded
142 */
143 static bool exposure(IKsControl* iKsControl, double& exposure, ControlMode& controlMode);
144
145 /**
146 * Translates the exposure value from log base 2 to a linear exposure in seconds.
147 * @param logBase2 The exposure value in log base 2, with range (-infinity, infinity)
148 * @return The resulting exposure value in seconds, with range [0, infinity)
149 */
150 static double translateExposure(const LONG logBase2);
151
152 /**
153 * Translates the exposure value from a linear exposure in seconds to log base 2.
154 * @param exposure The exposure value in seconds, with range [0, infinity)
155 * @return The resulting exposure value in log base 2, with range (-infinity, infinity)
156 */
157 static LONG translateExposure(const double exposure);
158
159 protected:
160
161 /// The symbolic link of the device.
162 std::string symbolicLink_;
163
164 /// True, if the session has been started.
165 bool sesssionStarted_ = false;
166
167 /// The exposure duration of the camera which will be set once the session has been started.
168 double delayedExposureDuration_ = NumericD::minValue();
169};
170
171}
172
173}
174
175}
176
177#endif // META_OCEAN_MEDIA_MF_LIVE_VIDEO_H
std::vector< Definition > Definitions
Definition of a vector holding medium definition objects.
Definition media/Library.h:111
This class is the base class for all live videos.
Definition LiveVideo.h:38
StreamType
Definition of individual stream types.
Definition LiveVideo.h:59
ControlMode
Definition of individual control modes.
Definition LiveVideo.h:46
std::vector< StreamConfiguration > StreamConfigurations
Definition of a vector holding stream configurations.
Definition LiveVideo.h:202
std::vector< StreamType > StreamTypes
Definition of a vector holding stream types.
Definition LiveVideo.h:73
This is the base class for all Media Foundation frame mediums.
Definition MFFrameMedium.h:34
This class implements the MediaFoundation library.
Definition MFLibrary.h:30
This class implements a MediaFoundation live video object allowing to access e.g.,...
Definition MFLiveVideo.h:33
std::unordered_map< StreamProperty, std::vector< double >, StreamProperty::Hash > StreamPropertyMap
Definition of an unordered map mapping stream properties to their frame rates.
Definition MFLiveVideo.h:41
bool createMediaSource() override
Creates the media source object.
bool createTopology(const bool respectPlaybackTime) override
Creates and builds the topology of this object.
void onSessionStopped() override
Session stopped event function.
static bool setExposure(IKsControl *iKsControl, const double exposure)
Sets the exposure of the camera.
StreamConfigurations supportedStreamConfigurations(const StreamType streamType) const override
Returns the supported stream configurations for a given stream type.
static bool exposureRange(IKsControl *iKsControl, double &minExposure, double &maxExposure)
Determines the exposure range of the camera.
static bool enumerateVideoDevices(Library::Definitions &definitions)
Enumerates all currently available video devices.
static LONG translateExposure(const double exposure)
Translates the exposure value from a linear exposure in seconds to log base 2.
StreamTypes supportedStreamTypes() const override
Returns the supported stream types.
void releaseTopology() override
Releases the topology.
static double translateExposure(const LONG logBase2)
Translates the exposure value from log base 2 to a linear exposure in seconds.
bool setExposureDuration(const double duration, const bool allowShorterExposure=false) override
Sets the exposure duration of this device.
std::string symbolicLink_
The symbolic link of the device.
Definition MFLiveVideo.h:162
void onSessionStarted() override
Session started event function.
static bool exposure(IKsControl *iKsControl, double &exposure, ControlMode &controlMode)
Returns the exposure of the camera.
double exposureDuration(double *minDuration=nullptr, double *maxDuration=nullptr, ControlMode *exposureMode=nullptr) const override
Returns the current exposure duration of this device.
MFLiveVideo(const std::string &url, const std::string &symbolicLink)
Creates a new live video by a given URL.
~MFLiveVideo() override
Destructs a MFLiveVideo object.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15