OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.media.MediaDrm; | 7 import android.media.MediaDrm; |
8 | 8 |
9 import org.chromium.base.Callback; | 9 import org.chromium.base.Callback; |
| 10 import org.chromium.media.MediaDrmStorageBridge.PersistentInfo; |
10 | 11 |
11 import java.nio.ByteBuffer; | 12 import java.nio.ByteBuffer; |
12 import java.util.ArrayList; | 13 import java.util.ArrayList; |
13 import java.util.Arrays; | 14 import java.util.Arrays; |
14 import java.util.HashMap; | 15 import java.util.HashMap; |
15 import java.util.List; | 16 import java.util.List; |
16 import java.util.UUID; | 17 import java.util.UUID; |
17 | 18 |
18 /** | 19 /** |
19 * The class manages relations among eme session ID, drm session ID and keyset | 20 * The class manages relations among eme session ID, drm session ID and keyset |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 // Private methods that are visible in this file only. | 153 // Private methods that are visible in this file only. |
153 | 154 |
154 private SessionId sessionId() { | 155 private SessionId sessionId() { |
155 return mSessionId; | 156 return mSessionId; |
156 } | 157 } |
157 | 158 |
158 private void setKeyType(int keyType) { | 159 private void setKeyType(int keyType) { |
159 mKeyType = keyType; | 160 mKeyType = keyType; |
160 } | 161 } |
| 162 |
| 163 private PersistentInfo toPersistentInfo() { |
| 164 assert mSessionId.keySetId() != null; |
| 165 |
| 166 return new PersistentInfo(mSessionId.emeId(), mSessionId.keySetId(),
mMimeType); |
| 167 } |
161 } | 168 } |
162 | 169 |
163 // Maps from DRM/EME session ID to SessionInfo. SessionInfo contains | 170 // Maps from DRM/EME session ID to SessionInfo. SessionInfo contains |
164 // SessionId, so that we can: | 171 // SessionId, so that we can: |
165 // 1. Get SessionInfo with EME/DRM session ID. | 172 // 1. Get SessionInfo with EME/DRM session ID. |
166 // 2. Get SessionId from EME/DRM session ID. | 173 // 2. Get SessionId from EME/DRM session ID. |
167 // 3. Get EME/DRM session ID from DRM/EME session ID. | 174 // 3. Get EME/DRM session ID from DRM/EME session ID. |
168 // SessionId always has a valid EME session ID, so all opened session should | 175 // SessionId always has a valid EME session ID, so all opened session should |
169 // have an entry in mEmeSessionInfoMap. | 176 // have an entry in mEmeSessionInfoMap. |
170 private HashMap<ByteBuffer, SessionInfo> mEmeSessionInfoMap; | 177 private HashMap<ByteBuffer, SessionInfo> mEmeSessionInfoMap; |
171 private HashMap<ByteBuffer, SessionInfo> mDrmSessionInfoMap; | 178 private HashMap<ByteBuffer, SessionInfo> mDrmSessionInfoMap; |
172 | 179 |
173 public MediaDrmSessionManager() { | 180 // The persistent storage to record map from EME session ID to key set ID |
| 181 // for persistent license. |
| 182 private MediaDrmStorageBridge mStorage; |
| 183 |
| 184 public MediaDrmSessionManager(MediaDrmStorageBridge storage) { |
174 mEmeSessionInfoMap = new HashMap<>(); | 185 mEmeSessionInfoMap = new HashMap<>(); |
175 mDrmSessionInfoMap = new HashMap<>(); | 186 mDrmSessionInfoMap = new HashMap<>(); |
| 187 |
| 188 mStorage = storage; |
176 } | 189 } |
177 | 190 |
178 /** | 191 /** |
179 * Set key set ID. It should only be called for persistent license session. | 192 * Set key set ID. It should only be called for persistent license session. |
180 */ | 193 */ |
181 void setKeySetId(SessionId sessionId, byte[] keySetId, Callback<Boolean> cal
lback) { | 194 void setKeySetId(SessionId sessionId, byte[] keySetId, Callback<Boolean> cal
lback) { |
182 assert get(sessionId) != null; | 195 assert get(sessionId) != null; |
183 assert get(sessionId).keyType() == MediaDrm.KEY_TYPE_OFFLINE; | 196 assert get(sessionId).keyType() == MediaDrm.KEY_TYPE_OFFLINE; |
184 assert sessionId.keySetId() == null; | 197 assert sessionId.keySetId() == null; |
185 | 198 |
186 sessionId.setKeySetId(keySetId); | 199 sessionId.setKeySetId(keySetId); |
187 | 200 |
188 // TODO(yucliu): Write updated key set ID to persistent storage. | 201 mStorage.saveInfo(get(sessionId).toPersistentInfo(), callback); |
189 callback.onResult(true); | |
190 } | 202 } |
191 | 203 |
192 /** | 204 /** |
193 * Remove session and related infomration from memory, but doesn't touch | 205 * Remove session and related infomration from memory, but doesn't touch |
194 * persistent storage. | 206 * persistent storage. |
195 */ | 207 */ |
196 void remove(SessionId sessionId) { | 208 void remove(SessionId sessionId) { |
197 SessionInfo info = get(sessionId); | 209 SessionInfo info = get(sessionId); |
198 | 210 |
199 assert info != null; | 211 assert info != null; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 251 |
240 private SessionId getSessionIdFromMap(HashMap<ByteBuffer, SessionInfo> map,
byte[] id) { | 252 private SessionId getSessionIdFromMap(HashMap<ByteBuffer, SessionInfo> map,
byte[] id) { |
241 SessionInfo info = map.get(ByteBuffer.wrap(id)); | 253 SessionInfo info = map.get(ByteBuffer.wrap(id)); |
242 if (info == null) { | 254 if (info == null) { |
243 return null; | 255 return null; |
244 } | 256 } |
245 | 257 |
246 return info.sessionId(); | 258 return info.sessionId(); |
247 } | 259 } |
248 } | 260 } |
OLD | NEW |