| 1 | /* | 
|---|---|
| 2 | Copyright 2018 Google Inc. All Rights Reserved. | 
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); | 
| 5 | you may not use this file except in compliance with the License. | 
| 6 | You may obtain a copy of the License at | 
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 | 
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software | 
| 11 | distributed under the License is distributed on an "AS-IS" BASIS, | 
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 13 | See the License for the specific language governing permissions and | 
| 14 | limitations under the License. | 
| 15 | */ | 
| 16 | |
| 17 | #include "node/sink_node.h" | 
| 18 | |
| 19 | #include "base/logging.h" | 
| 20 | |
| 21 | namespace vraudio { | 
| 22 | |
| 23 | SinkNode::SinkNode() : Node() {} | 
| 24 | |
| 25 | const std::vector<const AudioBuffer*>& SinkNode::ReadInputs() { | 
| 26 | return input_stream_.Read(); | 
| 27 | } | 
| 28 | |
| 29 | void SinkNode::Connect( | 
| 30 | const std::shared_ptr<PublisherNodeType>& publisher_node) { | 
| 31 | input_stream_.Connect(node: publisher_node->GetSharedNodePtr(), | 
| 32 | output: publisher_node->GetOutput()); | 
| 33 | } | 
| 34 | |
| 35 | void SinkNode::Process() { | 
| 36 |   LOG(FATAL) << "Process should not be called on audio sink node.";  | 
| 37 | } | 
| 38 | |
| 39 | bool SinkNode::CleanUp() { | 
| 40 | // We need to make a copy of the OutputNodeMap map since it might change due | 
| 41 | // to Disconnect() calls. | 
| 42 | const auto connected_nodes = input_stream_.GetConnectedNodeOutputPairs(); | 
| 43 | for (const auto& input_node : connected_nodes) { | 
| 44 | Output<const AudioBuffer*>* output = input_node.first; | 
| 45 | std::shared_ptr<Node> node = input_node.second; | 
| 46 | const bool is_orphaned = node->CleanUp(); | 
| 47 | if (is_orphaned) { | 
| 48 | input_stream_.Disconnect(output); | 
| 49 | } | 
| 50 | } | 
| 51 | return false; | 
| 52 | } | 
| 53 | |
| 54 | } // namespace vraudio | 
| 55 | 
