aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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_FRAMEWORK_COMMON_H__ |
| 18 | #define __DRM_FRAMEWORK_COMMON_H__ |
| 19 | |
| 20 | #include <utils/Vector.h> |
| 21 | #include <utils/KeyedVector.h> |
Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 23 | #include <utils/String8.h> |
| 24 | #include <utils/Errors.h> |
| 25 | |
| 26 | #define INVALID_VALUE -1 |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | /** |
| 31 | * Error code for DRM Frameowrk |
| 32 | */ |
| 33 | enum { |
Gloria Wang | 7340743 | 2011-04-29 10:44:46 -0700 | [diff] [blame^] | 34 | // The following constant values should be in sync with |
| 35 | // media/stagefright/MediaErrors.h |
| 36 | ERROR_BASE = -2000, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 37 | |
Gloria Wang | 7340743 | 2011-04-29 10:44:46 -0700 | [diff] [blame^] | 38 | DRM_ERROR_UNKNOWN = ERROR_BASE, |
| 39 | DRM_ERROR_NO_LICENSE = ERROR_BASE - 1, |
| 40 | DRM_ERROR_LICENSE_EXPIRED = ERROR_BASE - 2, |
| 41 | DRM_ERROR_SESSION_NOT_OPENED = ERROR_BASE - 3, |
| 42 | DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED = ERROR_BASE - 4, |
| 43 | DRM_ERROR_DECRYPT = ERROR_BASE - 5, |
| 44 | DRM_ERROR_CANNOT_HANDLE = ERROR_BASE - 6, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 45 | |
| 46 | DRM_NO_ERROR = NO_ERROR |
| 47 | }; |
| 48 | |
| 49 | /** |
Gloria Wang | 1da9aa6 | 2011-03-20 10:25:16 -0700 | [diff] [blame] | 50 | * copy control settings used in DecryptHandle::copyControlVector |
| 51 | */ |
| 52 | enum DrmCopyControl { |
| 53 | DRM_COPY_CONTROL_BASE = 1000, |
| 54 | // the key used to set the value for HDCP |
| 55 | // if the associated value is 1, then HDCP is required |
| 56 | // otherwise, HDCP is not required |
| 57 | DRM_COPY_CONTROL_HDCP = DRM_COPY_CONTROL_BASE |
| 58 | }; |
| 59 | |
| 60 | /** |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 61 | * Defines DRM Buffer |
| 62 | */ |
| 63 | class DrmBuffer { |
| 64 | public: |
| 65 | char* data; |
| 66 | int length; |
| 67 | |
| 68 | DrmBuffer() : |
| 69 | data(NULL), |
| 70 | length(0) { |
| 71 | } |
| 72 | |
| 73 | DrmBuffer(char* dataBytes, int dataLength) : |
| 74 | data(dataBytes), |
| 75 | length(dataLength) { |
| 76 | } |
| 77 | |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * Defines detailed description of the action |
| 82 | */ |
| 83 | class ActionDescription { |
| 84 | public: |
| 85 | ActionDescription(int _outputType, int _configuration) : |
| 86 | outputType(_outputType), |
| 87 | configuration(_configuration) { |
| 88 | } |
| 89 | |
| 90 | public: |
| 91 | int outputType; /* BLUETOOTH , HDMI*/ |
| 92 | int configuration; /* RESOLUTION_720_480 , RECORDABLE etc.*/ |
| 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * Defines constants related to DRM types |
| 97 | */ |
| 98 | class DrmObjectType { |
| 99 | private: |
| 100 | DrmObjectType(); |
| 101 | |
| 102 | public: |
| 103 | /** |
| 104 | * Field specifies the unknown type |
| 105 | */ |
| 106 | static const int UNKNOWN = 0x00; |
| 107 | /** |
| 108 | * Field specifies the protected content type |
| 109 | */ |
| 110 | static const int CONTENT = 0x01; |
| 111 | /** |
| 112 | * Field specifies the rights information |
| 113 | */ |
| 114 | static const int RIGHTS_OBJECT = 0x02; |
| 115 | /** |
| 116 | * Field specifies the trigger information |
| 117 | */ |
| 118 | static const int TRIGGER_OBJECT = 0x03; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * Defines constants related to play back |
| 123 | */ |
| 124 | class Playback { |
| 125 | private: |
| 126 | Playback(); |
| 127 | |
| 128 | public: |
| 129 | /** |
| 130 | * Constant field signifies playback start |
| 131 | */ |
| 132 | static const int START = 0x00; |
| 133 | /** |
| 134 | * Constant field signifies playback stop |
| 135 | */ |
| 136 | static const int STOP = 0x01; |
| 137 | /** |
| 138 | * Constant field signifies playback paused |
| 139 | */ |
| 140 | static const int PAUSE = 0x02; |
| 141 | /** |
| 142 | * Constant field signifies playback resumed |
| 143 | */ |
| 144 | static const int RESUME = 0x03; |
| 145 | }; |
| 146 | |
| 147 | /** |
| 148 | * Defines actions that can be performed on protected content |
| 149 | */ |
| 150 | class Action { |
| 151 | private: |
| 152 | Action(); |
| 153 | |
| 154 | public: |
| 155 | /** |
| 156 | * Constant field signifies that the default action |
| 157 | */ |
| 158 | static const int DEFAULT = 0x00; |
| 159 | /** |
| 160 | * Constant field signifies that the content can be played |
| 161 | */ |
| 162 | static const int PLAY = 0x01; |
| 163 | /** |
| 164 | * Constant field signifies that the content can be set as ring tone |
| 165 | */ |
| 166 | static const int RINGTONE = 0x02; |
| 167 | /** |
| 168 | * Constant field signifies that the content can be transfered |
| 169 | */ |
| 170 | static const int TRANSFER = 0x03; |
| 171 | /** |
| 172 | * Constant field signifies that the content can be set as output |
| 173 | */ |
| 174 | static const int OUTPUT = 0x04; |
| 175 | /** |
| 176 | * Constant field signifies that preview is allowed |
| 177 | */ |
| 178 | static const int PREVIEW = 0x05; |
| 179 | /** |
| 180 | * Constant field signifies that the content can be executed |
| 181 | */ |
| 182 | static const int EXECUTE = 0x06; |
| 183 | /** |
| 184 | * Constant field signifies that the content can displayed |
| 185 | */ |
| 186 | static const int DISPLAY = 0x07; |
| 187 | }; |
| 188 | |
| 189 | /** |
| 190 | * Defines constants related to status of the rights |
| 191 | */ |
| 192 | class RightsStatus { |
| 193 | private: |
| 194 | RightsStatus(); |
| 195 | |
| 196 | public: |
| 197 | /** |
| 198 | * Constant field signifies that the rights are valid |
| 199 | */ |
| 200 | static const int RIGHTS_VALID = 0x00; |
| 201 | /** |
| 202 | * Constant field signifies that the rights are invalid |
| 203 | */ |
| 204 | static const int RIGHTS_INVALID = 0x01; |
| 205 | /** |
| 206 | * Constant field signifies that the rights are expired for the content |
| 207 | */ |
| 208 | static const int RIGHTS_EXPIRED = 0x02; |
| 209 | /** |
| 210 | * Constant field signifies that the rights are not acquired for the content |
| 211 | */ |
| 212 | static const int RIGHTS_NOT_ACQUIRED = 0x03; |
| 213 | }; |
| 214 | |
| 215 | /** |
| 216 | * Defines API set for decryption |
| 217 | */ |
| 218 | class DecryptApiType { |
| 219 | private: |
| 220 | DecryptApiType(); |
| 221 | |
| 222 | public: |
| 223 | /** |
| 224 | * Decrypt API set for non encrypted content |
| 225 | */ |
| 226 | static const int NON_ENCRYPTED = 0x00; |
| 227 | /** |
| 228 | * Decrypt API set for ES based DRM |
| 229 | */ |
| 230 | static const int ELEMENTARY_STREAM_BASED = 0x01; |
| 231 | /** |
| 232 | * POSIX based Decrypt API set for container based DRM |
| 233 | */ |
| 234 | static const int CONTAINER_BASED = 0x02; |
Gloria Wang | 6dc55e7 | 2010-10-29 16:44:37 -0700 | [diff] [blame] | 235 | /** |
| 236 | * Decrypt API for Widevine streams |
| 237 | */ |
| 238 | static const int WV_BASED = 0x3; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | /** |
| 242 | * Defines decryption information |
| 243 | */ |
| 244 | class DecryptInfo { |
| 245 | public: |
| 246 | /** |
| 247 | * size of memory to be allocated to get the decrypted content. |
| 248 | */ |
| 249 | int decryptBufferLength; |
| 250 | /** |
| 251 | * reserved for future purpose |
| 252 | */ |
| 253 | }; |
| 254 | |
| 255 | /** |
| 256 | * Defines decryption handle |
| 257 | */ |
Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 258 | class DecryptHandle : public RefBase { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 259 | public: |
| 260 | /** |
| 261 | * Decryption session Handle |
| 262 | */ |
| 263 | int decryptId; |
| 264 | /** |
| 265 | * Mimetype of the content to be used to select the media extractor |
| 266 | * For e.g., "video/mpeg" or "audio/mp3" |
| 267 | */ |
| 268 | String8 mimeType; |
| 269 | /** |
| 270 | * Defines which decryption pattern should be used to decrypt the given content |
| 271 | * DrmFramework provides two different set of decryption APIs. |
| 272 | * 1. Decrypt APIs for elementary stream based DRM |
| 273 | * (file format is not encrypted but ES is encrypted) |
| 274 | * e.g., Marlin DRM (MP4 file format), WM-DRM (asf file format) |
| 275 | * |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 276 | * DecryptApiType::ELEMENTARY_STREAM_BASED |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 277 | * Decryption API set for ES based DRM |
| 278 | * initializeDecryptUnit(), decrypt(), and finalizeDecryptUnit() |
| 279 | * 2. Decrypt APIs for container based DRM (file format itself is encrypted) |
| 280 | * e.g., OMA DRM (dcf file format) |
| 281 | * |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 282 | * DecryptApiType::CONTAINER_BASED |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 283 | * POSIX based Decryption API set for container based DRM |
| 284 | * pread() |
| 285 | */ |
| 286 | int decryptApiType; |
| 287 | /** |
| 288 | * Defines the status of the rights like |
| 289 | * RIGHTS_VALID, RIGHTS_INVALID, RIGHTS_EXPIRED or RIGHTS_NOT_ACQUIRED |
| 290 | */ |
| 291 | int status; |
| 292 | /** |
| 293 | * Information required to decrypt content |
| 294 | * e.g. size of memory to be allocated to get the decrypted content. |
| 295 | */ |
| 296 | DecryptInfo* decryptInfo; |
Gloria Wang | 1da9aa6 | 2011-03-20 10:25:16 -0700 | [diff] [blame] | 297 | /** |
| 298 | * Defines a vector for the copy control settings sent from the DRM plugin |
| 299 | * to the player |
| 300 | */ |
| 301 | KeyedVector<DrmCopyControl, int> copyControlVector; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 302 | |
Gloria Wang | 6b2a35b | 2011-03-21 17:22:13 -0700 | [diff] [blame] | 303 | /** |
| 304 | * Defines a vector for any extra data the DRM plugin wants to send |
| 305 | * to the native code |
| 306 | */ |
| 307 | KeyedVector<String8, String8> extendedData; |
| 308 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 309 | public: |
| 310 | DecryptHandle(): |
| 311 | decryptId(INVALID_VALUE), |
| 312 | mimeType(""), |
| 313 | decryptApiType(INVALID_VALUE), |
Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 314 | status(INVALID_VALUE), |
| 315 | decryptInfo(NULL) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 316 | |
| 317 | } |
| 318 | |
Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 319 | ~DecryptHandle() { |
| 320 | delete decryptInfo; decryptInfo = NULL; |
| 321 | } |
| 322 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 323 | bool operator<(const DecryptHandle& handle) const { |
| 324 | return (decryptId < handle.decryptId); |
| 325 | } |
| 326 | |
| 327 | bool operator==(const DecryptHandle& handle) const { |
| 328 | return (decryptId == handle.decryptId); |
| 329 | } |
| 330 | }; |
| 331 | |
| 332 | }; |
| 333 | |
| 334 | #endif /* __DRM_FRAMEWORK_COMMON_H__ */ |
| 335 | |