blob: 1d0ed434daed496a5c673152dd4777cfa54d800e [file] [log] [blame]
Ronghua Wu10305cc2015-02-22 07:55:32 -08001/*
2 * Copyright (C) 2015 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 DRM_SESSION_MANAGER_H_
18
19#define DRM_SESSION_MANAGER_H_
20
21#include <media/stagefright/foundation/ABase.h>
22#include <utils/RefBase.h>
23#include <utils/KeyedVector.h>
24#include <utils/threads.h>
25#include <utils/Vector.h>
26
27namespace android {
28
29class DrmSessionManagerTest;
30struct DrmSessionClientInterface;
31struct ProcessInfoInterface;
32
33bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2);
34
35struct SessionInfo {
36 sp<DrmSessionClientInterface> drm;
37 Vector<uint8_t> sessionId;
38 int64_t timeStamp;
39};
40
41typedef Vector<SessionInfo > SessionInfos;
42typedef KeyedVector<int, SessionInfos > PidSessionInfosMap;
43
44struct DrmSessionManager : public RefBase {
45 DrmSessionManager();
46 DrmSessionManager(sp<ProcessInfoInterface> processInfo);
47
48 void addSession(int pid, sp<DrmSessionClientInterface> drm, const Vector<uint8_t>& sessionId);
49 void useSession(const Vector<uint8_t>& sessionId);
50 void removeSession(const Vector<uint8_t>& sessionId);
51 void removeDrm(sp<DrmSessionClientInterface> drm);
52 bool reclaimSession(int callingPid);
53
54protected:
55 virtual ~DrmSessionManager();
56
57private:
58 friend class DrmSessionManagerTest;
59
60 int64_t getTime_l();
61 bool getLowestPriority_l(int* lowestPriorityPid, int* lowestPriority);
62 bool getLeastUsedSession_l(
63 int pid, sp<DrmSessionClientInterface>* drm, Vector<uint8_t>* sessionId);
64
65 sp<ProcessInfoInterface> mProcessInfo;
66 mutable Mutex mLock;
67 PidSessionInfosMap mSessionMap;
68 int64_t mTime;
69
70 DISALLOW_EVIL_CONSTRUCTORS(DrmSessionManager);
71};
72
73} // namespace android
74
75#endif // DRM_SESSION_MANAGER_H_