1 /* 2 * Copyright 2019 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 17 #ifndef OBOETESTER_FULL_DUPLEX_ANALYZER_H 18 #define OBOETESTER_FULL_DUPLEX_ANALYZER_H 19 20 #include <unistd.h> 21 #include <sys/types.h> 22 23 #include "oboe/Oboe.h" 24 #include "analyzer/LatencyAnalyzer.h" 25 #include "FullDuplexStreamWithConversion.h" 26 #include "MultiChannelRecording.h" 27 28 class FullDuplexAnalyzer : public FullDuplexStreamWithConversion { 29 public: FullDuplexAnalyzer(LoopbackProcessor * processor)30 FullDuplexAnalyzer(LoopbackProcessor *processor) 31 : mLoopbackProcessor(processor) { 32 setNumInputBurstsCushion(1); 33 } 34 35 /** 36 * Called when data is available on both streams. 37 * Caller should override this method. 38 */ 39 oboe::DataCallbackResult onBothStreamsReadyFloat( 40 const float *inputData, 41 int numInputFrames, 42 float *outputData, 43 int numOutputFrames 44 ) override; 45 46 oboe::Result start() override; 47 getLoopbackProcessor()48 LoopbackProcessor *getLoopbackProcessor() { 49 return mLoopbackProcessor; 50 } 51 setRecording(MultiChannelRecording * recording)52 void setRecording(MultiChannelRecording *recording) { 53 mRecording = recording; 54 } 55 isWriteReadDeltaValid()56 bool isWriteReadDeltaValid() { 57 return mWriteReadDeltaValid; 58 } 59 getWriteReadDelta()60 int64_t getWriteReadDelta() { 61 return mWriteReadDelta; 62 } 63 64 private: 65 MultiChannelRecording *mRecording = nullptr; 66 67 LoopbackProcessor * const mLoopbackProcessor; 68 69 std::atomic<bool> mWriteReadDeltaValid{false}; 70 std::atomic<int64_t> mWriteReadDelta{0}; 71 }; 72 73 74 #endif //OBOETESTER_FULL_DUPLEX_ANALYZER_H 75 76