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 AudioStreamInternalCapture(AAudioServiceInterface &serviceInterface, bool inService = false); 32 virtual ~AudioStreamInternalCapture(); 33 34 aaudio_result_t read(void *buffer, 35 int32_t numFrames, 36 int64_t timeoutNanoseconds) override; 37 38 int64_t getFramesRead() override; 39 int64_t getFramesWritten() override; 40 41 void *callbackLoop() override; 42 getDirection()43 aaudio_direction_t getDirection() const override { 44 return AAUDIO_DIRECTION_INPUT; 45 } 46 protected: 47 48 void advanceClientToMatchServerPosition(int32_t serverOffset = 0) override; 49 50 /** 51 * Low level data processing that will not block. It will just read or write as much as it can. 52 * 53 * It passes back a recommended time to wake up if wakeTimePtr is not NULL. 54 * 55 * @return the number of frames processed or a negative error code. 56 */ 57 aaudio_result_t processDataNow(void *buffer, 58 int32_t numFrames, 59 int64_t currentTimeNanos, 60 int64_t *wakeTimePtr) override; 61 62 private: 63 /* 64 * Asynchronous read with data conversion. 65 * @param buffer 66 * @param numFrames 67 * @return frames written or negative error 68 */ 69 aaudio_result_t readNowWithConversion(void *buffer, int32_t numFrames); 70 }; 71 72 } /* namespace aaudio */ 73 74 #endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_CAPTURE_H 75