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 * Extracts the video stream type of a given Media Foundation media type.
57 * @param mediaType Media Foundation media type, must be valid
58 * @param streamType Resulting stream type
59 * @param codecType Optional resulting codec type, only if the resulting stream type is ST_CODEC; nullptr if not of interest
60 * @return True, if succeeded
61 */
62 static bool extractStreamType(IMFMediaType* mediaType, LiveVideo::StreamType& streamType, LiveVideo::CodecType* codecType = nullptr);
63
64 /**
65 * Extracts the media frame type of a given Media Foundation media type.
66 * @param mediaType Media Foundation media type, must be valid
67 * @param frameType Resulting media frame type
68 * @return True, if succeeded
69 */
70 static bool extractMediaFrameType(IMFMediaType* mediaType, MediaFrameType& frameType);
71
72 /**
73 * Creates the video format of a given Media Foundation media type.
74 * @param frameType Frame type used for modification, must be valid
75 * @return The resulting media type, invalid otherwise
76 */
78
79 /**
80 * Determines the video media type of a given topology.
81 * @param topology The topology for that the media type is determined, must be valid
82 * @param mediaFrameType Resulting media frame type
83 * @return True, if succeeded
84 */
85 static bool determineMediaType(IMFTopology* topology, FrameMedium::MediaFrameType& mediaFrameType);
86
87 /**
88 * Determines the video media type of a given topology node.
89 * @param node The topology node for that the media type is determined, must be valid
90 * @param mediaFrameType Resulting media frame type
91 * @return True, if succeeded
92 */
94
95 protected:
96
97 /**
98 * Creates a new frame medium by a given URL.
99 * @param url The URL of the frame medium
100 */
101 explicit MFFrameMedium(const std::string& url);
102
103 /**
104 * Destructs a MFFrameMedium object.
105 */
106 ~MFFrameMedium() override;
107
108 /**
109 * Returns the timestamp of the most recent media sample.
110 * @see MFMedium::recentMediaSampleTimestamp().
111 */
112 bool recentMediaSampleTimestamp(LONGLONG& timestamp, LONGLONG* nextTimestamp) const override;
113
114 /**
115 * Called by if a new sample arrived.
116 * @param guidMajorMediaType Major media type of the sample
117 * @param dwSampleFlags Reserved
118 * @param llSampleTime The presentation time for this sample, in 100-nanosecond units
119 * @param llSampleDuration The duration of the sample, in 100-nanosecond units
120 * @param pSampleBuffer A pointer to a buffer that contains the sample data
121 * @param dwSampleSize Size of the pSampleBuffer buffer, in bytes
122 */
123 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);
124
125 /**
126 * Topology set event function.
127 * @see MFMedium::onTopologySet().
128 */
129 void onTopologySet(IMFTopology* topology) override;
130
131 /**
132 * Format type changed event function.
133 * @see MFMedium::onFormatTypeChanged().
134 */
135 void onFormatTypeChanged(const TOPOID nodeId) override;
136
137 /**
138 * Builds the frame topology of this object.
139 * @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
140 * @return True, if succeeded
141 */
142 virtual bool buildFrameTopology(const bool respectPlaybackTime);
143
144 /**
145 * Releases the frame topology of this object.
146 */
147 virtual void releaseFrameTopology();
148
149 /**
150 * Connects the selected video stream with a given sink activate object.
151 * @param sinkActivate The sink activate object, must be valid
152 * @param preferredMediaFrameType The preferred media frame type
153 * @return True, if succeeded
154 */
155 bool connectSelectedStream(IMFActivate* sinkActivate, const MediaFrameType& preferredMediaFrameType);
156
157 /**
158 * Returns the best matching media type for a given preferred media type.
159 * @param mediaTypeHandler The type handler for which the best matching type will be determined, must be valid
160 * @param preferredMediaFrameType The preferred media frame type
161 * @return The best matching media type, invalid if no type could be found
162 */
163 static ScopedIMFMediaType determineBestMatchingMediaType(IMFMediaTypeHandler* mediaTypeHandler, const MediaFrameType& preferredMediaFrameType);
164
165 protected:
166
167 /// Frame sample grabber.
169
170 /// The media type handler which is associated with the stream.
172
173 /// The input node of the source.
175
176 /// The output node of the sink.
178
179 /// Frame type of the most recent (upcoming frame) frame.
181
182 /// Internal frame type of the most recent (upcoming frame) frame.
184
185 /// Optional cropping position left.
186 unsigned int croppingLeft_ = 0u;
187
188 /// Optional cropping position top.
189 unsigned int croppingTop_ = 0u;
190
191 /// Optional cropping width, 0 if no cropping is defined.
192 unsigned int croppingWidth_ = 0u;
193
194 /// Optional cropping height, 0 if no cropping is defined.
195 unsigned int croppingHeight_ = 0u;
196
197 /// True, if the medium waits for the first frame after the topology has been changed.
198 bool waitingForFirstFrame_ = true;
199};
200
201}
202
203}
204
205}
206
207#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:168
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:183
ScopedIMFTopologyNode inputNode_
The input node of the source.
Definition MFFrameMedium.h:174
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:177
ScopedMediaFoundationObject< IMFMediaTypeHandler > mediaTypeHandler_
The media type handler which is associated with the stream.
Definition MFFrameMedium.h:171
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:180
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
The namespace covering the entire Ocean framework.
Definition Accessor.h:15