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