blob: cab29428659a21e05a7b263aed30c78dcdceb33f [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;
28using android::IAAudioService;
29
30namespace aaudio {
31
32class AudioStreamInternalPlay : public AudioStreamInternal {
33public:
34 AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, bool inService = false);
35 virtual ~AudioStreamInternalPlay();
36
Phil Burk02fec702018-02-16 18:25:55 -080037 aaudio_result_t open(const AudioStreamBuilder &builder) override;
38
Phil Burkb336e892017-07-05 15:35:43 -070039 aaudio_result_t requestPause() override;
40
41 aaudio_result_t requestFlush() override;
42
Phil Burk5cc83c32017-11-28 15:43:18 -080043 bool isFlushSupported() const override {
44 // Only implement FLUSH for OUTPUT streams.
45 return true;
46 }
47
48 bool isPauseSupported() const override {
49 // Only implement PAUSE for OUTPUT streams.
50 return true;
51 }
52
Phil Burk87c9f642017-05-17 07:22:39 -070053 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
62 aaudio_direction_t getDirection() const override {
63 return AAUDIO_DIRECTION_OUTPUT;
64 }
65
66protected:
Phil Burkb336e892017-07-05 15:35:43 -070067
Phil Burkbcc36742017-08-31 17:24:51 -070068 void advanceClientToMatchServerPosition() override;
69
Phil Burkb336e892017-07-05 15:35:43 -070070 void onFlushFromServer() override;
71
Phil Burk965650e2017-09-07 21:00:09 -070072 android::status_t doSetVolume() override;
73
Phil Burk87c9f642017-05-17 07:22:39 -070074/**
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;
85private:
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
Phil Burk965650e2017-09-07 21:00:09 -070096
Phil Burk0127c1b2018-03-29 13:48:06 -070097 AAudioFlowGraph mFlowGraph;
Phil Burk965650e2017-09-07 21:00:09 -070098
Phil Burk87c9f642017-05-17 07:22:39 -070099};
100
101} /* namespace aaudio */
102
103#endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H