| 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 "graph/mixer_node.h" | 
| 18 | |
| 19 | |
| 20 | |
| 21 | namespace vraudio { | 
| 22 | |
| 23 | MixerNode::MixerNode(const SystemSettings& system_settings, size_t num_channels) | 
| 24 | : num_channels_(num_channels), | 
| 25 | mixer_(num_channels_, system_settings.GetFramesPerBuffer()) { | 
| 26 | DCHECK_NE(num_channels_, 0U); | 
| 27 | EnableProcessOnEmptyInput(enable: true); | 
| 28 | } | 
| 29 | |
| 30 | const AudioBuffer* MixerNode::GetOutputBuffer() const { | 
| 31 | return mixer_.GetOutput(); | 
| 32 | } | 
| 33 | |
| 34 | bool MixerNode::CleanUp() { | 
| 35 | CallCleanUpOnInputNodes(); | 
| 36 | // Prevent node from being disconnected when all sources are removed. | 
| 37 | return false; | 
| 38 | } | 
| 39 | |
| 40 | const AudioBuffer* MixerNode::AudioProcess(const NodeInput& input) { | 
| 41 | |
| 42 | |
| 43 | mixer_.Reset(); | 
| 44 | |
| 45 | const auto& input_buffers = input.GetInputBuffers(); | 
| 46 | if (input_buffers.empty()) { | 
| 47 | return nullptr; | 
| 48 | } | 
| 49 | |
| 50 | for (auto input_buffer : input_buffers) { | 
| 51 | DCHECK_EQ(input_buffer->num_channels(), num_channels_); | 
| 52 | mixer_.AddInput(input: *input_buffer); | 
| 53 | } | 
| 54 | return mixer_.GetOutput(); | 
| 55 | } | 
| 56 | |
| 57 | } // namespace vraudio | 
| 58 | 
