blob: 7b1cddc284d3282bc0fcbb193e416414cff70a4a [file] [log] [blame]
Phil Burk87c9f642017-05-17 07:22:39 -07001/*
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"
Phil Burk0127c1b2018-03-29 13:48:06 -070024#include "client/AAudioFlowGraph.h"
Phil Burk87c9f642017-05-17 07:22:39 -070025#include "client/AudioStreamInternal.h"
26
27using android::sp;
Phil Burk87c9f642017-05-17 07:22:39 -070028
29namespace aaudio {
30
31class AudioStreamInternalPlay : public AudioStreamInternal {
32public:
33 AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, bool inService = false);
34 virtual ~AudioStreamInternalPlay();
35
Phil Burk02fec702018-02-16 18:25:55 -080036 aaudio_result_t open(const AudioStreamBuilder &builder) override;
37
Phil Burkb336e892017-07-05 15:35:43 -070038 aaudio_result_t requestPause() override;
39
40 aaudio_result_t requestFlush() override;
41
Phil Burk5cc83c32017-11-28 15:43:18 -080042 bool isFlushSupported() const override {
43 // Only implement FLUSH for OUTPUT streams.
44 return true;
45 }
46
47 bool isPauseSupported() const override {
48 // Only implement PAUSE for OUTPUT streams.
49 return true;
50 }
51
Phil Burk87c9f642017-05-17 07:22:39 -070052 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
61 aaudio_direction_t getDirection() const override {
62 return AAUDIO_DIRECTION_OUTPUT;
63 }
64
65protected:
Phil Burkb336e892017-07-05 15:35:43 -070066
Phil Burkec8ca522020-05-19 10:05:58 -070067 void prepareBuffersForStart() override;
68
69 void advanceClientToMatchServerPosition(int32_t serverMargin = 0) override;
Phil Burkbcc36742017-08-31 17:24:51 -070070
Phil Burkb336e892017-07-05 15:35:43 -070071 void onFlushFromServer() override;
72
Phil Burk965650e2017-09-07 21:00:09 -070073 android::status_t doSetVolume() override;
74
Phil Burk87c9f642017-05-17 07:22:39 -070075/**
76 * Low level write that will not block. It will just write as much as it can.
77 *
78 * It passed back a recommended time to wake up if wakeTimePtr is not NULL.
79 *
80 * @return the number of frames written or a negative error code.
81 */
82 aaudio_result_t processDataNow(void *buffer,
83 int32_t numFrames,
84 int64_t currentTimeNanos,
85 int64_t *wakeTimePtr) override;
86private:
87 /*
88 * Asynchronous write with data conversion.
89 * @param buffer
90 * @param numFrames
91 * @return fdrames written or negative error
92 */
93 aaudio_result_t writeNowWithConversion(const void *buffer,
94 int32_t numFrames);
95
Phil Burk0127c1b2018-03-29 13:48:06 -070096 AAudioFlowGraph mFlowGraph;
Phil Burk965650e2017-09-07 21:00:09 -070097
Phil Burk87c9f642017-05-17 07:22:39 -070098};
99
100} /* namespace aaudio */
101
102#endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H