2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef AAUDIO_SERVICE_ENDPOINT_H
18 #define AAUDIO_SERVICE_ENDPOINT_H
25 #include "client/AudioStreamInternal.h"
26 #include "client/AudioStreamInternalPlay.h"
27 #include "core/AAudioStreamParameters.h"
28 #include "binding/AAudioServiceMessage.h"
29 #include "binding/AAudioStreamConfiguration.h"
31 #include "AAudioServiceStreamBase.h"
36 * AAudioServiceEndpoint is used by a subclass of AAudioServiceStreamBase
37 * to communicate with the underlying audio device or port.
39 class AAudioServiceEndpoint
40 : public virtual android::RefBase
41 , public AAudioStreamParameters {
44 virtual ~AAudioServiceEndpoint();
46 virtual std::string dump() const;
48 virtual aaudio_result_t open(const aaudio::AAudioStreamRequest &request) = 0;
50 virtual aaudio_result_t close() = 0;
52 virtual aaudio_result_t registerStream(android::sp<AAudioServiceStreamBase> stream);
54 virtual aaudio_result_t unregisterStream(android::sp<AAudioServiceStreamBase> stream);
56 virtual aaudio_result_t startStream(android::sp<AAudioServiceStreamBase> stream,
57 audio_port_handle_t *clientHandle) = 0;
59 virtual aaudio_result_t stopStream(android::sp<AAudioServiceStreamBase> stream,
60 audio_port_handle_t clientHandle) = 0;
62 virtual aaudio_result_t startClient(const android::AudioClient& client,
63 audio_port_handle_t *clientHandle) {
64 ALOGD("AAudioServiceEndpoint::startClient(%p, ...) AAUDIO_ERROR_UNAVAILABLE", &client);
65 return AAUDIO_ERROR_UNAVAILABLE;
68 virtual aaudio_result_t stopClient(audio_port_handle_t clientHandle) {
69 ALOGD("AAudioServiceEndpoint::stopClient(...) AAUDIO_ERROR_UNAVAILABLE");
70 return AAUDIO_ERROR_UNAVAILABLE;
74 * @param positionFrames
76 * @return AAUDIO_OK or AAUDIO_ERROR_UNAVAILABLE or other negative error
78 virtual aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) = 0;
80 virtual aaudio_result_t getTimestamp(int64_t *positionFrames, int64_t *timeNanos) = 0;
82 int32_t getFramesPerBurst() const {
83 return mFramesPerBurst;
86 int32_t getRequestedDeviceId() const { return mRequestedDeviceId; }
88 bool matches(const AAudioStreamConfiguration& configuration);
90 // This should only be called from the AAudioEndpointManager under a mutex.
91 int32_t getOpenCount() const {
95 // This should only be called from the AAudioEndpointManager under a mutex.
96 void setOpenCount(int32_t count) {
101 void disconnectRegisteredStreams();
103 mutable std::mutex mLockStreams;
104 std::vector<android::sp<AAudioServiceStreamBase>> mRegisteredStreams;
106 SimpleDoubleBuffer<Timestamp> mAtomicTimestamp;
108 android::AudioClient mMmapClient; // set in open, used in open and startStream
110 int32_t mFramesPerBurst = 0;
111 int32_t mOpenCount = 0;
112 int32_t mRequestedDeviceId = 0;
116 } /* namespace aaudio */
119 #endif //AAUDIO_SERVICE_ENDPOINT_H