1 /*
2  * Copyright 2016 The Android Open Source Project
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 #ifndef NATIVEOBOE_AUDIOGRAPHRUNNER_H
17 #define NATIVEOBOE_AUDIOGRAPHRUNNER_H
18 
19 #include <unistd.h>
20 #include <sys/types.h>
21 
22 #include "flowgraph/FlowGraphNode.h"
23 #include "oboe/Oboe.h"
24 #include "OboeTesterStreamCallback.h"
25 
26 using namespace oboe::flowgraph;
27 
28 /**
29  * Bridge between an audio flowgraph and an audio device.
30  * Pass in an AudioSink and then pass
31  * this object to the AudioStreamBuilder as a callback.
32  */
33 class AudioStreamGateway : public OboeTesterStreamCallback {
34 public:
35     virtual ~AudioStreamGateway() = default;
36 
setAudioSink(std::shared_ptr<oboe::flowgraph::FlowGraphSink> sink)37     void setAudioSink(std::shared_ptr<oboe::flowgraph::FlowGraphSink>  sink) {
38         mAudioSink = sink;
39     }
40 
41     /**
42      * Called by Oboe when the stream is ready to process audio.
43      */
44     oboe::DataCallbackResult onAudioReady(
45             oboe::AudioStream *audioStream,
46             void *audioData,
47             int numFrames) override;
48 
49 private:
50 
51     std::shared_ptr<oboe::flowgraph::FlowGraphSink>  mAudioSink;
52 };
53 
54 
55 #endif //NATIVEOBOE_AUDIOGRAPHRUNNER_H
56