blob: 251a7f2b11aa72f6896a1e674576795443e9e6c3 [file] [log] [blame]
Phil Burk87c9f642017-05-17 07:22:39 -07001/*
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
25using android::sp;
Phil Burk87c9f642017-05-17 07:22:39 -070026
27namespace aaudio {
28
29class AudioStreamInternalCapture : public AudioStreamInternal {
30public:
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
43 aaudio_direction_t getDirection() const override {
44 return AAUDIO_DIRECTION_INPUT;
45 }
46protected:
47
Phil Burkec8ca522020-05-19 10:05:58 -070048 void advanceClientToMatchServerPosition(int32_t serverOffset = 0) override;
Phil Burkbcc36742017-08-31 17:24:51 -070049
Phil Burk87c9f642017-05-17 07:22:39 -070050/**
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
62private:
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);
Phil Burk87c9f642017-05-17 07:22:39 -070070};
71
72} /* namespace aaudio */
73
74#endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_CAPTURE_H