• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_CAPTURE_H
17 #define ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_CAPTURE_H
18 
19 #include <stdint.h>
20 #include <aaudio/AAudio.h>
21 
22 #include "binding/AAudioServiceInterface.h"
23 #include "client/AudioStreamInternal.h"
24 
25 using android::sp;
26 
27 namespace aaudio {
28 
29 class AudioStreamInternalCapture : public AudioStreamInternal {
30 public:
31     explicit AudioStreamInternalCapture(AAudioServiceInterface  &serviceInterface,
32                                         bool inService = false);
33     virtual ~AudioStreamInternalCapture() = default;
34 
35     aaudio_result_t open(const AudioStreamBuilder &builder) override;
36 
37     aaudio_result_t read(void *buffer,
38                          int32_t numFrames,
39                          int64_t timeoutNanoseconds) override;
40 
41     int64_t getFramesRead() override;
42     int64_t getFramesWritten() override;
43 
44     void *callbackLoop() override;
45 
getDirection()46     aaudio_direction_t getDirection() const override {
47         return AAUDIO_DIRECTION_INPUT;
48     }
49 protected:
50 
51     void advanceClientToMatchServerPosition(int32_t serverOffset) override;
52 
53 /**
54  * Low level data processing that will not block. It will just read or write as much as it can.
55  *
56  * It passes back a recommended time to wake up if wakeTimePtr is not NULL.
57  *
58  * @return the number of frames processed or a negative error code.
59  */
60     aaudio_result_t processDataNow(void *buffer,
61                                    int32_t numFrames,
62                                    int64_t currentTimeNanos,
63                                    int64_t *wakeTimePtr) override;
64 
65 private:
66     /*
67      * Asynchronous read with data conversion.
68      * @param buffer
69      * @param numFrames
70      * @return frames written or negative error
71      */
72     aaudio_result_t readNowWithConversion(void *buffer, int32_t numFrames);
73 };
74 
75 } /* namespace aaudio */
76 
77 #endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_CAPTURE_H
78