xref: /aosp_15_r20/cts/apps/CtsVerifier/jni/audio_loopback/WavFileCapture.h (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1 /*
2  * Copyright (C) 2024 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 __WAVFILECAPTURE_H__
18 #define __WAVFILECAPTURE_H__
19 
20 #include <string>
21 
22 class WaveFileWriter;
23 class WavCaptureOutputStream;
24 
25 class WavFileCapture {
26 public:
27     WavFileCapture();
28     ~WavFileCapture();
29 
30     void setCaptureFile(const char* wavFilePath);
31     void setWavSpec(int numChannels, int sampleRate);
32 
33     void startCapture();
34 
35      /*
36       * completeCapture() status codes.
37       * Note: These need to be kept in sync with the equivalent constants
38       * in WavFileCapture.java.
39       */
40     static const int CAPTURE_NOTDONE = 1;
41     static const int CAPTURE_SUCCESS = 0;
42     static const int CAPTURE_BADOPEN = -1;
43     static const int CAPTURE_BADWRITE = -2;
44     int completeCapture();
45     void abandonCaptureData();
46 
47     void captureData(void *audioData, int32_t numFrames);
48 
49 private:
50     std::string mWavCapturePath;
51 
52     int mNumChannels;
53     int mSampleRate;
54 
55     bool mCaptureActive;
56 
57     WaveFileWriter* mWavFileWriter;
58     WavCaptureOutputStream*  mOutputStream;
59 };
60 
61 #endif // __WAVFILECAPTURE_H__
62 
63