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