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

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

Issue 1822333002: Motown: wholesale clang-format (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: dalesat Created 4 years, 9 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
« no previous file with comments | « services/media/framework/engine.h ('k') | services/media/framework/formatting.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "services/media/framework/engine.h" 5 #include "services/media/framework/engine.h"
6 6
7 namespace mojo { 7 namespace mojo {
8 namespace media { 8 namespace media {
9 9
10 Engine::Engine() {} 10 Engine::Engine() {}
11 11
12 Engine::~Engine() { 12 Engine::~Engine() {
13 base::AutoLock lock(lock_); 13 base::AutoLock lock(lock_);
14 } 14 }
15 15
16 void Engine::PrepareInput(const InputRef& input) { 16 void Engine::PrepareInput(const InputRef& input) {
17 VisitUpstream( 17 VisitUpstream(input, [](const InputRef& input, const OutputRef& output,
18 input, 18 const Stage::UpstreamCallback& callback) {
19 [] (const InputRef& input, 19 DCHECK(!input.actual().prepared());
20 const OutputRef& output, 20 PayloadAllocator* allocator = input.stage_->PrepareInput(input.index_);
21 const Stage::UpstreamCallback& callback) { 21 input.actual().set_prepared(true);
22 DCHECK(!input.actual().prepared()); 22 output.stage_->PrepareOutput(output.index_, allocator, callback);
23 PayloadAllocator* allocator = input.stage_->PrepareInput(input.index_); 23 });
24 input.actual().set_prepared(true);
25 output.stage_->PrepareOutput(output.index_, allocator, callback);
26 });
27 } 24 }
28 25
29 void Engine::UnprepareInput(const InputRef& input) { 26 void Engine::UnprepareInput(const InputRef& input) {
30 VisitUpstream( 27 VisitUpstream(input, [](const InputRef& input, const OutputRef& output,
31 input, 28 const Stage::UpstreamCallback& callback) {
32 [] (const InputRef& input, 29 DCHECK(input.actual().prepared());
33 const OutputRef& output, 30 input.stage_->UnprepareInput(input.index_);
34 const Stage::UpstreamCallback& callback) { 31 output.stage_->UnprepareOutput(output.index_, callback);
35 DCHECK(input.actual().prepared()); 32 });
36 input.stage_->UnprepareInput(input.index_);
37 output.stage_->UnprepareOutput(output.index_, callback);
38 });
39 } 33 }
40 34
41 void Engine::FlushOutput(const OutputRef& output) { 35 void Engine::FlushOutput(const OutputRef& output) {
42 if (!output.connected()) { 36 if (!output.connected()) {
43 return; 37 return;
44 } 38 }
45 VisitDownstream( 39 VisitDownstream(output, [](const OutputRef& output, const InputRef& input,
46 output, 40 const Stage::DownstreamCallback& callback) {
47 [] (const OutputRef& output, 41 DCHECK(input.actual().prepared());
48 const InputRef& input, 42 output.stage_->FlushOutput(output.index_);
49 const Stage::DownstreamCallback& callback) { 43 input.stage_->FlushInput(input.index_, callback);
50 DCHECK(input.actual().prepared()); 44 });
51 output.stage_->FlushOutput(output.index_);
52 input.stage_->FlushInput(input.index_, callback);
53 });
54 } 45 }
55 46
56 void Engine::RequestUpdate(Stage* stage) { 47 void Engine::RequestUpdate(Stage* stage) {
57 DCHECK(stage); 48 DCHECK(stage);
58 base::AutoLock lock(lock_); 49 base::AutoLock lock(lock_);
59 Update(stage); 50 Update(stage);
60 Update(); 51 Update();
61 } 52 }
62 53
63 void Engine::PushToSupplyBacklog(Stage* stage) { 54 void Engine::PushToSupplyBacklog(Stage* stage) {
(...skipping 10 matching lines...) Expand all
74 void Engine::PushToDemandBacklog(Stage* stage) { 65 void Engine::PushToDemandBacklog(Stage* stage) {
75 lock_.AssertAcquired(); 66 lock_.AssertAcquired();
76 DCHECK(stage); 67 DCHECK(stage);
77 68
78 if (!stage->in_demand_backlog_) { 69 if (!stage->in_demand_backlog_) {
79 demand_backlog_.push(stage); 70 demand_backlog_.push(stage);
80 stage->in_demand_backlog_ = true; 71 stage->in_demand_backlog_ = true;
81 } 72 }
82 } 73 }
83 74
84 void Engine::VisitUpstream( 75 void Engine::VisitUpstream(const InputRef& input,
85 const InputRef& input, 76 const UpstreamVisitor& vistor) {
86 const UpstreamVisitor& vistor) {
87 base::AutoLock lock(lock_); 77 base::AutoLock lock(lock_);
88 78
89 std::queue<InputRef> backlog; 79 std::queue<InputRef> backlog;
90 backlog.push(input); 80 backlog.push(input);
91 81
92 while (!backlog.empty()) { 82 while (!backlog.empty()) {
93 InputRef input = backlog.front(); 83 InputRef input = backlog.front();
94 backlog.pop(); 84 backlog.pop();
95 DCHECK(input.valid()); 85 DCHECK(input.valid());
96 DCHECK(input.connected()); 86 DCHECK(input.connected());
97 87
98 const OutputRef& output = input.mate(); 88 const OutputRef& output = input.mate();
99 Stage* output_stage = output.stage_; 89 Stage* output_stage = output.stage_;
100 90
101 vistor( 91 vistor(input, output, [output_stage, &backlog](size_t input_index) {
102 input, 92 backlog.push(InputRef(output_stage, input_index));
103 output, 93 });
104 [output_stage, &backlog](size_t input_index) {
105 backlog.push(InputRef(output_stage, input_index));
106 });
107 } 94 }
108 } 95 }
109 96
110 void Engine::VisitDownstream( 97 void Engine::VisitDownstream(const OutputRef& output,
111 const OutputRef& output, 98 const DownstreamVisitor& vistor) {
112 const DownstreamVisitor& vistor) {
113 base::AutoLock lock(lock_); 99 base::AutoLock lock(lock_);
114 100
115 std::queue<OutputRef> backlog; 101 std::queue<OutputRef> backlog;
116 backlog.push(output); 102 backlog.push(output);
117 103
118 while (!backlog.empty()) { 104 while (!backlog.empty()) {
119 OutputRef output = backlog.front(); 105 OutputRef output = backlog.front();
120 backlog.pop(); 106 backlog.pop();
121 DCHECK(output.valid()); 107 DCHECK(output.valid());
122 DCHECK(output.connected()); 108 DCHECK(output.connected());
123 109
124 const InputRef& input = output.mate(); 110 const InputRef& input = output.mate();
125 Stage* input_stage = input.stage_; 111 Stage* input_stage = input.stage_;
126 112
127 vistor( 113 vistor(output, input, [input_stage, &backlog](size_t output_index) {
128 output, 114 backlog.push(OutputRef(input_stage, output_index));
129 input, 115 });
130 [input_stage, &backlog](size_t output_index) {
131 backlog.push(OutputRef(input_stage, output_index));
132 });
133 } 116 }
134 } 117 }
135 118
136 void Engine::Update() { 119 void Engine::Update() {
137 lock_.AssertAcquired(); 120 lock_.AssertAcquired();
138 121
139 while (true) { 122 while (true) {
140 Stage* stage = PopFromSupplyBacklog(); 123 Stage* stage = PopFromSupplyBacklog();
141 if (stage != nullptr) { 124 if (stage != nullptr) {
142 Update(stage); 125 Update(stage);
143 continue; 126 continue;
144 } 127 }
145 128
146 stage = PopFromDemandBacklog(); 129 stage = PopFromDemandBacklog();
147 if (stage != nullptr) { 130 if (stage != nullptr) {
148 Update(stage); 131 Update(stage);
149 continue; 132 continue;
150 } 133 }
151 134
152 break; 135 break;
153 } 136 }
154 } 137 }
155 138
156 void Engine::Update(Stage *stage) { 139 void Engine::Update(Stage* stage) {
157 lock_.AssertAcquired(); 140 lock_.AssertAcquired();
158 141
159 DCHECK(stage); 142 DCHECK(stage);
160 143
161 packets_produced_ = false; 144 packets_produced_ = false;
162 145
163 stage->Update(this); 146 stage->Update(this);
164 147
165 // If the stage produced packets, it may need to reevaluate demand later. 148 // If the stage produced packets, it may need to reevaluate demand later.
166 if (packets_produced_) { 149 if (packets_produced_) {
(...skipping 24 matching lines...) Expand all
191 174
192 Stage* stage = demand_backlog_.top(); 175 Stage* stage = demand_backlog_.top();
193 demand_backlog_.pop(); 176 demand_backlog_.pop();
194 DCHECK(stage->in_demand_backlog_); 177 DCHECK(stage->in_demand_backlog_);
195 stage->in_demand_backlog_ = false; 178 stage->in_demand_backlog_ = false;
196 return stage; 179 return stage;
197 } 180 }
198 181
199 } // namespace media 182 } // namespace media
200 } // namespace mojo 183 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/framework/engine.h ('k') | services/media/framework/formatting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698