• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 using android::IAAudioService;
29 
30 namespace aaudio {
31 
32 class AudioStreamInternalPlay : public AudioStreamInternal {
33 public:
34     AudioStreamInternalPlay(AAudioServiceInterface  &serviceInterface, bool inService = false);
35     virtual ~AudioStreamInternalPlay();
36 
37     aaudio_result_t open(const AudioStreamBuilder &builder) override;
38 
39     aaudio_result_t requestPause() override;
40 
41     aaudio_result_t requestFlush() 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 advanceClientToMatchServerPosition() override;
69 
70     void onFlushFromServer() override;
71 
72     android::status_t doSetVolume() override;
73 
74 /**
75  * Low level write that will not block. It will just write as much as it can.
76  *
77  * It passed back a recommended time to wake up if wakeTimePtr is not NULL.
78  *
79  * @return the number of frames written or a negative error code.
80  */
81     aaudio_result_t processDataNow(void *buffer,
82                              int32_t numFrames,
83                              int64_t currentTimeNanos,
84                              int64_t *wakeTimePtr) override;
85 private:
86     /*
87      * Asynchronous write with data conversion.
88      * @param buffer
89      * @param numFrames
90      * @return fdrames written or negative error
91      */
92     aaudio_result_t writeNowWithConversion(const void *buffer,
93                                            int32_t numFrames);
94 
95     int64_t                  mLastFramesRead = 0; // used to prevent retrograde motion
96 
97     AAudioFlowGraph          mFlowGraph;
98 
99 };
100 
101 } /* namespace aaudio */
102 
103 #endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H
104