Home | History | Annotate | Download | only in drm
      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 
     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  */
     85 class ActionDescription {
     86 public:
     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      * Decrypt API for Widevine streams
    239      */
    240     static const int WV_BASED = 0x3;
    241 };
    242 
    243 /**
    244  * Defines decryption information
    245  */
    246 class DecryptInfo {
    247 public:
    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  */
    260 class DecryptHandle : public RefBase {
    261 public:
    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      *
    278      *         DecryptApiType::ELEMENTARY_STREAM_BASED
    279      *             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      *
    284      *         DecryptApiType::CONTAINER_BASED
    285      *             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;
    299     /**
    300      * Defines a vector for the copy control settings sent from the DRM plugin
    301      * to the player
    302      */
    303     KeyedVector<DrmCopyControl, int> copyControlVector;
    304 
    305     /**
    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 
    311 public:
    312     DecryptHandle():
    313             decryptId(INVALID_VALUE),
    314             mimeType(""),
    315             decryptApiType(INVALID_VALUE),
    316             status(INVALID_VALUE),
    317             decryptInfo(NULL) {
    318 
    319     }
    320 
    321     ~DecryptHandle() {
    322         delete decryptInfo; decryptInfo = NULL;
    323     }
    324 
    325     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 
    338