Ronghua Wu | 10305cc | 2015-02-22 07:55:32 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 27 | namespace android { |
| 28 | |
| 29 | class DrmSessionManagerTest; |
| 30 | struct DrmSessionClientInterface; |
| 31 | struct ProcessInfoInterface; |
| 32 | |
| 33 | bool isEqualSessionId(const Vector<uint8_t> &sessionId1, const Vector<uint8_t> &sessionId2); |
| 34 | |
| 35 | struct SessionInfo { |
| 36 | sp<DrmSessionClientInterface> drm; |
| 37 | Vector<uint8_t> sessionId; |
| 38 | int64_t timeStamp; |
| 39 | }; |
| 40 | |
| 41 | typedef Vector<SessionInfo > SessionInfos; |
| 42 | typedef KeyedVector<int, SessionInfos > PidSessionInfosMap; |
| 43 | |
| 44 | struct 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 | |
| 54 | protected: |
| 55 | virtual ~DrmSessionManager(); |
| 56 | |
| 57 | private: |
| 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_ |