• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/RefBase.h>
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 {
34     // The following constant values should be in sync with
35     // media/stagefright/MediaErrors.h
36     ERROR_BASE = -2000,
37 
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,
45     DRM_ERROR_TAMPER_DETECTED               = ERROR_BASE - 7,
46     DRM_ERROR_NO_PERMISSION                 = ERROR_BASE - 8,
47 
48     DRM_NO_ERROR                            = NO_ERROR
49 };
50 
51 /**
52  * copy control settings used in DecryptHandle::copyControlVector
53  */
54 enum 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 /**
63  * Defines DRM Buffer
64  */
65 class DrmBuffer {
66 public:
67     char* data;
68     int length;
69 
DrmBuffer()70     DrmBuffer() :
71         data(NULL),
72         length(0) {
73     }
74 
DrmBuffer(char * dataBytes,int dataLength)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  */
85 class ActionDescription {
86 public:
ActionDescription(int _outputType,int _configuration)87     ActionDescription(int _outputType, int _configuration) :
88         outputType(_outputType),
89         configuration(_configuration) {
90     }
91 
92 public:
93     int outputType;   /* BLUETOOTH , HDMI*/
94     int configuration; /* RESOLUTION_720_480 , RECORDABLE etc.*/
95 };
96 
97 /**
98  * Defines constants related to DRM types
99  */
100 class DrmObjectType {
101 private:
102     DrmObjectType();
103 
104 public:
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  */
126 class Playback {
127 private:
128     Playback();
129 
130 public:
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  */
152 class Action {
153 private:
154     Action();
155 
156 public:
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  */
194 class RightsStatus {
195 private:
196     RightsStatus();
197 
198 public:
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  */
220 class DecryptApiType {
221 private:
222     DecryptApiType();
223 
224 public:
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;
237 };
238 
239 /**
240  * Defines decryption information
241  */
242 class DecryptInfo {
243 public:
244     /**
245      * size of memory to be allocated to get the decrypted content.
246      */
247     int decryptBufferLength;
248     /**
249      * reserved for future purpose
250      */
251 };
252 
253 /**
254  * Defines decryption handle
255  */
256 class DecryptHandle : public RefBase {
257 public:
258     /**
259      * Decryption session Handle
260      */
261     int decryptId;
262     /**
263      * Mimetype of the content to be used to select the media extractor
264      * For e.g., "video/mpeg" or "audio/mp3"
265      */
266     String8 mimeType;
267     /**
268      * Defines which decryption pattern should be used to decrypt the given content
269      * DrmFramework provides two different set of decryption APIs.
270      *   1. Decrypt APIs for elementary stream based DRM
271      *      (file format is not encrypted but ES is encrypted)
272      *         e.g., Marlin DRM (MP4 file format), WM-DRM (asf file format)
273      *
274      *         DecryptApiType::ELEMENTARY_STREAM_BASED
275      *             Decryption API set for ES based DRM
276      *                 initializeDecryptUnit(), decrypt(), and finalizeDecryptUnit()
277      *   2. Decrypt APIs for container based DRM (file format itself is encrypted)
278      *         e.g., OMA DRM (dcf file format)
279      *
280      *         DecryptApiType::CONTAINER_BASED
281      *             POSIX based Decryption API set for container based DRM
282      *                 pread()
283      */
284     int decryptApiType;
285     /**
286      * Defines the status of the rights like
287      *     RIGHTS_VALID, RIGHTS_INVALID, RIGHTS_EXPIRED or RIGHTS_NOT_ACQUIRED
288      */
289     int status;
290     /**
291      * Information required to decrypt content
292      * e.g. size of memory to be allocated to get the decrypted content.
293      */
294     DecryptInfo* decryptInfo;
295     /**
296      * Defines a vector for the copy control settings sent from the DRM plugin
297      * to the player
298      */
299     KeyedVector<DrmCopyControl, int> copyControlVector;
300 
301     /**
302      * Defines a vector for any extra data the DRM plugin wants to send
303      * to the native code
304      */
305     KeyedVector<String8, String8> extendedData;
306 
307 public:
DecryptHandle()308     DecryptHandle():
309             decryptId(INVALID_VALUE),
310             mimeType(""),
311             decryptApiType(INVALID_VALUE),
312             status(INVALID_VALUE),
313             decryptInfo(NULL) {
314 
315     }
316 
~DecryptHandle()317     ~DecryptHandle() {
318         delete decryptInfo; decryptInfo = NULL;
319     }
320 };
321 
322 };
323 
324 #endif /* __DRM_FRAMEWORK_COMMON_H__ */
325 
326