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