OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ | 5 #ifndef SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ |
6 #define SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ | 6 #define SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "services/media/framework/engine.h" | 10 #include "services/media/framework/engine.h" |
11 #include "services/media/framework/refs.h" | 11 #include "services/media/framework/refs.h" |
12 #include "services/media/framework/stages/active_sink_stage.h" | 12 #include "services/media/framework/stages/active_sink_stage.h" |
13 #include "services/media/framework/stages/active_source_stage.h" | 13 #include "services/media/framework/stages/active_source_stage.h" |
14 #include "services/media/framework/stages/multistream_source_stage.h" | 14 #include "services/media/framework/stages/multistream_source_stage.h" |
15 #include "services/media/framework/stages/stage.h" | 15 #include "services/media/framework/stages/stage.h" |
16 #include "services/media/framework/stages/transform_stage.h" | 16 #include "services/media/framework/stages/transform_stage.h" |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // StageCreator::Create creates a stage for a part. DEFINE_STAGE_CREATOR defines | 23 // StageCreator::Create creates a stage for a part. DEFINE_STAGE_CREATOR defines |
24 // a specialization for a particular model/stage type pair. Every new | 24 // a specialization for a particular model/stage type pair. Every new |
25 // model/stage type pair that's defined will need an entry here. | 25 // model/stage type pair that's defined will need an entry here. |
26 template<typename T, typename Enable = void> class StageCreator; | 26 template <typename T, typename Enable = void> |
| 27 class StageCreator; |
27 | 28 |
28 #define DEFINE_STAGE_CREATOR(TModel, TStage) \ | 29 #define DEFINE_STAGE_CREATOR(TModel, TStage) \ |
29 template<typename T> \ | 30 template <typename T> \ |
30 class StageCreator<T, typename std::enable_if< \ | 31 class StageCreator< \ |
31 std::is_base_of<TModel, T>::value>::type> { \ | 32 T, typename std::enable_if<std::is_base_of<TModel, T>::value>::type> { \ |
32 public: \ | 33 public: \ |
33 static inline Stage* Create(std::shared_ptr<T> t_ptr) { \ | 34 static inline Stage* Create(std::shared_ptr<T> t_ptr) { \ |
34 return new TStage(std::shared_ptr<TModel>(t_ptr)); \ | 35 return new TStage(std::shared_ptr<TModel>(t_ptr)); \ |
35 } \ | 36 } \ |
36 }; | 37 }; |
37 | 38 |
38 DEFINE_STAGE_CREATOR(MultistreamSource, MultistreamSourceStage); | 39 DEFINE_STAGE_CREATOR(MultistreamSource, MultistreamSourceStage); |
39 DEFINE_STAGE_CREATOR(Transform, TransformStage); | 40 DEFINE_STAGE_CREATOR(Transform, TransformStage); |
40 DEFINE_STAGE_CREATOR(ActiveSource, ActiveSourceStage); | 41 DEFINE_STAGE_CREATOR(ActiveSource, ActiveSourceStage); |
41 DEFINE_STAGE_CREATOR(ActiveSink, ActiveSinkStage); | 42 DEFINE_STAGE_CREATOR(ActiveSink, ActiveSinkStage); |
42 | 43 |
43 #undef DEFINE_STAGE_CREATOR | 44 #undef DEFINE_STAGE_CREATOR |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 // | 48 // |
48 // USAGE | 49 // USAGE |
49 // | 50 // |
50 // Graph is a container for sources, sinks and transforms ('parts') connected | 51 // Graph is a container for sources, sinks and transforms ('parts') connected |
51 // in a graph. PartRef, InputRef and OutputRef are all | 52 // in a graph. PartRef, InputRef and OutputRef are all |
52 // references to parts and their inputs and outputs. Graph provides a variety | 53 // references to parts and their inputs and outputs. Graph provides a variety |
53 // of methods for adding and removing parts and for connecting inputs and | 54 // of methods for adding and removing parts and for connecting inputs and |
54 // outputs to form a graph. | 55 // outputs to form a graph. |
55 // | 56 // |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // | 113 // |
113 | 114 |
114 // Host for a source, sink or transform. | 115 // Host for a source, sink or transform. |
115 class Graph { | 116 class Graph { |
116 public: | 117 public: |
117 Graph(); | 118 Graph(); |
118 | 119 |
119 ~Graph(); | 120 ~Graph(); |
120 | 121 |
121 // Adds a part to the graph. | 122 // Adds a part to the graph. |
122 template<typename T> | 123 template <typename T> |
123 PartRef Add(std::shared_ptr<T> t_ptr) { | 124 PartRef Add(std::shared_ptr<T> t_ptr) { |
124 DCHECK(t_ptr); | 125 DCHECK(t_ptr); |
125 return Add(StageCreator<T>::Create(t_ptr)); | 126 return Add(StageCreator<T>::Create(t_ptr)); |
126 } | 127 } |
127 | 128 |
128 // Removes a part from the graph after disconnecting it from other parts. | 129 // Removes a part from the graph after disconnecting it from other parts. |
129 void RemovePart(PartRef part); | 130 void RemovePart(PartRef part); |
130 | 131 |
131 // Connects an output connector to an input connector. Returns the dowstream | 132 // Connects an output connector to an input connector. Returns the dowstream |
132 // part. | 133 // part. |
(...skipping 24 matching lines...) Expand all Loading... |
157 | 158 |
158 // Disconnects and removes everything connected to output. | 159 // Disconnects and removes everything connected to output. |
159 void RemovePartsConnectedToOutput(const OutputRef& output); | 160 void RemovePartsConnectedToOutput(const OutputRef& output); |
160 | 161 |
161 // Disconnects and removes everything connected to input. | 162 // Disconnects and removes everything connected to input. |
162 void RemovePartsConnectedToInput(const InputRef& input); | 163 void RemovePartsConnectedToInput(const InputRef& input); |
163 | 164 |
164 // Adds all the parts in t (which must all have one input and one output) and | 165 // Adds all the parts in t (which must all have one input and one output) and |
165 // connects them in sequence to the output connector. Returns the output | 166 // connects them in sequence to the output connector. Returns the output |
166 // connector of the last part or the output parameter if it is empty. | 167 // connector of the last part or the output parameter if it is empty. |
167 template<typename T> | 168 template <typename T> |
168 OutputRef AddAndConnectAll(OutputRef output, const T& t) { | 169 OutputRef AddAndConnectAll(OutputRef output, const T& t) { |
169 for (const auto& element : t) { | 170 for (const auto& element : t) { |
170 PartRef part = Add(StageCreator<T>::Create(element)); | 171 PartRef part = Add(StageCreator<T>::Create(element)); |
171 Connect(output, part.input()); | 172 Connect(output, part.input()); |
172 output = part.output(); | 173 output = part.output(); |
173 } | 174 } |
174 return output; | 175 return output; |
175 } | 176 } |
176 | 177 |
177 // Removes all parts from the graph. | 178 // Removes all parts from the graph. |
(...skipping 21 matching lines...) Expand all Loading... |
199 std::list<Stage*> sinks_; | 200 std::list<Stage*> sinks_; |
200 | 201 |
201 Engine engine_; | 202 Engine engine_; |
202 Stage::UpdateCallback update_function_; | 203 Stage::UpdateCallback update_function_; |
203 }; | 204 }; |
204 | 205 |
205 } // namespace media | 206 } // namespace media |
206 } // namespace mojo | 207 } // namespace mojo |
207 | 208 |
208 #endif // SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ | 209 #endif // SERVICES_MEDIA_FRAMEWORK_GRAPH_H_ |
OLD | NEW |