• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CLEARKEY_CAS_PLUGIN_H_
18 #define CLEARKEY_CAS_PLUGIN_H_
19 
20 #include <media/cas/CasAPI.h>
21 #include <media/cas/DescramblerAPI.h>
22 #include <utils/Mutex.h>
23 #include <utils/StrongPointer.h>
24 
25 extern "C" {
26       android::CasFactory *createCasFactory();
27       android::DescramblerFactory *createDescramblerFactory();
28 }
29 
30 namespace android {
31 namespace clearkeycas {
32 
33 class KeyFetcher;
34 class ClearKeyCasSession;
35 
36 class ClearKeyCasFactory : public CasFactory {
37 public:
ClearKeyCasFactory()38     ClearKeyCasFactory() {}
~ClearKeyCasFactory()39     virtual ~ClearKeyCasFactory() {}
40 
41     virtual bool isSystemIdSupported(
42             int32_t CA_system_id) const override;
43     virtual status_t queryPlugins(
44             std::vector<CasPluginDescriptor> *descriptors) const override;
45     virtual status_t createPlugin(
46             int32_t CA_system_id,
47             uint64_t appData,
48             CasPluginCallback callback,
49             CasPlugin **plugin) override;
50 };
51 
52 class ClearKeyDescramblerFactory : public DescramblerFactory {
53 public:
ClearKeyDescramblerFactory()54     ClearKeyDescramblerFactory() {}
~ClearKeyDescramblerFactory()55     virtual ~ClearKeyDescramblerFactory() {}
56 
57     virtual bool isSystemIdSupported(
58             int32_t CA_system_id) const override;
59     virtual status_t createPlugin(
60             int32_t CA_system_id, DescramblerPlugin **plugin) override;
61 };
62 
63 class ClearKeyCasPlugin : public CasPlugin {
64 public:
65     ClearKeyCasPlugin(uint64_t appData, CasPluginCallback callback);
66     virtual ~ClearKeyCasPlugin();
67 
68     virtual status_t setPrivateData(
69             const CasData &data) override;
70 
71     virtual status_t openSession(CasSessionId *sessionId) override;
72 
73     virtual status_t closeSession(
74             const CasSessionId &sessionId) override;
75 
76     virtual status_t setSessionPrivateData(
77             const CasSessionId &sessionId,
78             const CasData &data) override;
79 
80     virtual status_t processEcm(
81             const CasSessionId &sessionId, const CasEcm &ecm) override;
82 
83     virtual status_t processEmm(const CasEmm &emm) override;
84 
85     virtual status_t sendEvent(
86             int32_t event, int32_t arg, const CasData &eventData) override;
87 
88     virtual status_t provision(const String8 &str) override;
89 
90     virtual status_t refreshEntitlements(
91             int32_t refreshType, const CasData &refreshData) override;
92 
93 private:
94     Mutex mKeyFetcherLock;
95     std::unique_ptr<KeyFetcher> mKeyFetcher;
96     CasPluginCallback mCallback;
97     uint64_t mAppData;
98 };
99 
100 class ClearKeyDescramblerPlugin : public DescramblerPlugin {
101 public:
ClearKeyDescramblerPlugin()102     ClearKeyDescramblerPlugin() {}
~ClearKeyDescramblerPlugin()103     virtual ~ClearKeyDescramblerPlugin() {};
104 
105     virtual bool requiresSecureDecoderComponent(
106             const char *mime) const override;
107 
108     virtual status_t setMediaCasSession(
109             const CasSessionId &sessionId) override;
110 
111     virtual ssize_t descramble(
112             bool secure,
113             ScramblingControl scramblingControl,
114             size_t numSubSamples,
115             const SubSample *subSamples,
116             const void *srcPtr,
117             int32_t srcOffset,
118             void *dstPtr,
119             int32_t dstOffset,
120             AString *errorDetailMsg) override;
121 
122 private:
123     std::shared_ptr<ClearKeyCasSession> mCASSession;
124 
125     String8 subSamplesToString(
126             SubSample const *subSamples,
127             size_t numSubSamples) const;
128     String8 arrayToString(uint8_t const *array, size_t len) const;
129 };
130 
131 } // namespace clearkeycas
132 } // namespace android
133 
134 #endif // CLEARKEY_CAS_PLUGIN_H_
135