drm_framework_common.h revision 27ed8ad2db653f6ac07dcf8bcc05e2409c8bb024
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
27namespace android {
28
29/**
30 * Error code for DRM Frameowrk
31 */
32enum {
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 */
48class DrmBuffer {
49public:
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 */
68class ActionDescription {
69public:
70    ActionDescription(int _outputType, int _configuration) :
71        outputType(_outputType),
72        configuration(_configuration) {
73    }
74
75public:
76    int outputType;   /* BLUETOOTH , HDMI*/
77    int configuration; /* RESOLUTION_720_480 , RECORDABLE etc.*/
78};
79
80/**
81 * Defines constants related to DRM types
82 */
83class DrmObjectType {
84private:
85    DrmObjectType();
86
87public:
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 */
109class Playback {
110private:
111    Playback();
112
113public:
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 */
135class Action {
136private:
137    Action();
138
139public:
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 */
177class RightsStatus {
178private:
179    RightsStatus();
180
181public:
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 */
203class DecryptApiType {
204private:
205    DecryptApiType();
206
207public:
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;
220};
221
222/**
223 * Defines decryption information
224 */
225class DecryptInfo {
226public:
227    /**
228     * size of memory to be allocated to get the decrypted content.
229     */
230    int decryptBufferLength;
231    /**
232     * reserved for future purpose
233     */
234};
235
236/**
237 * Defines decryption handle
238 */
239class DecryptHandle {
240public:
241    /**
242     * Decryption session Handle
243     */
244    int decryptId;
245    /**
246     * Mimetype of the content to be used to select the media extractor
247     * For e.g., "video/mpeg" or "audio/mp3"
248     */
249    String8 mimeType;
250    /**
251     * Defines which decryption pattern should be used to decrypt the given content
252     * DrmFramework provides two different set of decryption APIs.
253     *   1. Decrypt APIs for elementary stream based DRM
254     *      (file format is not encrypted but ES is encrypted)
255     *         e.g., Marlin DRM (MP4 file format), WM-DRM (asf file format)
256     *
257     *         DecryptAPI::TYPE_ELEMENTARY_STREAM_BASED
258     *             Decryption API set for ES based DRM
259     *                 initializeDecryptUnit(), decrypt(), and finalizeDecryptUnit()
260     *   2. Decrypt APIs for container based DRM (file format itself is encrypted)
261     *         e.g., OMA DRM (dcf file format)
262     *
263     *         DecryptAPI::TYPE_CONTAINER_BASED
264     *             POSIX based Decryption API set for container based DRM
265     *                 pread()
266     */
267    int decryptApiType;
268    /**
269     * Defines the status of the rights like
270     *     RIGHTS_VALID, RIGHTS_INVALID, RIGHTS_EXPIRED or RIGHTS_NOT_ACQUIRED
271     */
272    int status;
273    /**
274     * Information required to decrypt content
275     * e.g. size of memory to be allocated to get the decrypted content.
276     */
277    DecryptInfo* decryptInfo;
278
279public:
280    DecryptHandle():
281            decryptId(INVALID_VALUE),
282            mimeType(""),
283            decryptApiType(INVALID_VALUE),
284            status(INVALID_VALUE) {
285
286    }
287
288    bool operator<(const DecryptHandle& handle) const {
289        return (decryptId < handle.decryptId);
290    }
291
292    bool operator==(const DecryptHandle& handle) const {
293        return (decryptId == handle.decryptId);
294    }
295};
296
297};
298
299#endif /* __DRM_FRAMEWORK_COMMON_H__ */
300
301