xref: /aosp_15_r20/frameworks/av/drm/libmediadrm/include/mediadrm/DrmHalListener.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright (C) 2022 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 DRM_HAL_LISTENER_H_
18 #define DRM_HAL_LISTENER_H_
19 
20 #include <aidl/android/hardware/drm/BnDrmPluginListener.h>
21 #include <mediadrm/DrmMetrics.h>
22 #include <mediadrm/IDrmClient.h>
23 
24 using EventTypeAidl = ::aidl::android::hardware::drm::EventType;
25 using KeyStatusAidl = ::aidl::android::hardware::drm::KeyStatus;
26 using aidl::android::hardware::drm::BnDrmPluginListener;
27 
28 namespace android {
29 struct DrmHalListener : public BnDrmPluginListener {
30     explicit DrmHalListener(const std::shared_ptr<MediaDrmMetrics>& in_metrics);
31     ~DrmHalListener();
32     ::ndk::ScopedAStatus onEvent(EventTypeAidl in_eventType,
33                                  const std::vector<uint8_t>& in_sessionId,
34                                  const std::vector<uint8_t>& in_data);
35     ::ndk::ScopedAStatus onExpirationUpdate(const std::vector<uint8_t>& in_sessionId,
36                                             int64_t in_expiryTimeInMS);
37     ::ndk::ScopedAStatus onKeysChange(const std::vector<uint8_t>& in_sessionId,
38                                       const std::vector<KeyStatusAidl>& in_keyStatusList,
39                                       bool in_hasNewUsableKey);
40     ::ndk::ScopedAStatus onSessionLostState(const std::vector<uint8_t>& in_sessionId);
41     void setListener(const sp<IDrmClient>& listener);
42 private:
43     std::shared_ptr<MediaDrmMetrics> mMetrics;
44     sp<IDrmClient> mListener;
45     mutable Mutex mEventLock;
46     mutable Mutex mNotifyLock;
47 };
48 } // namespace android
49 
50 #endif  // DRM_HAL_LISTENER_H_