Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H |
| 18 | #define ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <aaudio/AAudio.h> |
| 22 | |
| 23 | #include "binding/AAudioServiceInterface.h" |
| 24 | #include "client/AudioStreamInternal.h" |
| 25 | |
| 26 | using android::sp; |
| 27 | using android::IAAudioService; |
| 28 | |
| 29 | namespace aaudio { |
| 30 | |
| 31 | class AudioStreamInternalPlay : public AudioStreamInternal { |
| 32 | public: |
| 33 | AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, bool inService = false); |
| 34 | virtual ~AudioStreamInternalPlay(); |
| 35 | |
Phil Burk | b336e89 | 2017-07-05 15:35:43 -0700 | [diff] [blame^] | 36 | aaudio_result_t requestPause() override; |
| 37 | |
| 38 | aaudio_result_t requestFlush() override; |
| 39 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 40 | aaudio_result_t write(const void *buffer, |
| 41 | int32_t numFrames, |
| 42 | int64_t timeoutNanoseconds) override; |
| 43 | |
| 44 | int64_t getFramesRead() override; |
| 45 | int64_t getFramesWritten() override; |
| 46 | |
| 47 | void *callbackLoop() override; |
| 48 | |
| 49 | aaudio_direction_t getDirection() const override { |
| 50 | return AAUDIO_DIRECTION_OUTPUT; |
| 51 | } |
| 52 | |
| 53 | protected: |
Phil Burk | b336e89 | 2017-07-05 15:35:43 -0700 | [diff] [blame^] | 54 | |
| 55 | aaudio_result_t requestPauseInternal(); |
| 56 | |
| 57 | void onFlushFromServer() override; |
| 58 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Low level write that will not block. It will just write as much as it can. |
| 61 | * |
| 62 | * It passed back a recommended time to wake up if wakeTimePtr is not NULL. |
| 63 | * |
| 64 | * @return the number of frames written or a negative error code. |
| 65 | */ |
| 66 | aaudio_result_t processDataNow(void *buffer, |
| 67 | int32_t numFrames, |
| 68 | int64_t currentTimeNanos, |
| 69 | int64_t *wakeTimePtr) override; |
| 70 | private: |
| 71 | /* |
| 72 | * Asynchronous write with data conversion. |
| 73 | * @param buffer |
| 74 | * @param numFrames |
| 75 | * @return fdrames written or negative error |
| 76 | */ |
| 77 | aaudio_result_t writeNowWithConversion(const void *buffer, |
| 78 | int32_t numFrames); |
| 79 | |
| 80 | int64_t mLastFramesRead = 0; // used to prevent retrograde motion |
| 81 | }; |
| 82 | |
| 83 | } /* namespace aaudio */ |
| 84 | |
| 85 | #endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H |