• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <afutils/AllocatorFactory.h>
20 #include <audio_utils/mutex.h>
21 #include <android-base/macros.h>  // DISALLOW_COPY_AND_ASSIGN
22 #include <utils/RefBase.h>        // avoid transitive dependency
23 
24 // TODO(b/291318727) Move to nested namespace
25 namespace android {
26 
27 class IAfPlaybackThread;
28 
29 class IAfClientCallback : public virtual RefBase {
30 public:
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.
37     virtual status_t moveAuxEffectToIo(
38             int effectId,
39             const sp<IAfPlaybackThread>& dstThread,
40             sp<IAfPlaybackThread>* srcThread) EXCLUDES_AudioFlinger_Mutex = 0;
41 };
42 
43 class Client : public RefBase {
44 public:
45     Client(const sp<IAfClientCallback>& audioFlinger, pid_t pid);
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();
pid()51     pid_t pid() const { return mPid; }
afClientCallback()52     const auto& afClientCallback() const { return mAfClientCallback; }
53 
54 private:
55     DISALLOW_COPY_AND_ASSIGN(Client);
56 
57     const sp<IAfClientCallback> mAfClientCallback;
58     const pid_t mPid;
59     AllocatorFactory::ClientAllocator mClientAllocator;
60 };
61 
62 } // namespace android
63