• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
17 
18 #include <aidl/android/hardware/drm/BnCryptoPlugin.h>
19 #include <aidl/android/hardware/drm/Status.h>
20 
21 #include <aidl/android/hardware/common/Ashmem.h>
22 
23 #include <android/binder_auto_utils.h>
24 
25 #include <memory>
26 #include <mutex>
27 
28 #include "ClearKeyTypes.h"
29 #include "Session.h"
30 
31 namespace {
32 static const size_t KEY_ID_SIZE = 16;
33 static const size_t KEY_IV_SIZE = 16;
34 }  // namespace
35 
36 namespace aidl {
37 namespace android {
38 namespace hardware {
39 namespace drm {
40 namespace clearkey {
41 
42 using namespace clearkeydrm;
43 using ::aidl::android::hardware::drm::DecryptArgs;
44 using ::aidl::android::hardware::drm::Status;
45 
46 struct SharedBufferBase {
47     uint8_t* mBase;
48     int64_t mSize;
49     SharedBufferBase(const ::aidl::android::hardware::drm::SharedBuffer& mem);
50     ~SharedBufferBase();
51 };
52 
53 struct CryptoPlugin : public BnCryptoPlugin {
CryptoPluginCryptoPlugin54     explicit CryptoPlugin(const std::vector<uint8_t>& sessionId) {
55         const auto res = setMediaDrmSession(sessionId);
56         mInitStatus = Status::OK;
57         if (!res.isOk() && res.getExceptionCode() == EX_SERVICE_SPECIFIC) {
58             mInitStatus = static_cast<Status>(res.getServiceSpecificError());
59         }
60     }
~CryptoPluginCryptoPlugin61     virtual ~CryptoPlugin() {}
62 
63     ::ndk::ScopedAStatus decrypt(const DecryptArgs& in_args, int32_t* _aidl_return) override;
64 
65     ::ndk::ScopedAStatus getLogMessages(
66             std::vector<::aidl::android::hardware::drm::LogMessage>* _aidl_return) override;
67 
68     ::ndk::ScopedAStatus notifyResolution(int32_t in_width, int32_t in_height) override;
69 
70     ::ndk::ScopedAStatus requiresSecureDecoderComponent(const std::string& in_mime,
71                                                         bool* _aidl_return) override;
72 
73     ::ndk::ScopedAStatus setMediaDrmSession(const std::vector<uint8_t>& in_sessionId) override;
74 
75     ::ndk::ScopedAStatus setSharedBufferBase(
76             const ::aidl::android::hardware::drm::SharedBuffer& in_base) override;
77 
getInitStatusCryptoPlugin78     ::aidl::android::hardware::drm::Status getInitStatus() const { return mInitStatus; }
79 
80   private:
81     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(CryptoPlugin);
82 
83     std::mutex mSharedBufferLock;
84     std::map<uint32_t, std::shared_ptr<SharedBufferBase>> mSharedBufferMap
85             GUARDED_BY(mSharedBufferLock);
86     ::android::sp<Session> mSession;
87     ::aidl::android::hardware::drm::Status mInitStatus;
88 };
89 
90 }  // namespace clearkey
91 }  // namespace drm
92 }  // namespace hardware
93 }  // namespace android
94 }  // namespace aidl
95