blob: 04e4a6234fea3ee70b8d4848ad59566dc10a5003 [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"
24#include "client/AudioStreamInternal.h"
25
26using android::sp;
27using android::IAAudioService;
28
29namespace aaudio {
30
31class AudioStreamInternalPlay : public AudioStreamInternal {
32public:
33 AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, bool inService = false);
34 virtual ~AudioStreamInternalPlay();
35
Phil Burkb336e892017-07-05 15:35:43 -070036 aaudio_result_t requestPause() override;
37
38 aaudio_result_t requestFlush() override;
39
Phil Burk5cc83c32017-11-28 15:43:18 -080040 bool isFlushSupported() const override {
41 // Only implement FLUSH for OUTPUT streams.
42 return true;
43 }
44
45 bool isPauseSupported() const override {
46 // Only implement PAUSE for OUTPUT streams.
47 return true;
48 }
49
Phil Burk87c9f642017-05-17 07:22:39 -070050 aaudio_result_t write(const void *buffer,
51 int32_t numFrames,
52 int64_t timeoutNanoseconds) override;
53
54 int64_t getFramesRead() override;
55 int64_t getFramesWritten() override;
56
57 void *callbackLoop() override;
58
59 aaudio_direction_t getDirection() const override {
60 return AAUDIO_DIRECTION_OUTPUT;
61 }
62
63protected:
Phil Burkb336e892017-07-05 15:35:43 -070064
Phil Burkbcc36742017-08-31 17:24:51 -070065 void advanceClientToMatchServerPosition() override;
66
Phil Burkb336e892017-07-05 15:35:43 -070067 void onFlushFromServer() override;
68
Phil Burk965650e2017-09-07 21:00:09 -070069 android::status_t doSetVolume() override;
70
Phil Burk87c9f642017-05-17 07:22:39 -070071/**
72 * Low level write that will not block. It will just write as much as it can.
73 *
74 * It passed back a recommended time to wake up if wakeTimePtr is not NULL.
75 *
76 * @return the number of frames written or a negative error code.
77 */
78 aaudio_result_t processDataNow(void *buffer,
79 int32_t numFrames,
80 int64_t currentTimeNanos,
81 int64_t *wakeTimePtr) override;
82private:
83 /*
84 * Asynchronous write with data conversion.
85 * @param buffer
86 * @param numFrames
87 * @return fdrames written or negative error
88 */
89 aaudio_result_t writeNowWithConversion(const void *buffer,
90 int32_t numFrames);
91
92 int64_t mLastFramesRead = 0; // used to prevent retrograde motion
Phil Burk965650e2017-09-07 21:00:09 -070093
94 LinearRamp mVolumeRamp;
95
Phil Burk87c9f642017-05-17 07:22:39 -070096};
97
98} /* namespace aaudio */
99
100#endif //ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_PLAY_H