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.0/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_1 { 36 namespace clearkey { 37 38 using ::android::hardware::drm::V1_0::DestinationBuffer; 39 using ::android::hardware::drm::V1_0::ICryptoPlugin; 40 using ::android::hardware::drm::V1_0::Mode; 41 using ::android::hardware::drm::V1_0::Pattern; 42 using ::android::hardware::drm::V1_0::SharedBuffer; 43 using ::android::hardware::drm::V1_0::Status; 44 using ::android::hardware::drm::V1_0::SubSample; 45 using ::android::hardware::hidl_array; 46 using ::android::hardware::hidl_memory; 47 using ::android::hardware::hidl_string; 48 using ::android::hardware::hidl_vec; 49 using ::android::hardware::Return; 50 using ::android::hardware::Void; 51 using ::android::hidl::memory::V1_0::IMemory; 52 using ::android::sp; 53 54 struct CryptoPlugin : public ICryptoPlugin { 55 explicit CryptoPlugin(const hidl_vec<uint8_t>& sessionId) { 56 mInitStatus = setMediaDrmSession(sessionId); 57 } 58 virtual ~CryptoPlugin() {} 59 60 Return<bool> requiresSecureDecoderComponent(const hidl_string& mime) { 61 UNUSED(mime); 62 return false; 63 } 64 65 Return<void> notifyResolution(uint32_t width, uint32_t height) { 66 UNUSED(width); 67 UNUSED(height); 68 return Void(); 69 } 70 71 Return<void> decrypt( 72 bool secure, 73 const hidl_array<uint8_t, KEY_ID_SIZE>& keyId, 74 const hidl_array<uint8_t, KEY_IV_SIZE>& iv, 75 Mode mode, 76 const Pattern& pattern, 77 const hidl_vec<SubSample>& subSamples, 78 const SharedBuffer& source, 79 uint64_t offset, 80 const DestinationBuffer& destination, 81 decrypt_cb _hidl_cb); 82 83 Return<void> setSharedBufferBase(const hidl_memory& base, 84 uint32_t bufferId); 85 86 Return<Status> setMediaDrmSession(const hidl_vec<uint8_t>& sessionId); 87 88 Return<Status> getInitStatus() const { return mInitStatus; } 89 90 private: 91 CLEARKEY_DISALLOW_COPY_AND_ASSIGN(CryptoPlugin); 92 93 std::map<uint32_t, sp<IMemory> > mSharedBufferMap; 94 sp<Session> mSession; 95 Status mInitStatus; 96 }; 97 98 } // namespace clearkey 99 } // namespace V1_1 100 } // namespace drm 101 } // namespace hardware 102 } // namespace android 103 104 #endif // CLEARKEY_CRYPTO_PLUGIN_H_ 105