xref: /aosp_15_r20/external/oboe/apps/OboeTester/app/src/main/cpp/FullDuplexStreamWithConversion.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1 /*
2  * Copyright 2023 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_STREAM_WITH_CONVERSION_H
18 #define OBOETESTER_FULL_DUPLEX_STREAM_WITH_CONVERSION_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 
23 #include "oboe/Oboe.h"
24 #include "FormatConverterBox.h"
25 
26 class FullDuplexStreamWithConversion : public oboe::FullDuplexStream {
27 public:
28     /**
29      * Called when data is available on both streams.
30      * Caller must override this method.
31      */
32     virtual oboe::DataCallbackResult onBothStreamsReadyFloat(
33             const float *inputData,
34             int numInputFrames,
35             float *outputData,
36             int numOutputFrames
37     ) = 0;
38 
39     /**
40      * Overrides the default onBothStreamsReady by converting to floats and then calling
41      * onBothStreamsReadyFloat().
42      */
43     oboe::DataCallbackResult onBothStreamsReady(
44             const void *inputData,
45             int numInputFrames,
46             void *outputData,
47             int numOutputFrames
48     ) override;
49 
50     oboe::ResultWithValue<int32_t> readInput(int32_t numFrames) override;
51 
52     virtual oboe::Result start() override;
53 
54 private:
55     std::unique_ptr<FormatConverterBox> mInputConverter;
56     std::unique_ptr<FormatConverterBox> mOutputConverter;
57 
58 };
59 
60 
61 #endif //OBOETESTER_FULL_DUPLEX_STREAM_WITH_CONVERSION_H
62