blob: 0d091fae65d3c64f7d126a31d2b6843e5b85f3e5 [file] [log] [blame]
Jeff Tinkerb075caa2016-12-06 23:15:20 -08001/*
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
Jeff Tinkerda002fe2017-01-19 14:41:11 -080017#ifndef ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H
18#define ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H
Jeff Tinkerb075caa2016-12-06 23:15:20 -080019
Edwin Wong989975e2021-03-08 18:46:42 -080020#include <android-base/thread_annotations.h>
Jeff Tinkerda002fe2017-01-19 14:41:11 -080021#include <android/hardware/drm/1.0/ICryptoPlugin.h>
Edwin Wong989975e2021-03-08 18:46:42 -080022#include <android/hidl/memory/1.0/IMemory.h>
Jeff Tinkerb075caa2016-12-06 23:15:20 -080023#include <hidl/Status.h>
Jeff Tinkerda002fe2017-01-19 14:41:11 -080024#include <media/hardware/CryptoAPI.h>
Jeff Tinkerb075caa2016-12-06 23:15:20 -080025
Edwin Wong989975e2021-03-08 18:46:42 -080026#include <mutex>
27
Jeff Tinkerb075caa2016-12-06 23:15:20 -080028namespace android {
29namespace hardware {
30namespace drm {
Jeff Tinkerb075caa2016-12-06 23:15:20 -080031namespace V1_0 {
32namespace implementation {
33
Jeff Tinkerda002fe2017-01-19 14:41:11 -080034using ::android::hardware::drm::V1_0::DestinationBuffer;
35using ::android::hardware::drm::V1_0::ICryptoPlugin;
36using ::android::hardware::drm::V1_0::Mode;
37using ::android::hardware::drm::V1_0::Pattern;
38using ::android::hardware::drm::V1_0::SubSample;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080039using ::android::hardware::hidl_array;
40using ::android::hardware::hidl_string;
41using ::android::hardware::hidl_vec;
42using ::android::hardware::Return;
43using ::android::hardware::Void;
Jeff Tinkerf21cdaf2017-01-18 11:49:27 -080044using ::android::hidl::memory::V1_0::IMemory;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080045using ::android::sp;
46
47struct CryptoPlugin : public ICryptoPlugin {
48 CryptoPlugin(android::CryptoPlugin *plugin) : mLegacyPlugin(plugin) {}
Jeff Tinkerd59d3622016-12-16 01:34:52 -080049
Jeff Tinkere3b6ae12017-05-16 18:21:39 +000050 ~CryptoPlugin() {delete mLegacyPlugin;}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080051
Jeff Tinkerda002fe2017-01-19 14:41:11 -080052 // Methods from ::android::hardware::drm::V1_0::ICryptoPlugin
Jeff Tinkerb075caa2016-12-06 23:15:20 -080053 // 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
Jeff Tinker0b3f41e2017-02-16 12:20:30 -080063 Return<void> setSharedBufferBase(const ::android::hardware::hidl_memory& base,
64 uint32_t bufferId) override;
Jeff Tinkerf21cdaf2017-01-18 11:49:27 -080065
Edwin Wong989975e2021-03-08 18:46:42 -080066 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
Jeff Tinkerb075caa2016-12-06 23:15:20 -080071
Edwin Wong989975e2021-03-08 18:46:42 -080072 private:
Jeff Tinkerb075caa2016-12-06 23:15:20 -080073 android::CryptoPlugin *mLegacyPlugin;
Edwin Wong989975e2021-03-08 18:46:42 -080074 std::map<uint32_t, sp<IMemory>> mSharedBufferMap GUARDED_BY(mSharedBufferLock);
Jeff Tinkerb075caa2016-12-06 23:15:20 -080075
76 CryptoPlugin() = delete;
77 CryptoPlugin(const CryptoPlugin &) = delete;
78 void operator=(const CryptoPlugin &) = delete;
Edwin Wong989975e2021-03-08 18:46:42 -080079
80 std::mutex mSharedBufferLock;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080081};
82
83} // namespace implementation
84} // namespace V1_0
Jeff Tinkerb075caa2016-12-06 23:15:20 -080085} // namespace drm
86} // namespace hardware
87} // namespace android
88
Jeff Tinkerda002fe2017-01-19 14:41:11 -080089#endif // ANDROID_HARDWARE_DRM_V1_0__CRYPTOPLUGIN_H