Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | #pragma once |
| 18 | |
Andy Hung | 70a62f2 | 2023-07-18 17:32:15 -0700 | [diff] [blame] | 19 | #include <afutils/AllocatorFactory.h> |
Andy Hung | 2ac52f1 | 2023-08-28 18:36:53 -0700 | [diff] [blame] | 20 | #include <audio_utils/mutex.h> |
Andy Hung | 70a62f2 | 2023-07-18 17:32:15 -0700 | [diff] [blame] | 21 | #include <android-base/macros.h> // DISALLOW_COPY_AND_ASSIGN |
Andy Hung | 70a62f2 | 2023-07-18 17:32:15 -0700 | [diff] [blame] | 22 | #include <utils/RefBase.h> // avoid transitive dependency |
| 23 | |
Andy Hung | 5612670 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 24 | // TODO(b/291318727) Move to nested namespace |
Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 27 | class IAfPlaybackThread; |
| 28 | |
| 29 | class IAfClientCallback : public virtual RefBase { |
| 30 | public: |
Andy Hung | 51c7a1e | 2023-08-30 18:19:00 -0700 | [diff] [blame^] | 31 | virtual audio_utils::mutex& clientMutex() const |
| 32 | RETURN_CAPABILITY(audio_utils::AudioFlinger_ClientMutex) = 0; |
| 33 | virtual void removeClient_l(pid_t pid) REQUIRES(clientMutex()) = 0; |
| 34 | virtual void removeNotificationClient(pid_t pid) EXCLUDES_AudioFlinger_Mutex = 0; |
| 35 | |
| 36 | // used indirectly by clients. |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 37 | virtual status_t moveAuxEffectToIo( |
| 38 | int effectId, |
| 39 | const sp<IAfPlaybackThread>& dstThread, |
Andy Hung | 51c7a1e | 2023-08-30 18:19:00 -0700 | [diff] [blame^] | 40 | sp<IAfPlaybackThread>* srcThread) EXCLUDES_AudioFlinger_Mutex = 0; |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 41 | }; |
Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 42 | |
| 43 | class Client : public RefBase { |
| 44 | public: |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 45 | Client(const sp<IAfClientCallback>& audioFlinger, pid_t pid); |
Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 46 | |
| 47 | // TODO(b/289139675) make Client container. |
| 48 | // Client destructor must be called with AudioFlinger::mClientLock held |
| 49 | ~Client() override; |
| 50 | AllocatorFactory::ClientAllocator& allocator(); |
| 51 | pid_t pid() const { return mPid; } |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 52 | const auto& afClientCallback() const { return mAfClientCallback; } |
Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | DISALLOW_COPY_AND_ASSIGN(Client); |
| 56 | |
Andy Hung | fa2f4f3 | 2023-07-17 12:40:43 -0700 | [diff] [blame] | 57 | const sp<IAfClientCallback> mAfClientCallback; |
Andy Hung | d65869f | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 58 | const pid_t mPid; |
| 59 | AllocatorFactory::ClientAllocator mClientAllocator; |
| 60 | }; |
| 61 | |
| 62 | } // namespace android |