Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: services/media/framework/engine.h

Issue 1577953002: Motown in-proc streaming framework used to implement media services. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: removed build/util/LASTCHANGE Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_MEDIA_FRAMEWORK_ENGINE_H_
6 #define SERVICES_MEDIA_FRAMEWORK_ENGINE_H_
7
8 #include <deque>
9 #include <list>
10
11 #include "services/media/framework/stages/active_sink_stage.h"
12 #include "services/media/framework/stages/active_source_stage.h"
13 #include "services/media/framework/stages/distributor_stage.h"
14 #include "services/media/framework/stages/lpcm_transform_stage.h"
15 #include "services/media/framework/stages/packet_transform_stage.h"
16 #include "services/media/framework/stages/stage.h"
17
18 namespace mojo {
19 namespace media {
20
21 // Host for a source, sink or transform.
22 class Engine {
23 public:
24 class Input;
25 class Output;
26
27 // Opaque Stage pointer used for graph building.
28 class Part {
29 public:
30 Part() : stage_(nullptr) {}
31
32 uint32_t input_count();
33 Input input(uint32_t index);
johngro 2016/01/20 00:25:32 re: the accessors here which are making copies of
dalesat 2016/01/25 17:47:29 The intent is that Part, Input and Output are valu
dalesat 2016/01/25 23:29:37 Also, Input and Output are synthesized by these me
johngro 2016/01/27 22:35:22 Acknowledged.
34 Input input();
35 uint32_t output_count();
36 Output output(uint32_t index);
37 Output output();
38 Part upstream_part(uint32_t index);
39 Part upstream_part();
40 Part downstream_part(uint32_t index);
41 Part downstream_part();
42
43 private:
44 Part(Stage* stage) : stage_(stage) {}
45
46 explicit operator bool() const { return stage_ != nullptr; }
47
48 Stage* stage_;
49
50 friend Engine;
51 friend Input;
52 friend Output;
53 };
54
55 // Opaque StageInput pointer used for graph building.
56 class Input {
57 public:
58 Input() : stage_(nullptr), index_(0) {}
59
60 explicit operator bool() const { return stage_ != nullptr; }
61
62 Part part() { return Part(stage_); }
63
64 bool connected() {
65 DCHECK(stage_);
66 return stage_input().upstream_stage() != nullptr;
67 }
68
69 Part upstream_part() {
70 DCHECK(connected());
71 return Part(stage_input().upstream_stage());
72 }
73
74 private:
75 Input(Stage* stage, uint32_t index) :
76 stage_(stage), index_(index) {
77 DCHECK(stage_);
78 DCHECK(index_ < stage_->input_count());
79 }
80
81 StageInput& stage_input() {
82 DCHECK(stage_);
83 return stage_->input(index_);
84 }
85
86 Stage* stage_;
87 uint32_t index_;
88
89 friend Engine;
90 friend Part;
91 friend Output;
92 };
93
94 // Opaque StageOutput pointer used for graph building.
95 class Output {
96 public:
97 Output() : stage_(nullptr), index_(0) {}
98
99 explicit operator bool() const { return stage_ != nullptr; }
100
101 Part part() { return Part(stage_); }
102
103 bool connected() {
104 DCHECK(stage_);
105 return stage_output().downstream_stage() != nullptr;
106 }
107
108 Part downstream_part() {
109 DCHECK(connected());
110 return Part(stage_output().downstream_stage());
111 }
112
113 private:
114 Output(Stage* stage, uint32_t index) :
115 stage_(stage), index_(index) {
116 DCHECK(stage_);
117 DCHECK(index_ < stage_->output_count());
118 }
119
120 StageOutput& stage_output() {
121 DCHECK(stage_);
122 return stage_->output(index_);
123 }
124
125 Stage* stage_;
126 uint32_t index_;
127
128 friend Engine;
129 friend Part;
130 friend Input;
131 };
132
133 Engine();
134
135 ~Engine();
136
137 // Adds a part to the engine.
138 template<typename T, typename TBase>
139 Part Add(SharedPtr<T, TBase> t) {
140 DCHECK(t);
141 return Add(CreateStage(std::shared_ptr<TBase>(t)));
142 }
143
144 // Removes a part from the engine after disconnecting it from other parts.
145 void Remove(Part part);
146
147 // Connects an output connector to an input connector. Returns the dowstream
148 // part.
149 Part Connect(
150 Output output,
151 Input input);
152
153 // Connects a part with exactly one output to a part with exactly one input.
154 // Returns the downstream part.
155 Part Connect(Part upstream_part, Part downstream_part);
156
157 // Connects an output connector to a part that has exactly one input. Returns
158 // the downstream part.
159 Part Connect(
160 Output output,
161 Part downstream_part);
162
163 // Connects a part with exactly one output to an input connector. Returns the
164 // downstream part.
165 Part Connect(
166 Part upstream_part,
167 Input input);
168
169 // Disconnects an output connector and the input connector to which it's
170 // connected.
171 void Disconnect(Output output);
172
173 // Disconnects an input connector and the output connector to which it's
174 // connected.
175 void Disconnect(Input input);
176
177 // Disconnects and removes part and everything connected to it.
178 void RemoveAll(Part part);
179
180 // Disconnects and removes everything connected to output.
181 void RemoveAll(Output output);
182
183 // Disconnects and removes everything connected to input.
184 void RemoveAll(Input input);
185
186 // Adds all the parts in t (which must all have one input and one output) and
187 // connects them in sequence to the output connector. Returns the output
188 // connector of the last part or the output parameter if t is empty.
189 template<typename T>
190 Output AddAndConnectAll(
191 Output output,
192 const T& t) {
193 for (auto& element : t) {
194 Part part = Add(CreateStage(element));
195 Connect(output, part.input());
196 output = part.output();
197 }
198 return output;
199 }
200
201 // Prepares the engine.
202 void Prepare();
203
204 // Removes all parts from the engine.
205 void reset();
johngro 2016/01/20 00:25:32 Reset
dalesat 2016/01/25 23:29:37 Done.
206
207 // Pushes the stage to the supply backlog if it isn't already there.
208 void PushToSupplyBacklog(Stage* stage);
209
210 // Pushes the stage to the demand backlog if it isn't already there.
211 void PushToDemandBacklog(Stage* stage);
212
213 private:
214 // Adds a stage to the engine.
215 Part Add(Stage* stage);
216
217 // Creates a stage from a source, sink or transform. A specialization of this
218 // template is defined for each type of source, sink or transform that can be
219 // added to the engine.
220 template<typename T>
221 static Stage* CreateStage(std::shared_ptr<T> t);
222
223 // CreateStage template specialization for MultiStreamPacketSource.
224 static Stage* CreateStage(MultiStreamPacketSourcePtr source);
225
226 // CreateStage template specialization for PacketTransform.
227 static Stage* CreateStage(PacketTransformPtr transform);
228
229 // CreateStage template specialization for ActiveSource.
230 static Stage* CreateStage(ActiveSourcePtr source);
231
232 // CreateStage template specialization for ActiveSink.
233 static Stage* CreateStage(ActiveSinkPtr sink);
234
235 // CreateStage template specialization for LpcmTransform.
236 static Stage* CreateStage(LpcmTransformPtr transform);
237
238 // Prepares a stage.
239 void Prepare(Stage* stage);
240
241 // Processes the entire backlog.
242 void Update();
243
244 // Performs processing for a single stage, updating the backlog accordingly.
245 void Update(Stage *stage);
246
247 // Pops a stage from the supply backlog and returns it or returns nullptr if
248 // the supply backlog is empty.
249 Stage* PopFromSupplyBacklog();
250
251 // Pops a stage from the demand backlog and returns it or returns nullptr if
252 // the demand backlog is empty.
253 Stage* PopFromDemandBacklog();
254
255 std::list<std::unique_ptr<Stage>> stages_;
256 std::list<Stage*> sources_;
257 std::list<Stage*> sinks_;
258 std::deque<Stage*> supply_backlog_;
259 std::deque<Stage*> demand_backlog_;
260 Stage::UpdateCallback update_function_;
261 bool packets_produced_;
262 };
263
264 } // namespace media
265 } // namespace mojo
266
267 #endif // SERVICES_MEDIA_FRAMEWORK_ENGINE_ENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698