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