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