Index: services/media/framework/stages/active_source_stage.cc |
diff --git a/services/media/framework/stages/active_source_stage.cc b/services/media/framework/stages/active_source_stage.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..75bf3e1115dbe3a9cb0197ad041a764447b7bf7a |
--- /dev/null |
+++ b/services/media/framework/stages/active_source_stage.cc |
@@ -0,0 +1,48 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/media/framework/stages/active_source_stage.h" |
+ |
+namespace mojo { |
+namespace media { |
+ |
+ActiveSourceStage::ActiveSourceStage(ActiveSourcePtr source) : source_(source) { |
+ DCHECK(source_); |
+ |
+ supply_function_ = [this](PacketPtr packet) { |
+ bool packets_was_empty_ = packets_.empty(); |
+ packets_.push_back(std::move(packet)); |
+ if (packets_was_empty_ && update_callback_) { |
+ update_callback_(this); |
+ } |
+ }; |
+ |
+ source_->RegisterSupplyCallback(supply_function_); |
+} |
+ |
+ActiveSourceStage::~ActiveSourceStage() {} |
+ |
+bool ActiveSourceStage::Prepare(UpdateCallback update_callback) { |
+ update_callback_ = update_callback; |
+ Allocator* allocator = output_.Prepare(source_->can_accept_allocator()); |
+ if (allocator) { |
+ DCHECK(source_->can_accept_allocator()); |
+ source_->set_allocator(allocator); |
+ } |
+ return true; |
+} |
+ |
+void ActiveSourceStage::Update(Engine& engine) { |
+ Demand demand = output_.demand(); |
+ |
+ source_->SetDownstreamDemand(demand); |
+ |
+ if (demand != Demand::kNegative && !packets_.empty()) { |
+ output_.supply_packet(std::move(packets_.front()), engine); |
+ packets_.pop_front(); |
+ } |
+} |
+ |
+} // namespace media |
+} // namespace mojo |