Ocean
DSSoundMedium.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_SOUND_MEDIUM_H
9 #define META_OCEAN_MEDIA_DS_SOUND_MEDIUM_H
10 
14 
15 #include "ocean/math/Numeric.h"
16 
18 
19 namespace Ocean
20 {
21 
22 namespace Media
23 {
24 
25 namespace DirectShow
26 {
27 
28 /**
29  * This class is the base class for all DirectShow sound mediums.
30  * @ingroup mediads
31  */
32 class OCEAN_MEDIA_DS_EXPORT DSSoundMedium :
33  public virtual DSMedium,
34  public virtual SoundMedium
35 {
36  protected:
37 
38  /**
39  * Class allowing the sorting of several audio types according their popularity.
40  */
42  {
43  public:
44 
45  /**
46  * Creates a new sortable sound type.
47  * The given sound type has to be freed after the entire sorting process by the caller.
48  * @param dsMediaType The DirectShow media type
49  * @param soundType Preferable sound type
50  */
51  DSSortableSoundType(DSMediaType&& dsMediaType, const SoundType& soundType);
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 sound type objects.
67  */
68  typedef std::vector<DSSortableSoundType> DSSortableSoundTypes;
69 
70  /**
71  * Definition of a vector holding filters.
72  */
73  typedef std::vector<ScopedIBaseFilter> Filters;
74 
75  public:
76 
77  /**
78  * Returns the volume of the sound in db.
79  * @see SoundMedium::soundVolume().
80  */
81  float soundVolume() const override;
82 
83  /**
84  * Returns whether the sound medium is in a mute state.
85  * @see SoundMedium::soundMute().
86  */
87  bool soundMute() const override;
88 
89  /**
90  * Sets the volume of the sound in db.
91  * @see SoundMedium::setSoundVolume().
92  */
93  bool setSoundVolume(const float volume) override;
94 
95  /**
96  * Sets or un-sets the sound medium to a mute state.
97  * @see SoundMedium::setSoundMute().
98  */
99  bool setSoundMute(const bool mute) override;
100 
101  /**
102  * Extracts the sound format of a given DirectShow media type.
103  * @param mediaType DirectShow media type
104  * @param soundType Resulting sound type
105  * @return True, if succeeded
106  */
107  static bool extractSoundFormat(const AM_MEDIA_TYPE& mediaType, SoundType& soundType);
108 
109  protected:
110 
111  /**
112  * Creates a new sound medium by a given url.
113  * @param url Url of the sound medium
114  */
115  explicit DSSoundMedium(const std::string& url);
116 
117  /**
118  * Destructs a DSSoundMedium object.
119  */
120  ~DSSoundMedium() override;
121 
122  /**
123  * Creates the sound interface.
124  * @return True, if succeeded
125  */
127 
128  /**
129  * Initializes the audio interface.
130  * @param filter Audio renderer filter
131  * @return True, if succeeded
132  */
133  bool initializeSoundInterface(IBaseFilter* filter);
134 
135  /**
136  * Releases the audio interface.
137  */
139 
140  /**
141  * Removes the video branch from the filter graph.
142  * @return True, if succeeded
143  */
145 
146  /**
147  * Removes the sound branch from the filter graph.
148  * @return True, if succeeded
149  */
151 
152  protected:
153 
154  /// DirectShow basic audio interface.
156 
157  /// DirectShow null renderer for video suppression.
159 
160  /// DirectShow null renderer for video suppression.
162 
163  /// Sound volume before mute state.
164  float soundNonMuteVolume_ = NumericF::minValue();
165 };
166 
167 }
168 
169 }
170 
171 }
172 
173 #endif // META_OCEAN_MEDIA_DS_SOUND_MEDIUM_H
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
Class allowing the sorting of several audio types according their popularity.
Definition: DSSoundMedium.h:42
const AM_MEDIA_TYPE & type() const
Returns the DirectShow media type.
DSMediaType dsMediaType_
DirectShow media type.
Definition: DSSoundMedium.h:62
DSSortableSoundType(DSMediaType &&dsMediaType, const SoundType &soundType)
Creates a new sortable sound type.
This class is the base class for all DirectShow sound mediums.
Definition: DSSoundMedium.h:35
DSSoundMedium(const std::string &url)
Creates a new sound medium by a given url.
static bool extractSoundFormat(const AM_MEDIA_TYPE &mediaType, SoundType &soundType)
Extracts the sound format of a given DirectShow media type.
void releaseSoundInterface()
Releases the audio interface.
bool createSoundInterface()
Creates the sound interface.
bool setSoundMute(const bool mute) override
Sets or un-sets the sound medium to a mute state.
float soundVolume() const override
Returns the volume of the sound in db.
ScopedIBaseFilter soundVideoSuppressionNullRendererFilter_
DirectShow null renderer for video suppression.
Definition: DSSoundMedium.h:158
bool removeVideoBranch()
Removes the video branch from the filter graph.
ScopedIBaseFilter soundVideoSuppressionNullRendererFilter2_
DirectShow null renderer for video suppression.
Definition: DSSoundMedium.h:161
std::vector< ScopedIBaseFilter > Filters
Definition of a vector holding filters.
Definition: DSSoundMedium.h:73
std::vector< DSSortableSoundType > DSSortableSoundTypes
Definition of a vector holding sortable sound type objects.
Definition: DSSoundMedium.h:68
bool setSoundVolume(const float volume) override
Sets the volume of the sound in db.
~DSSoundMedium() override
Destructs a DSSoundMedium object.
ScopedIBasicAudio soundBasicAudioInterface_
DirectShow basic audio interface.
Definition: DSSoundMedium.h:155
bool initializeSoundInterface(IBaseFilter *filter)
Initializes the audio interface.
bool soundMute() const override
Returns whether the sound medium is in a mute state.
bool removeSoundBranch()
Removes the sound branch from the filter graph.
Class allowing the sorting of several sound media types according their popularity.
Definition: SoundMedium.h:134
Definition of a sound type composed by the sound frequency and channels.
Definition: SoundMedium.h:50
This class is the base class for all sound mediums.
Definition: SoundMedium.h:38
static constexpr T minValue()
Returns the min scalar value.
Definition: Numeric.h:3250
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