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/AAudioFlowGraph.h" 25 #include "client/AudioStreamInternal.h" 26 27 using android::sp; 28 29 namespace aaudio { 30 31 class AudioStreamInternalPlay : public AudioStreamInternal { 32 public: 33 explicit AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, 34 bool inService = false); 35 virtual ~AudioStreamInternalPlay() = default; 36 37 aaudio_result_t open(const AudioStreamBuilder &builder) override; 38 39 aaudio_result_t requestPause_l() override; 40 41 aaudio_result_t requestFlush_l() override; 42 isFlushSupported()43 bool isFlushSupported() const override { 44 // Only implement FLUSH for OUTPUT streams. 45 return true; 46 } 47 isPauseSupported()48 bool isPauseSupported() const override { 49 // Only implement PAUSE for OUTPUT streams. 50 return true; 51 } 52 53 aaudio_result_t write(const void *buffer, 54 int32_t numFrames, 55 int64_t timeoutNanoseconds) override; 56 57 int64_t getFramesRead() override; 58 int64_t getFramesWritten() override; 59 60 void *callbackLoop() override; 61 getDirection()62 aaudio_direction_t getDirection() const override { 63 return AAUDIO_DIRECTION_OUTPUT; 64 } 65 66 protected: 67 68 void prepareBuffersForStart() override; 69 70 void advanceClientToMatchServerPosition(int32_t serverMargin) override; 71 72 void onFlushFromServer() override; 73 74 android::status_t doSetVolume() override; 75 76 /** 77 * Low level write that will not block. It will just write as much as it can. 78 * 79 * It passed back a recommended time to wake up if wakeTimePtr is not NULL. 80 * 81 * @return the number of frames written or a negative error code. 82 */ 83 aaudio_result_t processDataNow(void *buffer, 84 int32_t numFrames, 85 int64_t currentTimeNanos, 86 int64_t *wakeTimePtr) override; 87 private: 88 /* 89 * Asynchronous write with data conversion. 90 * @param buffer 91 * @param numFrames 92 * @return fdrames written or negative error 93 */ 94 aaudio_result_t writeNowWithConversion(const void *buffer, 95 int32_t numFrames); 96 97 AAudioFlowGraph mFlowGraph; 98 99 }; 100 101 } /* namespace aaudio */ 102 103 #endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H 104