blob: 28ade20232914053716184245b1964ce1e4dbcaf [file] [log] [blame]
Jeff Tinkera53d6552017-01-20 00:31:46 -08001/*
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 Tinkerabeb36a2017-02-17 09:42:46 -080023
Jeff Tinkera53d6552017-01-20 00:31:46 -080024#include <media/ICrypto.h>
25#include <utils/KeyedVector.h>
26#include <utils/threads.h>
27
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080028using ::android::hardware::drm::V1_0::ICryptoFactory;
29using ::android::hardware::drm::V1_0::ICryptoPlugin;
30using ::android::hardware::drm::V1_0::SharedBuffer;
Jeff Tinkera53d6552017-01-20 00:31:46 -080031
Jeff Tinker3cb53162017-02-16 12:06:32 -080032class IMemoryHeap;
33
Jeff Tinkera53d6552017-01-20 00:31:46 -080034namespace android {
35
36struct CryptoHal : public BnCrypto {
37 CryptoHal();
38 virtual ~CryptoHal();
39
40 virtual status_t initCheck() const;
41
42 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
43
44 virtual status_t createPlugin(
45 const uint8_t uuid[16], const void *data, size_t size);
46
47 virtual status_t destroyPlugin();
48
49 virtual bool requiresSecureDecoderComponent(
50 const char *mime) const;
51
52 virtual void notifyResolution(uint32_t width, uint32_t height);
53
54 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId);
55
56 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
57 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
58 const sp<IMemory> &source, size_t offset,
59 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
60 const ICrypto::DestinationBuffer &destination,
61 AString *errorDetailMsg);
62
63private:
64 mutable Mutex mLock;
65
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080066 const Vector<sp<ICryptoFactory>> mFactories;
67 sp<ICryptoPlugin> mPlugin;
Jeff Tinkera53d6552017-01-20 00:31:46 -080068
69 /**
70 * mInitCheck is:
71 * NO_INIT if a plugin hasn't been created yet
72 * ERROR_UNSUPPORTED if a plugin can't be created for the uuid
73 * OK after a plugin has been created and mPlugin is valid
74 */
75 status_t mInitCheck;
76
Jeff Tinker3cb53162017-02-16 12:06:32 -080077 KeyedVector<void *, uint32_t> mHeapBases;
78 uint32_t mNextBufferId;
Jeff Tinkera53d6552017-01-20 00:31:46 -080079
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080080 Vector<sp<ICryptoFactory>> makeCryptoFactories();
81 sp<ICryptoPlugin> makeCryptoPlugin(const sp<ICryptoFactory>& factory,
82 const uint8_t uuid[16], const void *initData, size_t size);
Jeff Tinkera53d6552017-01-20 00:31:46 -080083
Jeff Tinker3cb53162017-02-16 12:06:32 -080084 void setHeapBase(const sp<IMemoryHeap>& heap);
85
Jeff Tinkerabeb36a2017-02-17 09:42:46 -080086 status_t toSharedBuffer(const sp<IMemory>& memory, ::SharedBuffer* buffer);
Jeff Tinkera53d6552017-01-20 00:31:46 -080087
88 DISALLOW_EVIL_CONSTRUCTORS(CryptoHal);
89};
90
91} // namespace android
92
93#endif // CRYPTO_HAL_H_