Chong Zhang | 783c33e | 2016-10-28 17:15:16 -0700 | [diff] [blame] | 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 { |
| 52 | CasFactory() {} |
| 53 | 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 { |
| 76 | CasPlugin() {} |
| 77 | 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. The session will receive the |
| 85 | // ECM stream corresponding to the CA_PID for the program. |
| 86 | virtual status_t openSession( |
| 87 | uint16_t program_number, |
| 88 | CasSessionId *sessionId) = 0; |
| 89 | |
| 90 | // Open a session for descrambling an elementary stream inside a program. |
| 91 | // The session will receive the ECM stream corresponding to the CA_PID for |
| 92 | // the stream. |
| 93 | virtual status_t openSession( |
| 94 | uint16_t program_number, |
| 95 | uint16_t elementary_PID, |
| 96 | CasSessionId *sessionId) = 0; |
| 97 | |
| 98 | // Close a previously opened session. |
| 99 | virtual status_t closeSession( |
| 100 | const CasSessionId &sessionId) = 0; |
| 101 | |
| 102 | // Provide the CA private data from a CA_descriptor in the program map |
| 103 | // table to a CasPlugin. |
| 104 | virtual status_t setSessionPrivateData( |
| 105 | const CasSessionId &sessionId, |
| 106 | const CasData &privateData) = 0; |
| 107 | |
| 108 | // Process an ECM from the ECM stream for this session’s elementary stream. |
| 109 | virtual status_t processEcm( |
| 110 | const CasSessionId &sessionId, |
| 111 | const CasEcm &ecm) = 0; |
| 112 | |
| 113 | // Process an in-band EMM from the EMM stream. |
| 114 | virtual status_t processEmm( |
| 115 | const CasEmm &emm) = 0; |
| 116 | |
| 117 | // Deliver an event to the CasPlugin. The format of the event is specific |
| 118 | // to the CA scheme and is opaque to the framework. |
| 119 | virtual status_t sendEvent( |
| 120 | int32_t event, |
| 121 | int32_t arg, |
| 122 | const CasData &eventData) = 0; |
| 123 | |
| 124 | // Native implementation of the MediaCas Java API provision method. |
| 125 | virtual status_t provision( |
| 126 | const String8 &provisionString) = 0; |
| 127 | |
| 128 | // Native implementation of the MediaCas Java API refreshEntitlements method |
| 129 | virtual status_t refreshEntitlements( |
| 130 | int32_t refreshType, |
| 131 | const CasData &refreshData) = 0; |
| 132 | |
| 133 | private: |
| 134 | CasPlugin(const CasPlugin &); |
| 135 | CasPlugin &operator=(const CasPlugin &); /* NOLINT */ |
| 136 | }; |
| 137 | |
| 138 | extern "C" { |
| 139 | extern android::CasFactory *createCasFactory(); |
| 140 | } |
| 141 | |
| 142 | } // namespace android |
| 143 | |
| 144 | #endif // CAS_API_H_ |