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

Unified Diff: services/media/framework/stages/active_source_stage.cc

Issue 1577953002: Motown in-proc streaming framework used to implement media services. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Changed lpcm input/output to use packets for supplying frames. Some name changes. Synced to master. 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698