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