1 /* 2 * Copyright (C) 2016 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 ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H 18 #define ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H 19 20 #include <android-base/thread_annotations.h> 21 #include <android/hardware/drm/1.0/ICryptoPlugin.h> 22 #include <android/hidl/memory/1.0/IMemory.h> 23 #include <hidl/Status.h> 24 #include <media/hardware/CryptoAPI.h> 25 26 #include <mutex> 27 28 namespace android { 29 namespace hardware { 30 namespace drm { 31 namespace V1_0 { 32 namespace implementation { 33 34 using ::android::hardware::drm::V1_0::DestinationBuffer; 35 using ::android::hardware::drm::V1_0::ICryptoPlugin; 36 using ::android::hardware::drm::V1_0::Mode; 37 using ::android::hardware::drm::V1_0::Pattern; 38 using ::android::hardware::drm::V1_0::SubSample; 39 using ::android::hardware::hidl_array; 40 using ::android::hardware::hidl_string; 41 using ::android::hardware::hidl_vec; 42 using ::android::hardware::Return; 43 using ::android::hardware::Void; 44 using ::android::hidl::memory::V1_0::IMemory; 45 using ::android::sp; 46 47 struct CryptoPlugin : public ICryptoPlugin { CryptoPluginCryptoPlugin48 CryptoPlugin(android::CryptoPlugin *plugin) : mLegacyPlugin(plugin) {} 49 ~CryptoPluginCryptoPlugin50 ~CryptoPlugin() {delete mLegacyPlugin;} 51 52 // Methods from ::android::hardware::drm::V1_0::ICryptoPlugin 53 // follow. 54 55 Return<bool> requiresSecureDecoderComponent(const hidl_string& mime) 56 override; 57 58 Return<void> notifyResolution(uint32_t width, uint32_t height) override; 59 60 Return<Status> setMediaDrmSession(const hidl_vec<uint8_t>& sessionId) 61 override; 62 63 Return<void> setSharedBufferBase(const ::android::hardware::hidl_memory& base, 64 uint32_t bufferId) override; 65 66 Return<void> decrypt( 67 bool secure, const hidl_array<uint8_t, 16>& keyId, const hidl_array<uint8_t, 16>& iv, 68 Mode mode, const Pattern& pattern, const hidl_vec<SubSample>& subSamples, 69 const SharedBuffer& source, uint64_t offset, const DestinationBuffer& destination, 70 decrypt_cb _hidl_cb) override NO_THREAD_SAFETY_ANALYSIS; // use unique_lock 71 72 private: 73 android::CryptoPlugin *mLegacyPlugin; 74 std::map<uint32_t, sp<IMemory>> mSharedBufferMap GUARDED_BY(mSharedBufferLock); 75 76 CryptoPlugin() = delete; 77 CryptoPlugin(const CryptoPlugin &) = delete; 78 void operator=(const CryptoPlugin &) = delete; 79 80 std::mutex mSharedBufferLock; 81 }; 82 83 } // namespace implementation 84 } // namespace V1_0 85 } // namespace drm 86 } // namespace hardware 87 } // namespace android 88 89 #endif // ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H 90