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