Ocean
Loading...
Searching...
No Matches
DSFrameMedium.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_DS_FRAME_MEDIUM_H
9#define META_OCEAN_MEDIA_DS_FRAME_MEDIUM_H
10
14
16
18
19namespace Ocean
20{
21
22namespace Media
23{
24
25namespace DirectShow
26{
27
28/**
29 * This is the base class for all DirectShow frame mediums.
30 * @ingroup mediads
31 */
32class OCEAN_MEDIA_DS_EXPORT DSFrameMedium :
33 virtual public DSMedium,
34 virtual public FrameMedium
35{
36 protected:
37
38 /**
39 * Class allowing the sorting of several video media types according their popularity.
40 */
42 {
43 public:
44
45 /**
46 * Creates a new sortable media type.
47 * The given media type has to be freed after the entire sorting process by the caller.
48 * @param dsMediaType The DirectShow media type
49 * @param frameType Preferable frame type
50 */
51 DSSortableFrameType(DSMediaType&& dsMediaType, const MediaFrameType& frameType);
52
53 /**
54 * Returns the DirectShow media type.
55 * @return Media type
56 */
57 const AM_MEDIA_TYPE& type() const;
58
59 protected:
60
61 /// DirectShow media type
63 };
64
65 /**
66 * Definition of a vector holding sortable media type objects.
67 */
68 typedef std::vector<DSSortableFrameType> DSSortableFrameTypes;
69
70 public:
71
72 /**
73 * Sets the preferred frame dimension.
74 * @see FrameMedium::setPreferredFrameDimension().
75 */
76 bool setPreferredFrameDimension(const unsigned int width, const unsigned int height) override;
77
78 /**
79 * Sets the preferred frame pixel format.
80 * @see FrameMedium::setPreferredFramePixelFormat().
81 */
83
84 /**
85 * Sets the preferred frame frequency in Hz.
86 * @see FrameMedium::setPreferredFrameFrequency().
87 */
88 bool setPreferredFrameFrequency(const FrameFrequency frequency) override;
89
90 /**
91 * Extracts the video format of a given DirectShow media type.
92 * @param mediaType DirectShow media type
93 * @param frameType Resulting frame type
94 * @return True, if succeeded
95 */
96 static bool extractFrameFormat(const AM_MEDIA_TYPE& mediaType, MediaFrameType& frameType);
97
98 /**
99 * Creates the video format of a given DirectShow media type.
100 * @param mediaType Media type to modify
101 * @param frameType Frame type used for modification
102 * @return True, if succeeded
103 */
104 static bool createMediaType(CMediaType& mediaType, const MediaFrameType& frameType);
105
106 /**
107 * Modifies the video format of a given DirectShow media type.
108 * @param mediaType Media type to modify
109 * @param frameType Frame type used for modification
110 * @return True, if succeeded
111 */
112 static bool modifyFrameFormat(AM_MEDIA_TYPE& mediaType, const MediaFrameType& frameType);
113
114 /**
115 * Collect all supported frame formats of a given pin.
116 * @param pin The pin to collect the formats for
117 * @param frameTypes Resulting valid and supported frame types
118 * @return True, if succeeded
119 */
120 static bool collectFrameFormats(IPin* pin, FrameTypes& frameTypes);
121
122 /**
123 * Converts a Directshow media subtype to a pixel format.
124 * @param mediaSubtype DirectShow media type to convert
125 * @return Resulting pixel format
126 */
127 static FrameType::PixelFormat convertMediaSubtype(const GUID& mediaSubtype);
128
129 /**
130 * Returns the pixel origin of a Directshow media subtype.
131 * @param mediaSubtype DirectShow media type to return the pixel origin for
132 * @return Pixel origin
133 */
134 static FrameType::PixelOrigin extractPixelOrigin(const GUID& mediaSubtype);
135
136 /**
137 * Converts a pixel format to a DirectShow media subtype.
138 * @param pixelFormat Pixel format
139 * @return DirectShow media type
140 */
141 static GUID convertPixelFormat(const FrameType::PixelFormat pixelFormat);
142
143 protected:
144
145 /**
146 * Creates a new frame medium by a given url.
147 * @param url Url of the frame medium
148 */
149 explicit DSFrameMedium(const std::string& url);
150
151 /**
152 * Destructs a DSFrameMedium object.
153 */
154 ~DSFrameMedium() override;
155
156 /**
157 * Creates the frame sink filter.
158 * @return True, if succeeded
159 */
161
162 /**
163 * Creates a new sample sink filter.
164 * @param outputPin Output pin to be connected with the sample sink filter
165 * @param pixelFormat Pixel format of the frame sink filter
166 * @return True, if succeeded
167 */
168 bool insertFrameSampleSinkFilter(IPin* outputPin, FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED);
169
170 /**
171 * Releases a the frame sample sink filter.
172 */
174
175 /**
176 * Called by the sample sink filter if a new sample arrived.
177 * @param sample New sample
178 * @param timestamp The sample timestamp
179 * @param relativeTimestamp Relative timestamp of the sample
180 */
181 virtual void onNewSample(IMediaSample* sample, const Timestamp timestamp, const Timestamp relativeTimestamp);
182
183 /**
184 * Specifies whether the media playback time will be respected or whether the media content will be provided as fast as possible.
185 * @see DSMedium::setRespectPlaybackTime().
186 */
187 bool setRespectPlaybackTime(const bool respectPlaybackTime) override;
188
189 protected:
190
191 /// DirectShow sample sink filter.
193
194 /// Frame type of the most recent (upcoming frame) frame.
196
197 /// The recent camera profile, if known.
199
200 /// DirecShow media sub type for YUV420, 30323449-0000-0010-8000-00AA00389B71 'I420' == MEDIASUBTYPE_I420
201 static constexpr GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
202
203 /// True, to deliver the media content based on the presentation time; False, to ignore the presentation clock and to deliver the media content as fast as possible.
204 bool respectPlaybackTime_ = true;
205};
206
207}
208
209}
210
211}
212
213#endif // META_OCEAN_MEDIA_DS_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
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
Class allowing the sorting of several video media types according their popularity.
Definition DSFrameMedium.h:42
DSMediaType dsMediaType_
DirectShow media type.
Definition DSFrameMedium.h:62
const AM_MEDIA_TYPE & type() const
Returns the DirectShow media type.
DSSortableFrameType(DSMediaType &&dsMediaType, const MediaFrameType &frameType)
Creates a new sortable media type.
This is the base class for all DirectShow frame mediums.
Definition DSFrameMedium.h:35
bool setPreferredFramePixelFormat(const FrameType::PixelFormat format) override
Sets the preferred frame pixel format.
std::vector< DSSortableFrameType > DSSortableFrameTypes
Definition of a vector holding sortable media type objects.
Definition DSFrameMedium.h:68
bool setPreferredFrameDimension(const unsigned int width, const unsigned int height) override
Sets the preferred frame dimension.
ScopedDSSampleSinkFilter sampleSinkFilter_
DirectShow sample sink filter.
Definition DSFrameMedium.h:192
static FrameType::PixelFormat convertMediaSubtype(const GUID &mediaSubtype)
Converts a Directshow media subtype to a pixel format.
~DSFrameMedium() override
Destructs a DSFrameMedium object.
SharedAnyCamera recentAnyCamera_
The recent camera profile, if known.
Definition DSFrameMedium.h:198
static FrameType::PixelOrigin extractPixelOrigin(const GUID &mediaSubtype)
Returns the pixel origin of a Directshow media subtype.
bool setPreferredFrameFrequency(const FrameFrequency frequency) override
Sets the preferred frame frequency in Hz.
bool insertFrameSampleSinkFilter(IPin *outputPin, FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED)
Creates a new sample sink filter.
static bool collectFrameFormats(IPin *pin, FrameTypes &frameTypes)
Collect all supported frame formats of a given pin.
void releaseFrameSampleSinkFilter()
Releases a the frame sample sink filter.
static bool modifyFrameFormat(AM_MEDIA_TYPE &mediaType, const MediaFrameType &frameType)
Modifies the video format of a given DirectShow media type.
bool setRespectPlaybackTime(const bool respectPlaybackTime) override
Specifies whether the media playback time will be respected or whether the media content will be prov...
DSFrameMedium(const std::string &url)
Creates a new frame medium by a given url.
virtual void onNewSample(IMediaSample *sample, const Timestamp timestamp, const Timestamp relativeTimestamp)
Called by the sample sink filter if a new sample arrived.
static bool extractFrameFormat(const AM_MEDIA_TYPE &mediaType, MediaFrameType &frameType)
Extracts the video format of a given DirectShow media type.
static bool createMediaType(CMediaType &mediaType, const MediaFrameType &frameType)
Creates the video format of a given DirectShow media type.
bool createFrameSampleSinkFilter()
Creates the frame sink filter.
static GUID convertPixelFormat(const FrameType::PixelFormat pixelFormat)
Converts a pixel format to a DirectShow media subtype.
FrameType recentFrameType_
Frame type of the most recent (upcoming frame) frame.
Definition DSFrameMedium.h:195
This class wraps the DirectShow AM_MEDIA_TYPE struct;.
Definition DSMediaType.h:31
This is the base class for all direct show mediums.
Definition DSMedium.h:36
Definition of a media frame type composed by the frame dimension, pixel format, pixel origin and a fr...
Definition FrameMedium.h:65
Class allowing the sorting of several frame media types according their popularity.
Definition FrameMedium.h:308
This is the base class for all frame mediums.
Definition FrameMedium.h:53
std::vector< MediaFrameType > FrameTypes
Definition of a vector holding frame types.
Definition FrameMedium.h:302
double FrameFrequency
Definition of a frame frequency defined in Hz.
Definition FrameMedium.h:59
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition ScopedObject.h:166
This class implements a timestamp.
Definition Timestamp.h:36
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