Ocean
DSGraphObject.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_GRAPH_OBJECT_H
9 #define META_OCEAN_MEDIA_DS_GRAPH_OBJECT_H
10 
13 
14 namespace Ocean
15 {
16 
17 namespace Media
18 {
19 
20 namespace DirectShow
21 {
22 
23 /**
24  * This class is the base class for all object holding a DirectShow filter graph manager.
25  * @ingroup mediads
26  */
27 class OCEAN_MEDIA_DS_EXPORT DSGraphObject : virtual public DSObject
28 {
29  protected:
30 
31  /**
32  * Definition of a vector holding DirectShow filters.
33  */
34  typedef std::vector<ScopedIBaseFilter> Filters;
35 
36  protected:
37 
38  /**
39  * Creates a new DSGraphObject element.
40  */
41  DSGraphObject() = default;
42 
43  /**
44  * Destructs a DSGraphObject.
45  */
46  virtual ~DSGraphObject();
47 
48  /**
49  * Creates a new filter graph builder.
50  * @return True, if succeeded
51  */
53 
54  /**
55  * Releases a filter graph builder.
56  */
58 
59  /**
60  * Builds the entire filter graph.
61  * @return True, if succeeded
62  */
63  virtual bool buildGraph() = 0;
64 
65  /**
66  * Releases the entire filter graph.
67  */
68  virtual void releaseGraph() = 0;
69 
70  /**
71  * Stars the filter graph.
72  * @return True, if succeeded
73  */
74  virtual bool startGraph();
75 
76  /**
77  * Pauses the filter graph.
78  * @return True, if succeeded
79  */
80  virtual bool pauseGraph();
81 
82  /**
83  * Stops the filter graph.
84  * @return True, if succeeded
85  */
86  virtual bool stopGraph();
87 
88  /**
89  * Adds a new filter to the filter graph.
90  * The specified filter will be created and afterwards added to the filter graph.
91  * @param classIdentifier The filter's class identifier to add
92  * @param name The name of the resulting filter
93  * @return Pointer to the filter if succeeded
94  */
95  ScopedIBaseFilter addFilter(const GUID& classIdentifier, const std::wstring& name);
96 
97  /**
98  * Connects two filters by using the first free pins.
99  * @param outputFilter Filter with a free output pin
100  * @param inputFilter Filter with a free input pin
101  * @param type Optional type of the filter connection
102  * @return True, if succeeded
103  */
104  bool connectFilters(IBaseFilter* outputFilter, IBaseFilter* inputFilter, const AM_MEDIA_TYPE* type = nullptr);
105 
106  /**
107  * Connects a pin with the first free pin of a filter.
108  * @param outputPin Output pin of a filter
109  * @param inputFilter Filter with a free input pin
110  * @param type Optional type of the filter connection
111  * @return True, if succeeded
112  */
113  bool connectFilter(IPin* outputPin, IBaseFilter* inputFilter, const AM_MEDIA_TYPE* type = nullptr);
114 
115  /**
116  * Connects a pin with the first free pin of a filter.
117  * @param outputFilter Filter with a free output pin
118  * @param inputPin Input pin of a filter
119  * @param type Optional type of the filter connection
120  * @return True, if succeeded
121  */
122  bool connectFilter(IBaseFilter* outputFilter, IPin* inputPin, const AM_MEDIA_TYPE* type = nullptr);
123 
124  /**
125  * Returns all filters which are part of the current filter graph.
126  * The caller has to release all filters after usage.
127  * @return Enumerated filters
128  */
130 
131 #ifdef OCEAN_DEBUG
132 
133  /**
134  * Adds the filter graph to the running object table.
135  */
137 
138  /**
139  * Removes the filter graph from the running object table.
140  */
142 
143 #endif
144 
145  protected:
146 
147  /// DirectShow filter graph manager.
149 
150  /// DirectShow media control interface.
152 
153  /// DirectShow media event interface.
155 
156  /// Indicates whether the graph is running.
157  bool graphIsRunning_ = false;
158 
159  private:
160 
161 #ifdef OCEAN_DEBUG
162 
163  /// DirectShow ROT interface.
164  DWORD rotId_ = DWORD(0);
165 
166 #endif
167 };
168 
169 }
170 
171 }
172 
173 }
174 
175 #endif // META_OCEAN_MEDIA_DS_GRAPH_OBJECT_H
This class is the base class for all object holding a DirectShow filter graph manager.
Definition: DSGraphObject.h:28
ScopedIBaseFilter addFilter(const GUID &classIdentifier, const std::wstring &name)
Adds a new filter to the filter graph.
Filters filters()
Returns all filters which are part of the current filter graph.
void releaseGraphBuilder()
Releases a filter graph builder.
DSGraphObject()=default
Creates a new DSGraphObject element.
bool createGraphBuilder()
Creates a new filter graph builder.
bool connectFilter(IPin *outputPin, IBaseFilter *inputFilter, const AM_MEDIA_TYPE *type=nullptr)
Connects a pin with the first free pin of a filter.
std::vector< ScopedIBaseFilter > Filters
Definition of a vector holding DirectShow filters.
Definition: DSGraphObject.h:34
virtual bool pauseGraph()
Pauses the filter graph.
virtual bool startGraph()
Stars the filter graph.
bool connectFilter(IBaseFilter *outputFilter, IPin *inputPin, const AM_MEDIA_TYPE *type=nullptr)
Connects a pin with the first free pin of a filter.
virtual bool buildGraph()=0
Builds the entire filter graph.
virtual void releaseGraph()=0
Releases the entire filter graph.
ScopedIMediaControl mediaControlInterface_
DirectShow media control interface.
Definition: DSGraphObject.h:151
ScopedIMediaEvent mediaEventInterface_
DirectShow media event interface.
Definition: DSGraphObject.h:154
bool connectFilters(IBaseFilter *outputFilter, IBaseFilter *inputFilter, const AM_MEDIA_TYPE *type=nullptr)
Connects two filters by using the first free pins.
ScopedIGraphBuilder filterGraph_
DirectShow filter graph manager.
Definition: DSGraphObject.h:148
virtual ~DSGraphObject()
Destructs a DSGraphObject.
virtual bool stopGraph()
Stops the filter graph.
bool removeFilterGraphFromROT()
Removes the filter graph from the running object table.
bool addFilterGraphToROT()
Adds the filter graph to the running object table.
This class provides basic DirectShow functionalities.
Definition: DSObject.h:175
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