Ocean
Loading...
Searching...
No Matches
MFFrameMedium.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_FRAME_MEDIUM_H
9#define META_OCEAN_MEDIA_MF_FRAME_MEDIUM_H
10
14
17
18namespace Ocean
19{
20
21namespace Media
22{
23
24namespace MediaFoundation
25{
26
27/**
28 * This is the base class for all Media Foundation frame mediums.
29 * @ingroup mediamf
30 */
31class OCEAN_MEDIA_MF_EXPORT MFFrameMedium :
32 virtual public MFMedium,
33 virtual public FrameMedium
34{
35 public:
36
37 /**
38 * Sets the preferred frame dimension.
39 * @see FrameMedium::setPreferredFrameDimension().
40 */
41 bool setPreferredFrameDimension(const unsigned int width, const unsigned int height) override;
42
43 /**
44 * Sets the preferred frame pixel format.
45 * @see FrameMedium::setPreferredFramePixelFormat().
46 */
48
49 /**
50 * Sets the preferred frame frequency in Hz.
51 * @see FrameMedium::setPreferredFrameFrequency().
52 */
53 bool setPreferredFrameFrequency(const FrameFrequency frequency) override;
54
55 /**
56 * Sets the known camera profile of this frame medium.
57 * @see FrameMedium::setCamera()
58 */
59 bool setCamera(SharedAnyCamera&& camera) override;
60
61 /**
62 * Extracts the video stream type of a given Media Foundation media type.
63 * @param mediaType Media Foundation media type, must be valid
64 * @param streamType Resulting stream type
65 * @param codecType Optional resulting codec type, only if the resulting stream type is ST_CODEC; nullptr if not of interest
66 * @return True, if succeeded
67 */
68 static bool extractStreamType(IMFMediaType* mediaType, LiveVideo::StreamType& streamType, LiveVideo::CodecType* codecType = nullptr);
69
70 /**
71 * Extracts the media frame type of a given Media Foundation media type.
72 * @param mediaType Media Foundation media type, must be valid
73 * @param frameType Resulting media frame type
74 * @return True, if succeeded
75 */
76 static bool extractMediaFrameType(IMFMediaType* mediaType, MediaFrameType& frameType);
77
78 /**
79 * Creates the video format of a given Media Foundation media type.
80 * @param frameType Frame type used for modification, must be valid
81 * @return The resulting media type, invalid otherwise
82 */
84
85 /**
86 * Determines the video media type of a given topology.
87 * @param topology The topology for that the media type is determined, must be valid
88 * @param mediaFrameType Resulting media frame type
89 * @return True, if succeeded
90 */
91 static bool determineMediaType(IMFTopology* topology, FrameMedium::MediaFrameType& mediaFrameType);
92
93 /**
94 * Determines the video media type of a given topology node.
95 * @param node The topology node for that the media type is determined, must be valid
96 * @param mediaFrameType Resulting media frame type
97 * @return True, if succeeded
98 */
100
101 protected:
102
103 /**
104 * Creates a new frame medium by a given URL.
105 * @param url The URL of the frame medium
106 */
107 explicit MFFrameMedium(const std::string& url);
108
109 /**
110 * Destructs a MFFrameMedium object.
111 */
112 ~MFFrameMedium() override;
113
114 /**
115 * Returns the timestamp of the most recent media sample.
116 * @see MFMedium::recentMediaSampleTimestamp().
117 */
118 bool recentMediaSampleTimestamp(LONGLONG& timestamp, LONGLONG* nextTimestamp) const override;
119
120 /**
121 * Called by if a new sample arrived.
122 * @param guidMajorMediaType Major media type of the sample
123 * @param dwSampleFlags Reserved
124 * @param llSampleTime The presentation time for this sample, in 100-nanosecond units
125 * @param llSampleDuration The duration of the sample, in 100-nanosecond units
126 * @param pSampleBuffer A pointer to a buffer that contains the sample data
127 * @param dwSampleSize Size of the pSampleBuffer buffer, in bytes
128 */
129 virtual void onNewSample(const GUID& guidMajorMediaType, const unsigned int dwSampleFlags, const long long llSampleTime, const long long llSampleDuration, const void* pSampleBuffer, const unsigned int dwSampleSize);
130
131 /**
132 * Topology set event function.
133 * @see MFMedium::onTopologySet().
134 */
135 void onTopologySet(IMFTopology* topology) override;
136
137 /**
138 * Format type changed event function.
139 * @see MFMedium::onFormatTypeChanged().
140 */
141 void onFormatTypeChanged(const TOPOID nodeId) override;
142
143 /**
144 * Builds the frame topology of this object.
145 * @param respectPlaybackTime True, to deliver samples based on the presentation time; False, to ignore the presentation clock and to deliver samples as fast as possible
146 * @return True, if succeeded
147 */
148 virtual bool buildFrameTopology(const bool respectPlaybackTime);
149
150 /**
151 * Releases the frame topology of this object.
152 */
153 virtual void releaseFrameTopology();
154
155 /**
156 * Connects the selected video stream with a given sink activate object.
157 * @param sinkActivate The sink activate object, must be valid
158 * @param preferredMediaFrameType The preferred media frame type
159 * @return True, if succeeded
160 */
161 bool connectSelectedStream(IMFActivate* sinkActivate, const MediaFrameType& preferredMediaFrameType);
162
163 /**
164 * Returns the best matching media type for a given preferred media type.
165 * @param mediaTypeHandler The type handler for which the best matching type will be determined, must be valid
166 * @param preferredMediaFrameType The preferred media frame type
167 * @return The best matching media type, invalid if no type could be found
168 */
169 static ScopedIMFMediaType determineBestMatchingMediaType(IMFMediaTypeHandler* mediaTypeHandler, const MediaFrameType& preferredMediaFrameType);
170
171 protected:
172
173 /// Frame sample grabber.
175
176 /// The media type handler which is associated with the stream.
178
179 /// The input node of the source.
181
182 /// The output node of the sink.
184
185 /// Frame type of the most recent (upcoming frame) frame.
187
188 /// Internal frame type of the most recent (upcoming frame) frame.
190
191 /// Optional cropping position left.
192 unsigned int croppingLeft_ = 0u;
193
194 /// Optional cropping position top.
195 unsigned int croppingTop_ = 0u;
196
197 /// Optional cropping width, 0 if no cropping is defined.
198 unsigned int croppingWidth_ = 0u;
199
200 /// Optional cropping height, 0 if no cropping is defined.
201 unsigned int croppingHeight_ = 0u;
202
203 /// True, if the medium waits for the first frame after the topology has been changed.
204 bool waitingForFirstFrame_ = true;
205
206 /// The camera profile for all images.
208};
209
210}
211
212}
213
214}
215
216#endif // META_OCEAN_MEDIA_MF_FRAME_MEDIUM_H
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
Definition of a media frame type composed by the frame dimension, pixel format, pixel origin and a fr...
Definition FrameMedium.h:65
This is the base class for all frame mediums.
Definition FrameMedium.h:53
double FrameFrequency
Definition of a frame frequency defined in Hz.
Definition FrameMedium.h:59
CodecType
Definition of individual codec types.
Definition LiveVideo.h:79
StreamType
Definition of individual stream types.
Definition LiveVideo.h:59
This is the base class for all Media Foundation frame mediums.
Definition MFFrameMedium.h:34
ScopedSampleGrabber frameSampleGrabber_
Frame sample grabber.
Definition MFFrameMedium.h:174
virtual bool buildFrameTopology(const bool respectPlaybackTime)
Builds the frame topology of this object.
bool setPreferredFrameFrequency(const FrameFrequency frequency) override
Sets the preferred frame frequency in Hz.
virtual void onNewSample(const GUID &guidMajorMediaType, const unsigned int dwSampleFlags, const long long llSampleTime, const long long llSampleDuration, const void *pSampleBuffer, const unsigned int dwSampleSize)
Called by if a new sample arrived.
bool connectSelectedStream(IMFActivate *sinkActivate, const MediaFrameType &preferredMediaFrameType)
Connects the selected video stream with a given sink activate object.
MFFrameMedium(const std::string &url)
Creates a new frame medium by a given URL.
static ScopedIMFMediaType determineBestMatchingMediaType(IMFMediaTypeHandler *mediaTypeHandler, const MediaFrameType &preferredMediaFrameType)
Returns the best matching media type for a given preferred media type.
bool setPreferredFrameDimension(const unsigned int width, const unsigned int height) override
Sets the preferred frame dimension.
bool setPreferredFramePixelFormat(const FrameType::PixelFormat format) override
Sets the preferred frame pixel format.
FrameType internalRecentFrameType_
Internal frame type of the most recent (upcoming frame) frame.
Definition MFFrameMedium.h:189
ScopedIMFTopologyNode inputNode_
The input node of the source.
Definition MFFrameMedium.h:180
bool recentMediaSampleTimestamp(LONGLONG &timestamp, LONGLONG *nextTimestamp) const override
Returns the timestamp of the most recent media sample.
~MFFrameMedium() override
Destructs a MFFrameMedium object.
ScopedIMFTopologyNode outputNode_
The output node of the sink.
Definition MFFrameMedium.h:183
SharedAnyCamera camera_
The camera profile for all images.
Definition MFFrameMedium.h:207
bool setCamera(SharedAnyCamera &&camera) override
Sets the known camera profile of this frame medium.
ScopedMediaFoundationObject< IMFMediaTypeHandler > mediaTypeHandler_
The media type handler which is associated with the stream.
Definition MFFrameMedium.h:177
void onFormatTypeChanged(const TOPOID nodeId) override
Format type changed event function.
virtual void releaseFrameTopology()
Releases the frame topology of this object.
static bool extractMediaFrameType(IMFMediaType *mediaType, MediaFrameType &frameType)
Extracts the media frame type of a given Media Foundation media type.
static bool determineMediaType(IMFTopologyNode *node, FrameMedium::MediaFrameType &mediaFrameType)
Determines the video media type of a given topology node.
static bool determineMediaType(IMFTopology *topology, FrameMedium::MediaFrameType &mediaFrameType)
Determines the video media type of a given topology.
static bool extractStreamType(IMFMediaType *mediaType, LiveVideo::StreamType &streamType, LiveVideo::CodecType *codecType=nullptr)
Extracts the video stream type of a given Media Foundation media type.
static ScopedIMFMediaType createMediaType(const MediaFrameType &frameType)
Creates the video format of a given Media Foundation media type.
void onTopologySet(IMFTopology *topology) override
Topology set event function.
FrameType recentFrameType_
Frame type of the most recent (upcoming frame) frame.
Definition MFFrameMedium.h:186
This is the base class for all MediaFoundation mediums.
Definition MFMedium.h:31
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition ScopedObject.h:166
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
The namespace covering the entire Ocean framework.
Definition Accessor.h:15