Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 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 CRYPTO_HAL_H_ |
| 18 | |
| 19 | #define CRYPTO_HAL_H_ |
| 20 | |
| 21 | #include <android/hardware/drm/1.0/ICryptoFactory.h> |
| 22 | #include <android/hardware/drm/1.0/ICryptoPlugin.h> |
Jeff Tinker | e307dc4 | 2018-02-11 19:53:54 +0000 | [diff] [blame^] | 23 | #include <android/hardware/drm/1.1/ICryptoFactory.h> |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 24 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 25 | #include <media/ICrypto.h> |
| 26 | #include <utils/KeyedVector.h> |
| 27 | #include <utils/threads.h> |
| 28 | |
Jeff Tinker | e307dc4 | 2018-02-11 19:53:54 +0000 | [diff] [blame^] | 29 | namespace drm = ::android::hardware::drm; |
| 30 | using drm::V1_0::ICryptoFactory; |
| 31 | using drm::V1_0::ICryptoPlugin; |
| 32 | using drm::V1_0::SharedBuffer; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 33 | |
Jeff Tinker | 3cb5316 | 2017-02-16 12:06:32 -0800 | [diff] [blame] | 34 | class IMemoryHeap; |
| 35 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 36 | namespace android { |
| 37 | |
| 38 | struct CryptoHal : public BnCrypto { |
| 39 | CryptoHal(); |
| 40 | virtual ~CryptoHal(); |
| 41 | |
| 42 | virtual status_t initCheck() const; |
| 43 | |
| 44 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]); |
| 45 | |
| 46 | virtual status_t createPlugin( |
| 47 | const uint8_t uuid[16], const void *data, size_t size); |
| 48 | |
| 49 | virtual status_t destroyPlugin(); |
| 50 | |
| 51 | virtual bool requiresSecureDecoderComponent( |
| 52 | const char *mime) const; |
| 53 | |
| 54 | virtual void notifyResolution(uint32_t width, uint32_t height); |
| 55 | |
| 56 | virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId); |
| 57 | |
| 58 | virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16], |
| 59 | CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern, |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 60 | const ICrypto::SourceBuffer &source, size_t offset, |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 61 | const CryptoPlugin::SubSample *subSamples, size_t numSubSamples, |
| 62 | const ICrypto::DestinationBuffer &destination, |
| 63 | AString *errorDetailMsg); |
| 64 | |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 65 | virtual int32_t setHeap(const sp<IMemoryHeap>& heap) { |
| 66 | return setHeapBase(heap); |
| 67 | } |
| 68 | virtual void unsetHeap(int32_t seqNum) { clearHeapBase(seqNum); } |
Chong Zhang | d07c927 | 2017-03-28 11:02:06 -0700 | [diff] [blame] | 69 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 70 | private: |
| 71 | mutable Mutex mLock; |
| 72 | |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 73 | const Vector<sp<ICryptoFactory>> mFactories; |
| 74 | sp<ICryptoPlugin> mPlugin; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * mInitCheck is: |
| 78 | * NO_INIT if a plugin hasn't been created yet |
| 79 | * ERROR_UNSUPPORTED if a plugin can't be created for the uuid |
| 80 | * OK after a plugin has been created and mPlugin is valid |
| 81 | */ |
| 82 | status_t mInitCheck; |
| 83 | |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 84 | KeyedVector<int32_t, uint32_t> mHeapBases; |
Jeff Tinker | 3cb5316 | 2017-02-16 12:06:32 -0800 | [diff] [blame] | 85 | uint32_t mNextBufferId; |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 86 | int32_t mHeapSeqNum; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 87 | |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 88 | Vector<sp<ICryptoFactory>> makeCryptoFactories(); |
| 89 | sp<ICryptoPlugin> makeCryptoPlugin(const sp<ICryptoFactory>& factory, |
| 90 | const uint8_t uuid[16], const void *initData, size_t size); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 91 | |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 92 | int32_t setHeapBase(const sp<IMemoryHeap>& heap); |
| 93 | void clearHeapBase(int32_t seqNum); |
Jeff Tinker | 3cb5316 | 2017-02-16 12:06:32 -0800 | [diff] [blame] | 94 | |
Chong Zhang | 6dcab2b | 2017-03-28 14:18:27 -0700 | [diff] [blame] | 95 | status_t toSharedBuffer(const sp<IMemory>& memory, int32_t seqNum, ::SharedBuffer* buffer); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 96 | |
| 97 | DISALLOW_EVIL_CONSTRUCTORS(CryptoHal); |
| 98 | }; |
| 99 | |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif // CRYPTO_HAL_H_ |