| 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/buffered_source_node.h" | 
| 18 | |
| 19 | #include "base/constants_and_types.h" | 
| 20 | #include "base/logging.h" | 
| 21 | |
| 22 | namespace vraudio { | 
| 23 | |
| 24 | BufferedSourceNode::BufferedSourceNode(SourceId source_id, size_t num_channels, | 
| 25 | size_t frames_per_buffer) | 
| 26 | : source_id_(source_id), | 
| 27 | input_audio_buffer_(num_channels, frames_per_buffer), | 
| 28 | new_buffer_flag_(false) { | 
| 29 | input_audio_buffer_.Clear(); | 
| 30 | } | 
| 31 | |
| 32 | AudioBuffer* BufferedSourceNode::GetMutableAudioBufferAndSetNewBufferFlag() { | 
| 33 | new_buffer_flag_ = true; | 
| 34 | return &input_audio_buffer_; | 
| 35 | } | 
| 36 | |
| 37 | const AudioBuffer* BufferedSourceNode::AudioProcess() { | 
| 38 | if (!new_buffer_flag_) { | 
| 39 | return nullptr; | 
| 40 | } | 
| 41 | new_buffer_flag_ = false; | 
| 42 | input_audio_buffer_.set_source_id(source_id_); | 
| 43 | return &input_audio_buffer_; | 
| 44 | } | 
| 45 | |
| 46 | } // namespace vraudio | 
| 47 | 
