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 struct CasFactory { CasFactoryCasFactory52 CasFactory() {} ~CasFactoryCasFactory53 virtual ~CasFactory() {} 54 55 // Determine if the plugin can handle the CA scheme identified by CA_system_id. 56 virtual bool isSystemIdSupported( 57 int32_t CA_system_id) const = 0; 58 59 // Get a list of the CA schemes supported by the plugin. 60 virtual status_t queryPlugins( 61 std::vector<CasPluginDescriptor> *descriptors) const = 0; 62 63 // Construct a new instance of a CasPlugin given a CA_system_id 64 virtual status_t createPlugin( 65 int32_t CA_system_id, 66 uint64_t appData, 67 CasPluginCallback callback, 68 CasPlugin **plugin) = 0; 69 70 private: 71 CasFactory(const CasFactory &); 72 CasFactory &operator=(const CasFactory &); /* NOLINT */ 73 }; 74 75 struct CasPlugin { CasPluginCasPlugin76 CasPlugin() {} ~CasPluginCasPlugin77 virtual ~CasPlugin() {} 78 79 // Provide the CA private data from a CA_descriptor in the conditional 80 // access table to a CasPlugin. 81 virtual status_t setPrivateData( 82 const CasData &privateData) = 0; 83 84 // Open a session for descrambling a program, or one or more elementary 85 // streams. 86 virtual status_t openSession(CasSessionId *sessionId) = 0; 87 88 // Close a previously opened session. 89 virtual status_t closeSession(const CasSessionId &sessionId) = 0; 90 91 // Provide the CA private data from a CA_descriptor in the program map 92 // table to a CasPlugin. 93 virtual status_t setSessionPrivateData( 94 const CasSessionId &sessionId, 95 const CasData &privateData) = 0; 96 97 // Process an ECM from the ECM stream for this session’s elementary stream. 98 virtual status_t processEcm( 99 const CasSessionId &sessionId, 100 const CasEcm &ecm) = 0; 101 102 // Process an in-band EMM from the EMM stream. 103 virtual status_t processEmm( 104 const CasEmm &emm) = 0; 105 106 // Deliver an event to the CasPlugin. The format of the event is specific 107 // to the CA scheme and is opaque to the framework. 108 virtual status_t sendEvent( 109 int32_t event, 110 int32_t arg, 111 const CasData &eventData) = 0; 112 113 // Native implementation of the MediaCas Java API provision method. 114 virtual status_t provision( 115 const String8 &provisionString) = 0; 116 117 // Native implementation of the MediaCas Java API refreshEntitlements method 118 virtual status_t refreshEntitlements( 119 int32_t refreshType, 120 const CasData &refreshData) = 0; 121 122 private: 123 CasPlugin(const CasPlugin &); 124 CasPlugin &operator=(const CasPlugin &); /* NOLINT */ 125 }; 126 127 extern "C" { 128 extern android::CasFactory *createCasFactory(); 129 } 130 131 } // namespace android 132 133 #endif // CAS_API_H_ 134