blob: e74c8bfc938f30488efa6320ff301030e8aa98f8 [file] [log] [blame]
Phil Burk11e8d332017-05-24 09:59:02 -07001/*
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 ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H
18#define ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H
19
20#include <map>
21#include <mutex>
22#include <set>
23
24#include <utils/Singleton.h>
25
26#include <aaudio/AAudio.h>
27#include "binding/IAAudioClient.h"
28#include "AAudioService.h"
29
30namespace aaudio {
31
32class AAudioClientTracker : public android::Singleton<AAudioClientTracker>{
33public:
34 AAudioClientTracker();
35 ~AAudioClientTracker() = default;
36
37 aaudio_result_t registerClient(pid_t pid, const android::sp<android::IAAudioClient>& client);
38
39 void unregisterClient(pid_t pid);
40
Phil Burk91692942017-06-30 12:23:05 -070041 int32_t getStreamCount(pid_t pid);
42
Phil Burk11e8d332017-05-24 09:59:02 -070043 aaudio_result_t registerClientStream(pid_t pid,
44 android::sp<AAudioServiceStreamBase> serviceStream);
45
46 aaudio_result_t unregisterClientStream(pid_t pid,
47 android::sp<AAudioServiceStreamBase> serviceStream);
48
49 android::AAudioService *getAAudioService() const {
50 return mAAudioService;
51 }
52
53 void setAAudioService(android::AAudioService *aaudioService) {
54 mAAudioService = aaudioService;
55 }
56
57private:
Phil Burk91692942017-06-30 12:23:05 -070058
59 /**
60 * One per process.
61 */
Phil Burk11e8d332017-05-24 09:59:02 -070062 class NotificationClient : public IBinder::DeathRecipient {
63 public:
64 NotificationClient(pid_t pid);
65 virtual ~NotificationClient();
66
Phil Burk91692942017-06-30 12:23:05 -070067 int32_t getStreamCount();
68
Phil Burk11e8d332017-05-24 09:59:02 -070069 aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
70
71 aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
72
73 // IBinder::DeathRecipient
74 virtual void binderDied(const android::wp<IBinder>& who);
75
76 protected:
77 std::mutex mLock;
78 const pid_t mProcessId;
79 std::set<android::sp<AAudioServiceStreamBase>> mStreams;
80 };
81
82 std::mutex mLock;
83 std::map<pid_t, android::sp<NotificationClient>> mNotificationClients;
84 android::AAudioService *mAAudioService = nullptr;
85};
86
87} /* namespace aaudio */
88
89#endif //ANDROID_AAUDIO_AAUDIO_CLIENT_TRACKER_H