Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 LEGACY_AUDIO_STREAM_LEGACY_H |
| 18 | #define LEGACY_AUDIO_STREAM_LEGACY_H |
| 19 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame^] | 20 | #include <media/AudioTimestamp.h> |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 21 | |
| 22 | #include <aaudio/AAudio.h> |
| 23 | |
| 24 | #include "AudioStream.h" |
| 25 | #include "AAudioLegacy.h" |
| 26 | #include "utility/FixedBlockAdapter.h" |
| 27 | |
| 28 | namespace aaudio { |
| 29 | |
| 30 | |
| 31 | typedef void (*aaudio_legacy_callback_t)(int event, void* user, void *info); |
| 32 | |
| 33 | enum { |
| 34 | /** |
| 35 | * Request that the callback function should fill the data buffer of an output stream, |
| 36 | * or process the data of an input stream. |
| 37 | * The address parameter passed to the callback function will point to a data buffer. |
| 38 | * For an input stream, the data is read-only. |
| 39 | * The value1 parameter will be the number of frames. |
| 40 | * The value2 parameter is reserved and will be set to zero. |
| 41 | * The callback should return AAUDIO_CALLBACK_RESULT_CONTINUE or AAUDIO_CALLBACK_RESULT_STOP. |
| 42 | */ |
| 43 | AAUDIO_CALLBACK_OPERATION_PROCESS_DATA, |
| 44 | |
| 45 | /** |
| 46 | * Inform the callback function that the stream was disconnected. |
| 47 | * The address parameter passed to the callback function will be NULL. |
| 48 | * The value1 will be an error code or AAUDIO_OK. |
| 49 | * The value2 parameter is reserved and will be set to zero. |
| 50 | * The callback return value will be ignored. |
| 51 | */ |
| 52 | AAUDIO_CALLBACK_OPERATION_DISCONNECTED, |
| 53 | }; |
| 54 | typedef int32_t aaudio_callback_operation_t; |
| 55 | |
| 56 | |
| 57 | class AudioStreamLegacy : public AudioStream, public FixedBlockProcessor { |
| 58 | public: |
| 59 | AudioStreamLegacy(); |
| 60 | |
| 61 | virtual ~AudioStreamLegacy(); |
| 62 | |
| 63 | aaudio_legacy_callback_t getLegacyCallback(); |
| 64 | |
| 65 | // This is public so it can be called from the C callback function. |
| 66 | // This is called from the AudioTrack/AudioRecord client. |
| 67 | virtual void processCallback(int event, void *info) = 0; |
| 68 | |
| 69 | void processCallbackCommon(aaudio_callback_operation_t opcode, void *info); |
| 70 | |
| 71 | // Implement FixedBlockProcessor |
| 72 | int32_t onProcessFixedBlock(uint8_t *buffer, int32_t numBytes) override; |
| 73 | |
Phil Burk | 4c5129b | 2017-04-28 15:17:32 -0700 | [diff] [blame] | 74 | virtual int64_t incrementClientFrameCounter(int32_t frames) = 0; |
| 75 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 76 | protected: |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame^] | 77 | |
| 78 | aaudio_result_t getBestTimestamp(clockid_t clockId, |
| 79 | int64_t *framePosition, |
| 80 | int64_t *timeNanoseconds, |
| 81 | android::ExtendedTimestamp *extendedTimestamp); |
| 82 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 83 | FixedBlockAdapter *mBlockAdapter = nullptr; |
| 84 | aaudio_wrapping_frames_t mPositionWhenStarting = 0; |
| 85 | int32_t mCallbackBufferSize = 0; |
| 86 | }; |
| 87 | |
| 88 | } /* namespace aaudio */ |
| 89 | |
| 90 | #endif //LEGACY_AUDIO_STREAM_LEGACY_H |