• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
33 
34     /**
35      * Called when data is available on both streams.
36      * Caller should override this method.
37      */
38     oboe::DataCallbackResult onBothStreamsReadyFloat(
39             const float *inputData,
40             int   numInputFrames,
41             float *outputData,
42             int   numOutputFrames
43     ) override;
44 
45     oboe::Result start() override;
46 
getLoopbackProcessor()47     LoopbackProcessor *getLoopbackProcessor() {
48         return mLoopbackProcessor;
49     }
50 
setRecording(MultiChannelRecording * recording)51     void setRecording(MultiChannelRecording *recording) {
52         mRecording = recording;
53     }
54 
isWriteReadDeltaValid()55     bool isWriteReadDeltaValid() {
56         return mWriteReadDeltaValid;
57     }
58 
getWriteReadDelta()59     int64_t getWriteReadDelta() {
60         return mWriteReadDelta;
61     }
62 
63 private:
64     MultiChannelRecording  *mRecording = nullptr;
65 
66     LoopbackProcessor * const mLoopbackProcessor;
67 
68     std::atomic<bool> mWriteReadDeltaValid{false};
69     std::atomic<int64_t> mWriteReadDelta{0};
70 };
71 
72 
73 #endif //OBOETESTER_FULL_DUPLEX_ANALYZER_H
74 
75