blob: 3330ebc5d7135d9f43557477a488074961de61fb [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,
aimitakeshid074e302010-07-29 10:12:27 +090045
46 DRM_NO_ERROR = NO_ERROR
47};
48
49/**
Gloria Wang3bbeaac2011-03-20 10:25:16 -070050 * copy control settings used in DecryptHandle::copyControlVector
51 */
52enum 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/**
aimitakeshid074e302010-07-29 10:12:27 +090061 * Defines DRM Buffer
62 */
63class DrmBuffer {
64public:
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 */
83class ActionDescription {
84public:
85 ActionDescription(int _outputType, int _configuration) :
86 outputType(_outputType),
87 configuration(_configuration) {
88 }
89
90public:
91 int outputType; /* BLUETOOTH , HDMI*/
92 int configuration; /* RESOLUTION_720_480 , RECORDABLE etc.*/
93};
94
95/**
96 * Defines constants related to DRM types
97 */
98class DrmObjectType {
99private:
100 DrmObjectType();
101
102public:
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 */
124class Playback {
125private:
126 Playback();
127
128public:
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 */
150class Action {
151private:
152 Action();
153
154public:
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 */
192class RightsStatus {
193private:
194 RightsStatus();
195
196public:
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 */
218class DecryptApiType {
219private:
220 DecryptApiType();
221
222public:
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 Wang6793a04d62010-10-29 16:44:37 -0700235 /**
236 * Decrypt API for Widevine streams
237 */
238 static const int WV_BASED = 0x3;
aimitakeshid074e302010-07-29 10:12:27 +0900239};
240
241/**
242 * Defines decryption information
243 */
244class DecryptInfo {
245public:
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 Wangae775272011-02-24 16:40:57 -0800258class DecryptHandle : public RefBase {
aimitakeshid074e302010-07-29 10:12:27 +0900259public:
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 Aimidc549d62010-09-20 23:40:41 +0900276 * DecryptApiType::ELEMENTARY_STREAM_BASED
aimitakeshid074e302010-07-29 10:12:27 +0900277 * 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 Aimidc549d62010-09-20 23:40:41 +0900282 * DecryptApiType::CONTAINER_BASED
aimitakeshid074e302010-07-29 10:12:27 +0900283 * 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 Wang3bbeaac2011-03-20 10:25:16 -0700297 /**
298 * Defines a vector for the copy control settings sent from the DRM plugin
299 * to the player
300 */
301 KeyedVector<DrmCopyControl, int> copyControlVector;
aimitakeshid074e302010-07-29 10:12:27 +0900302
Gloria Wangc4303942011-03-21 17:22:13 -0700303 /**
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
aimitakeshid074e302010-07-29 10:12:27 +0900309public:
310 DecryptHandle():
311 decryptId(INVALID_VALUE),
312 mimeType(""),
313 decryptApiType(INVALID_VALUE),
Gloria Wangae775272011-02-24 16:40:57 -0800314 status(INVALID_VALUE),
315 decryptInfo(NULL) {
aimitakeshid074e302010-07-29 10:12:27 +0900316
317 }
318
Gloria Wangae775272011-02-24 16:40:57 -0800319 ~DecryptHandle() {
320 delete decryptInfo; decryptInfo = NULL;
321 }
322
aimitakeshid074e302010-07-29 10:12:27 +0900323 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