1 /* 2 * Copyright (C) 2018 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_CRYPTO_PLUGIN_H_ 18 #define CLEARKEY_CRYPTO_PLUGIN_H_ 19 20 #include <android/hardware/drm/1.2/ICryptoPlugin.h> 21 #include <android/hidl/memory/1.0/IMemory.h> 22 23 #include "ClearKeyTypes.h" 24 #include "Session.h" 25 #include "Utils.h" 26 27 namespace { 28 static const size_t KEY_ID_SIZE = 16; 29 static const size_t KEY_IV_SIZE = 16; 30 } 31 32 namespace android { 33 namespace hardware { 34 namespace drm { 35 namespace V1_2 { 36 namespace clearkey { 37 38 namespace drm = ::android::hardware::drm; 39 using drm::V1_0::DestinationBuffer; 40 using drm::V1_0::Mode; 41 using drm::V1_0::Pattern; 42 using drm::V1_0::SharedBuffer; 43 using drm::V1_0::Status; 44 using drm::V1_0::SubSample; 45 46 using ::android::hardware::hidl_array; 47 using ::android::hardware::hidl_memory; 48 using ::android::hardware::hidl_string; 49 using ::android::hardware::hidl_vec; 50 using ::android::hardware::Return; 51 using ::android::hardware::Void; 52 using ::android::hidl::memory::V1_0::IMemory; 53 using ::android::sp; 54 55 typedef drm::V1_2::Status Status_V1_2; 56 57 struct CryptoPlugin : public drm::V1_2::ICryptoPlugin { CryptoPluginCryptoPlugin58 explicit CryptoPlugin(const hidl_vec<uint8_t>& sessionId) { 59 mInitStatus = setMediaDrmSession(sessionId); 60 } ~CryptoPluginCryptoPlugin61 virtual ~CryptoPlugin() {} 62 requiresSecureDecoderComponentCryptoPlugin63 Return<bool> requiresSecureDecoderComponent(const hidl_string& mime) { 64 UNUSED(mime); 65 return false; 66 } 67 notifyResolutionCryptoPlugin68 Return<void> notifyResolution(uint32_t width, uint32_t height) { 69 UNUSED(width); 70 UNUSED(height); 71 return Void(); 72 } 73 74 Return<void> decrypt( 75 bool secure, 76 const hidl_array<uint8_t, KEY_ID_SIZE>& keyId, 77 const hidl_array<uint8_t, KEY_IV_SIZE>& iv, 78 Mode mode, 79 const Pattern& pattern, 80 const hidl_vec<SubSample>& subSamples, 81 const SharedBuffer& source, 82 uint64_t offset, 83 const DestinationBuffer& destination, 84 decrypt_cb _hidl_cb); 85 86 Return<void> decrypt_1_2( 87 bool secure, 88 const hidl_array<uint8_t, KEY_ID_SIZE>& keyId, 89 const hidl_array<uint8_t, KEY_IV_SIZE>& iv, 90 Mode mode, 91 const Pattern& pattern, 92 const hidl_vec<SubSample>& subSamples, 93 const SharedBuffer& source, 94 uint64_t offset, 95 const DestinationBuffer& destination, 96 decrypt_1_2_cb _hidl_cb); 97 98 Return<void> setSharedBufferBase(const hidl_memory& base, 99 uint32_t bufferId); 100 101 Return<Status> setMediaDrmSession(const hidl_vec<uint8_t>& sessionId); 102 getInitStatusCryptoPlugin103 Return<Status> getInitStatus() const { return mInitStatus; } 104 105 private: 106 CLEARKEY_DISALLOW_COPY_AND_ASSIGN(CryptoPlugin); 107 108 std::map<uint32_t, sp<IMemory> > mSharedBufferMap; 109 sp<Session> mSession; 110 Status mInitStatus; 111 }; 112 113 } // namespace clearkey 114 } // namespace V1_2 115 } // namespace drm 116 } // namespace hardware 117 } // namespace android 118 119 #endif // CLEARKEY_CRYPTO_PLUGIN_H_ 120