Home | History | Annotate | Download | only in cas
      1 /*
      2  * Copyright (C) 2017 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 CAS_API_H_
     18 #define CAS_API_H_
     19 
     20 #include <vector>
     21 #include <utils/String8.h>
     22 
     23 //  Loadable CasPlugin shared libraries should define the entry points
     24 //  as shown below:
     25 //
     26 //  extern "C" {
     27 //      extern android::CasFactory *createCasFactory();
     28 //      extern android::DescramblerFactory *createDescramblerFactory();
     29 //  }
     30 
     31 namespace android {
     32 
     33 struct CasPlugin;
     34 
     35 struct CasPluginDescriptor {
     36     int32_t CA_system_id;
     37     String8 name;
     38 };
     39 
     40 typedef std::vector<uint8_t> CasData;
     41 typedef std::vector<uint8_t> CasSessionId;
     42 typedef std::vector<uint8_t> CasEmm;
     43 typedef std::vector<uint8_t> CasEcm;
     44 typedef void (*CasPluginCallback)(
     45         void *appData,
     46         int32_t event,
     47         int32_t arg,
     48         uint8_t *data,
     49         size_t size);
     50 
     51 typedef void (*CasPluginCallbackExt)(
     52         void *appData,
     53         int32_t event,
     54         int32_t arg,
     55         uint8_t *data,
     56         size_t size,
     57         const CasSessionId *sessionId);
     58 
     59 struct CasFactory {
     60     CasFactory() {}
     61     virtual ~CasFactory() {}
     62 
     63     // Determine if the plugin can handle the CA scheme identified by CA_system_id.
     64     virtual bool isSystemIdSupported(
     65             int32_t CA_system_id) const = 0;
     66 
     67     // Get a list of the CA schemes supported by the plugin.
     68     virtual status_t queryPlugins(
     69             std::vector<CasPluginDescriptor> *descriptors) const = 0;
     70 
     71     // Construct a new instance of a CasPlugin given a CA_system_id
     72     virtual status_t createPlugin(
     73             int32_t CA_system_id,
     74             void *appData,
     75             CasPluginCallback callback,
     76             CasPlugin **plugin) = 0;
     77 
     78     // Construct a new extend instance of a CasPlugin given a CA_system_id
     79     virtual status_t createPlugin(
     80             int32_t CA_system_id,
     81             void *appData,
     82             CasPluginCallbackExt callback,
     83             CasPlugin **plugin) = 0;
     84 
     85 private:
     86     CasFactory(const CasFactory &);
     87     CasFactory &operator=(const CasFactory &); /* NOLINT */
     88 };
     89 
     90 struct CasPlugin {
     91     CasPlugin() {}
     92     virtual ~CasPlugin() {}
     93 
     94     // Provide the CA private data from a CA_descriptor in the conditional
     95     // access table to a CasPlugin.
     96     virtual status_t setPrivateData(
     97             const CasData &privateData) = 0;
     98 
     99     // Open a session for descrambling a program, or one or more elementary
    100     // streams.
    101     virtual status_t openSession(CasSessionId *sessionId) = 0;
    102 
    103     // Close a previously opened session.
    104     virtual status_t closeSession(const CasSessionId &sessionId) = 0;
    105 
    106     // Provide the CA private data from a CA_descriptor in the program map
    107     // table to a CasPlugin.
    108     virtual status_t setSessionPrivateData(
    109             const CasSessionId &sessionId,
    110             const CasData &privateData) = 0;
    111 
    112     // Process an ECM from the ECM stream for this sessions elementary stream.
    113     virtual status_t processEcm(
    114             const CasSessionId &sessionId,
    115             const CasEcm &ecm) = 0;
    116 
    117     // Process an in-band EMM from the EMM stream.
    118     virtual status_t processEmm(
    119             const CasEmm &emm) = 0;
    120 
    121     // Deliver an event to the CasPlugin. The format of the event is specific
    122     // to the CA scheme and is opaque to the framework.
    123     virtual status_t sendEvent(
    124             int32_t event,
    125             int32_t arg,
    126             const CasData &eventData) = 0;
    127 
    128     // Deliver an session event to the CasPlugin. The format of the event is
    129     // specific to the CA scheme and is opaque to the framework.
    130     virtual status_t sendSessionEvent(
    131             const CasSessionId &sessionId,
    132             int32_t event,
    133             int32_t arg,
    134             const CasData &eventData) = 0;
    135 
    136    // Native implementation of the MediaCas Java API provision method.
    137     virtual status_t provision(
    138             const String8 &provisionString) = 0;
    139 
    140     // Native implementation of the MediaCas Java API refreshEntitlements method
    141     virtual status_t refreshEntitlements(
    142             int32_t refreshType,
    143             const CasData &refreshData) = 0;
    144 
    145 private:
    146     CasPlugin(const CasPlugin &);
    147     CasPlugin &operator=(const CasPlugin &); /* NOLINT */
    148 };
    149 
    150 extern "C" {
    151     extern android::CasFactory *createCasFactory();
    152 }
    153 
    154 } // namespace android
    155 
    156 #endif // CAS_API_H_
    157