blob: ff0d751112e7f9d445668ea6bf4e560913103378 [file] [log] [blame]
Andy Hungd65869f2023-06-27 17:05:02 -07001/*
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 Hung70a62f22023-07-18 17:32:15 -070019#include <afutils/AllocatorFactory.h>
Andy Hung2ac52f12023-08-28 18:36:53 -070020#include <audio_utils/mutex.h>
Andy Hung70a62f22023-07-18 17:32:15 -070021#include <android-base/macros.h> // DISALLOW_COPY_AND_ASSIGN
Andy Hung70a62f22023-07-18 17:32:15 -070022#include <utils/RefBase.h> // avoid transitive dependency
23
Andy Hung56126702023-07-14 11:00:08 -070024// TODO(b/291318727) Move to nested namespace
Andy Hungd65869f2023-06-27 17:05:02 -070025namespace android {
26
Andy Hungfa2f4f32023-07-17 12:40:43 -070027class IAfPlaybackThread;
28
29class IAfClientCallback : public virtual RefBase {
30public:
Andy Hung51c7a1e2023-08-30 18:19:00 -070031 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 Hungfa2f4f32023-07-17 12:40:43 -070037 virtual status_t moveAuxEffectToIo(
38 int effectId,
39 const sp<IAfPlaybackThread>& dstThread,
Andy Hung51c7a1e2023-08-30 18:19:00 -070040 sp<IAfPlaybackThread>* srcThread) EXCLUDES_AudioFlinger_Mutex = 0;
Andy Hungfa2f4f32023-07-17 12:40:43 -070041};
Andy Hungd65869f2023-06-27 17:05:02 -070042
43class Client : public RefBase {
44public:
Andy Hungfa2f4f32023-07-17 12:40:43 -070045 Client(const sp<IAfClientCallback>& audioFlinger, pid_t pid);
Andy Hungd65869f2023-06-27 17:05:02 -070046
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 Hungfa2f4f32023-07-17 12:40:43 -070052 const auto& afClientCallback() const { return mAfClientCallback; }
Andy Hungd65869f2023-06-27 17:05:02 -070053
54private:
55 DISALLOW_COPY_AND_ASSIGN(Client);
56
Andy Hungfa2f4f32023-07-17 12:40:43 -070057 const sp<IAfClientCallback> mAfClientCallback;
Andy Hungd65869f2023-06-27 17:05:02 -070058 const pid_t mPid;
59 AllocatorFactory::ClientAllocator mClientAllocator;
60};
61
62} // namespace android