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 typedef void (*CasPluginStatusCallback)( 60 void *appData, 61 int32_t event, 62 int32_t arg); 63 64 struct CasFactory { CasFactoryCasFactory65 CasFactory() {} ~CasFactoryCasFactory66 virtual ~CasFactory() {} 67 68 // Determine if the plugin can handle the CA scheme identified by CA_system_id. 69 virtual bool isSystemIdSupported( 70 int32_t CA_system_id) const = 0; 71 72 // Get a list of the CA schemes supported by the plugin. 73 virtual status_t queryPlugins( 74 std::vector<CasPluginDescriptor> *descriptors) const = 0; 75 76 // Construct a new instance of a CasPlugin given a CA_system_id 77 virtual status_t createPlugin( 78 int32_t CA_system_id, 79 void *appData, 80 CasPluginCallback callback, 81 CasPlugin **plugin) = 0; 82 83 // Construct a new extend instance of a CasPlugin given a CA_system_id 84 virtual status_t createPlugin( 85 int32_t CA_system_id, 86 void *appData, 87 CasPluginCallbackExt callback, 88 CasPlugin **plugin) = 0; 89 90 private: 91 CasFactory(const CasFactory &); 92 CasFactory &operator=(const CasFactory &); /* NOLINT */ 93 }; 94 95 struct CasPlugin { CasPluginCasPlugin96 CasPlugin() {} ~CasPluginCasPlugin97 virtual ~CasPlugin() {} 98 99 // Provide a callback to report plugin status 100 virtual status_t setStatusCallback( 101 CasPluginStatusCallback callback) = 0; 102 103 // Provide the CA private data from a CA_descriptor in the conditional 104 // access table to a CasPlugin. 105 virtual status_t setPrivateData( 106 const CasData &privateData) = 0; 107 108 // Open a session for descrambling a program, or one or more elementary 109 // streams. 110 virtual status_t openSession(CasSessionId *sessionId) = 0; 111 112 // Open a session with intend and mode for descrambling a program, or one 113 // or more elementary streams. 114 virtual status_t openSession(uint32_t intent, uint32_t mode, 115 CasSessionId *sessionId) = 0; 116 117 // Close a previously opened session. 118 virtual status_t closeSession(const CasSessionId &sessionId) = 0; 119 120 // Provide the CA private data from a CA_descriptor in the program map 121 // table to a CasPlugin. 122 virtual status_t setSessionPrivateData( 123 const CasSessionId &sessionId, 124 const CasData &privateData) = 0; 125 126 // Process an ECM from the ECM stream for this session’s elementary stream. 127 virtual status_t processEcm( 128 const CasSessionId &sessionId, 129 const CasEcm &ecm) = 0; 130 131 // Process an in-band EMM from the EMM stream. 132 virtual status_t processEmm( 133 const CasEmm &emm) = 0; 134 135 // Deliver an event to the CasPlugin. The format of the event is specific 136 // to the CA scheme and is opaque to the framework. 137 virtual status_t sendEvent( 138 int32_t event, 139 int32_t arg, 140 const CasData &eventData) = 0; 141 142 // Deliver an session event to the CasPlugin. The format of the event is 143 // specific to the CA scheme and is opaque to the framework. 144 virtual status_t sendSessionEvent( 145 const CasSessionId &sessionId, 146 int32_t event, 147 int32_t arg, 148 const CasData &eventData) = 0; 149 150 // Native implementation of the MediaCas Java API provision method. 151 virtual status_t provision( 152 const String8 &provisionString) = 0; 153 154 // Native implementation of the MediaCas Java API refreshEntitlements method 155 virtual status_t refreshEntitlements( 156 int32_t refreshType, 157 const CasData &refreshData) = 0; 158 159 private: 160 CasPlugin(const CasPlugin &); 161 CasPlugin &operator=(const CasPlugin &); /* NOLINT */ 162 }; 163 164 extern "C" { 165 extern android::CasFactory *createCasFactory(); 166 } 167 168 } // namespace android 169 170 #endif // CAS_API_H_ 171