Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 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 AAUDIO_SERVICE_ENDPOINT_H |
| 18 | #define AAUDIO_SERVICE_ENDPOINT_H |
| 19 | |
| 20 | #include <atomic> |
| 21 | #include <functional> |
| 22 | #include <mutex> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "client/AudioStreamInternal.h" |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 26 | #include "client/AudioStreamInternalPlay.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 27 | #include "binding/AAudioServiceMessage.h" |
| 28 | #include "AAudioServiceStreamShared.h" |
| 29 | #include "AAudioServiceStreamMMAP.h" |
| 30 | #include "AAudioMixer.h" |
| 31 | #include "AAudioService.h" |
| 32 | |
| 33 | namespace aaudio { |
| 34 | |
| 35 | class AAudioServiceEndpoint { |
| 36 | public: |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 37 | virtual ~AAudioServiceEndpoint() = default; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 38 | |
Eric Laurent | a17ae74 | 2017-06-29 15:43:55 -0700 | [diff] [blame^] | 39 | virtual aaudio_result_t open(const AAudioStreamConfiguration& configuration); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 40 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 41 | int32_t getSampleRate() const { return mStreamInternal->getSampleRate(); } |
| 42 | int32_t getSamplesPerFrame() const { return mStreamInternal->getSamplesPerFrame(); } |
| 43 | int32_t getFramesPerBurst() const { return mStreamInternal->getFramesPerBurst(); } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 44 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 45 | aaudio_result_t registerStream(android::sp<AAudioServiceStreamShared> sharedStream); |
| 46 | aaudio_result_t unregisterStream(android::sp<AAudioServiceStreamShared> sharedStream); |
| 47 | aaudio_result_t startStream(android::sp<AAudioServiceStreamShared> sharedStream); |
| 48 | aaudio_result_t stopStream(android::sp<AAudioServiceStreamShared> sharedStream); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 49 | aaudio_result_t close(); |
| 50 | |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 51 | int32_t getRequestedDeviceId() const { return mRequestedDeviceId; } |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 52 | int32_t getDeviceId() const { return mStreamInternal->getDeviceId(); } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 53 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 54 | aaudio_direction_t getDirection() const { return mStreamInternal->getDirection(); } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 55 | |
| 56 | void disconnectRegisteredStreams(); |
| 57 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 58 | virtual void *callbackLoop() = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 59 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 60 | // This should only be called from the AAudioEndpointManager under a mutex. |
| 61 | int32_t getReferenceCount() const { |
| 62 | return mReferenceCount; |
| 63 | } |
| 64 | |
| 65 | // This should only be called from the AAudioEndpointManager under a mutex. |
| 66 | void setReferenceCount(int32_t count) { |
| 67 | mReferenceCount = count; |
| 68 | } |
| 69 | |
Eric Laurent | a17ae74 | 2017-06-29 15:43:55 -0700 | [diff] [blame^] | 70 | bool matches(const AAudioStreamConfiguration& configuration); |
| 71 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 72 | virtual AudioStreamInternal *getStreamInternal() = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 73 | |
| 74 | std::atomic<bool> mCallbackEnabled; |
| 75 | |
| 76 | std::mutex mLockStreams; |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 77 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 78 | std::vector<android::sp<AAudioServiceStreamShared>> mRegisteredStreams; |
| 79 | |
| 80 | std::vector<android::sp<AAudioServiceStreamShared>> mRunningStreams; |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 81 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 82 | private: |
| 83 | aaudio_result_t startSharingThread_l(); |
| 84 | aaudio_result_t stopSharingThread(); |
| 85 | |
| 86 | AudioStreamInternal *mStreamInternal = nullptr; |
| 87 | int32_t mReferenceCount = 0; |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 88 | int32_t mRequestedDeviceId = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } /* namespace aaudio */ |
| 92 | |
| 93 | |
| 94 | #endif //AAUDIO_SERVICE_ENDPOINT_H |