blob: 3291ea26ab86926478131e4bfcb6504feaae6b80 [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 */
Jeff Tinkerda002fe2017-01-19 14:41:11 -080016#ifndef ANDROID_HARDWARE_DRM_V1_0__DRMFACTORY_H
17#define ANDROID_HARDWARE_DRM_V1_0__DRMFACTORY_H
Jeff Tinkerb075caa2016-12-06 23:15:20 -080018
Jeff Tinkerda002fe2017-01-19 14:41:11 -080019#include <android/hardware/drm/1.0/IDrmFactory.h>
Jeff Tinkerb075caa2016-12-06 23:15:20 -080020#include <hidl/Status.h>
21#include <media/drm/DrmAPI.h>
22#include <media/PluginLoader.h>
23#include <media/SharedLibrary.h>
24
25namespace android {
26namespace hardware {
27namespace drm {
Jeff Tinkerb075caa2016-12-06 23:15:20 -080028namespace V1_0 {
29namespace implementation {
30
Jeff Tinkerda002fe2017-01-19 14:41:11 -080031using ::android::hardware::drm::V1_0::IDrmFactory;
32using ::android::hardware::drm::V1_0::IDrmPlugin;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080033using ::android::hardware::hidl_array;
34using ::android::hardware::hidl_string;
35using ::android::hardware::hidl_vec;
36using ::android::hardware::Return;
37using ::android::hardware::Void;
38using ::android::sp;
39
40struct DrmFactory : public IDrmFactory {
41 DrmFactory();
42 virtual ~DrmFactory() {}
43
Jeff Tinkerda002fe2017-01-19 14:41:11 -080044 // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
Jeff Tinkerb075caa2016-12-06 23:15:20 -080045 Return<bool> isCryptoSchemeSupported(const hidl_array<uint8_t, 16>& uuid)
46 override;
47
Jeff Tinkerfbf36502017-01-24 06:58:26 -080048 Return<bool> isContentTypeSupported(const hidl_string& mimeType)
Jeff Tinkerb3a16722016-12-30 19:03:17 -080049 override;
50
Jeff Tinkerb075caa2016-12-06 23:15:20 -080051 Return<void> createPlugin(const hidl_array<uint8_t, 16>& uuid,
Jeff Tinkerfbf36502017-01-24 06:58:26 -080052 createPlugin_cb _hidl_cb) override;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080053private:
Jeff Tinkerfbf36502017-01-24 06:58:26 -080054 template <typename L> Return<bool> isCryptoSchemeSupported(
55 const L& loader, const hidl_array<uint8_t, 16>& uuid) {
56 for (size_t i = 0; i < loader.factoryCount(); i++) {
57 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
58 return true;
59 }
60 }
61 return false;
62 }
63
64 template <typename L, typename S> Return<bool> isContentTypeSupported(
65 const L& loader, const hidl_string& mimeType) {
66 for (size_t i = 0; i < loader.factoryCount(); i++) {
67 if (loader.getFactory(i)->isContentTypeSupported(S(mimeType))) {
68 return true;
69 }
70 }
71 return false;
72 }
73
74 sp<IDrmPlugin> createTreblePlugin(const hidl_array<uint8_t, 16>& uuid);
75 sp<IDrmPlugin> createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid);
76
77 typedef android::PluginLoader<IDrmFactory> PluginLoader;
78 PluginLoader trebleLoader;
79
80 typedef android::PluginLoader<android::DrmFactory> LegacyLoader;
81 LegacyLoader legacyLoader;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080082
83 DrmFactory(const DrmFactory &) = delete;
84 void operator=(const DrmFactory &) = delete;
85};
86
87extern "C" IDrmFactory* HIDL_FETCH_IDrmFactory(const char* name);
88
89} // namespace implementation
90} // namespace V1_0
91} // namespace drm
Jeff Tinkerb075caa2016-12-06 23:15:20 -080092} // namespace hardware
93} // namespace android
94
Jeff Tinkerda002fe2017-01-19 14:41:11 -080095#endif // ANDROID_HARDWARE_DRM_V1_0__DRMFACTORY_H