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